From 0c2c398dc05fc73ae6b83f783dd5a6f1a7a98bf0 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 3 Jan 2024 16:11:20 +0100 Subject: [PATCH 001/131] wip --- composer.json | 14 ++-- src/Contracts/SingleResourceEndpoint.php | 7 ++ src/Endpoints/BalanceEndpoint.php | 21 +++--- src/Endpoints/BalanceReportEndpoint.php | 2 +- src/Endpoints/BalanceTransactionEndpoint.php | 26 +++---- src/Endpoints/ChargebackEndpoint.php | 19 ++--- src/Endpoints/ClientEndpoint.php | 19 ++--- src/Endpoints/ClientLinkEndpoint.php | 7 +- src/Endpoints/CollectionEndpointAbstract.php | 6 +- src/Endpoints/CustomerEndpoint.php | 36 ++++------ src/Endpoints/CustomerPaymentsEndpoint.php | 41 ++++++----- src/Endpoints/EndpointAbstract.php | 62 ++++++++-------- src/Endpoints/InvoiceEndpoint.php | 25 +++---- src/Endpoints/MandateEndpoint.php | 71 ++++++++++--------- src/Endpoints/MethodEndpoint.php | 43 +++++------ src/Endpoints/OnboardingEndpoint.php | 47 ++++-------- src/Endpoints/OrderEndpoint.php | 41 ++++------- src/Endpoints/OrderLineEndpoint.php | 52 +++++--------- src/Endpoints/OrderPaymentEndpoint.php | 34 +++------ src/Endpoints/OrderRefundEndpoint.php | 21 ++---- src/Endpoints/OrganizationEndpoint.php | 28 +++----- src/Endpoints/OrganizationPartnerEndpoint.php | 37 ++-------- src/Endpoints/PaymentCaptureEndpoint.php | 51 ++++++------- src/Endpoints/PaymentChargebackEndpoint.php | 43 +++++------ src/Endpoints/PaymentEndpoint.php | 44 +++++------- src/Endpoints/PaymentLinkEndpoint.php | 9 +-- src/Endpoints/PaymentRefundEndpoint.php | 4 +- src/Endpoints/PaymentRouteEndpoint.php | 18 +---- src/Endpoints/PermissionEndpoint.php | 4 +- src/Endpoints/ProfileEndpoint.php | 9 +-- src/Endpoints/ProfileMethodEndpoint.php | 4 +- src/Endpoints/RefundEndpoint.php | 4 +- src/Endpoints/SettlementCaptureEndpoint.php | 4 +- .../SettlementChargebackEndpoint.php | 4 +- src/Endpoints/SettlementPaymentEndpoint.php | 4 +- src/Endpoints/SettlementRefundEndpoint.php | 4 +- src/Endpoints/SettlementsEndpoint.php | 4 +- src/Endpoints/ShipmentEndpoint.php | 9 +-- src/Endpoints/SubscriptionEndpoint.php | 9 +-- src/Endpoints/TerminalEndpoint.php | 9 +-- src/Resources/OrganizationCollection.php | 22 ------ src/Resources/ResourceFactory.php | 31 ++++---- src/Resources/RouteCollection.php | 22 ------ .../Guzzle6And7MollieHttpAdapterTest.php | 23 +++--- tests/Mollie/API/MollieApiClientTest.php | 3 +- 45 files changed, 388 insertions(+), 609 deletions(-) create mode 100644 src/Contracts/SingleResourceEndpoint.php delete mode 100644 src/Resources/OrganizationCollection.php delete mode 100644 src/Resources/RouteCollection.php diff --git a/composer.json b/composer.json index 47040d24b..20193917b 100644 --- a/composer.json +++ b/composer.json @@ -47,18 +47,18 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^7.4|^8.0", "ext-curl": "*", "ext-json": "*", "ext-openssl": "*", - "composer/ca-bundle": "^1.2" + "composer/ca-bundle": "^1.4" }, "require-dev": { - "eloquent/liberator": "^2.0||^3.0", - "friendsofphp/php-cs-fixer": "^3.0", - "guzzlehttp/guzzle": "^6.3 || ^7.0", - "phpstan/phpstan": "^1.4", - "phpunit/phpunit": "^8.5 || ^9.5" + "friendsofphp/php-cs-fixer": "^3.39", + "guzzlehttp/guzzle": "^7.6", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.6", + "spatie/invade": "^2.0" }, "suggest": { "mollie/oauth2-mollie-php": "Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information." diff --git a/src/Contracts/SingleResourceEndpoint.php b/src/Contracts/SingleResourceEndpoint.php new file mode 100644 index 000000000..52288eaca --- /dev/null +++ b/src/Contracts/SingleResourceEndpoint.php @@ -0,0 +1,7 @@ +client, $count, $_links); } @@ -28,7 +25,7 @@ protected function getResourceCollectionObject($count, $_links) /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Balance { return new Balance($this->client); } @@ -43,7 +40,7 @@ protected function getResourceObject() * @return \Mollie\Api\Resources\Balance|\Mollie\Api\Resources\BaseResource * @throws ApiException */ - public function get(string $balanceId, array $parameters = []) + public function get(string $balanceId, array $parameters = []): Balance { if (empty($balanceId) || strpos($balanceId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid balance ID: '{$balanceId}'. A balance ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -58,10 +55,10 @@ public function get(string $balanceId, array $parameters = []) * Will throw an ApiException if the balance id is invalid or the resource cannot be found. * * @param array $parameters - * @return \Mollie\Api\Resources\Balance|\Mollie\Api\Resources\BaseResource + * @return \Mollie\Api\Resources\Balance * @throws ApiException */ - public function primary(array $parameters = []) + public function primary(array $parameters = []): Balance { return parent::rest_read("primary", $parameters); } @@ -73,10 +70,10 @@ public function primary(array $parameters = []) * @param int|null $limit * @param array $parameters * - * @return BaseCollection|BalanceCollection + * @return BalanceCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index 86effa9cc..5d0861e0b 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -10,7 +10,7 @@ class BalanceReportEndpoint extends EndpointAbstract { - protected $resourcePath = "balances_report"; + protected string $resourcePath = "balances_report"; /** * @inheritDoc diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 4f2447139..329c62476 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -11,20 +11,14 @@ class BalanceTransactionEndpoint extends CollectionEndpointAbstract { - /** - * @var string - */ - const RESOURCE_ID_PREFIX = 'baltr_'; + const string RESOURCE_ID_PREFIX = 'baltr_'; - /** - * @var string - */ - protected $resourcePath = "balances_transactions"; + protected string $resourcePath = "balances_transactions"; /** * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): BalanceTransactionCollection { return new BalanceTransactionCollection($this->client, $count, $_links); } @@ -32,7 +26,7 @@ protected function getResourceCollectionObject($count, $_links) /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): BalanceTransaction { return new BalanceTransaction($this->client); } @@ -42,11 +36,11 @@ protected function getResourceObject() * * @param Balance $balance * @param array $parameters - * @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection + * @return BalanceTransactionCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Balance $balance, array $parameters = []) + public function listFor(Balance $balance, array $parameters = []): BalanceTransactionCollection { return $this->listForId($balance->id, $parameters); } @@ -70,11 +64,11 @@ public function iteratorFor(Balance $balance, array $parameters = [], bool $iter * * @param string $balanceId * @param array $parameters - * @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection + * @return BalanceTransactionCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId(string $balanceId, array $parameters = []) + public function listForId(string $balanceId, array $parameters = []): BalanceTransactionCollection { $this->parentId = $balanceId; @@ -101,11 +95,11 @@ public function iteratorForId(string $balanceId, array $parameters = [], bool $i * List the transactions for the primary Balance. * * @param array $parameters - * @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection + * @return BalanceTransactionCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForPrimary(array $parameters = []) + public function listForPrimary(array $parameters = []): BalanceTransactionCollection { $this->parentId = "primary"; diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index c40c179c0..f9711a1b0 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -9,27 +9,20 @@ class ChargebackEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "chargebacks"; + protected string $resourcePath = "chargebacks"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Chargeback + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Chargeback { return new Chargeback($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return ChargebackCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection { return new ChargebackCollection($this->client, $count, $_links); } @@ -44,7 +37,7 @@ protected function getResourceCollectionObject($count, $_links) * @return ChargebackCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 9d7ba66b1..e20107a25 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -9,25 +9,20 @@ class ClientEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "clients"; + protected string $resourcePath = "clients"; /** - * @return Client + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Client { return new Client($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return ClientCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): ClientCollection { return new ClientCollection($this->client, $count, $_links); } @@ -44,7 +39,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Client * @throws ApiException */ - public function get($clientId, array $parameters = []) + public function get(string $clientId, array $parameters = []): Client { if (empty($clientId)) { throw new ApiException("Client ID is empty."); @@ -63,7 +58,7 @@ public function get($clientId, array $parameters = []) * @return ClientCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 5641cc0d7..377158b29 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -7,12 +7,9 @@ class ClientLinkEndpoint extends EndpointAbstract { - protected $resourcePath = "client-links"; + protected string $resourcePath = "client-links"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'cl_'; + public const string RESOURCE_ID_PREFIX = 'cl_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index 06b1dec21..2de0fe997 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -17,10 +17,10 @@ abstract class CollectionEndpointAbstract extends EndpointAbstract * @param int $limit * @param array $filters * - * @return mixed + * @return BaseCollection * @throws ApiException */ - protected function rest_list(?string $from = null, ?int $limit = null, array $filters = []) + protected function rest_list(?string $from = null, ?int $limit = null, array $filters = []): BaseCollection { $filters = array_merge(["from" => $from, "limit" => $limit], $filters); @@ -67,5 +67,5 @@ protected function rest_iterator(?string $from = null, ?int $limit = null, array * * @return BaseCollection */ - abstract protected function getResourceCollectionObject($count, $_links); + abstract protected function getResourceCollectionObject(int $count, object $_links): BaseCollection; } diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 61c8e6895..07dcc2fc9 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -9,32 +9,22 @@ class CustomerEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "customers"; + protected string $resourcePath = "customers"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'cst_'; + public const string RESOURCE_ID_PREFIX = 'cst_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Customer + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Customer { return new Customer($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return CustomerCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): CustomerCollection { return new CustomerCollection($this->client, $count, $_links); } @@ -48,7 +38,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Customer * @throws ApiException */ - public function create(array $data = [], array $filters = []) + public function create(array $data = [], array $filters = []): Customer { return $this->rest_create($data, $filters); } @@ -63,7 +53,7 @@ public function create(array $data = [], array $filters = []) * @return Customer * @throws ApiException */ - public function get($customerId, array $parameters = []) + public function get(string $customerId, array $parameters = []): Customer { return $this->rest_read($customerId, $parameters); } @@ -74,12 +64,11 @@ public function get($customerId, array $parameters = []) * Will throw an ApiException if the customer id is invalid or the resource cannot be found. * * @param string $customerId - * * @param array $data * @return Customer * @throws ApiException */ - public function update($customerId, array $data = []) + public function update(string $customerId, array $data = []): Customer { if (empty($customerId) || strpos($customerId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid order ID: '{$customerId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -95,12 +84,11 @@ public function update($customerId, array $data = []) * Returns with HTTP status No Content (204) if successful. * * @param string $customerId - * * @param array $data - * @return null + * @return null|Customer * @throws ApiException */ - public function delete($customerId, array $data = []) + public function delete(string $customerId, array $data = []): ?Customer { return $this->rest_delete($customerId, $data); } @@ -115,7 +103,7 @@ public function delete($customerId, array $data = []) * @return CustomerCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index 1730cb245..e54a9c811 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -9,27 +9,20 @@ class CustomerPaymentsEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "customers_payments"; + protected string $resourcePath = "customers_payments"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Payment + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Payment { return new Payment($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return PaymentCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection { return new PaymentCollection($this->client, $count, $_links); } @@ -44,7 +37,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Customer $customer, array $options = [], array $filters = []) + public function createFor(Customer $customer, array $options = [], array $filters = []): Payment { return $this->createForId($customer->id, $options, $filters); } @@ -75,7 +68,7 @@ public function createForId($customerId, array $options = [], array $filters = [ * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []) + public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection { return $this->listForId($customer->id, $from, $limit, $parameters); } @@ -91,8 +84,13 @@ public function listFor(Customer $customer, ?string $from = null, ?int $limit = * * @return LazyCollection */ - public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); } @@ -105,7 +103,7 @@ public function iteratorFor(Customer $customer, ?string $from = null, ?int $limi * @return \Mollie\Api\Resources\PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($customerId, ?string $from = null, ?int $limit = null, array $parameters = []) + public function listForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection { $this->parentId = $customerId; @@ -123,8 +121,13 @@ public function listForId($customerId, ?string $from = null, ?int $limit = null, * * @return LazyCollection */ - public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $customerId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/EndpointAbstract.php b/src/Endpoints/EndpointAbstract.php index fe87e9787..0d7af6d60 100644 --- a/src/Endpoints/EndpointAbstract.php +++ b/src/Endpoints/EndpointAbstract.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Mollie\Api\Contracts\SingleResourceEndpoint; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\BaseResource; @@ -15,24 +16,12 @@ abstract class EndpointAbstract public const REST_LIST = MollieApiClient::HTTP_GET; public const REST_DELETE = MollieApiClient::HTTP_DELETE; - /** - * @var MollieApiClient - */ - protected $client; + protected MollieApiClient $client; - /** - * @var string - */ - protected $resourcePath; + protected string $resourcePath; - /** - * @var string|null - */ - protected $parentId; + protected ?string $parentId; - /** - * @param MollieApiClient $api - */ public function __construct(MollieApiClient $api) { $this->client = $api; @@ -42,7 +31,7 @@ public function __construct(MollieApiClient $api) * @param array $filters * @return string */ - protected function buildQueryString(array $filters) + protected function buildQueryString(array $filters): string { if (empty($filters)) { return ""; @@ -64,10 +53,10 @@ protected function buildQueryString(array $filters) /** * @param array $body * @param array $filters - * @return mixed + * @return BaseResource * @throws ApiException */ - protected function rest_create(array $body, array $filters) + protected function rest_create(array $body, array $filters): BaseResource { $result = $this->client->performHttpCall( self::REST_CREATE, @@ -84,10 +73,10 @@ protected function rest_create(array $body, array $filters) * @param string $id * @param array $body * - * @return mixed + * @return null|BaseResource * @throws ApiException */ - protected function rest_update($id, array $body = []) + protected function rest_update(string $id, array $body = []): ?BaseResource { if (empty($id)) { throw new ApiException("Invalid resource id."); @@ -96,7 +85,7 @@ protected function rest_update($id, array $body = []) $id = urlencode($id); $result = $this->client->performHttpCall( self::REST_UPDATE, - "{$this->getResourcePath()}/{$id}", + $this->getPathToSingleResource($id), $this->parseRequestBody($body) ); @@ -112,19 +101,19 @@ protected function rest_update($id, array $body = []) * * @param string $id Id of the object to retrieve. * @param array $filters - * @return mixed + * @return BaseResource * @throws ApiException */ - protected function rest_read($id, array $filters) + protected function rest_read(string $id, array $filters): BaseResource { - if (empty($id)) { + if (!$this instanceof SingleResourceEndpoint && empty($id)) { throw new ApiException("Invalid resource id."); } $id = urlencode($id); $result = $this->client->performHttpCall( self::REST_READ, - "{$this->getResourcePath()}/{$id}" . $this->buildQueryString($filters) + $this->getPathToSingleResource($id) . $this->buildQueryString($filters) ); return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); @@ -136,10 +125,10 @@ protected function rest_read($id, array $filters) * @param string $id * @param array $body * - * @return mixed + * @return null|BaseResource * @throws ApiException */ - protected function rest_delete($id, array $body = []) + protected function rest_delete(string $id, array $body = []): ?BaseResource { if (empty($id)) { throw new ApiException("Invalid resource id."); @@ -148,7 +137,7 @@ protected function rest_delete($id, array $body = []) $id = urlencode($id); $result = $this->client->performHttpCall( self::REST_DELETE, - "{$this->getResourcePath()}/{$id}", + $this->getPathToSingleResource($id), $this->parseRequestBody($body) ); @@ -159,14 +148,12 @@ protected function rest_delete($id, array $body = []) return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); } - - /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. * * @return BaseResource */ - abstract protected function getResourceObject(); + abstract protected function getResourceObject(): BaseResource; /** * @param string $resourcePath @@ -180,7 +167,7 @@ public function setResourcePath($resourcePath) * @return string * @throws ApiException */ - public function getResourcePath() + public function getResourcePath(): string { if (strpos($this->resourcePath, "_") !== false) { [$parentResource, $childResource] = explode("_", $this->resourcePath, 2); @@ -195,11 +182,20 @@ public function getResourcePath() return $this->resourcePath; } + protected function getPathToSingleResource(string $id): string + { + if ($this instanceof SingleResourceEndpoint) { + return $this->getResourcePath(); + } + + return "{$this->getResourcePath()}/{$id}"; + } + /** * @param array $body * @return null|string */ - protected function parseRequestBody(array $body) + protected function parseRequestBody(array $body): ?string { if (empty($body)) { return null; diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index e577abd93..d752cbf81 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -9,27 +9,20 @@ class InvoiceEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "invoices"; + protected string $resourcePath = "invoices"; /** - * Get the object that is used by this API. Every API uses one type of object. - * - * @return \Mollie\Api\Resources\BaseResource + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Invoice { return new Invoice($this->client); } /** - * Get the collection object that is used by this API. Every API uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return \Mollie\Api\Resources\BaseCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): InvoiceCollection { return new InvoiceCollection($this->client, $count, $_links); } @@ -45,7 +38,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Invoice * @throws ApiException */ - public function get($invoiceId, array $parameters = []) + public function get(string $invoiceId, array $parameters = []): Invoice { return $this->rest_read($invoiceId, $parameters); } @@ -60,7 +53,7 @@ public function get($invoiceId, array $parameters = []) * @return InvoiceCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection { return $this->rest_list($from, $limit, $parameters); } @@ -70,10 +63,10 @@ public function page($from = null, $limit = null, array $parameters = []) * * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection + * @return InvoiceCollection * @throws ApiException */ - public function all(array $parameters = []) + public function all(array $parameters = []): InvoiceCollection { return $this->page(null, null, $parameters); } diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index d6dee89f3..5f8afdbfd 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -9,27 +9,20 @@ class MandateEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "customers_mandates"; + protected string $resourcePath = "customers_mandates"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Mandate + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Mandate { return new Mandate($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return MandateCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): MandateCollection { return new MandateCollection($this->client, $count, $_links); } @@ -39,10 +32,10 @@ protected function getResourceCollectionObject($count, $_links) * @param array $options * @param array $filters * - * @return \Mollie\Api\Resources\Mandate + * @return Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Customer $customer, array $options = [], array $filters = []) + public function createFor(Customer $customer, array $options = [], array $filters = []): Mandate { return $this->createForId($customer->id, $options, $filters); } @@ -52,10 +45,10 @@ public function createFor(Customer $customer, array $options = [], array $filter * @param array $options * @param array $filters * - * @return \Mollie\Api\Resources\Mandate + * @return Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($customerId, array $options = [], array $filters = []) + public function createForId(string $customerId, array $options = [], array $filters = []): Mandate { $this->parentId = $customerId; @@ -67,10 +60,10 @@ public function createForId($customerId, array $options = [], array $filters = [ * @param string $mandateId * @param array $parameters * - * @return \Mollie\Api\Resources\Mandate + * @return Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Customer $customer, $mandateId, array $parameters = []) + public function getFor(Customer $customer, $mandateId, array $parameters = []): Mandate { return $this->getForId($customer->id, $mandateId, $parameters); } @@ -80,10 +73,10 @@ public function getFor(Customer $customer, $mandateId, array $parameters = []) * @param string $mandateId * @param array $parameters * - * @return \Mollie\Api\Resources\Mandate + * @return Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId($customerId, $mandateId, array $parameters = []) + public function getForId(string $customerId, $mandateId, array $parameters = []) { $this->parentId = $customerId; @@ -96,10 +89,10 @@ public function getForId($customerId, $mandateId, array $parameters = []) * @param int $limit * @param array $parameters * - * @return \Mollie\Api\Resources\MandateCollection + * @return MandateCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = []) + public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = []): MandateCollection { return $this->listForId($customer->id, $from, $limit, $parameters); } @@ -115,21 +108,26 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ * * @return LazyCollection */ - public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); } /** * @param string $customerId - * @param null $from - * @param null $limit + * @param ?string $from + * @param ?int $limit * @param array $parameters * - * @return \Mollie\Api\Resources\MandateCollection + * @return MandateCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($customerId, $from = null, $limit = null, array $parameters = []) + public function listForId(string $customerId, string $from = null, int $limit = null, array $parameters = []): MandateCollection { $this->parentId = $customerId; @@ -147,8 +145,13 @@ public function listForId($customerId, $from = null, $limit = null, array $param * * @return LazyCollection */ - public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $customerId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); @@ -159,10 +162,10 @@ public function iteratorForId(string $customerId, ?string $from = null, ?int $li * @param string $mandateId * @param array $data * - * @return null + * @return null|Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function revokeFor(Customer $customer, $mandateId, $data = []) + public function revokeFor(Customer $customer, string $mandateId, array $data = []): ?Mandate { return $this->revokeForId($customer->id, $mandateId, $data); } @@ -172,10 +175,10 @@ public function revokeFor(Customer $customer, $mandateId, $data = []) * @param string $mandateId * @param array $data * - * @return null + * @return null|Mandate * @throws \Mollie\Api\Exceptions\ApiException */ - public function revokeForId($customerId, $mandateId, $data = []) + public function revokeForId(string $customerId, string $mandateId, array $data = []): ?Mandate { $this->parentId = $customerId; diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 934a27a84..29691bf56 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -9,26 +9,34 @@ class MethodEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "methods"; + protected string $resourcePath = "methods"; /** - * @return Method + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Method { return new Method($this->client); } + /** + * @inheritDoc + */ + protected function getResourceCollectionObject(int $count, object $_links): MethodCollection + { + return new MethodCollection($count, $_links); + } + /** * Retrieve all active methods. In test mode, this includes pending methods. The results are not paginated. * * @deprecated Use allActive() instead * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection + * @return MethodCollection * @throws ApiException */ - public function all(array $parameters = []) + public function all(array $parameters = []): MethodCollection { return $this->allActive($parameters); } @@ -39,10 +47,10 @@ public function all(array $parameters = []) * * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection + * @return MethodCollection * @throws ApiException */ - public function allActive(array $parameters = []) + public function allActive(array $parameters = []): MethodCollection { return parent::rest_list(null, null, $parameters); } @@ -52,10 +60,10 @@ public function allActive(array $parameters = []) * results are not paginated. Make sure to include the profileId parameter if using an OAuth Access Token. * * @param array $parameters Query string parameters. - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection + * @return MethodCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function allAvailable(array $parameters = []) + public function allAvailable(array $parameters = []): MethodCollection { $url = 'methods/all' . $this->buildQueryString($parameters); @@ -69,19 +77,6 @@ public function allAvailable(array $parameters = []) ); } - /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return MethodCollection - */ - protected function getResourceCollectionObject($count, $_links) - { - return new MethodCollection($count, $_links); - } - /** * Retrieve a payment method from Mollie. * @@ -89,10 +84,10 @@ protected function getResourceCollectionObject($count, $_links) * * @param string $methodId * @param array $parameters - * @return \Mollie\Api\Resources\Method + * @return Method * @throws ApiException */ - public function get($methodId, array $parameters = []) + public function get(string $methodId, array $parameters = []): Method { if (empty($methodId)) { throw new ApiException("Method ID is empty."); diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 52ba56958..4617b2555 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -2,26 +2,18 @@ namespace Mollie\Api\Endpoints; +use Mollie\Api\Contracts\SingleResourceEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\Onboarding; -use Mollie\Api\Resources\ResourceFactory; -class OnboardingEndpoint extends EndpointAbstract +class OnboardingEndpoint extends EndpointAbstract implements SingleResourceEndpoint { - protected $resourcePath = "onboarding/me"; - - protected function getResourceCollectionObject($count, $links) - { - throw new \BadMethodCallException('not implemented'); - } + protected string $resourcePath = "onboarding/me"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return BaseResource + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Onboarding { return new Onboarding($this->client); } @@ -34,7 +26,7 @@ protected function getResourceObject() * @return Onboarding * @throws ApiException */ - public function get() + public function get(): Onboarding { return $this->rest_read('', []); } @@ -47,38 +39,23 @@ public function get() * * Will throw a ApiException if the resource cannot be found. * + * @return void * @throws ApiException + * @deprecated use ClientLinkEndpoint create() method */ - public function submit(array $parameters = []) - { - return $this->rest_create($parameters, []); - } - - /** - * @param string $id - * @param array $filters - * - * @return mixed - * @throws \Mollie\Api\Exceptions\ApiException - */ - protected function rest_read($id, array $filters) + public function submit(array $parameters = []): void { - $result = $this->client->performHttpCall( - self::REST_READ, - $this->getResourcePath() . $this->buildQueryString($filters) - ); - - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + return $this->create($parameters, []); } /** * @param array $body * @param array $filters * - * @return mixed + * @return void * @throws \Mollie\Api\Exceptions\ApiException */ - protected function rest_create(array $body, array $filters) + private function create(array $body, array $filters): void { $this->client->performHttpCall( self::REST_CREATE, diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 91f7bc347..fc9645bcd 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -9,34 +9,22 @@ class OrderEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "orders"; + protected string $resourcePath = "orders"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'ord_'; + public const string RESOURCE_ID_PREFIX = 'ord_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one - * type of object. - * - * @return Order + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Order { return new Order($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return OrderCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): OrderCollection { return new OrderCollection($this->client, $count, $_links); } @@ -50,7 +38,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Order * @throws ApiException */ - public function create(array $data = [], array $filters = []) + public function create(array $data = [], array $filters = []): Order { return $this->rest_create($data, $filters); } @@ -61,12 +49,12 @@ public function create(array $data = [], array $filters = []) * Will throw a ApiException if the order id is invalid or the resource cannot be found. * * @param string $orderId - * * @param array $data + * * @return Order * @throws ApiException */ - public function update($orderId, array $data = []) + public function update(string $orderId, array $data = []): Order { if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -81,11 +69,12 @@ public function update($orderId, array $data = []) * Will throw a ApiException if the order id is invalid or the resource cannot * be found. * + * @param string $orderId * @param array $parameters * @return Order * @throws ApiException */ - public function get($orderId, array $parameters = []) + public function get(string $orderId, array $parameters = []): Order { if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -104,12 +93,12 @@ public function get($orderId, array $parameters = []) * Returns the canceled order with HTTP status 200. * * @param string $orderId - * * @param array $parameters - * @return Order + * + * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancel($orderId, $parameters = []) + public function cancel(string $orderId, $parameters = []): ?Order { return $this->rest_delete($orderId, $parameters); } @@ -124,7 +113,7 @@ public function cancel($orderId, $parameters = []) * @return OrderCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 2f16f0dad..5dbc95c3c 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -10,34 +10,22 @@ class OrderLineEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "orders_lines"; + protected string $resourcePath = "orders_lines"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'odl_'; + public const string RESOURCE_ID_PREFIX = 'odl_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one - * type of object. - * - * @return OrderLine + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): OrderLine { return new OrderLine($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return OrderLineCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): OrderLineCollection { return new OrderLineCollection($count, $_links); } @@ -49,18 +37,17 @@ protected function getResourceCollectionObject($count, $_links) * * @param string|null $orderId * @param string $orderlineId - * * @param array $data * - * @return \Mollie\Api\Resources\BaseResource|null + * @return OrderLine * @throws \Mollie\Api\Exceptions\ApiException */ - public function update($orderId, $orderlineId, array $data = []) + public function update(string $orderId, string $orderlineId, array $data = []): OrderLine { $this->parentId = $orderId; if (empty($orderlineId) || strpos($orderlineId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order line ID: '{$orderlineId}'. An order line ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid order line ID: '{$orderlineId}'. An order line ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_update($orderlineId, $data); @@ -70,10 +57,11 @@ public function update($orderId, $orderlineId, array $data = []) * @param string $orderId * @param array $operations * @param array $parameters - * @return Order|\Mollie\Api\Resources\BaseResource + * + * @return Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function updateMultiple(string $orderId, array $operations, array $parameters = []) + public function updateMultiple(string $orderId, array $operations, array $parameters = []): Order { if (empty($orderId)) { throw new ApiException("Invalid resource id."); @@ -96,34 +84,32 @@ public function updateMultiple(string $orderId, array $operations, array $parame * Cancel lines for the provided order. * The data array must contain a lines array. * You can pass an empty lines array if you want to cancel all eligible lines. - * Returns null if successful. * * @param Order $order * @param array $data * - * @return null + * @return void * @throws ApiException */ - public function cancelFor(Order $order, array $data) + public function cancelFor(Order $order, array $data): void { - return $this->cancelForId($order->id, $data); + $this->cancelForId($order->id, $data); } /** * Cancel lines for the provided order id. * The data array must contain a lines array. * You can pass an empty lines array if you want to cancel all eligible lines. - * Returns null if successful. * * @param string $orderId * @param array $data * - * @return null + * @return void * @throws ApiException */ - public function cancelForId($orderId, array $data) + public function cancelForId(string $orderId, array $data): void { - if (! isset($data['lines']) || ! is_array($data['lines'])) { + if (!isset($data['lines']) || !is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; @@ -133,7 +119,5 @@ public function cancelForId($orderId, array $data) "{$this->getResourcePath()}", $this->parseRequestBody($data) ); - - return null; } } diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index 6bedacf3e..6b4981e12 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -8,34 +8,22 @@ class OrderPaymentEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "orders_payments"; + protected string $resourcePath = "orders_payments"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'tr_'; + public const string RESOURCE_ID_PREFIX = 'tr_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one - * type of object. - * - * @return \Mollie\Api\Resources\Payment + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Payment { return new Payment($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return \Mollie\Api\Resources\PaymentCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection { return new PaymentCollection($this->client, $count, $_links); } @@ -43,14 +31,14 @@ protected function getResourceCollectionObject($count, $_links) /** * Creates a payment in Mollie for a specific order. * - * @param \Mollie\Api\Resources\Order $order + * @param Order $order * @param array $data An array containing details on the order payment. * @param array $filters * - * @return \Mollie\Api\Resources\Payment + * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Order $order, array $data, array $filters = []) + public function createFor(Order $order, array $data, array $filters = []): Payment { return $this->createForId($order->id, $data, $filters); } @@ -62,10 +50,10 @@ public function createFor(Order $order, array $data, array $filters = []) * @param array $data An array containing details on the order payment. * @param array $filters * - * @return \Mollie\Api\Resources\Payment + * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($orderId, array $data, array $filters = []) + public function createForId(string $orderId, array $data, array $filters = []): Payment { $this->parentId = $orderId; diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index d50c9e3b4..078b18dc7 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -8,27 +8,20 @@ class OrderRefundEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "orders_refunds"; + protected string $resourcePath = "orders_refunds"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Refund + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Refund { return new Refund($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return RefundCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): RefundCollection { return new RefundCollection($this->client, $count, $_links); } @@ -44,7 +37,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Order $order, array $data, array $filters = []) + public function createFor(Order $order, array $data, array $filters = []): Refund { return $this->createForId($order->id, $data, $filters); } @@ -60,7 +53,7 @@ public function createFor(Order $order, array $data, array $filters = []) * @return \Mollie\Api\Resources\Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($orderId, array $data, array $filters = []) + public function createForId(string $orderId, array $data, array $filters = []): Refund { $this->parentId = $orderId; diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index 10a7d7b95..ed0c60a5e 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -4,33 +4,19 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Organization; -use Mollie\Api\Resources\OrganizationCollection; -class OrganizationEndpoint extends CollectionEndpointAbstract +class OrganizationEndpoint extends EndpointAbstract { - protected $resourcePath = "organizations"; + protected string $resourcePath = "organizations"; /** - * @return Organization + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Organization { return new Organization($this->client); } - /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return OrganizationCollection - */ - protected function getResourceCollectionObject($count, $_links) - { - return new OrganizationCollection($this->client, $count, $_links); - } - /** * Retrieve an organization from Mollie. * @@ -38,10 +24,11 @@ protected function getResourceCollectionObject($count, $_links) * * @param string $organizationId * @param array $parameters + * * @return Organization * @throws ApiException */ - public function get($organizationId, array $parameters = []) + public function get(string $organizationId, array $parameters = []): Organization { if (empty($organizationId)) { throw new ApiException("Organization ID is empty."); @@ -54,10 +41,11 @@ public function get($organizationId, array $parameters = []) * Retrieve the current organization from Mollie. * * @param array $parameters + * * @return Organization * @throws ApiException */ - public function current(array $parameters = []) + public function current(array $parameters = []): Organization { return parent::rest_read('me', $parameters); } diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index 06a677b04..118972943 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -2,26 +2,18 @@ namespace Mollie\Api\Endpoints; +use Mollie\Api\Contracts\SingleResourceEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\Partner; -use Mollie\Api\Resources\ResourceFactory; -class OrganizationPartnerEndpoint extends EndpointAbstract +class OrganizationPartnerEndpoint extends EndpointAbstract implements SingleResourceEndpoint { - protected $resourcePath = "organizations/me/partner"; - - protected function getResourceCollectionObject($count, $links) - { - throw new \BadMethodCallException('not implemented'); - } + protected string $resourcePath = "organizations/me/partner"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return BaseResource + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Partner { return new Partner($this->client); } @@ -34,25 +26,8 @@ protected function getResourceObject() * @return Partner * @throws ApiException */ - public function get() + public function get(): Partner { return $this->rest_read('', []); } - - /** - * @param string $id - * @param array $filters - * - * @return mixed - * @throws \Mollie\Api\Exceptions\ApiException - */ - protected function rest_read($id, array $filters) - { - $result = $this->client->performHttpCall( - self::REST_READ, - $this->getResourcePath() . $this->buildQueryString($filters) - ); - - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); - } } diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 61b2a6d24..bf8e07ab6 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -9,27 +9,20 @@ class PaymentCaptureEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "payments_captures"; + protected string $resourcePath = "payments_captures"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Capture + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Capture { return new Capture($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return \Mollie\Api\Resources\CaptureCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): CaptureCollection { return new CaptureCollection($this->client, $count, $_links); } @@ -44,7 +37,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Capture * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Payment $payment, array $data = [], array $filters = []) + public function createFor(Payment $payment, array $data = [], array $filters = []): Capture { return $this->createForId($payment->id, $data, $filters); } @@ -59,7 +52,7 @@ public function createFor(Payment $payment, array $data = [], array $filters = [ * @return Capture * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($paymentId, array $data = [], array $filters = []) + public function createForId(string $paymentId, array $data = [], array $filters = []): Capture { $this->parentId = $paymentId; @@ -74,7 +67,7 @@ public function createForId($paymentId, array $data = [], array $filters = []) * @return Capture * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Payment $payment, $captureId, array $parameters = []) + public function getFor(Payment $payment, string $captureId, array $parameters = []): Capture { return $this->getForId($payment->id, $captureId, $parameters); } @@ -87,7 +80,7 @@ public function getFor(Payment $payment, $captureId, array $parameters = []) * @return \Mollie\Api\Resources\Capture * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId($paymentId, $captureId, array $parameters = []) + public function getForId(string $paymentId, string $captureId, array $parameters = []): Capture { $this->parentId = $paymentId; @@ -98,10 +91,10 @@ public function getForId($paymentId, $captureId, array $parameters = []) * @param Payment $payment * @param array $parameters * - * @return Capture + * @return CaptureCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Payment $payment, array $parameters = []) + public function listFor(Payment $payment, array $parameters = []): CaptureCollection { return $this->listForId($payment->id, $parameters); } @@ -117,8 +110,13 @@ public function listFor(Payment $payment, array $parameters = []) * * @return LazyCollection */ - public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Payment $payment, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); } @@ -126,10 +124,10 @@ public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit * @param string $paymentId * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Capture + * @return CaptureCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($paymentId, array $parameters = []) + public function listForId(string $paymentId, array $parameters = []): CaptureCollection { $this->parentId = $paymentId; @@ -147,8 +145,13 @@ public function listForId($paymentId, array $parameters = []) * * @return LazyCollection */ - public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $paymentId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $paymentId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index 5a232f889..40377fd4c 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -9,27 +9,20 @@ class PaymentChargebackEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "payments_chargebacks"; + protected string $resourcePath = "payments_chargebacks"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Chargeback + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Chargeback { return new Chargeback($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return ChargebackCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection { return new ChargebackCollection($this->client, $count, $_links); } @@ -42,7 +35,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Chargeback * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Payment $payment, $chargebackId, array $parameters = []) + public function getFor(Payment $payment, string $chargebackId, array $parameters = []): Chargeback { return $this->getForId($payment->id, $chargebackId, $parameters); } @@ -55,7 +48,7 @@ public function getFor(Payment $payment, $chargebackId, array $parameters = []) * @return Chargeback * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId($paymentId, $chargebackId, array $parameters = []) + public function getForId(string $paymentId, string $chargebackId, array $parameters = []): Chargeback { $this->parentId = $paymentId; @@ -69,7 +62,7 @@ public function getForId($paymentId, $chargebackId, array $parameters = []) * @return Chargeback * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Payment $payment, array $parameters = []) + public function listFor(Payment $payment, array $parameters = []): ChargebackCollection { return $this->listForId($payment->id, $parameters); } @@ -85,8 +78,13 @@ public function listFor(Payment $payment, array $parameters = []) * * @return LazyCollection */ - public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Payment $payment, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); } @@ -97,7 +95,7 @@ public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Chargeback * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($paymentId, array $parameters = []) + public function listForId(string $paymentId, array $parameters = []): ChargebackCollection { $this->parentId = $paymentId; @@ -115,8 +113,13 @@ public function listForId($paymentId, array $parameters = []) * * @return LazyCollection */ - public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $paymentId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $paymentId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 79b1c6b6e..b47722bf8 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -11,30 +11,22 @@ class PaymentEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "payments"; + protected string $resourcePath = "payments"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'tr_'; + public const string RESOURCE_ID_PREFIX = 'tr_'; /** - * @return Payment + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Payment { return new Payment($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return PaymentCollection + * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection { return new PaymentCollection($this->client, $count, $_links); } @@ -48,7 +40,7 @@ protected function getResourceCollectionObject($count, $_links) * @return Payment * @throws ApiException */ - public function create(array $data = [], array $filters = []) + public function create(array $data = [], array $filters = []): Payment { return $this->rest_create($data, $filters); } @@ -59,12 +51,12 @@ public function create(array $data = [], array $filters = []) * Will throw a ApiException if the payment id is invalid or the resource cannot be found. * * @param string $paymentId - * * @param array $data + * * @return Payment * @throws ApiException */ - public function update($paymentId, array $data = []) + public function update($paymentId, array $data = []): Payment { if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -80,10 +72,11 @@ public function update($paymentId, array $data = []) * * @param string $paymentId * @param array $parameters + * * @return Payment * @throws ApiException */ - public function get($paymentId, array $parameters = []) + public function get($paymentId, array $parameters = []): Payment { if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -99,14 +92,14 @@ public function get($paymentId, array $parameters = []) * Returns with HTTP status No Content (204) if successful. * * @param string $paymentId - * * @param array $data + * * @return Payment * @throws ApiException */ - public function delete($paymentId, array $data = []) + public function delete(string $paymentId, array $data = []): ?Payment { - return $this->rest_delete($paymentId, $data); + return $this->cancel($paymentId, $data); } /** @@ -116,12 +109,12 @@ public function delete($paymentId, array $data = []) * Returns with HTTP status No Content (204) if successful. * * @param string $paymentId - * * @param array $data + * * @return Payment * @throws ApiException */ - public function cancel($paymentId, array $data = []) + public function cancel(string $paymentId, array $data = []): ?Payment { return $this->rest_delete($paymentId, $data); } @@ -136,7 +129,7 @@ public function cancel($paymentId, array $data = []) * @return PaymentCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(string $from = null, int $limit = null, array $parameters = []): PaymentCollection { return $this->rest_list($from, $limit, $parameters); } @@ -167,8 +160,9 @@ public function iterator(?string $from = null, ?int $limit = null, array $parame * * @return Refund * @throws ApiException + * @todo: Refactor */ - public function refund(Payment $payment, $data = []) + public function refund(Payment $payment, $data = []): Refund { $resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds"; diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index f27d09ddf..7970aebaf 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -10,12 +10,9 @@ class PaymentLinkEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "payment-links"; + protected string $resourcePath = "payment-links"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'pl_'; + public const string RESOURCE_ID_PREFIX = 'pl_'; /** * @return PaymentLink @@ -33,7 +30,7 @@ protected function getResourceObject() * * @return PaymentLinkCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new PaymentLinkCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 68524ec8c..18d578d61 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -9,7 +9,7 @@ class PaymentRefundEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "payments_refunds"; + protected string $resourcePath = "payments_refunds"; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -29,7 +29,7 @@ protected function getResourceObject() * * @return RefundCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new RefundCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index fc5c654cb..708af3ba6 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -4,11 +4,10 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Route; -use Mollie\Api\Resources\RouteCollection; -class PaymentRouteEndpoint extends CollectionEndpointAbstract +class PaymentRouteEndpoint extends EndpointAbstract { - protected $resourcePath = "payments_routes"; + protected string $resourcePath = "payments_routes"; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -20,19 +19,6 @@ protected function getResourceObject() return new Route($this->client); } - /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return \Mollie\Api\Resources\RouteCollection - */ - protected function getResourceCollectionObject($count, $_links) - { - return new RouteCollection($this->client, $count, $_links); - } - /** * @param Payment $payment * @param string $routeId diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index fbe038204..acff7b63a 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -8,7 +8,7 @@ class PermissionEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "permissions"; + protected string $resourcePath = "permissions"; /** * Get the object that is used by this API endpoint. Every API endpoint uses one @@ -30,7 +30,7 @@ protected function getResourceObject() * * @return PermissionCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new PermissionCollection($count, $_links); } diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index d430275c9..b4d0d0b4f 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -10,14 +10,11 @@ class ProfileEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "profiles"; + protected string $resourcePath = "profiles"; protected $resourceClass = Profile::class; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'pfl_'; + public const string RESOURCE_ID_PREFIX = 'pfl_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. * @@ -36,7 +33,7 @@ protected function getResourceObject() * * @return ProfileCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new ProfileCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 606d6141c..38744742b 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -9,7 +9,7 @@ class ProfileMethodEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "profiles_methods"; + protected string $resourcePath = "profiles_methods"; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -29,7 +29,7 @@ protected function getResourceObject() * * @return MethodCollection() */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new MethodCollection($count, $_links); } diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index de03c477a..384ff1671 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -9,7 +9,7 @@ class RefundEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "refunds"; + protected string $resourcePath = "refunds"; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -29,7 +29,7 @@ protected function getResourceObject() * * @return RefundCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new RefundCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 3e51443ef..a26e0b6d6 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -10,7 +10,7 @@ class SettlementCaptureEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "settlements_captures"; + protected string $resourcePath = "settlements_captures"; /** * @inheritDoc @@ -20,7 +20,7 @@ protected function getResourceObject() return new Capture($this->client); } - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new CaptureCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 585ccf2c5..dda994cc8 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -10,7 +10,7 @@ class SettlementChargebackEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "settlements_chargebacks"; + protected string $resourcePath = "settlements_chargebacks"; /** * @inheritDoc @@ -23,7 +23,7 @@ protected function getResourceObject() /** * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new ChargebackCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index ed9b10b5f..9c9daff72 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -8,7 +8,7 @@ class SettlementPaymentEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "settlements_payments"; + protected string $resourcePath = "settlements_payments"; /** * @inheritDoc @@ -21,7 +21,7 @@ protected function getResourceObject() /** * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new PaymentCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 4f751da79..81cd16f7e 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -10,12 +10,12 @@ class SettlementRefundEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "settlements_refunds"; + protected string $resourcePath = "settlements_refunds"; /** * @inheritDoc */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new RefundCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 76c7cad84..5c74e4de7 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -9,7 +9,7 @@ class SettlementsEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "settlements"; + protected string $resourcePath = "settlements"; /** * Get the object that is used by this API. Every API uses one type of object. @@ -29,7 +29,7 @@ protected function getResourceObject() * * @return \Mollie\Api\Resources\BaseCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new SettlementCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index c62bcb361..95731820e 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -9,12 +9,9 @@ class ShipmentEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "orders_shipments"; + protected string $resourcePath = "orders_shipments"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'shp_'; + public const string RESOURCE_ID_PREFIX = 'shp_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -35,7 +32,7 @@ protected function getResourceObject() * * @return ShipmentCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new ShipmentCollection($count, $_links); } diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 8e2d8122c..cef5a7cff 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -11,12 +11,9 @@ class SubscriptionEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "customers_subscriptions"; + protected string $resourcePath = "customers_subscriptions"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'sub_'; + public const string RESOURCE_ID_PREFIX = 'sub_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. @@ -36,7 +33,7 @@ protected function getResourceObject() * * @return SubscriptionCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new SubscriptionCollection($this->client, $count, $_links); } diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 4f7a65c62..4742e975d 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -9,12 +9,9 @@ class TerminalEndpoint extends CollectionEndpointAbstract { - protected $resourcePath = "terminals"; + protected string $resourcePath = "terminals"; - /** - * @var string - */ - public const RESOURCE_ID_PREFIX = 'term_'; + public const string RESOURCE_ID_PREFIX = 'term_'; /** * @return Terminal @@ -32,7 +29,7 @@ protected function getResourceObject() * * @return TerminalCollection */ - protected function getResourceCollectionObject($count, $_links) + protected function getResourceCollectionObject(int $count, object $_links) { return new TerminalCollection($this->client, $count, $_links); } diff --git a/src/Resources/OrganizationCollection.php b/src/Resources/OrganizationCollection.php deleted file mode 100644 index 1b2add379..000000000 --- a/src/Resources/OrganizationCollection.php +++ /dev/null @@ -1,22 +0,0 @@ -client); - } -} diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index bd418e6c2..8951dc57d 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -12,10 +12,9 @@ class ResourceFactory * * @param object $apiResult * @param BaseResource $resource - * - * @return mixed + * @return BaseResource */ - public static function createFromApiResult($apiResult, BaseResource $resource) + public static function createFromApiResult(object $apiResult, BaseResource $resource): BaseResource { foreach ($apiResult as $property => $value) { $resource->{$property} = $value; @@ -30,15 +29,15 @@ public static function createFromApiResult($apiResult, BaseResource $resource) * @param array $data * @param null $_links * @param string $resourceCollectionClass - * @return mixed + * @return BaseCollection */ public static function createBaseResourceCollection( MollieApiClient $client, - $resourceClass, - $data, - $_links = null, - $resourceCollectionClass = null - ) { + string $resourceClass, + array $data, + object $_links = null, + string $resourceCollectionClass = null + ): BaseCollection { $resourceCollectionClass = $resourceCollectionClass ?: $resourceClass . 'Collection'; $data = $data ?: []; @@ -56,17 +55,17 @@ public static function createBaseResourceCollection( * @param string $resourceClass * @param null $_links * @param null $resourceCollectionClass - * @return mixed + * @return CursorCollection */ public static function createCursorResourceCollection( - $client, + MollieApiClient $client, array $input, - $resourceClass, - $_links = null, - $resourceCollectionClass = null - ) { + string $resourceClass, + object $_links = null, + string $resourceCollectionClass = null + ): CursorCollection { if (null === $resourceCollectionClass) { - $resourceCollectionClass = $resourceClass.'Collection'; + $resourceCollectionClass = $resourceClass . 'Collection'; } $data = new $resourceCollectionClass($client, count($input), $_links); diff --git a/src/Resources/RouteCollection.php b/src/Resources/RouteCollection.php deleted file mode 100644 index 34e797366..000000000 --- a/src/Resources/RouteCollection.php +++ /dev/null @@ -1,22 +0,0 @@ -client); - } -} diff --git a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php index b789a74e1..401dbca63 100644 --- a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php @@ -2,7 +2,6 @@ namespace Tests\Mollie\API\HttpAdapter; -use Eloquent\Liberator\Liberator; use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\Request; @@ -32,15 +31,15 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() { $guzzleClient = $this->createMock(Client::class); $guzzleClient - ->expects($this->once()) - ->method('send') - ->with($this->isInstanceOf(Request::class)) - ->willThrowException( - new ConnectException( - 'Mock exception', - new Request('POST', 'https://api.mollie.com') - ) - ); + ->expects($this->once()) + ->method('send') + ->with($this->isInstanceOf(Request::class)) + ->willThrowException( + new ConnectException( + 'Mock exception', + new Request('POST', 'https://api.mollie.com') + ) + ); $adapter = new Guzzle6And7MollieHttpAdapter($guzzleClient); $adapter->enableDebugging(); @@ -54,7 +53,7 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - $exception = Liberator::liberate($e); + $exception = invade($e); $this->assertInstanceOf(RequestInterface::class, $exception->request); } } @@ -86,7 +85,7 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - $exception = Liberator::liberate($e); + $exception = invade($e); $this->assertNull($exception->request); } } diff --git a/tests/Mollie/API/MollieApiClientTest.php b/tests/Mollie/API/MollieApiClientTest.php index bd1103a42..abbdde2ca 100644 --- a/tests/Mollie/API/MollieApiClientTest.php +++ b/tests/Mollie/API/MollieApiClientTest.php @@ -2,7 +2,6 @@ namespace Tests\Mollie\Api; -use Eloquent\Liberator\Liberator; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Psr7\Response; @@ -125,7 +124,7 @@ public function testCanBeSerializedAndUnserialized() $this->assertStringNotContainsString('test_foobarfoobarfoobarfoobarfoobar', $serialized, "API key should not be in serialized data or it will end up in caches."); /** @var MollieApiClient $client_copy */ - $client_copy = Liberator::liberate(unserialize($serialized)); + $client_copy = invade(unserialize($serialized)); $this->assertEmpty($client_copy->apiKey, "API key should not have been remembered"); $this->assertInstanceOf(Guzzle6And7MollieHttpAdapter::class, $client_copy->httpClient, "A Guzzle client should have been set."); From 6c9102e54e73197d43134adaa4fa4a43b2f51056 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 3 Jan 2024 16:12:06 +0100 Subject: [PATCH 002/131] wip --- src/Endpoints/ClientLinkEndpoint.php | 2 +- src/Endpoints/CustomerEndpoint.php | 2 +- src/Endpoints/OrderEndpoint.php | 2 +- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/OrderPaymentEndpoint.php | 2 +- src/Endpoints/PaymentEndpoint.php | 2 +- src/Endpoints/PaymentLinkEndpoint.php | 2 +- src/Endpoints/ProfileEndpoint.php | 2 +- src/Endpoints/ShipmentEndpoint.php | 2 +- src/Endpoints/SubscriptionEndpoint.php | 2 +- src/Endpoints/TerminalEndpoint.php | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 377158b29..d711019df 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -9,7 +9,7 @@ class ClientLinkEndpoint extends EndpointAbstract { protected string $resourcePath = "client-links"; - public const string RESOURCE_ID_PREFIX = 'cl_'; + public const RESOURCE_ID_PREFIX = 'cl_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 07dcc2fc9..5e12b5390 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -11,7 +11,7 @@ class CustomerEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "customers"; - public const string RESOURCE_ID_PREFIX = 'cst_'; + public const RESOURCE_ID_PREFIX = 'cst_'; /** * @inheritDoc diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index fc9645bcd..db462b49c 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -11,7 +11,7 @@ class OrderEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "orders"; - public const string RESOURCE_ID_PREFIX = 'ord_'; + public const RESOURCE_ID_PREFIX = 'ord_'; /** * @inheritDoc diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 5dbc95c3c..a58a4cf0d 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -12,7 +12,7 @@ class OrderLineEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "orders_lines"; - public const string RESOURCE_ID_PREFIX = 'odl_'; + public const RESOURCE_ID_PREFIX = 'odl_'; /** * @inheritDoc diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index 6b4981e12..6bdd536c2 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -10,7 +10,7 @@ class OrderPaymentEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "orders_payments"; - public const string RESOURCE_ID_PREFIX = 'tr_'; + public const RESOURCE_ID_PREFIX = 'tr_'; /** * @inheritDoc diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index b47722bf8..80fbcb6b5 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -13,7 +13,7 @@ class PaymentEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "payments"; - public const string RESOURCE_ID_PREFIX = 'tr_'; + public const RESOURCE_ID_PREFIX = 'tr_'; /** * @inheritDoc diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index 7970aebaf..f35cf8d40 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -12,7 +12,7 @@ class PaymentLinkEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "payment-links"; - public const string RESOURCE_ID_PREFIX = 'pl_'; + public const RESOURCE_ID_PREFIX = 'pl_'; /** * @return PaymentLink diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index b4d0d0b4f..d42354743 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -14,7 +14,7 @@ class ProfileEndpoint extends CollectionEndpointAbstract protected $resourceClass = Profile::class; - public const string RESOURCE_ID_PREFIX = 'pfl_'; + public const RESOURCE_ID_PREFIX = 'pfl_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. * diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index 95731820e..6b8213de4 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -11,7 +11,7 @@ class ShipmentEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "orders_shipments"; - public const string RESOURCE_ID_PREFIX = 'shp_'; + public const RESOURCE_ID_PREFIX = 'shp_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index cef5a7cff..400410148 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -13,7 +13,7 @@ class SubscriptionEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "customers_subscriptions"; - public const string RESOURCE_ID_PREFIX = 'sub_'; + public const RESOURCE_ID_PREFIX = 'sub_'; /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 4742e975d..8b4399302 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -11,7 +11,7 @@ class TerminalEndpoint extends CollectionEndpointAbstract { protected string $resourcePath = "terminals"; - public const string RESOURCE_ID_PREFIX = 'term_'; + public const RESOURCE_ID_PREFIX = 'term_'; /** * @return Terminal From 1da742e7558f5cd581e6cf39b858025645380494 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 5 Jan 2024 10:50:47 +0100 Subject: [PATCH 003/131] add type declarations to all endpoints --- src/Endpoints/BalanceEndpoint.php | 2 +- src/Endpoints/BalanceReportEndpoint.php | 2 +- src/Endpoints/BalanceTransactionEndpoint.php | 2 +- src/Endpoints/BaseEndpoint.php | 91 ++++++++++++++++++ src/Endpoints/ChargebackEndpoint.php | 2 +- src/Endpoints/ClientEndpoint.php | 2 +- src/Endpoints/ClientLinkEndpoint.php | 2 +- src/Endpoints/CollectionEndpointAbstract.php | 39 +++++--- src/Endpoints/CustomerEndpoint.php | 2 +- src/Endpoints/CustomerPaymentsEndpoint.php | 2 +- src/Endpoints/InvoiceEndpoint.php | 2 +- src/Endpoints/MandateEndpoint.php | 6 +- src/Endpoints/MethodEndpoint.php | 2 +- src/Endpoints/OnboardingEndpoint.php | 2 +- src/Endpoints/OrderEndpoint.php | 2 +- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/OrderPaymentEndpoint.php | 2 +- src/Endpoints/OrderRefundEndpoint.php | 2 +- src/Endpoints/OrganizationEndpoint.php | 2 +- src/Endpoints/OrganizationPartnerEndpoint.php | 2 +- src/Endpoints/PaymentCaptureEndpoint.php | 2 +- src/Endpoints/PaymentChargebackEndpoint.php | 2 +- src/Endpoints/PaymentEndpoint.php | 16 +--- src/Endpoints/PaymentLinkEndpoint.php | 22 ++--- src/Endpoints/PaymentRefundEndpoint.php | 51 +++++----- src/Endpoints/PaymentRouteEndpoint.php | 18 ++-- src/Endpoints/PermissionEndpoint.php | 23 ++--- src/Endpoints/ProfileEndpoint.php | 38 ++++---- src/Endpoints/ProfileMethodEndpoint.php | 58 ++++++------ src/Endpoints/RefundEndpoint.php | 27 +++--- ...{EndpointAbstract.php => RestEndpoint.php} | 92 +------------------ src/Endpoints/SettlementCaptureEndpoint.php | 22 +++-- .../SettlementChargebackEndpoint.php | 19 ++-- src/Endpoints/SettlementPaymentEndpoint.php | 19 ++-- src/Endpoints/SettlementRefundEndpoint.php | 23 +++-- src/Endpoints/SettlementsEndpoint.php | 26 ++---- src/Endpoints/ShipmentEndpoint.php | 38 +++----- src/Endpoints/SubscriptionEndpoint.php | 79 ++++++++-------- src/Endpoints/TerminalEndpoint.php | 30 +++--- src/Endpoints/WalletEndpoint.php | 16 +--- 40 files changed, 383 insertions(+), 408 deletions(-) create mode 100644 src/Endpoints/BaseEndpoint.php rename src/Endpoints/{EndpointAbstract.php => RestEndpoint.php} (58%) diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index 31e089693..0c701304b 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\LazyCollection; -class BalanceEndpoint extends CollectionEndpointAbstract +class BalanceEndpoint extends CollectionRestEndpoint { const string RESOURCE_ID_PREFIX = 'bal_'; diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index 5d0861e0b..c3465af8c 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\BalanceReport; use Mollie\Api\Resources\ResourceFactory; -class BalanceReportEndpoint extends EndpointAbstract +class BalanceReportEndpoint extends RestEndpoint { protected string $resourcePath = "balances_report"; diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 329c62476..28b94c79d 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -9,7 +9,7 @@ use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Resources\LazyCollection; -class BalanceTransactionEndpoint extends CollectionEndpointAbstract +class BalanceTransactionEndpoint extends CollectionRestEndpoint { const string RESOURCE_ID_PREFIX = 'baltr_'; diff --git a/src/Endpoints/BaseEndpoint.php b/src/Endpoints/BaseEndpoint.php new file mode 100644 index 000000000..8475510f2 --- /dev/null +++ b/src/Endpoints/BaseEndpoint.php @@ -0,0 +1,91 @@ +client = $api; + } + + /** + * @param array $filters + * @return string + */ + protected function buildQueryString(array $filters): string + { + if (empty($filters)) { + return ""; + } + + foreach ($filters as $key => $value) { + if ($value === true) { + $filters[$key] = "true"; + } + + if ($value === false) { + $filters[$key] = "false"; + } + } + + return "?" . http_build_query($filters, "", "&"); + } + + /** + * @return string + * @throws ApiException + */ + public function getResourcePath(): string + { + if (strpos($this->resourcePath, "_") !== false) { + [$parentResource, $childResource] = explode("_", $this->resourcePath, 2); + + if (empty($this->parentId)) { + throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); + } + + return "$parentResource/{$this->parentId}/$childResource"; + } + + return $this->resourcePath; + } + + protected function getPathToSingleResource(string $id): string + { + if ($this instanceof SingleResourceEndpoint) { + return $this->getResourcePath(); + } + + return "{$this->getResourcePath()}/{$id}"; + } + + /** + * @param array $body + * @return null|string + */ + protected function parseRequestBody(array $body): ?string + { + if (empty($body)) { + return null; + } + + return @json_encode($body); + } +} diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index f9711a1b0..d3468880f 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; -class ChargebackEndpoint extends CollectionEndpointAbstract +class ChargebackEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "chargebacks"; diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index e20107a25..38631fc41 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\ClientCollection; use Mollie\Api\Resources\LazyCollection; -class ClientEndpoint extends CollectionEndpointAbstract +class ClientEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "clients"; diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index d711019df..6c68726fa 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -5,7 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\ClientLink; -class ClientLinkEndpoint extends EndpointAbstract +class ClientLinkEndpoint extends RestEndpoint { protected string $resourcePath = "client-links"; diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index 2de0fe997..1a7c8439d 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceFactory; -abstract class CollectionEndpointAbstract extends EndpointAbstract +abstract class CollectionRestEndpoint extends RestEndpoint { /** * Get a collection of objects from the REST API. @@ -22,20 +22,16 @@ abstract class CollectionEndpointAbstract extends EndpointAbstract */ protected function rest_list(?string $from = null, ?int $limit = null, array $filters = []): BaseCollection { - $filters = array_merge(["from" => $from, "limit" => $limit], $filters); + $apiPath = $this->getResourcePath() . $this->buildQueryString( + $this->getMergedFilters($filters, $from, $limit) + ); - $apiPath = $this->getResourcePath() . $this->buildQueryString($filters); + $result = $this->client->performHttpCall( + self::REST_LIST, + $apiPath + ); - $result = $this->client->performHttpCall(self::REST_LIST, $apiPath); - - /** @var BaseCollection $collection */ - $collection = $this->getResourceCollectionObject($result->count, $result->_links); - - foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { - $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject()); - } - - return $collection; + return $this->createCollectionFromResult($result); } /** @@ -59,6 +55,23 @@ protected function rest_iterator(?string $from = null, ?int $limit = null, array return $page->getAutoIterator($iterateBackwards); } + protected function getMergedFilters(array $filters = [], ?string $from = null, ?int $limit = null): array + { + return array_merge(["from" => $from, "limit" => $limit], $filters); + } + + protected function createCollectionFromResult(object $result): BaseCollection + { + /** @var BaseCollection $collection */ + $collection = $this->getResourceCollectionObject($result->count, $result->_links); + + foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { + $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject()); + } + + return $collection; + } + /** * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. * diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 5e12b5390..ed18d85e6 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Resources\LazyCollection; -class CustomerEndpoint extends CollectionEndpointAbstract +class CustomerEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "customers"; diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index e54a9c811..d372af0eb 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class CustomerPaymentsEndpoint extends CollectionEndpointAbstract +class CustomerPaymentsEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "customers_payments"; diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index d752cbf81..78d7049c2 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\InvoiceCollection; use Mollie\Api\Resources\LazyCollection; -class InvoiceEndpoint extends CollectionEndpointAbstract +class InvoiceEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "invoices"; diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index 5f8afdbfd..e717c91d6 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -class MandateEndpoint extends CollectionEndpointAbstract +class MandateEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "customers_mandates"; @@ -92,7 +92,7 @@ public function getForId(string $customerId, $mandateId, array $parameters = []) * @return MandateCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = []): MandateCollection + public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection { return $this->listForId($customer->id, $from, $limit, $parameters); } @@ -127,7 +127,7 @@ public function iteratorFor( * @return MandateCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId(string $customerId, string $from = null, int $limit = null, array $parameters = []): MandateCollection + public function listForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection { $this->parentId = $customerId; diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 29691bf56..5df5dda8d 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Resources\ResourceFactory; -class MethodEndpoint extends CollectionEndpointAbstract +class MethodEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "methods"; diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 4617b2555..26d6e394f 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Onboarding; -class OnboardingEndpoint extends EndpointAbstract implements SingleResourceEndpoint +class OnboardingEndpoint extends RestEndpoint implements SingleResourceEndpoint { protected string $resourcePath = "onboarding/me"; diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index db462b49c..2308fc2e5 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Order; use Mollie\Api\Resources\OrderCollection; -class OrderEndpoint extends CollectionEndpointAbstract +class OrderEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "orders"; diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index a58a4cf0d..6fd243eeb 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\OrderLineCollection; use Mollie\Api\Resources\ResourceFactory; -class OrderLineEndpoint extends CollectionEndpointAbstract +class OrderLineEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "orders_lines"; diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index 6bdd536c2..a1d558ab5 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class OrderPaymentEndpoint extends CollectionEndpointAbstract +class OrderPaymentEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "orders_payments"; diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index 078b18dc7..d172d656c 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class OrderRefundEndpoint extends CollectionEndpointAbstract +class OrderRefundEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "orders_refunds"; diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index ed0c60a5e..9403dcb00 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -5,7 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Organization; -class OrganizationEndpoint extends EndpointAbstract +class OrganizationEndpoint extends RestEndpoint { protected string $resourcePath = "organizations"; diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index 118972943..a82e86ea2 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Partner; -class OrganizationPartnerEndpoint extends EndpointAbstract implements SingleResourceEndpoint +class OrganizationPartnerEndpoint extends RestEndpoint implements SingleResourceEndpoint { protected string $resourcePath = "organizations/me/partner"; diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index bf8e07ab6..f3acfd991 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; -class PaymentCaptureEndpoint extends CollectionEndpointAbstract +class PaymentCaptureEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "payments_captures"; diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index 40377fd4c..96c52331d 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; -class PaymentChargebackEndpoint extends CollectionEndpointAbstract +class PaymentChargebackEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "payments_chargebacks"; diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 80fbcb6b5..90833208e 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -7,9 +7,8 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -use Mollie\Api\Resources\ResourceFactory; -class PaymentEndpoint extends CollectionEndpointAbstract +class PaymentEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "payments"; @@ -160,19 +159,10 @@ public function iterator(?string $from = null, ?int $limit = null, array $parame * * @return Refund * @throws ApiException - * @todo: Refactor */ public function refund(Payment $payment, $data = []): Refund { - $resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds"; - - $body = null; - if (($data === null ? 0 : count($data)) > 0) { - $body = json_encode($data); - } - - $result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body); - - return ResourceFactory::createFromApiResult($result, new Refund($this->client)); + return (new PaymentRefundEndpoint($this->client)) + ->createFor($payment, $data); } } diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index f35cf8d40..f6af37b09 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -4,33 +4,27 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\LazyCollection; -use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; -class PaymentLinkEndpoint extends CollectionEndpointAbstract +class PaymentLinkEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "payment-links"; public const RESOURCE_ID_PREFIX = 'pl_'; /** - * @return PaymentLink + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): PaymentLink { return new PaymentLink($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return PaymentLinkCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): PaymentLinkCollection { return new PaymentLinkCollection($this->client, $count, $_links); } @@ -44,7 +38,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return PaymentLink * @throws ApiException */ - public function create(array $data = [], array $filters = []) + public function create(array $data = [], array $filters = []): PaymentLink { return $this->rest_create($data, $filters); } @@ -59,7 +53,7 @@ public function create(array $data = [], array $filters = []) * @return PaymentLink * @throws ApiException */ - public function get($paymentLinkId, array $parameters = []) + public function get(string $paymentLinkId, array $parameters = []): PaymentLink { if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid payment link ID: '{$paymentLinkId}'. A payment link ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -78,7 +72,7 @@ public function get($paymentLinkId, array $parameters = []) * @return PaymentLinkCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 18d578d61..81dafb81e 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -7,29 +7,22 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class PaymentRefundEndpoint extends CollectionEndpointAbstract +class PaymentRefundEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "payments_refunds"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Refund + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Refund { return new Refund($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return RefundCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): RefundCollection { return new RefundCollection($this->client, $count, $_links); } @@ -42,7 +35,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Payment $payment, $refundId, array $parameters = []) + public function getFor(Payment $payment, $refundId, array $parameters = []): Refund { return $this->getForId($payment->id, $refundId, $parameters); } @@ -55,7 +48,7 @@ public function getFor(Payment $payment, $refundId, array $parameters = []) * @return \Mollie\Api\Resources\Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId($paymentId, $refundId, array $parameters = []) + public function getForId(string $paymentId, $refundId, array $parameters = []): Refund { $this->parentId = $paymentId; @@ -66,10 +59,10 @@ public function getForId($paymentId, $refundId, array $parameters = []) * @param Payment $payment * @param array $parameters * - * @return Refund + * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Payment $payment, array $parameters = []) + public function listFor(Payment $payment, array $parameters = []): RefundCollection { return $this->listForId($payment->id, $parameters); } @@ -85,8 +78,13 @@ public function listFor(Payment $payment, array $parameters = []) * * @return LazyCollection */ - public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Payment $payment, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); } @@ -94,10 +92,10 @@ public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit * @param string $paymentId * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Refund + * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($paymentId, array $parameters = []) + public function listForId(string $paymentId, array $parameters = []): RefundCollection { $this->parentId = $paymentId; @@ -115,8 +113,13 @@ public function listForId($paymentId, array $parameters = []) * * @return LazyCollection */ - public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $paymentId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $paymentId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); @@ -133,7 +136,7 @@ public function iteratorForId(string $paymentId, ?string $from = null, ?int $lim * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Payment $payment, array $data, array $filters = []) + public function createFor(Payment $payment, array $data, array $filters = []): Refund { return $this->createForId($payment->id, $data, $filters); } @@ -148,7 +151,7 @@ public function createFor(Payment $payment, array $data, array $filters = []) * @return \Mollie\Api\Resources\Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId(string $paymentId, array $data, array $filters = []) + public function createForId(string $paymentId, array $data, array $filters = []): Refund { $this->parentId = $paymentId; diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index 708af3ba6..ced43f467 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -5,16 +5,14 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Route; -class PaymentRouteEndpoint extends EndpointAbstract +class PaymentRouteEndpoint extends RestEndpoint { protected string $resourcePath = "payments_routes"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return \Mollie\Api\Resources\Route + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Route { return new Route($this->client); } @@ -28,7 +26,7 @@ protected function getResourceObject() * @return Route * @throws \Mollie\Api\Exceptions\ApiException */ - public function updateReleaseDateFor(Payment $payment, $routeId, $releaseDate) + public function updateReleaseDateFor(Payment $payment, $routeId, $releaseDate): Route { return $this->updateReleaseDateForPaymentId($payment->id, $routeId, $releaseDate); } @@ -42,15 +40,13 @@ public function updateReleaseDateFor(Payment $payment, $routeId, $releaseDate) * @return \Mollie\Api\Resources\Route * @throws \Mollie\Api\Exceptions\ApiException */ - public function updateReleaseDateForPaymentId($paymentId, $routeId, $releaseDate, $testmode = false) + public function updateReleaseDateForPaymentId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): Route { $this->parentId = $paymentId; - $params = [ + return parent::rest_update($routeId, [ 'releaseDate' => $releaseDate, 'testmode' => $testmode, - ]; - - return parent::rest_update($routeId, $params); + ]); } } diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index acff7b63a..26abc99e1 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -6,31 +6,22 @@ use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; -class PermissionEndpoint extends CollectionEndpointAbstract +class PermissionEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "permissions"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one - * type of object. - * - * @return Permission + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Permission { return new Permission($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return PermissionCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): PermissionCollection { return new PermissionCollection($count, $_links); } @@ -45,7 +36,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return Permission * @throws ApiException */ - public function get($permissionId, array $parameters = []) + public function get(string $permissionId, array $parameters = []): Permission { return $this->rest_read($permissionId, $parameters); } @@ -58,7 +49,7 @@ public function get($permissionId, array $parameters = []) * @return PermissionCollection * @throws ApiException */ - public function all(array $parameters = []) + public function all(array $parameters = []): PermissionCollection { return parent::rest_list(null, null, $parameters); } diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index d42354743..61f8d00f0 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; -class ProfileEndpoint extends CollectionEndpointAbstract +class ProfileEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "profiles"; @@ -16,24 +16,17 @@ class ProfileEndpoint extends CollectionEndpointAbstract public const RESOURCE_ID_PREFIX = 'pfl_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Profile + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Profile { return new $this->resourceClass($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return ProfileCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): ProfileCollection { return new ProfileCollection($this->client, $count, $_links); } @@ -47,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return Profile * @throws ApiException */ - public function create(array $data = [], array $filters = []) + public function create(array $data = [], array $filters = []): Profile { return $this->rest_create($data, $filters); } @@ -63,7 +56,7 @@ public function create(array $data = [], array $filters = []) * @return Profile * @throws ApiException */ - public function get($profileId, array $parameters = []) + public function get($profileId, array $parameters = []): Profile { if ($profileId === 'me') { return $this->getCurrent($parameters); @@ -78,12 +71,11 @@ public function get($profileId, array $parameters = []) * Will throw an ApiException if the profile id is invalid or the resource cannot be found. * * @param string $profileId - * * @param array $data * @return Profile * @throws ApiException */ - public function update($profileId, array $data = []) + public function update(string $profileId, array $data = []): Profile { if (empty($profileId) || strpos($profileId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid profile id: '{$profileId}'. An profile id should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -100,7 +92,7 @@ public function update($profileId, array $data = []) * @return CurrentProfile * @throws ApiException */ - public function getCurrent(array $parameters = []) + public function getCurrent(array $parameters = []): CurrentProfile { $this->resourceClass = CurrentProfile::class; @@ -119,7 +111,7 @@ public function getCurrent(array $parameters = []) * @return Profile * @throws ApiException */ - public function delete($profileId, array $data = []) + public function delete($profileId, array $data = []): ?Profile { return $this->rest_delete($profileId, $data); } @@ -134,7 +126,7 @@ public function delete($profileId, array $data = []) * @return ProfileCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection { return $this->rest_list($from, $limit, $parameters); } @@ -149,8 +141,12 @@ public function page($from = null, $limit = null, array $parameters = []) * * @return LazyCollection */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iterator( + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 38744742b..688259c0c 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -7,29 +7,22 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ResourceFactory; -class ProfileMethodEndpoint extends CollectionEndpointAbstract +class ProfileMethodEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "profiles_methods"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Method + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Method { return new Method($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return MethodCollection() + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): MethodCollection { return new MethodCollection($count, $_links); } @@ -40,22 +33,21 @@ protected function getResourceCollectionObject(int $count, object $_links) * @param string $profileId * @param string $methodId * @param array $data - * @return \Mollie\Api\Resources\Method + * + * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($profileId, $methodId, array $data = []) + public function createForId(string $profileId, string $methodId, array $data = []): Method { $this->parentId = $profileId; - $resource = $this->getResourcePath() . '/' . urlencode($methodId); - - $body = null; - if (count($data) > 0) { - $body = json_encode($data); - } - $result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body); + $result = $this->client->performHttpCall( + self::REST_CREATE, + $this->getResourcePath() . '/' . urlencode($methodId), + $this->parseRequestBody($data) + ); - return ResourceFactory::createFromApiResult($result, new Method($this->client)); + return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); } /** @@ -64,10 +56,11 @@ public function createForId($profileId, $methodId, array $data = []) * @param Profile $profile * @param string $methodId * @param array $data + * * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor($profile, $methodId, array $data = []) + public function createFor(Profile $profile, string $methodId, array $data = []): Method { return $this->createForId($profile->id, $methodId, $data); } @@ -77,10 +70,11 @@ public function createFor($profile, $methodId, array $data = []) * * @param string $methodId * @param array $data - * @return \Mollie\Api\Resources\Method + * + * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForCurrentProfile($methodId, array $data = []) + public function createForCurrentProfile(string $methodId, array $data = []): Method { return $this->createForId('me', $methodId, $data); } @@ -91,10 +85,11 @@ public function createForCurrentProfile($methodId, array $data = []) * @param string $profileId * @param string $methodId * @param array $data - * @return mixed + * + * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function deleteForId($profileId, $methodId, array $data = []) + public function deleteForId($profileId, $methodId, array $data = []): ?Method { $this->parentId = $profileId; @@ -107,9 +102,11 @@ public function deleteForId($profileId, $methodId, array $data = []) * @param Profile $profile * @param string $methodId * @param array $data + * + * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function deleteFor($profile, $methodId, array $data = []) + public function deleteFor($profile, $methodId, array $data = []): ?Method { return $this->deleteForId($profile->id, $methodId, $data); } @@ -119,10 +116,11 @@ public function deleteFor($profile, $methodId, array $data = []) * * @param string $methodId * @param array $data - * @return \Mollie\Api\Resources\Method + * + * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ - public function deleteForCurrentProfile($methodId, array $data) + public function deleteForCurrentProfile($methodId, array $data): ?Method { return $this->deleteForId('me', $methodId, $data); } diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 384ff1671..75f49d00b 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -7,29 +7,22 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class RefundEndpoint extends CollectionEndpointAbstract +class RefundEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "refunds"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Refund + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Refund { return new Refund($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return RefundCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): RefundCollection { return new RefundCollection($this->client, $count, $_links); } @@ -44,7 +37,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return RefundCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection { return $this->rest_list($from, $limit, $parameters); } @@ -59,8 +52,12 @@ public function page($from = null, $limit = null, array $parameters = []) * * @return LazyCollection */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iterator( + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/EndpointAbstract.php b/src/Endpoints/RestEndpoint.php similarity index 58% rename from src/Endpoints/EndpointAbstract.php rename to src/Endpoints/RestEndpoint.php index 0d7af6d60..180841238 100644 --- a/src/Endpoints/EndpointAbstract.php +++ b/src/Endpoints/RestEndpoint.php @@ -4,52 +4,11 @@ use Mollie\Api\Contracts\SingleResourceEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\ResourceFactory; -abstract class EndpointAbstract +abstract class RestEndpoint extends BaseEndpoint { - public const REST_CREATE = MollieApiClient::HTTP_POST; - public const REST_UPDATE = MollieApiClient::HTTP_PATCH; - public const REST_READ = MollieApiClient::HTTP_GET; - public const REST_LIST = MollieApiClient::HTTP_GET; - public const REST_DELETE = MollieApiClient::HTTP_DELETE; - - protected MollieApiClient $client; - - protected string $resourcePath; - - protected ?string $parentId; - - public function __construct(MollieApiClient $api) - { - $this->client = $api; - } - - /** - * @param array $filters - * @return string - */ - protected function buildQueryString(array $filters): string - { - if (empty($filters)) { - return ""; - } - - foreach ($filters as $key => $value) { - if ($value === true) { - $filters[$key] = "true"; - } - - if ($value === false) { - $filters[$key] = "false"; - } - } - - return "?" . http_build_query($filters, "", "&"); - } - /** * @param array $body * @param array $filters @@ -154,53 +113,4 @@ protected function rest_delete(string $id, array $body = []): ?BaseResource * @return BaseResource */ abstract protected function getResourceObject(): BaseResource; - - /** - * @param string $resourcePath - */ - public function setResourcePath($resourcePath) - { - $this->resourcePath = strtolower($resourcePath); - } - - /** - * @return string - * @throws ApiException - */ - public function getResourcePath(): string - { - if (strpos($this->resourcePath, "_") !== false) { - [$parentResource, $childResource] = explode("_", $this->resourcePath, 2); - - if (empty($this->parentId)) { - throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); - } - - return "$parentResource/{$this->parentId}/$childResource"; - } - - return $this->resourcePath; - } - - protected function getPathToSingleResource(string $id): string - { - if ($this instanceof SingleResourceEndpoint) { - return $this->getResourcePath(); - } - - return "{$this->getResourcePath()}/{$id}"; - } - - /** - * @param array $body - * @return null|string - */ - protected function parseRequestBody(array $body): ?string - { - if (empty($body)) { - return null; - } - - return @json_encode($body); - } } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index a26e0b6d6..520f0deb9 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -8,19 +8,22 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; -class SettlementCaptureEndpoint extends CollectionEndpointAbstract +class SettlementCaptureEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "settlements_captures"; /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Capture { return new Capture($this->client); } - protected function getResourceCollectionObject(int $count, object $_links) + /** + * @inheritDoc + */ + protected function getResourceCollectionObject(int $count, object $_links): CaptureCollection { return new CaptureCollection($this->client, $count, $_links); } @@ -33,10 +36,10 @@ protected function getResourceCollectionObject(int $count, object $_links) * @param int|null $limit * @param array $parameters * - * @return mixed + * @return CaptureCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = []) + public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = []): CaptureCollection { $this->parentId = $settlementId; @@ -54,8 +57,13 @@ public function pageForId(string $settlementId, string $from = null, int $limit * * @return LazyCollection */ - public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $settlementId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index dda994cc8..ac6265e6d 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -8,14 +8,14 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; -class SettlementChargebackEndpoint extends CollectionEndpointAbstract +class SettlementChargebackEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "settlements_chargebacks"; /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Chargeback { return new Chargeback($this->client); } @@ -23,7 +23,7 @@ protected function getResourceObject() /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection { return new ChargebackCollection($this->client, $count, $_links); } @@ -36,10 +36,10 @@ protected function getResourceCollectionObject(int $count, object $_links) * @param int|null $limit * @param array $parameters * - * @return mixed + * @return ChargebackCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = []) + public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection { $this->parentId = $settlementId; @@ -57,8 +57,13 @@ public function pageForId(string $settlementId, string $from = null, int $limit * * @return LazyCollection */ - public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $settlementId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index 9c9daff72..fb27ed725 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -6,14 +6,14 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class SettlementPaymentEndpoint extends CollectionEndpointAbstract +class SettlementPaymentEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "settlements_payments"; /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Payment { return new Payment($this->client); } @@ -21,7 +21,7 @@ protected function getResourceObject() /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection { return new PaymentCollection($this->client, $count, $_links); } @@ -34,10 +34,10 @@ protected function getResourceCollectionObject(int $count, object $_links) * @param int $limit * @param array $parameters * - * @return mixed + * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId($settlementId, $from = null, $limit = null, array $parameters = []) + public function pageForId($settlementId, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection { $this->parentId = $settlementId; @@ -55,8 +55,13 @@ public function pageForId($settlementId, $from = null, $limit = null, array $par * * @return LazyCollection */ - public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $settlementId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 81cd16f7e..7849c640e 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -8,24 +8,24 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class SettlementRefundEndpoint extends CollectionEndpointAbstract +class SettlementRefundEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "settlements_refunds"; /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceObject(): Refund { - return new RefundCollection($this->client, $count, $_links); + return new Refund($this->client); } /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceCollectionObject(int $count, object $_links): RefundCollection { - return new Refund($this->client); + return new RefundCollection($this->client, $count, $_links); } /** @@ -36,10 +36,10 @@ protected function getResourceObject() * @param int|null $limit * @param array $parameters * - * @return mixed + * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = []) + public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = []): RefundCollection { $this->parentId = $settlementId; @@ -57,8 +57,13 @@ public function pageForId(string $settlementId, string $from = null, int $limit * * @return LazyCollection */ - public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $settlementId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 5c74e4de7..ec7f6c8ce 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -7,29 +7,22 @@ use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; -class SettlementsEndpoint extends CollectionEndpointAbstract +class SettlementsEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "settlements"; /** - * Get the object that is used by this API. Every API uses one type of object. - * - * @return \Mollie\Api\Resources\BaseResource + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Settlement { return new Settlement($this->client); } /** - * Get the collection object that is used by this API. Every API uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return \Mollie\Api\Resources\BaseCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): SettlementCollection { return new SettlementCollection($this->client, $count, $_links); } @@ -41,10 +34,11 @@ protected function getResourceCollectionObject(int $count, object $_links) * * @param string $settlementId * @param array $parameters + * * @return Settlement * @throws ApiException */ - public function get($settlementId, array $parameters = []) + public function get(string $settlementId, array $parameters = []): Settlement { return parent::rest_read($settlementId, $parameters); } @@ -55,7 +49,7 @@ public function get($settlementId, array $parameters = []) * @return Settlement * @throws ApiException */ - public function next() + public function next(): Settlement { return parent::rest_read("next", []); } @@ -66,7 +60,7 @@ public function next() * @return Settlement * @throws ApiException */ - public function open() + public function open(): Settlement { return parent::rest_read("open", []); } @@ -81,7 +75,7 @@ public function open() * @return SettlementCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection { return $this->rest_list($from, $limit, $parameters); } diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index 6b8213de4..9ada1b9ad 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -7,32 +7,24 @@ use Mollie\Api\Resources\Shipment; use Mollie\Api\Resources\ShipmentCollection; -class ShipmentEndpoint extends CollectionEndpointAbstract +class ShipmentEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "orders_shipments"; public const RESOURCE_ID_PREFIX = 'shp_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Shipment + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Shipment { return new Shipment($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return ShipmentCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): ShipmentCollection { return new ShipmentCollection($count, $_links); } @@ -48,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return Shipment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Order $order, array $options = [], array $filters = []) + public function createFor(Order $order, array $options = [], array $filters = []): Shipment { return $this->createForId($order->id, $options, $filters); } @@ -64,7 +56,7 @@ public function createFor(Order $order, array $options = [], array $filters = [] * @return Shipment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId($orderId, array $options = [], array $filters = []) + public function createForId(string $orderId, array $options = [], array $filters = []): Shipment { $this->parentId = $orderId; @@ -81,7 +73,7 @@ public function createForId($orderId, array $options = [], array $filters = []) * @return Shipment * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Order $order, $shipmentId, array $parameters = []) + public function getFor(Order $order, string $shipmentId, array $parameters = []): Shipment { return $this->getForId($order->id, $shipmentId, $parameters); } @@ -93,10 +85,10 @@ public function getFor(Order $order, $shipmentId, array $parameters = []) * @param string $shipmentId * @param array $parameters * - * @return \Mollie\Api\Resources\Shipment + * @return Shipment * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId($orderId, $shipmentId, array $parameters = []) + public function getForId(string $orderId, string $shipmentId, array $parameters = []): Shipment { $this->parentId = $orderId; @@ -110,12 +102,12 @@ public function getForId($orderId, $shipmentId, array $parameters = []) * * @param string $shipmentId * @param string $orderId - * * @param array $data + * * @return Shipment * @throws ApiException */ - public function update($orderId, $shipmentId, array $data = []) + public function update(string $orderId, $shipmentId, array $data = []): Shipment { if (empty($shipmentId) || strpos($shipmentId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid subscription ID: '{$shipmentId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -135,7 +127,7 @@ public function update($orderId, $shipmentId, array $data = []) * @return ShipmentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Order $order, array $parameters = []) + public function listFor(Order $order, array $parameters = []): ShipmentCollection { return $this->listForId($order->id, $parameters); } @@ -146,10 +138,10 @@ public function listFor(Order $order, array $parameters = []) * @param string $orderId * @param array $parameters * - * @return \Mollie\Api\Resources\ShipmentCollection + * @return ShipmentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($orderId, array $parameters = []) + public function listForId(string $orderId, array $parameters = []): ShipmentCollection { $this->parentId = $orderId; diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 400410148..44aa48465 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -9,31 +9,24 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -class SubscriptionEndpoint extends CollectionEndpointAbstract +class SubscriptionEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "customers_subscriptions"; public const RESOURCE_ID_PREFIX = 'sub_'; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return Subscription + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Subscription { return new Subscription($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return SubscriptionCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): SubscriptionCollection { return new SubscriptionCollection($this->client, $count, $_links); } @@ -48,7 +41,7 @@ protected function getResourceCollectionObject(int $count, object $_links) * @return Subscription * @throws ApiException */ - public function createFor(Customer $customer, array $options = [], array $filters = []) + public function createFor(Customer $customer, array $options = [], array $filters = []): Subscription { return $this->createForId($customer->id, $options, $filters); } @@ -63,7 +56,7 @@ public function createFor(Customer $customer, array $options = [], array $filter * @return Subscription * @throws ApiException */ - public function createForId($customerId, array $options = [], array $filters = []) + public function createForId(string $customerId, array $options = [], array $filters = []): Subscription { $this->parentId = $customerId; @@ -83,7 +76,7 @@ public function createForId($customerId, array $options = [], array $filters = [ * @return Subscription * @throws ApiException */ - public function update($customerId, $subscriptionId, array $data = []) + public function update(string $customerId, string $subscriptionId, array $data = []): Subscription { if (empty($subscriptionId) || strpos($subscriptionId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid subscription ID: '{$subscriptionId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -102,7 +95,7 @@ public function update($customerId, $subscriptionId, array $data = []) * @return Subscription * @throws ApiException */ - public function getFor(Customer $customer, $subscriptionId, array $parameters = []) + public function getFor(Customer $customer, string $subscriptionId, array $parameters = []): Subscription { return $this->getForId($customer->id, $subscriptionId, $parameters); } @@ -115,7 +108,7 @@ public function getFor(Customer $customer, $subscriptionId, array $parameters = * @return Subscription * @throws ApiException */ - public function getForId($customerId, $subscriptionId, array $parameters = []) + public function getForId(string $customerId, string $subscriptionId, array $parameters = []): Subscription { $this->parentId = $customerId; @@ -131,7 +124,7 @@ public function getForId($customerId, $subscriptionId, array $parameters = []) * @return SubscriptionCollection * @throws ApiException */ - public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = []) + public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { return $this->listForId($customer->id, $from, $limit, $parameters); } @@ -147,8 +140,13 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ * * @return LazyCollection */ - public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); } @@ -161,7 +159,7 @@ public function iteratorFor(Customer $customer, ?string $from = null, ?int $limi * @return SubscriptionCollection * @throws ApiException */ - public function listForId($customerId, $from = null, $limit = null, array $parameters = []) + public function listForId($customerId, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { $this->parentId = $customerId; @@ -179,8 +177,13 @@ public function listForId($customerId, $from = null, $limit = null, array $param * * @return LazyCollection */ - public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { $this->parentId = $customerId; return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); @@ -191,10 +194,10 @@ public function iteratorForId(string $customerId, ?string $from = null, ?int $li * @param string $subscriptionId * @param array $data * - * @return null + * @return null|Subscription * @throws ApiException */ - public function cancelFor(Customer $customer, $subscriptionId, array $data = []) + public function cancelFor(Customer $customer, string $subscriptionId, array $data = []): ?Subscription { return $this->cancelForId($customer->id, $subscriptionId, $data); } @@ -204,10 +207,10 @@ public function cancelFor(Customer $customer, $subscriptionId, array $data = []) * @param string $subscriptionId * @param array $data * - * @return null + * @return null|Subscription * @throws ApiException */ - public function cancelForId($customerId, $subscriptionId, array $data = []) + public function cancelForId(string $customerId, string $subscriptionId, array $data = []): ?Subscription { $this->parentId = $customerId; @@ -224,22 +227,18 @@ public function cancelForId($customerId, $subscriptionId, array $data = []) * @return SubscriptionCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { - $filters = array_merge(["from" => $from, "limit" => $limit], $parameters); - - $apiPath = 'subscriptions' . $this->buildQueryString($filters); - - $result = $this->client->performHttpCall(self::REST_LIST, $apiPath); + $apiPath = 'subscriptions' . $this->buildQueryString( + $this->getMergedFilters($parameters, $from, $limit) + ); - /** @var SubscriptionCollection $collection */ - $collection = $this->getResourceCollectionObject($result->count, $result->_links); - - foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { - $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject()); - } + $result = $this->client->performHttpCall( + self::REST_LIST, + $apiPath + ); - return $collection; + return $this->createCollectionFromResult($result); } /** diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 8b4399302..3ca6a89b0 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -7,29 +7,24 @@ use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; -class TerminalEndpoint extends CollectionEndpointAbstract +class TerminalEndpoint extends CollectionRestEndpoint { protected string $resourcePath = "terminals"; public const RESOURCE_ID_PREFIX = 'term_'; /** - * @return Terminal + * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): Terminal { return new Terminal($this->client); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * - * @return TerminalCollection + * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links) + protected function getResourceCollectionObject(int $count, object $_links): TerminalCollection { return new TerminalCollection($this->client, $count, $_links); } @@ -41,10 +36,11 @@ protected function getResourceCollectionObject(int $count, object $_links) * * @param string $terminalId * @param array $parameters + * * @return Terminal * @throws ApiException */ - public function get($terminalId, array $parameters = []) + public function get(string $terminalId, array $parameters = []): Terminal { if (empty($terminalId) || strpos($terminalId, self::RESOURCE_ID_PREFIX) !== 0) { throw new ApiException("Invalid terminal ID: '{$terminalId}'. A terminal ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); @@ -63,9 +59,9 @@ public function get($terminalId, array $parameters = []) * @return TerminalCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection { - return $this->rest_list($from, $limit, $parameters); + return parent::rest_list($from, $limit, $parameters); } /** @@ -78,8 +74,12 @@ public function page($from = null, $limit = null, array $parameters = []) * * @return LazyCollection */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { + public function iterator( + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/WalletEndpoint.php b/src/Endpoints/WalletEndpoint.php index 628aaebde..62b55d42f 100644 --- a/src/Endpoints/WalletEndpoint.php +++ b/src/Endpoints/WalletEndpoint.php @@ -2,20 +2,8 @@ namespace Mollie\Api\Endpoints; -use Mollie\Api\Resources\BaseResource; - -class WalletEndpoint extends EndpointAbstract +class WalletEndpoint extends BaseEndpoint { - /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return void|BaseResource - */ - protected function getResourceObject() - { - // Not used - } - /** * Obtain a new ApplePay payment session. * @@ -26,7 +14,7 @@ protected function getResourceObject() * @return false|string * @throws \Mollie\Api\Exceptions\ApiException */ - public function requestApplePayPaymentSession($domain, $validationUrl, $parameters = []) + public function requestApplePayPaymentSession($domain, $validationUrl, $parameters = []): string|false { $body = $this->parseRequestBody(array_merge([ 'domain' => $domain, From 5cb58e265ddc53973294af767fa2e14aa4a8ccee Mon Sep 17 00:00:00 2001 From: Naoray Date: Fri, 5 Jan 2024 09:51:05 +0000 Subject: [PATCH 004/131] Fix styling --- src/Endpoints/BalanceEndpoint.php | 1 - src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/RestEndpoint.php | 2 +- src/Endpoints/SubscriptionEndpoint.php | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index 0c701304b..b6047ae71 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; -use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\LazyCollection; class BalanceEndpoint extends CollectionRestEndpoint diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 6fd243eeb..15977260b 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -109,7 +109,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (!isset($data['lines']) || !is_array($data['lines'])) { + if (! isset($data['lines']) || ! is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index 180841238..7bd23e999 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -65,7 +65,7 @@ protected function rest_update(string $id, array $body = []): ?BaseResource */ protected function rest_read(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpoint && empty($id)) { + if (! $this instanceof SingleResourceEndpoint && empty($id)) { throw new ApiException("Invalid resource id."); } diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 44aa48465..79e1a8acf 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\LazyCollection; -use Mollie\Api\Resources\ResourceFactory; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; From f66f9c0158d1789b0db095de8030638dbac2ea2b Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 5 Jan 2024 11:10:48 +0100 Subject: [PATCH 005/131] fix tests --- src/Endpoints/BalanceEndpoint.php | 4 ++-- src/Endpoints/BalanceReportEndpoint.php | 18 ++++++++++-------- src/Endpoints/BalanceTransactionEndpoint.php | 4 ++-- src/Endpoints/ChargebackEndpoint.php | 2 +- src/Endpoints/ClientEndpoint.php | 2 +- src/Endpoints/CustomerEndpoint.php | 2 +- src/Endpoints/CustomerPaymentsEndpoint.php | 2 +- ...ointAbstract.php => EndpointCollection.php} | 2 +- src/Endpoints/InvoiceEndpoint.php | 2 +- src/Endpoints/MandateEndpoint.php | 2 +- src/Endpoints/MethodEndpoint.php | 2 +- src/Endpoints/OnboardingEndpoint.php | 2 +- src/Endpoints/OrderEndpoint.php | 2 +- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/OrderPaymentEndpoint.php | 2 +- src/Endpoints/OrderRefundEndpoint.php | 2 +- src/Endpoints/PaymentCaptureEndpoint.php | 2 +- src/Endpoints/PaymentChargebackEndpoint.php | 2 +- src/Endpoints/PaymentEndpoint.php | 2 +- src/Endpoints/PaymentLinkEndpoint.php | 2 +- src/Endpoints/PaymentRefundEndpoint.php | 2 +- src/Endpoints/PermissionEndpoint.php | 2 +- src/Endpoints/ProfileEndpoint.php | 2 +- src/Endpoints/ProfileMethodEndpoint.php | 2 +- src/Endpoints/RefundEndpoint.php | 2 +- src/Endpoints/SettlementCaptureEndpoint.php | 2 +- src/Endpoints/SettlementChargebackEndpoint.php | 2 +- src/Endpoints/SettlementPaymentEndpoint.php | 2 +- src/Endpoints/SettlementRefundEndpoint.php | 2 +- src/Endpoints/SettlementsEndpoint.php | 2 +- src/Endpoints/ShipmentEndpoint.php | 2 +- src/Endpoints/SubscriptionEndpoint.php | 2 +- src/Endpoints/TerminalEndpoint.php | 2 +- src/Resources/ResourceFactory.php | 10 +++++----- .../API/Endpoints/OrderLineEndpointTest.php | 5 ++++- 35 files changed, 53 insertions(+), 48 deletions(-) rename src/Endpoints/{CollectionEndpointAbstract.php => EndpointCollection.php} (98%) diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index b6047ae71..a322c70d3 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -7,9 +7,9 @@ use Mollie\Api\Resources\BalanceCollection; use Mollie\Api\Resources\LazyCollection; -class BalanceEndpoint extends CollectionRestEndpoint +class BalanceEndpoint extends EndpointCollection { - const string RESOURCE_ID_PREFIX = 'bal_'; + const RESOURCE_ID_PREFIX = 'bal_'; protected string $resourcePath = "balances"; diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index c3465af8c..51e8af821 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -15,7 +15,7 @@ class BalanceReportEndpoint extends RestEndpoint /** * @inheritDoc */ - protected function getResourceObject() + protected function getResourceObject(): BalanceReport { return new BalanceReport($this->client); } @@ -25,10 +25,11 @@ protected function getResourceObject() * * @param string $balanceId * @param array $parameters - * @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource + * + * @return BalanceReport * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId(string $balanceId, array $parameters = []) + public function getForId(string $balanceId, array $parameters = []): BalanceReport { $this->parentId = $balanceId; @@ -45,10 +46,11 @@ public function getForId(string $balanceId, array $parameters = []) * This is the balance of your account’s primary currency, where all payments are settled to by default. * * @param array $parameters - * @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource + * + * @return BalanceReport * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForPrimary(array $parameters = []) + public function getForPrimary(array $parameters = []): BalanceReport { return $this->getForId("primary", $parameters); } @@ -57,12 +59,12 @@ public function getForPrimary(array $parameters = []) /** * Retrieve a balance report for the provided balance resource and parameters. * - * @param \Mollie\Api\Resources\Balance $balance + * @param Balance $balance * @param array $parameters - * @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource + * @return BalanceReport * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Balance $balance, array $parameters = []) + public function getFor(Balance $balance, array $parameters = []): BalanceReport { return $this->getForId($balance->id, $parameters); } diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 28b94c79d..52a18ea1b 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -9,9 +9,9 @@ use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Resources\LazyCollection; -class BalanceTransactionEndpoint extends CollectionRestEndpoint +class BalanceTransactionEndpoint extends EndpointCollection { - const string RESOURCE_ID_PREFIX = 'baltr_'; + const RESOURCE_ID_PREFIX = 'baltr_'; protected string $resourcePath = "balances_transactions"; diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index d3468880f..31c0e375a 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; -class ChargebackEndpoint extends CollectionRestEndpoint +class ChargebackEndpoint extends EndpointCollection { protected string $resourcePath = "chargebacks"; diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 38631fc41..66cfaf294 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\ClientCollection; use Mollie\Api\Resources\LazyCollection; -class ClientEndpoint extends CollectionRestEndpoint +class ClientEndpoint extends EndpointCollection { protected string $resourcePath = "clients"; diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index ed18d85e6..2ee9d4207 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Resources\LazyCollection; -class CustomerEndpoint extends CollectionRestEndpoint +class CustomerEndpoint extends EndpointCollection { protected string $resourcePath = "customers"; diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index d372af0eb..0469beeb4 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class CustomerPaymentsEndpoint extends CollectionRestEndpoint +class CustomerPaymentsEndpoint extends EndpointCollection { protected string $resourcePath = "customers_payments"; diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/EndpointCollection.php similarity index 98% rename from src/Endpoints/CollectionEndpointAbstract.php rename to src/Endpoints/EndpointCollection.php index 1a7c8439d..105ac9829 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/EndpointCollection.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceFactory; -abstract class CollectionRestEndpoint extends RestEndpoint +abstract class EndpointCollection extends RestEndpoint { /** * Get a collection of objects from the REST API. diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index 78d7049c2..6cc8a0eab 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\InvoiceCollection; use Mollie\Api\Resources\LazyCollection; -class InvoiceEndpoint extends CollectionRestEndpoint +class InvoiceEndpoint extends EndpointCollection { protected string $resourcePath = "invoices"; diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index e717c91d6..ee26a3f02 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -class MandateEndpoint extends CollectionRestEndpoint +class MandateEndpoint extends EndpointCollection { protected string $resourcePath = "customers_mandates"; diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 5df5dda8d..72643e63d 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Resources\ResourceFactory; -class MethodEndpoint extends CollectionRestEndpoint +class MethodEndpoint extends EndpointCollection { protected string $resourcePath = "methods"; diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 26d6e394f..639658df5 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -45,7 +45,7 @@ public function get(): Onboarding */ public function submit(array $parameters = []): void { - return $this->create($parameters, []); + $this->create($parameters, []); } /** diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 2308fc2e5..d064edfd6 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Order; use Mollie\Api\Resources\OrderCollection; -class OrderEndpoint extends CollectionRestEndpoint +class OrderEndpoint extends EndpointCollection { protected string $resourcePath = "orders"; diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 15977260b..52ba3badf 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\OrderLineCollection; use Mollie\Api\Resources\ResourceFactory; -class OrderLineEndpoint extends CollectionRestEndpoint +class OrderLineEndpoint extends EndpointCollection { protected string $resourcePath = "orders_lines"; diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index a1d558ab5..d661b9d5f 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class OrderPaymentEndpoint extends CollectionRestEndpoint +class OrderPaymentEndpoint extends EndpointCollection { protected string $resourcePath = "orders_payments"; diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index d172d656c..46979f309 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class OrderRefundEndpoint extends CollectionRestEndpoint +class OrderRefundEndpoint extends EndpointCollection { protected string $resourcePath = "orders_refunds"; diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index f3acfd991..2d896a460 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; -class PaymentCaptureEndpoint extends CollectionRestEndpoint +class PaymentCaptureEndpoint extends EndpointCollection { protected string $resourcePath = "payments_captures"; diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index 96c52331d..b28ca54e1 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; -class PaymentChargebackEndpoint extends CollectionRestEndpoint +class PaymentChargebackEndpoint extends EndpointCollection { protected string $resourcePath = "payments_chargebacks"; diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 90833208e..66e50a06e 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -class PaymentEndpoint extends CollectionRestEndpoint +class PaymentEndpoint extends EndpointCollection { protected string $resourcePath = "payments"; diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index f6af37b09..d4df8a25e 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; -class PaymentLinkEndpoint extends CollectionRestEndpoint +class PaymentLinkEndpoint extends EndpointCollection { protected string $resourcePath = "payment-links"; diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 81dafb81e..f86fa69fc 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class PaymentRefundEndpoint extends CollectionRestEndpoint +class PaymentRefundEndpoint extends EndpointCollection { protected string $resourcePath = "payments_refunds"; diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index 26abc99e1..6672332ed 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; -class PermissionEndpoint extends CollectionRestEndpoint +class PermissionEndpoint extends EndpointCollection { protected string $resourcePath = "permissions"; diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index 61f8d00f0..e25f46c55 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; -class ProfileEndpoint extends CollectionRestEndpoint +class ProfileEndpoint extends EndpointCollection { protected string $resourcePath = "profiles"; diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 688259c0c..b616ce5fe 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ResourceFactory; -class ProfileMethodEndpoint extends CollectionRestEndpoint +class ProfileMethodEndpoint extends EndpointCollection { protected string $resourcePath = "profiles_methods"; diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 75f49d00b..673af6043 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class RefundEndpoint extends CollectionRestEndpoint +class RefundEndpoint extends EndpointCollection { protected string $resourcePath = "refunds"; diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 520f0deb9..70f162d9e 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; -class SettlementCaptureEndpoint extends CollectionRestEndpoint +class SettlementCaptureEndpoint extends EndpointCollection { protected string $resourcePath = "settlements_captures"; diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index ac6265e6d..77de4403d 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; -class SettlementChargebackEndpoint extends CollectionRestEndpoint +class SettlementChargebackEndpoint extends EndpointCollection { protected string $resourcePath = "settlements_chargebacks"; diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index fb27ed725..872bf7a87 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -class SettlementPaymentEndpoint extends CollectionRestEndpoint +class SettlementPaymentEndpoint extends EndpointCollection { protected string $resourcePath = "settlements_payments"; diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 7849c640e..c7007f98c 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -class SettlementRefundEndpoint extends CollectionRestEndpoint +class SettlementRefundEndpoint extends EndpointCollection { protected string $resourcePath = "settlements_refunds"; diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index ec7f6c8ce..d061d2784 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; -class SettlementsEndpoint extends CollectionRestEndpoint +class SettlementsEndpoint extends EndpointCollection { protected string $resourcePath = "settlements"; diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index 9ada1b9ad..1f64b4393 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Shipment; use Mollie\Api\Resources\ShipmentCollection; -class ShipmentEndpoint extends CollectionRestEndpoint +class ShipmentEndpoint extends EndpointCollection { protected string $resourcePath = "orders_shipments"; diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 79e1a8acf..76338f220 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -class SubscriptionEndpoint extends CollectionRestEndpoint +class SubscriptionEndpoint extends EndpointCollection { protected string $resourcePath = "customers_subscriptions"; diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 3ca6a89b0..0678827a9 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; -class TerminalEndpoint extends CollectionRestEndpoint +class TerminalEndpoint extends EndpointCollection { protected string $resourcePath = "terminals"; diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 8951dc57d..07a3a8459 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -34,9 +34,9 @@ public static function createFromApiResult(object $apiResult, BaseResource $reso public static function createBaseResourceCollection( MollieApiClient $client, string $resourceClass, - array $data, - object $_links = null, - string $resourceCollectionClass = null + ?array $data = null, + ?object $_links = null, + ?string $resourceCollectionClass = null ): BaseCollection { $resourceCollectionClass = $resourceCollectionClass ?: $resourceClass . 'Collection'; $data = $data ?: []; @@ -61,8 +61,8 @@ public static function createCursorResourceCollection( MollieApiClient $client, array $input, string $resourceClass, - object $_links = null, - string $resourceCollectionClass = null + ?object $_links = null, + ?string $resourceCollectionClass = null ): CursorCollection { if (null === $resourceCollectionClass) { $resourceCollectionClass = $resourceClass . 'Collection'; diff --git a/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php b/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php index 75079cec4..601ce439b 100644 --- a/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php @@ -18,7 +18,10 @@ public function testCancelLinesRequiresLinesArray() $this->guzzleClient = $this->createMock(Client::class); $this->apiClient = new MollieApiClient($this->guzzleClient); - $this->apiClient->orderLines->cancelFor(new Order($this->apiClient), []); + $order = new Order($this->apiClient); + $order->id = 'ord_pbjz8x'; + + $this->apiClient->orderLines->cancelFor($order, []); } public function testUpdateMultipleOrderLines() From edcc1e8f3267bac5c3a0af537b8a80393499cf2f Mon Sep 17 00:00:00 2001 From: Naoray Date: Mon, 24 Jun 2024 10:29:03 +0000 Subject: [PATCH 006/131] Fix styling --- src/Endpoints/RestEndpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index d5a353afc..284bc3ef1 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -65,7 +65,7 @@ protected function rest_update(string $id, array $body = []): ?BaseResource */ protected function rest_read(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpoint && empty($id)) { + if (! $this instanceof SingleResourceEndpoint && empty($id)) { throw new ApiException("Invalid resource id."); } From c10e1752b4f7ba3fc93e55ee1396f496cb201a48 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 24 Jun 2024 13:33:08 +0200 Subject: [PATCH 007/131] add PSR18 http adapter --- src/Exceptions/ApiException.php | 95 +++++++------- src/HttpAdapter/CurlMollieHttpAdapter.php | 26 ++-- .../Guzzle6And7MollieHttpAdapter.php | 26 ++-- .../Guzzle6And7RetryMiddlewareFactory.php | 8 +- .../MollieHttpAdapterInterface.php | 6 +- src/HttpAdapter/MollieHttpAdapterPicker.php | 8 +- .../MollieHttpAdapterPickerInterface.php | 6 +- src/HttpAdapter/PSR18MollieHttpAdapter.php | 116 ++++++++++++++++++ 8 files changed, 205 insertions(+), 86 deletions(-) create mode 100644 src/HttpAdapter/PSR18MollieHttpAdapter.php diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index dc619db6e..05a024ed1 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -3,71 +3,74 @@ namespace Mollie\Api\Exceptions; use DateTime; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Throwable; class ApiException extends \Exception { /** * @var string */ - protected $field; + protected ?string $field; /** * @var string */ - protected $plainMessage; + protected string $plainMessage; /** - * @var \Psr\Http\Message\RequestInterface|null + * @var RequestInterface|null */ - protected $request; + protected ?RequestInterface $request; /** - * @var \Psr\Http\Message\ResponseInterface|null + * @var ResponseInterface|null */ - protected $response; + protected ?ResponseInterface $response; /** * ISO8601 representation of the moment this exception was thrown * * @var \DateTimeImmutable */ - protected $raisedAt; + protected \DateTimeImmutable $raisedAt; /** * @var array */ - protected $links = []; + protected array $links = []; /** * @param string $message * @param int $code * @param string|null $field - * @param \Psr\Http\Message\RequestInterface|null $request - * @param \Psr\Http\Message\ResponseInterface|null $response - * @param \Throwable|null $previous - * @throws \Mollie\Api\Exceptions\ApiException + * @param RequestInterface|null $request + * @param ResponseInterface|null $response + * @param Throwable|null $previous + * @throws ApiException */ public function __construct( - $message = "", - $code = 0, - $field = null, - $request = null, - $response = null, - $previous = null + string $message = "", + int $code = 0, + ?string $field = null, + ?RequestInterface $request = null, + ?ResponseInterface $response = null, + ?Throwable $previous = null ) { $this->plainMessage = $message; $this->raisedAt = new \DateTimeImmutable(); - $formattedRaisedAt = $this->raisedAt->format(DateTime::ISO8601); + $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); $message = "[{$formattedRaisedAt}] " . $message; - if (! empty($field)) { + if (!empty($field)) { $this->field = (string)$field; $message .= ". Field: {$this->field}"; } - if (! empty($response)) { + if (!empty($response)) { $this->response = $response; $object = static::parseResponseBody($this->response); @@ -96,18 +99,18 @@ public function __construct( } /** - * @param \Psr\Http\Message\ResponseInterface $response - * @param \Psr\Http\Message\RequestInterface $request - * @param \Throwable|null $previous - * @return \Mollie\Api\Exceptions\ApiException - * @throws \Mollie\Api\Exceptions\ApiException + * @param ResponseInterface $response + * @param ?RequestInterface $request + * @param Throwable|null $previous + * @return ApiException + * @throws ApiException */ - public static function createFromResponse($response, $request = null, $previous = null) + public static function createFromResponse(ResponseInterface $response, ?RequestInterface $request = null, ?Throwable $previous = null): self { $object = static::parseResponseBody($response); $field = null; - if (! empty($object->field)) { + if (!empty($object->field)) { $field = $object->field; } @@ -124,7 +127,7 @@ public static function createFromResponse($response, $request = null, $previous /** * @return string|null */ - public function getField() + public function getField(): ?string { return $this->field; } @@ -132,7 +135,7 @@ public function getField() /** * @return string|null */ - public function getDocumentationUrl() + public function getDocumentationUrl(): ?string { return $this->getUrl('documentation'); } @@ -140,15 +143,15 @@ public function getDocumentationUrl() /** * @return string|null */ - public function getDashboardUrl() + public function getDashboardUrl(): ?string { return $this->getUrl('dashboard'); } /** - * @return \Psr\Http\Message\ResponseInterface|null + * @return ResponseInterface|null */ - public function getResponse() + public function getResponse(): ?ResponseInterface { return $this->response; } @@ -156,16 +159,16 @@ public function getResponse() /** * @return bool */ - public function hasResponse() + public function hasResponse(): bool { - return $this->response !== null; + return !!$this->response; } /** * @param string $key * @return bool */ - public function hasLink($key) + public function hasLink($key): bool { return array_key_exists($key, $this->links); } @@ -174,7 +177,7 @@ public function hasLink($key) * @param string $key * @return mixed|null */ - public function getLink($key) + public function getLink($key): ?\stdClass { if ($this->hasLink($key)) { return $this->links[$key]; @@ -185,9 +188,9 @@ public function getLink($key) /** * @param string $key - * @return null + * @return string|null */ - public function getUrl($key) + public function getUrl($key): ?string { if ($this->hasLink($key)) { return $this->getLink($key)->href; @@ -197,9 +200,9 @@ public function getUrl($key) } /** - * @return \Psr\Http\Message\RequestInterface + * @return null|RequestInterface */ - public function getRequest() + public function getRequest(): ?RequestInterface { return $this->request; } @@ -209,17 +212,17 @@ public function getRequest() * * @return \DateTimeImmutable */ - public function getRaisedAt() + public function getRaisedAt(): \DateTimeImmutable { return $this->raisedAt; } /** - * @param \Psr\Http\Message\ResponseInterface $response + * @param ResponseInterface $response * @return \stdClass - * @throws \Mollie\Api\Exceptions\ApiException + * @throws ApiException */ - protected static function parseResponseBody($response) + protected static function parseResponseBody($response): \stdClass { $body = (string) $response->getBody(); @@ -237,7 +240,7 @@ protected static function parseResponseBody($response) * * @return string */ - public function getPlainMessage() + public function getPlainMessage(): string { return $this->plainMessage; } diff --git a/src/HttpAdapter/CurlMollieHttpAdapter.php b/src/HttpAdapter/CurlMollieHttpAdapter.php index dad4a2832..4cbdb4917 100644 --- a/src/HttpAdapter/CurlMollieHttpAdapter.php +++ b/src/HttpAdapter/CurlMollieHttpAdapter.php @@ -43,7 +43,7 @@ final class CurlMollieHttpAdapter implements MollieHttpAdapterInterface * @throws \Mollie\Api\Exceptions\ApiException * @throws \Mollie\Api\Exceptions\CurlConnectTimeoutException */ - public function send($httpMethod, $url, $headers, $httpBody) + public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass { for ($i = 0; $i <= self::MAX_RETRIES; $i++) { usleep($i * self::DELAY_INCREASE_MS); @@ -51,12 +51,12 @@ public function send($httpMethod, $url, $headers, $httpBody) try { return $this->attemptRequest($httpMethod, $url, $headers, $httpBody); } catch (CurlConnectTimeoutException $e) { - // Nothing + return null; } } throw new CurlConnectTimeoutException( - "Unable to connect to Mollie. Maximum number of retries (". self::MAX_RETRIES .") reached." + "Unable to connect to Mollie. Maximum number of retries (" . self::MAX_RETRIES . ") reached." ); } @@ -68,7 +68,7 @@ public function send($httpMethod, $url, $headers, $httpBody) * @return \stdClass|void|null * @throws \Mollie\Api\Exceptions\ApiException */ - protected function attemptRequest($httpMethod, $url, $headers, $httpBody) + protected function attemptRequest(string $httpMethod, string $url, array $headers, string $httpBody): ?\stdClass { $curl = curl_init($url); $headers["Content-Type"] = "application/json"; @@ -99,7 +99,7 @@ protected function attemptRequest($httpMethod, $url, $headers, $httpBody) break; default: - throw new \InvalidArgumentException("Invalid http method: ". $httpMethod); + throw new \InvalidArgumentException("Invalid http method: " . $httpMethod); } $startTime = microtime(true); @@ -130,7 +130,7 @@ protected function attemptRequest($httpMethod, $url, $headers, $httpBody) * * @return string|null */ - public function versionString() + public function versionString(): string { return 'Curl/*'; } @@ -139,9 +139,9 @@ public function versionString() * Whether this http adapter provides a debugging mode. If debugging mode is enabled, the * request will be included in the ApiException. * - * @return false + * @return bool */ - public function supportsDebugging() + public function supportsDebugging(): bool { return false; } @@ -151,7 +151,7 @@ public function supportsDebugging() * @param string|float $executionTime * @return bool */ - protected function isConnectTimeoutError($curlErrorNumber, $executionTime) + protected function isConnectTimeoutError(int $curlErrorNumber, $executionTime): bool { $connectErrors = [ \CURLE_COULDNT_RESOLVE_HOST => true, @@ -182,7 +182,7 @@ protected function isConnectTimeoutError($curlErrorNumber, $executionTime) * @return \stdClass|null * @throws \Mollie\Api\Exceptions\ApiException */ - protected function parseResponseBody($response, $statusCode, $httpBody) + protected function parseResponseBody(string $response, int $statusCode, string $httpBody): ?\stdClass { if (empty($response)) { if ($statusCode === self::HTTP_NO_CONTENT) { @@ -208,7 +208,7 @@ protected function parseResponseBody($response, $statusCode, $httpBody) $field = null; - if (! empty($body->field)) { + if (!empty($body->field)) { $field = $body->field; } @@ -226,12 +226,12 @@ protected function parseResponseBody($response, $statusCode, $httpBody) return $body; } - protected function parseHeaders($headers) + protected function parseHeaders(array $headers): array { $result = []; foreach ($headers as $key => $value) { - $result[] = $key .': ' . $value; + $result[] = $key . ': ' . $value; } return $result; diff --git a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php index a9e27cdb3..ddec07931 100644 --- a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php +++ b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php @@ -32,7 +32,7 @@ final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface /** * @var \GuzzleHttp\ClientInterface */ - protected $httpClient; + protected ClientInterface $httpClient; /** * Whether debugging is enabled. If debugging mode is enabled, the request will @@ -41,7 +41,7 @@ final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface * * @var bool */ - protected $debugging = false; + protected bool $debugging = false; public function __construct(ClientInterface $httpClient) { @@ -51,9 +51,9 @@ public function __construct(ClientInterface $httpClient) /** * Instantiate a default adapter with sane configuration for Guzzle 6 or 7. * - * @return static + * @return self */ - public static function createDefault() + public static function createDefault(): self { $retryMiddlewareFactory = new Guzzle6And7RetryMiddlewareFactory; $handlerStack = HandlerStack::create(); @@ -79,7 +79,7 @@ public static function createDefault() * @return \stdClass|null * @throws \Mollie\Api\Exceptions\ApiException */ - public function send($httpMethod, $url, $headers, $httpBody) + public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass { $request = new Request($httpMethod, $url, $headers, $httpBody); @@ -87,7 +87,7 @@ public function send($httpMethod, $url, $headers, $httpBody) $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (! $this->debugging) { + if (!$this->debugging) { $request = null; } @@ -108,9 +108,9 @@ public function send($httpMethod, $url, $headers, $httpBody) * Whether this http adapter provides a debugging mode. If debugging mode is enabled, the * request will be included in the ApiException. * - * @return true + * @return bool */ - public function supportsDebugging() + public function supportsDebugging(): bool { return true; } @@ -122,7 +122,7 @@ public function supportsDebugging() * * @return bool */ - public function debugging() + public function debugging(): bool { return $this->debugging; } @@ -132,7 +132,7 @@ public function debugging() * be included in the ApiException. By default, debugging is disabled to prevent * sensitive request data from leaking into exception logs. */ - public function enableDebugging() + public function enableDebugging(): void { $this->debugging = true; } @@ -142,7 +142,7 @@ public function enableDebugging() * be included in the ApiException. By default, debugging is disabled to prevent * sensitive request data from leaking into exception logs. */ - public function disableDebugging() + public function disableDebugging(): void { $this->debugging = false; } @@ -154,7 +154,7 @@ public function disableDebugging() * @return \stdClass|null * @throws ApiException */ - private function parseResponseBody(ResponseInterface $response) + private function parseResponseBody(ResponseInterface $response): ?\stdClass { $body = (string) $response->getBody(); if (empty($body)) { @@ -185,7 +185,7 @@ private function parseResponseBody(ResponseInterface $response) * * @return string|null */ - public function versionString() + public function versionString(): ?string { if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { // Guzzle 7 return "Guzzle/" . ClientInterface::MAJOR_VERSION; diff --git a/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php b/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php index b6d8cb73e..15ef49a32 100644 --- a/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php +++ b/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php @@ -25,7 +25,7 @@ class Guzzle6And7RetryMiddlewareFactory * * @return callable */ - public function retry($delay = true) + public function retry(bool $delay = true): callable { return Middleware::retry( $this->newRetryDecider(), @@ -39,7 +39,7 @@ public function retry($delay = true) * * @return callable */ - private function getRetryDelay() + private function getRetryDelay(): callable { return function ($numberOfRetries) { return static::DELAY_INCREASE_MS * $numberOfRetries; @@ -51,7 +51,7 @@ private function getRetryDelay() * * @return callable */ - private function getZeroRetryDelay() + private function getZeroRetryDelay(): callable { return function ($numberOfRetries) { return 0; @@ -61,7 +61,7 @@ private function getZeroRetryDelay() /** * @return callable */ - private function newRetryDecider() + private function newRetryDecider(): callable { return function ( $retries, diff --git a/src/HttpAdapter/MollieHttpAdapterInterface.php b/src/HttpAdapter/MollieHttpAdapterInterface.php index 226bbef85..9f3fb2f6e 100644 --- a/src/HttpAdapter/MollieHttpAdapterInterface.php +++ b/src/HttpAdapter/MollieHttpAdapterInterface.php @@ -10,11 +10,11 @@ interface MollieHttpAdapterInterface * @param string $httpMethod * @param string $url * @param string|array $headers - * @param string $httpBody + * @param ?string $httpBody * @return \stdClass|null * @throws \Mollie\Api\Exceptions\ApiException */ - public function send($httpMethod, $url, $headers, $httpBody); + public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass; /** * The version number for the underlying http client, if available. @@ -22,5 +22,5 @@ public function send($httpMethod, $url, $headers, $httpBody); * * @return string|null */ - public function versionString(); + public function versionString(): ?string; } diff --git a/src/HttpAdapter/MollieHttpAdapterPicker.php b/src/HttpAdapter/MollieHttpAdapterPicker.php index 41615d744..a08c99449 100644 --- a/src/HttpAdapter/MollieHttpAdapterPicker.php +++ b/src/HttpAdapter/MollieHttpAdapterPicker.php @@ -12,9 +12,9 @@ class MollieHttpAdapterPicker implements MollieHttpAdapterPickerInterface * @return \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface * @throws \Mollie\Api\Exceptions\UnrecognizedClientException */ - public function pickHttpAdapter($httpClient) + public function pickHttpAdapter($httpClient): MollieHttpAdapterInterface { - if (! $httpClient) { + if (!$httpClient) { if ($this->guzzleIsDetected()) { $guzzleVersion = $this->guzzleMajorVersionNumber(); @@ -40,7 +40,7 @@ public function pickHttpAdapter($httpClient) /** * @return bool */ - private function guzzleIsDetected() + private function guzzleIsDetected(): bool { return interface_exists('\\' . \GuzzleHttp\ClientInterface::class); } @@ -48,7 +48,7 @@ private function guzzleIsDetected() /** * @return int|null */ - private function guzzleMajorVersionNumber() + private function guzzleMajorVersionNumber(): ?int { // Guzzle 7 if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { diff --git a/src/HttpAdapter/MollieHttpAdapterPickerInterface.php b/src/HttpAdapter/MollieHttpAdapterPickerInterface.php index b91542d61..1e6a96c9f 100644 --- a/src/HttpAdapter/MollieHttpAdapterPickerInterface.php +++ b/src/HttpAdapter/MollieHttpAdapterPickerInterface.php @@ -5,9 +5,9 @@ interface MollieHttpAdapterPickerInterface { /** - * @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface $httpClient + * @param \GuzzleHttp\ClientInterface|MollieHttpAdapterInterface $httpClient * - * @return \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface + * @return MollieHttpAdapterInterface */ - public function pickHttpAdapter($httpClient); + public function pickHttpAdapter($httpClient): MollieHttpAdapterInterface; } diff --git a/src/HttpAdapter/PSR18MollieHttpAdapter.php b/src/HttpAdapter/PSR18MollieHttpAdapter.php new file mode 100644 index 000000000..b2d63bf39 --- /dev/null +++ b/src/HttpAdapter/PSR18MollieHttpAdapter.php @@ -0,0 +1,116 @@ +httpClient = $httpClient; + $this->requestFactory = $requestFactory; + $this->streamFactory = $streamFactory; + } + + /** + * {@inheritdoc} + */ + public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass + { + try { + $request = $this->createRequest($httpMethod, $url, $headers, $httpBody ?? ''); + $response = $this->httpClient->sendRequest($request); + + $body = (string) $response->getBody(); + return json_decode($body); + } catch (\Exception $e) { + throw new ApiException("Error while sending request to Mollie API: " . $e->getMessage(), 0, $e); + } + } + + /** + * {@inheritdoc} + */ + public function versionString(): string + { + return 'PSR18MollieHttpAdapter'; + } + + /** + * Create a PSR-7 request. + * + * @param string $httpMethod + * @param string $url + * @param string|array $headers + * @param string $httpBody + * @return RequestInterface + */ + private function createRequest(string $httpMethod, string $url, $headers, ?string $httpBody): RequestInterface + { + $stream = $this->streamFactory->createStream($httpBody); + + $request = $this + ->requestFactory + ->createRequest($httpMethod, $url) + ->withBody($stream); + + return $this->addHeadersToRequest($request, $headers); + } + + /** + * Parse and add headers to request. + * + * @param RequestInterface $request + * @param string|array $headers + * @return RequestInterface + */ + private function addHeadersToRequest(RequestInterface $request, $headers): RequestInterface + { + if (is_array($headers)) { + foreach ($headers as $name => $value) { + $request = $request->withHeader($name, $value); + } + } + + if (is_string($headers)) { + $headerLines = explode("\r\n", $headers); + + foreach ($headerLines as $line) { + list($name, $value) = explode(': ', $line, 2); + $request = $request->withHeader($name, $value); + } + } + + return $request; + } +} From 9d6929962eaa5c8e1aa36fc3b7d9c1c2033b274f Mon Sep 17 00:00:00 2001 From: Naoray Date: Mon, 24 Jun 2024 11:33:48 +0000 Subject: [PATCH 008/131] Fix styling --- src/Exceptions/ApiException.php | 8 ++++---- src/HttpAdapter/CurlMollieHttpAdapter.php | 2 +- src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php | 2 +- src/HttpAdapter/MollieHttpAdapterPicker.php | 2 +- src/HttpAdapter/PSR18MollieHttpAdapter.php | 5 +++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 05a024ed1..75388ef25 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -65,12 +65,12 @@ public function __construct( $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); $message = "[{$formattedRaisedAt}] " . $message; - if (!empty($field)) { + if (! empty($field)) { $this->field = (string)$field; $message .= ". Field: {$this->field}"; } - if (!empty($response)) { + if (! empty($response)) { $this->response = $response; $object = static::parseResponseBody($this->response); @@ -110,7 +110,7 @@ public static function createFromResponse(ResponseInterface $response, ?RequestI $object = static::parseResponseBody($response); $field = null; - if (!empty($object->field)) { + if (! empty($object->field)) { $field = $object->field; } @@ -161,7 +161,7 @@ public function getResponse(): ?ResponseInterface */ public function hasResponse(): bool { - return !!$this->response; + return ! ! $this->response; } /** diff --git a/src/HttpAdapter/CurlMollieHttpAdapter.php b/src/HttpAdapter/CurlMollieHttpAdapter.php index 4cbdb4917..da9f696c2 100644 --- a/src/HttpAdapter/CurlMollieHttpAdapter.php +++ b/src/HttpAdapter/CurlMollieHttpAdapter.php @@ -208,7 +208,7 @@ protected function parseResponseBody(string $response, int $statusCode, string $ $field = null; - if (!empty($body->field)) { + if (! empty($body->field)) { $field = $body->field; } diff --git a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php index ddec07931..a45287b2e 100644 --- a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php +++ b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php @@ -87,7 +87,7 @@ public function send(string $httpMethod, string $url, $headers, ?string $httpBod $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (!$this->debugging) { + if (! $this->debugging) { $request = null; } diff --git a/src/HttpAdapter/MollieHttpAdapterPicker.php b/src/HttpAdapter/MollieHttpAdapterPicker.php index a08c99449..b663636ee 100644 --- a/src/HttpAdapter/MollieHttpAdapterPicker.php +++ b/src/HttpAdapter/MollieHttpAdapterPicker.php @@ -14,7 +14,7 @@ class MollieHttpAdapterPicker implements MollieHttpAdapterPickerInterface */ public function pickHttpAdapter($httpClient): MollieHttpAdapterInterface { - if (!$httpClient) { + if (! $httpClient) { if ($this->guzzleIsDetected()) { $guzzleVersion = $this->guzzleMajorVersionNumber(); diff --git a/src/HttpAdapter/PSR18MollieHttpAdapter.php b/src/HttpAdapter/PSR18MollieHttpAdapter.php index b2d63bf39..04b99955f 100644 --- a/src/HttpAdapter/PSR18MollieHttpAdapter.php +++ b/src/HttpAdapter/PSR18MollieHttpAdapter.php @@ -2,11 +2,11 @@ namespace Mollie\Api\HttpAdapter; +use Mollie\Api\Exceptions\ApiException; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\RequestInterface; -use Mollie\Api\Exceptions\ApiException; +use Psr\Http\Message\StreamFactoryInterface; final class PSR18MollieHttpAdapter implements MollieHttpAdapterInterface { @@ -52,6 +52,7 @@ public function send(string $httpMethod, string $url, $headers, ?string $httpBod $response = $this->httpClient->sendRequest($request); $body = (string) $response->getBody(); + return json_decode($body); } catch (\Exception $e) { throw new ApiException("Error while sending request to Mollie API: " . $e->getMessage(), 0, $e); From 1da1fc4ac62afe151c93be716fa4da4cc59efb97 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 24 Jun 2024 22:02:29 +0200 Subject: [PATCH 009/131] wip --- .../create-customer-first-payment.php | 2 +- .../create-customer-recurring-payment.php | 6 +- .../orders/update-order-lines-multiple.php | 3 +- src/Resources/Invoice.php | 6 +- src/Resources/Mandate.php | 8 +- src/Resources/Order.php | 20 +- src/Resources/OrderLine.php | 30 +-- src/Resources/Payment.php | 32 +-- src/Resources/Profile.php | 14 +- src/Resources/Refund.php | 12 +- src/Resources/Settlement.php | 8 +- src/Resources/Subscription.php | 14 +- src/Resources/Terminal.php | 6 +- src/Types/CaptureMode.php | 9 + src/Types/InvoiceStatus.php | 6 +- src/Types/MandateStatus.php | 6 +- src/Types/OrderLineStatus.php | 14 +- src/Types/OrderLineType.php | 14 +- src/Types/OrderStatus.php | 18 +- src/Types/PaymentStatus.php | 14 +- src/Types/ProfileStatus.php | 6 +- src/Types/RefundStatus.php | 14 +- src/Types/SequenceType.php | 6 +- src/Types/SettlementStatus.php | 8 +- src/Types/SubscriptionStatus.php | 10 +- src/Types/TerminalStatus.php | 6 +- .../Endpoints/CustomerPaymentEndpointTest.php | 4 +- .../API/Endpoints/InvoiceEndpointTest.php | 2 +- .../API/Endpoints/MandateEndpointTest.php | 6 +- .../API/Endpoints/OrderEndpointTest.php | 28 +-- .../Endpoints/OrderPaymentEndpointTest.php | 6 +- .../API/Endpoints/OrderRefundEndpointTest.php | 4 +- .../API/Endpoints/PaymentEndpointTest.php | 8 +- .../API/Endpoints/ProfileEndpointTest.php | 4 +- .../API/Endpoints/SettlementEndpointTest.php | 2 +- .../API/Endpoints/ShipmentEndpointTest.php | 14 +- .../Endpoints/SubscriptionEndpointTest.php | 8 +- .../API/Endpoints/TerminalEndpointTest.php | 2 +- tests/Mollie/API/Resources/InvoiceTest.php | 18 +- .../API/Resources/MandateCollectionTest.php | 18 +- tests/Mollie/API/Resources/OrderLineTest.php | 192 +++++++++--------- tests/Mollie/API/Resources/OrderTest.php | 150 +++++++------- tests/Mollie/API/Resources/PaymentTest.php | 100 ++++----- tests/Mollie/API/Resources/ProfileTest.php | 18 +- tests/Mollie/API/Resources/RefundTest.php | 62 +++--- tests/Mollie/API/Resources/SettlementTest.php | 38 ++-- .../Mollie/API/Resources/SubscriptionTest.php | 58 +++--- 47 files changed, 521 insertions(+), 513 deletions(-) create mode 100644 src/Types/CaptureMode.php diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index 0775f27b4..d232b4ae9 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -45,7 +45,7 @@ ], // Flag this payment as a first payment to allow recurring payments later. - "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST, + "sequenceType" => \Mollie\Api\Types\SequenceType::FIRST, ]); /* diff --git a/examples/customers/create-customer-recurring-payment.php b/examples/customers/create-customer-recurring-payment.php index dedae9179..500581000 100644 --- a/examples/customers/create-customer-recurring-payment.php +++ b/examples/customers/create-customer-recurring-payment.php @@ -14,7 +14,7 @@ * If no customers are created yet, run the create-customer example. */ $customer = $mollie->customers->page(null, 1)[0]; - + /* * Generate a unique order id for this example. */ @@ -43,9 +43,9 @@ ], // Flag this payment as a recurring payment. - "sequenceType" => \Mollie\Api\Types\SequenceType::SEQUENCETYPE_RECURRING, + "sequenceType" => \Mollie\Api\Types\SequenceType::RECURRING, ]); - + /* * In this example we store the order with its payment status in a database. */ diff --git a/examples/orders/update-order-lines-multiple.php b/examples/orders/update-order-lines-multiple.php index 0fded1460..cad794118 100644 --- a/examples/orders/update-order-lines-multiple.php +++ b/examples/orders/update-order-lines-multiple.php @@ -20,7 +20,7 @@ $addOrderLine = [ "operation" => \Mollie\Api\Types\OrderLineUpdateOperationType::ADD, "data" => [ - "type" => \Mollie\Api\Types\OrderLineType::TYPE_DIGITAL, + "type" => \Mollie\Api\Types\OrderLineType::DIGITAL, "name" => "Adding new orderline", "quantity" => 2, "sku" => "12345679", @@ -60,7 +60,6 @@ ]; $order = $mollie->orderLines->updateMultiple('ord_pbjz8x', $operations); - } catch (\Mollie\Api\Exceptions\ApiException $e) { /* * When updating order lines for orders that used a pay after delivery method such as Klarna Pay Later, the diff --git a/src/Resources/Invoice.php b/src/Resources/Invoice.php index 70b86e775..dd45265f8 100644 --- a/src/Resources/Invoice.php +++ b/src/Resources/Invoice.php @@ -88,7 +88,7 @@ class Invoice extends BaseResource */ public function isPaid() { - return $this->status == InvoiceStatus::STATUS_PAID; + return $this->status == InvoiceStatus::PAID; } /** @@ -96,7 +96,7 @@ public function isPaid() */ public function isOpen() { - return $this->status == InvoiceStatus::STATUS_OPEN; + return $this->status == InvoiceStatus::OPEN; } /** @@ -104,6 +104,6 @@ public function isOpen() */ public function isOverdue() { - return $this->status == InvoiceStatus::STATUS_OVERDUE; + return $this->status == InvoiceStatus::OVERDUE; } } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index 24e56f684..75aac1624 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -64,7 +64,7 @@ class Mandate extends BaseResource */ public function isValid() { - return $this->status === MandateStatus::STATUS_VALID; + return $this->status === MandateStatus::VALID; } /** @@ -72,7 +72,7 @@ public function isValid() */ public function isPending() { - return $this->status === MandateStatus::STATUS_PENDING; + return $this->status === MandateStatus::PENDING; } /** @@ -80,7 +80,7 @@ public function isPending() */ public function isInvalid() { - return $this->status === MandateStatus::STATUS_INVALID; + return $this->status === MandateStatus::INVALID; } /** @@ -90,7 +90,7 @@ public function isInvalid() */ public function revoke() { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index a30531d9a..4c7be3257 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -228,7 +228,7 @@ class Order extends BaseResource */ public function isCreated() { - return $this->status === OrderStatus::STATUS_CREATED; + return $this->status === OrderStatus::CREATED; } /** @@ -238,7 +238,7 @@ public function isCreated() */ public function isPaid() { - return $this->status === OrderStatus::STATUS_PAID; + return $this->status === OrderStatus::PAID; } /** @@ -248,7 +248,7 @@ public function isPaid() */ public function isAuthorized() { - return $this->status === OrderStatus::STATUS_AUTHORIZED; + return $this->status === OrderStatus::AUTHORIZED; } /** @@ -258,7 +258,7 @@ public function isAuthorized() */ public function isCanceled() { - return $this->status === OrderStatus::STATUS_CANCELED; + return $this->status === OrderStatus::CANCELED; } /** @@ -269,7 +269,7 @@ public function isCanceled() */ public function isRefunded() { - return $this->status === OrderStatus::STATUS_REFUNDED; + return $this->status === OrderStatus::REFUNDED; } /** @@ -279,7 +279,7 @@ public function isRefunded() */ public function isShipping() { - return $this->status === OrderStatus::STATUS_SHIPPING; + return $this->status === OrderStatus::SHIPPING; } /** @@ -289,7 +289,7 @@ public function isShipping() */ public function isCompleted() { - return $this->status === OrderStatus::STATUS_COMPLETED; + return $this->status === OrderStatus::COMPLETED; } /** @@ -299,7 +299,7 @@ public function isCompleted() */ public function isExpired() { - return $this->status === OrderStatus::STATUS_EXPIRED; + return $this->status === OrderStatus::EXPIRED; } /** @@ -309,7 +309,7 @@ public function isExpired() */ public function isPending() { - return $this->status === OrderStatus::STATUS_PENDING; + return $this->status === OrderStatus::PENDING; } /** @@ -519,7 +519,7 @@ public function createPayment($data, $filters = []) */ public function payments() { - if (! isset($this->_embedded, $this->_embedded->payments)) { + if (!isset($this->_embedded, $this->_embedded->payments)) { return null; } diff --git a/src/Resources/OrderLine.php b/src/Resources/OrderLine.php index aa700feb2..08f01e1d3 100644 --- a/src/Resources/OrderLine.php +++ b/src/Resources/OrderLine.php @@ -187,7 +187,7 @@ class OrderLine extends BaseResource * @var string|null */ public $productUrl; - + /** * During creation of the order you can set custom metadata on order lines that is stored with * the order, and given back whenever you retrieve that order line. @@ -244,7 +244,7 @@ public function getImageUrl() */ public function isCreated() { - return $this->status === OrderLineStatus::STATUS_CREATED; + return $this->status === OrderLineStatus::CREATED; } /** @@ -254,7 +254,7 @@ public function isCreated() */ public function isPaid() { - return $this->status === OrderLineStatus::STATUS_PAID; + return $this->status === OrderLineStatus::PAID; } /** @@ -264,7 +264,7 @@ public function isPaid() */ public function isAuthorized() { - return $this->status === OrderLineStatus::STATUS_AUTHORIZED; + return $this->status === OrderLineStatus::AUTHORIZED; } /** @@ -274,7 +274,7 @@ public function isAuthorized() */ public function isCanceled() { - return $this->status === OrderLineStatus::STATUS_CANCELED; + return $this->status === OrderLineStatus::CANCELED; } /** @@ -285,7 +285,7 @@ public function isCanceled() */ public function isRefunded() { - return $this->status === OrderLineStatus::STATUS_REFUNDED; + return $this->status === OrderLineStatus::REFUNDED; } /** @@ -295,7 +295,7 @@ public function isRefunded() */ public function isShipping() { - return $this->status === OrderLineStatus::STATUS_SHIPPING; + return $this->status === OrderLineStatus::SHIPPING; } /** @@ -305,7 +305,7 @@ public function isShipping() */ public function isCompleted() { - return $this->status === OrderLineStatus::STATUS_COMPLETED; + return $this->status === OrderLineStatus::COMPLETED; } /** @@ -315,7 +315,7 @@ public function isCompleted() */ public function isPhysical() { - return $this->type === OrderLineType::TYPE_PHYSICAL; + return $this->type === OrderLineType::PHYSICAL; } /** @@ -325,7 +325,7 @@ public function isPhysical() */ public function isDiscount() { - return $this->type === OrderLineType::TYPE_DISCOUNT; + return $this->type === OrderLineType::DISCOUNT; } /** @@ -335,7 +335,7 @@ public function isDiscount() */ public function isDigital() { - return $this->type === OrderLineType::TYPE_DIGITAL; + return $this->type === OrderLineType::DIGITAL; } /** @@ -345,7 +345,7 @@ public function isDigital() */ public function isShippingFee() { - return $this->type === OrderLineType::TYPE_SHIPPING_FEE; + return $this->type === OrderLineType::SHIPPING_FEE; } /** @@ -355,7 +355,7 @@ public function isShippingFee() */ public function isStoreCredit() { - return $this->type === OrderLineType::TYPE_STORE_CREDIT; + return $this->type === OrderLineType::STORE_CREDIT; } /** @@ -365,7 +365,7 @@ public function isStoreCredit() */ public function isGiftCard() { - return $this->type === OrderLineType::TYPE_GIFT_CARD; + return $this->type === OrderLineType::GIFT_CARD; } /** @@ -375,7 +375,7 @@ public function isGiftCard() */ public function isSurcharge() { - return $this->type === OrderLineType::TYPE_SURCHARGE; + return $this->type === OrderLineType::SURCHARGE; } /** diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 3c85aa632..bb833238d 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -88,7 +88,7 @@ class Payment extends BaseResource * * @var string */ - public $status = PaymentStatus::STATUS_OPEN; + public $status = PaymentStatus::OPEN; /** * UTC datetime the payment was created in ISO-8601 format. @@ -383,7 +383,7 @@ class Payment extends BaseResource */ public function isCanceled() { - return $this->status === PaymentStatus::STATUS_CANCELED; + return $this->status === PaymentStatus::CANCELED; } /** @@ -393,7 +393,7 @@ public function isCanceled() */ public function isExpired() { - return $this->status === PaymentStatus::STATUS_EXPIRED; + return $this->status === PaymentStatus::EXPIRED; } /** @@ -403,7 +403,7 @@ public function isExpired() */ public function isOpen() { - return $this->status === PaymentStatus::STATUS_OPEN; + return $this->status === PaymentStatus::OPEN; } /** @@ -413,7 +413,7 @@ public function isOpen() */ public function isPending() { - return $this->status === PaymentStatus::STATUS_PENDING; + return $this->status === PaymentStatus::PENDING; } /** @@ -423,7 +423,7 @@ public function isPending() */ public function isAuthorized() { - return $this->status === PaymentStatus::STATUS_AUTHORIZED; + return $this->status === PaymentStatus::AUTHORIZED; } /** @@ -433,7 +433,7 @@ public function isAuthorized() */ public function isPaid() { - return ! empty($this->paidAt); + return !empty($this->paidAt); } /** @@ -443,7 +443,7 @@ public function isPaid() */ public function hasRefunds() { - return ! empty($this->_links->refunds); + return !empty($this->_links->refunds); } /** @@ -453,7 +453,7 @@ public function hasRefunds() */ public function hasChargebacks() { - return ! empty($this->_links->chargebacks); + return !empty($this->_links->chargebacks); } /** @@ -463,7 +463,7 @@ public function hasChargebacks() */ public function isFailed() { - return $this->status === PaymentStatus::STATUS_FAILED; + return $this->status === PaymentStatus::FAILED; } /** @@ -475,7 +475,7 @@ public function isFailed() */ public function hasSequenceTypeFirst() { - return $this->sequenceType === SequenceType::SEQUENCETYPE_FIRST; + return $this->sequenceType === SequenceType::FIRST; } /** @@ -487,7 +487,7 @@ public function hasSequenceTypeFirst() */ public function hasSequenceTypeRecurring() { - return $this->sequenceType === SequenceType::SEQUENCETYPE_RECURRING; + return $this->sequenceType === SequenceType::RECURRING; } /** @@ -586,7 +586,7 @@ public function getAmountChargedBack() */ public function hasSplitPayments() { - return ! empty($this->routing); + return !empty($this->routing); } /** @@ -597,7 +597,7 @@ public function hasSplitPayments() */ public function refunds() { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } @@ -645,7 +645,7 @@ public function listRefunds(array $parameters = []) */ public function captures() { - if (! isset($this->_links->captures->href)) { + if (!isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } @@ -686,7 +686,7 @@ public function getCapture($captureId, array $parameters = []) */ public function chargebacks() { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 1c87d9d65..6b27ec43f 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -84,7 +84,7 @@ class Profile extends BaseResource */ public function isUnverified() { - return $this->status == ProfileStatus::STATUS_UNVERIFIED; + return $this->status == ProfileStatus::UNVERIFIED; } /** @@ -92,7 +92,7 @@ public function isUnverified() */ public function isVerified() { - return $this->status == ProfileStatus::STATUS_VERIFIED; + return $this->status == ProfileStatus::VERIFIED; } /** @@ -100,7 +100,7 @@ public function isVerified() */ public function isBlocked() { - return $this->status == ProfileStatus::STATUS_BLOCKED; + return $this->status == ProfileStatus::BLOCKED; } /** @@ -131,7 +131,7 @@ public function update() */ public function chargebacks() { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -153,7 +153,7 @@ public function chargebacks() */ public function methods() { - if (! isset($this->_links->methods->href)) { + if (!isset($this->_links->methods->href)) { return new MethodCollection(0, null); } @@ -201,7 +201,7 @@ public function disableMethod($methodId, array $data = []) */ public function payments() { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } @@ -223,7 +223,7 @@ public function payments() */ public function refunds() { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index 651b13f13..b8794c979 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -105,7 +105,7 @@ public function canBeCanceled() */ public function isQueued() { - return $this->status === RefundStatus::STATUS_QUEUED; + return $this->status === RefundStatus::QUEUED; } /** @@ -115,7 +115,7 @@ public function isQueued() */ public function isPending() { - return $this->status === RefundStatus::STATUS_PENDING; + return $this->status === RefundStatus::PENDING; } /** @@ -125,7 +125,7 @@ public function isPending() */ public function isProcessing() { - return $this->status === RefundStatus::STATUS_PROCESSING; + return $this->status === RefundStatus::PROCESSING; } /** @@ -135,7 +135,7 @@ public function isProcessing() */ public function isTransferred() { - return $this->status === RefundStatus::STATUS_REFUNDED; + return $this->status === RefundStatus::REFUNDED; } /** @@ -145,7 +145,7 @@ public function isTransferred() */ public function isFailed() { - return $this->status === RefundStatus::STATUS_FAILED; + return $this->status === RefundStatus::FAILED; } /** @@ -155,7 +155,7 @@ public function isFailed() */ public function isCanceled() { - return $this->status === RefundStatus::STATUS_CANCELED; + return $this->status === RefundStatus::CANCELED; } /** diff --git a/src/Resources/Settlement.php b/src/Resources/Settlement.php index 54f71cd24..29e789939 100644 --- a/src/Resources/Settlement.php +++ b/src/Resources/Settlement.php @@ -77,7 +77,7 @@ class Settlement extends BaseResource */ public function isOpen() { - return $this->status === SettlementStatus::STATUS_OPEN; + return $this->status === SettlementStatus::OPEN; } /** @@ -87,7 +87,7 @@ public function isOpen() */ public function isPending() { - return $this->status === SettlementStatus::STATUS_PENDING; + return $this->status === SettlementStatus::PENDING; } /** @@ -97,7 +97,7 @@ public function isPending() */ public function isPaidout() { - return $this->status === SettlementStatus::STATUS_PAIDOUT; + return $this->status === SettlementStatus::PAIDOUT; } /** @@ -107,7 +107,7 @@ public function isPaidout() */ public function isFailed() { - return $this->status === SettlementStatus::STATUS_FAILED; + return $this->status === SettlementStatus::FAILED; } /** diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 62d085039..96a8227f4 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -138,7 +138,7 @@ public function update() */ public function isActive() { - return $this->status === SubscriptionStatus::STATUS_ACTIVE; + return $this->status === SubscriptionStatus::ACTIVE; } /** @@ -148,7 +148,7 @@ public function isActive() */ public function isPending() { - return $this->status === SubscriptionStatus::STATUS_PENDING; + return $this->status === SubscriptionStatus::PENDING; } /** @@ -158,7 +158,7 @@ public function isPending() */ public function isCanceled() { - return $this->status === SubscriptionStatus::STATUS_CANCELED; + return $this->status === SubscriptionStatus::CANCELED; } /** @@ -168,7 +168,7 @@ public function isCanceled() */ public function isSuspended() { - return $this->status === SubscriptionStatus::STATUS_SUSPENDED; + return $this->status === SubscriptionStatus::SUSPENDED; } /** @@ -178,7 +178,7 @@ public function isSuspended() */ public function isCompleted() { - return $this->status === SubscriptionStatus::STATUS_COMPLETED; + return $this->status === SubscriptionStatus::COMPLETED; } /** @@ -189,7 +189,7 @@ public function isCompleted() */ public function cancel() { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } @@ -217,7 +217,7 @@ public function cancel() */ public function payments() { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } diff --git a/src/Resources/Terminal.php b/src/Resources/Terminal.php index a2fd3b436..3e709933b 100644 --- a/src/Resources/Terminal.php +++ b/src/Resources/Terminal.php @@ -136,7 +136,7 @@ class Terminal extends BaseResource */ public function isPending() { - return $this->status === TerminalStatus::STATUS_PENDING; + return $this->status === TerminalStatus::PENDING; } /** @@ -144,7 +144,7 @@ public function isPending() */ public function isActive() { - return $this->status === TerminalStatus::STATUS_ACTIVE; + return $this->status === TerminalStatus::ACTIVE; } /** @@ -152,6 +152,6 @@ public function isActive() */ public function isInactive() { - return $this->status === TerminalStatus::STATUS_INACTIVE; + return $this->status === TerminalStatus::INACTIVE; } } diff --git a/src/Types/CaptureMode.php b/src/Types/CaptureMode.php new file mode 100644 index 000000000..6b80a7a4b --- /dev/null +++ b/src/Types/CaptureMode.php @@ -0,0 +1,9 @@ +assertEquals('My first API payment', $payment->description); $this->assertNull($payment->method); $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); - $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status); + $this->assertEquals(PaymentStatus::OPEN, $payment->status); $this->assertFalse($payment->isCancelable); $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt); $this->assertNull($payment->details); $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); - $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType); + $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php index 3e251fd4a..12c338fff 100644 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php @@ -89,7 +89,7 @@ public function testGetInvoice() $this->assertEquals("inv_bsa6PvAwaK", $invoice->id); $this->assertEquals("2018.190241", $invoice->reference); $this->assertEquals("123456789B01", $invoice->vatNumber); - $this->assertEquals(InvoiceStatus::STATUS_PAID, $invoice->status); + $this->assertEquals(InvoiceStatus::PAID, $invoice->status); $this->assertEquals("2018-05-02", $invoice->issuedAt); $this->assertEquals("2018-05-02", $invoice->paidAt); diff --git a/tests/Mollie/API/Endpoints/MandateEndpointTest.php b/tests/Mollie/API/Endpoints/MandateEndpointTest.php index 9efeb9083..ebbc91d09 100644 --- a/tests/Mollie/API/Endpoints/MandateEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MandateEndpointTest.php @@ -62,7 +62,7 @@ public function testCreateWorks() $this->assertInstanceOf(Mandate::class, $mandate); $this->assertEquals("mandate", $mandate->resource); - $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status); + $this->assertEquals(MandateStatus::VALID, $mandate->status); $this->assertEquals("directdebit", $mandate->method); $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details); $this->assertNull($mandate->mandateReference); @@ -124,7 +124,7 @@ public function testGetWorks() $this->assertInstanceOf(Mandate::class, $mandate); $this->assertEquals("mandate", $mandate->resource); - $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status); + $this->assertEquals(MandateStatus::VALID, $mandate->status); $this->assertEquals(MandateMethod::DIRECTDEBIT, $mandate->method); $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details); $this->assertNull($mandate->mandateReference); @@ -204,7 +204,7 @@ public function testListWorks() foreach ($mandates as $mandate) { $this->assertInstanceOf(Mandate::class, $mandate); $this->assertEquals("mandate", $mandate->resource); - $this->assertEquals(MandateStatus::STATUS_VALID, $mandate->status); + $this->assertEquals(MandateStatus::VALID, $mandate->status); $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; $this->assertEquals($customerLink, $mandate->_links->customer); diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index 998d7f281..b1a2b5674 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -615,12 +615,12 @@ public function testCancelOrderDirectly() [], $this->getOrderResponseFixture( 'ord_pbjz1x', - OrderStatus::STATUS_CANCELED + OrderStatus::CANCELED ) ) ); $order = $this->apiClient->orders->cancel('ord_pbjz1x'); - $this->assertOrder($order, 'ord_pbjz1x', OrderStatus::STATUS_CANCELED); + $this->assertOrder($order, 'ord_pbjz1x', OrderStatus::CANCELED); } public function testCancelOrderOnResource() @@ -632,13 +632,13 @@ public function testCancelOrderOnResource() [], $this->getOrderResponseFixture( 'ord_pbjz1x', - OrderStatus::STATUS_CANCELED + OrderStatus::CANCELED ) ) ); $order = $this->getOrder('ord_pbjz1x'); $canceledOrder = $order->cancel(); - $this->assertOrder($canceledOrder, 'ord_pbjz1x', OrderStatus::STATUS_CANCELED); + $this->assertOrder($canceledOrder, 'ord_pbjz1x', OrderStatus::CANCELED); } public function testCancelOrderLines() @@ -741,7 +741,7 @@ public function testUpdateOrder() [], $this->getOrderResponseFixture( "ord_pbjz8x", - OrderStatus::STATUS_CREATED, + OrderStatus::CREATED, "16738" ) ) @@ -767,7 +767,7 @@ public function testUpdateOrder() $order->webhookUrl = "https://example.org/updated-webhook"; $order = $order->update(); - $this->assertOrder($order, "ord_pbjz8x", OrderStatus::STATUS_CREATED, "16738"); + $this->assertOrder($order, "ord_pbjz8x", OrderStatus::CREATED, "16738"); } public function testUpdateOrderLine() @@ -828,7 +828,7 @@ public function testUpdateOrderLine() $this->assertOrder($result, 'ord_pbjz8x'); } - protected function assertOrder($order, $order_id, $order_status = OrderStatus::STATUS_CREATED, $orderNumber = "1337") + protected function assertOrder($order, $order_id, $order_status = OrderStatus::CREATED, $orderNumber = "1337") { $this->assertInstanceOf(Order::class, $order); $this->assertEquals('order', $order->resource); @@ -902,8 +902,8 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::S $line1->productUrl = "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083"; $line1->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$'; $line1->sku = "5702016116977"; - $line1->type = OrderLineType::TYPE_PHYSICAL; - $line1->status = OrderLineStatus::STATUS_CREATED; + $line1->type = OrderLineType::PHYSICAL; + $line1->status = OrderLineStatus::CREATED; $line1->isCancelable = true; $line1->quantity = 2; $line1->unitPrice = $this->createAmountObject("399.00", "EUR"); @@ -922,8 +922,8 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::S $line2->productUrl = "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056"; $line2->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$'; $line2->sku = "5702015594028"; - $line2->type = OrderLineType::TYPE_DIGITAL; - $line2->status = OrderLineStatus::STATUS_CREATED; + $line2->type = OrderLineType::DIGITAL; + $line2->status = OrderLineStatus::CREATED; $line2->isCancelable = true; $line2->quantity = 1; $line2->unitPrice = $this->createAmountObject("329.99", "EUR"); @@ -943,7 +943,7 @@ protected function getOrder($id) return $this->copy(json_decode($orderJson), new Order($this->apiClient)); } - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED, $orderNumber = '1337') + protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED, $orderNumber = '1337') { return str_replace( [ @@ -1083,7 +1083,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu ); } - protected function getShipment($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::STATUS_SHIPPING) + protected function getShipment($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::SHIPPING) { $shipmentJson = $this->getShipmentResponseFixture( $shipmentId, @@ -1094,7 +1094,7 @@ protected function getShipment($shipmentId, $orderId, $orderlineStatus = OrderLi return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient)); } - protected function getShipmentResponseFixture($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::STATUS_SHIPPING) + protected function getShipmentResponseFixture($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::SHIPPING) { return str_replace( [ diff --git a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php index e3eb923e4..361d0b176 100644 --- a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php @@ -99,7 +99,7 @@ public function testCreateOrderPayment() $this->assertEquals('test', $payment->mode); $this->assertAmountObject(698, 'EUR', $payment->amount); $this->assertEquals('open', $payment->status); - $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status); + $this->assertEquals(PaymentStatus::OPEN, $payment->status); $this->assertEquals('Order #1337 (Lego cars)', $payment->description); $this->assertEquals('2018-12-01T17:09:02+00:00', $payment->createdAt); $this->assertEquals(PaymentMethod::BANKTRANSFER, $payment->method); @@ -108,7 +108,7 @@ public function testCreateOrderPayment() $this->assertTrue($payment->isCancelable); $this->assertEquals('nl_NL', $payment->locale); $this->assertEquals('pfl_URR55HPMGx', $payment->profileId); - $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType); + $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); $this->assertAmountObject(698, 'EUR', $payment->settlementAmount); $this->assertLinkObject( @@ -150,7 +150,7 @@ protected function getOrder($id) return $this->copy(json_decode($orderJson), new Order($this->apiClient)); } - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED) + protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( "<>", diff --git a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php index 87819fb0c..1ac3c40a7 100644 --- a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php @@ -188,7 +188,7 @@ public function testListOrderRefunds() $this->assertOrderRefund($refunds[0], 're_4qqhO89gsT'); } - protected function assertOrderRefund($refund, $refund_id, $refund_status = RefundStatus::STATUS_PENDING) + protected function assertOrderRefund($refund, $refund_id, $refund_status = RefundStatus::PENDING) { $this->assertInstanceOf(Refund::class, $refund); $this->assertEquals($refund_id, $refund->id); @@ -290,7 +290,7 @@ protected function getOrder($id) return $this->copy(json_decode($orderJson), new Order($this->apiClient)); } - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED) + protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( "<>", diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index f742501d5..344f1b922 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -104,12 +104,12 @@ public function testCreatePayment() $this->assertEquals('My first API payment', $payment->description); $this->assertNull($payment->method); $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); - $this->assertEquals(PaymentStatus::STATUS_OPEN, $payment->status); + $this->assertEquals(PaymentStatus::OPEN, $payment->status); $this->assertFalse($payment->isCancelable); $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt); $this->assertNull($payment->details); $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); - $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType); + $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); @@ -314,7 +314,7 @@ public function testGetPayment() $this->assertEquals('My first API payment', $payment->description); $this->assertEquals("ideal", $payment->method); $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); - $this->assertEquals(PaymentStatus::STATUS_PAID, $payment->status); + $this->assertEquals(PaymentStatus::PAID, $payment->status); $amountRefunded = new Stdclass(); $amountRefunded->value = '0.00'; @@ -334,7 +334,7 @@ public function testGetPayment() $this->assertEquals($details, $payment->details); $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); - $this->assertEquals(SequenceType::SEQUENCETYPE_ONEOFF, $payment->sequenceType); + $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php index 05ad639e3..61a81731b 100644 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php @@ -77,7 +77,7 @@ public function testGetProfile() $this->assertEquals("info@mywebsite.com", $profile->email); $this->assertEquals("31123456789", $profile->phone); $this->assertEquals(5399, $profile->categoryCode); - $this->assertEquals(ProfileStatus::STATUS_VERIFIED, $profile->status); + $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); $this->assertEquals((object) ["status" => "pending"], $profile->review); $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"]; @@ -229,7 +229,7 @@ public function testGetCurrentProfile() $this->assertEquals("info@mywebsite.com", $profile->email); $this->assertEquals("31123456789", $profile->phone); $this->assertEquals(5399, $profile->categoryCode); - $this->assertEquals(ProfileStatus::STATUS_VERIFIED, $profile->status); + $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); $this->assertEquals((object) ["status" => "pending"], $profile->review); $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"]; diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php index a0e8ae314..a8eab4902 100644 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php @@ -203,7 +203,7 @@ public function testGetSettlement() $this->assertEquals("1234567.1234.12", $settlement->reference); $this->assertEquals("2018-04-30T04:00:02+00:00", $settlement->createdAt); $this->assertEquals("2018-05-01T04:00:02+00:00", $settlement->settledAt); - $this->assertEquals(SettlementStatus::STATUS_PENDING, $settlement->status); + $this->assertEquals(SettlementStatus::PENDING, $settlement->status); $this->assertEquals((object) ["value" => "1980.98", "currency" => "EUR"], $settlement->amount); $this->assertNotEmpty($settlement->periods); $this->assertEquals("inv_VseyTUhJSy", $settlement->invoiceId); diff --git a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php b/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php index b9c4dcbd9..299417b8e 100644 --- a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php @@ -225,7 +225,7 @@ public function testUpdateShipmentTrackingInfo() $this->getShipmentResponseFixture( "shp_3wmsgCJN4U", "ord_pbjz8x", - OrderLineStatus::STATUS_SHIPPING, + OrderLineStatus::SHIPPING, '"tracking": { "carrier": "PostNL", "code": "3SKABA000000000", @@ -235,7 +235,7 @@ public function testUpdateShipmentTrackingInfo() ) ); - $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x', OrderLineStatus::STATUS_SHIPPING); + $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x', OrderLineStatus::SHIPPING); $shipment->tracking = [ 'carrier' => 'PostNL', @@ -285,7 +285,7 @@ protected function assertShipment($shipment, $shipment_id, $order_id) $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line1->imageUrl); $this->assertEquals('5702016116977', $line1->sku); $this->assertEquals('physical', $line1->type); - $this->assertEquals(OrderLineStatus::STATUS_SHIPPING, $line1->status); + $this->assertEquals(OrderLineStatus::SHIPPING, $line1->status); $this->assertEquals(2, $line1->quantity); $this->assertEquals('2018-08-02T09:29:56+00:00', $line1->createdAt); $this->assertEquals('21.00', $line1->vatRate); @@ -303,7 +303,7 @@ protected function assertShipment($shipment, $shipment_id, $order_id) $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', $line2->imageUrl); $this->assertEquals('5702015594028', $line2->sku); $this->assertEquals('digital', $line2->type); - $this->assertEquals(OrderLineStatus::STATUS_SHIPPING, $line2->status); + $this->assertEquals(OrderLineStatus::SHIPPING, $line2->status); $this->assertEquals(1, $line2->quantity); $this->assertEquals('2018-08-02T09:29:56+00:00', $line2->createdAt); $this->assertEquals('21.00', $line2->vatRate); @@ -319,14 +319,14 @@ protected function getOrder($id) return $this->copy(json_decode($orderJson), new Order($this->apiClient)); } - protected function getShipment($shipment_id, $order_id, $orderLineStatus = OrderLineStatus::STATUS_SHIPPING) + protected function getShipment($shipment_id, $order_id, $orderLineStatus = OrderLineStatus::SHIPPING) { $shipmentJson = $this->getShipmentResponseFixture($shipment_id, $order_id, $orderLineStatus); return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient)); } - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::STATUS_CREATED) + protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( "<>", @@ -465,7 +465,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu ); } - protected function getShipmentResponseFixture($shipment_id, $order_id, $orderline_status = OrderLineStatus::STATUS_SHIPPING, $tracking_info = '') + protected function getShipmentResponseFixture($shipment_id, $order_id, $orderline_status = OrderLineStatus::SHIPPING, $tracking_info = '') { return str_replace( [ diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php index 66b2f4c75..f5ccb3f9f 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php @@ -69,7 +69,7 @@ public function testCreateWorks() $this->assertEquals("sub_wByQa6efm6", $subscription->id); $this->assertEquals("test", $subscription->mode); $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); - $this->assertEquals(SubscriptionStatus::STATUS_ACTIVE, $subscription->status); + $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount); $this->assertEquals("Order 1234", $subscription->description); $this->assertNull($subscription->method); @@ -138,7 +138,7 @@ public function testGetWorks() $this->assertEquals("sub_wByQa6efm6", $subscription->id); $this->assertEquals("test", $subscription->mode); $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); - $this->assertEquals(SubscriptionStatus::STATUS_ACTIVE, $subscription->status); + $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount); $this->assertEquals("Order 1234", $subscription->description); $this->assertNull($subscription->method); @@ -282,7 +282,7 @@ public function testCancelViaCustomerResourceWorks() $this->assertEquals("subscription", $subscription->resource); $this->assertEquals("sub_wByQa6efm6", $subscription->id); $this->assertEquals("test", $subscription->mode); - $this->assertEquals(SubscriptionStatus::STATUS_CANCELED, $subscription->status); + $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt); @@ -347,7 +347,7 @@ public function testCancelOnSubscriptionResourceWorks($value = '') $this->assertEquals("subscription", $subscription->resource); $this->assertEquals("sub_DRjwaT5qHx", $subscription->id); $this->assertEquals("test", $subscription->mode); - $this->assertEquals(SubscriptionStatus::STATUS_CANCELED, $subscription->status); + $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt); diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index e3e0d146a..fc4494e10 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -58,7 +58,7 @@ public function testGetTerminal() $this->assertInstanceOf(Terminal::class, $terminal); $this->assertEquals('term_7MgL4wea46qkRcoTZjWEH', $terminal->id); $this->assertEquals('pfl_QkEhN94Ba', $terminal->profileId); - $this->assertEquals(TerminalStatus::STATUS_ACTIVE, $terminal->status); + $this->assertEquals(TerminalStatus::ACTIVE, $terminal->status); $this->assertEquals('PAX', $terminal->brand); $this->assertEquals('A920', $terminal->model); $this->assertEquals('1234567890', $terminal->serialNumber); diff --git a/tests/Mollie/API/Resources/InvoiceTest.php b/tests/Mollie/API/Resources/InvoiceTest.php index ad51cbca3..15abef3cb 100644 --- a/tests/Mollie/API/Resources/InvoiceTest.php +++ b/tests/Mollie/API/Resources/InvoiceTest.php @@ -27,17 +27,17 @@ public function testInvoiceStatuses($status, $function, $expected_boolean) public function dpTestInvoiceStatuses() { return [ - [InvoiceStatus::STATUS_PAID, "isPaid", true], - [InvoiceStatus::STATUS_PAID, "isOpen", false], - [InvoiceStatus::STATUS_PAID, "isOverdue", false], + [InvoiceStatus::PAID, "isPaid", true], + [InvoiceStatus::PAID, "isOpen", false], + [InvoiceStatus::PAID, "isOverdue", false], - [InvoiceStatus::STATUS_OPEN, "isPaid", false], - [InvoiceStatus::STATUS_OPEN, "isOpen", true], - [InvoiceStatus::STATUS_OPEN, "isOverdue", false], + [InvoiceStatus::OPEN, "isPaid", false], + [InvoiceStatus::OPEN, "isOpen", true], + [InvoiceStatus::OPEN, "isOverdue", false], - [InvoiceStatus::STATUS_OVERDUE, "isPaid", false], - [InvoiceStatus::STATUS_OVERDUE, "isOpen", false], - [InvoiceStatus::STATUS_OVERDUE, "isOverdue", true], + [InvoiceStatus::OVERDUE, "isPaid", false], + [InvoiceStatus::OVERDUE, "isOpen", false], + [InvoiceStatus::OVERDUE, "isOverdue", true], ]; } } diff --git a/tests/Mollie/API/Resources/MandateCollectionTest.php b/tests/Mollie/API/Resources/MandateCollectionTest.php index cc971c934..14b707127 100644 --- a/tests/Mollie/API/Resources/MandateCollectionTest.php +++ b/tests/Mollie/API/Resources/MandateCollectionTest.php @@ -25,16 +25,16 @@ protected function setUp(): void public function testWhereStatus() { $collection = new MandateCollection($this->client, 6, null); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_INVALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_INVALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::STATUS_PENDING); + $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); + $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); + $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); + $collection[] = $this->getMandateWithStatus(MandateStatus::INVALID); + $collection[] = $this->getMandateWithStatus(MandateStatus::INVALID); + $collection[] = $this->getMandateWithStatus(MandateStatus::PENDING); - $valid = $collection->whereStatus(MandateStatus::STATUS_VALID); - $invalid = $collection->whereStatus(MandateStatus::STATUS_INVALID); - $pending = $collection->whereStatus(MandateStatus::STATUS_PENDING); + $valid = $collection->whereStatus(MandateStatus::VALID); + $invalid = $collection->whereStatus(MandateStatus::INVALID); + $pending = $collection->whereStatus(MandateStatus::PENDING); $this->assertInstanceOf(MandateCollection::class, $collection); $this->assertInstanceOf(MandateCollection::class, $valid); diff --git a/tests/Mollie/API/Resources/OrderLineTest.php b/tests/Mollie/API/Resources/OrderLineTest.php index 8bdcff3dc..373e1152c 100644 --- a/tests/Mollie/API/Resources/OrderLineTest.php +++ b/tests/Mollie/API/Resources/OrderLineTest.php @@ -65,108 +65,108 @@ public function dpTestUpdateVatRate() public function dpTestOrderLineTypes() { return [ - [OrderLineType::TYPE_PHYSICAL, "isPhysical", true], - [OrderLineType::TYPE_PHYSICAL, "isDiscount", false], - [OrderLineType::TYPE_PHYSICAL, "isDigital", false], - [OrderLineType::TYPE_PHYSICAL, "isShippingFee", false], - [OrderLineType::TYPE_PHYSICAL, "isStoreCredit", false], - [OrderLineType::TYPE_PHYSICAL, "isGiftCard", false], - [OrderLineType::TYPE_PHYSICAL, "isSurcharge", false], - - [OrderLineType::TYPE_DISCOUNT, "isPhysical", false], - [OrderLineType::TYPE_DISCOUNT, "isDiscount", true], - [OrderLineType::TYPE_DISCOUNT, "isDigital", false], - [OrderLineType::TYPE_DISCOUNT, "isShippingFee", false], - [OrderLineType::TYPE_DISCOUNT, "isStoreCredit", false], - [OrderLineType::TYPE_DISCOUNT, "isGiftCard", false], - [OrderLineType::TYPE_DISCOUNT, "isSurcharge", false], - - [OrderLineType::TYPE_DIGITAL, "isPhysical", false], - [OrderLineType::TYPE_DIGITAL, "isDiscount", false], - [OrderLineType::TYPE_DIGITAL, "isDigital", true], - [OrderLineType::TYPE_DIGITAL, "isShippingFee", false], - [OrderLineType::TYPE_DIGITAL, "isStoreCredit", false], - [OrderLineType::TYPE_DIGITAL, "isGiftCard", false], - [OrderLineType::TYPE_DIGITAL, "isSurcharge", false], - - [OrderLineType::TYPE_SHIPPING_FEE, "isPhysical", false], - [OrderLineType::TYPE_SHIPPING_FEE, "isDiscount", false], - [OrderLineType::TYPE_SHIPPING_FEE, "isDigital", false], - [OrderLineType::TYPE_SHIPPING_FEE, "isShippingFee", true], - [OrderLineType::TYPE_SHIPPING_FEE, "isStoreCredit", false], - [OrderLineType::TYPE_SHIPPING_FEE, "isGiftCard", false], - [OrderLineType::TYPE_SHIPPING_FEE, "isSurcharge", false], - - [OrderLineType::TYPE_STORE_CREDIT, "isPhysical", false], - [OrderLineType::TYPE_STORE_CREDIT, "isDiscount", false], - [OrderLineType::TYPE_STORE_CREDIT, "isDigital", false], - [OrderLineType::TYPE_STORE_CREDIT, "isShippingFee", false], - [OrderLineType::TYPE_STORE_CREDIT, "isStoreCredit", true], - [OrderLineType::TYPE_STORE_CREDIT, "isGiftCard", false], - [OrderLineType::TYPE_STORE_CREDIT, "isSurcharge", false], - - [OrderLineType::TYPE_GIFT_CARD, "isPhysical", false], - [OrderLineType::TYPE_GIFT_CARD, "isDiscount", false], - [OrderLineType::TYPE_GIFT_CARD, "isDigital", false], - [OrderLineType::TYPE_GIFT_CARD, "isShippingFee", false], - [OrderLineType::TYPE_GIFT_CARD, "isStoreCredit", false], - [OrderLineType::TYPE_GIFT_CARD, "isGiftCard", true], - [OrderLineType::TYPE_GIFT_CARD, "isSurcharge", false], - - [OrderLineType::TYPE_SURCHARGE, "isPhysical", false], - [OrderLineType::TYPE_SURCHARGE, "isDiscount", false], - [OrderLineType::TYPE_SURCHARGE, "isDigital", false], - [OrderLineType::TYPE_SURCHARGE, "isShippingFee", false], - [OrderLineType::TYPE_SURCHARGE, "isStoreCredit", false], - [OrderLineType::TYPE_SURCHARGE, "isGiftCard", false], - [OrderLineType::TYPE_SURCHARGE, "isSurcharge", true], + [OrderLineType::PHYSICAL, "isPhysical", true], + [OrderLineType::PHYSICAL, "isDiscount", false], + [OrderLineType::PHYSICAL, "isDigital", false], + [OrderLineType::PHYSICAL, "isShippingFee", false], + [OrderLineType::PHYSICAL, "isStoreCredit", false], + [OrderLineType::PHYSICAL, "isGiftCard", false], + [OrderLineType::PHYSICAL, "isSurcharge", false], + + [OrderLineType::DISCOUNT, "isPhysical", false], + [OrderLineType::DISCOUNT, "isDiscount", true], + [OrderLineType::DISCOUNT, "isDigital", false], + [OrderLineType::DISCOUNT, "isShippingFee", false], + [OrderLineType::DISCOUNT, "isStoreCredit", false], + [OrderLineType::DISCOUNT, "isGiftCard", false], + [OrderLineType::DISCOUNT, "isSurcharge", false], + + [OrderLineType::DIGITAL, "isPhysical", false], + [OrderLineType::DIGITAL, "isDiscount", false], + [OrderLineType::DIGITAL, "isDigital", true], + [OrderLineType::DIGITAL, "isShippingFee", false], + [OrderLineType::DIGITAL, "isStoreCredit", false], + [OrderLineType::DIGITAL, "isGiftCard", false], + [OrderLineType::DIGITAL, "isSurcharge", false], + + [OrderLineType::SHIPPING_FEE, "isPhysical", false], + [OrderLineType::SHIPPING_FEE, "isDiscount", false], + [OrderLineType::SHIPPING_FEE, "isDigital", false], + [OrderLineType::SHIPPING_FEE, "isShippingFee", true], + [OrderLineType::SHIPPING_FEE, "isStoreCredit", false], + [OrderLineType::SHIPPING_FEE, "isGiftCard", false], + [OrderLineType::SHIPPING_FEE, "isSurcharge", false], + + [OrderLineType::STORE_CREDIT, "isPhysical", false], + [OrderLineType::STORE_CREDIT, "isDiscount", false], + [OrderLineType::STORE_CREDIT, "isDigital", false], + [OrderLineType::STORE_CREDIT, "isShippingFee", false], + [OrderLineType::STORE_CREDIT, "isStoreCredit", true], + [OrderLineType::STORE_CREDIT, "isGiftCard", false], + [OrderLineType::STORE_CREDIT, "isSurcharge", false], + + [OrderLineType::GIFT_CARD, "isPhysical", false], + [OrderLineType::GIFT_CARD, "isDiscount", false], + [OrderLineType::GIFT_CARD, "isDigital", false], + [OrderLineType::GIFT_CARD, "isShippingFee", false], + [OrderLineType::GIFT_CARD, "isStoreCredit", false], + [OrderLineType::GIFT_CARD, "isGiftCard", true], + [OrderLineType::GIFT_CARD, "isSurcharge", false], + + [OrderLineType::SURCHARGE, "isPhysical", false], + [OrderLineType::SURCHARGE, "isDiscount", false], + [OrderLineType::SURCHARGE, "isDigital", false], + [OrderLineType::SURCHARGE, "isShippingFee", false], + [OrderLineType::SURCHARGE, "isStoreCredit", false], + [OrderLineType::SURCHARGE, "isGiftCard", false], + [OrderLineType::SURCHARGE, "isSurcharge", true], ]; } public function dpTestOrderLineStatuses() { return [ - [OrderLineStatus::STATUS_CREATED, "isCreated", true], - [OrderLineStatus::STATUS_CREATED, "isPaid", false], - [OrderLineStatus::STATUS_CREATED, "isAuthorized", false], - [OrderLineStatus::STATUS_CREATED, "isCanceled", false], - [OrderLineStatus::STATUS_CREATED, "isShipping", false], - [OrderLineStatus::STATUS_CREATED, "isCompleted", false], - - [OrderLineStatus::STATUS_PAID, "isCreated", false], - [OrderLineStatus::STATUS_PAID, "isPaid", true], - [OrderLineStatus::STATUS_PAID, "isAuthorized", false], - [OrderLineStatus::STATUS_PAID, "isCanceled", false], - [OrderLineStatus::STATUS_PAID, "isShipping", false], - [OrderLineStatus::STATUS_PAID, "isCompleted", false], - - [OrderLineStatus::STATUS_AUTHORIZED, "isCreated", false], - [OrderLineStatus::STATUS_AUTHORIZED, "isPaid", false], - [OrderLineStatus::STATUS_AUTHORIZED, "isAuthorized", true], - [OrderLineStatus::STATUS_AUTHORIZED, "isCanceled", false], - [OrderLineStatus::STATUS_AUTHORIZED, "isShipping", false], - [OrderLineStatus::STATUS_AUTHORIZED, "isCompleted", false], - - [OrderLineStatus::STATUS_CANCELED, "isCreated", false], - [OrderLineStatus::STATUS_CANCELED, "isPaid", false], - [OrderLineStatus::STATUS_CANCELED, "isAuthorized", false], - [OrderLineStatus::STATUS_CANCELED, "isCanceled", true], - [OrderLineStatus::STATUS_CANCELED, "isShipping", false], - [OrderLineStatus::STATUS_CANCELED, "isCompleted", false], - - [OrderLineStatus::STATUS_SHIPPING, "isCreated", false], - [OrderLineStatus::STATUS_SHIPPING, "isPaid", false], - [OrderLineStatus::STATUS_SHIPPING, "isAuthorized", false], - [OrderLineStatus::STATUS_SHIPPING, "isCanceled", false], - [OrderLineStatus::STATUS_SHIPPING, "isShipping", true], - [OrderLineStatus::STATUS_SHIPPING, "isCompleted", false], - - [OrderLineStatus::STATUS_COMPLETED, "isCreated", false], - [OrderLineStatus::STATUS_COMPLETED, "isPaid", false], - [OrderLineStatus::STATUS_COMPLETED, "isAuthorized", false], - [OrderLineStatus::STATUS_COMPLETED, "isCanceled", false], - [OrderLineStatus::STATUS_COMPLETED, "isShipping", false], - [OrderLineStatus::STATUS_COMPLETED, "isCompleted", true], + [OrderLineStatus::CREATED, "isCreated", true], + [OrderLineStatus::CREATED, "isPaid", false], + [OrderLineStatus::CREATED, "isAuthorized", false], + [OrderLineStatus::CREATED, "isCanceled", false], + [OrderLineStatus::CREATED, "isShipping", false], + [OrderLineStatus::CREATED, "isCompleted", false], + + [OrderLineStatus::PAID, "isCreated", false], + [OrderLineStatus::PAID, "isPaid", true], + [OrderLineStatus::PAID, "isAuthorized", false], + [OrderLineStatus::PAID, "isCanceled", false], + [OrderLineStatus::PAID, "isShipping", false], + [OrderLineStatus::PAID, "isCompleted", false], + + [OrderLineStatus::AUTHORIZED, "isCreated", false], + [OrderLineStatus::AUTHORIZED, "isPaid", false], + [OrderLineStatus::AUTHORIZED, "isAuthorized", true], + [OrderLineStatus::AUTHORIZED, "isCanceled", false], + [OrderLineStatus::AUTHORIZED, "isShipping", false], + [OrderLineStatus::AUTHORIZED, "isCompleted", false], + + [OrderLineStatus::CANCELED, "isCreated", false], + [OrderLineStatus::CANCELED, "isPaid", false], + [OrderLineStatus::CANCELED, "isAuthorized", false], + [OrderLineStatus::CANCELED, "isCanceled", true], + [OrderLineStatus::CANCELED, "isShipping", false], + [OrderLineStatus::CANCELED, "isCompleted", false], + + [OrderLineStatus::SHIPPING, "isCreated", false], + [OrderLineStatus::SHIPPING, "isPaid", false], + [OrderLineStatus::SHIPPING, "isAuthorized", false], + [OrderLineStatus::SHIPPING, "isCanceled", false], + [OrderLineStatus::SHIPPING, "isShipping", true], + [OrderLineStatus::SHIPPING, "isCompleted", false], + + [OrderLineStatus::COMPLETED, "isCreated", false], + [OrderLineStatus::COMPLETED, "isPaid", false], + [OrderLineStatus::COMPLETED, "isAuthorized", false], + [OrderLineStatus::COMPLETED, "isCanceled", false], + [OrderLineStatus::COMPLETED, "isShipping", false], + [OrderLineStatus::COMPLETED, "isCompleted", true], ]; } } diff --git a/tests/Mollie/API/Resources/OrderTest.php b/tests/Mollie/API/Resources/OrderTest.php index f5050879c..20be8eb5e 100644 --- a/tests/Mollie/API/Resources/OrderTest.php +++ b/tests/Mollie/API/Resources/OrderTest.php @@ -36,77 +36,77 @@ public function testOrderStatuses($status, $function, $expected_boolean) public function dpTestOrderStatuses() { return [ - [OrderStatus::STATUS_CREATED, "isCreated", true], - [OrderStatus::STATUS_CREATED, "isPaid", false], - [OrderStatus::STATUS_CREATED, "isAuthorized", false], - [OrderStatus::STATUS_CREATED, "isCanceled", false], - [OrderStatus::STATUS_CREATED, "isShipping", false], - [OrderStatus::STATUS_CREATED, "isCompleted", false], - [OrderStatus::STATUS_CREATED, "isExpired", false], - [OrderStatus::STATUS_CREATED, "isPending", false], - - [OrderStatus::STATUS_PAID, "isCreated", false], - [OrderStatus::STATUS_PAID, "isPaid", true], - [OrderStatus::STATUS_PAID, "isAuthorized", false], - [OrderStatus::STATUS_PAID, "isCanceled", false], - [OrderStatus::STATUS_PAID, "isShipping", false], - [OrderStatus::STATUS_PAID, "isCompleted", false], - [OrderStatus::STATUS_PAID, "isExpired", false], - [OrderStatus::STATUS_PAID, "isPending", false], - - [OrderStatus::STATUS_AUTHORIZED, "isCreated", false], - [OrderStatus::STATUS_AUTHORIZED, "isPaid", false], - [OrderStatus::STATUS_AUTHORIZED, "isAuthorized", true], - [OrderStatus::STATUS_AUTHORIZED, "isCanceled", false], - [OrderStatus::STATUS_AUTHORIZED, "isShipping", false], - [OrderStatus::STATUS_AUTHORIZED, "isCompleted", false], - [OrderStatus::STATUS_AUTHORIZED, "isExpired", false], - [OrderStatus::STATUS_AUTHORIZED, "isPending", false], - - [OrderStatus::STATUS_CANCELED, "isCreated", false], - [OrderStatus::STATUS_CANCELED, "isPaid", false], - [OrderStatus::STATUS_CANCELED, "isAuthorized", false], - [OrderStatus::STATUS_CANCELED, "isCanceled", true], - [OrderStatus::STATUS_CANCELED, "isShipping", false], - [OrderStatus::STATUS_CANCELED, "isCompleted", false], - [OrderStatus::STATUS_CANCELED, "isExpired", false], - [OrderStatus::STATUS_CANCELED, "isPending", false], - - [OrderStatus::STATUS_SHIPPING, "isCreated", false], - [OrderStatus::STATUS_SHIPPING, "isPaid", false], - [OrderStatus::STATUS_SHIPPING, "isAuthorized", false], - [OrderStatus::STATUS_SHIPPING, "isCanceled", false], - [OrderStatus::STATUS_SHIPPING, "isShipping", true], - [OrderStatus::STATUS_SHIPPING, "isCompleted", false], - [OrderStatus::STATUS_SHIPPING, "isExpired", false], - [OrderStatus::STATUS_SHIPPING, "isPending", false], - - [OrderStatus::STATUS_COMPLETED, "isCreated", false], - [OrderStatus::STATUS_COMPLETED, "isPaid", false], - [OrderStatus::STATUS_COMPLETED, "isAuthorized", false], - [OrderStatus::STATUS_COMPLETED, "isCanceled", false], - [OrderStatus::STATUS_COMPLETED, "isShipping", false], - [OrderStatus::STATUS_COMPLETED, "isCompleted", true], - [OrderStatus::STATUS_COMPLETED, "isExpired", false], - [OrderStatus::STATUS_COMPLETED, "isPending", false], - - [OrderStatus::STATUS_EXPIRED, "isCreated", false], - [OrderStatus::STATUS_EXPIRED, "isPaid", false], - [OrderStatus::STATUS_EXPIRED, "isAuthorized", false], - [OrderStatus::STATUS_EXPIRED, "isCanceled", false], - [OrderStatus::STATUS_EXPIRED, "isShipping", false], - [OrderStatus::STATUS_EXPIRED, "isCompleted", false], - [OrderStatus::STATUS_EXPIRED, "isExpired", true], - [OrderStatus::STATUS_EXPIRED, "isPending", false], - - [OrderStatus::STATUS_PENDING, "isCreated", false], - [OrderStatus::STATUS_PENDING, "isPaid", false], - [OrderStatus::STATUS_PENDING, "isAuthorized", false], - [OrderStatus::STATUS_PENDING, "isCanceled", false], - [OrderStatus::STATUS_PENDING, "isShipping", false], - [OrderStatus::STATUS_PENDING, "isCompleted", false], - [OrderStatus::STATUS_PENDING, "isExpired", false], - [OrderStatus::STATUS_PENDING, "isPending", true], + [OrderStatus::CREATED, "isCreated", true], + [OrderStatus::CREATED, "isPaid", false], + [OrderStatus::CREATED, "isAuthorized", false], + [OrderStatus::CREATED, "isCanceled", false], + [OrderStatus::CREATED, "isShipping", false], + [OrderStatus::CREATED, "isCompleted", false], + [OrderStatus::CREATED, "isExpired", false], + [OrderStatus::CREATED, "isPending", false], + + [OrderStatus::PAID, "isCreated", false], + [OrderStatus::PAID, "isPaid", true], + [OrderStatus::PAID, "isAuthorized", false], + [OrderStatus::PAID, "isCanceled", false], + [OrderStatus::PAID, "isShipping", false], + [OrderStatus::PAID, "isCompleted", false], + [OrderStatus::PAID, "isExpired", false], + [OrderStatus::PAID, "isPending", false], + + [OrderStatus::AUTHORIZED, "isCreated", false], + [OrderStatus::AUTHORIZED, "isPaid", false], + [OrderStatus::AUTHORIZED, "isAuthorized", true], + [OrderStatus::AUTHORIZED, "isCanceled", false], + [OrderStatus::AUTHORIZED, "isShipping", false], + [OrderStatus::AUTHORIZED, "isCompleted", false], + [OrderStatus::AUTHORIZED, "isExpired", false], + [OrderStatus::AUTHORIZED, "isPending", false], + + [OrderStatus::CANCELED, "isCreated", false], + [OrderStatus::CANCELED, "isPaid", false], + [OrderStatus::CANCELED, "isAuthorized", false], + [OrderStatus::CANCELED, "isCanceled", true], + [OrderStatus::CANCELED, "isShipping", false], + [OrderStatus::CANCELED, "isCompleted", false], + [OrderStatus::CANCELED, "isExpired", false], + [OrderStatus::CANCELED, "isPending", false], + + [OrderStatus::SHIPPING, "isCreated", false], + [OrderStatus::SHIPPING, "isPaid", false], + [OrderStatus::SHIPPING, "isAuthorized", false], + [OrderStatus::SHIPPING, "isCanceled", false], + [OrderStatus::SHIPPING, "isShipping", true], + [OrderStatus::SHIPPING, "isCompleted", false], + [OrderStatus::SHIPPING, "isExpired", false], + [OrderStatus::SHIPPING, "isPending", false], + + [OrderStatus::COMPLETED, "isCreated", false], + [OrderStatus::COMPLETED, "isPaid", false], + [OrderStatus::COMPLETED, "isAuthorized", false], + [OrderStatus::COMPLETED, "isCanceled", false], + [OrderStatus::COMPLETED, "isShipping", false], + [OrderStatus::COMPLETED, "isCompleted", true], + [OrderStatus::COMPLETED, "isExpired", false], + [OrderStatus::COMPLETED, "isPending", false], + + [OrderStatus::EXPIRED, "isCreated", false], + [OrderStatus::EXPIRED, "isPaid", false], + [OrderStatus::EXPIRED, "isAuthorized", false], + [OrderStatus::EXPIRED, "isCanceled", false], + [OrderStatus::EXPIRED, "isShipping", false], + [OrderStatus::EXPIRED, "isCompleted", false], + [OrderStatus::EXPIRED, "isExpired", true], + [OrderStatus::EXPIRED, "isPending", false], + + [OrderStatus::PENDING, "isCreated", false], + [OrderStatus::PENDING, "isPaid", false], + [OrderStatus::PENDING, "isAuthorized", false], + [OrderStatus::PENDING, "isCanceled", false], + [OrderStatus::PENDING, "isShipping", false], + [OrderStatus::PENDING, "isCompleted", false], + [OrderStatus::PENDING, "isExpired", false], + [OrderStatus::PENDING, "isPending", true], ]; } @@ -167,8 +167,8 @@ public function testCanGetLinesAsResourcesOnOrderResource() $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl); $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); $this->assertEquals("5702016116977", $line->sku); - $this->assertEquals(OrderLineType::TYPE_PHYSICAL, $line->type); - $this->assertEquals(OrderLineStatus::STATUS_CREATED, $line->status); + $this->assertEquals(OrderLineType::PHYSICAL, $line->type); + $this->assertEquals(OrderLineStatus::CREATED, $line->status); $this->assertEquals(2, $line->quantity); $this->assertAmountObject("399.00", "EUR", $line->unitPrice); $this->assertEquals("21.00", $line->vatRate); @@ -235,8 +235,8 @@ public function testCanGetPaymentsAsResourcesOnOrderResource() $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl); $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); $this->assertEquals("5702016116977", $line->sku); - $this->assertEquals(OrderLineType::TYPE_PHYSICAL, $line->type); - $this->assertEquals(OrderLineStatus::STATUS_CREATED, $line->status); + $this->assertEquals(OrderLineType::PHYSICAL, $line->type); + $this->assertEquals(OrderLineStatus::CREATED, $line->status); $this->assertEquals(2, $line->quantity); $this->assertAmountObject("399.00", "EUR", $line->unitPrice); $this->assertEquals("21.00", $line->vatRate); diff --git a/tests/Mollie/API/Resources/PaymentTest.php b/tests/Mollie/API/Resources/PaymentTest.php index 480e755a2..5397919ed 100644 --- a/tests/Mollie/API/Resources/PaymentTest.php +++ b/tests/Mollie/API/Resources/PaymentTest.php @@ -28,53 +28,53 @@ public function testPaymentStatuses($status, $function, $expected_boolean) public function dpTestPaymentStatuses() { return [ - [PaymentStatus::STATUS_PENDING, "isPending", true], - [PaymentStatus::STATUS_PENDING, "isAuthorized", false], - [PaymentStatus::STATUS_PENDING, "isFailed", false], - [PaymentStatus::STATUS_PENDING, "isOpen", false], - [PaymentStatus::STATUS_PENDING, "isCanceled", false], - [PaymentStatus::STATUS_PENDING, "isPaid", false], - [PaymentStatus::STATUS_PENDING, "isExpired", false], - - [PaymentStatus::STATUS_AUTHORIZED, "isPending", false], - [PaymentStatus::STATUS_AUTHORIZED, "isAuthorized", true], - [PaymentStatus::STATUS_AUTHORIZED, "isFailed", false], - [PaymentStatus::STATUS_AUTHORIZED, "isOpen", false], - [PaymentStatus::STATUS_AUTHORIZED, "isCanceled", false], - [PaymentStatus::STATUS_AUTHORIZED, "isPaid", false], - [PaymentStatus::STATUS_AUTHORIZED, "isExpired", false], - - [PaymentStatus::STATUS_FAILED, "isPending", false], - [PaymentStatus::STATUS_FAILED, "isAuthorized", false], - [PaymentStatus::STATUS_FAILED, "isFailed", true], - [PaymentStatus::STATUS_FAILED, "isOpen", false], - [PaymentStatus::STATUS_FAILED, "isCanceled", false], - [PaymentStatus::STATUS_FAILED, "isPaid", false], - [PaymentStatus::STATUS_FAILED, "isExpired", false], - - [PaymentStatus::STATUS_OPEN, "isPending", false], - [PaymentStatus::STATUS_OPEN, "isAuthorized", false], - [PaymentStatus::STATUS_OPEN, "isFailed", false], - [PaymentStatus::STATUS_OPEN, "isOpen", true], - [PaymentStatus::STATUS_OPEN, "isCanceled", false], - [PaymentStatus::STATUS_OPEN, "isPaid", false], - [PaymentStatus::STATUS_OPEN, "isExpired", false], - - [PaymentStatus::STATUS_CANCELED, "isPending", false], - [PaymentStatus::STATUS_CANCELED, "isAuthorized", false], - [PaymentStatus::STATUS_CANCELED, "isFailed", false], - [PaymentStatus::STATUS_CANCELED, "isOpen", false], - [PaymentStatus::STATUS_CANCELED, "isCanceled", true], - [PaymentStatus::STATUS_CANCELED, "isPaid", false], - [PaymentStatus::STATUS_CANCELED, "isExpired", false], - - [PaymentStatus::STATUS_EXPIRED, "isPending", false], - [PaymentStatus::STATUS_EXPIRED, "isAuthorized", false], - [PaymentStatus::STATUS_EXPIRED, "isFailed", false], - [PaymentStatus::STATUS_EXPIRED, "isOpen", false], - [PaymentStatus::STATUS_EXPIRED, "isCanceled", false], - [PaymentStatus::STATUS_EXPIRED, "isPaid", false], - [PaymentStatus::STATUS_EXPIRED, "isExpired", true], + [PaymentStatus::PENDING, "isPending", true], + [PaymentStatus::PENDING, "isAuthorized", false], + [PaymentStatus::PENDING, "isFailed", false], + [PaymentStatus::PENDING, "isOpen", false], + [PaymentStatus::PENDING, "isCanceled", false], + [PaymentStatus::PENDING, "isPaid", false], + [PaymentStatus::PENDING, "isExpired", false], + + [PaymentStatus::AUTHORIZED, "isPending", false], + [PaymentStatus::AUTHORIZED, "isAuthorized", true], + [PaymentStatus::AUTHORIZED, "isFailed", false], + [PaymentStatus::AUTHORIZED, "isOpen", false], + [PaymentStatus::AUTHORIZED, "isCanceled", false], + [PaymentStatus::AUTHORIZED, "isPaid", false], + [PaymentStatus::AUTHORIZED, "isExpired", false], + + [PaymentStatus::FAILED, "isPending", false], + [PaymentStatus::FAILED, "isAuthorized", false], + [PaymentStatus::FAILED, "isFailed", true], + [PaymentStatus::FAILED, "isOpen", false], + [PaymentStatus::FAILED, "isCanceled", false], + [PaymentStatus::FAILED, "isPaid", false], + [PaymentStatus::FAILED, "isExpired", false], + + [PaymentStatus::OPEN, "isPending", false], + [PaymentStatus::OPEN, "isAuthorized", false], + [PaymentStatus::OPEN, "isFailed", false], + [PaymentStatus::OPEN, "isOpen", true], + [PaymentStatus::OPEN, "isCanceled", false], + [PaymentStatus::OPEN, "isPaid", false], + [PaymentStatus::OPEN, "isExpired", false], + + [PaymentStatus::CANCELED, "isPending", false], + [PaymentStatus::CANCELED, "isAuthorized", false], + [PaymentStatus::CANCELED, "isFailed", false], + [PaymentStatus::CANCELED, "isOpen", false], + [PaymentStatus::CANCELED, "isCanceled", true], + [PaymentStatus::CANCELED, "isPaid", false], + [PaymentStatus::CANCELED, "isExpired", false], + + [PaymentStatus::EXPIRED, "isPending", false], + [PaymentStatus::EXPIRED, "isAuthorized", false], + [PaymentStatus::EXPIRED, "isFailed", false], + [PaymentStatus::EXPIRED, "isOpen", false], + [PaymentStatus::EXPIRED, "isCanceled", false], + [PaymentStatus::EXPIRED, "isPaid", false], + [PaymentStatus::EXPIRED, "isExpired", true], ]; } @@ -126,7 +126,7 @@ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsFirst() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->sequenceType = SequenceType::SEQUENCETYPE_FIRST; + $payment->sequenceType = SequenceType::FIRST; $this->assertFalse($payment->hasSequenceTypeRecurring()); $this->assertTrue($payment->hasSequenceTypeFirst()); } @@ -135,7 +135,7 @@ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsRecurring() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->sequenceType = SequenceType::SEQUENCETYPE_RECURRING; + $payment->sequenceType = SequenceType::RECURRING; $this->assertTrue($payment->hasSequenceTypeRecurring()); $this->assertFalse($payment->hasSequenceTypeFirst()); } @@ -144,7 +144,7 @@ public function testHasRecurringTypeReturnsFalseWhenRecurringTypeIsNone() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->sequenceType = SequenceType::SEQUENCETYPE_ONEOFF; + $payment->sequenceType = SequenceType::ONEOFF; $this->assertFalse($payment->hasSequenceTypeFirst()); $this->assertFalse($payment->hasSequenceTypeRecurring()); } diff --git a/tests/Mollie/API/Resources/ProfileTest.php b/tests/Mollie/API/Resources/ProfileTest.php index 1dbb9030c..57af90667 100644 --- a/tests/Mollie/API/Resources/ProfileTest.php +++ b/tests/Mollie/API/Resources/ProfileTest.php @@ -26,17 +26,17 @@ public function testProfileStatusses($status, $function, $expected_boolean) public function dpTestProfileStatusses() { return [ - [ProfileStatus::STATUS_BLOCKED, "isBlocked", true], - [ProfileStatus::STATUS_BLOCKED, "isVerified", false], - [ProfileStatus::STATUS_BLOCKED, "isUnverified", false], + [ProfileStatus::BLOCKED, "isBlocked", true], + [ProfileStatus::BLOCKED, "isVerified", false], + [ProfileStatus::BLOCKED, "isUnverified", false], - [ProfileStatus::STATUS_VERIFIED, "isBlocked", false], - [ProfileStatus::STATUS_VERIFIED, "isVerified", true], - [ProfileStatus::STATUS_VERIFIED, "isUnverified", false], + [ProfileStatus::VERIFIED, "isBlocked", false], + [ProfileStatus::VERIFIED, "isVerified", true], + [ProfileStatus::VERIFIED, "isUnverified", false], - [ProfileStatus::STATUS_UNVERIFIED, "isBlocked", false], - [ProfileStatus::STATUS_UNVERIFIED, "isVerified", false], - [ProfileStatus::STATUS_UNVERIFIED, "isUnverified", true], + [ProfileStatus::UNVERIFIED, "isBlocked", false], + [ProfileStatus::UNVERIFIED, "isVerified", false], + [ProfileStatus::UNVERIFIED, "isUnverified", true], ]; } } diff --git a/tests/Mollie/API/Resources/RefundTest.php b/tests/Mollie/API/Resources/RefundTest.php index 7ea14163b..1f95bb39d 100644 --- a/tests/Mollie/API/Resources/RefundTest.php +++ b/tests/Mollie/API/Resources/RefundTest.php @@ -40,47 +40,47 @@ public function testRefundCanBeCanceled($status, $expected_boolean) public function dpTestRefundStatuses() { return [ - [RefundStatus::STATUS_PENDING, "isPending", true], - [RefundStatus::STATUS_PENDING, "isProcessing", false], - [RefundStatus::STATUS_PENDING, "isQueued", false], - [RefundStatus::STATUS_PENDING, "isTransferred", false], - [RefundStatus::STATUS_PENDING, "isFailed", false], + [RefundStatus::PENDING, "isPending", true], + [RefundStatus::PENDING, "isProcessing", false], + [RefundStatus::PENDING, "isQueued", false], + [RefundStatus::PENDING, "isTransferred", false], + [RefundStatus::PENDING, "isFailed", false], - [RefundStatus::STATUS_PROCESSING, "isPending", false], - [RefundStatus::STATUS_PROCESSING, "isProcessing", true], - [RefundStatus::STATUS_PROCESSING, "isQueued", false], - [RefundStatus::STATUS_PROCESSING, "isTransferred", false], - [RefundStatus::STATUS_PROCESSING, "isFailed", false], + [RefundStatus::PROCESSING, "isPending", false], + [RefundStatus::PROCESSING, "isProcessing", true], + [RefundStatus::PROCESSING, "isQueued", false], + [RefundStatus::PROCESSING, "isTransferred", false], + [RefundStatus::PROCESSING, "isFailed", false], - [RefundStatus::STATUS_QUEUED, "isPending", false], - [RefundStatus::STATUS_QUEUED, "isProcessing", false], - [RefundStatus::STATUS_QUEUED, "isQueued", true], - [RefundStatus::STATUS_QUEUED, "isTransferred", false], - [RefundStatus::STATUS_QUEUED, "isFailed", false], + [RefundStatus::QUEUED, "isPending", false], + [RefundStatus::QUEUED, "isProcessing", false], + [RefundStatus::QUEUED, "isQueued", true], + [RefundStatus::QUEUED, "isTransferred", false], + [RefundStatus::QUEUED, "isFailed", false], - [RefundStatus::STATUS_REFUNDED, "isPending", false], - [RefundStatus::STATUS_REFUNDED, "isProcessing", false], - [RefundStatus::STATUS_REFUNDED, "isQueued", false], - [RefundStatus::STATUS_REFUNDED, "isTransferred", true], - [RefundStatus::STATUS_REFUNDED, "isFailed", false], + [RefundStatus::REFUNDED, "isPending", false], + [RefundStatus::REFUNDED, "isProcessing", false], + [RefundStatus::REFUNDED, "isQueued", false], + [RefundStatus::REFUNDED, "isTransferred", true], + [RefundStatus::REFUNDED, "isFailed", false], - [RefundStatus::STATUS_FAILED, "isPending", false], - [RefundStatus::STATUS_FAILED, "isProcessing", false], - [RefundStatus::STATUS_FAILED, "isQueued", false], - [RefundStatus::STATUS_FAILED, "isTransferred", false], - [RefundStatus::STATUS_FAILED, "isFailed", true], + [RefundStatus::FAILED, "isPending", false], + [RefundStatus::FAILED, "isProcessing", false], + [RefundStatus::FAILED, "isQueued", false], + [RefundStatus::FAILED, "isTransferred", false], + [RefundStatus::FAILED, "isFailed", true], ]; } public function dpTestRefundCanBeCanceled() { return [ - [RefundStatus::STATUS_PENDING, true], - [RefundStatus::STATUS_PROCESSING, false], - [RefundStatus::STATUS_QUEUED, true], - [RefundStatus::STATUS_REFUNDED, false], - [RefundStatus::STATUS_FAILED, false], - [RefundStatus::STATUS_CANCELED, false], + [RefundStatus::PENDING, true], + [RefundStatus::PROCESSING, false], + [RefundStatus::QUEUED, true], + [RefundStatus::REFUNDED, false], + [RefundStatus::FAILED, false], + [RefundStatus::CANCELED, false], ]; } } diff --git a/tests/Mollie/API/Resources/SettlementTest.php b/tests/Mollie/API/Resources/SettlementTest.php index 85c0c5597..060b81c5b 100644 --- a/tests/Mollie/API/Resources/SettlementTest.php +++ b/tests/Mollie/API/Resources/SettlementTest.php @@ -26,25 +26,25 @@ public function testSettlementStatuses($status, $function, $expected_boolean) public function dpTestSettlementStatuses() { return [ - [SettlementStatus::STATUS_PENDING, "isPending", true], - [SettlementStatus::STATUS_PENDING, "isOpen", false], - [SettlementStatus::STATUS_PENDING, "isPaidout", false], - [SettlementStatus::STATUS_PENDING, "isFailed", false], - - [SettlementStatus::STATUS_OPEN, "isPending", false], - [SettlementStatus::STATUS_OPEN, "isOpen", true], - [SettlementStatus::STATUS_OPEN, "isPaidout", false], - [SettlementStatus::STATUS_OPEN, "isFailed", false], - - [SettlementStatus::STATUS_PAIDOUT, "isPending", false], - [SettlementStatus::STATUS_PAIDOUT, "isOpen", false], - [SettlementStatus::STATUS_PAIDOUT, "isPaidout", true], - [SettlementStatus::STATUS_PAIDOUT, "isFailed", false], - - [SettlementStatus::STATUS_FAILED, "isPending", false], - [SettlementStatus::STATUS_FAILED, "isOpen", false], - [SettlementStatus::STATUS_FAILED, "isPaidout", false], - [SettlementStatus::STATUS_FAILED, "isFailed", true], + [SettlementStatus::PENDING, "isPending", true], + [SettlementStatus::PENDING, "isOpen", false], + [SettlementStatus::PENDING, "isPaidout", false], + [SettlementStatus::PENDING, "isFailed", false], + + [SettlementStatus::OPEN, "isPending", false], + [SettlementStatus::OPEN, "isOpen", true], + [SettlementStatus::OPEN, "isPaidout", false], + [SettlementStatus::OPEN, "isFailed", false], + + [SettlementStatus::PAIDOUT, "isPending", false], + [SettlementStatus::PAIDOUT, "isOpen", false], + [SettlementStatus::PAIDOUT, "isPaidout", true], + [SettlementStatus::PAIDOUT, "isFailed", false], + + [SettlementStatus::FAILED, "isPending", false], + [SettlementStatus::FAILED, "isOpen", false], + [SettlementStatus::FAILED, "isPaidout", false], + [SettlementStatus::FAILED, "isFailed", true], ]; } } diff --git a/tests/Mollie/API/Resources/SubscriptionTest.php b/tests/Mollie/API/Resources/SubscriptionTest.php index c5e6bd518..9f5fb08b5 100644 --- a/tests/Mollie/API/Resources/SubscriptionTest.php +++ b/tests/Mollie/API/Resources/SubscriptionTest.php @@ -26,35 +26,35 @@ public function testSubscriptionStatuses($status, $function, $expected_boolean) public function dpTestSubscriptionStatuses() { return [ - [SubscriptionStatus::STATUS_PENDING, "isPending", true], - [SubscriptionStatus::STATUS_PENDING, "isCanceled", false], - [SubscriptionStatus::STATUS_PENDING, "isCompleted", false], - [SubscriptionStatus::STATUS_PENDING, "isSuspended", false], - [SubscriptionStatus::STATUS_PENDING, "isActive", false], - - [SubscriptionStatus::STATUS_CANCELED, "isPending", false], - [SubscriptionStatus::STATUS_CANCELED, "isCanceled", true], - [SubscriptionStatus::STATUS_CANCELED, "isCompleted", false], - [SubscriptionStatus::STATUS_CANCELED, "isSuspended", false], - [SubscriptionStatus::STATUS_CANCELED, "isActive", false], - - [SubscriptionStatus::STATUS_COMPLETED, "isPending", false], - [SubscriptionStatus::STATUS_COMPLETED, "isCanceled", false], - [SubscriptionStatus::STATUS_COMPLETED, "isCompleted", true], - [SubscriptionStatus::STATUS_COMPLETED, "isSuspended", false], - [SubscriptionStatus::STATUS_COMPLETED, "isActive", false], - - [SubscriptionStatus::STATUS_SUSPENDED, "isPending", false], - [SubscriptionStatus::STATUS_SUSPENDED, "isCanceled", false], - [SubscriptionStatus::STATUS_SUSPENDED, "isCompleted", false], - [SubscriptionStatus::STATUS_SUSPENDED, "isSuspended", true], - [SubscriptionStatus::STATUS_SUSPENDED, "isActive", false], - - [SubscriptionStatus::STATUS_ACTIVE, "isPending", false], - [SubscriptionStatus::STATUS_ACTIVE, "isCanceled", false], - [SubscriptionStatus::STATUS_ACTIVE, "isCompleted", false], - [SubscriptionStatus::STATUS_ACTIVE, "isSuspended", false], - [SubscriptionStatus::STATUS_ACTIVE, "isActive", true], + [SubscriptionStatus::PENDING, "isPending", true], + [SubscriptionStatus::PENDING, "isCanceled", false], + [SubscriptionStatus::PENDING, "isCompleted", false], + [SubscriptionStatus::PENDING, "isSuspended", false], + [SubscriptionStatus::PENDING, "isActive", false], + + [SubscriptionStatus::CANCELED, "isPending", false], + [SubscriptionStatus::CANCELED, "isCanceled", true], + [SubscriptionStatus::CANCELED, "isCompleted", false], + [SubscriptionStatus::CANCELED, "isSuspended", false], + [SubscriptionStatus::CANCELED, "isActive", false], + + [SubscriptionStatus::COMPLETED, "isPending", false], + [SubscriptionStatus::COMPLETED, "isCanceled", false], + [SubscriptionStatus::COMPLETED, "isCompleted", true], + [SubscriptionStatus::COMPLETED, "isSuspended", false], + [SubscriptionStatus::COMPLETED, "isActive", false], + + [SubscriptionStatus::SUSPENDED, "isPending", false], + [SubscriptionStatus::SUSPENDED, "isCanceled", false], + [SubscriptionStatus::SUSPENDED, "isCompleted", false], + [SubscriptionStatus::SUSPENDED, "isSuspended", true], + [SubscriptionStatus::SUSPENDED, "isActive", false], + + [SubscriptionStatus::ACTIVE, "isPending", false], + [SubscriptionStatus::ACTIVE, "isCanceled", false], + [SubscriptionStatus::ACTIVE, "isCompleted", false], + [SubscriptionStatus::ACTIVE, "isSuspended", false], + [SubscriptionStatus::ACTIVE, "isActive", true], ]; } } From ac55229c9dc6d25a96f86b5c35188711f3421ef1 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 24 Jun 2024 22:06:21 +0200 Subject: [PATCH 010/131] wip --- .github/workflows/tests.yml | 6 +++--- composer.json | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 208a66b57..c4b3b3dd1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,14 +3,14 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" jobs: tests: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3] + php: [7.4, 8.0, 8.1, 8.2, 8.3] name: PHP - ${{ matrix.php }} steps: - name: Checkout code @@ -31,4 +31,4 @@ jobs: composer require "phpstan/phpstan:1.9.2" vendor/bin/phpstan analyse --no-progress - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/paratest --verbose diff --git a/composer.json b/composer.json index 20193917b..c1296d2a1 100644 --- a/composer.json +++ b/composer.json @@ -54,6 +54,7 @@ "composer/ca-bundle": "^1.4" }, "require-dev": { + "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", "phpstan/phpstan": "^1.10", From 29200907ecda65ad0d4f6d92fa9433c31d51b12f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 25 Jun 2024 00:33:39 +0200 Subject: [PATCH 011/131] wip --- examples/captures/create-capture.php | 15 +- .../create-customer-first-payment.php | 2 +- .../customers/create-customer-payment.php | 2 +- .../create-customer-recurring-payment.php | 2 +- examples/customers/list-customer-payments.php | 2 +- examples/mandates/create-mandate.php | 2 +- examples/orders/list-orders.php | 6 +- examples/pagination/backwards.php | 6 +- examples/pagination/basic_usage.php | 6 +- examples/payment-links/list-payment-links.php | 2 +- examples/payments/create-payment-oauth.php | 4 +- examples/payments/list-payments.php | 4 +- examples/profiles/list-profiles.php | 2 +- examples/settlements/list-settlements.php | 2 +- .../subscriptions/cancel-subscription.php | 2 +- .../subscriptions/create-subscription.php | 2 +- src/CompatibilityChecker.php | 6 +- src/Contracts/SupportsDebugging.php | 20 + src/Endpoints/BalanceEndpoint.php | 10 +- src/Endpoints/BalanceTransactionEndpoint.php | 8 +- src/Endpoints/ChargebackEndpoint.php | 6 +- src/Endpoints/ClientEndpoint.php | 8 +- src/Endpoints/ClientLinkEndpoint.php | 2 +- src/Endpoints/CustomerEndpoint.php | 14 +- src/Endpoints/CustomerPaymentsEndpoint.php | 6 +- src/Endpoints/EndpointCollection.php | 10 +- src/Endpoints/InvoiceEndpoint.php | 10 +- src/Endpoints/MandateEndpoint.php | 10 +- src/Endpoints/MethodEndpoint.php | 4 +- src/Endpoints/OnboardingEndpoint.php | 2 +- src/Endpoints/OrderEndpoint.php | 14 +- src/Endpoints/OrderLineEndpoint.php | 4 +- src/Endpoints/OrderPaymentEndpoint.php | 2 +- src/Endpoints/OrderRefundEndpoint.php | 4 +- src/Endpoints/OrganizationEndpoint.php | 4 +- src/Endpoints/OrganizationPartnerEndpoint.php | 2 +- src/Endpoints/PaymentCaptureEndpoint.php | 8 +- src/Endpoints/PaymentChargebackEndpoint.php | 6 +- src/Endpoints/PaymentEndpoint.php | 14 +- src/Endpoints/PaymentLinkEndpoint.php | 10 +- src/Endpoints/PaymentRefundEndpoint.php | 8 +- src/Endpoints/PaymentRouteEndpoint.php | 2 +- src/Endpoints/PermissionEndpoint.php | 4 +- src/Endpoints/ProfileEndpoint.php | 16 +- src/Endpoints/ProfileMethodEndpoint.php | 2 +- src/Endpoints/RefundEndpoint.php | 6 +- src/Endpoints/RestEndpoint.php | 10 +- src/Endpoints/SettlementCaptureEndpoint.php | 4 +- .../SettlementChargebackEndpoint.php | 4 +- src/Endpoints/SettlementPaymentEndpoint.php | 4 +- src/Endpoints/SettlementRefundEndpoint.php | 4 +- src/Endpoints/SettlementsEndpoint.php | 12 +- src/Endpoints/ShipmentEndpoint.php | 8 +- src/Endpoints/SubscriptionEndpoint.php | 18 +- src/Endpoints/TerminalEndpoint.php | 8 +- src/HandlesDebugging.php | 54 ++ src/HandlesIdempotency.php | 126 ++++ src/HttpAdapter/CurlMollieHttpAdapter.php | 8 +- .../Guzzle6And7MollieHttpAdapter.php | 67 +- src/HttpAdapter/IsDebuggable.php | 51 ++ .../MollieHttpAdapterInterface.php | 6 +- src/HttpAdapter/PSR18MollieHttpAdapter.php | 4 +- src/MollieApiClient.php | 673 +++++------------- src/Resources/BaseCollection.php | 7 +- src/Resources/BaseResource.php | 5 +- src/Resources/CursorCollection.php | 21 +- src/Resources/Customer.php | 6 +- .../API/Endpoints/BalanceEndpointTest.php | 2 +- .../API/Endpoints/ChargebackEndpointTest.php | 2 +- .../API/Endpoints/ClientEndpointTest.php | 4 +- .../API/Endpoints/CustomerEndpointTest.php | 2 +- .../API/Endpoints/InvoiceEndpointTest.php | 2 +- .../API/Endpoints/OrderEndpointTest.php | 2 +- .../API/Endpoints/PaymentEndpointTest.php | 2 +- .../API/Endpoints/ProfileEndpointTest.php | 2 +- .../API/Endpoints/RefundEndpointTest.php | 2 +- .../API/Endpoints/SettlementEndpointTest.php | 2 +- .../Endpoints/SubscriptionEndpointTest.php | 2 +- .../API/Endpoints/TerminalEndpointTest.php | 2 +- .../Guzzle6And7MollieHttpAdapterTest.php | 11 +- .../API/HttpAdapter/MockMollieHttpAdapter.php | 4 +- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 13 +- 82 files changed, 652 insertions(+), 785 deletions(-) create mode 100644 src/Contracts/SupportsDebugging.php create mode 100644 src/HandlesDebugging.php create mode 100644 src/HandlesIdempotency.php create mode 100644 src/HttpAdapter/IsDebuggable.php diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index a51030ea8..bb7332b9c 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -17,13 +17,14 @@ * description Description of the capture. * metadata Custom metadata that is stored with the payment. */ - $capture = $mollie->paymentCaptures->createForId('tr_WDqYK6vllg', [ - "amount" => [ - "currency" => "EUR", - "value" => "5.00", - ], - "description" => "Order #12345", - ]); + $capture = $mollie + ->paymentCaptures->createForId('tr_WDqYK6vllg', [ + "amount" => [ + "currency" => "EUR", + "value" => "5.00", + ], + "description" => "Order #12345", + ]); echo "

New capture created " . htmlspecialchars($capture->id) . " (" . htmlspecialchars($capture->description) . ").

"; } catch (\Mollie\Api\Exceptions\ApiException $e) { diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index d232b4ae9..05d340415 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -13,7 +13,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run the create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute diff --git a/examples/customers/create-customer-payment.php b/examples/customers/create-customer-payment.php index 5713dd18d..f02aab07f 100644 --- a/examples/customers/create-customer-payment.php +++ b/examples/customers/create-customer-payment.php @@ -13,7 +13,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute diff --git a/examples/customers/create-customer-recurring-payment.php b/examples/customers/create-customer-recurring-payment.php index 500581000..812026b00 100644 --- a/examples/customers/create-customer-recurring-payment.php +++ b/examples/customers/create-customer-recurring-payment.php @@ -13,7 +13,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run the create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Generate a unique order id for this example. diff --git a/examples/customers/list-customer-payments.php b/examples/customers/list-customer-payments.php index ae7329baa..9325f56e0 100644 --- a/examples/customers/list-customer-payments.php +++ b/examples/customers/list-customer-payments.php @@ -21,7 +21,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Get the all payments for this API key ordered by newest. diff --git a/examples/mandates/create-mandate.php b/examples/mandates/create-mandate.php index b628e9255..316ba47ac 100644 --- a/examples/mandates/create-mandate.php +++ b/examples/mandates/create-mandate.php @@ -13,7 +13,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Create a SEPA Direct Debit mandate for the customer diff --git a/examples/orders/list-orders.php b/examples/orders/list-orders.php index e311b16e4..01076935d 100644 --- a/examples/orders/list-orders.php +++ b/examples/orders/list-orders.php @@ -16,7 +16,7 @@ * See: https://docs.mollie.com/reference/v2/orders-api/list-orders */ echo '
    '; - $latestOrders = $mollie->orders->page(); + $latestOrders = $mollie->orders->collect(); printOrders($latestOrders); $previousOrders = $latestOrders->next(); @@ -29,7 +29,7 @@ function printOrders($orders) { if (empty($orders)) { - return ; + return; } foreach ($orders as $order) { @@ -42,7 +42,7 @@ function printOrders($orders) echo '' . htmlspecialchars($order->amount->currency) . str_replace('.', ',', htmlspecialchars($order->amount->value)) . ''; echo ''; echo ''; - echo 'Click here to pay'; + echo 'Click here to pay'; echo ''; } } diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index 35aa63631..582f92610 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -37,11 +37,11 @@ $orderId = 'ord_8wmqcHMN4U'; // cursor paginating backwards through all orders - $page = $mollie->orders->page($orderId); + $page = $mollie->orders->collect($orderId); while ($page->hasPrevious()) { foreach ($page as $order) { - echo($order->id); + echo ($order->id); } $page = $page->previous(); @@ -50,7 +50,7 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) foreach ($mollie->orders->iterator(null, null, [], true) as $order) { - echo($order->id); + echo ($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index 3e927ca86..c7f708661 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -36,11 +36,11 @@ // cursor paginating through all orders - $page = $mollie->orders->page(); + $page = $mollie->orders->collect(); while ($page->hasNext()) { foreach ($page as $order) { - echo($order->id); + echo ($order->id); } $page = $page->next(); @@ -49,7 +49,7 @@ // using the iterator we can iterate over all orders directly foreach ($mollie->orders->iterator() as $order) { - echo($order->id); + echo ($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/payment-links/list-payment-links.php b/examples/payment-links/list-payment-links.php index b39c56cc5..df7d3ce84 100644 --- a/examples/payment-links/list-payment-links.php +++ b/examples/payment-links/list-payment-links.php @@ -21,7 +21,7 @@ /* * Get the all payments for this API key ordered by newest. */ - $paymentLinks = $mollie->paymentLinks->page(); + $paymentLinks = $mollie->paymentLinks->collect(); echo "
      "; foreach ($paymentLinks as $paymentLink) { diff --git a/examples/payments/create-payment-oauth.php b/examples/payments/create-payment-oauth.php index b601029b9..d1dd34779 100644 --- a/examples/payments/create-payment-oauth.php +++ b/examples/payments/create-payment-oauth.php @@ -16,13 +16,13 @@ * Determine the url parts to these example files. */ $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; - $hostname = $_SERVER['HTTP_HOST'] ? : "my.app"; + $hostname = $_SERVER['HTTP_HOST'] ?: "my.app"; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); /* * Since unlike an API key the OAuth access token does NOT belong to a profile, we need to retrieve a profile * so we can specify the profileId-parameter when creating a payment below. */ - $profiles = $mollie->profiles->page(); + $profiles = $mollie->profiles->collect(); $profile = reset($profiles); /** diff --git a/examples/payments/list-payments.php b/examples/payments/list-payments.php index 2d5fce084..d5b48e804 100644 --- a/examples/payments/list-payments.php +++ b/examples/payments/list-payments.php @@ -21,7 +21,7 @@ /* * Get the all payments for this API key ordered by newest. */ - $payments = $mollie->payments->page(); + $payments = $mollie->payments->collect(); echo "
        "; foreach ($payments as $payment) { @@ -53,7 +53,7 @@ */ $nextPayments = $payments->next(); - if (! empty($nextPayments)) { + if (!empty($nextPayments)) { echo "
          "; foreach ($nextPayments as $payment) { echo "
        • "; diff --git a/examples/profiles/list-profiles.php b/examples/profiles/list-profiles.php index 49a88d6dc..8323f0366 100644 --- a/examples/profiles/list-profiles.php +++ b/examples/profiles/list-profiles.php @@ -11,7 +11,7 @@ /* * Get the all the profiles for this account. */ - $profiles = $mollie->profiles->page(); + $profiles = $mollie->profiles->collect(); foreach ($profiles as $profile) { echo '
          '; echo htmlspecialchars($profile->name) . diff --git a/examples/settlements/list-settlements.php b/examples/settlements/list-settlements.php index cc93c893f..9938acd07 100644 --- a/examples/settlements/list-settlements.php +++ b/examples/settlements/list-settlements.php @@ -12,7 +12,7 @@ /* * Get the all the settlements for this account. */ - $settlements = $mollie->settlements->page(); + $settlements = $mollie->settlements->collect(); echo '
            '; foreach ($settlements as $settlement) { echo '
          • Settlement ' . htmlspecialchars($settlement->reference) . ': (' . htmlspecialchars($settlement->createdAt) . ')'; diff --git a/examples/subscriptions/cancel-subscription.php b/examples/subscriptions/cancel-subscription.php index 0ef515256..c7cd11821 100644 --- a/examples/subscriptions/cancel-subscription.php +++ b/examples/subscriptions/cancel-subscription.php @@ -13,7 +13,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run the create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * The subscription ID, starting with sub_ diff --git a/examples/subscriptions/create-subscription.php b/examples/subscriptions/create-subscription.php index 83ac4e886..9df37f301 100644 --- a/examples/subscriptions/create-subscription.php +++ b/examples/subscriptions/create-subscription.php @@ -20,7 +20,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run create-customer example. */ - $customer = $mollie->customers->page(null, 1)[0]; + $customer = $mollie->customers->collect(null, 1)[0]; /* * Generate a unique subscription id for this example. It is important to include this unique attribute diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index b754b2116..3ab386976 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -9,7 +9,7 @@ class CompatibilityChecker /** * @var string */ - public const MIN_PHP_VERSION = "7.2"; + public const MIN_PHP_VERSION = "7.4"; /** * @throws IncompatiblePlatform @@ -17,14 +17,14 @@ class CompatibilityChecker */ public function checkCompatibility() { - if (! $this->satisfiesPhpVersion()) { + if (!$this->satisfiesPhpVersion()) { throw new IncompatiblePlatform( "The client requires PHP version >= " . self::MIN_PHP_VERSION . ", you have " . PHP_VERSION . ".", IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION ); } - if (! $this->satisfiesJsonExtension()) { + if (!$this->satisfiesJsonExtension()) { throw new IncompatiblePlatform( "PHP extension json is not enabled. Please make sure to enable 'json' in your PHP configuration.", IncompatiblePlatform::INCOMPATIBLE_JSON_EXTENSION diff --git a/src/Contracts/SupportsDebugging.php b/src/Contracts/SupportsDebugging.php new file mode 100644 index 000000000..bb4d934d0 --- /dev/null +++ b/src/Contracts/SupportsDebugging.php @@ -0,0 +1,20 @@ +rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -89,6 +89,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 52a18ea1b..d33fd9a05 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -72,7 +72,7 @@ public function listForId(string $balanceId, array $parameters = []): BalanceTra { $this->parentId = $balanceId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -88,7 +88,7 @@ public function iteratorForId(string $balanceId, array $parameters = [], bool $i { $this->parentId = $balanceId; - return $this->rest_iterator(null, null, $parameters, $iterateBackwards); + return $this->createIterator(null, null, $parameters, $iterateBackwards); } /** @@ -103,7 +103,7 @@ public function listForPrimary(array $parameters = []): BalanceTransactionCollec { $this->parentId = "primary"; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -118,6 +118,6 @@ public function iteratorForPrimary(array $parameters = [], bool $iterateBackward { $this->parentId = "primary"; - return $this->rest_iterator(null, null, $parameters, $iterateBackwards); + return $this->createIterator(null, null, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index 31c0e375a..a567d9bca 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -37,9 +37,9 @@ protected function getResourceCollectionObject(int $count, object $_links): Char * @return ChargebackCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -54,6 +54,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 66cfaf294..bb264bcda 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -45,7 +45,7 @@ public function get(string $clientId, array $parameters = []): Client throw new ApiException("Client ID is empty."); } - return parent::rest_read($clientId, $parameters); + return parent::readResource($clientId, $parameters); } /** @@ -58,9 +58,9 @@ public function get(string $clientId, array $parameters = []): Client * @return ClientCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -75,6 +75,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 6c68726fa..4d96f74d4 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -32,6 +32,6 @@ protected function getResourceObject(): ClientLink */ public function create(array $data = []): ClientLink { - return $this->rest_create($data, []); + return $this->createResource($data, []); } } diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 2ee9d4207..6107ee799 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -40,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Cust */ public function create(array $data = [], array $filters = []): Customer { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -55,7 +55,7 @@ public function create(array $data = [], array $filters = []): Customer */ public function get(string $customerId, array $parameters = []): Customer { - return $this->rest_read($customerId, $parameters); + return $this->readResource($customerId, $parameters); } /** @@ -74,7 +74,7 @@ public function update(string $customerId, array $data = []): Customer throw new ApiException("Invalid order ID: '{$customerId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_update($customerId, $data); + return parent::updateResource($customerId, $data); } /** @@ -90,7 +90,7 @@ public function update(string $customerId, array $data = []): Customer */ public function delete(string $customerId, array $data = []): ?Customer { - return $this->rest_delete($customerId, $data); + return $this->deleteResource($customerId, $data); } /** @@ -103,9 +103,9 @@ public function delete(string $customerId, array $data = []): ?Customer * @return CustomerCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -120,6 +120,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index 0469beeb4..010af19cc 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -56,7 +56,7 @@ public function createForId($customerId, array $options = [], array $filters = [ { $this->parentId = $customerId; - return parent::rest_create($options, $filters); + return parent::createResource($options, $filters); } /** @@ -107,7 +107,7 @@ public function listForId(string $customerId, ?string $from = null, ?int $limit { $this->parentId = $customerId; - return parent::rest_list($from, $limit, $parameters); + return parent::fetchCollection($from, $limit, $parameters); } /** @@ -130,6 +130,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $customerId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php index 105ac9829..1c1a079f8 100644 --- a/src/Endpoints/EndpointCollection.php +++ b/src/Endpoints/EndpointCollection.php @@ -20,7 +20,7 @@ abstract class EndpointCollection extends RestEndpoint * @return BaseCollection * @throws ApiException */ - protected function rest_list(?string $from = null, ?int $limit = null, array $filters = []): BaseCollection + protected function fetchCollection(?string $from = null, ?int $limit = null, array $filters = []): BaseCollection { $apiPath = $this->getResourcePath() . $this->buildQueryString( $this->getMergedFilters($filters, $from, $limit) @@ -31,7 +31,7 @@ protected function rest_list(?string $from = null, ?int $limit = null, array $fi $apiPath ); - return $this->createCollectionFromResult($result); + return $this->buildResultCollection($result); } /** @@ -47,10 +47,10 @@ protected function rest_list(?string $from = null, ?int $limit = null, array $fi * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * @return LazyCollection */ - protected function rest_iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + protected function createIterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { /** @var CursorCollection $page */ - $page = $this->rest_list($from, $limit, $filters); + $page = $this->fetchCollection($from, $limit, $filters); return $page->getAutoIterator($iterateBackwards); } @@ -60,7 +60,7 @@ protected function getMergedFilters(array $filters = [], ?string $from = null, ? return array_merge(["from" => $from, "limit" => $limit], $filters); } - protected function createCollectionFromResult(object $result): BaseCollection + protected function buildResultCollection(object $result): BaseCollection { /** @var BaseCollection $collection */ $collection = $this->getResourceCollectionObject($result->count, $result->_links); diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index 6cc8a0eab..b77a6e7c7 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -40,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Invo */ public function get(string $invoiceId, array $parameters = []): Invoice { - return $this->rest_read($invoiceId, $parameters); + return $this->readResource($invoiceId, $parameters); } /** @@ -53,9 +53,9 @@ public function get(string $invoiceId, array $parameters = []): Invoice * @return InvoiceCollection * @throws ApiException */ - public function page(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection + public function collect(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -68,7 +68,7 @@ public function page(string $from = null, int $limit = null, array $parameters = */ public function all(array $parameters = []): InvoiceCollection { - return $this->page(null, null, $parameters); + return $this->collect(null, null, $parameters); } /** @@ -83,6 +83,6 @@ public function all(array $parameters = []): InvoiceCollection */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index ee26a3f02..4634067f5 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -52,7 +52,7 @@ public function createForId(string $customerId, array $options = [], array $filt { $this->parentId = $customerId; - return parent::rest_create($options, $filters); + return parent::createResource($options, $filters); } /** @@ -80,7 +80,7 @@ public function getForId(string $customerId, $mandateId, array $parameters = []) { $this->parentId = $customerId; - return parent::rest_read($mandateId, $parameters); + return parent::readResource($mandateId, $parameters); } /** @@ -131,7 +131,7 @@ public function listForId(string $customerId, ?string $from = null, ?int $limit { $this->parentId = $customerId; - return parent::rest_list($from, $limit, $parameters); + return parent::fetchCollection($from, $limit, $parameters); } /** @@ -154,7 +154,7 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $customerId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } /** @@ -182,6 +182,6 @@ public function revokeForId(string $customerId, string $mandateId, array $data = { $this->parentId = $customerId; - return parent::rest_delete($mandateId, $data); + return parent::deleteResource($mandateId, $data); } } diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 72643e63d..74872bc4f 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -52,7 +52,7 @@ public function all(array $parameters = []): MethodCollection */ public function allActive(array $parameters = []): MethodCollection { - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -93,6 +93,6 @@ public function get(string $methodId, array $parameters = []): Method throw new ApiException("Method ID is empty."); } - return parent::rest_read($methodId, $parameters); + return parent::readResource($methodId, $parameters); } } diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 639658df5..9e4386fd9 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -28,7 +28,7 @@ protected function getResourceObject(): Onboarding */ public function get(): Onboarding { - return $this->rest_read('', []); + return $this->readResource('', []); } /** diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index d064edfd6..cb8e00505 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -40,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Orde */ public function create(array $data = [], array $filters = []): Order { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -60,7 +60,7 @@ public function update(string $orderId, array $data = []): Order throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_update($orderId, $data); + return parent::updateResource($orderId, $data); } /** @@ -80,7 +80,7 @@ public function get(string $orderId, array $parameters = []): Order throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_read($orderId, $parameters); + return parent::readResource($orderId, $parameters); } /** @@ -100,7 +100,7 @@ public function get(string $orderId, array $parameters = []): Order */ public function cancel(string $orderId, $parameters = []): ?Order { - return $this->rest_delete($orderId, $parameters); + return $this->deleteResource($orderId, $parameters); } /** @@ -113,9 +113,9 @@ public function cancel(string $orderId, $parameters = []): ?Order * @return OrderCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -130,6 +130,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 52ba3badf..d4273c97d 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -50,7 +50,7 @@ public function update(string $orderId, string $orderlineId, array $data = []): throw new ApiException("Invalid order line ID: '{$orderlineId}'. An order line ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_update($orderlineId, $data); + return parent::updateResource($orderlineId, $data); } /** @@ -109,7 +109,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (! isset($data['lines']) || ! is_array($data['lines'])) { + if (!isset($data['lines']) || !is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index d661b9d5f..1f0d754f8 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -57,6 +57,6 @@ public function createForId(string $orderId, array $data, array $filters = []): { $this->parentId = $orderId; - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } } diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index 5fc0bfe95..06611423e 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -57,7 +57,7 @@ public function createForId(string $orderId, array $data, array $filters = []): { $this->parentId = $orderId; - return parent::rest_create($data, $filters); + return parent::createResource($data, $filters); } /** @@ -70,7 +70,7 @@ public function pageForId($orderId, array $parameters = []) { $this->parentId = $orderId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index 9403dcb00..5c5d6c784 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -34,7 +34,7 @@ public function get(string $organizationId, array $parameters = []): Organizatio throw new ApiException("Organization ID is empty."); } - return parent::rest_read($organizationId, $parameters); + return parent::readResource($organizationId, $parameters); } /** @@ -47,6 +47,6 @@ public function get(string $organizationId, array $parameters = []): Organizatio */ public function current(array $parameters = []): Organization { - return parent::rest_read('me', $parameters); + return parent::readResource('me', $parameters); } } diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index a82e86ea2..33a2f46a1 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -28,6 +28,6 @@ protected function getResourceObject(): Partner */ public function get(): Partner { - return $this->rest_read('', []); + return $this->readResource('', []); } } diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 2d896a460..25aebdd8d 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -56,7 +56,7 @@ public function createForId(string $paymentId, array $data = [], array $filters { $this->parentId = $paymentId; - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -84,7 +84,7 @@ public function getForId(string $paymentId, string $captureId, array $parameters { $this->parentId = $paymentId; - return parent::rest_read($captureId, $parameters); + return parent::readResource($captureId, $parameters); } /** @@ -131,7 +131,7 @@ public function listForId(string $paymentId, array $parameters = []): CaptureCol { $this->parentId = $paymentId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -154,6 +154,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $paymentId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index b28ca54e1..c77a46d9f 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -52,7 +52,7 @@ public function getForId(string $paymentId, string $chargebackId, array $paramet { $this->parentId = $paymentId; - return parent::rest_read($chargebackId, $parameters); + return parent::readResource($chargebackId, $parameters); } /** @@ -99,7 +99,7 @@ public function listForId(string $paymentId, array $parameters = []): Chargeback { $this->parentId = $paymentId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -122,6 +122,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $paymentId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 66e50a06e..4e1db7130 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -41,7 +41,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Paym */ public function create(array $data = [], array $filters = []): Payment { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -61,7 +61,7 @@ public function update($paymentId, array $data = []): Payment throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_update($paymentId, $data); + return parent::updateResource($paymentId, $data); } /** @@ -81,7 +81,7 @@ public function get($paymentId, array $parameters = []): Payment throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_read($paymentId, $parameters); + return parent::readResource($paymentId, $parameters); } /** @@ -115,7 +115,7 @@ public function delete(string $paymentId, array $data = []): ?Payment */ public function cancel(string $paymentId, array $data = []): ?Payment { - return $this->rest_delete($paymentId, $data); + return $this->deleteResource($paymentId, $data); } /** @@ -128,9 +128,9 @@ public function cancel(string $paymentId, array $data = []): ?Payment * @return PaymentCollection * @throws ApiException */ - public function page(string $from = null, int $limit = null, array $parameters = []): PaymentCollection + public function collect(string $from = null, int $limit = null, array $parameters = []): PaymentCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -145,7 +145,7 @@ public function page(string $from = null, int $limit = null, array $parameters = */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } /** diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index d4df8a25e..c783c540c 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -40,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Paym */ public function create(array $data = [], array $filters = []): PaymentLink { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -59,7 +59,7 @@ public function get(string $paymentLinkId, array $parameters = []): PaymentLink throw new ApiException("Invalid payment link ID: '{$paymentLinkId}'. A payment link ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_read($paymentLinkId, $parameters); + return parent::readResource($paymentLinkId, $parameters); } /** @@ -72,9 +72,9 @@ public function get(string $paymentLinkId, array $parameters = []): PaymentLink * @return PaymentLinkCollection * @throws ApiException */ - public function page(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection + public function collect(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -89,6 +89,6 @@ public function page(string $from = null, int $limit = null, array $parameters = */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index f86fa69fc..1289c5d30 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -52,7 +52,7 @@ public function getForId(string $paymentId, $refundId, array $parameters = []): { $this->parentId = $paymentId; - return parent::rest_read($refundId, $parameters); + return parent::readResource($refundId, $parameters); } /** @@ -99,7 +99,7 @@ public function listForId(string $paymentId, array $parameters = []): RefundColl { $this->parentId = $paymentId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } /** @@ -122,7 +122,7 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $paymentId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } @@ -155,6 +155,6 @@ public function createForId(string $paymentId, array $data, array $filters = []) { $this->parentId = $paymentId; - return parent::rest_create($data, $filters); + return parent::createResource($data, $filters); } } diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index ced43f467..6fa64703d 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -44,7 +44,7 @@ public function updateReleaseDateForPaymentId(string $paymentId, string $routeId { $this->parentId = $paymentId; - return parent::rest_update($routeId, [ + return parent::updateResource($routeId, [ 'releaseDate' => $releaseDate, 'testmode' => $testmode, ]); diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index 6672332ed..e0de8aa59 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -38,7 +38,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Perm */ public function get(string $permissionId, array $parameters = []): Permission { - return $this->rest_read($permissionId, $parameters); + return $this->readResource($permissionId, $parameters); } /** @@ -51,6 +51,6 @@ public function get(string $permissionId, array $parameters = []): Permission */ public function all(array $parameters = []): PermissionCollection { - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } } diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index e25f46c55..c910ebcd9 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -42,7 +42,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Prof */ public function create(array $data = [], array $filters = []): Profile { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -62,7 +62,7 @@ public function get($profileId, array $parameters = []): Profile return $this->getCurrent($parameters); } - return $this->rest_read($profileId, $parameters); + return $this->readResource($profileId, $parameters); } /** @@ -81,7 +81,7 @@ public function update(string $profileId, array $data = []): Profile throw new ApiException("Invalid profile id: '{$profileId}'. An profile id should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_update($profileId, $data); + return parent::updateResource($profileId, $data); } /** @@ -96,7 +96,7 @@ public function getCurrent(array $parameters = []): CurrentProfile { $this->resourceClass = CurrentProfile::class; - return $this->rest_read('me', $parameters); + return $this->readResource('me', $parameters); } /** @@ -113,7 +113,7 @@ public function getCurrent(array $parameters = []): CurrentProfile */ public function delete($profileId, array $data = []): ?Profile { - return $this->rest_delete($profileId, $data); + return $this->deleteResource($profileId, $data); } /** @@ -126,9 +126,9 @@ public function delete($profileId, array $data = []): ?Profile * @return ProfileCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -147,6 +147,6 @@ public function iterator( array $parameters = [], bool $iterateBackwards = false ): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index b616ce5fe..0af5c6f59 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -93,7 +93,7 @@ public function deleteForId($profileId, $methodId, array $data = []): ?Method { $this->parentId = $profileId; - return $this->rest_delete($methodId, $data); + return $this->deleteResource($methodId, $data); } /** diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 673af6043..09b0d03c3 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -37,9 +37,9 @@ protected function getResourceCollectionObject(int $count, object $_links): Refu * @return RefundCollection * @throws ApiException */ - public function page(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection + public function collect(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -58,6 +58,6 @@ public function iterator( array $parameters = [], bool $iterateBackwards = false ): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index 284bc3ef1..daa4bce0f 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -15,7 +15,7 @@ abstract class RestEndpoint extends BaseEndpoint * @return BaseResource * @throws ApiException */ - protected function rest_create(array $body, array $filters): BaseResource + protected function createResource(array $body, array $filters): BaseResource { $result = $this->client->performHttpCall( self::REST_CREATE, @@ -35,7 +35,7 @@ protected function rest_create(array $body, array $filters): BaseResource * @return null|BaseResource * @throws ApiException */ - protected function rest_update(string $id, array $body = []): ?BaseResource + protected function updateResource(string $id, array $body = []): ?BaseResource { if (empty($id)) { throw new ApiException("Invalid resource id."); @@ -63,9 +63,9 @@ protected function rest_update(string $id, array $body = []): ?BaseResource * @return BaseResource * @throws ApiException */ - protected function rest_read(string $id, array $filters): BaseResource + protected function readResource(string $id, array $filters): BaseResource { - if (! $this instanceof SingleResourceEndpoint && empty($id)) { + if (!$this instanceof SingleResourceEndpoint && empty($id)) { throw new ApiException("Invalid resource id."); } @@ -87,7 +87,7 @@ protected function rest_read(string $id, array $filters): BaseResource * @return null|BaseResource * @throws ApiException */ - protected function rest_delete(string $id, array $body = []): ?BaseResource + protected function deleteResource(string $id, array $body = []): ?BaseResource { if (empty($id)) { throw new ApiException("Invalid resource id."); diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 70f162d9e..4d9b39870 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -43,7 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -66,6 +66,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $settlementId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 77de4403d..7b1adb37b 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -43,7 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -66,6 +66,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $settlementId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index 872bf7a87..e1a3f9ef6 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -41,7 +41,7 @@ public function pageForId($settlementId, ?string $from = null, ?int $limit = nul { $this->parentId = $settlementId; - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -64,6 +64,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $settlementId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index c7007f98c..409f99686 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -43,7 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -66,6 +66,6 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $settlementId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index d061d2784..05e273892 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -40,7 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Sett */ public function get(string $settlementId, array $parameters = []): Settlement { - return parent::rest_read($settlementId, $parameters); + return parent::readResource($settlementId, $parameters); } /** @@ -51,7 +51,7 @@ public function get(string $settlementId, array $parameters = []): Settlement */ public function next(): Settlement { - return parent::rest_read("next", []); + return parent::readResource("next", []); } /** @@ -62,7 +62,7 @@ public function next(): Settlement */ public function open(): Settlement { - return parent::rest_read("open", []); + return parent::readResource("open", []); } /** @@ -75,9 +75,9 @@ public function open(): Settlement * @return SettlementCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -92,6 +92,6 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index 1f64b4393..7d52fa669 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -60,7 +60,7 @@ public function createForId(string $orderId, array $options = [], array $filters { $this->parentId = $orderId; - return parent::rest_create($options, $filters); + return parent::createResource($options, $filters); } /** @@ -92,7 +92,7 @@ public function getForId(string $orderId, string $shipmentId, array $parameters { $this->parentId = $orderId; - return parent::rest_read($shipmentId, $parameters); + return parent::readResource($shipmentId, $parameters); } /** @@ -115,7 +115,7 @@ public function update(string $orderId, $shipmentId, array $data = []): Shipment $this->parentId = $orderId; - return parent::rest_update($shipmentId, $data); + return parent::updateResource($shipmentId, $data); } /** @@ -145,6 +145,6 @@ public function listForId(string $orderId, array $parameters = []): ShipmentColl { $this->parentId = $orderId; - return parent::rest_list(null, null, $parameters); + return parent::fetchCollection(null, null, $parameters); } } diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 76338f220..9bb56d831 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -59,7 +59,7 @@ public function createForId(string $customerId, array $options = [], array $filt { $this->parentId = $customerId; - return parent::rest_create($options, $filters); + return parent::createResource($options, $filters); } /** @@ -83,7 +83,7 @@ public function update(string $customerId, string $subscriptionId, array $data = $this->parentId = $customerId; - return parent::rest_update($subscriptionId, $data); + return parent::updateResource($subscriptionId, $data); } /** @@ -111,7 +111,7 @@ public function getForId(string $customerId, string $subscriptionId, array $para { $this->parentId = $customerId; - return parent::rest_read($subscriptionId, $parameters); + return parent::readResource($subscriptionId, $parameters); } /** @@ -162,7 +162,7 @@ public function listForId($customerId, ?string $from = null, ?int $limit = null, { $this->parentId = $customerId; - return parent::rest_list($from, $limit, $parameters); + return parent::fetchCollection($from, $limit, $parameters); } /** @@ -185,7 +185,7 @@ public function iteratorForId( ): LazyCollection { $this->parentId = $customerId; - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } /** @@ -213,7 +213,7 @@ public function cancelForId(string $customerId, string $subscriptionId, array $d { $this->parentId = $customerId; - return parent::rest_delete($subscriptionId, $data); + return parent::deleteResource($subscriptionId, $data); } /** @@ -226,7 +226,7 @@ public function cancelForId(string $customerId, string $subscriptionId, array $d * @return SubscriptionCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { $apiPath = 'subscriptions' . $this->buildQueryString( $this->getMergedFilters($parameters, $from, $limit) @@ -237,7 +237,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters $apiPath ); - return $this->createCollectionFromResult($result); + return $this->buildResultCollection($result); } /** @@ -252,7 +252,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - $page = $this->page($from, $limit, $parameters); + $page = $this->collect($from, $limit, $parameters); return $page->getAutoIterator($iterateBackwards); } diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 0678827a9..c7bace563 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -46,7 +46,7 @@ public function get(string $terminalId, array $parameters = []): Terminal throw new ApiException("Invalid terminal ID: '{$terminalId}'. A terminal ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } - return parent::rest_read($terminalId, $parameters); + return parent::readResource($terminalId, $parameters); } /** @@ -59,9 +59,9 @@ public function get(string $terminalId, array $parameters = []): Terminal * @return TerminalCollection * @throws ApiException */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection + public function collect(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection { - return parent::rest_list($from, $limit, $parameters); + return parent::fetchCollection($from, $limit, $parameters); } /** @@ -80,6 +80,6 @@ public function iterator( array $parameters = [], bool $iterateBackwards = false ): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/HandlesDebugging.php b/src/HandlesDebugging.php new file mode 100644 index 000000000..989f92a25 --- /dev/null +++ b/src/HandlesDebugging.php @@ -0,0 +1,54 @@ +setDebugging(true); + } + + /** + * Disable debugging mode. + * + * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException + */ + public function disableDebugging(): void + { + $this->setDebugging(false); + } + + /** + * Toggle debugging mode. If debugging mode is enabled, the attempted request will be included in the ApiException. + * By default, debugging is disabled to prevent leaking sensitive request data into exception logs. + * + * @param bool $enable + * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException + */ + public function setDebugging(bool $enable) + { + if (!$this->httpClient instanceof SupportsDebugging) { + throw new HttpAdapterDoesNotSupportDebuggingException( + "Debugging is not supported by " . get_class($this->httpClient) . "." + ); + } + + if ($enable) { + $this->httpClient->enableDebugging(); + } else { + $this->httpClient->disableDebugging(); + } + } +} diff --git a/src/HandlesIdempotency.php b/src/HandlesIdempotency.php new file mode 100644 index 000000000..c23400f19 --- /dev/null +++ b/src/HandlesIdempotency.php @@ -0,0 +1,126 @@ +idempotencyKeyGenerator = $generator ? $generator : new DefaultIdempotencyKeyGenerator(); + } + + /** + * Set the idempotency key used on the next request. The idempotency key is a unique string ensuring a request to a + * mutating Mollie endpoint is processed only once. The idempotency key resets to null after each request. Using + * the setIdempotencyKey method supersedes the IdempotencyKeyGenerator. + * + * @param $key + * @return $this + */ + public function setIdempotencyKey($key): self + { + $this->idempotencyKey = $key; + + return $this; + } + + /** + * Retrieve the idempotency key. The idempotency key is a unique string ensuring a request to a + * mutating Mollie endpoint is processed only once. Note that the idempotency key gets reset to null after each + * request. + * + * @return string|null + */ + public function getIdempotencyKey(): ?string + { + return $this->idempotencyKey; + } + + /** + * Reset the idempotency key. Note that the idempotency key automatically resets to null after each request. + * + * @return $this + */ + public function resetIdempotencyKey(): self + { + $this->idempotencyKey = null; + + return $this; + } + + /** + * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator + * @return \Mollie\Api\MollieApiClient + */ + public function setIdempotencyKeyGenerator($generator): self + { + $this->idempotencyKeyGenerator = $generator; + + return $this; + } + + /** + * @return \Mollie\Api\MollieApiClient + */ + public function clearIdempotencyKeyGenerator(): self + { + $this->idempotencyKeyGenerator = null; + + return $this; + } + + /** + * Conditionally apply the idempotency key to the request headers + * + * @param array $headers + * @param string $httpMethod + * @return array + */ + protected function applyIdempotencyKey(array $headers, string $httpMethod) + { + if (!in_array($httpMethod, [MollieApiClient::HTTP_POST, MollieApiClient::HTTP_PATCH, MollieApiClient::HTTP_DELETE])) { + unset($headers['Idempotency-Key']); + + return $headers; + } + + if ($this->idempotencyKey) { + $headers['Idempotency-Key'] = $this->idempotencyKey; + + return $headers; + } + + if ($this->idempotencyKeyGenerator) { + $headers['Idempotency-Key'] = $this->idempotencyKeyGenerator->generate(); + + return $headers; + } + + unset($headers['Idempotency-Key']); + + return $headers; + } +} diff --git a/src/HttpAdapter/CurlMollieHttpAdapter.php b/src/HttpAdapter/CurlMollieHttpAdapter.php index da9f696c2..1f6775efb 100644 --- a/src/HttpAdapter/CurlMollieHttpAdapter.php +++ b/src/HttpAdapter/CurlMollieHttpAdapter.php @@ -35,21 +35,21 @@ final class CurlMollieHttpAdapter implements MollieHttpAdapterInterface public const DELAY_INCREASE_MS = 1000; /** - * @param string $httpMethod + * @param string $meethod * @param string $url * @param array $headers - * @param string $httpBody + * @param string $body * @return \stdClass|void|null * @throws \Mollie\Api\Exceptions\ApiException * @throws \Mollie\Api\Exceptions\CurlConnectTimeoutException */ - public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass + public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass { for ($i = 0; $i <= self::MAX_RETRIES; $i++) { usleep($i * self::DELAY_INCREASE_MS); try { - return $this->attemptRequest($httpMethod, $url, $headers, $httpBody); + return $this->attemptRequest($meethod, $url, $headers, $body); } catch (CurlConnectTimeoutException $e) { return null; } diff --git a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php index a45287b2e..76bc03ea2 100644 --- a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php +++ b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php @@ -9,11 +9,14 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions as GuzzleRequestOptions; +use Mollie\Api\Contracts\SupportsDebugging; use Mollie\Api\Exceptions\ApiException; use Psr\Http\Message\ResponseInterface; -final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface +final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface, SupportsDebugging { + use IsDebuggable; + /** * Default response timeout (in seconds). */ @@ -34,15 +37,6 @@ final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface */ protected ClientInterface $httpClient; - /** - * Whether debugging is enabled. If debugging mode is enabled, the request will - * be included in the ApiException. By default, debugging is disabled to prevent - * sensitive request data from leaking into exception logs. - * - * @var bool - */ - protected bool $debugging = false; - public function __construct(ClientInterface $httpClient) { $this->httpClient = $httpClient; @@ -72,22 +66,22 @@ public static function createDefault(): self /** * Send a request to the specified Mollie api url. * - * @param string $httpMethod + * @param string $meethod * @param string $url * @param array $headers - * @param string $httpBody + * @param string $body * @return \stdClass|null * @throws \Mollie\Api\Exceptions\ApiException */ - public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass + public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass { - $request = new Request($httpMethod, $url, $headers, $httpBody); + $request = new Request($meethod, $url, $headers, $body); try { $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (! $this->debugging) { + if (!$this->debug) { $request = null; } @@ -104,49 +98,6 @@ public function send(string $httpMethod, string $url, $headers, ?string $httpBod return $this->parseResponseBody($response); } - /** - * Whether this http adapter provides a debugging mode. If debugging mode is enabled, the - * request will be included in the ApiException. - * - * @return bool - */ - public function supportsDebugging(): bool - { - return true; - } - - /** - * Whether debugging is enabled. If debugging mode is enabled, the request will - * be included in the ApiException. By default, debugging is disabled to prevent - * sensitive request data from leaking into exception logs. - * - * @return bool - */ - public function debugging(): bool - { - return $this->debugging; - } - - /** - * Enable debugging. If debugging mode is enabled, the request will - * be included in the ApiException. By default, debugging is disabled to prevent - * sensitive request data from leaking into exception logs. - */ - public function enableDebugging(): void - { - $this->debugging = true; - } - - /** - * Disable debugging. If debugging mode is enabled, the request will - * be included in the ApiException. By default, debugging is disabled to prevent - * sensitive request data from leaking into exception logs. - */ - public function disableDebugging(): void - { - $this->debugging = false; - } - /** * Parse the PSR-7 Response body * diff --git a/src/HttpAdapter/IsDebuggable.php b/src/HttpAdapter/IsDebuggable.php new file mode 100644 index 000000000..b23269af1 --- /dev/null +++ b/src/HttpAdapter/IsDebuggable.php @@ -0,0 +1,51 @@ +debug = true; + + return $this; + } + + /** + * Disable debugging. If debugging mode is enabled, the request will + * be included in the ApiException. By default, debugging is disabled to prevent + * sensitive request data from leaking into exception logs. + * + * @return $this + */ + public function disableDebugging(): MollieHttpAdapterInterface + { + $this->debug = false; + + return $this; + } + + /** + * Whether debugging is enabled. If debugging mode is enabled, the request will + * be included in the ApiException. By default, debugging is disabled to prevent + * sensitive request data from leaking into exception logs. + * + * @return bool + */ + public function debuggingIsActive(): bool + { + return $this->debug; + } +} diff --git a/src/HttpAdapter/MollieHttpAdapterInterface.php b/src/HttpAdapter/MollieHttpAdapterInterface.php index 9f3fb2f6e..f67d103c9 100644 --- a/src/HttpAdapter/MollieHttpAdapterInterface.php +++ b/src/HttpAdapter/MollieHttpAdapterInterface.php @@ -7,14 +7,14 @@ interface MollieHttpAdapterInterface /** * Send a request to the specified Mollie api url. * - * @param string $httpMethod + * @param string $meethod * @param string $url * @param string|array $headers - * @param ?string $httpBody + * @param ?string $body * @return \stdClass|null * @throws \Mollie\Api\Exceptions\ApiException */ - public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass; + public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass; /** * The version number for the underlying http client, if available. diff --git a/src/HttpAdapter/PSR18MollieHttpAdapter.php b/src/HttpAdapter/PSR18MollieHttpAdapter.php index 04b99955f..69c111ca4 100644 --- a/src/HttpAdapter/PSR18MollieHttpAdapter.php +++ b/src/HttpAdapter/PSR18MollieHttpAdapter.php @@ -45,10 +45,10 @@ public function __construct( /** * {@inheritdoc} */ - public function send(string $httpMethod, string $url, $headers, ?string $httpBody): ?\stdClass + public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass { try { - $request = $this->createRequest($httpMethod, $url, $headers, $httpBody ?? ''); + $request = $this->createRequest($meethod, $url, $headers, $body ?? ''); $response = $this->httpClient->sendRequest($request); $body = (string) $response->getBody(); diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 5aaec3448..80291067a 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,6 +2,7 @@ namespace Mollie\Api; +use Mollie\Api\Contracts\SupportsDebugging; use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; use Mollie\Api\Endpoints\BalanceTransactionEndpoint; @@ -40,17 +41,58 @@ use Mollie\Api\Endpoints\TerminalEndpoint; use Mollie\Api\Endpoints\WalletEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; use Mollie\Api\Exceptions\IncompatiblePlatform; +use Mollie\Api\HttpAdapter\MollieHttpAdapterInterface; use Mollie\Api\HttpAdapter\MollieHttpAdapterPicker; -use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; +/** + * @property BalanceEndpoint $balances + * @property BalanceReportEndpoint $balanceReports + * @property BalanceTransactionEndpoint $balanceTransactions + * @property ChargebackEndpoint $chargebacks + * @property ClientEndpoint $clients + * @property ClientLinkEndpoint $clientLinks + * @property CustomerPaymentsEndpoint $customerPayments + * @property CustomerEndpoint $customers + * @property InvoiceEndpoint $invoices + * @property MandateEndpoint $mandates + * @property MethodEndpoint $methods + * @property OnboardingEndpoint $onboarding + * @property OrderEndpoint $orders + * @property OrderLineEndpoint $orderLines + * @property OrderPaymentEndpoint $orderPayments + * @property OrderRefundEndpoint $orderRefunds + * @property OrganizationEndpoint $organizations + * @property OrganizationPartnerEndpoint $organizationPartners + * @property PaymentEndpoint $payments + * @property PaymentCaptureEndpoint $paymentCaptures + * @property PaymentChargebackEndpoint $paymentChargebacks + * @property PaymentLinkEndpoint $paymentLinks + * @property PaymentRefundEndpoint $paymentRefunds + * @property PaymentRouteEndpoint $paymentRoutes + * @property PermissionEndpoint $permissions + * @property ProfileEndpoint $profiles + * @property ProfileMethodEndpoint $profileMethods + * @property RefundEndpoint $refunds + * @property SettlementsEndpoint $settlements + * @property SettlementCaptureEndpoint $settlementCaptures + * @property SettlementChargebackEndpoint $settlementChargebacks + * @property SettlementPaymentEndpoint $settlementPayments + * @property SettlementRefundEndpoint $settlementRefunds + * @property ShipmentEndpoint $shipments + * @property SubscriptionEndpoint $subscriptions + * @property TerminalEndpoint $terminals + * @property WalletEndpoint $wallets + */ class MollieApiClient { + use HandlesIdempotency; + use HandlesDebugging; + /** * Version of our client. */ - public const CLIENT_VERSION = "2.68.0"; + public const CLIENT_VERSION = "3.0.0"; /** * Endpoint of the remote API. @@ -71,253 +113,14 @@ class MollieApiClient public const HTTP_PATCH = "PATCH"; /** - * @var \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface + * @var MollieHttpAdapterInterface */ - protected $httpClient; + protected MollieHttpAdapterInterface $httpClient; /** * @var string */ - protected $apiEndpoint = self::API_ENDPOINT; - - /** - * RESTful Payments resource. - * - * @var PaymentEndpoint - */ - public $payments; - - /** - * RESTful Methods resource. - * - * @var MethodEndpoint - */ - public $methods; - - /** - * @var ProfileMethodEndpoint - */ - public $profileMethods; - - /** - * RESTful Customers resource. - * - * @var CustomerEndpoint - */ - public $customers; - - /** - * RESTful Customer payments resource. - * - * @var CustomerPaymentsEndpoint - */ - public $customerPayments; - - /** - * RESTful Settlement resource. - * - * @var SettlementsEndpoint - */ - public $settlements; - - /** - * RESTful Settlement capture resource. - * - * @var \Mollie\Api\Endpoints\SettlementCaptureEndpoint - */ - public $settlementCaptures; - - /** - * RESTful Settlement chargeback resource. - * - * @var \Mollie\Api\Endpoints\SettlementChargebackEndpoint - */ - public $settlementChargebacks; - - /** - * RESTful Settlement payment resource. - * - * @var \Mollie\Api\Endpoints\SettlementPaymentEndpoint - */ - public $settlementPayments; - - /** - * RESTful Settlement refund resource. - * - * @var \Mollie\Api\Endpoints\SettlementRefundEndpoint - */ - public $settlementRefunds; - - /** - * RESTful Subscription resource. - * - * @var SubscriptionEndpoint - */ - public $subscriptions; - - /** - * RESTful Mandate resource. - * - * @var MandateEndpoint - */ - public $mandates; - - /** - * RESTful Profile resource. - * - * @var ProfileEndpoint - */ - public $profiles; - - /** - * RESTful Organization resource. - * - * @var OrganizationEndpoint - */ - public $organizations; - - /** - * RESTful Permission resource. - * - * @var PermissionEndpoint - */ - public $permissions; - - /** - * RESTful Invoice resource. - * - * @var InvoiceEndpoint - */ - public $invoices; - - /** - * RESTful Balance resource. - * - * @var BalanceEndpoint - */ - public $balances; - - /** - * @var BalanceTransactionEndpoint - */ - public $balanceTransactions; - - /** - * @var BalanceReportEndpoint - */ - public $balanceReports; - - /** - * RESTful Onboarding resource. - * - * @var OnboardingEndpoint - */ - public $onboarding; - - /** - * RESTful Order resource. - * - * @var OrderEndpoint - */ - public $orders; - - /** - * RESTful OrderLine resource. - * - * @var OrderLineEndpoint - */ - public $orderLines; - - /** - * RESTful OrderPayment resource. - * - * @var OrderPaymentEndpoint - */ - public $orderPayments; - - /** - * RESTful Shipment resource. - * - * @var ShipmentEndpoint - */ - public $shipments; - - /** - * RESTful Refunds resource. - * - * @var RefundEndpoint - */ - public $refunds; - - /** - * RESTful Payment Refunds resource. - * - * @var PaymentRefundEndpoint - */ - public $paymentRefunds; - - /** - * RESTful Payment Route resource. - * - * @var PaymentRouteEndpoint - */ - public $paymentRoutes; - - /** - * RESTful Payment Captures resource. - * - * @var PaymentCaptureEndpoint - */ - public $paymentCaptures; - - /** - * RESTful Chargebacks resource. - * - * @var ChargebackEndpoint - */ - public $chargebacks; - - /** - * RESTful Payment Chargebacks resource. - * - * @var PaymentChargebackEndpoint - */ - public $paymentChargebacks; - - /** - * RESTful Order Refunds resource. - * - * @var OrderRefundEndpoint - */ - public $orderRefunds; - - /** - * Manages Payment Links requests - * - * @var PaymentLinkEndpoint - */ - public $paymentLinks; - - /** - * RESTful Terminal resource. - * - * @var TerminalEndpoint - */ - public $terminals; - - /** - * RESTful Onboarding resource. - * - * @var OrganizationPartnerEndpoint - */ - public $organizationPartners; - - /** - * Manages Wallet requests - * - * @var WalletEndpoint - */ - public $wallets; + protected string $apiEndpoint = self::API_ENDPOINT; /** * @var string @@ -331,48 +134,29 @@ class MollieApiClient */ protected $oauthAccess; - /** - * A unique string ensuring a request to a mutating Mollie endpoint is processed only once. - * This key resets to null after each request. - * - * @var string|null - */ - protected $idempotencyKey = null; - - /** - * @var \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract|null - */ - protected $idempotencyKeyGenerator; - /** * @var array */ protected $versionStrings = []; /** - * RESTful Client resource. - * - * @var ClientEndpoint - */ - public $clients; - - /** - * RESTful Client resource. - * - * @var ClientLinkEndpoint + * @var array */ - public $clientLinks; + protected array $endpoints = []; /** - * @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface|null $httpClient + * @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface|null $client * @param \Mollie\Api\HttpAdapter\MollieHttpAdapterPickerInterface|null $httpAdapterPicker, * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $idempotencyKeyGenerator, * @throws \Mollie\Api\Exceptions\IncompatiblePlatform|\Mollie\Api\Exceptions\UnrecognizedClientException */ - public function __construct($httpClient = null, $httpAdapterPicker = null, $idempotencyKeyGenerator = null) - { - $httpAdapterPicker = $httpAdapterPicker ?: new MollieHttpAdapterPicker; - $this->httpClient = $httpAdapterPicker->pickHttpAdapter($httpClient); + public function __construct( + $client = null, + $adapter = null, + $idempotencyKeyGenerator = null + ) { + $adapter = $adapter ?: new MollieHttpAdapterPicker; + $this->httpClient = $adapter->pickHttpAdapter($client); $compatibilityChecker = new CompatibilityChecker; $compatibilityChecker->checkCompatibility(); @@ -382,73 +166,69 @@ public function __construct($httpClient = null, $httpAdapterPicker = null, $idem $this->initializeIdempotencyKeyGenerator($idempotencyKeyGenerator); } - public function initializeEndpoints() + private function initializeEndpoints(): void { - $this->payments = new PaymentEndpoint($this); - $this->methods = new MethodEndpoint($this); - $this->profileMethods = new ProfileMethodEndpoint($this); - $this->customers = new CustomerEndpoint($this); - $this->settlements = new SettlementsEndpoint($this); - $this->settlementCaptures = new SettlementCaptureEndpoint($this); - $this->settlementChargebacks = new SettlementChargebackEndpoint($this); - $this->settlementPayments = new SettlementPaymentEndpoint($this); - $this->settlementRefunds = new SettlementRefundEndpoint($this); - $this->subscriptions = new SubscriptionEndpoint($this); - $this->customerPayments = new CustomerPaymentsEndpoint($this); - $this->mandates = new MandateEndpoint($this); - $this->balances = new BalanceEndpoint($this); - $this->balanceTransactions = new BalanceTransactionEndpoint($this); - $this->balanceReports = new BalanceReportEndpoint($this); - $this->invoices = new InvoiceEndpoint($this); - $this->permissions = new PermissionEndpoint($this); - $this->profiles = new ProfileEndpoint($this); - $this->onboarding = new OnboardingEndpoint($this); - $this->organizations = new OrganizationEndpoint($this); - $this->orders = new OrderEndpoint($this); - $this->orderLines = new OrderLineEndpoint($this); - $this->orderPayments = new OrderPaymentEndpoint($this); - $this->orderRefunds = new OrderRefundEndpoint($this); - $this->shipments = new ShipmentEndpoint($this); - $this->refunds = new RefundEndpoint($this); - $this->paymentRefunds = new PaymentRefundEndpoint($this); - $this->paymentCaptures = new PaymentCaptureEndpoint($this); - $this->paymentRoutes = new PaymentRouteEndpoint($this); - $this->chargebacks = new ChargebackEndpoint($this); - $this->paymentChargebacks = new PaymentChargebackEndpoint($this); - $this->wallets = new WalletEndpoint($this); - $this->paymentLinks = new PaymentLinkEndpoint($this); - $this->terminals = new TerminalEndpoint($this); - $this->organizationPartners = new OrganizationPartnerEndpoint($this); - $this->clients = new ClientEndpoint($this); - $this->clientLinks = new ClientLinkEndpoint($this); + $endpointClasses = [ + 'balances' => BalanceEndpoint::class, + 'balanceReports' => BalanceReportEndpoint::class, + 'balanceTransactions' => BalanceTransactionEndpoint::class, + 'chargebacks' => ChargebackEndpoint::class, + 'clients' => ClientEndpoint::class, + 'clientLinks' => ClientLinkEndpoint::class, + 'customerPayments' => CustomerPaymentsEndpoint::class, + 'customers' => CustomerEndpoint::class, + 'invoices' => InvoiceEndpoint::class, + 'mandates' => MandateEndpoint::class, + 'methods' => MethodEndpoint::class, + 'onboarding' => OnboardingEndpoint::class, + 'orderLines' => OrderLineEndpoint::class, + 'orderPayments' => OrderPaymentEndpoint::class, + 'orderRefunds' => OrderRefundEndpoint::class, + 'orders' => OrderEndpoint::class, + 'organizationPartners' => OrganizationPartnerEndpoint::class, + 'organizations' => OrganizationEndpoint::class, + 'paymentCaptures' => PaymentCaptureEndpoint::class, + 'paymentChargebacks' => PaymentChargebackEndpoint::class, + 'paymentLinks' => PaymentLinkEndpoint::class, + 'paymentRefunds' => PaymentRefundEndpoint::class, + 'paymentRoutes' => PaymentRouteEndpoint::class, + 'payments' => PaymentEndpoint::class, + 'permissions' => PermissionEndpoint::class, + 'profiles' => ProfileEndpoint::class, + 'profileMethods' => ProfileMethodEndpoint::class, + 'refunds' => RefundEndpoint::class, + 'settlementCaptures' => SettlementCaptureEndpoint::class, + 'settlementChargebacks' => SettlementChargebackEndpoint::class, + 'settlementPayments' => SettlementPaymentEndpoint::class, + 'settlementRefunds' => SettlementRefundEndpoint::class, + 'settlements' => SettlementsEndpoint::class, + 'shipments' => ShipmentEndpoint::class, + 'subscriptions' => SubscriptionEndpoint::class, + 'terminals' => TerminalEndpoint::class, + 'wallets' => WalletEndpoint::class, + ]; + + foreach ($endpointClasses as $name => $class) { + $this->endpoints[$name] = $class; + } } - protected function initializeVersionStrings() + private function initializeVersionStrings(): void { $this->addVersionString("Mollie/" . self::CLIENT_VERSION); $this->addVersionString("PHP/" . phpversion()); - $httpClientVersionString = $this->httpClient->versionString(); - if ($httpClientVersionString) { - $this->addVersionString($httpClientVersionString); + if ($clientVersion = $this->httpClient->versionString()) { + $this->addVersionString($clientVersion); } } - /** - * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator - * @return void - */ - protected function initializeIdempotencyKeyGenerator($generator) - { - $this->idempotencyKeyGenerator = $generator ? $generator : new DefaultIdempotencyKeyGenerator; - } - /** * @param string $url * - * @return MollieApiClient + * @return self */ - public function setApiEndpoint($url) + public function setApiEndpoint($url): self { $this->apiEndpoint = rtrim(trim($url), '/'); @@ -458,7 +238,7 @@ public function setApiEndpoint($url) /** * @return string */ - public function getApiEndpoint() + public function getApiEndpoint(): string { return $this->apiEndpoint; } @@ -466,7 +246,7 @@ public function getApiEndpoint() /** * @return array */ - public function getVersionStrings() + public function getVersionStrings(): array { return $this->versionStrings; } @@ -477,11 +257,11 @@ public function getVersionStrings() * @return MollieApiClient * @throws ApiException */ - public function setApiKey($apiKey) + public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -497,11 +277,11 @@ public function setApiKey($apiKey) * @return MollieApiClient * @throws ApiException */ - public function setAccessToken($accessToken) + public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (! preg_match('/^access_\w+$/', $accessToken)) { + if (!preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } @@ -516,7 +296,7 @@ public function setAccessToken($accessToken) * * @return bool|null */ - public function usesOAuth() + public function usesOAuth(): ?bool { return $this->oauthAccess; } @@ -526,7 +306,7 @@ public function usesOAuth() * * @return MollieApiClient */ - public function addVersionString($versionString) + public function addVersionString($versionString): self { $this->versionStrings[] = str_replace([" ", "\t", "\n", "\r"], '-', $versionString); @@ -534,150 +314,78 @@ public function addVersionString($versionString) } /** - * Enable debugging mode. If debugging mode is enabled, the attempted request will be included in the ApiException. - * By default, debugging is disabled to prevent leaking sensitive request data into exception logs. + * Perform an HTTP call. This method is used by the resource-specific classes. * - * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException - */ - public function enableDebugging() - { - if ( - ! method_exists($this->httpClient, 'supportsDebugging') - || ! $this->httpClient->supportsDebugging() - ) { - throw new HttpAdapterDoesNotSupportDebuggingException( - "Debugging is not supported by " . get_class($this->httpClient) . "." - ); - } - - $this->httpClient->enableDebugging(); - } - - /** - * Disable debugging mode. If debugging mode is enabled, the attempted request will be included in the ApiException. - * By default, debugging is disabled to prevent leaking sensitive request data into exception logs. + * @param string $method + * @param string $path + * @param string|null $body * - * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException + * @return \stdClass + * @throws ApiException */ - public function disableDebugging() + public function performHttpCall(string $method, string $path, ?string $body = null): \stdClass { - if ( - ! method_exists($this->httpClient, 'supportsDebugging') - || ! $this->httpClient->supportsDebugging() - ) { - throw new HttpAdapterDoesNotSupportDebuggingException( - "Debugging is not supported by " . get_class($this->httpClient) . "." - ); - } + $url = $this->buildApiUrl($path); - $this->httpClient->disableDebugging(); + return $this->performHttpCallToFullUrl($method, $url, $body); } /** - * Set the idempotency key used on the next request. The idempotency key is a unique string ensuring a request to a - * mutating Mollie endpoint is processed only once. The idempotency key resets to null after each request. Using - * the setIdempotencyKey method supersedes the IdempotencyKeyGenerator. + * Perform an HTTP call to a full URL. This method is used by the resource-specific classes. * - * @param $key - * @return $this - */ - public function setIdempotencyKey($key) - { - $this->idempotencyKey = $key; - - return $this; - } - - /** - * Retrieve the idempotency key. The idempotency key is a unique string ensuring a request to a - * mutating Mollie endpoint is processed only once. Note that the idempotency key gets reset to null after each - * request. + * @param string $method + * @param string $url + * @param string|null $body * - * @return string|null - */ - public function getIdempotencyKey() - { - return $this->idempotencyKey; - } - - /** - * Reset the idempotency key. Note that the idempotency key automatically resets to null after each request. - * @return $this + * @return \stdClass + * @throws ApiException */ - public function resetIdempotencyKey() + public function performHttpCallToFullUrl(string $method, string $url, ?string $body = null): \stdClass { - $this->idempotencyKey = null; + $this->ensureApiKeyIsSet(); - return $this; - } + $headers = $this->prepareHeaders($method, $body); + $response = $this->httpClient->send($method, $url, $headers, $body); - /** - * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator - * @return \Mollie\Api\MollieApiClient - */ - public function setIdempotencyKeyGenerator($generator) - { - $this->idempotencyKeyGenerator = $generator; + $this->resetIdempotencyKey(); - return $this; + return $response; } /** - * @return \Mollie\Api\MollieApiClient + * Build the full API URL for a given method. + * + * @param string $path + * @return string */ - public function clearIdempotencyKeyGenerator() + private function buildApiUrl(string $path): string { - $this->idempotencyKeyGenerator = null; - - return $this; + return rtrim($this->apiEndpoint, '/') . '/' . self::API_VERSION . '/' . ltrim($path, '/'); } /** - * Perform a http call. This method is used by the resource specific classes. Please use the $payments property to - * perform operations on payments. + * Ensure that the API key is set. * - * @param string $httpMethod - * @param string $apiMethod - * @param string|null $httpBody - * - * @return \stdClass * @throws ApiException - * - * @codeCoverageIgnore */ - public function performHttpCall($httpMethod, $apiMethod, $httpBody = null) + protected function ensureApiKeyIsSet(): void { - $url = $this->apiEndpoint . "/" . self::API_VERSION . "/" . $apiMethod; - - return $this->performHttpCallToFullUrl($httpMethod, $url, $httpBody); + if (empty($this->apiKey)) { + throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key."); + } } /** - * Perform a http call to a full url. This method is used by the resource specific classes. - * - * @see $payments - * @see $isuers + * Prepare the headers for the HTTP request. * - * @param string $httpMethod - * @param string $url - * @param string|null $httpBody - * - * @return \stdClass|null - * @throws ApiException - * - * @codeCoverageIgnore + * @param string $method + * @param string|null $body + * @return array */ - public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null) + protected function prepareHeaders(string $method, ?string $body): array { - if (empty($this->apiKey)) { - throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key."); - } - - $userAgent = implode(' ', $this->versionStrings); - - if ($this->usesOAuth()) { - $userAgent .= " OAuth/2.0"; - } + $userAgent = implode(' ', $this->versionStrings) + . ($this->usesOAuth() ? " OAuth/2.0" : ""); $headers = [ 'Accept' => "application/json", @@ -685,7 +393,7 @@ public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null) 'User-Agent' => $userAgent, ]; - if ($httpBody !== null) { + if ($body !== null) { $headers['Content-Type'] = "application/json"; } @@ -693,74 +401,35 @@ public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null) $headers['X-Mollie-Client-Info'] = php_uname(); } - $headers = $this->applyIdempotencyKey($headers, $httpMethod); - - $response = $this->httpClient->send($httpMethod, $url, $headers, $httpBody); - - $this->resetIdempotencyKey(); - - return $response; + return $this->applyIdempotencyKey($headers, $method); } /** - * Conditionally apply the idempotency key to the request headers - * - * @param array $headers - * @param string $httpMethod - * @return array - */ - private function applyIdempotencyKey(array $headers, string $httpMethod) - { - if (! in_array($httpMethod, [self::HTTP_POST, self::HTTP_PATCH, self::HTTP_DELETE])) { - unset($headers['Idempotency-Key']); - - return $headers; - } - - if ($this->idempotencyKey) { - $headers['Idempotency-Key'] = $this->idempotencyKey; - - return $headers; - } - - if ($this->idempotencyKeyGenerator) { - $headers['Idempotency-Key'] = $this->idempotencyKeyGenerator->generate(); - - return $headers; - } - - unset($headers['Idempotency-Key']); - - return $headers; - } - - /** - * Serialization can be used for caching. Of course doing so can be dangerous but some like to live dangerously. - * - * \serialize() should be called on the collections or object you want to cache. - * - * We don't need any property that can be set by the constructor, only properties that are set by setters. + * When unserializing a collection or a resource, this class should restore itself. * - * Note that the API key is not serialized, so you need to set the key again after unserializing if you want to do - * more API calls. + * Note that if you have set an HttpAdapter, this adapter is lost on wakeup and reset to the default one. * - * @deprecated - * @return string[] + * @throws IncompatiblePlatform If suddenly unserialized on an incompatible platform. */ - public function __sleep() + public function __wakeup() { - return ["apiEndpoint"]; + $this->__construct(); } /** - * When unserializing a collection or a resource, this class should restore itself. + * Magic getter to access the endpoints. * - * Note that if you have set an HttpAdapter, this adapter is lost on wakeup and reset to the default one. + * @param string $name * - * @throws IncompatiblePlatform If suddenly unserialized on an incompatible platform. + * @return mixed + * @throws \Exception */ - public function __wakeup() + public function __get(string $name) { - $this->__construct(); + if (isset($this->endpoints[$name])) { + return new $this->endpoints[$name]($this); + } + + throw new \Exception("Undefined endpoint: $name"); } } diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index fd43b87a6..1b338da53 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -9,21 +9,22 @@ abstract class BaseCollection extends \ArrayObject * * @var int */ - public $count; + public int $count; /** * @var \stdClass|null */ - public $_links; + public ?\stdClass $_links; /** * @param int $count * @param \stdClass|null $_links */ - public function __construct($count, $_links) + public function __construct(int $count, ?\stdClass $_links) { $this->count = $count; $this->_links = $_links; + parent::__construct(); } diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index d5762ccfd..ea015227f 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -7,10 +7,7 @@ #[\AllowDynamicProperties] abstract class BaseResource { - /** - * @var MollieApiClient - */ - protected $client; + protected MollieApiClient $client; /** * Indicates the type of resource. diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 0f83c7e56..17eed9987 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -7,17 +7,14 @@ abstract class CursorCollection extends BaseCollection { - /** - * @var MollieApiClient - */ - protected $client; + protected MollieApiClient $client; /** * @param MollieApiClient $client * @param int $count * @param \stdClass|null $_links */ - final public function __construct(MollieApiClient $client, $count, $_links) + final public function __construct(MollieApiClient $client, int $count, ?\stdClass $_links) { parent::__construct($count, $_links); @@ -35,9 +32,9 @@ abstract protected function createResourceObject(); * @return CursorCollection|null * @throws \Mollie\Api\Exceptions\ApiException */ - final public function next() + final public function next(): ?CursorCollection { - if (! $this->hasNext()) { + if (!$this->hasNext()) { return null; } @@ -58,9 +55,9 @@ final public function next() * @return CursorCollection|null * @throws \Mollie\Api\Exceptions\ApiException */ - final public function previous() + final public function previous(): ?CursorCollection { - if (! $this->hasPrevious()) { + if (!$this->hasPrevious()) { return null; } @@ -80,7 +77,7 @@ final public function previous() * * @return bool */ - public function hasNext() + public function hasNext(): bool { return isset($this->_links->next->href); } @@ -90,7 +87,7 @@ public function hasNext() * * @return bool */ - public function hasPrevious() + public function hasPrevious(): bool { return isset($this->_links->previous->href); } @@ -112,7 +109,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { break; } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 98fc7443d..c30d2ae7a 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -210,7 +210,7 @@ public function hasValidMandate() * * @return bool */ - public function hasValidMandateForMethod($method) + public function hasValidMandateForMethod($method): bool { $mandates = $this->mandates(); foreach ($mandates as $mandate) { @@ -227,7 +227,7 @@ public function hasValidMandateForMethod($method) * * @return array */ - private function getPresetOptions() + private function getPresetOptions(): array { $options = []; if ($this->client->usesOAuth()) { @@ -243,7 +243,7 @@ private function getPresetOptions() * @param array $options * @return array */ - private function withPresetOptions(array $options) + private function withPresetOptions(array $options): array { return array_merge($this->getPresetOptions(), $options); } diff --git a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php index c2b14129b..cbc82aef8 100644 --- a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php @@ -129,7 +129,7 @@ public function testListBalances() ); /** @var BalanceCollection $balances */ - $balances = $this->apiClient->balances->page(); + $balances = $this->apiClient->balances->collect(); $this->assertInstanceOf(BalanceCollection::class, $balances); $this->assertEquals(2, $balances->count); diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index 44fb3b568..c2727e6b9 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -107,7 +107,7 @@ public function testListChargebacks() ) ); - $chargebacks = $this->apiClient->chargebacks->page(); + $chargebacks = $this->apiClient->chargebacks->collect(); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); $this->assertEquals(2, $chargebacks->count); diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php index bd0781f84..ddf9adbb2 100644 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientEndpointTest.php @@ -119,7 +119,7 @@ public function testGetClientsPage() ) ); - $clients = $this->apiClient->clients->page(); + $clients = $this->apiClient->clients->collect(); $this->assertInstanceOf(ClientCollection::class, $clients); $this->assertEquals(1, $clients->count); @@ -156,7 +156,7 @@ protected function assertClient($client) 'application/hal+json', $client->_links->onboarding ); - + $this->assertLinkObject( 'https://docs.mollie.com/reference/v2/clients-api/get-client', 'text/html', diff --git a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php index 20e939ba0..c3672109b 100644 --- a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php @@ -140,7 +140,7 @@ public function testListWorks() ) ); - $customers = $this->apiClient->customers->page(); + $customers = $this->apiClient->customers->collect(); $this->assertInstanceOf(CustomerCollection::class, $customers); diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php index 12c338fff..e715a6025 100644 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php @@ -200,7 +200,7 @@ public function testListInvoices() ) ); - $invoices = $this->apiClient->invoices->page(); + $invoices = $this->apiClient->invoices->collect(); $this->assertInstanceOf(InvoiceCollection::class, $invoices); $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html']; diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index b1a2b5674..c497cc2fd 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -539,7 +539,7 @@ public function testListOrders() ) ); - $orders = $this->apiClient->orders->page(); + $orders = $this->apiClient->orders->collect(); $this->assertInstanceOf(OrderCollection::class, $orders); $this->assertEquals(3, $orders->count); diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index 344f1b922..f2821140d 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -475,7 +475,7 @@ public function testListPayment() ) ); - $payments = $this->apiClient->payments->page(null, 3); + $payments = $this->apiClient->payments->collect(null, 3); $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertEquals(3, $payments->count); diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php index 61a81731b..2f2d35d9f 100644 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php @@ -366,7 +366,7 @@ public function testListProfiles() ) ); - $profiles = $this->apiClient->profiles->page(); + $profiles = $this->apiClient->profiles->collect(); $this->assertInstanceOf(ProfileCollection::class, $profiles); $this->assertEquals(2, $profiles->count); diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php index 351e2b461..ba5fd91ec 100644 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/RefundEndpointTest.php @@ -69,7 +69,7 @@ public function testListRefunds() ) ); - $refunds = $this->apiClient->refunds->page(); + $refunds = $this->apiClient->refunds->collect(); $this->assertInstanceOf(RefundCollection::class, $refunds); $this->assertEquals(1, $refunds->count); diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php index a8eab4902..42e59be58 100644 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php @@ -426,7 +426,7 @@ public function testListSettlement() ); /** @var SettlementCollection $settlements */ - $settlements = $this->apiClient->settlements->page(); + $settlements = $this->apiClient->settlements->collect(); $this->assertInstanceOf(SettlementCollection::class, $settlements); $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html']; diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php index f5ccb3f9f..859eefb7a 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php @@ -476,7 +476,7 @@ public function testListPageOfRootSubscriptionsWorks() ) ); - $subscriptions = $this->apiClient->subscriptions->page(); + $subscriptions = $this->apiClient->subscriptions->collect(); $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); $this->assertCount(1, $subscriptions); diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index fc4494e10..c7f83cabd 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -177,7 +177,7 @@ public function testListTerminal() ) ); - $terminals = $this->apiClient->terminals->page(null, 3); + $terminals = $this->apiClient->terminals->collect(null, 3); $this->assertInstanceOf(TerminalCollection::class, $terminals); $this->assertEquals(3, $terminals->count); diff --git a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php index 401dbca63..fd0a6b9a9 100644 --- a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\Request; +use Mollie\Api\Contracts\SupportsDebugging; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter; use PHPUnit\Framework\TestCase; @@ -16,14 +17,14 @@ class Guzzle6And7MollieHttpAdapterTest extends TestCase public function testDebuggingIsSupported() { $adapter = Guzzle6And7MollieHttpAdapter::createDefault(); - $this->assertTrue($adapter->supportsDebugging()); - $this->assertFalse($adapter->debugging()); + $this->assertTrue($adapter instanceof SupportsDebugging); + $this->assertFalse($adapter->debuggingIsActive()); $adapter->enableDebugging(); - $this->assertTrue($adapter->debugging()); + $this->assertTrue($adapter->debuggingIsActive()); $adapter->disableDebugging(); - $this->assertFalse($adapter->debugging()); + $this->assertFalse($adapter->debuggingIsActive()); } /** @test */ @@ -74,7 +75,7 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() ); $adapter = new Guzzle6And7MollieHttpAdapter($guzzleClient); - $this->assertFalse($adapter->debugging()); + $this->assertFalse($adapter->debuggingIsActive()); try { $adapter->send( diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php index cf480b8b8..5f11b7af8 100644 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php @@ -7,7 +7,7 @@ class MockMollieHttpAdapter implements \Mollie\Api\HttpAdapter\MollieHttpAdapter /** * @inheritDoc */ - public function send($httpMethod, $url, $headers, $httpBody) + public function send(string $meethod, string $url, $headers, ?string $body): \stdClass { return (object) ['foo' => 'bar']; } @@ -15,7 +15,7 @@ public function send($httpMethod, $url, $headers, $httpBody) /** * @inheritDoc */ - public function versionString() + public function versionString(): string { return 'mock-client/1.0'; } diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php index a7d525525..c6c615e2b 100644 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ b/tests/Mollie/TestHelpers/FakeHttpAdapter.php @@ -31,7 +31,6 @@ class FakeHttpAdapter implements MollieHttpAdapterInterface */ private $usedBody; - /** * FakeHttpAdapter constructor. * @param \stdClass|null|\GuzzleHttp\Psr7\Response $response @@ -42,18 +41,18 @@ public function __construct($response) } /** - * @param string $httpMethod + * @param string $meethod * @param string $url * @param string $headers - * @param string $httpBody + * @param string $body * @return \stdClass|void|null */ - public function send($httpMethod, $url, $headers, $httpBody) + public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass { - $this->usedMethod = $httpMethod; + $this->usedMethod = $meethod; $this->usedUrl = $url; $this->usedHeaders = $headers; - $this->usedBody = $httpBody; + $this->usedBody = $body; return $this->response; } @@ -61,7 +60,7 @@ public function send($httpMethod, $url, $headers, $httpBody) /** * @return string */ - public function versionString() + public function versionString(): string { return 'fake'; } From d66feba9f7e95c5f98083e37fd2eda8e08e3b703 Mon Sep 17 00:00:00 2001 From: Naoray Date: Mon, 24 Jun 2024 22:34:03 +0000 Subject: [PATCH 012/131] Fix styling --- examples/pagination/backwards.php | 4 ++-- examples/pagination/basic_usage.php | 4 ++-- examples/payments/list-payments.php | 2 +- src/CompatibilityChecker.php | 4 ++-- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/RestEndpoint.php | 2 +- src/HandlesDebugging.php | 2 +- src/HandlesIdempotency.php | 2 +- src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php | 2 +- src/MollieApiClient.php | 5 ++--- src/Resources/CursorCollection.php | 6 +++--- src/Resources/Mandate.php | 2 +- src/Resources/Order.php | 2 +- src/Resources/Payment.php | 14 +++++++------- src/Resources/Profile.php | 8 ++++---- src/Resources/Subscription.php | 4 ++-- 16 files changed, 32 insertions(+), 33 deletions(-) diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index 582f92610..a663ceb1f 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -41,7 +41,7 @@ while ($page->hasPrevious()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->previous(); @@ -50,7 +50,7 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) foreach ($mollie->orders->iterator(null, null, [], true) as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index c7f708661..c80af631b 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -40,7 +40,7 @@ while ($page->hasNext()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->next(); @@ -49,7 +49,7 @@ // using the iterator we can iterate over all orders directly foreach ($mollie->orders->iterator() as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/payments/list-payments.php b/examples/payments/list-payments.php index d5b48e804..6682487fe 100644 --- a/examples/payments/list-payments.php +++ b/examples/payments/list-payments.php @@ -53,7 +53,7 @@ */ $nextPayments = $payments->next(); - if (!empty($nextPayments)) { + if (! empty($nextPayments)) { echo "
              "; foreach ($nextPayments as $payment) { echo "
            • "; diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index 3ab386976..40127dac6 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -17,14 +17,14 @@ class CompatibilityChecker */ public function checkCompatibility() { - if (!$this->satisfiesPhpVersion()) { + if (! $this->satisfiesPhpVersion()) { throw new IncompatiblePlatform( "The client requires PHP version >= " . self::MIN_PHP_VERSION . ", you have " . PHP_VERSION . ".", IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION ); } - if (!$this->satisfiesJsonExtension()) { + if (! $this->satisfiesJsonExtension()) { throw new IncompatiblePlatform( "PHP extension json is not enabled. Please make sure to enable 'json' in your PHP configuration.", IncompatiblePlatform::INCOMPATIBLE_JSON_EXTENSION diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index d4273c97d..10a2c5e26 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -109,7 +109,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (!isset($data['lines']) || !is_array($data['lines'])) { + if (! isset($data['lines']) || ! is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index daa4bce0f..a266f3633 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -65,7 +65,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpoint && empty($id)) { + if (! $this instanceof SingleResourceEndpoint && empty($id)) { throw new ApiException("Invalid resource id."); } diff --git a/src/HandlesDebugging.php b/src/HandlesDebugging.php index 989f92a25..a3c1f4103 100644 --- a/src/HandlesDebugging.php +++ b/src/HandlesDebugging.php @@ -39,7 +39,7 @@ public function disableDebugging(): void */ public function setDebugging(bool $enable) { - if (!$this->httpClient instanceof SupportsDebugging) { + if (! $this->httpClient instanceof SupportsDebugging) { throw new HttpAdapterDoesNotSupportDebuggingException( "Debugging is not supported by " . get_class($this->httpClient) . "." ); diff --git a/src/HandlesIdempotency.php b/src/HandlesIdempotency.php index c23400f19..8e36ca3d2 100644 --- a/src/HandlesIdempotency.php +++ b/src/HandlesIdempotency.php @@ -101,7 +101,7 @@ public function clearIdempotencyKeyGenerator(): self */ protected function applyIdempotencyKey(array $headers, string $httpMethod) { - if (!in_array($httpMethod, [MollieApiClient::HTTP_POST, MollieApiClient::HTTP_PATCH, MollieApiClient::HTTP_DELETE])) { + if (! in_array($httpMethod, [MollieApiClient::HTTP_POST, MollieApiClient::HTTP_PATCH, MollieApiClient::HTTP_DELETE])) { unset($headers['Idempotency-Key']); return $headers; diff --git a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php index 76bc03ea2..5eba90963 100644 --- a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php +++ b/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php @@ -81,7 +81,7 @@ public function send(string $meethod, string $url, $headers, ?string $body): ?\s $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (!$this->debug) { + if (! $this->debug) { $request = null; } diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 80291067a..91b8d735e 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,7 +2,6 @@ namespace Mollie\Api; -use Mollie\Api\Contracts\SupportsDebugging; use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; use Mollie\Api\Endpoints\BalanceTransactionEndpoint; @@ -261,7 +260,7 @@ public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -281,7 +280,7 @@ public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (!preg_match('/^access_\w+$/', $accessToken)) { + if (! preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 17eed9987..3434c4570 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -34,7 +34,7 @@ abstract protected function createResourceObject(); */ final public function next(): ?CursorCollection { - if (!$this->hasNext()) { + if (! $this->hasNext()) { return null; } @@ -57,7 +57,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (!$this->hasPrevious()) { + if (! $this->hasPrevious()) { return null; } @@ -109,7 +109,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index 75aac1624..a2ce98c7c 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -90,7 +90,7 @@ public function isInvalid() */ public function revoke() { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index 4c7be3257..addeb9442 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -519,7 +519,7 @@ public function createPayment($data, $filters = []) */ public function payments() { - if (!isset($this->_embedded, $this->_embedded->payments)) { + if (! isset($this->_embedded, $this->_embedded->payments)) { return null; } diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index bb833238d..9509f2cfb 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -433,7 +433,7 @@ public function isAuthorized() */ public function isPaid() { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** @@ -443,7 +443,7 @@ public function isPaid() */ public function hasRefunds() { - return !empty($this->_links->refunds); + return ! empty($this->_links->refunds); } /** @@ -453,7 +453,7 @@ public function hasRefunds() */ public function hasChargebacks() { - return !empty($this->_links->chargebacks); + return ! empty($this->_links->chargebacks); } /** @@ -586,7 +586,7 @@ public function getAmountChargedBack() */ public function hasSplitPayments() { - return !empty($this->routing); + return ! empty($this->routing); } /** @@ -597,7 +597,7 @@ public function hasSplitPayments() */ public function refunds() { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } @@ -645,7 +645,7 @@ public function listRefunds(array $parameters = []) */ public function captures() { - if (!isset($this->_links->captures->href)) { + if (! isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } @@ -686,7 +686,7 @@ public function getCapture($captureId, array $parameters = []) */ public function chargebacks() { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 6b27ec43f..62238d65b 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -131,7 +131,7 @@ public function update() */ public function chargebacks() { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -153,7 +153,7 @@ public function chargebacks() */ public function methods() { - if (!isset($this->_links->methods->href)) { + if (! isset($this->_links->methods->href)) { return new MethodCollection(0, null); } @@ -201,7 +201,7 @@ public function disableMethod($methodId, array $data = []) */ public function payments() { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } @@ -223,7 +223,7 @@ public function payments() */ public function refunds() { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 96a8227f4..04634ecd9 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -189,7 +189,7 @@ public function isCompleted() */ public function cancel() { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } @@ -217,7 +217,7 @@ public function cancel() */ public function payments() { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } From 8b1ba43dbc3410cfb63af60da237950a8f332092 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 26 Jun 2024 00:28:13 +0200 Subject: [PATCH 013/131] wip --- .../MollieHttpAdapterContract.php} | 12 +- .../MollieHttpAdapterPickerContract.php | 13 ++ src/Contracts/ResponseContract.php | 15 ++ ...php => SingleResourceEndpointContract.php} | 2 +- ...ging.php => SupportsDebuggingContract.php} | 2 +- src/Endpoints/BalanceEndpoint.php | 8 +- src/Endpoints/BalanceTransactionEndpoint.php | 2 - src/Endpoints/BaseEndpoint.php | 15 +- src/Endpoints/ChargebackEndpoint.php | 2 +- src/Endpoints/ClientEndpoint.php | 2 +- src/Endpoints/ClientLinkEndpoint.php | 2 - src/Endpoints/CustomerEndpoint.php | 8 +- ...dpoint.php => CustomerMandateEndpoint.php} | 4 +- ...t.php => CustomerSubscriptionEndpoint.php} | 12 +- src/Endpoints/InvoiceEndpoint.php | 4 +- src/Endpoints/IsDependableOnParent.php | 18 ++ src/Endpoints/MethodEndpoint.php | 8 +- src/Endpoints/OnboardingEndpoint.php | 4 +- src/Endpoints/OrderEndpoint.php | 12 +- src/Endpoints/OrderLineEndpoint.php | 6 +- src/Endpoints/OrderPaymentEndpoint.php | 2 - src/Endpoints/OrderRefundEndpoint.php | 2 +- ...Endpoint.php => OrderShipmentEndpoint.php} | 8 +- src/Endpoints/OrganizationPartnerEndpoint.php | 4 +- src/Endpoints/PaymentEndpoint.php | 12 +- src/Endpoints/PaymentLinkEndpoint.php | 8 +- src/Endpoints/ProfileEndpoint.php | 9 +- src/Endpoints/RefundEndpoint.php | 2 +- src/Endpoints/RestEndpoint.php | 40 +++- src/Endpoints/SettlementsEndpoint.php | 2 +- src/Endpoints/TerminalEndpoint.php | 4 +- src/Exceptions/ApiException.php | 10 +- src/HandlesDebugging.php | 4 +- .../Adapter}/CurlMollieHttpAdapter.php | 219 ++++++++---------- .../Adapter/GuzzleMollieHttpAdapter.php} | 42 ++-- .../Adapter/GuzzleRetryMiddlewareFactory.php} | 4 +- .../Adapter}/MollieHttpAdapterPicker.php | 20 +- .../Adapter}/PSR18MollieHttpAdapter.php | 34 ++- src/Http/HasHttpPhrases.php | 72 ++++++ src/{HttpAdapter => Http}/IsDebuggable.php | 8 +- src/Http/NoResponse.php | 23 ++ src/Http/PsrResponseHandler.php | 52 +++++ src/Http/Response.php | 107 +++++++++ src/Http/ResponseHandler.php | 101 ++++++++ src/Http/ResponseStatusCode.php | 70 ++++++ .../MollieHttpAdapterPickerInterface.php | 13 -- src/MollieApiClient.php | 73 +++--- src/Resources/CursorCollection.php | 17 +- src/Resources/ResourceFactory.php | 9 +- .../HttpAdapter/CurlMollieHttpAdapterTest.php | 2 +- ...st.php => GuzzleMollieHttpAdapterTest.php} | 14 +- .../API/HttpAdapter/MockMollieHttpAdapter.php | 26 ++- .../MollieHttpAdapterPickerTest.php | 8 +- tests/Mollie/API/MollieApiClientTest.php | 8 +- .../Guzzle/RetryMiddlewareFactoryTest.php | 12 +- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 19 +- 56 files changed, 847 insertions(+), 364 deletions(-) rename src/{HttpAdapter/MollieHttpAdapterInterface.php => Contracts/MollieHttpAdapterContract.php} (58%) create mode 100644 src/Contracts/MollieHttpAdapterPickerContract.php create mode 100644 src/Contracts/ResponseContract.php rename src/Contracts/{SingleResourceEndpoint.php => SingleResourceEndpointContract.php} (51%) rename src/Contracts/{SupportsDebugging.php => SupportsDebuggingContract.php} (89%) rename src/Endpoints/{MandateEndpoint.php => CustomerMandateEndpoint.php} (97%) rename src/Endpoints/{SubscriptionEndpoint.php => CustomerSubscriptionEndpoint.php} (93%) create mode 100644 src/Endpoints/IsDependableOnParent.php rename src/Endpoints/{ShipmentEndpoint.php => OrderShipmentEndpoint.php} (91%) rename src/{HttpAdapter => Http/Adapter}/CurlMollieHttpAdapter.php (51%) rename src/{HttpAdapter/Guzzle6And7MollieHttpAdapter.php => Http/Adapter/GuzzleMollieHttpAdapter.php} (76%) rename src/{HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php => Http/Adapter/GuzzleRetryMiddlewareFactory.php} (96%) rename src/{HttpAdapter => Http/Adapter}/MollieHttpAdapterPicker.php (73%) rename src/{HttpAdapter => Http/Adapter}/PSR18MollieHttpAdapter.php (72%) create mode 100644 src/Http/HasHttpPhrases.php rename src/{HttpAdapter => Http}/IsDebuggable.php (84%) create mode 100644 src/Http/NoResponse.php create mode 100644 src/Http/PsrResponseHandler.php create mode 100644 src/Http/Response.php create mode 100644 src/Http/ResponseHandler.php create mode 100644 src/Http/ResponseStatusCode.php delete mode 100644 src/HttpAdapter/MollieHttpAdapterPickerInterface.php rename tests/Mollie/API/HttpAdapter/{Guzzle6And7MollieHttpAdapterTest.php => GuzzleMollieHttpAdapterTest.php} (85%) diff --git a/src/HttpAdapter/MollieHttpAdapterInterface.php b/src/Contracts/MollieHttpAdapterContract.php similarity index 58% rename from src/HttpAdapter/MollieHttpAdapterInterface.php rename to src/Contracts/MollieHttpAdapterContract.php index f67d103c9..5421bd99b 100644 --- a/src/HttpAdapter/MollieHttpAdapterInterface.php +++ b/src/Contracts/MollieHttpAdapterContract.php @@ -1,20 +1,20 @@ guardAgainstInvalidId($balanceId); return parent::readResource($balanceId, $parameters); } @@ -72,7 +70,7 @@ public function primary(array $parameters = []): Balance * @return BalanceCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index d33fd9a05..ddeb4776b 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -11,8 +11,6 @@ class BalanceTransactionEndpoint extends EndpointCollection { - const RESOURCE_ID_PREFIX = 'baltr_'; - protected string $resourcePath = "balances_transactions"; /** diff --git a/src/Endpoints/BaseEndpoint.php b/src/Endpoints/BaseEndpoint.php index 8475510f2..9c8f45c37 100644 --- a/src/Endpoints/BaseEndpoint.php +++ b/src/Endpoints/BaseEndpoint.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Endpoints; -use Mollie\Api\Contracts\SingleResourceEndpoint; +use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; @@ -57,9 +57,7 @@ public function getResourcePath(): string if (strpos($this->resourcePath, "_") !== false) { [$parentResource, $childResource] = explode("_", $this->resourcePath, 2); - if (empty($this->parentId)) { - throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); - } + $this->guardAgainstMissingParentId($parentResource); return "$parentResource/{$this->parentId}/$childResource"; } @@ -69,7 +67,7 @@ public function getResourcePath(): string protected function getPathToSingleResource(string $id): string { - if ($this instanceof SingleResourceEndpoint) { + if ($this instanceof SingleResourceEndpointContract) { return $this->getResourcePath(); } @@ -88,4 +86,11 @@ protected function parseRequestBody(array $body): ?string return @json_encode($body); } + + private function guardAgainstMissingParentId(string $parentResource): void + { + if (empty($this->parentId)) { + throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); + } + } } diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index a567d9bca..e199a60ea 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -37,7 +37,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Char * @return ChargebackCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index bb264bcda..f633d4325 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -58,7 +58,7 @@ public function get(string $clientId, array $parameters = []): Client * @return ClientCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 4d96f74d4..80215a3fa 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -9,8 +9,6 @@ class ClientLinkEndpoint extends RestEndpoint { protected string $resourcePath = "client-links"; - public const RESOURCE_ID_PREFIX = 'cl_'; - /** * Get the object that is used by this API endpoint. Every API endpoint uses one * type of object. diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 6107ee799..a6ad1b71d 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -11,7 +11,7 @@ class CustomerEndpoint extends EndpointCollection { protected string $resourcePath = "customers"; - public const RESOURCE_ID_PREFIX = 'cst_'; + protected static string $resourceIdPrefix = 'cst_'; /** * @inheritDoc @@ -70,9 +70,7 @@ public function get(string $customerId, array $parameters = []): Customer */ public function update(string $customerId, array $data = []): Customer { - if (empty($customerId) || strpos($customerId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$customerId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($customerId); return parent::updateResource($customerId, $data); } @@ -103,7 +101,7 @@ public function delete(string $customerId, array $data = []): ?Customer * @return CustomerCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/CustomerMandateEndpoint.php similarity index 97% rename from src/Endpoints/MandateEndpoint.php rename to src/Endpoints/CustomerMandateEndpoint.php index 4634067f5..963b4805e 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/CustomerMandateEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -class MandateEndpoint extends EndpointCollection +class CustomerMandateEndpoint extends EndpointCollection { protected string $resourcePath = "customers_mandates"; @@ -80,7 +80,7 @@ public function getForId(string $customerId, $mandateId, array $parameters = []) { $this->parentId = $customerId; - return parent::readResource($mandateId, $parameters); + return $this->readResource($mandateId, $parameters); } /** diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/CustomerSubscriptionEndpoint.php similarity index 93% rename from src/Endpoints/SubscriptionEndpoint.php rename to src/Endpoints/CustomerSubscriptionEndpoint.php index 9bb56d831..0071f2250 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/CustomerSubscriptionEndpoint.php @@ -8,11 +8,11 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -class SubscriptionEndpoint extends EndpointCollection +class CustomerSubscriptionEndpoint extends EndpointCollection { protected string $resourcePath = "customers_subscriptions"; - public const RESOURCE_ID_PREFIX = 'sub_'; + protected static string $resourceIdPrefix = 'sub_'; /** * @inheritDoc @@ -77,9 +77,7 @@ public function createForId(string $customerId, array $options = [], array $filt */ public function update(string $customerId, string $subscriptionId, array $data = []): Subscription { - if (empty($subscriptionId) || strpos($subscriptionId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid subscription ID: '{$subscriptionId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($subscriptionId); $this->parentId = $customerId; @@ -226,7 +224,7 @@ public function cancelForId(string $customerId, string $subscriptionId, array $d * @return SubscriptionCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { $apiPath = 'subscriptions' . $this->buildQueryString( $this->getMergedFilters($parameters, $from, $limit) @@ -252,7 +250,7 @@ public function collect(?string $from = null, ?int $limit = null, array $paramet */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - $page = $this->collect($from, $limit, $parameters); + $page = $this->page($from, $limit, $parameters); return $page->getAutoIterator($iterateBackwards); } diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index b77a6e7c7..970143c57 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -53,7 +53,7 @@ public function get(string $invoiceId, array $parameters = []): Invoice * @return InvoiceCollection * @throws ApiException */ - public function collect(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection + public function page(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection { return $this->fetchCollection($from, $limit, $parameters); } @@ -68,7 +68,7 @@ public function collect(string $from = null, int $limit = null, array $parameter */ public function all(array $parameters = []): InvoiceCollection { - return $this->collect(null, null, $parameters); + return $this->page(null, null, $parameters); } /** diff --git a/src/Endpoints/IsDependableOnParent.php b/src/Endpoints/IsDependableOnParent.php new file mode 100644 index 000000000..0aeeda76f --- /dev/null +++ b/src/Endpoints/IsDependableOnParent.php @@ -0,0 +1,18 @@ +parentId; + } +} diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 74872bc4f..bb1dfd34b 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; -use Mollie\Api\Resources\ResourceFactory; class MethodEndpoint extends EndpointCollection { @@ -69,12 +68,7 @@ public function allAvailable(array $parameters = []): MethodCollection $result = $this->client->performHttpCall('GET', $url); - return ResourceFactory::createBaseResourceCollection( - $this->client, - Method::class, - $result->_embedded->methods, - $result->_links - ); + return $this->buildResultCollection($result); } /** diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 9e4386fd9..faff971b4 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -2,11 +2,11 @@ namespace Mollie\Api\Endpoints; -use Mollie\Api\Contracts\SingleResourceEndpoint; +use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Onboarding; -class OnboardingEndpoint extends RestEndpoint implements SingleResourceEndpoint +class OnboardingEndpoint extends RestEndpoint implements SingleResourceEndpointContract { protected string $resourcePath = "onboarding/me"; diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index cb8e00505..8d0fbad18 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -11,7 +11,7 @@ class OrderEndpoint extends EndpointCollection { protected string $resourcePath = "orders"; - public const RESOURCE_ID_PREFIX = 'ord_'; + protected static string $resourceIdPrefix = 'ord_'; /** * @inheritDoc @@ -56,9 +56,7 @@ public function create(array $data = [], array $filters = []): Order */ public function update(string $orderId, array $data = []): Order { - if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($orderId); return parent::updateResource($orderId, $data); } @@ -76,9 +74,7 @@ public function update(string $orderId, array $data = []): Order */ public function get(string $orderId, array $parameters = []): Order { - if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($orderId); return parent::readResource($orderId, $parameters); } @@ -113,7 +109,7 @@ public function cancel(string $orderId, $parameters = []): ?Order * @return OrderCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 10a2c5e26..a1d69626f 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -12,7 +12,7 @@ class OrderLineEndpoint extends EndpointCollection { protected string $resourcePath = "orders_lines"; - public const RESOURCE_ID_PREFIX = 'odl_'; + protected static string $resourceIdPrefix = 'odl_'; /** * @inheritDoc @@ -46,9 +46,7 @@ public function update(string $orderId, string $orderlineId, array $data = []): { $this->parentId = $orderId; - if (empty($orderlineId) || strpos($orderlineId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order line ID: '{$orderlineId}'. An order line ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($orderlineId); return parent::updateResource($orderlineId, $data); } diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index 1f0d754f8..c0a49870f 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -10,8 +10,6 @@ class OrderPaymentEndpoint extends EndpointCollection { protected string $resourcePath = "orders_payments"; - public const RESOURCE_ID_PREFIX = 'tr_'; - /** * @inheritDoc */ diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index 06611423e..1e514680b 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -70,7 +70,7 @@ public function pageForId($orderId, array $parameters = []) { $this->parentId = $orderId; - return parent::fetchCollection(null, null, $parameters); + return $this->fetchCollection(null, null, $parameters); } /** diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/OrderShipmentEndpoint.php similarity index 91% rename from src/Endpoints/ShipmentEndpoint.php rename to src/Endpoints/OrderShipmentEndpoint.php index 7d52fa669..fb09156bd 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/OrderShipmentEndpoint.php @@ -7,11 +7,11 @@ use Mollie\Api\Resources\Shipment; use Mollie\Api\Resources\ShipmentCollection; -class ShipmentEndpoint extends EndpointCollection +class OrderShipmentEndpoint extends EndpointCollection { protected string $resourcePath = "orders_shipments"; - public const RESOURCE_ID_PREFIX = 'shp_'; + protected static string $resourceIdPrefix = 'shp_'; /** * @inheritDoc @@ -109,9 +109,7 @@ public function getForId(string $orderId, string $shipmentId, array $parameters */ public function update(string $orderId, $shipmentId, array $data = []): Shipment { - if (empty($shipmentId) || strpos($shipmentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid subscription ID: '{$shipmentId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($shipmentId); $this->parentId = $orderId; diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index 33a2f46a1..63be47629 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -2,11 +2,11 @@ namespace Mollie\Api\Endpoints; -use Mollie\Api\Contracts\SingleResourceEndpoint; +use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Partner; -class OrganizationPartnerEndpoint extends RestEndpoint implements SingleResourceEndpoint +class OrganizationPartnerEndpoint extends RestEndpoint implements SingleResourceEndpointContract { protected string $resourcePath = "organizations/me/partner"; diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 4e1db7130..c5d55e6e0 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -12,7 +12,7 @@ class PaymentEndpoint extends EndpointCollection { protected string $resourcePath = "payments"; - public const RESOURCE_ID_PREFIX = 'tr_'; + protected static string $resourceIdPrefix = 'tr_'; /** * @inheritDoc @@ -57,9 +57,7 @@ public function create(array $data = [], array $filters = []): Payment */ public function update($paymentId, array $data = []): Payment { - if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($paymentId); return parent::updateResource($paymentId, $data); } @@ -77,9 +75,7 @@ public function update($paymentId, array $data = []): Payment */ public function get($paymentId, array $parameters = []): Payment { - if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($paymentId); return parent::readResource($paymentId, $parameters); } @@ -128,7 +124,7 @@ public function cancel(string $paymentId, array $data = []): ?Payment * @return PaymentCollection * @throws ApiException */ - public function collect(string $from = null, int $limit = null, array $parameters = []): PaymentCollection + public function page(string $from = null, int $limit = null, array $parameters = []): PaymentCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index c783c540c..ef695f4d6 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -11,7 +11,7 @@ class PaymentLinkEndpoint extends EndpointCollection { protected string $resourcePath = "payment-links"; - public const RESOURCE_ID_PREFIX = 'pl_'; + protected static string $resourceIdPrefix = 'pl_'; /** * @inheritDoc @@ -55,9 +55,7 @@ public function create(array $data = [], array $filters = []): PaymentLink */ public function get(string $paymentLinkId, array $parameters = []): PaymentLink { - if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment link ID: '{$paymentLinkId}'. A payment link ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($paymentLinkId); return parent::readResource($paymentLinkId, $parameters); } @@ -72,7 +70,7 @@ public function get(string $paymentLinkId, array $parameters = []): PaymentLink * @return PaymentLinkCollection * @throws ApiException */ - public function collect(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection + public function page(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index c910ebcd9..5e3198ec6 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -14,7 +14,8 @@ class ProfileEndpoint extends EndpointCollection protected $resourceClass = Profile::class; - public const RESOURCE_ID_PREFIX = 'pfl_'; + protected static string $resourceIdPrefix = 'pfl_'; + /** * @inheritDoc */ @@ -77,9 +78,7 @@ public function get($profileId, array $parameters = []): Profile */ public function update(string $profileId, array $data = []): Profile { - if (empty($profileId) || strpos($profileId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid profile id: '{$profileId}'. An profile id should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($profileId); return parent::updateResource($profileId, $data); } @@ -126,7 +125,7 @@ public function delete($profileId, array $data = []): ?Profile * @return ProfileCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 09b0d03c3..3ff2c39de 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -37,7 +37,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Refu * @return RefundCollection * @throws ApiException */ - public function collect(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection + public function page(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index a266f3633..873b483a2 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -2,13 +2,22 @@ namespace Mollie\Api\Endpoints; -use Mollie\Api\Contracts\SingleResourceEndpoint; +use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\ResourceFactory; +use RuntimeException; abstract class RestEndpoint extends BaseEndpoint { + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ + protected static string $resourceIdPrefix; + /** * @param array $body * @param array $filters @@ -48,10 +57,6 @@ protected function updateResource(string $id, array $body = []): ?BaseResource $this->parseRequestBody($body) ); - if ($result == null) { - return null; - } - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); } @@ -65,7 +70,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (! $this instanceof SingleResourceEndpoint && empty($id)) { + if (!$this instanceof SingleResourceEndpointContract && empty($id)) { throw new ApiException("Invalid resource id."); } @@ -100,11 +105,28 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource $this->parseRequestBody($body) ); - if ($result == null) { - return null; + return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + } + + protected function guardAgainstInvalidId(string $id): void + { + if (empty(static::$resourceIdPrefix)) { + throw new RuntimeException("Resource ID prefix is not set."); } - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + if (empty($id) || strpos($id, static::$resourceIdPrefix) !== 0) { + $resourceType = $this->getResourceType(); + + throw new ApiException("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '" . static::$resourceIdPrefix . "'."); + } + } + + public function getResourceType(): string + { + $resourceClass = $this->getResourceObject()::class; + $classBasename = basename(str_replace("\\", "/", $resourceClass)); +\ + return strtolower($classBasename); } /** diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 05e273892..31a5c9a93 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -75,7 +75,7 @@ public function open(): Settlement * @return SettlementCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection { return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index c7bace563..bc7a562ca 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -11,8 +11,6 @@ class TerminalEndpoint extends EndpointCollection { protected string $resourcePath = "terminals"; - public const RESOURCE_ID_PREFIX = 'term_'; - /** * @inheritDoc */ @@ -59,7 +57,7 @@ public function get(string $terminalId, array $parameters = []): Terminal * @return TerminalCollection * @throws ApiException */ - public function collect(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection { return parent::fetchCollection($from, $limit, $parameters); } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 75388ef25..2b593481a 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -12,7 +12,7 @@ class ApiException extends \Exception /** * @var string */ - protected ?string $field; + protected ?string $field = null; /** * @var string @@ -65,12 +65,12 @@ public function __construct( $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); $message = "[{$formattedRaisedAt}] " . $message; - if (! empty($field)) { + if (!empty($field)) { $this->field = (string)$field; $message .= ". Field: {$this->field}"; } - if (! empty($response)) { + if (!empty($response)) { $this->response = $response; $object = static::parseResponseBody($this->response); @@ -110,7 +110,7 @@ public static function createFromResponse(ResponseInterface $response, ?RequestI $object = static::parseResponseBody($response); $field = null; - if (! empty($object->field)) { + if (!empty($object->field)) { $field = $object->field; } @@ -161,7 +161,7 @@ public function getResponse(): ?ResponseInterface */ public function hasResponse(): bool { - return ! ! $this->response; + return !!$this->response; } /** diff --git a/src/HandlesDebugging.php b/src/HandlesDebugging.php index a3c1f4103..05bfe9e74 100644 --- a/src/HandlesDebugging.php +++ b/src/HandlesDebugging.php @@ -2,7 +2,7 @@ namespace Mollie\Api; -use Mollie\Api\Contracts\SupportsDebugging; +use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; /** @@ -39,7 +39,7 @@ public function disableDebugging(): void */ public function setDebugging(bool $enable) { - if (! $this->httpClient instanceof SupportsDebugging) { + if (!$this->httpClient instanceof SupportsDebuggingContract) { throw new HttpAdapterDoesNotSupportDebuggingException( "Debugging is not supported by " . get_class($this->httpClient) . "." ); diff --git a/src/HttpAdapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php similarity index 51% rename from src/HttpAdapter/CurlMollieHttpAdapter.php rename to src/Http/Adapter/CurlMollieHttpAdapter.php index 1f6775efb..e326d4d51 100644 --- a/src/HttpAdapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -1,13 +1,17 @@ attemptRequest($meethod, $url, $headers, $body); + return ResponseHandler::create() + ->handle( + $this->attemptRequest($method, $url, $headers, $body), + $body + ); } catch (CurlConnectTimeoutException $e) { - return null; + return ResponseHandler::noResponse(); } } @@ -61,89 +64,111 @@ public function send(string $meethod, string $url, $headers, ?string $body): ?\s } /** - * @param string $httpMethod + * @param string $method * @param string $url * @param array $headers - * @param string $httpBody - * @return \stdClass|void|null + * @param string $body + * @return Response * @throws \Mollie\Api\Exceptions\ApiException */ - protected function attemptRequest(string $httpMethod, string $url, array $headers, string $httpBody): ?\stdClass + protected function attemptRequest(string $method, string $url, array $headers = [], ?string $body): Response + { + $curl = $this->initializeCurl($url); + $this->setCurlHeaders($curl, $headers); + $this->setCurlMethodOptions($curl, $method, $body); + + $startTime = microtime(true); + $response = curl_exec($curl); + $endTime = microtime(true); + + if ($response === false) { + $this->handleCurlError($curl, $endTime - $startTime); + } + + [$headers, $content, $statusCode] = $this->extractResponseDetails($curl, $response); + curl_close($curl); + + return new Response($statusCode, $headers, $content, ''); + } + + private function initializeCurl(string $url) { $curl = curl_init($url); - $headers["Content-Type"] = "application/json"; + $headerValues["Content-Type"] = "application/json"; curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $this->parseHeaders($headers)); + curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::DEFAULT_CONNECT_TIMEOUT); curl_setopt($curl, CURLOPT_TIMEOUT, self::DEFAULT_TIMEOUT); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_CAINFO, CaBundle::getBundledCaBundlePath()); - switch ($httpMethod) { + return $curl; + } + + private function setCurlHeaders($curl, array $headers) + { + $headers["Content-Type"] = "application/json"; + + curl_setopt($curl, CURLOPT_HTTPHEADER, $this->parseHeaders($headers)); + } + + private function setCurlMethodOptions($curl, string $method, ?string $body): void + { + switch ($method) { case MollieApiClient::HTTP_POST: curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody); - + curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; - case MollieApiClient::HTTP_GET: - break; - case MollieApiClient::HTTP_PATCH: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH'); - curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody); + case MollieApiClient::HTTP_PATCH: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_PATCH); + curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; - case MollieApiClient::HTTP_DELETE: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); - curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody); + case MollieApiClient::HTTP_DELETE: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_DELETE); + curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; + + case MollieApiClient::HTTP_GET: default: - throw new \InvalidArgumentException("Invalid http method: " . $httpMethod); + if ($method !== MollieApiClient::HTTP_GET) { + throw new \InvalidArgumentException("Invalid HTTP method: " . $method); + } + break; } + } - $startTime = microtime(true); - $response = curl_exec($curl); - $endTime = microtime(true); - - if ($response === false) { - $executionTime = $endTime - $startTime; - $curlErrorNumber = curl_errno($curl); - $curlErrorMessage = "Curl error: " . curl_error($curl); - - if ($this->isConnectTimeoutError($curlErrorNumber, $executionTime)) { - throw new CurlConnectTimeoutException("Unable to connect to Mollie. " . $curlErrorMessage); - } + private function handleCurlError($curl, float $executionTime): void + { + $curlErrorNumber = curl_errno($curl); + $curlErrorMessage = "Curl error: " . curl_error($curl); - throw new ApiException($curlErrorMessage); + if ($this->isConnectTimeoutError($curlErrorNumber, $executionTime)) { + throw new CurlConnectTimeoutException("Unable to connect to Mollie. " . $curlErrorMessage); } - $statusCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); - curl_close($curl); - - return $this->parseResponseBody($response, $statusCode, $httpBody); + throw new ApiException($curlErrorMessage); } - /** - * The version number for the underlying http client, if available. - * @example Guzzle/6.3 - * - * @return string|null - */ - public function versionString(): string + private function extractResponseDetails($curl, string $response): array { - return 'Curl/*'; - } + $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); + $headerValues = substr($response, 0, $headerSize); + $content = substr($response, $headerSize); + $statusCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE); - /** - * Whether this http adapter provides a debugging mode. If debugging mode is enabled, the - * request will be included in the ApiException. - * - * @return bool - */ - public function supportsDebugging(): bool - { - return false; + $headers = []; + $headerLines = explode("\r\n", $headerValues); + foreach ($headerLines as $headerLine) { + if (strpos($headerLine, ':') !== false) { + list($key, $value) = explode(': ', $headerLine, 2); + $headers[$key] = $value; + } + } + + return [$headers, $content, $statusCode]; } /** @@ -175,58 +200,7 @@ protected function isConnectTimeoutError(int $curlErrorNumber, $executionTime): return false; } - /** - * @param string $response - * @param int $statusCode - * @param string $httpBody - * @return \stdClass|null - * @throws \Mollie\Api\Exceptions\ApiException - */ - protected function parseResponseBody(string $response, int $statusCode, string $httpBody): ?\stdClass - { - if (empty($response)) { - if ($statusCode === self::HTTP_NO_CONTENT) { - return null; - } - - throw new ApiException("No response body found."); - } - - $body = @json_decode($response); - - // GUARDS - if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$response}'."); - } - - if (isset($body->error)) { - throw new ApiException($body->error->message); - } - - if ($statusCode >= 400) { - $message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}"; - - $field = null; - - if (! empty($body->field)) { - $field = $body->field; - } - - if (isset($body->_links, $body->_links->documentation)) { - $message .= ". Documentation: {$body->_links->documentation->href}"; - } - - if ($httpBody) { - $message .= ". Request body: {$httpBody}"; - } - - throw new ApiException($message, $statusCode, $field); - } - - return $body; - } - - protected function parseHeaders(array $headers): array + private function parseHeaders(array $headers): array { $result = []; @@ -236,4 +210,15 @@ protected function parseHeaders(array $headers): array return $result; } + + /** + * The version number for the underlying http client, if available. + * @example Guzzle/6.3 + * + * @return string|null + */ + public function version(): string + { + return 'Curl/*'; + } } diff --git a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php similarity index 76% rename from src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php rename to src/Http/Adapter/GuzzleMollieHttpAdapter.php index 5eba90963..7be5e581e 100644 --- a/src/HttpAdapter/Guzzle6And7MollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -1,6 +1,6 @@ push($retryMiddlewareFactory->retry()); @@ -60,22 +64,22 @@ public static function createDefault(): self 'handler' => $handlerStack, ]); - return new Guzzle6And7MollieHttpAdapter($client); + return new GuzzleMollieHttpAdapter($client); } /** * Send a request to the specified Mollie api url. * - * @param string $meethod + * @param string $method * @param string $url * @param array $headers * @param string $body - * @return \stdClass|null + * @return ResponseContract * @throws \Mollie\Api\Exceptions\ApiException */ - public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass + public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - $request = new Request($meethod, $url, $headers, $body); + $request = new Request($method, $url, $headers, $body); try { $response = $this->httpClient->send($request, ['http_errors' => false]); @@ -95,7 +99,8 @@ public function send(string $meethod, string $url, $headers, ?string $body): ?\s throw new ApiException($e->getMessage(), $e->getCode(), null, $request, null); } - return $this->parseResponseBody($response); + return PsrResponseHandler::create() + ->handle($response, $response->getStatusCode(), $body); } /** @@ -130,20 +135,15 @@ private function parseResponseBody(ResponseInterface $response): ?\stdClass } /** - * The version number for the underlying http client, if available. This is used to report the UserAgent to Mollie, - * for convenient support. - * @example Guzzle/6.3 + * The version number for the underlying http client, if available. + * This is used to report the UserAgent to Mollie, for convenient support. + * + * @example Guzzle/7.0 * * @return string|null */ - public function versionString(): ?string + public function version(): string { - if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { // Guzzle 7 - return "Guzzle/" . ClientInterface::MAJOR_VERSION; - } elseif (defined('\GuzzleHttp\ClientInterface::VERSION')) { // Before Guzzle 7 - return "Guzzle/" . ClientInterface::VERSION; - } - - return null; + return "Guzzle/" . ClientInterface::MAJOR_VERSION; } } diff --git a/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php b/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php similarity index 96% rename from src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php rename to src/Http/Adapter/GuzzleRetryMiddlewareFactory.php index 15ef49a32..f705ad1da 100644 --- a/src/HttpAdapter/Guzzle6And7RetryMiddlewareFactory.php +++ b/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php @@ -1,6 +1,6 @@ guzzleIsDetected()) { $guzzleVersion = $this->guzzleMajorVersionNumber(); if ($guzzleVersion && in_array($guzzleVersion, [6, 7])) { - return Guzzle6And7MollieHttpAdapter::createDefault(); + return GuzzleMollieHttpAdapter::createDefault(); } } return new CurlMollieHttpAdapter; } - if ($httpClient instanceof MollieHttpAdapterInterface) { + if ($httpClient instanceof MollieHttpAdapterContract) { return $httpClient; } if ($httpClient instanceof \GuzzleHttp\ClientInterface) { - return new Guzzle6And7MollieHttpAdapter($httpClient); + return new GuzzleMollieHttpAdapter($httpClient); } throw new UnrecognizedClientException('The provided http client or adapter was not recognized.'); diff --git a/src/HttpAdapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php similarity index 72% rename from src/HttpAdapter/PSR18MollieHttpAdapter.php rename to src/Http/Adapter/PSR18MollieHttpAdapter.php index 69c111ca4..407542782 100644 --- a/src/HttpAdapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -1,15 +1,22 @@ createRequest($meethod, $url, $headers, $body ?? ''); + $request = $this->createRequest($method, $url, $headers, $body ?? ''); $response = $this->httpClient->sendRequest($request); - $body = (string) $response->getBody(); - - return json_decode($body); + return PsrResponseHandler::create() + ->handle($response, $response->getStatusCode(), $body); } catch (\Exception $e) { - throw new ApiException("Error while sending request to Mollie API: " . $e->getMessage(), 0, $e); + if (!$this->debug) { + $request = null; + } + + throw new ApiException( + "Error while sending request to Mollie API: " . $e->getMessage(), + 0, + $e, + $request, + null + ); } } /** * {@inheritdoc} */ - public function versionString(): string + public function version(): string { return 'PSR18MollieHttpAdapter'; } diff --git a/src/Http/HasHttpPhrases.php b/src/Http/HasHttpPhrases.php new file mode 100644 index 000000000..7b12f2f90 --- /dev/null +++ b/src/Http/HasHttpPhrases.php @@ -0,0 +1,72 @@ + 'Continue', + 101 => 'Switching Protocols', + 102 => 'Processing', + 103 => 'Early Hints', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 207 => 'Multi-Status', + 208 => 'Already Reported', + 226 => 'IM Used', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 306 => 'Switch Proxy', + 307 => 'Temporary Redirect', + 308 => 'Permanent Redirect', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Payload Too Large', + 414 => 'URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Range Not Satisfiable', + 417 => 'Expectation Failed', + 418 => "I'm a teapot", + 421 => 'Misdirected Request', + 422 => 'Unprocessable Entity', + 423 => 'Locked', + 424 => 'Failed Dependency', + 425 => 'Too Early', + 426 => 'Upgrade Required', + 428 => 'Precondition Required', + 429 => 'Too Many Requests', + 431 => 'Request Header Fields Too Large', + 451 => 'Unavailable For Legal Reasons', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 506 => 'Variant Also Negotiates', + 507 => 'Insufficient Storage', + 508 => 'Loop Detected', + 510 => 'Not Extended', + 511 => 'Network Authentication Required', + ]; +} diff --git a/src/HttpAdapter/IsDebuggable.php b/src/Http/IsDebuggable.php similarity index 84% rename from src/HttpAdapter/IsDebuggable.php rename to src/Http/IsDebuggable.php index b23269af1..5bcc458e7 100644 --- a/src/HttpAdapter/IsDebuggable.php +++ b/src/Http/IsDebuggable.php @@ -1,6 +1,8 @@ debug = true; @@ -30,7 +32,7 @@ public function enableDebugging(): MollieHttpAdapterInterface * * @return $this */ - public function disableDebugging(): MollieHttpAdapterInterface + public function disableDebugging(): MollieHttpAdapterContract { $this->debug = false; diff --git a/src/Http/NoResponse.php b/src/Http/NoResponse.php new file mode 100644 index 000000000..d3538618d --- /dev/null +++ b/src/Http/NoResponse.php @@ -0,0 +1,23 @@ +responseHandler = $responseHandler; + } + + public static function create(): self + { + return new self(new ResponseHandler()); + } + + /** + * Undocumented function + * + * @param mixed|callback|ResponseContract|null $response + * @param int $code + * @param string|null $requestBody + * @return ResponseContract + */ + public function handle(?ResponseInterface $response = null, int $code, ?string $requestBody = null): ResponseContract + { + if ($response === null) { + return ResponseHandler::noResponse(); + } + + if (!$response instanceof ResponseInterface) { + throw new RuntimeException("Response must be an instance of ResponseInterface."); + } + + $body = (string) $response->getBody(); + + return $this->responseHandler->handle( + new Response( + $code, + $response->getHeaders(), + $body + ), + $requestBody + ); + } +} diff --git a/src/Http/Response.php b/src/Http/Response.php new file mode 100644 index 000000000..cced992a9 --- /dev/null +++ b/src/Http/Response.php @@ -0,0 +1,107 @@ +statusCode = $statusCode; + $this->headers = $headers; + $this->body = $body; + $this->reasonPhrase = $reasonPhrase; + } + + /** + * Get the body of the response. + * + * @return string + */ + public function body(): string + { + return $this->body; + } + + /** + * Get the JSON decoded body of the response as an array or scalar value. + * + * @return \stdClass + */ + public function json(): \stdClass + { + if (!$this->decoded) { + $this->decoded = @json_decode($this->body()); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new ApiException("Unable to decode Mollie response: '{$this->body()}'."); + } + } + + return $this->decoded; + } + + public function status(): int + { + return $this->statusCode; + } + + public function getReasonPhrase(): string + { + if (empty($this->reasonPhrase) && isset(static::$phrases[$this->statusCode])) { + return static::$phrases[$this->statusCode]; + } + + return $this->reasonPhrase; + } + + public function getHeaders(): array + { + return $this->headers; + } + + public function hasHeader(string $name): bool + { + return isset($this->headers[$name]); + } + + public function getHeader(string $name): array + { + return $this->hasHeader($name) + ? $this->headers[$name] + : []; + } + + public function getHeaderLine(string $name): string + { + return implode(', ', $this->getHeader($name)); + } +} diff --git a/src/Http/ResponseHandler.php b/src/Http/ResponseHandler.php new file mode 100644 index 000000000..c1128ce13 --- /dev/null +++ b/src/Http/ResponseHandler.php @@ -0,0 +1,101 @@ +guard($response); + + $this->throwExceptionIfRequestFailed($response, $requestBody); + + return $response; + } + + public static function create(): self + { + return new static(); + } + + public static function noResponse(): ResponseContract + { + return (new static())->handle(null); + } + + protected function guard(ResponseContract $response): void + { + $this->guardNoContentWithBody($response); + $this->guardJsonNotDecodable($response); + + // @todo check if this is still necessary as it seems to be from api v1 + if (isset($response->json()->error)) { + throw new ApiException($response->json()->error->message); + } + } + + protected function guardNoContentWithBody(ResponseContract $response): void + { + if ($response->status() === ResponseStatusCode::HTTP_NO_CONTENT && !empty($response->body())) { + throw new ApiException("No response body found."); + } + } + + protected function guardJsonNotDecodable(ResponseContract $response): void + { + $response->json(); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new ApiException("Unable to decode Mollie response: '{$response->body()}'."); + } + } + + protected function throwExceptionIfRequestFailed(ResponseContract $response, ?string $requestBody): void + { + if ($this->requestSucceeded($response->status())) { + return; + } + + $body = $response->json(); + + $message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}"; + + $field = null; + + if (!empty($body->field)) { + $field = $body->field; + } + + if (isset($body->_links, $body->_links->documentation)) { + $message .= ". Documentation: {$body->_links->documentation->href}"; + } + + if ($requestBody) { + $message .= ". Request body: {$body}"; + } + + throw new ApiException($message, $response->status(), $field); + } + + /** + * Determine if the response indicates a client or server error occurred. + * + * @return bool + */ + private function requestSucceeded(int $status) + { + return $status < ResponseStatusCode::HTTP_BAD_REQUEST; + } +} diff --git a/src/Http/ResponseStatusCode.php b/src/Http/ResponseStatusCode.php new file mode 100644 index 000000000..27ca4caaa --- /dev/null +++ b/src/Http/ResponseStatusCode.php @@ -0,0 +1,70 @@ + CustomerPaymentsEndpoint::class, 'customers' => CustomerEndpoint::class, 'invoices' => InvoiceEndpoint::class, - 'mandates' => MandateEndpoint::class, + 'mandates' => CustomerMandateEndpoint::class, 'methods' => MethodEndpoint::class, 'onboarding' => OnboardingEndpoint::class, 'orderLines' => OrderLineEndpoint::class, @@ -201,8 +201,8 @@ private function initializeEndpoints(): void 'settlementPayments' => SettlementPaymentEndpoint::class, 'settlementRefunds' => SettlementRefundEndpoint::class, 'settlements' => SettlementsEndpoint::class, - 'shipments' => ShipmentEndpoint::class, - 'subscriptions' => SubscriptionEndpoint::class, + 'shipments' => OrderShipmentEndpoint::class, + 'subscriptions' => CustomerSubscriptionEndpoint::class, 'terminals' => TerminalEndpoint::class, 'wallets' => WalletEndpoint::class, ]; @@ -217,7 +217,7 @@ private function initializeVersionStrings(): void $this->addVersionString("Mollie/" . self::CLIENT_VERSION); $this->addVersionString("PHP/" . phpversion()); - if ($clientVersion = $this->httpClient->versionString()) { + if ($clientVersion = $this->httpClient->version()) { $this->addVersionString($clientVersion); } } @@ -319,10 +319,10 @@ public function addVersionString($versionString): self * @param string $path * @param string|null $body * - * @return \stdClass + * @return Response * @throws ApiException */ - public function performHttpCall(string $method, string $path, ?string $body = null): \stdClass + public function performHttpCall(string $method, string $path, ?string $body = null): Response { $url = $this->buildApiUrl($path); @@ -336,10 +336,10 @@ public function performHttpCall(string $method, string $path, ?string $body = nu * @param string $url * @param string|null $body * - * @return \stdClass + * @return Response * @throws ApiException */ - public function performHttpCallToFullUrl(string $method, string $url, ?string $body = null): \stdClass + public function performHttpCallToFullUrl(string $method, string $url, ?string $body = null): Response { $this->ensureApiKeyIsSet(); @@ -403,18 +403,6 @@ protected function prepareHeaders(string $method, ?string $body): array return $this->applyIdempotencyKey($headers, $method); } - /** - * When unserializing a collection or a resource, this class should restore itself. - * - * Note that if you have set an HttpAdapter, this adapter is lost on wakeup and reset to the default one. - * - * @throws IncompatiblePlatform If suddenly unserialized on an incompatible platform. - */ - public function __wakeup() - { - $this->__construct(); - } - /** * Magic getter to access the endpoints. * @@ -431,4 +419,23 @@ public function __get(string $name) throw new \Exception("Undefined endpoint: $name"); } + + /** + * @return array + */ + public function __serialize(): array + { + return ['apiEndpoint' => $this->apiEndpoint]; + } + + /** + * @param array $data + * @return void + * @throws IncompatiblePlatform + */ + public function __unserialize(array $data): void + { + $this->__construct(); + $this->apiEndpoint = $data['apiEndpoint']; + } } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 3434c4570..2577e6216 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -38,15 +38,7 @@ final public function next(): ?CursorCollection return null; } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->next->href); - - $collection = new static($this->client, $result->count, $result->_links); - - foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { - $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject()); - } - - return $collection; + return $this->fetchCollection($this->_links->next->href); } /** @@ -61,7 +53,12 @@ final public function previous(): ?CursorCollection return null; } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->previous->href); + return $this->fetchCollection($this->_links->previous->href); + } + + private function fetchCollection(string $url): CursorCollection + { + $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $url); $collection = new static($this->client, $result->count, $result->_links); diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 07a3a8459..81e81b9e1 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Contracts\ResponseContract; use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] @@ -10,13 +11,13 @@ class ResourceFactory /** * Create resource object from Api result * - * @param object $apiResult + * @param ResponseContract $response * @param BaseResource $resource * @return BaseResource */ - public static function createFromApiResult(object $apiResult, BaseResource $resource): BaseResource + public static function createFromApiResult(ResponseContract $response, BaseResource $resource): BaseResource { - foreach ($apiResult as $property => $value) { + foreach ($response->json() as $property => $value) { $resource->{$property} = $value; } @@ -41,6 +42,7 @@ public static function createBaseResourceCollection( $resourceCollectionClass = $resourceCollectionClass ?: $resourceClass . 'Collection'; $data = $data ?: []; + /** @var BaseCollection $result */ $result = new $resourceCollectionClass(count($data), $_links); foreach ($data as $item) { $result[] = static::createFromApiResult($item, new $resourceClass($client)); @@ -68,6 +70,7 @@ public static function createCursorResourceCollection( $resourceCollectionClass = $resourceClass . 'Collection'; } + /** @var CursorCollection $data */ $data = new $resourceCollectionClass($client, count($input), $_links); foreach ($input as $item) { $data[] = static::createFromApiResult($item, new $resourceClass($client)); diff --git a/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php index 114e09451..9b99dbf8d 100644 --- a/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php @@ -2,7 +2,7 @@ namespace Tests\Mollie\API\HttpAdapter; -use Mollie\Api\HttpAdapter\CurlMollieHttpAdapter; +use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; use PHPUnit\Framework\TestCase; class CurlMollieHttpAdapterTest extends TestCase diff --git a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php similarity index 85% rename from tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php rename to tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php index fd0a6b9a9..3233d1028 100644 --- a/tests/Mollie/API/HttpAdapter/Guzzle6And7MollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php @@ -5,19 +5,19 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\Request; -use Mollie\Api\Contracts\SupportsDebugging; +use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter; +use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; -class Guzzle6And7MollieHttpAdapterTest extends TestCase +class GuzzleMollieHttpAdapterTest extends TestCase { /** @test */ public function testDebuggingIsSupported() { - $adapter = Guzzle6And7MollieHttpAdapter::createDefault(); - $this->assertTrue($adapter instanceof SupportsDebugging); + $adapter = GuzzleMollieHttpAdapter::createDefault(); + $this->assertTrue($adapter instanceof SupportsDebuggingContract); $this->assertFalse($adapter->debuggingIsActive()); $adapter->enableDebugging(); @@ -42,7 +42,7 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() ) ); - $adapter = new Guzzle6And7MollieHttpAdapter($guzzleClient); + $adapter = new GuzzleMollieHttpAdapter($guzzleClient); $adapter->enableDebugging(); try { @@ -74,7 +74,7 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() ) ); - $adapter = new Guzzle6And7MollieHttpAdapter($guzzleClient); + $adapter = new GuzzleMollieHttpAdapter($guzzleClient); $this->assertFalse($adapter->debuggingIsActive()); try { diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php index 5f11b7af8..f7279a89b 100644 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php @@ -2,20 +2,38 @@ namespace Tests\Mollie\API\HttpAdapter; -class MockMollieHttpAdapter implements \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface +use Mollie\Api\Contracts\ResponseContract; + +class MockMollieHttpAdapter implements \Mollie\Api\Contracts\MollieHttpAdapterContract { /** * @inheritDoc */ - public function send(string $meethod, string $url, $headers, ?string $body): \stdClass + public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - return (object) ['foo' => 'bar']; + return new class implements ResponseContract + { + public function json(): \stdClass + { + return (object) ['foo' => 'bar']; + } + + public function status(): int + { + return 200; + } + + public function body(): string + { + return 'foo'; + } + }; } /** * @inheritDoc */ - public function versionString(): string + public function version(): string { return 'mock-client/1.0'; } diff --git a/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php b/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php index 42e7523d4..a7fd93f8b 100644 --- a/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php +++ b/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php @@ -4,8 +4,8 @@ use GuzzleHttp\Client as GuzzleClient; use Mollie\Api\Exceptions\UnrecognizedClientException; -use Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter; -use Mollie\Api\HttpAdapter\MollieHttpAdapterPicker; +use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; +use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use PHPUnit\Framework\TestCase; class MollieHttpAdapterPickerTest extends TestCase @@ -17,7 +17,7 @@ public function createsAGuzzleAdapterIfNullIsPassedAndGuzzleIsDetected() $adapter = $picker->pickHttpAdapter(null); - $this->assertInstanceOf(Guzzle6And7MollieHttpAdapter::class, $adapter); + $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $adapter); } /** @test */ @@ -40,7 +40,7 @@ public function wrapsAGuzzleClientIntoAnAdapter() $adapter = $picker->pickHttpAdapter($guzzleClient); - $this->assertInstanceOf(Guzzle6And7MollieHttpAdapter::class, $adapter); + $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $adapter); } /** @test */ diff --git a/tests/Mollie/API/MollieApiClientTest.php b/tests/Mollie/API/MollieApiClientTest.php index abbdde2ca..5a6dfe5f6 100644 --- a/tests/Mollie/API/MollieApiClientTest.php +++ b/tests/Mollie/API/MollieApiClientTest.php @@ -7,8 +7,8 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; -use Mollie\Api\HttpAdapter\CurlMollieHttpAdapter; -use Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter; +use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; +use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; use Tests\Mollie\TestHelpers\FakeHttpAdapter; @@ -23,7 +23,7 @@ class MollieApiClientTest extends \PHPUnit\Framework\TestCase /** * @var MollieApiClient */ - private $mollieApiClient; + private MollieApiClient $mollieApiClient; protected function setUp(): void { @@ -127,7 +127,7 @@ public function testCanBeSerializedAndUnserialized() $client_copy = invade(unserialize($serialized)); $this->assertEmpty($client_copy->apiKey, "API key should not have been remembered"); - $this->assertInstanceOf(Guzzle6And7MollieHttpAdapter::class, $client_copy->httpClient, "A Guzzle client should have been set."); + $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->httpClient, "A Guzzle client should have been set."); $this->assertNull($client_copy->usesOAuth()); $this->assertEquals("https://mymollieproxy.local", $client_copy->getApiEndpoint(), "The API endpoint should be remembered"); diff --git a/tests/Mollie/Guzzle/RetryMiddlewareFactoryTest.php b/tests/Mollie/Guzzle/RetryMiddlewareFactoryTest.php index 1ee85e713..714415503 100644 --- a/tests/Mollie/Guzzle/RetryMiddlewareFactoryTest.php +++ b/tests/Mollie/Guzzle/RetryMiddlewareFactoryTest.php @@ -8,14 +8,14 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use Mollie\Api\HttpAdapter\Guzzle6And7RetryMiddlewareFactory; +use Mollie\Api\Http\Adapter\GuzzleRetryMiddlewareFactory; use PHPUnit\Framework\TestCase; class RetryMiddlewareFactoryTest extends TestCase { public function testRetriesConnectException() { - $middlewareFactory = new Guzzle6And7RetryMiddlewareFactory; + $middlewareFactory = new GuzzleRetryMiddlewareFactory; $mock = new MockHandler( [ @@ -35,7 +35,7 @@ public function testRetriesConnectException() public function testRetryLimit() { - $middlewareFactory = new Guzzle6And7RetryMiddlewareFactory; + $middlewareFactory = new GuzzleRetryMiddlewareFactory; $mock = new MockHandler( [ @@ -50,7 +50,7 @@ public function testRetryLimit() $handler = HandlerStack::create($mock); $handler->push($middlewareFactory->retry(false)); - $client = new Client([ 'handler' => $handler ]); + $client = new Client(['handler' => $handler]); $this->expectException(ConnectException::class); $this->expectExceptionMessage("Error 6"); @@ -60,7 +60,7 @@ public function testRetryLimit() public function testRetryDelay() { - $middlewareFactory = new Guzzle6And7RetryMiddlewareFactory; + $middlewareFactory = new GuzzleRetryMiddlewareFactory; $mock = new MockHandler( [ @@ -72,7 +72,7 @@ public function testRetryDelay() $handler = HandlerStack::create($mock); $handler->push($middlewareFactory->retry(true)); - $client = new Client([ 'handler' => $handler ]); + $client = new Client(['handler' => $handler]); $startTime = time(); $client->request('GET', '/')->getStatusCode(); diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php index c6c615e2b..9bad85e45 100644 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ b/tests/Mollie/TestHelpers/FakeHttpAdapter.php @@ -2,9 +2,11 @@ namespace Tests\Mollie\TestHelpers; -use Mollie\Api\HttpAdapter\MollieHttpAdapterInterface; +use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Http\PsrResponseHandler; -class FakeHttpAdapter implements MollieHttpAdapterInterface +class FakeHttpAdapter implements MollieHttpAdapterContract { /** * @var \stdClass|null @@ -41,26 +43,27 @@ public function __construct($response) } /** - * @param string $meethod + * @param string $method * @param string $url * @param string $headers * @param string $body - * @return \stdClass|void|null + * @return \stdClass|null */ - public function send(string $meethod, string $url, $headers, ?string $body): ?\stdClass + public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - $this->usedMethod = $meethod; + $this->usedMethod = $method; $this->usedUrl = $url; $this->usedHeaders = $headers; $this->usedBody = $body; - return $this->response; + return PsrResponseHandler::create() + ->handle($this->response, 200, $body); } /** * @return string */ - public function versionString(): string + public function version(): string { return 'fake'; } From 035d70ee0fde0b76b402a089a75cf25c4f9bae11 Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 25 Jun 2024 22:29:14 +0000 Subject: [PATCH 014/131] Fix styling --- src/Exceptions/ApiException.php | 8 ++++---- src/HandlesDebugging.php | 2 +- src/Http/Adapter/CurlMollieHttpAdapter.php | 4 ++++ src/Http/Adapter/MollieHttpAdapterPicker.php | 2 +- src/Http/Adapter/PSR18MollieHttpAdapter.php | 2 +- src/Http/PsrResponseHandler.php | 4 ++-- src/Http/Response.php | 2 +- src/Http/ResponseHandler.php | 4 ++-- src/MollieApiClient.php | 10 +++++----- tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php | 3 +-- 10 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 2b593481a..017274235 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -65,12 +65,12 @@ public function __construct( $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); $message = "[{$formattedRaisedAt}] " . $message; - if (!empty($field)) { + if (! empty($field)) { $this->field = (string)$field; $message .= ". Field: {$this->field}"; } - if (!empty($response)) { + if (! empty($response)) { $this->response = $response; $object = static::parseResponseBody($this->response); @@ -110,7 +110,7 @@ public static function createFromResponse(ResponseInterface $response, ?RequestI $object = static::parseResponseBody($response); $field = null; - if (!empty($object->field)) { + if (! empty($object->field)) { $field = $object->field; } @@ -161,7 +161,7 @@ public function getResponse(): ?ResponseInterface */ public function hasResponse(): bool { - return !!$this->response; + return ! ! $this->response; } /** diff --git a/src/HandlesDebugging.php b/src/HandlesDebugging.php index 05bfe9e74..ec4933896 100644 --- a/src/HandlesDebugging.php +++ b/src/HandlesDebugging.php @@ -39,7 +39,7 @@ public function disableDebugging(): void */ public function setDebugging(bool $enable) { - if (!$this->httpClient instanceof SupportsDebuggingContract) { + if (! $this->httpClient instanceof SupportsDebuggingContract) { throw new HttpAdapterDoesNotSupportDebuggingException( "Debugging is not supported by " . get_class($this->httpClient) . "." ); diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index e326d4d51..46d52700e 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -119,16 +119,19 @@ private function setCurlMethodOptions($curl, string $method, ?string $body): voi case MollieApiClient::HTTP_POST: curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); + break; case MollieApiClient::HTTP_PATCH: curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_PATCH); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); + break; case MollieApiClient::HTTP_DELETE: curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_DELETE); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); + break; case MollieApiClient::HTTP_GET: @@ -136,6 +139,7 @@ private function setCurlMethodOptions($curl, string $method, ?string $body): voi if ($method !== MollieApiClient::HTTP_GET) { throw new \InvalidArgumentException("Invalid HTTP method: " . $method); } + break; } } diff --git a/src/Http/Adapter/MollieHttpAdapterPicker.php b/src/Http/Adapter/MollieHttpAdapterPicker.php index 0d61f3cec..b709e1d29 100644 --- a/src/Http/Adapter/MollieHttpAdapterPicker.php +++ b/src/Http/Adapter/MollieHttpAdapterPicker.php @@ -16,7 +16,7 @@ class MollieHttpAdapterPicker implements MollieHttpAdapterPickerContract */ public function pickHttpAdapter($httpClient): MollieHttpAdapterContract { - if (!$httpClient) { + if (! $httpClient) { if ($this->guzzleIsDetected()) { $guzzleVersion = $this->guzzleMajorVersionNumber(); diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 407542782..c8e4ef227 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -61,7 +61,7 @@ public function send(string $method, string $url, $headers, ?string $body): Resp return PsrResponseHandler::create() ->handle($response, $response->getStatusCode(), $body); } catch (\Exception $e) { - if (!$this->debug) { + if (! $this->debug) { $request = null; } diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php index 70f1aff8d..4e2e89b56 100644 --- a/src/Http/PsrResponseHandler.php +++ b/src/Http/PsrResponseHandler.php @@ -23,7 +23,7 @@ public static function create(): self /** * Undocumented function * - * @param mixed|callback|ResponseContract|null $response + * @param mixed|callable|ResponseContract|null $response * @param int $code * @param string|null $requestBody * @return ResponseContract @@ -34,7 +34,7 @@ public function handle(?ResponseInterface $response = null, int $code, ?string $ return ResponseHandler::noResponse(); } - if (!$response instanceof ResponseInterface) { + if (! $response instanceof ResponseInterface) { throw new RuntimeException("Response must be an instance of ResponseInterface."); } diff --git a/src/Http/Response.php b/src/Http/Response.php index cced992a9..bda56fea9 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -58,7 +58,7 @@ public function body(): string */ public function json(): \stdClass { - if (!$this->decoded) { + if (! $this->decoded) { $this->decoded = @json_decode($this->body()); if (json_last_error() !== JSON_ERROR_NONE) { diff --git a/src/Http/ResponseHandler.php b/src/Http/ResponseHandler.php index c1128ce13..7d5269abe 100644 --- a/src/Http/ResponseHandler.php +++ b/src/Http/ResponseHandler.php @@ -48,7 +48,7 @@ protected function guard(ResponseContract $response): void protected function guardNoContentWithBody(ResponseContract $response): void { - if ($response->status() === ResponseStatusCode::HTTP_NO_CONTENT && !empty($response->body())) { + if ($response->status() === ResponseStatusCode::HTTP_NO_CONTENT && ! empty($response->body())) { throw new ApiException("No response body found."); } } @@ -74,7 +74,7 @@ protected function throwExceptionIfRequestFailed(ResponseContract $response, ?st $field = null; - if (!empty($body->field)) { + if (! empty($body->field)) { $field = $body->field; } diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index cae0abc2b..97aacda90 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,6 +2,8 @@ namespace Mollie\Api; +use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\ResponseContract as Response; use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; use Mollie\Api\Endpoints\BalanceTransactionEndpoint; @@ -9,15 +11,17 @@ use Mollie\Api\Endpoints\ClientEndpoint; use Mollie\Api\Endpoints\ClientLinkEndpoint; use Mollie\Api\Endpoints\CustomerEndpoint; +use Mollie\Api\Endpoints\CustomerMandateEndpoint; use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; +use Mollie\Api\Endpoints\CustomerSubscriptionEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; -use Mollie\Api\Endpoints\CustomerMandateEndpoint; use Mollie\Api\Endpoints\MethodEndpoint; use Mollie\Api\Endpoints\OnboardingEndpoint; use Mollie\Api\Endpoints\OrderEndpoint; use Mollie\Api\Endpoints\OrderLineEndpoint; use Mollie\Api\Endpoints\OrderPaymentEndpoint; use Mollie\Api\Endpoints\OrderRefundEndpoint; +use Mollie\Api\Endpoints\OrderShipmentEndpoint; use Mollie\Api\Endpoints\OrganizationEndpoint; use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; use Mollie\Api\Endpoints\PaymentCaptureEndpoint; @@ -35,14 +39,10 @@ use Mollie\Api\Endpoints\SettlementPaymentEndpoint; use Mollie\Api\Endpoints\SettlementRefundEndpoint; use Mollie\Api\Endpoints\SettlementsEndpoint; -use Mollie\Api\Endpoints\OrderShipmentEndpoint; -use Mollie\Api\Endpoints\CustomerSubscriptionEndpoint; use Mollie\Api\Endpoints\TerminalEndpoint; use Mollie\Api\Endpoints\WalletEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Contracts\MollieHttpAdapterContract; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; -use Mollie\Api\Contracts\ResponseContract as Response; /** * @property BalanceEndpoint $balances diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php index f7279a89b..541615165 100644 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php @@ -11,8 +11,7 @@ class MockMollieHttpAdapter implements \Mollie\Api\Contracts\MollieHttpAdapterCo */ public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - return new class implements ResponseContract - { + return new class implements ResponseContract { public function json(): \stdClass { return (object) ['foo' => 'bar']; From 18b13e8f57b65dac432c741afeece03ac7d68213 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 27 Jun 2024 23:06:14 +0200 Subject: [PATCH 015/131] merge in changes --- README.md | 2 +- phpstan-baseline.neon | 263 +++++++++++++++++- phpstan.neon | 6 - src/Contracts/ResponseContract.php | 4 +- src/Endpoints/BalanceEndpoint.php | 9 +- src/Endpoints/BalanceReportEndpoint.php | 13 +- src/Endpoints/BalanceTransactionEndpoint.php | 6 +- src/Endpoints/ChargebackEndpoint.php | 1 + src/Endpoints/ClientEndpoint.php | 4 +- src/Endpoints/ClientLinkEndpoint.php | 1 + src/Endpoints/CustomerEndpoint.php | 11 +- src/Endpoints/CustomerPaymentsEndpoint.php | 19 +- src/Endpoints/EndpointCollection.php | 2 +- src/Endpoints/InvoiceEndpoint.php | 2 + ...andateEndpoint.php => MandateEndpoint.php} | 12 +- src/Endpoints/MethodEndpoint.php | 13 +- src/Endpoints/OnboardingEndpoint.php | 1 + src/Endpoints/OrderEndpoint.php | 13 +- src/Endpoints/OrderLineEndpoint.php | 14 +- src/Endpoints/OrderPaymentEndpoint.php | 1 + src/Endpoints/OrderRefundEndpoint.php | 14 +- src/Endpoints/OrderShipmentEndpoint.php | 16 +- src/Endpoints/OrganizationEndpoint.php | 6 +- src/Endpoints/OrganizationPartnerEndpoint.php | 1 + src/Endpoints/PaymentCaptureEndpoint.php | 7 +- src/Endpoints/PaymentChargebackEndpoint.php | 11 +- src/Endpoints/PaymentEndpoint.php | 15 +- src/Endpoints/PaymentLinkEndpoint.php | 5 +- src/Endpoints/PaymentRefundEndpoint.php | 14 +- src/Endpoints/PaymentRouteEndpoint.php | 7 +- src/Endpoints/PermissionEndpoint.php | 4 +- src/Endpoints/ProfileEndpoint.php | 14 +- src/Endpoints/ProfileMethodEndpoint.php | 4 +- src/Endpoints/RefundEndpoint.php | 7 +- src/Endpoints/RestEndpoint.php | 24 +- src/Endpoints/SettlementCaptureEndpoint.php | 1 + .../SettlementChargebackEndpoint.php | 1 + src/Endpoints/SettlementPaymentEndpoint.php | 1 + src/Endpoints/SettlementRefundEndpoint.php | 1 + src/Endpoints/SettlementsEndpoint.php | 10 +- ...nEndpoint.php => SubscriptionEndpoint.php} | 24 +- src/Endpoints/TerminalEndpoint.php | 12 +- src/Endpoints/WalletEndpoint.php | 2 +- src/Exceptions/ApiException.php | 2 +- src/Http/Adapter/CurlMollieHttpAdapter.php | 6 +- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 39 +-- src/Http/Adapter/PSR18MollieHttpAdapter.php | 4 +- .../{NoResponse.php => EmptyResponse.php} | 9 +- src/Http/PsrResponseHandler.php | 47 +++- src/Http/Response.php | 17 +- src/Http/ResponseHandler.php | 35 ++- src/MollieApiClient.php | 43 +-- src/Resources/CursorCollection.php | 22 +- src/Resources/Customer.php | 11 +- src/Resources/Mandate.php | 11 +- src/Resources/Method.php | 6 +- src/Resources/Order.php | 37 +-- src/Resources/Payment.php | 50 ++-- src/Resources/Profile.php | 49 +++- src/Resources/ResourceFactory.php | 7 +- src/Resources/Shipment.php | 18 +- src/Resources/Subscription.php | 31 ++- .../API/Endpoints/BalanceEndpointTest.php | 2 +- .../API/Endpoints/ChargebackEndpointTest.php | 2 +- .../API/Endpoints/ClientEndpointTest.php | 2 +- .../API/Endpoints/CustomerEndpointTest.php | 2 +- .../API/Endpoints/InvoiceEndpointTest.php | 2 +- .../API/Endpoints/OrderEndpointTest.php | 2 +- .../API/Endpoints/PaymentEndpointTest.php | 2 +- .../API/Endpoints/ProfileEndpointTest.php | 2 +- .../API/Endpoints/RefundEndpointTest.php | 2 +- .../API/Endpoints/SettlementEndpointTest.php | 2 +- .../Endpoints/SubscriptionEndpointTest.php | 2 +- .../API/Endpoints/TerminalEndpointTest.php | 2 +- .../HttpAdapter/CurlMollieHttpAdapterTest.php | 16 -- .../GuzzleMollieHttpAdapterTest.php | 8 +- .../API/HttpAdapter/MockMollieHttpAdapter.php | 10 +- tests/Mollie/API/MollieApiClientTest.php | 6 +- .../API/Resources/CursorCollectionTest.php | 25 +- .../API/Resources/ResourceFactoryTest.php | 19 +- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 34 +-- 81 files changed, 804 insertions(+), 380 deletions(-) rename src/Endpoints/{CustomerMandateEndpoint.php => MandateEndpoint.php} (93%) rename src/Endpoints/{CustomerSubscriptionEndpoint.php => SubscriptionEndpoint.php} (90%) rename src/Http/{NoResponse.php => EmptyResponse.php} (66%) delete mode 100644 tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php diff --git a/README.md b/README.md index e05b773d1..8696756a8 100644 --- a/README.md +++ b/README.md @@ -394,7 +394,7 @@ To disable debugging again: $mollie->disableDebugging(); ``` -Please note that debugging is only available when using the default Guzzle http adapter (`Guzzle6And7MollieHttpAdapter`). +Please note that debugging is only available when using the default Guzzle http adapter (`GuzzleMollieHttpAdapter`). ## API documentation ## For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 56cabd08a..fae4008e3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,4 +2,265 @@ parameters: ignoreErrors: - message: "#^Variable \\$mollie might not be defined\\.$#" - path: examples/* + count: 1 + path: examples/captures/create-capture.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/captures/get-capture.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/captures/list-captures.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/client-links/create-client-link.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/create-customer-first-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/create-customer-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/create-customer-recurring-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/create-customer.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/delete-customer.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/list-customer-payments.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/customers/update-customer.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/invoices/list-invoices.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/mandates/create-mandate.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/mandates/list-mandates.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/mandates/revoke-mandate.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 2 + path: examples/orders/cancel-order-lines.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/cancel-order.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/create-order.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/list-methods.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/list-orders.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/refund-order-completely.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/refund-order-partially.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/update-order-line.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/update-order-lines-multiple.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/update-order.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/orders/webhook.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 2 + path: examples/pagination/backwards.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 2 + path: examples/pagination/basic_usage.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payment-links/create-payment-link.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payment-links/list-payment-links.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/create-capturable-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 2 + path: examples/payments/create-ideal-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 2 + path: examples/payments/create-payment-oauth.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/create-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/list-methods.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/list-payments.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/refund-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/return.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/update-payment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/payments/webhook.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/profiles/create-profile.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/profiles/delete-profile.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/profiles/list-profiles.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/profiles/update-profile.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/settlements/list-settlements.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/shipments/create-shipment-all.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/shipments/create-shipment-partial.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/shipments/get-shipment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/shipments/list-shipments.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/shipments/update-shipment.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/subscriptions/cancel-subscription.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/subscriptions/create-subscription.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/subscriptions/update-subscription.php diff --git a/phpstan.neon b/phpstan.neon index ecd56da76..5d1ecaba6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,12 +6,6 @@ parameters: - %currentWorkingDirectory%/examples excludePaths: - %currentWorkingDirectory%/vendor - ignoreErrors: - - '#Access to an undefined property Eloquent\\Liberator\\LiberatorProxyInterface::\$request#' - - '#Access to protected property Mollie\\Api\\MollieApiClient::\$apiKey#' - - '#Access to protected property Mollie\\Api\\MollieApiClient::\$httpClient#' - - '#Call to an undefined method Mollie\\Api\\HttpAdapter\\MollieHttpAdapterInterface::enableDebugging\(\)#' - - '#Call to an undefined method Mollie\\Api\\HttpAdapter\\MollieHttpAdapterInterface::disableDebugging\(\)#' treatPhpDocTypesAsCertain: false includes: - phpstan-baseline.neon diff --git a/src/Contracts/ResponseContract.php b/src/Contracts/ResponseContract.php index 633673726..05c1ec1d0 100644 --- a/src/Contracts/ResponseContract.php +++ b/src/Contracts/ResponseContract.php @@ -9,7 +9,9 @@ public function body(): string; /** * @return \stdClass */ - public function json(): \stdClass; + public function decode(): \stdClass; public function status(): int; + + public function isEmpty(): bool; } diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index 6ef69c291..52c76c252 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -36,14 +36,15 @@ protected function getResourceObject(): Balance * * @param string $balanceId * @param array $parameters - * @return \Mollie\Api\Resources\Balance|\Mollie\Api\Resources\BaseResource + * @return Balance * @throws ApiException */ public function get(string $balanceId, array $parameters = []): Balance { $this->guardAgainstInvalidId($balanceId); - return parent::readResource($balanceId, $parameters); + /** @var Balance */ + return $this->readResource($balanceId, $parameters); } /** @@ -57,7 +58,8 @@ public function get(string $balanceId, array $parameters = []): Balance */ public function primary(array $parameters = []): Balance { - return parent::readResource("primary", $parameters); + /** @var Balance */ + return $this->readResource("primary", $parameters); } /** @@ -72,6 +74,7 @@ public function primary(array $parameters = []): Balance */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection { + /** @var BalanceCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index 51e8af821..de8602433 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -26,19 +26,24 @@ protected function getResourceObject(): BalanceReport * @param string $balanceId * @param array $parameters * - * @return BalanceReport + * @return null|BalanceReport * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId(string $balanceId, array $parameters = []): BalanceReport + public function getForId(string $balanceId, array $parameters = []): ?BalanceReport { $this->parentId = $balanceId; - $result = $this->client->performHttpCall( + $response = $this->client->performHttpCall( self::REST_READ, $this->getResourcePath() . $this->buildQueryString($parameters) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + if ($response->isEmpty()) { + return null; + } + + /** @var BalanceReport */ + return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); } /** diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index ddeb4776b..fd6d321af 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -70,7 +70,8 @@ public function listForId(string $balanceId, array $parameters = []): BalanceTra { $this->parentId = $balanceId; - return parent::fetchCollection(null, null, $parameters); + /** @var BalanceTransactionCollection */ + return $this->fetchCollection(null, null, $parameters); } /** @@ -101,7 +102,8 @@ public function listForPrimary(array $parameters = []): BalanceTransactionCollec { $this->parentId = "primary"; - return parent::fetchCollection(null, null, $parameters); + /** @var BalanceTransactionCollection */ + return $this->fetchCollection(null, null, $parameters); } /** diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index e199a60ea..71d9502b7 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -39,6 +39,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Char */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): ChargebackCollection { + /** @var ChargebackCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index f633d4325..dd7e9651e 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -45,7 +45,8 @@ public function get(string $clientId, array $parameters = []): Client throw new ApiException("Client ID is empty."); } - return parent::readResource($clientId, $parameters); + /** @var Client */ + return $this->readResource($clientId, $parameters); } /** @@ -60,6 +61,7 @@ public function get(string $clientId, array $parameters = []): Client */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection { + /** @var ClientCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 80215a3fa..65498b145 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -30,6 +30,7 @@ protected function getResourceObject(): ClientLink */ public function create(array $data = []): ClientLink { + /** @var ClientLink */ return $this->createResource($data, []); } } diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index a6ad1b71d..e770f9027 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -40,6 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Cust */ public function create(array $data = [], array $filters = []): Customer { + /** @var Customer */ return $this->createResource($data, $filters); } @@ -55,6 +56,7 @@ public function create(array $data = [], array $filters = []): Customer */ public function get(string $customerId, array $parameters = []): Customer { + /** @var Customer */ return $this->readResource($customerId, $parameters); } @@ -65,14 +67,15 @@ public function get(string $customerId, array $parameters = []): Customer * * @param string $customerId * @param array $data - * @return Customer + * @return null|Customer * @throws ApiException */ - public function update(string $customerId, array $data = []): Customer + public function update(string $customerId, array $data = []): ?Customer { $this->guardAgainstInvalidId($customerId); - return parent::updateResource($customerId, $data); + /** @var null|Customer */ + return $this->updateResource($customerId, $data); } /** @@ -88,6 +91,7 @@ public function update(string $customerId, array $data = []): Customer */ public function delete(string $customerId, array $data = []): ?Customer { + /** @var null|Customer */ return $this->deleteResource($customerId, $data); } @@ -103,6 +107,7 @@ public function delete(string $customerId, array $data = []): ?Customer */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection { + /** @var CustomerCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index 010af19cc..376fdc7ea 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; @@ -35,7 +36,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Paym * @param array $filters * * @return Payment - * @throws \Mollie\Api\Exceptions\ApiException + * @throws ApiException */ public function createFor(Customer $customer, array $options = [], array $filters = []): Payment { @@ -49,14 +50,15 @@ public function createFor(Customer $customer, array $options = [], array $filter * @param array $options * @param array $filters * - * @return \Mollie\Api\Resources\Payment - * @throws \Mollie\Api\Exceptions\ApiException + * @return Payment + * @throws ApiException */ public function createForId($customerId, array $options = [], array $filters = []) { $this->parentId = $customerId; - return parent::createResource($options, $filters); + /** @var Payment */ + return $this->createResource($options, $filters); } /** @@ -66,7 +68,7 @@ public function createForId($customerId, array $options = [], array $filters = [ * @param array $parameters * * @return PaymentCollection - * @throws \Mollie\Api\Exceptions\ApiException + * @throws ApiException */ public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection { @@ -100,14 +102,15 @@ public function iteratorFor( * @param int $limit * @param array $parameters * - * @return \Mollie\Api\Resources\PaymentCollection - * @throws \Mollie\Api\Exceptions\ApiException + * @return PaymentCollection + * @throws ApiException */ public function listForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection { $this->parentId = $customerId; - return parent::fetchCollection($from, $limit, $parameters); + /** @var PaymentCollection */ + return $this->fetchCollection($from, $limit, $parameters); } /** diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php index 1c1a079f8..a9052e8ab 100644 --- a/src/Endpoints/EndpointCollection.php +++ b/src/Endpoints/EndpointCollection.php @@ -31,7 +31,7 @@ protected function fetchCollection(?string $from = null, ?int $limit = null, arr $apiPath ); - return $this->buildResultCollection($result); + return $this->buildResultCollection($result->decode()); } /** diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index 970143c57..4ce260890 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -40,6 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Invo */ public function get(string $invoiceId, array $parameters = []): Invoice { + /** @var Invoice */ return $this->readResource($invoiceId, $parameters); } @@ -55,6 +56,7 @@ public function get(string $invoiceId, array $parameters = []): Invoice */ public function page(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection { + /** @var InvoiceCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/CustomerMandateEndpoint.php b/src/Endpoints/MandateEndpoint.php similarity index 93% rename from src/Endpoints/CustomerMandateEndpoint.php rename to src/Endpoints/MandateEndpoint.php index 963b4805e..f3df75936 100644 --- a/src/Endpoints/CustomerMandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -class CustomerMandateEndpoint extends EndpointCollection +class MandateEndpoint extends EndpointCollection { protected string $resourcePath = "customers_mandates"; @@ -52,7 +52,8 @@ public function createForId(string $customerId, array $options = [], array $filt { $this->parentId = $customerId; - return parent::createResource($options, $filters); + /** @var Mandate */ + return $this->createResource($options, $filters); } /** @@ -80,6 +81,7 @@ public function getForId(string $customerId, $mandateId, array $parameters = []) { $this->parentId = $customerId; + /** @var Mandate */ return $this->readResource($mandateId, $parameters); } @@ -131,7 +133,8 @@ public function listForId(string $customerId, ?string $from = null, ?int $limit { $this->parentId = $customerId; - return parent::fetchCollection($from, $limit, $parameters); + /** @var MandateCollection */ + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -182,6 +185,7 @@ public function revokeForId(string $customerId, string $mandateId, array $data = { $this->parentId = $customerId; - return parent::deleteResource($mandateId, $data); + /** @var null|Mandate */ + return $this->deleteResource($mandateId, $data); } } diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index bb1dfd34b..4ada2e2a9 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -51,7 +51,8 @@ public function all(array $parameters = []): MethodCollection */ public function allActive(array $parameters = []): MethodCollection { - return parent::fetchCollection(null, null, $parameters); + /** @var MethodCollection */ + return $this->fetchCollection(null, null, $parameters); } /** @@ -68,7 +69,8 @@ public function allAvailable(array $parameters = []): MethodCollection $result = $this->client->performHttpCall('GET', $url); - return $this->buildResultCollection($result); + /** @var MethodCollection */ + return $this->buildResultCollection($result->decode()); } /** @@ -83,10 +85,7 @@ public function allAvailable(array $parameters = []): MethodCollection */ public function get(string $methodId, array $parameters = []): Method { - if (empty($methodId)) { - throw new ApiException("Method ID is empty."); - } - - return parent::readResource($methodId, $parameters); + /** @var Method */ + return $this->readResource($methodId, $parameters); } } diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index faff971b4..557225214 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -28,6 +28,7 @@ protected function getResourceObject(): Onboarding */ public function get(): Onboarding { + /** @var Onboarding */ return $this->readResource('', []); } diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 8d0fbad18..8c7a6dac5 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -40,6 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Orde */ public function create(array $data = [], array $filters = []): Order { + /** @var Order */ return $this->createResource($data, $filters); } @@ -51,14 +52,15 @@ public function create(array $data = [], array $filters = []): Order * @param string $orderId * @param array $data * - * @return Order + * @return null|Order * @throws ApiException */ - public function update(string $orderId, array $data = []): Order + public function update(string $orderId, array $data = []): ?Order { $this->guardAgainstInvalidId($orderId); - return parent::updateResource($orderId, $data); + /** @var null|Order */ + return $this->updateResource($orderId, $data); } /** @@ -76,7 +78,8 @@ public function get(string $orderId, array $parameters = []): Order { $this->guardAgainstInvalidId($orderId); - return parent::readResource($orderId, $parameters); + /** @var Order */ + return $this->readResource($orderId, $parameters); } /** @@ -96,6 +99,7 @@ public function get(string $orderId, array $parameters = []): Order */ public function cancel(string $orderId, $parameters = []): ?Order { + /** @var null|Order */ return $this->deleteResource($orderId, $parameters); } @@ -111,6 +115,7 @@ public function cancel(string $orderId, $parameters = []): ?Order */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection { + /** @var OrderCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index a1d69626f..96b454350 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -35,20 +35,21 @@ protected function getResourceCollectionObject(int $count, object $_links): Orde * * Will throw an ApiException if the order line id is invalid or the resource cannot be found. * - * @param string|null $orderId + * @param string $orderId * @param string $orderlineId * @param array $data * - * @return OrderLine + * @return null|OrderLine * @throws \Mollie\Api\Exceptions\ApiException */ - public function update(string $orderId, string $orderlineId, array $data = []): OrderLine + public function update(string $orderId, string $orderlineId, array $data = []): ?OrderLine { $this->parentId = $orderId; $this->guardAgainstInvalidId($orderlineId); - return parent::updateResource($orderlineId, $data); + /** @var null|OrderLine */ + return $this->updateResource($orderlineId, $data); } /** @@ -75,7 +76,8 @@ public function updateMultiple(string $orderId, array $operations, array $parame $this->parseRequestBody($parameters) ); - return ResourceFactory::createFromApiResult($result, new Order($this->client)); + /** @var Order */ + return ResourceFactory::createFromApiResult($result->decode(), new Order($this->client)); } /** @@ -107,7 +109,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (! isset($data['lines']) || ! is_array($data['lines'])) { + if (!isset($data['lines']) || !is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index c0a49870f..ef56872ca 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -55,6 +55,7 @@ public function createForId(string $orderId, array $data, array $filters = []): { $this->parentId = $orderId; + /** @var Payment */ return $this->createResource($data, $filters); } } diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index 1e514680b..f080f2afb 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -50,14 +50,15 @@ public function createFor(Order $order, array $data, array $filters = []): Refun * @param array $data * @param array $filters * - * @return \Mollie\Api\Resources\Refund + * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ public function createForId(string $orderId, array $data, array $filters = []): Refund { $this->parentId = $orderId; - return parent::createResource($data, $filters); + /** @var Refund */ + return $this->createResource($data, $filters); } /** @@ -66,20 +67,21 @@ public function createForId(string $orderId, array $data, array $filters = []): * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId($orderId, array $parameters = []) + public function pageForId($orderId, array $parameters = []): RefundCollection { $this->parentId = $orderId; + /** @var RefundCollection */ return $this->fetchCollection(null, null, $parameters); } /** - * @param \Mollie\Api\Resources\Order $order + * @param Order $order * @param array $parameters - * @return \Mollie\Api\Resources\RefundCollection + * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageFor(Order $order, array $parameters = []) + public function pageFor(Order $order, array $parameters = []): RefundCollection { return $this->pageForId($order->id, $parameters); } diff --git a/src/Endpoints/OrderShipmentEndpoint.php b/src/Endpoints/OrderShipmentEndpoint.php index fb09156bd..36f2ca52f 100644 --- a/src/Endpoints/OrderShipmentEndpoint.php +++ b/src/Endpoints/OrderShipmentEndpoint.php @@ -60,7 +60,8 @@ public function createForId(string $orderId, array $options = [], array $filters { $this->parentId = $orderId; - return parent::createResource($options, $filters); + /** @var Shipment */ + return $this->createResource($options, $filters); } /** @@ -92,7 +93,8 @@ public function getForId(string $orderId, string $shipmentId, array $parameters { $this->parentId = $orderId; - return parent::readResource($shipmentId, $parameters); + /** @var Shipment */ + return $this->readResource($shipmentId, $parameters); } /** @@ -104,16 +106,17 @@ public function getForId(string $orderId, string $shipmentId, array $parameters * @param string $orderId * @param array $data * - * @return Shipment + * @return null|Shipment * @throws ApiException */ - public function update(string $orderId, $shipmentId, array $data = []): Shipment + public function update(string $orderId, $shipmentId, array $data = []): ?Shipment { $this->guardAgainstInvalidId($shipmentId); $this->parentId = $orderId; - return parent::updateResource($shipmentId, $data); + /** @var null|Shipment */ + return $this->updateResource($shipmentId, $data); } /** @@ -143,6 +146,7 @@ public function listForId(string $orderId, array $parameters = []): ShipmentColl { $this->parentId = $orderId; - return parent::fetchCollection(null, null, $parameters); + /** @var ShipmentCollection */ + return $this->fetchCollection(null, null, $parameters); } } diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index 5c5d6c784..4a1a8b75e 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -34,7 +34,8 @@ public function get(string $organizationId, array $parameters = []): Organizatio throw new ApiException("Organization ID is empty."); } - return parent::readResource($organizationId, $parameters); + /** @var Organization */ + return $this->readResource($organizationId, $parameters); } /** @@ -47,6 +48,7 @@ public function get(string $organizationId, array $parameters = []): Organizatio */ public function current(array $parameters = []): Organization { - return parent::readResource('me', $parameters); + /** @var Organization */ + return $this->readResource('me', $parameters); } } diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index 63be47629..cc3f90aa5 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -28,6 +28,7 @@ protected function getResourceObject(): Partner */ public function get(): Partner { + /** @var Partner */ return $this->readResource('', []); } } diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 25aebdd8d..8df4a6b67 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -56,6 +56,7 @@ public function createForId(string $paymentId, array $data = [], array $filters { $this->parentId = $paymentId; + /** @var Capture */ return $this->createResource($data, $filters); } @@ -84,7 +85,8 @@ public function getForId(string $paymentId, string $captureId, array $parameters { $this->parentId = $paymentId; - return parent::readResource($captureId, $parameters); + /** @var Capture */ + return $this->readResource($captureId, $parameters); } /** @@ -131,7 +133,8 @@ public function listForId(string $paymentId, array $parameters = []): CaptureCol { $this->parentId = $paymentId; - return parent::fetchCollection(null, null, $parameters); + /** @var CaptureCollection */ + return $this->fetchCollection(null, null, $parameters); } /** diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index c77a46d9f..f64f0ed56 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -52,18 +52,20 @@ public function getForId(string $paymentId, string $chargebackId, array $paramet { $this->parentId = $paymentId; - return parent::readResource($chargebackId, $parameters); + /** @var Chargeback */ + return $this->readResource($chargebackId, $parameters); } /** * @param Payment $payment * @param array $parameters * - * @return Chargeback + * @return ChargebackCollection * @throws \Mollie\Api\Exceptions\ApiException */ public function listFor(Payment $payment, array $parameters = []): ChargebackCollection { + /** @var ChargebackCollection */ return $this->listForId($payment->id, $parameters); } @@ -92,14 +94,15 @@ public function iteratorFor( * @param string $paymentId * @param array $parameters * - * @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Chargeback + * @return ChargebackCollection * @throws \Mollie\Api\Exceptions\ApiException */ public function listForId(string $paymentId, array $parameters = []): ChargebackCollection { $this->parentId = $paymentId; - return parent::fetchCollection(null, null, $parameters); + /** @var ChargebackCollection */ + return $this->fetchCollection(null, null, $parameters); } /** diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index c5d55e6e0..acd84a13d 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -41,6 +41,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Paym */ public function create(array $data = [], array $filters = []): Payment { + /** @var Payment */ return $this->createResource($data, $filters); } @@ -52,14 +53,15 @@ public function create(array $data = [], array $filters = []): Payment * @param string $paymentId * @param array $data * - * @return Payment + * @return null|Payment * @throws ApiException */ - public function update($paymentId, array $data = []): Payment + public function update($paymentId, array $data = []): ?Payment { $this->guardAgainstInvalidId($paymentId); - return parent::updateResource($paymentId, $data); + /** @var null|Payment */ + return $this->updateResource($paymentId, $data); } /** @@ -77,7 +79,8 @@ public function get($paymentId, array $parameters = []): Payment { $this->guardAgainstInvalidId($paymentId); - return parent::readResource($paymentId, $parameters); + /** @var Payment */ + return $this->readResource($paymentId, $parameters); } /** @@ -106,11 +109,12 @@ public function delete(string $paymentId, array $data = []): ?Payment * @param string $paymentId * @param array $data * - * @return Payment + * @return null|Payment * @throws ApiException */ public function cancel(string $paymentId, array $data = []): ?Payment { + /** @var null|Payment */ return $this->deleteResource($paymentId, $data); } @@ -126,6 +130,7 @@ public function cancel(string $paymentId, array $data = []): ?Payment */ public function page(string $from = null, int $limit = null, array $parameters = []): PaymentCollection { + /** @var PaymentCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index ef695f4d6..9bc8fe0ae 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -40,6 +40,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Paym */ public function create(array $data = [], array $filters = []): PaymentLink { + /** @var PaymentLink */ return $this->createResource($data, $filters); } @@ -57,7 +58,8 @@ public function get(string $paymentLinkId, array $parameters = []): PaymentLink { $this->guardAgainstInvalidId($paymentLinkId); - return parent::readResource($paymentLinkId, $parameters); + /** @var PaymentLink */ + return $this->readResource($paymentLinkId, $parameters); } /** @@ -72,6 +74,7 @@ public function get(string $paymentLinkId, array $parameters = []): PaymentLink */ public function page(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection { + /** @var PaymentLinkCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 1289c5d30..969c84b8c 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -45,14 +45,15 @@ public function getFor(Payment $payment, $refundId, array $parameters = []): Ref * @param string $refundId * @param array $parameters * - * @return \Mollie\Api\Resources\Refund + * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ public function getForId(string $paymentId, $refundId, array $parameters = []): Refund { $this->parentId = $paymentId; - return parent::readResource($refundId, $parameters); + /** @var Refund */ + return $this->readResource($refundId, $parameters); } /** @@ -64,6 +65,7 @@ public function getForId(string $paymentId, $refundId, array $parameters = []): */ public function listFor(Payment $payment, array $parameters = []): RefundCollection { + /** @var RefundCollection */ return $this->listForId($payment->id, $parameters); } @@ -99,7 +101,8 @@ public function listForId(string $paymentId, array $parameters = []): RefundColl { $this->parentId = $paymentId; - return parent::fetchCollection(null, null, $parameters); + /** @var RefundCollection */ + return $this->fetchCollection(null, null, $parameters); } /** @@ -148,13 +151,14 @@ public function createFor(Payment $payment, array $data, array $filters = []): R * @param array $data * @param array $filters * - * @return \Mollie\Api\Resources\Refund + * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ public function createForId(string $paymentId, array $data, array $filters = []): Refund { $this->parentId = $paymentId; - return parent::createResource($data, $filters); + /** @var Refund */ + return $this->createResource($data, $filters); } } diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index 6fa64703d..ed4078881 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -37,14 +37,15 @@ public function updateReleaseDateFor(Payment $payment, $routeId, $releaseDate): * @param string $releaseDate - UTC datetime in ISO-8601 format when the funds for the following payment will become available on * the balance of the connected account * - * @return \Mollie\Api\Resources\Route + * @return Route * @throws \Mollie\Api\Exceptions\ApiException */ - public function updateReleaseDateForPaymentId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): Route + public function updateReleaseDateForPaymentId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): ?Route { $this->parentId = $paymentId; - return parent::updateResource($routeId, [ + /** @var Route */ + return $this->updateResource($routeId, [ 'releaseDate' => $releaseDate, 'testmode' => $testmode, ]); diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index e0de8aa59..f7af61305 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -38,6 +38,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Perm */ public function get(string $permissionId, array $parameters = []): Permission { + /** @var Permission */ return $this->readResource($permissionId, $parameters); } @@ -51,6 +52,7 @@ public function get(string $permissionId, array $parameters = []): Permission */ public function all(array $parameters = []): PermissionCollection { - return parent::fetchCollection(null, null, $parameters); + /** @var PermissionCollection */ + return $this->fetchCollection(null, null, $parameters); } } diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index 5e3198ec6..ff7887cb9 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -43,6 +43,7 @@ protected function getResourceCollectionObject(int $count, object $_links): Prof */ public function create(array $data = [], array $filters = []): Profile { + /** @var Profile */ return $this->createResource($data, $filters); } @@ -63,6 +64,7 @@ public function get($profileId, array $parameters = []): Profile return $this->getCurrent($parameters); } + /** @var Profile */ return $this->readResource($profileId, $parameters); } @@ -73,14 +75,15 @@ public function get($profileId, array $parameters = []): Profile * * @param string $profileId * @param array $data - * @return Profile + * @return null|Profile * @throws ApiException */ - public function update(string $profileId, array $data = []): Profile + public function update(string $profileId, array $data = []): ?Profile { $this->guardAgainstInvalidId($profileId); - return parent::updateResource($profileId, $data); + /** @var null|Profile */ + return $this->updateResource($profileId, $data); } /** @@ -95,6 +98,7 @@ public function getCurrent(array $parameters = []): CurrentProfile { $this->resourceClass = CurrentProfile::class; + /** @var CurrentProfile */ return $this->readResource('me', $parameters); } @@ -107,11 +111,12 @@ public function getCurrent(array $parameters = []): CurrentProfile * @param string $profileId * * @param array $data - * @return Profile + * @return null|Profile * @throws ApiException */ public function delete($profileId, array $data = []): ?Profile { + /** @var null|Profile */ return $this->deleteResource($profileId, $data); } @@ -127,6 +132,7 @@ public function delete($profileId, array $data = []): ?Profile */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection { + /** @var ProfileCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 0af5c6f59..dd3ed3c2c 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -47,7 +47,8 @@ public function createForId(string $profileId, string $methodId, array $data = [ $this->parseRequestBody($data) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + /** @var Method */ + return ResourceFactory::createFromApiResult($result->decode(), $this->getResourceObject()); } /** @@ -93,6 +94,7 @@ public function deleteForId($profileId, $methodId, array $data = []): ?Method { $this->parentId = $profileId; + /** @var null|Method */ return $this->deleteResource($methodId, $data); } diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 3ff2c39de..45a1dc74a 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -30,15 +30,16 @@ protected function getResourceCollectionObject(int $count, object $_links): Refu /** * Retrieves a collection of Refunds from Mollie. * - * @param string $from The first refund ID you want to include in your list. - * @param int $limit + * @param null|string $from The first refund ID you want to include in your list. + * @param null|int $limit * @param array $parameters * * @return RefundCollection * @throws ApiException */ - public function page(?string $from = null, ?string $limit = null, array $parameters = []): RefundCollection + public function page(?string $from = null, ?int $limit = null, array $parameters = []): RefundCollection { + /** @var RefundCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index 873b483a2..b860ae024 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -32,7 +32,7 @@ protected function createResource(array $body, array $filters): BaseResource $this->parseRequestBody($body) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + return ResourceFactory::createFromApiResult($result->decode(), $this->getResourceObject()); } /** @@ -51,13 +51,17 @@ protected function updateResource(string $id, array $body = []): ?BaseResource } $id = urlencode($id); - $result = $this->client->performHttpCall( + $response = $this->client->performHttpCall( self::REST_UPDATE, $this->getPathToSingleResource($id), $this->parseRequestBody($body) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + if ($response->isEmpty()) { + return null; + } + + return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); } /** @@ -75,12 +79,12 @@ protected function readResource(string $id, array $filters): BaseResource } $id = urlencode($id); - $result = $this->client->performHttpCall( + $response = $this->client->performHttpCall( self::REST_READ, $this->getPathToSingleResource($id) . $this->buildQueryString($filters) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); } /** @@ -99,13 +103,17 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource } $id = urlencode($id); - $result = $this->client->performHttpCall( + $response = $this->client->performHttpCall( self::REST_DELETE, $this->getPathToSingleResource($id), $this->parseRequestBody($body) ); - return ResourceFactory::createFromApiResult($result, $this->getResourceObject()); + if ($response->isEmpty()) { + return null; + } + + return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); } protected function guardAgainstInvalidId(string $id): void @@ -125,7 +133,7 @@ public function getResourceType(): string { $resourceClass = $this->getResourceObject()::class; $classBasename = basename(str_replace("\\", "/", $resourceClass)); -\ + return strtolower($classBasename); } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 4d9b39870..15a3b04dd 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -43,6 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; + /** @var CaptureCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 7b1adb37b..860aae3de 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -43,6 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; + /** @var ChargebackCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index e1a3f9ef6..f9eeeae77 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -41,6 +41,7 @@ public function pageForId($settlementId, ?string $from = null, ?int $limit = nul { $this->parentId = $settlementId; + /** @var PaymentCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 409f99686..53f683231 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -43,6 +43,7 @@ public function pageForId(string $settlementId, ?string $from = null, ?int $limi { $this->parentId = $settlementId; + /** @var RefundCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 31a5c9a93..e7a08bc59 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -40,7 +40,8 @@ protected function getResourceCollectionObject(int $count, object $_links): Sett */ public function get(string $settlementId, array $parameters = []): Settlement { - return parent::readResource($settlementId, $parameters); + /** @var Settlement */ + return $this->readResource($settlementId, $parameters); } /** @@ -51,7 +52,8 @@ public function get(string $settlementId, array $parameters = []): Settlement */ public function next(): Settlement { - return parent::readResource("next", []); + /** @var Settlement */ + return $this->readResource("next", []); } /** @@ -62,7 +64,8 @@ public function next(): Settlement */ public function open(): Settlement { - return parent::readResource("open", []); + /** @var Settlement */ + return $this->readResource("open", []); } /** @@ -77,6 +80,7 @@ public function open(): Settlement */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection { + /** @var SettlementCollection */ return $this->fetchCollection($from, $limit, $parameters); } diff --git a/src/Endpoints/CustomerSubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php similarity index 90% rename from src/Endpoints/CustomerSubscriptionEndpoint.php rename to src/Endpoints/SubscriptionEndpoint.php index 0071f2250..31a822b2a 100644 --- a/src/Endpoints/CustomerSubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -class CustomerSubscriptionEndpoint extends EndpointCollection +class SubscriptionEndpoint extends EndpointCollection { protected string $resourcePath = "customers_subscriptions"; @@ -59,7 +59,8 @@ public function createForId(string $customerId, array $options = [], array $filt { $this->parentId = $customerId; - return parent::createResource($options, $filters); + /** @var Subscription */ + return $this->createResource($options, $filters); } /** @@ -72,16 +73,17 @@ public function createForId(string $customerId, array $options = [], array $filt * * @param array $data * - * @return Subscription + * @return null|Subscription * @throws ApiException */ - public function update(string $customerId, string $subscriptionId, array $data = []): Subscription + public function update(string $customerId, string $subscriptionId, array $data = []): ?Subscription { $this->guardAgainstInvalidId($subscriptionId); $this->parentId = $customerId; - return parent::updateResource($subscriptionId, $data); + /** @var null|Subscription */ + return $this->updateResource($subscriptionId, $data); } /** @@ -109,7 +111,8 @@ public function getForId(string $customerId, string $subscriptionId, array $para { $this->parentId = $customerId; - return parent::readResource($subscriptionId, $parameters); + /** @var Subscription */ + return $this->readResource($subscriptionId, $parameters); } /** @@ -160,7 +163,8 @@ public function listForId($customerId, ?string $from = null, ?int $limit = null, { $this->parentId = $customerId; - return parent::fetchCollection($from, $limit, $parameters); + /** @var SubscriptionCollection */ + return $this->fetchCollection($from, $limit, $parameters); } /** @@ -211,7 +215,8 @@ public function cancelForId(string $customerId, string $subscriptionId, array $d { $this->parentId = $customerId; - return parent::deleteResource($subscriptionId, $data); + /** @var null|Subscription */ + return $this->deleteResource($subscriptionId, $data); } /** @@ -235,7 +240,8 @@ public function page(?string $from = null, ?int $limit = null, array $parameters $apiPath ); - return $this->buildResultCollection($result); + /** @var SubscriptionCollection */ + return $this->buildResultCollection($result->decode()); } /** diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index bc7a562ca..5f1aa0e54 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -11,6 +11,8 @@ class TerminalEndpoint extends EndpointCollection { protected string $resourcePath = "terminals"; + protected static string $resourceIdPrefix = 'term_'; + /** * @inheritDoc */ @@ -40,11 +42,10 @@ protected function getResourceCollectionObject(int $count, object $_links): Term */ public function get(string $terminalId, array $parameters = []): Terminal { - if (empty($terminalId) || strpos($terminalId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid terminal ID: '{$terminalId}'. A terminal ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); - } + $this->guardAgainstInvalidId($terminalId); - return parent::readResource($terminalId, $parameters); + /** @var Terminal */ + return $this->readResource($terminalId, $parameters); } /** @@ -59,7 +60,8 @@ public function get(string $terminalId, array $parameters = []): Terminal */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection { - return parent::fetchCollection($from, $limit, $parameters); + /** @var TerminalCollection */ + return $this->fetchCollection($from, $limit, $parameters); } /** diff --git a/src/Endpoints/WalletEndpoint.php b/src/Endpoints/WalletEndpoint.php index 62b55d42f..5db82e297 100644 --- a/src/Endpoints/WalletEndpoint.php +++ b/src/Endpoints/WalletEndpoint.php @@ -27,6 +27,6 @@ public function requestApplePayPaymentSession($domain, $validationUrl, $paramete $body ); - return json_encode($response); + return $response->body(); } } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 017274235..02936b93d 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -175,7 +175,7 @@ public function hasLink($key): bool /** * @param string $key - * @return mixed|null + * @return \stdClass|null */ public function getLink($key): ?\stdClass { diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index 46d52700e..6683d8ed5 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -42,7 +42,7 @@ final class CurlMollieHttpAdapter implements MollieHttpAdapterContract * @throws \Mollie\Api\Exceptions\ApiException * @throws \Mollie\Api\Exceptions\CurlConnectTimeoutException */ - public function send(string $method, string $url, $headers, ?string $body): ResponseContract + public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract { for ($i = 0; $i <= self::MAX_RETRIES; $i++) { usleep($i * self::DELAY_INCREASE_MS); @@ -71,7 +71,7 @@ public function send(string $method, string $url, $headers, ?string $body): Resp * @return Response * @throws \Mollie\Api\Exceptions\ApiException */ - protected function attemptRequest(string $method, string $url, array $headers = [], ?string $body): Response + protected function attemptRequest(string $method, string $url, array $headers = [], ?string $body = null): Response { $curl = $this->initializeCurl($url); $this->setCurlHeaders($curl, $headers); @@ -219,7 +219,7 @@ private function parseHeaders(array $headers): array * The version number for the underlying http client, if available. * @example Guzzle/6.3 * - * @return string|null + * @return string */ public function version(): string { diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 7be5e581e..4a8d578dd 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -77,7 +77,7 @@ public static function createDefault(): self * @return ResponseContract * @throws \Mollie\Api\Exceptions\ApiException */ - public function send(string $method, string $url, $headers, ?string $body): ResponseContract + public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract { $request = new Request($method, $url, $headers, $body); @@ -85,7 +85,7 @@ public function send(string $method, string $url, $headers, ?string $body): Resp $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (! $this->debug) { + if (!$this->debug) { $request = null; } @@ -100,38 +100,7 @@ public function send(string $method, string $url, $headers, ?string $body): Resp } return PsrResponseHandler::create() - ->handle($response, $response->getStatusCode(), $body); - } - - /** - * Parse the PSR-7 Response body - * - * @param ResponseInterface $response - * @return \stdClass|null - * @throws ApiException - */ - private function parseResponseBody(ResponseInterface $response): ?\stdClass - { - $body = (string) $response->getBody(); - if (empty($body)) { - if ($response->getStatusCode() === self::HTTP_NO_CONTENT) { - return null; - } - - throw new ApiException("No response body found."); - } - - $object = @json_decode($body); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$body}'."); - } - - if ($response->getStatusCode() >= 400) { - throw ApiException::createFromResponse($response, null); - } - - return $object; + ->handle($request, $response, $response->getStatusCode(), $body); } /** @@ -140,7 +109,7 @@ private function parseResponseBody(ResponseInterface $response): ?\stdClass * * @example Guzzle/7.0 * - * @return string|null + * @return string */ public function version(): string { diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index c8e4ef227..7afda88d5 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -52,14 +52,14 @@ public function __construct( /** * {@inheritdoc} */ - public function send(string $method, string $url, $headers, ?string $body): ResponseContract + public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract { try { $request = $this->createRequest($method, $url, $headers, $body ?? ''); $response = $this->httpClient->sendRequest($request); return PsrResponseHandler::create() - ->handle($response, $response->getStatusCode(), $body); + ->handle($request, $response, $response->getStatusCode(), $body); } catch (\Exception $e) { if (! $this->debug) { $request = null; diff --git a/src/Http/NoResponse.php b/src/Http/EmptyResponse.php similarity index 66% rename from src/Http/NoResponse.php rename to src/Http/EmptyResponse.php index d3538618d..ef40374e3 100644 --- a/src/Http/NoResponse.php +++ b/src/Http/EmptyResponse.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\ResponseContract; -class NoResponse implements ResponseContract +class EmptyResponse implements ResponseContract { public function status(): int { @@ -16,8 +16,13 @@ public function body(): string return ''; } - public function json(): \stdClass + public function decode(): \stdClass { return (object)[]; } + + public function isEmpty(): bool + { + return true; + } } diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php index 4e2e89b56..751c8160d 100644 --- a/src/Http/PsrResponseHandler.php +++ b/src/Http/PsrResponseHandler.php @@ -3,6 +3,8 @@ namespace Mollie\Api\Http; use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Exceptions\ApiException; +use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use RuntimeException; @@ -23,30 +25,49 @@ public static function create(): self /** * Undocumented function * - * @param mixed|callable|ResponseContract|null $response + * @param RequestInterface|null $psrResponse + * @param ResponseInterface|null $psrResponse * @param int $code * @param string|null $requestBody * @return ResponseContract */ - public function handle(?ResponseInterface $response = null, int $code, ?string $requestBody = null): ResponseContract - { - if ($response === null) { + public function handle( + ?RequestInterface $prsRequest = null, + ?ResponseInterface $psrResponse = null, + int $code = 200, + ?string $requestBody = null + ): ResponseContract { + if ($psrResponse === null) { return ResponseHandler::noResponse(); } - if (! $response instanceof ResponseInterface) { + if (!$psrResponse instanceof ResponseInterface) { throw new RuntimeException("Response must be an instance of ResponseInterface."); } - $body = (string) $response->getBody(); + $body = (string) $psrResponse->getBody(); - return $this->responseHandler->handle( - new Response( - $code, - $response->getHeaders(), - $body - ), - $requestBody + $response = new Response( + $code, + $psrResponse->getHeaders(), + $body ); + + $this->responseHandler->guard($response); + + try { + $this->responseHandler->throwExceptionIfRequestFailed($response, $requestBody); + } catch (ApiException $e) { + throw new ApiException( + $e->getMessage(), + $e->getCode(), + $e->getField(), + $prsRequest, + $psrResponse, + $e->getPrevious() + ); + } + + return $response; } } diff --git a/src/Http/Response.php b/src/Http/Response.php index bda56fea9..a3916cb72 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -56,13 +56,17 @@ public function body(): string * * @return \stdClass */ - public function json(): \stdClass + public function decode(): \stdClass { - if (! $this->decoded) { - $this->decoded = @json_decode($this->body()); + if (empty($body = $this->body())) { + return (object)[]; + } + + if (!$this->decoded) { + $this->decoded = @json_decode($body); if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$this->body()}'."); + throw new ApiException("Unable to decode Mollie response: '{$body}'."); } } @@ -74,6 +78,11 @@ public function status(): int return $this->statusCode; } + public function isEmpty(): bool + { + return empty($this->body()); + } + public function getReasonPhrase(): string { if (empty($this->reasonPhrase) && isset(static::$phrases[$this->statusCode])) { diff --git a/src/Http/ResponseHandler.php b/src/Http/ResponseHandler.php index 7d5269abe..757a39456 100644 --- a/src/Http/ResponseHandler.php +++ b/src/Http/ResponseHandler.php @@ -15,7 +15,7 @@ class ResponseHandler public function handle(?ResponseContract $response = null, ?string $requestBody = null): ResponseContract { if ($response === null) { - return new NoResponse(); + return new EmptyResponse(); } $this->guard($response); @@ -27,54 +27,59 @@ public function handle(?ResponseContract $response = null, ?string $requestBody public static function create(): self { - return new static(); + return new self(); } public static function noResponse(): ResponseContract { - return (new static())->handle(null); + return (new self())->handle(null); } - protected function guard(ResponseContract $response): void + public function guard(ResponseContract $response): void { $this->guardNoContentWithBody($response); + + if (empty($response->body())) { + return; + } + $this->guardJsonNotDecodable($response); // @todo check if this is still necessary as it seems to be from api v1 - if (isset($response->json()->error)) { - throw new ApiException($response->json()->error->message); + if (isset($response->decode()->error)) { + throw new ApiException($response->decode()->error->message); } } protected function guardNoContentWithBody(ResponseContract $response): void { - if ($response->status() === ResponseStatusCode::HTTP_NO_CONTENT && ! empty($response->body())) { + if (empty($response->body()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { throw new ApiException("No response body found."); } } protected function guardJsonNotDecodable(ResponseContract $response): void { - $response->json(); + $response->decode(); if (json_last_error() !== JSON_ERROR_NONE) { throw new ApiException("Unable to decode Mollie response: '{$response->body()}'."); } } - protected function throwExceptionIfRequestFailed(ResponseContract $response, ?string $requestBody): void + public function throwExceptionIfRequestFailed(ResponseContract $response, ?string $requestBody): void { if ($this->requestSucceeded($response->status())) { return; } - $body = $response->json(); + $body = $response->decode(); $message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}"; $field = null; - if (! empty($body->field)) { + if (!empty($body->field)) { $field = $body->field; } @@ -83,10 +88,14 @@ protected function throwExceptionIfRequestFailed(ResponseContract $response, ?st } if ($requestBody) { - $message .= ". Request body: {$body}"; + $message .= ". Request body: {$requestBody}"; } - throw new ApiException($message, $response->status(), $field); + throw new ApiException( + $message, + $response->status(), + $field, + ); } /** diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 97aacda90..3536b7e99 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,7 +2,6 @@ namespace Mollie\Api; -use Mollie\Api\Contracts\MollieHttpAdapterContract; use Mollie\Api\Contracts\ResponseContract as Response; use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; @@ -11,17 +10,15 @@ use Mollie\Api\Endpoints\ClientEndpoint; use Mollie\Api\Endpoints\ClientLinkEndpoint; use Mollie\Api\Endpoints\CustomerEndpoint; -use Mollie\Api\Endpoints\CustomerMandateEndpoint; use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; -use Mollie\Api\Endpoints\CustomerSubscriptionEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; +use Mollie\Api\Endpoints\MandateEndpoint; use Mollie\Api\Endpoints\MethodEndpoint; use Mollie\Api\Endpoints\OnboardingEndpoint; use Mollie\Api\Endpoints\OrderEndpoint; use Mollie\Api\Endpoints\OrderLineEndpoint; use Mollie\Api\Endpoints\OrderPaymentEndpoint; use Mollie\Api\Endpoints\OrderRefundEndpoint; -use Mollie\Api\Endpoints\OrderShipmentEndpoint; use Mollie\Api\Endpoints\OrganizationEndpoint; use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; use Mollie\Api\Endpoints\PaymentCaptureEndpoint; @@ -39,10 +36,16 @@ use Mollie\Api\Endpoints\SettlementPaymentEndpoint; use Mollie\Api\Endpoints\SettlementRefundEndpoint; use Mollie\Api\Endpoints\SettlementsEndpoint; +use Mollie\Api\Endpoints\OrderShipmentEndpoint; +use Mollie\Api\Endpoints\SubscriptionEndpoint; use Mollie\Api\Endpoints\TerminalEndpoint; use Mollie\Api\Endpoints\WalletEndpoint; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; +use Mollie\Api\Exceptions\IncompatiblePlatform; +use Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract; /** * @property BalanceEndpoint $balances @@ -54,7 +57,7 @@ * @property CustomerPaymentsEndpoint $customerPayments * @property CustomerEndpoint $customers * @property InvoiceEndpoint $invoices - * @property CustomerMandateEndpoint $mandates + * @property MandateEndpoint $mandates * @property MethodEndpoint $methods * @property OnboardingEndpoint $onboarding * @property OrderEndpoint $orders @@ -79,7 +82,7 @@ * @property SettlementPaymentEndpoint $settlementPayments * @property SettlementRefundEndpoint $settlementRefunds * @property OrderShipmentEndpoint $shipments - * @property CustomerSubscriptionEndpoint $subscriptions + * @property SubscriptionEndpoint $subscriptions * @property TerminalEndpoint $terminals * @property WalletEndpoint $wallets */ @@ -124,19 +127,19 @@ class MollieApiClient /** * @var string */ - protected $apiKey; + protected string $apiKey; /** * True if an OAuth access token is set as API key. * * @var bool */ - protected $oauthAccess; + protected bool $oauthAccess; /** * @var array */ - protected $versionStrings = []; + protected array $versionStrings = []; /** * @var array @@ -144,18 +147,18 @@ class MollieApiClient protected array $endpoints = []; /** - * @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterContract|null $client - * @param \Mollie\Api\HttpAdapter\MollieHttpAdapterPickerContract|null $httpAdapterPicker, - * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $idempotencyKeyGenerator, + * @param \GuzzleHttp\ClientInterface|\Mollie\Api\Contracts\MollieHttpAdapterContract|null $client + * @param MollieHttpAdapterPickerContract|null $adapterPicker, + * @param IdempotencyKeyGeneratorContract|null $idempotencyKeyGenerator, * @throws \Mollie\Api\Exceptions\IncompatiblePlatform|\Mollie\Api\Exceptions\UnrecognizedClientException */ public function __construct( $client = null, - $adapter = null, - $idempotencyKeyGenerator = null + ?MollieHttpAdapterPickerContract $adapterPicker = null, + ?IdempotencyKeyGeneratorContract $idempotencyKeyGenerator = null ) { - $adapter = $adapter ?: new MollieHttpAdapterPicker; - $this->httpClient = $adapter->pickHttpAdapter($client); + $adapterPicker = $adapterPicker ?: new MollieHttpAdapterPicker; + $this->httpClient = $adapterPicker->pickHttpAdapter($client); $compatibilityChecker = new CompatibilityChecker; $compatibilityChecker->checkCompatibility(); @@ -177,7 +180,7 @@ private function initializeEndpoints(): void 'customerPayments' => CustomerPaymentsEndpoint::class, 'customers' => CustomerEndpoint::class, 'invoices' => InvoiceEndpoint::class, - 'mandates' => CustomerMandateEndpoint::class, + 'mandates' => MandateEndpoint::class, 'methods' => MethodEndpoint::class, 'onboarding' => OnboardingEndpoint::class, 'orderLines' => OrderLineEndpoint::class, @@ -202,7 +205,7 @@ private function initializeEndpoints(): void 'settlementRefunds' => SettlementRefundEndpoint::class, 'settlements' => SettlementsEndpoint::class, 'shipments' => OrderShipmentEndpoint::class, - 'subscriptions' => CustomerSubscriptionEndpoint::class, + 'subscriptions' => SubscriptionEndpoint::class, 'terminals' => TerminalEndpoint::class, 'wallets' => WalletEndpoint::class, ]; @@ -260,7 +263,7 @@ public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -280,7 +283,7 @@ public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (! preg_match('/^access_\w+$/', $accessToken)) { + if (!preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 2577e6216..83271a26c 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -3,6 +3,8 @@ namespace Mollie\Api\Resources; use Generator; +use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\ResponseStatusCode; use Mollie\Api\MollieApiClient; abstract class CursorCollection extends BaseCollection @@ -34,7 +36,7 @@ abstract protected function createResourceObject(); */ final public function next(): ?CursorCollection { - if (! $this->hasNext()) { + if (!$this->hasNext()) { return null; } @@ -49,7 +51,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (! $this->hasPrevious()) { + if (!$this->hasPrevious()) { return null; } @@ -58,11 +60,19 @@ final public function previous(): ?CursorCollection private function fetchCollection(string $url): CursorCollection { - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $url); + $response = $this + ->client + ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $url); - $collection = new static($this->client, $result->count, $result->_links); + if ($response->status() !== ResponseStatusCode::HTTP_OK) { + throw new ApiException($response->body(), $response->status()); + } + + $data = $response->decode(); + + $collection = new static($this->client, $data->count, $data->_links); - foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { + foreach ($data->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject()); } @@ -106,7 +116,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { break; } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index c30d2ae7a..2ad564871 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -56,10 +56,10 @@ class Customer extends BaseResource public $_links; /** - * @return \Mollie\Api\Resources\Customer - * @throws \Mollie\Api\Exceptions\ApiException + * @return null|Customer + * @throws ApiException */ - public function update() + public function update(): ?Customer { $body = [ "name" => $this->name, @@ -68,9 +68,8 @@ public function update() "metadata" => $this->metadata, ]; - $result = $this->client->customers->update($this->id, $body); - - return ResourceFactory::createFromApiResult($result, new Customer($this->client)); + /** @var null|Customer */ + return $this->client->customers->update($this->id, $body); } /** diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index a2ce98c7c..c0ecd8bfd 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -86,11 +86,11 @@ public function isInvalid() /** * Revoke the mandate * - * @return null|\stdClass|\Mollie\Api\Resources\Mandate + * @return null|\Mollie\Api\Resources\Mandate */ - public function revoke() + public function revoke(): ?Mandate { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } @@ -107,6 +107,9 @@ public function revoke() $body ); - return $result; + /** @var null|Mandate */ + return $result->isEmpty() + ? null + : ResourceFactory::createFromApiResult($result->decode(), new self($this->client)); } } diff --git a/src/Resources/Method.php b/src/Resources/Method.php index fac587437..a0d21ff77 100644 --- a/src/Resources/Method.php +++ b/src/Resources/Method.php @@ -75,8 +75,9 @@ class Method extends BaseResource * * @return IssuerCollection */ - public function issuers() + public function issuers(): IssuerCollection { + /** @var IssuerCollection */ return ResourceFactory::createBaseResourceCollection( $this->client, Issuer::class, @@ -89,8 +90,9 @@ public function issuers() * * @return MethodPriceCollection */ - public function pricing() + public function pricing(): MethodPriceCollection { + /** @var MethodPriceCollection */ return ResourceFactory::createBaseResourceCollection( $this->client, MethodPrice::class, diff --git a/src/Resources/Order.php b/src/Resources/Order.php index addeb9442..f4465b8a4 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -334,27 +334,27 @@ public function cancel() * Returns null if successful. * * @param array $data - * @return null + * @return void * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancelLines(array $data) + public function cancelLines(array $data): void { - return $this->client->orderLines->cancelFor($this, $data); + $this->client->orderLines->cancelFor($this, $data); } /** * Cancels all eligible lines for this order. * Returns null if successful. * - * @param array|null $data - * @return null + * @param array $data + * @return void * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancelAllLines($data = []) + public function cancelAllLines($data = []): void { $data['lines'] = []; - return $this->client->orderLines->cancelFor($this, $data); + $this->client->orderLines->cancelFor($this, $data); } /** @@ -362,8 +362,9 @@ public function cancelAllLines($data = []) * * @return OrderLineCollection */ - public function lines() + public function lines(): OrderLineCollection { + /** @var OrderLineCollection */ return ResourceFactory::createBaseResourceCollection( $this->client, OrderLine::class, @@ -471,7 +472,7 @@ public function refundAll(array $data = []) * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function refunds() + public function refunds(): RefundCollection { return $this->client->orderRefunds->pageFor($this); } @@ -479,10 +480,10 @@ public function refunds() /** * Saves the order's updated billingAddress and/or shippingAddress. * - * @return \Mollie\Api\Resources\Order + * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function update() + public function update(): ?Order { $body = [ "billingAddress" => $this->billingAddress, @@ -493,9 +494,8 @@ public function update() "webhookUrl" => $this->webhookUrl, ]; - $result = $this->client->orders->update($this->id, $body); - - return ResourceFactory::createFromApiResult($result, new Order($this->client)); + /** @var null|Order */ + return $this->client->orders->update($this->id, $body); } /** @@ -503,7 +503,7 @@ public function update() * * @param array $data * @param array $filters - * @return \Mollie\Api\Resources\Payment + * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ public function createPayment($data, $filters = []) @@ -515,14 +515,15 @@ public function createPayment($data, $filters = []) * Retrieve the payments for this order. * Requires the order to be retrieved using the embed payments parameter. * - * @return null|\Mollie\Api\Resources\PaymentCollection + * @return null|PaymentCollection */ - public function payments() + public function payments(): ?PaymentCollection { - if (! isset($this->_embedded, $this->_embedded->payments)) { + if (!isset($this->_embedded, $this->_embedded->payments)) { return null; } + /** @var PaymentCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $this->_embedded->payments, diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 9509f2cfb..e035dd9c1 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -433,7 +433,7 @@ public function isAuthorized() */ public function isPaid() { - return ! empty($this->paidAt); + return !empty($this->paidAt); } /** @@ -443,7 +443,7 @@ public function isPaid() */ public function hasRefunds() { - return ! empty($this->_links->refunds); + return !empty($this->_links->refunds); } /** @@ -453,7 +453,7 @@ public function hasRefunds() */ public function hasChargebacks() { - return ! empty($this->_links->chargebacks); + return !empty($this->_links->chargebacks); } /** @@ -586,7 +586,7 @@ public function getAmountChargedBack() */ public function hasSplitPayments() { - return ! empty($this->routing); + return !empty($this->routing); } /** @@ -595,17 +595,18 @@ public function hasSplitPayments() * @return RefundCollection * @throws ApiException */ - public function refunds() + public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } $result = $this->client->performHttpCallToFullUrl( MollieApiClient::HTTP_GET, $this->_links->refunds->href - ); + )->decode(); + /** @var RefundCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->refunds, @@ -629,12 +630,18 @@ public function getRefund($refundId, array $parameters = []) /** * @param array $parameters * - * @return Refund + * @return RefundCollection * @throws ApiException */ - public function listRefunds(array $parameters = []) + public function listRefunds(array $parameters = []): RefundCollection { - return $this->client->paymentRefunds->listFor($this, $this->withPresetOptions($parameters)); + return $this + ->client + ->paymentRefunds + ->listFor( + $this, + $this->withPresetOptions($parameters) + ); } /** @@ -643,17 +650,18 @@ public function listRefunds(array $parameters = []) * @return CaptureCollection * @throws ApiException */ - public function captures() + public function captures(): CaptureCollection { - if (! isset($this->_links->captures->href)) { + if (!isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } $result = $this->client->performHttpCallToFullUrl( MollieApiClient::HTTP_GET, $this->_links->captures->href - ); + )->decode(); + /** @var CaptureCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->captures, @@ -684,17 +692,18 @@ public function getCapture($captureId, array $parameters = []) * @return ChargebackCollection * @throws ApiException */ - public function chargebacks() + public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } $result = $this->client->performHttpCallToFullUrl( MollieApiClient::HTTP_GET, $this->_links->chargebacks->href - ); + )->decode(); + /** @var ChargebackCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->chargebacks, @@ -735,10 +744,10 @@ public function refund($data) } /** - * @return \Mollie\Api\Resources\Payment + * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ - public function update() + public function update(): ?Payment { $body = [ "description" => $this->description, @@ -751,12 +760,11 @@ public function update() "dueDate" => $this->dueDate, ]; - $result = $this->client->payments->update( + /** @var null|Payment */ + return $this->client->payments->update( $this->id, $this->withPresetOptions($body) ); - - return ResourceFactory::createFromApiResult($result, new Payment($this->client)); } /** diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 62238d65b..6b06f6f32 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -104,10 +104,10 @@ public function isBlocked() } /** - * @return \Mollie\Api\Resources\Profile + * @return null|Profile * @throws ApiException */ - public function update() + public function update(): ?Profile { $body = [ "name" => $this->name, @@ -120,6 +120,11 @@ public function update() $result = $this->client->profiles->update($this->id, $body); + if (!$result) { + return null; + } + + /** @var Profile */ return ResourceFactory::createFromApiResult($result, new Profile($this->client)); } @@ -129,14 +134,18 @@ public function update() * @return ChargebackCollection * @throws ApiException */ - public function chargebacks() + public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href); + $result = $this + ->client + ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href) + ->decode(); + /** @var ChargebackCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->chargebacks, @@ -151,14 +160,18 @@ public function chargebacks() * @return MethodCollection * @throws ApiException */ - public function methods() + public function methods(): MethodCollection { - if (! isset($this->_links->methods->href)) { + if (!isset($this->_links->methods->href)) { return new MethodCollection(0, null); } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->methods->href); + $result = $this + ->client + ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->methods->href) + ->decode(); + /** @var MethodCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->methods, @@ -199,14 +212,18 @@ public function disableMethod($methodId, array $data = []) * @return PaymentCollection * @throws ApiException */ - public function payments() + public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->payments->href); + $result = $this + ->client + ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->payments->href) + ->decode(); + /** @var PaymentCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->methods, @@ -221,14 +238,18 @@ public function payments() * @return RefundCollection * @throws ApiException */ - public function refunds() + public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } - $result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href); + $result = $this + ->client + ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href) + ->decode(); + /** @var RefundCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->refunds, diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 81e81b9e1..f997bffce 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Contracts\ResponseContract; use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] @@ -11,13 +10,13 @@ class ResourceFactory /** * Create resource object from Api result * - * @param ResponseContract $response + * @param object $response * @param BaseResource $resource * @return BaseResource */ - public static function createFromApiResult(ResponseContract $response, BaseResource $resource): BaseResource + public static function createFromApiResult(object $response, BaseResource $resource): BaseResource { - foreach ($response->json() as $property => $value) { + foreach ($response as $property => $value) { $resource->{$property} = $value; } diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index 01c1e9ae4..2ef5a8448 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -63,7 +63,7 @@ public function hasTracking() */ public function hasTrackingUrl() { - return $this->hasTracking() && ! empty($this->tracking->url); + return $this->hasTracking() && !empty($this->tracking->url); } /** @@ -73,7 +73,7 @@ public function hasTrackingUrl() */ public function getTrackingUrl() { - if (! $this->hasTrackingUrl()) { + if (!$this->hasTrackingUrl()) { return null; } @@ -85,8 +85,9 @@ public function getTrackingUrl() * * @return OrderLineCollection */ - public function lines() + public function lines(): OrderLineCollection { + /** @var OrderLineCollection */ return ResourceFactory::createBaseResourceCollection( $this->client, OrderLine::class, @@ -100,7 +101,7 @@ public function lines() * @return Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function order() + public function order(): Order { return $this->client->orders->get($this->orderId); } @@ -108,10 +109,10 @@ public function order() /** * Save changes made to this shipment. * - * @return BaseResource|Shipment + * @return null|Shipment * @throws \Mollie\Api\Exceptions\ApiException */ - public function update() + public function update(): ?Shipment { $body = [ "tracking" => $this->tracking, @@ -119,6 +120,11 @@ public function update() $result = $this->client->shipments->update($this->orderId, $this->id, $body); + if (!$result) { + return null; + } + + /** @var Shipment */ return ResourceFactory::createFromApiResult($result, new Shipment($this->client)); } } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 04634ecd9..2d14bff43 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -110,10 +110,10 @@ class Subscription extends BaseResource public $_links; /** - * @return Subscription + * @return null|Subscription * @throws \Mollie\Api\Exceptions\ApiException */ - public function update() + public function update(): ?Subscription { $body = [ "amount" => $this->amount, @@ -128,6 +128,11 @@ public function update() $result = $this->client->subscriptions->update($this->customerId, $this->id, $body); + if (!$result) { + return null; + } + + /** @var Subscription */ return ResourceFactory::createFromApiResult($result, new Subscription($this->client)); } @@ -184,12 +189,12 @@ public function isCompleted() /** * Cancels this subscription * - * @return Subscription + * @return null|Subscription * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancel() + public function cancel(): ?Subscription { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } @@ -206,26 +211,32 @@ public function cancel() $body ); - return ResourceFactory::createFromApiResult($result, new Subscription($this->client)); + if ($result->isEmpty()) { + return null; + } + + /** @var Subscription */ + return ResourceFactory::createFromApiResult($result->decode(), new Subscription($this->client)); } /** * Get subscription payments * - * @return \Mollie\Api\Resources\PaymentCollection + * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function payments() + public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } $result = $this->client->performHttpCallToFullUrl( MollieApiClient::HTTP_GET, $this->_links->payments->href - ); + )->decode(); + /** @var PaymentCollection */ return ResourceFactory::createCursorResourceCollection( $this->client, $result->_embedded->payments, diff --git a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php index cbc82aef8..c2b14129b 100644 --- a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php @@ -129,7 +129,7 @@ public function testListBalances() ); /** @var BalanceCollection $balances */ - $balances = $this->apiClient->balances->collect(); + $balances = $this->apiClient->balances->page(); $this->assertInstanceOf(BalanceCollection::class, $balances); $this->assertEquals(2, $balances->count); diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index c2727e6b9..44fb3b568 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -107,7 +107,7 @@ public function testListChargebacks() ) ); - $chargebacks = $this->apiClient->chargebacks->collect(); + $chargebacks = $this->apiClient->chargebacks->page(); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); $this->assertEquals(2, $chargebacks->count); diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php index ddf9adbb2..4aaff5539 100644 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientEndpointTest.php @@ -119,7 +119,7 @@ public function testGetClientsPage() ) ); - $clients = $this->apiClient->clients->collect(); + $clients = $this->apiClient->clients->page(); $this->assertInstanceOf(ClientCollection::class, $clients); $this->assertEquals(1, $clients->count); diff --git a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php index c3672109b..20e939ba0 100644 --- a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php @@ -140,7 +140,7 @@ public function testListWorks() ) ); - $customers = $this->apiClient->customers->collect(); + $customers = $this->apiClient->customers->page(); $this->assertInstanceOf(CustomerCollection::class, $customers); diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php index e715a6025..12c338fff 100644 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php @@ -200,7 +200,7 @@ public function testListInvoices() ) ); - $invoices = $this->apiClient->invoices->collect(); + $invoices = $this->apiClient->invoices->page(); $this->assertInstanceOf(InvoiceCollection::class, $invoices); $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html']; diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index c497cc2fd..b1a2b5674 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -539,7 +539,7 @@ public function testListOrders() ) ); - $orders = $this->apiClient->orders->collect(); + $orders = $this->apiClient->orders->page(); $this->assertInstanceOf(OrderCollection::class, $orders); $this->assertEquals(3, $orders->count); diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index f2821140d..344f1b922 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -475,7 +475,7 @@ public function testListPayment() ) ); - $payments = $this->apiClient->payments->collect(null, 3); + $payments = $this->apiClient->payments->page(null, 3); $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertEquals(3, $payments->count); diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php index 2f2d35d9f..61a81731b 100644 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php @@ -366,7 +366,7 @@ public function testListProfiles() ) ); - $profiles = $this->apiClient->profiles->collect(); + $profiles = $this->apiClient->profiles->page(); $this->assertInstanceOf(ProfileCollection::class, $profiles); $this->assertEquals(2, $profiles->count); diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php index ba5fd91ec..351e2b461 100644 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/RefundEndpointTest.php @@ -69,7 +69,7 @@ public function testListRefunds() ) ); - $refunds = $this->apiClient->refunds->collect(); + $refunds = $this->apiClient->refunds->page(); $this->assertInstanceOf(RefundCollection::class, $refunds); $this->assertEquals(1, $refunds->count); diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php index 42e59be58..a8eab4902 100644 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php @@ -426,7 +426,7 @@ public function testListSettlement() ); /** @var SettlementCollection $settlements */ - $settlements = $this->apiClient->settlements->collect(); + $settlements = $this->apiClient->settlements->page(); $this->assertInstanceOf(SettlementCollection::class, $settlements); $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html']; diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php index 859eefb7a..f5ccb3f9f 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php @@ -476,7 +476,7 @@ public function testListPageOfRootSubscriptionsWorks() ) ); - $subscriptions = $this->apiClient->subscriptions->collect(); + $subscriptions = $this->apiClient->subscriptions->page(); $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); $this->assertCount(1, $subscriptions); diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index c7f83cabd..fc4494e10 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -177,7 +177,7 @@ public function testListTerminal() ) ); - $terminals = $this->apiClient->terminals->collect(null, 3); + $terminals = $this->apiClient->terminals->page(null, 3); $this->assertInstanceOf(TerminalCollection::class, $terminals); $this->assertEquals(3, $terminals->count); diff --git a/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php deleted file mode 100644 index 9b99dbf8d..000000000 --- a/tests/Mollie/API/HttpAdapter/CurlMollieHttpAdapterTest.php +++ /dev/null @@ -1,16 +0,0 @@ -assertFalse($adapter->supportsDebugging()); - } -} diff --git a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php index 3233d1028..9f7b14184 100644 --- a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php @@ -54,8 +54,8 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - $exception = invade($e); - $this->assertInstanceOf(RequestInterface::class, $exception->request); + /** @phpstan-ignore-next-line */ + $this->assertInstanceOf(RequestInterface::class, invade($e)->request); } } @@ -86,8 +86,8 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - $exception = invade($e); - $this->assertNull($exception->request); + /** @phpstan-ignore-next-line */ + $this->assertNull(invade($e)->request); } } } diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php index 541615165..dfa6203e1 100644 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php @@ -11,8 +11,9 @@ class MockMollieHttpAdapter implements \Mollie\Api\Contracts\MollieHttpAdapterCo */ public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - return new class implements ResponseContract { - public function json(): \stdClass + return new class implements ResponseContract + { + public function decode(): \stdClass { return (object) ['foo' => 'bar']; } @@ -26,6 +27,11 @@ public function body(): string { return 'foo'; } + + public function isEmpty(): bool + { + return false; + } }; } diff --git a/tests/Mollie/API/MollieApiClientTest.php b/tests/Mollie/API/MollieApiClientTest.php index 5a6dfe5f6..2d0c0b28c 100644 --- a/tests/Mollie/API/MollieApiClientTest.php +++ b/tests/Mollie/API/MollieApiClientTest.php @@ -49,7 +49,7 @@ public function testPerformHttpCallReturnsBodyAsObject() $this->assertEquals( (object)['resource' => 'payment'], - $parsedResponse + $parsedResponse->decode() ); } @@ -126,7 +126,9 @@ public function testCanBeSerializedAndUnserialized() /** @var MollieApiClient $client_copy */ $client_copy = invade(unserialize($serialized)); + /** @phpstan-ignore-next-line */ $this->assertEmpty($client_copy->apiKey, "API key should not have been remembered"); + /** @phpstan-ignore-next-line */ $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->httpClient, "A Guzzle client should have been set."); $this->assertNull($client_copy->usesOAuth()); $this->assertEquals("https://mymollieproxy.local", $client_copy->getApiEndpoint(), "The API endpoint should be remembered"); @@ -158,7 +160,7 @@ public function testResponseBodyCanBeReadMultipleTimesIfMiddlewareReadsItFirst() $this->assertEquals( (object)['resource' => 'payment'], - $parsedResponse + $parsedResponse->decode() ); } diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index d521d4dce..eb351c006 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\Mollie\API\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\OrderCollection; @@ -15,7 +16,7 @@ public function testCanGetNextCollectionResultWhenNextLinkIsAvailable() $mockedClient = $this->createMock(MollieApiClient::class); $mockedClient->expects($this->once()) ->method('performHttpCallToFullUrl') - ->willReturn($this->arrayToObject([ + ->willReturn($this->arrayToResponse([ 'count' => 1, '_links' => [ 'self' => [ @@ -67,7 +68,7 @@ public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() $mockedClient->expects($this->once()) ->method('performHttpCallToFullUrl') ->willReturn( - $this->arrayToObject([ + $this->arrayToResponse([ 'count' => 1, '_links' => [ 'self' => [ @@ -131,7 +132,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() $mockedClient->expects($this->exactly(3)) ->method('performHttpCallToFullUrl') ->willReturnOnConsecutiveCalls( - $this->arrayToObject([ + $this->arrayToResponse([ 'count' => 1, '_links' => [ 'self' => [ @@ -147,7 +148,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() ], ], ]), - $this->arrayToObject([ + $this->arrayToResponse([ 'count' => 1, '_links' => [ 'self' => [ @@ -163,7 +164,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() ], ], ]), - $this->arrayToObject([ + $this->arrayToResponse([ 'count' => 1, '_links' => [ 'self' => [ @@ -204,7 +205,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() */ private function arrayToObject($data) { - if (! is_array($data)) { + if (!is_array($data)) { return $data; } @@ -216,4 +217,16 @@ private function arrayToObject($data) return $obj; } + + private function objectToResponse(object $obj): Response + { + return new Response(200, [], json_encode($obj)); + } + + private function arrayToResponse($data): Response + { + $obj = $this->arrayToObject($data); + + return $this->objectToResponse($obj); + } } diff --git a/tests/Mollie/API/Resources/ResourceFactoryTest.php b/tests/Mollie/API/Resources/ResourceFactoryTest.php index 5fcfc8950..f80e5cbcd 100644 --- a/tests/Mollie/API/Resources/ResourceFactoryTest.php +++ b/tests/Mollie/API/Resources/ResourceFactoryTest.php @@ -2,6 +2,7 @@ namespace Tests\Mollie\Api\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\ResourceFactory; @@ -11,15 +12,15 @@ class ResourceFactoryTest extends \PHPUnit\Framework\TestCase public function testCreateFromApiResponseWorks() { $apiResult = json_decode('{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - } - }'); + "resource":"payment", + "id":"tr_44aKxzEbr8", + "mode":"test", + "createdAt":"2018-03-13T14:02:29+00:00", + "amount":{ + "value":"20.00", + "currency":"EUR" + } + }'); $payment = ResourceFactory::createFromApiResult($apiResult, new Payment($this->createMock(MollieApiClient::class))); diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php index 9bad85e45..b3c65d105 100644 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ b/tests/Mollie/TestHelpers/FakeHttpAdapter.php @@ -2,42 +2,28 @@ namespace Tests\Mollie\TestHelpers; +use GuzzleHttp\Psr7\Response; use Mollie\Api\Contracts\MollieHttpAdapterContract; use Mollie\Api\Contracts\ResponseContract; use Mollie\Api\Http\PsrResponseHandler; class FakeHttpAdapter implements MollieHttpAdapterContract { - /** - * @var \stdClass|null - */ - private $response; + private Response $response; - /** - * @var string - */ - private $usedMethod; + private string $usedMethod; - /** - * @var string - */ - private $usedUrl; + private string $usedUrl; - /** - * @var string - */ - private $usedHeaders; + private string $usedHeaders; - /** - * @var string - */ - private $usedBody; + private string $usedBody; /** * FakeHttpAdapter constructor. - * @param \stdClass|null|\GuzzleHttp\Psr7\Response $response + * @paramResponse $response */ - public function __construct($response) + public function __construct(Response $response) { $this->response = $response; } @@ -47,7 +33,7 @@ public function __construct($response) * @param string $url * @param string $headers * @param string $body - * @return \stdClass|null + * @return ResponseContract */ public function send(string $method, string $url, $headers, ?string $body): ResponseContract { @@ -57,7 +43,7 @@ public function send(string $method, string $url, $headers, ?string $body): Resp $this->usedBody = $body; return PsrResponseHandler::create() - ->handle($this->response, 200, $body); + ->handle(null, $this->response, 200, $body); } /** From c5e6e182d7820ebe0783c1c2a7c5dbc3eccb1566 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 27 Jun 2024 21:06:39 +0000 Subject: [PATCH 016/131] Fix styling --- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/RestEndpoint.php | 2 +- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 3 +-- src/Http/PsrResponseHandler.php | 2 +- src/Http/Response.php | 2 +- src/Http/ResponseHandler.php | 2 +- src/MollieApiClient.php | 12 ++++++------ src/Resources/CursorCollection.php | 6 +++--- src/Resources/Mandate.php | 2 +- src/Resources/Order.php | 2 +- src/Resources/Payment.php | 14 +++++++------- src/Resources/Profile.php | 10 +++++----- src/Resources/Shipment.php | 6 +++--- src/Resources/Subscription.php | 6 +++--- .../API/HttpAdapter/MockMollieHttpAdapter.php | 3 +-- .../Mollie/API/Resources/CursorCollectionTest.php | 2 +- tests/Mollie/API/Resources/ResourceFactoryTest.php | 1 - 17 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 96b454350..82f048d55 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -109,7 +109,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (!isset($data['lines']) || !is_array($data['lines'])) { + if (! isset($data['lines']) || ! is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index b860ae024..dd1aac521 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -74,7 +74,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpointContract && empty($id)) { + if (! $this instanceof SingleResourceEndpointContract && empty($id)) { throw new ApiException("Invalid resource id."); } diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 4a8d578dd..c2d872132 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -15,7 +15,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\IsDebuggable; use Mollie\Api\Http\PsrResponseHandler; -use Psr\Http\Message\ResponseInterface; final class GuzzleMollieHttpAdapter implements MollieHttpAdapterContract, SupportsDebuggingContract { @@ -85,7 +84,7 @@ public function send(string $method, string $url, $headers, ?string $body = null $response = $this->httpClient->send($request, ['http_errors' => false]); } catch (GuzzleException $e) { // Prevent sensitive request data from ending up in exception logs unintended - if (!$this->debug) { + if (! $this->debug) { $request = null; } diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php index 751c8160d..4f718ddf1 100644 --- a/src/Http/PsrResponseHandler.php +++ b/src/Http/PsrResponseHandler.php @@ -41,7 +41,7 @@ public function handle( return ResponseHandler::noResponse(); } - if (!$psrResponse instanceof ResponseInterface) { + if (! $psrResponse instanceof ResponseInterface) { throw new RuntimeException("Response must be an instance of ResponseInterface."); } diff --git a/src/Http/Response.php b/src/Http/Response.php index a3916cb72..b3be4d5c6 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -62,7 +62,7 @@ public function decode(): \stdClass return (object)[]; } - if (!$this->decoded) { + if (! $this->decoded) { $this->decoded = @json_decode($body); if (json_last_error() !== JSON_ERROR_NONE) { diff --git a/src/Http/ResponseHandler.php b/src/Http/ResponseHandler.php index 757a39456..d7ff9e4a7 100644 --- a/src/Http/ResponseHandler.php +++ b/src/Http/ResponseHandler.php @@ -79,7 +79,7 @@ public function throwExceptionIfRequestFailed(ResponseContract $response, ?strin $field = null; - if (!empty($body->field)) { + if (! empty($body->field)) { $field = $body->field; } diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 3536b7e99..54a79b5e2 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,6 +2,8 @@ namespace Mollie\Api; +use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; use Mollie\Api\Contracts\ResponseContract as Response; use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; @@ -19,6 +21,7 @@ use Mollie\Api\Endpoints\OrderLineEndpoint; use Mollie\Api\Endpoints\OrderPaymentEndpoint; use Mollie\Api\Endpoints\OrderRefundEndpoint; +use Mollie\Api\Endpoints\OrderShipmentEndpoint; use Mollie\Api\Endpoints\OrganizationEndpoint; use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; use Mollie\Api\Endpoints\PaymentCaptureEndpoint; @@ -36,15 +39,12 @@ use Mollie\Api\Endpoints\SettlementPaymentEndpoint; use Mollie\Api\Endpoints\SettlementRefundEndpoint; use Mollie\Api\Endpoints\SettlementsEndpoint; -use Mollie\Api\Endpoints\OrderShipmentEndpoint; use Mollie\Api\Endpoints\SubscriptionEndpoint; use Mollie\Api\Endpoints\TerminalEndpoint; use Mollie\Api\Endpoints\WalletEndpoint; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Contracts\MollieHttpAdapterContract; -use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; -use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Exceptions\IncompatiblePlatform; +use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract; /** @@ -263,7 +263,7 @@ public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -283,7 +283,7 @@ public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (!preg_match('/^access_\w+$/', $accessToken)) { + if (! preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 83271a26c..844ea437d 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -36,7 +36,7 @@ abstract protected function createResourceObject(); */ final public function next(): ?CursorCollection { - if (!$this->hasNext()) { + if (! $this->hasNext()) { return null; } @@ -51,7 +51,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (!$this->hasPrevious()) { + if (! $this->hasPrevious()) { return null; } @@ -116,7 +116,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index c0ecd8bfd..0c7c48ffc 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -90,7 +90,7 @@ public function isInvalid() */ public function revoke(): ?Mandate { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index f4465b8a4..0168b82c2 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -519,7 +519,7 @@ public function createPayment($data, $filters = []) */ public function payments(): ?PaymentCollection { - if (!isset($this->_embedded, $this->_embedded->payments)) { + if (! isset($this->_embedded, $this->_embedded->payments)) { return null; } diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index e035dd9c1..4713bb6f3 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -433,7 +433,7 @@ public function isAuthorized() */ public function isPaid() { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** @@ -443,7 +443,7 @@ public function isPaid() */ public function hasRefunds() { - return !empty($this->_links->refunds); + return ! empty($this->_links->refunds); } /** @@ -453,7 +453,7 @@ public function hasRefunds() */ public function hasChargebacks() { - return !empty($this->_links->chargebacks); + return ! empty($this->_links->chargebacks); } /** @@ -586,7 +586,7 @@ public function getAmountChargedBack() */ public function hasSplitPayments() { - return !empty($this->routing); + return ! empty($this->routing); } /** @@ -597,7 +597,7 @@ public function hasSplitPayments() */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } @@ -652,7 +652,7 @@ public function listRefunds(array $parameters = []): RefundCollection */ public function captures(): CaptureCollection { - if (!isset($this->_links->captures->href)) { + if (! isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } @@ -694,7 +694,7 @@ public function getCapture($captureId, array $parameters = []) */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 6b06f6f32..435489826 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -120,7 +120,7 @@ public function update(): ?Profile $result = $this->client->profiles->update($this->id, $body); - if (!$result) { + if (! $result) { return null; } @@ -136,7 +136,7 @@ public function update(): ?Profile */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -162,7 +162,7 @@ public function chargebacks(): ChargebackCollection */ public function methods(): MethodCollection { - if (!isset($this->_links->methods->href)) { + if (! isset($this->_links->methods->href)) { return new MethodCollection(0, null); } @@ -214,7 +214,7 @@ public function disableMethod($methodId, array $data = []) */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } @@ -240,7 +240,7 @@ public function payments(): PaymentCollection */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index 2ef5a8448..bec126dc4 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -63,7 +63,7 @@ public function hasTracking() */ public function hasTrackingUrl() { - return $this->hasTracking() && !empty($this->tracking->url); + return $this->hasTracking() && ! empty($this->tracking->url); } /** @@ -73,7 +73,7 @@ public function hasTrackingUrl() */ public function getTrackingUrl() { - if (!$this->hasTrackingUrl()) { + if (! $this->hasTrackingUrl()) { return null; } @@ -120,7 +120,7 @@ public function update(): ?Shipment $result = $this->client->shipments->update($this->orderId, $this->id, $body); - if (!$result) { + if (! $result) { return null; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 2d14bff43..753105992 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -128,7 +128,7 @@ public function update(): ?Subscription $result = $this->client->subscriptions->update($this->customerId, $this->id, $body); - if (!$result) { + if (! $result) { return null; } @@ -194,7 +194,7 @@ public function isCompleted() */ public function cancel(): ?Subscription { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } @@ -227,7 +227,7 @@ public function cancel(): ?Subscription */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php index dfa6203e1..859db24c1 100644 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php @@ -11,8 +11,7 @@ class MockMollieHttpAdapter implements \Mollie\Api\Contracts\MollieHttpAdapterCo */ public function send(string $method, string $url, $headers, ?string $body): ResponseContract { - return new class implements ResponseContract - { + return new class implements ResponseContract { public function decode(): \stdClass { return (object) ['foo' => 'bar']; diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index eb351c006..8ad487f52 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -205,7 +205,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() */ private function arrayToObject($data) { - if (!is_array($data)) { + if (! is_array($data)) { return $data; } diff --git a/tests/Mollie/API/Resources/ResourceFactoryTest.php b/tests/Mollie/API/Resources/ResourceFactoryTest.php index f80e5cbcd..388ae2e55 100644 --- a/tests/Mollie/API/Resources/ResourceFactoryTest.php +++ b/tests/Mollie/API/Resources/ResourceFactoryTest.php @@ -2,7 +2,6 @@ namespace Tests\Mollie\Api\Resources; -use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\ResourceFactory; From 7d86f99d4081823139f35ecf6b942eb7116ada58 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 27 Jun 2024 23:10:12 +0200 Subject: [PATCH 017/131] fix typehints --- src/MollieApiClient.php | 6 +++--- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 54a79b5e2..0c38f459e 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -127,14 +127,14 @@ class MollieApiClient /** * @var string */ - protected string $apiKey; + protected string $apiKey = ''; /** * True if an OAuth access token is set as API key. * - * @var bool + * @var null|bool */ - protected bool $oauthAccess; + protected ?bool $oauthAccess = null; /** * @var array diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php index b3c65d105..59b71189f 100644 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ b/tests/Mollie/TestHelpers/FakeHttpAdapter.php @@ -15,9 +15,9 @@ class FakeHttpAdapter implements MollieHttpAdapterContract private string $usedUrl; - private string $usedHeaders; + private array $usedHeaders = []; - private string $usedBody; + private ?string $usedBody = null; /** * FakeHttpAdapter constructor. From b21057f293eb81ae36edb85fe85b23fab8d3175f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 27 Jun 2024 23:56:12 +0200 Subject: [PATCH 018/131] wip --- src/Endpoints/OrderLineEndpoint.php | 20 ++++-- src/Endpoints/RestEndpoint.php | 7 +- src/Resources/BalanceCollection.php | 10 +-- .../BalanceTransactionCollection.php | 4 +- src/Resources/BaseCollection.php | 16 +++-- src/Resources/CaptureCollection.php | 6 +- src/Resources/ChargebackCollection.php | 6 +- src/Resources/ClientCollection.php | 6 +- src/Resources/CurrentProfile.php | 4 +- src/Resources/CursorCollection.php | 25 +++++-- src/Resources/Customer.php | 20 ++---- src/Resources/CustomerCollection.php | 6 +- src/Resources/Invoice.php | 6 +- src/Resources/InvoiceCollection.php | 6 +- src/Resources/IssuerCollection.php | 4 +- src/Resources/Mandate.php | 10 +-- src/Resources/MandateCollection.php | 21 ++---- src/Resources/MethodCollection.php | 2 +- src/Resources/MethodPriceCollection.php | 4 +- src/Resources/Onboarding.php | 6 +- src/Resources/Order.php | 47 +++++-------- src/Resources/OrderCollection.php | 6 +- src/Resources/OrderLine.php | 47 +++++-------- src/Resources/OrderLineCollection.php | 6 +- src/Resources/Payment.php | 70 +++++++++---------- src/Resources/PaymentCollection.php | 6 +- src/Resources/PaymentLink.php | 8 +-- src/Resources/PaymentLinkCollection.php | 6 +- src/Resources/PermissionCollection.php | 2 +- src/Resources/Profile.php | 27 +++---- src/Resources/ProfileCollection.php | 6 +- src/Resources/Refund.php | 21 +++--- src/Resources/RefundCollection.php | 6 +- src/Resources/Settlement.php | 14 ++-- src/Resources/SettlementCollection.php | 6 +- src/Resources/Shipment.php | 19 ++--- src/Resources/ShipmentCollection.php | 2 +- src/Resources/Subscription.php | 23 +++--- src/Resources/SubscriptionCollection.php | 6 +- src/Resources/Terminal.php | 6 +- src/Resources/TerminalCollection.php | 6 +- src/Types/OrderLineStatus.php | 6 -- src/Types/OrderStatus.php | 6 -- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 2 +- 44 files changed, 243 insertions(+), 300 deletions(-) diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 82f048d55..c41b9f8a8 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -39,17 +39,27 @@ protected function getResourceCollectionObject(int $count, object $_links): Orde * @param string $orderlineId * @param array $data * - * @return null|OrderLine + * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function update(string $orderId, string $orderlineId, array $data = []): ?OrderLine + public function update(string $orderId, string $orderlineId, array $data = []): ?Order { $this->parentId = $orderId; $this->guardAgainstInvalidId($orderlineId); - /** @var null|OrderLine */ - return $this->updateResource($orderlineId, $data); + $response = $this->client->performHttpCall( + self::REST_UPDATE, + $this->getPathToSingleResource(urlencode($orderlineId)), + $this->parseRequestBody($data) + ); + + if ($response->isEmpty()) { + return null; + } + + /** @var Order */ + return ResourceFactory::createFromApiResult($response->decode(), new Order($this->client)); } /** @@ -109,7 +119,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (! isset($data['lines']) || ! is_array($data['lines'])) { + if (!isset($data['lines']) || !is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index dd1aac521..bf0562bf8 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -46,11 +46,8 @@ protected function createResource(array $body, array $filters): BaseResource */ protected function updateResource(string $id, array $body = []): ?BaseResource { - if (empty($id)) { - throw new ApiException("Invalid resource id."); - } - $id = urlencode($id); + $response = $this->client->performHttpCall( self::REST_UPDATE, $this->getPathToSingleResource($id), @@ -74,7 +71,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (! $this instanceof SingleResourceEndpointContract && empty($id)) { + if (!$this instanceof SingleResourceEndpointContract && empty($id)) { throw new ApiException("Invalid resource id."); } diff --git a/src/Resources/BalanceCollection.php b/src/Resources/BalanceCollection.php index 04f07cb83..1b661e754 100644 --- a/src/Resources/BalanceCollection.php +++ b/src/Resources/BalanceCollection.php @@ -4,18 +4,12 @@ class BalanceCollection extends CursorCollection { - /** - * @return string - */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "balances"; } - /** - * @return BaseResource - */ - protected function createResourceObject() + protected function createResourceObject(): Balance { return new Balance($this->client); } diff --git a/src/Resources/BalanceTransactionCollection.php b/src/Resources/BalanceTransactionCollection.php index 303de05c2..923b12c70 100644 --- a/src/Resources/BalanceTransactionCollection.php +++ b/src/Resources/BalanceTransactionCollection.php @@ -9,7 +9,7 @@ class BalanceTransactionCollection extends CursorCollection /** * @inheritDoc */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "balance_transactions"; } @@ -17,7 +17,7 @@ public function getCollectionResourceName() /** * @inheritDoc */ - protected function createResourceObject() + protected function createResourceObject(): BalanceTransaction { return new BalanceTransaction($this->client); } diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 1b338da53..2f07e278b 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -28,8 +28,16 @@ public function __construct(int $count, ?\stdClass $_links) parent::__construct(); } - /** - * @return string|null - */ - abstract public function getCollectionResourceName(); + abstract public function getCollectionResourceName(): ?string; + + public function contains(callable $callback): bool + { + foreach ($this as $item) { + if ($callback($item)) { + return true; + } + } + + return false; + } } diff --git a/src/Resources/CaptureCollection.php b/src/Resources/CaptureCollection.php index 38a5d7d81..55e270a9b 100644 --- a/src/Resources/CaptureCollection.php +++ b/src/Resources/CaptureCollection.php @@ -7,15 +7,15 @@ class CaptureCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "captures"; } /** - * @return BaseResource + * @return Capture */ - protected function createResourceObject() + protected function createResourceObject(): Capture { return new Capture($this->client); } diff --git a/src/Resources/ChargebackCollection.php b/src/Resources/ChargebackCollection.php index e8a8a2803..7f802df67 100644 --- a/src/Resources/ChargebackCollection.php +++ b/src/Resources/ChargebackCollection.php @@ -7,15 +7,15 @@ class ChargebackCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "chargebacks"; } /** - * @return BaseResource + * @return Chargeback */ - protected function createResourceObject() + protected function createResourceObject(): Chargeback { return new Chargeback($this->client); } diff --git a/src/Resources/ClientCollection.php b/src/Resources/ClientCollection.php index 707a16762..49657c828 100644 --- a/src/Resources/ClientCollection.php +++ b/src/Resources/ClientCollection.php @@ -7,15 +7,15 @@ class ClientCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "clients"; } /** - * @return BaseResource + * @return Client */ - protected function createResourceObject() + protected function createResourceObject(): Client { return new Client($this->client); } diff --git a/src/Resources/CurrentProfile.php b/src/Resources/CurrentProfile.php index b351fa92e..984672455 100644 --- a/src/Resources/CurrentProfile.php +++ b/src/Resources/CurrentProfile.php @@ -14,7 +14,7 @@ class CurrentProfile extends Profile * @return Method * @throws ApiException */ - public function enableMethod($methodId, array $data = []) + public function enableMethod($methodId, array $data = []): Method { return $this->client->profileMethods->createForCurrentProfile($methodId, $data); } @@ -27,7 +27,7 @@ public function enableMethod($methodId, array $data = []) * @return Method * @throws ApiException */ - public function disableMethod($methodId, array $data = []) + public function disableMethod($methodId, array $data = []): ?Method { return $this->client->profileMethods->deleteForCurrentProfile($methodId, $data); } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 844ea437d..f2c57dece 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -23,10 +23,7 @@ final public function __construct(MollieApiClient $client, int $count, ?\stdClas $this->client = $client; } - /** - * @return BaseResource - */ - abstract protected function createResourceObject(); + abstract protected function createResourceObject(): BaseResource; /** * Return the next set of resources when available @@ -36,7 +33,7 @@ abstract protected function createResourceObject(); */ final public function next(): ?CursorCollection { - if (! $this->hasNext()) { + if (!$this->hasNext()) { return null; } @@ -51,7 +48,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (! $this->hasPrevious()) { + if (!$this->hasPrevious()) { return null; } @@ -116,7 +113,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { break; } @@ -126,4 +123,18 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection } }); } + + public function filter(callable $callback): static + { + $collection = new static($this->client, 0, $this->_links); + + foreach ($this as $item) { + if ($callback($item)) { + $collection[] = $item; + $collection->count++; + } + } + + return $collection; + } } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 2ad564871..aa62879c0 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -194,14 +194,8 @@ public function mandates() */ public function hasValidMandate() { - $mandates = $this->mandates(); - foreach ($mandates as $mandate) { - if ($mandate->isValid()) { - return true; - } - } - - return false; + return $this->mandates() + ->contains(fn (Mandate $mandate) => $mandate->isValid()); } /** @@ -211,14 +205,8 @@ public function hasValidMandate() */ public function hasValidMandateForMethod($method): bool { - $mandates = $this->mandates(); - foreach ($mandates as $mandate) { - if ($mandate->method === $method && $mandate->isValid()) { - return true; - } - } - - return false; + return $this->mandates() + ->contains(fn (Mandate $mandate) => $mandate->isValid() && $mandate->method === $method); } /** diff --git a/src/Resources/CustomerCollection.php b/src/Resources/CustomerCollection.php index deece5770..5ffabdd93 100644 --- a/src/Resources/CustomerCollection.php +++ b/src/Resources/CustomerCollection.php @@ -7,15 +7,15 @@ class CustomerCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "customers"; } /** - * @return BaseResource + * @return Customer */ - protected function createResourceObject() + protected function createResourceObject(): Customer { return new Customer($this->client); } diff --git a/src/Resources/Invoice.php b/src/Resources/Invoice.php index dd45265f8..66049a846 100644 --- a/src/Resources/Invoice.php +++ b/src/Resources/Invoice.php @@ -86,7 +86,7 @@ class Invoice extends BaseResource /** * @return bool */ - public function isPaid() + public function isPaid(): bool { return $this->status == InvoiceStatus::PAID; } @@ -94,7 +94,7 @@ public function isPaid() /** * @return bool */ - public function isOpen() + public function isOpen(): bool { return $this->status == InvoiceStatus::OPEN; } @@ -102,7 +102,7 @@ public function isOpen() /** * @return bool */ - public function isOverdue() + public function isOverdue(): bool { return $this->status == InvoiceStatus::OVERDUE; } diff --git a/src/Resources/InvoiceCollection.php b/src/Resources/InvoiceCollection.php index 3278dd082..bf0a358c5 100644 --- a/src/Resources/InvoiceCollection.php +++ b/src/Resources/InvoiceCollection.php @@ -7,15 +7,15 @@ class InvoiceCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "invoices"; } /** - * @return BaseResource + * @return Invoice */ - protected function createResourceObject() + protected function createResourceObject(): Invoice { return new Invoice($this->client); } diff --git a/src/Resources/IssuerCollection.php b/src/Resources/IssuerCollection.php index ec4b7b794..338896795 100644 --- a/src/Resources/IssuerCollection.php +++ b/src/Resources/IssuerCollection.php @@ -5,9 +5,9 @@ class IssuerCollection extends BaseCollection { /** - * @return string|null + * @return null */ - public function getCollectionResourceName() + public function getCollectionResourceName(): null { return null; } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index 0c7c48ffc..ddf038b13 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -62,7 +62,7 @@ class Mandate extends BaseResource /** * @return bool */ - public function isValid() + public function isValid(): bool { return $this->status === MandateStatus::VALID; } @@ -70,7 +70,7 @@ public function isValid() /** * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === MandateStatus::PENDING; } @@ -78,7 +78,7 @@ public function isPending() /** * @return bool */ - public function isInvalid() + public function isInvalid(): bool { return $this->status === MandateStatus::INVALID; } @@ -86,11 +86,11 @@ public function isInvalid() /** * Revoke the mandate * - * @return null|\Mollie\Api\Resources\Mandate + * @return null|Mandate */ public function revoke(): ?Mandate { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } diff --git a/src/Resources/MandateCollection.php b/src/Resources/MandateCollection.php index 23d39d16c..e362a17aa 100644 --- a/src/Resources/MandateCollection.php +++ b/src/Resources/MandateCollection.php @@ -7,34 +7,25 @@ class MandateCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "mandates"; } /** - * @return BaseResource + * @return Mandate */ - protected function createResourceObject() + protected function createResourceObject(): Mandate { return new Mandate($this->client); } /** * @param string $status - * @return array|\Mollie\Api\Resources\MandateCollection + * @return MandateCollection */ - public function whereStatus($status) + public function whereStatus($status): self { - $collection = new self($this->client, 0, $this->_links); - - foreach ($this as $item) { - if ($item->status === $status) { - $collection[] = $item; - $collection->count++; - } - } - - return $collection; + return $this->filter(fn (Mandate $mandate) => $mandate->status === $status); } } diff --git a/src/Resources/MethodCollection.php b/src/Resources/MethodCollection.php index a1f204109..78cb3e9cd 100644 --- a/src/Resources/MethodCollection.php +++ b/src/Resources/MethodCollection.php @@ -7,7 +7,7 @@ class MethodCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "methods"; } diff --git a/src/Resources/MethodPriceCollection.php b/src/Resources/MethodPriceCollection.php index ca81fc2f3..93dcac557 100644 --- a/src/Resources/MethodPriceCollection.php +++ b/src/Resources/MethodPriceCollection.php @@ -5,9 +5,9 @@ class MethodPriceCollection extends BaseCollection { /** - * @return string|null + * @return null */ - public function getCollectionResourceName() + public function getCollectionResourceName(): null { return null; } diff --git a/src/Resources/Onboarding.php b/src/Resources/Onboarding.php index a45326c67..7f29f8629 100644 --- a/src/Resources/Onboarding.php +++ b/src/Resources/Onboarding.php @@ -42,7 +42,7 @@ class Onboarding extends BaseResource /** * @return bool */ - public function needsData() + public function needsData(): bool { return $this->status === OnboardingStatus::NEEDS_DATA; } @@ -50,7 +50,7 @@ public function needsData() /** * @return bool */ - public function isInReview() + public function isInReview(): bool { return $this->status === OnboardingStatus::IN_REVIEW; } @@ -58,7 +58,7 @@ public function isInReview() /** * @return bool */ - public function isCompleted() + public function isCompleted(): bool { return $this->status === OnboardingStatus::COMPLETED; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index 0168b82c2..9857b9608 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -226,7 +226,7 @@ class Order extends BaseResource * * @return bool */ - public function isCreated() + public function isCreated(): bool { return $this->status === OrderStatus::CREATED; } @@ -236,7 +236,7 @@ public function isCreated() * * @return bool */ - public function isPaid() + public function isPaid(): bool { return $this->status === OrderStatus::PAID; } @@ -246,7 +246,7 @@ public function isPaid() * * @return bool */ - public function isAuthorized() + public function isAuthorized(): bool { return $this->status === OrderStatus::AUTHORIZED; } @@ -256,28 +256,17 @@ public function isAuthorized() * * @return bool */ - public function isCanceled() + public function isCanceled(): bool { return $this->status === OrderStatus::CANCELED; } - /** - * (Deprecated) Is this order refunded? - * @deprecated 2018-11-27 - * - * @return bool - */ - public function isRefunded() - { - return $this->status === OrderStatus::REFUNDED; - } - /** * Is this order shipping? * * @return bool */ - public function isShipping() + public function isShipping(): bool { return $this->status === OrderStatus::SHIPPING; } @@ -287,7 +276,7 @@ public function isShipping() * * @return bool */ - public function isCompleted() + public function isCompleted(): bool { return $this->status === OrderStatus::COMPLETED; } @@ -297,7 +286,7 @@ public function isCompleted() * * @return bool */ - public function isExpired() + public function isExpired(): bool { return $this->status === OrderStatus::EXPIRED; } @@ -307,7 +296,7 @@ public function isExpired() * * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === OrderStatus::PENDING; } @@ -381,7 +370,7 @@ public function lines(): OrderLineCollection * @return Shipment * @throws ApiException */ - public function createShipment(array $options = []) + public function createShipment(array $options = []): Shipment { return $this->client->shipments->createFor($this, $this->withPresetOptions($options)); } @@ -393,7 +382,7 @@ public function createShipment(array $options = []) * * @return Shipment */ - public function shipAll(array $options = []) + public function shipAll(array $options = []): Shipment { $options['lines'] = []; @@ -422,7 +411,7 @@ public function getShipment($shipmentId, array $parameters = []) * @return ShipmentCollection * @throws ApiException */ - public function shipments(array $parameters = []) + public function shipments(array $parameters = []): ShipmentCollection { return $this->client->shipments->listFor($this, $this->withPresetOptions($parameters)); } @@ -432,7 +421,7 @@ public function shipments(array $parameters = []) * * @return string|null */ - public function getCheckoutUrl() + public function getCheckoutUrl(): ?string { if (empty($this->_links->checkout)) { return null; @@ -448,7 +437,7 @@ public function getCheckoutUrl() * @return Refund * @throws ApiException */ - public function refund(array $data) + public function refund(array $data): Refund { return $this->client->orderRefunds->createFor($this, $this->withPresetOptions($data)); } @@ -459,7 +448,7 @@ public function refund(array $data) * @param array $data * @return Refund */ - public function refundAll(array $data = []) + public function refundAll(array $data = []): Refund { $data['lines'] = []; @@ -506,7 +495,7 @@ public function update(): ?Order * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ - public function createPayment($data, $filters = []) + public function createPayment($data, $filters = []): Payment { return $this->client->orderPayments->createFor($this, $data, $filters); } @@ -519,7 +508,7 @@ public function createPayment($data, $filters = []) */ public function payments(): ?PaymentCollection { - if (! isset($this->_embedded, $this->_embedded->payments)) { + if (!isset($this->_embedded, $this->_embedded->payments)) { return null; } @@ -536,7 +525,7 @@ public function payments(): ?PaymentCollection * * @return array */ - private function getPresetOptions() + private function getPresetOptions(): array { $options = []; if ($this->client->usesOAuth()) { @@ -552,7 +541,7 @@ private function getPresetOptions() * @param array $options * @return array */ - private function withPresetOptions(array $options) + private function withPresetOptions(array $options): array { return array_merge($this->getPresetOptions(), $options); } diff --git a/src/Resources/OrderCollection.php b/src/Resources/OrderCollection.php index ff5fad80c..3733669af 100644 --- a/src/Resources/OrderCollection.php +++ b/src/Resources/OrderCollection.php @@ -7,15 +7,15 @@ class OrderCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "orders"; } /** - * @return BaseResource + * @return Order */ - protected function createResourceObject() + protected function createResourceObject(): Order { return new Order($this->client); } diff --git a/src/Resources/OrderLine.php b/src/Resources/OrderLine.php index 08f01e1d3..3a031250a 100644 --- a/src/Resources/OrderLine.php +++ b/src/Resources/OrderLine.php @@ -228,7 +228,7 @@ public function getProductUrl() * * @return string|null */ - public function getImageUrl() + public function getImageUrl(): ?string { if (empty($this->_links->imageUrl)) { return null; @@ -242,7 +242,7 @@ public function getImageUrl() * * @return bool */ - public function isCreated() + public function isCreated(): bool { return $this->status === OrderLineStatus::CREATED; } @@ -252,7 +252,7 @@ public function isCreated() * * @return bool */ - public function isPaid() + public function isPaid(): bool { return $this->status === OrderLineStatus::PAID; } @@ -262,7 +262,7 @@ public function isPaid() * * @return bool */ - public function isAuthorized() + public function isAuthorized(): bool { return $this->status === OrderLineStatus::AUTHORIZED; } @@ -272,28 +272,17 @@ public function isAuthorized() * * @return bool */ - public function isCanceled() + public function isCanceled(): bool { return $this->status === OrderLineStatus::CANCELED; } - /** - * (Deprecated) Is this order line refunded? - * @deprecated 2018-11-27 - * - * @return bool - */ - public function isRefunded() - { - return $this->status === OrderLineStatus::REFUNDED; - } - /** * Is this order line shipping? * * @return bool */ - public function isShipping() + public function isShipping(): bool { return $this->status === OrderLineStatus::SHIPPING; } @@ -303,7 +292,7 @@ public function isShipping() * * @return bool */ - public function isCompleted() + public function isCompleted(): bool { return $this->status === OrderLineStatus::COMPLETED; } @@ -313,7 +302,7 @@ public function isCompleted() * * @return bool */ - public function isPhysical() + public function isPhysical(): bool { return $this->type === OrderLineType::PHYSICAL; } @@ -323,7 +312,7 @@ public function isPhysical() * * @return bool */ - public function isDiscount() + public function isDiscount(): bool { return $this->type === OrderLineType::DISCOUNT; } @@ -333,7 +322,7 @@ public function isDiscount() * * @return bool */ - public function isDigital() + public function isDigital(): bool { return $this->type === OrderLineType::DIGITAL; } @@ -343,7 +332,7 @@ public function isDigital() * * @return bool */ - public function isShippingFee() + public function isShippingFee(): bool { return $this->type === OrderLineType::SHIPPING_FEE; } @@ -353,7 +342,7 @@ public function isShippingFee() * * @return bool */ - public function isStoreCredit() + public function isStoreCredit(): bool { return $this->type === OrderLineType::STORE_CREDIT; } @@ -363,7 +352,7 @@ public function isStoreCredit() * * @return bool */ - public function isGiftCard() + public function isGiftCard(): bool { return $this->type === OrderLineType::GIFT_CARD; } @@ -373,7 +362,7 @@ public function isGiftCard() * * @return bool */ - public function isSurcharge() + public function isSurcharge(): bool { return $this->type === OrderLineType::SURCHARGE; } @@ -381,13 +370,15 @@ public function isSurcharge() /** * Update an orderline by supplying one or more parameters in the data array * - * @return BaseResource + * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ - public function update() + public function update(): ?Order { + /** @var null|Order */ $result = $this->client->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); + /** @var Order */ return ResourceFactory::createFromApiResult($result, new Order($this->client)); } @@ -396,7 +387,7 @@ public function update() * * @return array */ - public function getUpdateData() + public function getUpdateData(): array { $data = [ "name" => $this->name, diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php index d2f8bc285..749ad0bfe 100644 --- a/src/Resources/OrderLineCollection.php +++ b/src/Resources/OrderLineCollection.php @@ -5,9 +5,9 @@ class OrderLineCollection extends BaseCollection { /** - * @return string|null + * @return null */ - public function getCollectionResourceName() + public function getCollectionResourceName(): null { return null; } @@ -19,7 +19,7 @@ public function getCollectionResourceName() * @param string $lineId * @return OrderLine|null */ - public function get($lineId) + public function get($lineId): ?OrderLine { foreach ($this as $line) { if ($line->id === $lineId) { diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 4713bb6f3..c5ab19e1e 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -381,7 +381,7 @@ class Payment extends BaseResource * * @return bool */ - public function isCanceled() + public function isCanceled(): bool { return $this->status === PaymentStatus::CANCELED; } @@ -391,7 +391,7 @@ public function isCanceled() * * @return bool */ - public function isExpired() + public function isExpired(): bool { return $this->status === PaymentStatus::EXPIRED; } @@ -401,7 +401,7 @@ public function isExpired() * * @return bool */ - public function isOpen() + public function isOpen(): bool { return $this->status === PaymentStatus::OPEN; } @@ -411,7 +411,7 @@ public function isOpen() * * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === PaymentStatus::PENDING; } @@ -421,7 +421,7 @@ public function isPending() * * @return bool */ - public function isAuthorized() + public function isAuthorized(): bool { return $this->status === PaymentStatus::AUTHORIZED; } @@ -431,9 +431,9 @@ public function isAuthorized() * * @return bool */ - public function isPaid() + public function isPaid(): bool { - return ! empty($this->paidAt); + return !empty($this->paidAt); } /** @@ -441,9 +441,9 @@ public function isPaid() * * @return bool */ - public function hasRefunds() + public function hasRefunds(): bool { - return ! empty($this->_links->refunds); + return !empty($this->_links->refunds); } /** @@ -451,9 +451,9 @@ public function hasRefunds() * * @return bool */ - public function hasChargebacks() + public function hasChargebacks(): bool { - return ! empty($this->_links->chargebacks); + return !empty($this->_links->chargebacks); } /** @@ -461,7 +461,7 @@ public function hasChargebacks() * * @return bool */ - public function isFailed() + public function isFailed(): bool { return $this->status === PaymentStatus::FAILED; } @@ -473,7 +473,7 @@ public function isFailed() * * @return bool */ - public function hasSequenceTypeFirst() + public function hasSequenceTypeFirst(): bool { return $this->sequenceType === SequenceType::FIRST; } @@ -485,7 +485,7 @@ public function hasSequenceTypeFirst() * * @return bool */ - public function hasSequenceTypeRecurring() + public function hasSequenceTypeRecurring(): bool { return $this->sequenceType === SequenceType::RECURRING; } @@ -495,7 +495,7 @@ public function hasSequenceTypeRecurring() * * @return string|null */ - public function getCheckoutUrl() + public function getCheckoutUrl(): ?string { if (empty($this->_links->checkout)) { return null; @@ -509,7 +509,7 @@ public function getCheckoutUrl() * * @return string|null */ - public function getMobileAppCheckoutUrl() + public function getMobileAppCheckoutUrl(): ?string { if (empty($this->_links->mobileAppCheckout)) { return null; @@ -521,7 +521,7 @@ public function getMobileAppCheckoutUrl() /** * @return bool */ - public function canBeRefunded() + public function canBeRefunded(): bool { return $this->amountRemaining !== null; } @@ -529,7 +529,7 @@ public function canBeRefunded() /** * @return bool */ - public function canBePartiallyRefunded() + public function canBePartiallyRefunded(): bool { return $this->canBeRefunded(); } @@ -539,7 +539,7 @@ public function canBePartiallyRefunded() * * @return float */ - public function getAmountRefunded() + public function getAmountRefunded(): float { if ($this->amountRefunded) { return (float)$this->amountRefunded->value; @@ -555,7 +555,7 @@ public function getAmountRefunded() * * @return float */ - public function getAmountRemaining() + public function getAmountRemaining(): float { if ($this->amountRemaining) { return (float)$this->amountRemaining->value; @@ -570,7 +570,7 @@ public function getAmountRemaining() * * @return float */ - public function getAmountChargedBack() + public function getAmountChargedBack(): float { if ($this->amountChargedBack) { return (float)$this->amountChargedBack->value; @@ -584,9 +584,9 @@ public function getAmountChargedBack() * * @return bool */ - public function hasSplitPayments() + public function hasSplitPayments(): bool { - return ! empty($this->routing); + return !empty($this->routing); } /** @@ -597,7 +597,7 @@ public function hasSplitPayments() */ public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } @@ -622,7 +622,7 @@ public function refunds(): RefundCollection * @return Refund * @throws ApiException */ - public function getRefund($refundId, array $parameters = []) + public function getRefund($refundId, array $parameters = []): Refund { return $this->client->paymentRefunds->getFor($this, $refundId, $this->withPresetOptions($parameters)); } @@ -652,7 +652,7 @@ public function listRefunds(array $parameters = []): RefundCollection */ public function captures(): CaptureCollection { - if (! isset($this->_links->captures->href)) { + if (!isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } @@ -677,7 +677,7 @@ public function captures(): CaptureCollection * @return Capture * @throws ApiException */ - public function getCapture($captureId, array $parameters = []) + public function getCapture($captureId, array $parameters = []): Capture { return $this->client->paymentCaptures->getFor( $this, @@ -694,7 +694,7 @@ public function getCapture($captureId, array $parameters = []) */ public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -721,7 +721,7 @@ public function chargebacks(): ChargebackCollection * @return Chargeback * @throws ApiException */ - public function getChargeback($chargebackId, array $parameters = []) + public function getChargeback($chargebackId, array $parameters = []): Chargeback { return $this->client->paymentChargebacks->getFor( $this, @@ -738,7 +738,7 @@ public function getChargeback($chargebackId, array $parameters = []) * @return \Mollie\Api\Resources\Refund * @throws ApiException */ - public function refund($data) + public function refund($data): Refund { return $this->client->paymentRefunds->createFor($this, $data); } @@ -772,7 +772,7 @@ public function update(): ?Payment * * @return array */ - private function getPresetOptions() + private function getPresetOptions(): array { $options = []; if ($this->client->usesOAuth()) { @@ -788,7 +788,7 @@ private function getPresetOptions() * @param array $options * @return array */ - private function withPresetOptions(array $options) + private function withPresetOptions(array $options): array { return array_merge($this->getPresetOptions(), $options); } @@ -799,7 +799,7 @@ private function withPresetOptions(array $options) * * @return float */ - public function getAmountCaptured() + public function getAmountCaptured(): float { if ($this->amountCaptured) { return (float)$this->amountCaptured->value; @@ -813,7 +813,7 @@ public function getAmountCaptured() * * @return float */ - public function getSettlementAmount() + public function getSettlementAmount(): float { if ($this->settlementAmount) { return (float)$this->settlementAmount->value; @@ -828,7 +828,7 @@ public function getSettlementAmount() * * @return float */ - public function getApplicationFeeAmount() + public function getApplicationFeeAmount(): float { if ($this->applicationFee) { return (float)$this->applicationFee->amount->value; diff --git a/src/Resources/PaymentCollection.php b/src/Resources/PaymentCollection.php index 892deb1be..4b968169b 100644 --- a/src/Resources/PaymentCollection.php +++ b/src/Resources/PaymentCollection.php @@ -7,15 +7,15 @@ class PaymentCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "payments"; } /** - * @return BaseResource + * @return Payment */ - protected function createResourceObject() + protected function createResourceObject(): Payment { return new Payment($this->client); } diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index cd64ed7d9..cdb157633 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -50,7 +50,7 @@ class PaymentLink extends BaseResource * @var bool */ public $archived; - + /** * UTC datetime the payment link was updated in ISO-8601 format. * @@ -106,9 +106,9 @@ class PaymentLink extends BaseResource * * @return bool */ - public function isPaid() + public function isPaid(): bool { - return ! empty($this->paidAt); + return !empty($this->paidAt); } /** @@ -116,7 +116,7 @@ public function isPaid() * * @return string|null */ - public function getCheckoutUrl() + public function getCheckoutUrl(): ?string { if (empty($this->_links->paymentLink)) { return null; diff --git a/src/Resources/PaymentLinkCollection.php b/src/Resources/PaymentLinkCollection.php index 061f1f665..0e6a41df6 100644 --- a/src/Resources/PaymentLinkCollection.php +++ b/src/Resources/PaymentLinkCollection.php @@ -7,15 +7,15 @@ class PaymentLinkCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "payment_links"; } /** - * @return BaseResource + * @return PaymentLink */ - protected function createResourceObject() + protected function createResourceObject(): PaymentLink { return new PaymentLink($this->client); } diff --git a/src/Resources/PermissionCollection.php b/src/Resources/PermissionCollection.php index 510cc64a7..d99da739c 100644 --- a/src/Resources/PermissionCollection.php +++ b/src/Resources/PermissionCollection.php @@ -7,7 +7,7 @@ class PermissionCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "permissions"; } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 435489826..1bcf6cd4a 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -82,7 +82,7 @@ class Profile extends BaseResource /** * @return bool */ - public function isUnverified() + public function isUnverified(): bool { return $this->status == ProfileStatus::UNVERIFIED; } @@ -90,7 +90,7 @@ public function isUnverified() /** * @return bool */ - public function isVerified() + public function isVerified(): bool { return $this->status == ProfileStatus::VERIFIED; } @@ -98,7 +98,7 @@ public function isVerified() /** * @return bool */ - public function isBlocked() + public function isBlocked(): bool { return $this->status == ProfileStatus::BLOCKED; } @@ -118,14 +118,7 @@ public function update(): ?Profile "mode" => $this->mode, ]; - $result = $this->client->profiles->update($this->id, $body); - - if (! $result) { - return null; - } - - /** @var Profile */ - return ResourceFactory::createFromApiResult($result, new Profile($this->client)); + return $this->client->profiles->update($this->id, $body); } /** @@ -136,7 +129,7 @@ public function update(): ?Profile */ public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { + if (!isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -162,7 +155,7 @@ public function chargebacks(): ChargebackCollection */ public function methods(): MethodCollection { - if (! isset($this->_links->methods->href)) { + if (!isset($this->_links->methods->href)) { return new MethodCollection(0, null); } @@ -188,7 +181,7 @@ public function methods(): MethodCollection * @return Method * @throws ApiException */ - public function enableMethod($methodId, array $data = []) + public function enableMethod($methodId, array $data = []): Method { return $this->client->profileMethods->createFor($this, $methodId, $data); } @@ -201,7 +194,7 @@ public function enableMethod($methodId, array $data = []) * @return Method * @throws ApiException */ - public function disableMethod($methodId, array $data = []) + public function disableMethod($methodId, array $data = []): ?Method { return $this->client->profileMethods->deleteFor($this, $methodId, $data); } @@ -214,7 +207,7 @@ public function disableMethod($methodId, array $data = []) */ public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } @@ -240,7 +233,7 @@ public function payments(): PaymentCollection */ public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { + if (!isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } diff --git a/src/Resources/ProfileCollection.php b/src/Resources/ProfileCollection.php index 536926b37..fcf3d05bc 100644 --- a/src/Resources/ProfileCollection.php +++ b/src/Resources/ProfileCollection.php @@ -7,15 +7,15 @@ class ProfileCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "profiles"; } /** - * @return BaseResource + * @return Profile */ - protected function createResourceObject() + protected function createResourceObject(): Profile { return new Profile($this->client); } diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index b8794c979..fd8bee67c 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -93,7 +93,7 @@ class Refund extends BaseResource /** * @return bool */ - public function canBeCanceled() + public function canBeCanceled(): bool { return $this->isQueued() || $this->isPending(); } @@ -103,7 +103,7 @@ public function canBeCanceled() * * @return bool */ - public function isQueued() + public function isQueued(): bool { return $this->status === RefundStatus::QUEUED; } @@ -113,7 +113,7 @@ public function isQueued() * * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === RefundStatus::PENDING; } @@ -123,7 +123,7 @@ public function isPending() * * @return bool */ - public function isProcessing() + public function isProcessing(): bool { return $this->status === RefundStatus::PROCESSING; } @@ -133,7 +133,7 @@ public function isProcessing() * * @return bool */ - public function isTransferred() + public function isTransferred(): bool { return $this->status === RefundStatus::REFUNDED; } @@ -143,7 +143,7 @@ public function isTransferred() * * @return bool */ - public function isFailed() + public function isFailed(): bool { return $this->status === RefundStatus::FAILED; } @@ -153,25 +153,22 @@ public function isFailed() * * @return bool */ - public function isCanceled() + public function isCanceled(): bool { return $this->status === RefundStatus::CANCELED; } /** * Cancel the refund. - * Returns null if successful. * - * @return null + * @return void * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancel() + public function cancel(): void { $this->client->performHttpCallToFullUrl( MollieApiClient::HTTP_DELETE, $this->_links->self->href ); - - return null; } } diff --git a/src/Resources/RefundCollection.php b/src/Resources/RefundCollection.php index 01b55a3ce..73b711ff5 100644 --- a/src/Resources/RefundCollection.php +++ b/src/Resources/RefundCollection.php @@ -7,15 +7,15 @@ class RefundCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "refunds"; } /** - * @return BaseResource + * @return Refund */ - protected function createResourceObject() + protected function createResourceObject(): Refund { return new Refund($this->client); } diff --git a/src/Resources/Settlement.php b/src/Resources/Settlement.php index 29e789939..41a980aeb 100644 --- a/src/Resources/Settlement.php +++ b/src/Resources/Settlement.php @@ -75,7 +75,7 @@ class Settlement extends BaseResource * * @return bool */ - public function isOpen() + public function isOpen(): bool { return $this->status === SettlementStatus::OPEN; } @@ -85,7 +85,7 @@ public function isOpen() * * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === SettlementStatus::PENDING; } @@ -95,7 +95,7 @@ public function isPending() * * @return bool */ - public function isPaidout() + public function isPaidout(): bool { return $this->status === SettlementStatus::PAIDOUT; } @@ -105,7 +105,7 @@ public function isPaidout() * * @return bool */ - public function isFailed() + public function isFailed(): bool { return $this->status === SettlementStatus::FAILED; } @@ -136,7 +136,7 @@ public function payments(int $limit = null, array $parameters = []): PaymentColl * @return RefundCollection * @throws ApiException */ - public function refunds(int $limit = null, array $parameters = []) + public function refunds(int $limit = null, array $parameters = []): RefundCollection { return $this->client->settlementRefunds->pageForId( $this->id, @@ -154,7 +154,7 @@ public function refunds(int $limit = null, array $parameters = []) * @return ChargebackCollection * @throws ApiException */ - public function chargebacks(int $limit = null, array $parameters = []) + public function chargebacks(int $limit = null, array $parameters = []): ChargebackCollection { return $this->client->settlementChargebacks->pageForId( $this->id, @@ -172,7 +172,7 @@ public function chargebacks(int $limit = null, array $parameters = []) * @return CaptureCollection * @throws ApiException */ - public function captures(int $limit = null, array $parameters = []) + public function captures(int $limit = null, array $parameters = []): CaptureCollection { return $this->client->settlementCaptures->pageForId( $this->id, diff --git a/src/Resources/SettlementCollection.php b/src/Resources/SettlementCollection.php index f8910b6f6..f69ded6a6 100644 --- a/src/Resources/SettlementCollection.php +++ b/src/Resources/SettlementCollection.php @@ -7,15 +7,15 @@ class SettlementCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "settlements"; } /** - * @return BaseResource + * @return Settlement */ - protected function createResourceObject() + protected function createResourceObject(): Settlement { return new Settlement($this->client); } diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index bec126dc4..75203c8ac 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -51,7 +51,7 @@ class Shipment extends BaseResource * * @return bool */ - public function hasTracking() + public function hasTracking(): bool { return $this->tracking !== null; } @@ -61,9 +61,9 @@ public function hasTracking() * * @return bool */ - public function hasTrackingUrl() + public function hasTrackingUrl(): bool { - return $this->hasTracking() && ! empty($this->tracking->url); + return $this->hasTracking() && !empty($this->tracking->url); } /** @@ -71,9 +71,9 @@ public function hasTrackingUrl() * * @return string|null */ - public function getTrackingUrl() + public function getTrackingUrl(): ?string { - if (! $this->hasTrackingUrl()) { + if (!$this->hasTrackingUrl()) { return null; } @@ -118,13 +118,6 @@ public function update(): ?Shipment "tracking" => $this->tracking, ]; - $result = $this->client->shipments->update($this->orderId, $this->id, $body); - - if (! $result) { - return null; - } - - /** @var Shipment */ - return ResourceFactory::createFromApiResult($result, new Shipment($this->client)); + return $this->client->shipments->update($this->orderId, $this->id, $body); } } diff --git a/src/Resources/ShipmentCollection.php b/src/Resources/ShipmentCollection.php index b87f3453e..b8b8bb776 100644 --- a/src/Resources/ShipmentCollection.php +++ b/src/Resources/ShipmentCollection.php @@ -7,7 +7,7 @@ class ShipmentCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return 'shipments'; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 753105992..4dcc948c0 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -126,14 +126,7 @@ public function update(): ?Subscription "interval" => $this->interval, ]; - $result = $this->client->subscriptions->update($this->customerId, $this->id, $body); - - if (! $result) { - return null; - } - - /** @var Subscription */ - return ResourceFactory::createFromApiResult($result, new Subscription($this->client)); + return $this->client->subscriptions->update($this->customerId, $this->id, $body); } /** @@ -141,7 +134,7 @@ public function update(): ?Subscription * * @return bool */ - public function isActive() + public function isActive(): bool { return $this->status === SubscriptionStatus::ACTIVE; } @@ -151,7 +144,7 @@ public function isActive() * * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === SubscriptionStatus::PENDING; } @@ -161,7 +154,7 @@ public function isPending() * * @return bool */ - public function isCanceled() + public function isCanceled(): bool { return $this->status === SubscriptionStatus::CANCELED; } @@ -171,7 +164,7 @@ public function isCanceled() * * @return bool */ - public function isSuspended() + public function isSuspended(): bool { return $this->status === SubscriptionStatus::SUSPENDED; } @@ -181,7 +174,7 @@ public function isSuspended() * * @return bool */ - public function isCompleted() + public function isCompleted(): bool { return $this->status === SubscriptionStatus::COMPLETED; } @@ -194,7 +187,7 @@ public function isCompleted() */ public function cancel(): ?Subscription { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } @@ -227,7 +220,7 @@ public function cancel(): ?Subscription */ public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { + if (!isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } diff --git a/src/Resources/SubscriptionCollection.php b/src/Resources/SubscriptionCollection.php index 848130895..b020b77eb 100644 --- a/src/Resources/SubscriptionCollection.php +++ b/src/Resources/SubscriptionCollection.php @@ -7,15 +7,15 @@ class SubscriptionCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "subscriptions"; } /** - * @return BaseResource + * @return Subscription */ - protected function createResourceObject() + protected function createResourceObject(): Subscription { return new Subscription($this->client); } diff --git a/src/Resources/Terminal.php b/src/Resources/Terminal.php index 3e709933b..a4ff90a83 100644 --- a/src/Resources/Terminal.php +++ b/src/Resources/Terminal.php @@ -134,7 +134,7 @@ class Terminal extends BaseResource /** * @return bool */ - public function isPending() + public function isPending(): bool { return $this->status === TerminalStatus::PENDING; } @@ -142,7 +142,7 @@ public function isPending() /** * @return bool */ - public function isActive() + public function isActive(): bool { return $this->status === TerminalStatus::ACTIVE; } @@ -150,7 +150,7 @@ public function isActive() /** * @return bool */ - public function isInactive() + public function isInactive(): bool { return $this->status === TerminalStatus::INACTIVE; } diff --git a/src/Resources/TerminalCollection.php b/src/Resources/TerminalCollection.php index af785a6e2..1640178dd 100644 --- a/src/Resources/TerminalCollection.php +++ b/src/Resources/TerminalCollection.php @@ -7,15 +7,15 @@ class TerminalCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName() + public function getCollectionResourceName(): string { return "terminals"; } /** - * @return BaseResource + * @return Terminal */ - protected function createResourceObject() + protected function createResourceObject(): Terminal { return new Terminal($this->client); } diff --git a/src/Types/OrderLineStatus.php b/src/Types/OrderLineStatus.php index 09273f50d..6594fa2cd 100644 --- a/src/Types/OrderLineStatus.php +++ b/src/Types/OrderLineStatus.php @@ -24,12 +24,6 @@ class OrderLineStatus */ public const CANCELED = "canceled"; - /** - * (Deprecated) The order line has been refunded. - * @deprecated - */ - public const REFUNDED = "refunded"; - /** * The order line is shipping. */ diff --git a/src/Types/OrderStatus.php b/src/Types/OrderStatus.php index 4e756f7f1..65f3c604e 100644 --- a/src/Types/OrderStatus.php +++ b/src/Types/OrderStatus.php @@ -43,10 +43,4 @@ class OrderStatus * The order is pending. */ public const PENDING = "pending"; - - /** - * (Deprecated) The order has been refunded. - * @deprecated 2018-11-27 - */ - public const REFUNDED = "refunded"; } diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php index 59b71189f..0a2866d92 100644 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ b/tests/Mollie/TestHelpers/FakeHttpAdapter.php @@ -31,7 +31,7 @@ public function __construct(Response $response) /** * @param string $method * @param string $url - * @param string $headers + * @param array $headers * @param string $body * @return ResponseContract */ From 1d42fa98d5cb26dd9b6a36a60a1d9bc4b5fbcc1b Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 27 Jun 2024 21:56:30 +0000 Subject: [PATCH 019/131] Fix styling --- src/Endpoints/OrderLineEndpoint.php | 2 +- src/Endpoints/RestEndpoint.php | 2 +- src/Resources/CursorCollection.php | 6 +++--- src/Resources/Mandate.php | 2 +- src/Resources/Order.php | 2 +- src/Resources/OrderLine.php | 2 +- src/Resources/Payment.php | 14 +++++++------- src/Resources/PaymentLink.php | 2 +- src/Resources/Profile.php | 8 ++++---- src/Resources/Shipment.php | 4 ++-- src/Resources/Subscription.php | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index c41b9f8a8..6ee5aec35 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -119,7 +119,7 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (!isset($data['lines']) || !is_array($data['lines'])) { + if (! isset($data['lines']) || ! is_array($data['lines'])) { throw new ApiException("A lines array is required."); } $this->parentId = $orderId; diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index bf0562bf8..8ce5da49c 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -71,7 +71,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpointContract && empty($id)) { + if (! $this instanceof SingleResourceEndpointContract && empty($id)) { throw new ApiException("Invalid resource id."); } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index f2c57dece..597f495c9 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -33,7 +33,7 @@ abstract protected function createResourceObject(): BaseResource; */ final public function next(): ?CursorCollection { - if (!$this->hasNext()) { + if (! $this->hasNext()) { return null; } @@ -48,7 +48,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (!$this->hasPrevious()) { + if (! $this->hasPrevious()) { return null; } @@ -113,7 +113,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index ddf038b13..1824a07c6 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -90,7 +90,7 @@ public function isInvalid(): bool */ public function revoke(): ?Mandate { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index 9857b9608..a1bcb251c 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -508,7 +508,7 @@ public function createPayment($data, $filters = []): Payment */ public function payments(): ?PaymentCollection { - if (!isset($this->_embedded, $this->_embedded->payments)) { + if (! isset($this->_embedded, $this->_embedded->payments)) { return null; } diff --git a/src/Resources/OrderLine.php b/src/Resources/OrderLine.php index 3a031250a..13a727aaa 100644 --- a/src/Resources/OrderLine.php +++ b/src/Resources/OrderLine.php @@ -375,7 +375,7 @@ public function isSurcharge(): bool */ public function update(): ?Order { - /** @var null|Order */ + /** @var null|Order */ $result = $this->client->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); /** @var Order */ diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index c5ab19e1e..441199a96 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -433,7 +433,7 @@ public function isAuthorized(): bool */ public function isPaid(): bool { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** @@ -443,7 +443,7 @@ public function isPaid(): bool */ public function hasRefunds(): bool { - return !empty($this->_links->refunds); + return ! empty($this->_links->refunds); } /** @@ -453,7 +453,7 @@ public function hasRefunds(): bool */ public function hasChargebacks(): bool { - return !empty($this->_links->chargebacks); + return ! empty($this->_links->chargebacks); } /** @@ -586,7 +586,7 @@ public function getAmountChargedBack(): float */ public function hasSplitPayments(): bool { - return !empty($this->routing); + return ! empty($this->routing); } /** @@ -597,7 +597,7 @@ public function hasSplitPayments(): bool */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } @@ -652,7 +652,7 @@ public function listRefunds(array $parameters = []): RefundCollection */ public function captures(): CaptureCollection { - if (!isset($this->_links->captures->href)) { + if (! isset($this->_links->captures->href)) { return new CaptureCollection($this->client, 0, null); } @@ -694,7 +694,7 @@ public function getCapture($captureId, array $parameters = []): Capture */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index cdb157633..c98e5bf0b 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -108,7 +108,7 @@ class PaymentLink extends BaseResource */ public function isPaid(): bool { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 1bcf6cd4a..88b5be756 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -129,7 +129,7 @@ public function update(): ?Profile */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client, 0, null); } @@ -155,7 +155,7 @@ public function chargebacks(): ChargebackCollection */ public function methods(): MethodCollection { - if (!isset($this->_links->methods->href)) { + if (! isset($this->_links->methods->href)) { return new MethodCollection(0, null); } @@ -207,7 +207,7 @@ public function disableMethod($methodId, array $data = []): ?Method */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } @@ -233,7 +233,7 @@ public function payments(): PaymentCollection */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client, 0, null); } diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index 75203c8ac..5e15ec1b5 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -63,7 +63,7 @@ public function hasTracking(): bool */ public function hasTrackingUrl(): bool { - return $this->hasTracking() && !empty($this->tracking->url); + return $this->hasTracking() && ! empty($this->tracking->url); } /** @@ -73,7 +73,7 @@ public function hasTrackingUrl(): bool */ public function getTrackingUrl(): ?string { - if (!$this->hasTrackingUrl()) { + if (! $this->hasTrackingUrl()) { return null; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 4dcc948c0..6d69d88ab 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -187,7 +187,7 @@ public function isCompleted(): bool */ public function cancel(): ?Subscription { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } @@ -220,7 +220,7 @@ public function cancel(): ?Subscription */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client, 0, null); } From 76e46b597cb2131909475564a3a267e1c0334ff9 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 28 Jun 2024 17:23:03 +0200 Subject: [PATCH 020/131] wip --- src/Contracts/EmbeddedResourcesContract.php | 8 ++ src/Endpoints/BalanceEndpoint.php | 8 +- src/Endpoints/BalanceReportEndpoint.php | 6 +- src/Endpoints/BalanceTransactionEndpoint.php | 8 +- src/Endpoints/ChargebackEndpoint.php | 8 +- src/Endpoints/ClientEndpoint.php | 8 +- src/Endpoints/ClientLinkEndpoint.php | 9 +- src/Endpoints/CustomerEndpoint.php | 8 +- src/Endpoints/CustomerPaymentsEndpoint.php | 8 +- src/Endpoints/EndpointCollection.php | 24 ++-- src/Endpoints/InvoiceEndpoint.php | 8 +- src/Endpoints/MandateEndpoint.php | 8 +- src/Endpoints/MethodEndpoint.php | 8 +- src/Endpoints/OnboardingEndpoint.php | 4 +- src/Endpoints/OrderEndpoint.php | 8 +- src/Endpoints/OrderLineEndpoint.php | 12 +- src/Endpoints/OrderPaymentEndpoint.php | 8 +- src/Endpoints/OrderRefundEndpoint.php | 8 +- src/Endpoints/OrderShipmentEndpoint.php | 8 +- src/Endpoints/OrganizationEndpoint.php | 4 +- src/Endpoints/OrganizationPartnerEndpoint.php | 4 +- src/Endpoints/PaymentCaptureEndpoint.php | 8 +- src/Endpoints/PaymentChargebackEndpoint.php | 8 +- src/Endpoints/PaymentEndpoint.php | 22 ++- src/Endpoints/PaymentLinkEndpoint.php | 8 +- src/Endpoints/PaymentRefundEndpoint.php | 8 +- src/Endpoints/PaymentRouteEndpoint.php | 4 +- src/Endpoints/PermissionEndpoint.php | 8 +- src/Endpoints/ProfileEndpoint.php | 8 +- src/Endpoints/ProfileMethodEndpoint.php | 10 +- src/Endpoints/RefundEndpoint.php | 8 +- src/Endpoints/RestEndpoint.php | 15 +-- src/Endpoints/SettlementCaptureEndpoint.php | 8 +- .../SettlementChargebackEndpoint.php | 8 +- src/Endpoints/SettlementPaymentEndpoint.php | 8 +- src/Endpoints/SettlementRefundEndpoint.php | 8 +- src/Endpoints/SettlementsEndpoint.php | 8 +- src/Endpoints/SubscriptionEndpoint.php | 8 +- src/Endpoints/TerminalEndpoint.php | 8 +- src/Http/Response.php | 29 +--- .../DefaultIdempotencyKeyGenerator.php | 5 +- .../FakeIdempotencyKeyGenerator.php | 6 +- .../IdempotencyKeyGeneratorContract.php | 3 +- src/Resources/BalanceCollection.php | 6 +- .../BalanceTransactionCollection.php | 6 +- src/Resources/BaseCollection.php | 35 +++-- src/Resources/CaptureCollection.php | 8 +- src/Resources/ChargebackCollection.php | 8 +- src/Resources/Client.php | 11 +- src/Resources/ClientCollection.php | 8 +- src/Resources/CursorCollection.php | 43 +----- src/Resources/Customer.php | 28 +--- src/Resources/CustomerCollection.php | 8 +- src/Resources/HasPresetOptions.php | 36 +++++ src/Resources/InvoiceCollection.php | 8 +- src/Resources/IssuerCollection.php | 2 +- src/Resources/Mandate.php | 2 +- src/Resources/MandateCollection.php | 8 +- src/Resources/MethodCollection.php | 2 +- src/Resources/MethodPriceCollection.php | 2 +- src/Resources/Order.php | 40 ++---- src/Resources/OrderCollection.php | 8 +- src/Resources/OrderLine.php | 2 +- src/Resources/OrderLineCollection.php | 2 +- src/Resources/Payment.php | 60 ++++----- src/Resources/PaymentCollection.php | 8 +- src/Resources/PaymentLinkCollection.php | 8 +- src/Resources/PermissionCollection.php | 2 +- src/Resources/Profile.php | 16 +-- src/Resources/ProfileCollection.php | 8 +- src/Resources/RefundCollection.php | 8 +- src/Resources/ResourceFactory.php | 126 ++++++++++++++---- src/Resources/SettlementCollection.php | 8 +- src/Resources/ShipmentCollection.php | 2 +- src/Resources/Subscription.php | 8 +- src/Resources/SubscriptionCollection.php | 8 +- src/Resources/TerminalCollection.php | 8 +- .../API/Endpoints/BalanceEndpointTest.php | 2 +- .../BalanceTransactionEndpointTest.php | 2 +- .../API/Endpoints/ChargebackEndpointTest.php | 2 +- .../API/Endpoints/ClientEndpointTest.php | 2 +- .../Endpoints/CustomerPaymentEndpointTest.php | 2 +- ...ustomerSubscriptionPaymentEndpointTest.php | 2 +- .../API/Endpoints/MethodEndpointTest.php | 4 +- .../API/Endpoints/OrderEndpointTest.php | 2 +- .../API/Endpoints/OrderRefundEndpointTest.php | 2 +- .../Endpoints/PaymentCaptureEndpointTest.php | 2 +- .../PaymentChargebackEndpointTest.php | 2 +- .../API/Endpoints/PaymentEndpointTest.php | 2 +- .../Endpoints/PaymentRefundEndpointTest.php | 4 +- .../API/Endpoints/ProfileEndpointTest.php | 2 +- .../API/Endpoints/RefundEndpointTest.php | 2 +- .../Endpoints/SubscriptionEndpointTest.php | 2 +- .../API/Endpoints/TerminalEndpointTest.php | 2 +- .../API/Resources/CursorCollectionTest.php | 14 +- .../API/Resources/MandateCollectionTest.php | 23 ++-- .../API/Resources/OrderLineCollectionTest.php | 9 +- .../API/Resources/ResourceFactoryTest.php | 39 +++++- 98 files changed, 557 insertions(+), 490 deletions(-) create mode 100644 src/Contracts/EmbeddedResourcesContract.php create mode 100644 src/Resources/HasPresetOptions.php diff --git a/src/Contracts/EmbeddedResourcesContract.php b/src/Contracts/EmbeddedResourcesContract.php new file mode 100644 index 000000000..9bc0bc8bf --- /dev/null +++ b/src/Contracts/EmbeddedResourcesContract.php @@ -0,0 +1,8 @@ +client, $count, $_links); + return BalanceCollection::class; } /** * @inheritDoc */ - protected function getResourceObject(): Balance + public static function getResourceClass(): string { - return new Balance($this->client); + return Balance::class; } /** diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index de8602433..dda3798ab 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -15,9 +15,9 @@ class BalanceReportEndpoint extends RestEndpoint /** * @inheritDoc */ - protected function getResourceObject(): BalanceReport + public static function getResourceClass(): string { - return new BalanceReport($this->client); + return BalanceReport::class; } /** @@ -43,7 +43,7 @@ public function getForId(string $balanceId, array $parameters = []): ?BalanceRep } /** @var BalanceReport */ - return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); } /** diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index fd6d321af..24265c49d 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -16,17 +16,17 @@ class BalanceTransactionEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): BalanceTransactionCollection + protected function getResourceCollectionClass(): string { - return new BalanceTransactionCollection($this->client, $count, $_links); + return BalanceTransactionCollection::class; } /** * @inheritDoc */ - protected function getResourceObject(): BalanceTransaction + public static function getResourceClass(): string { - return new BalanceTransaction($this->client); + return BalanceTransaction::class; } /** diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index 71d9502b7..5ed652bf0 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -14,17 +14,17 @@ class ChargebackEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Chargeback + public static function getResourceClass(): string { - return new Chargeback($this->client); + return Chargeback::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection + protected function getResourceCollectionClass(): string { - return new ChargebackCollection($this->client, $count, $_links); + return ChargebackCollection::class; } /** diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index dd7e9651e..3a6d56b2c 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -14,17 +14,17 @@ class ClientEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Client + public static function getResourceClass(): string { - return new Client($this->client); + return Client::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ClientCollection + protected function getResourceCollectionClass(): string { - return new ClientCollection($this->client, $count, $_links); + return ClientCollection::class; } /** diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index 65498b145..a3686e5da 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -10,14 +10,11 @@ class ClientLinkEndpoint extends RestEndpoint protected string $resourcePath = "client-links"; /** - * Get the object that is used by this API endpoint. Every API endpoint uses one - * type of object. - * - * @return ClientLink + * @inheritDoc */ - protected function getResourceObject(): ClientLink + public static function getResourceClass(): string { - return new ClientLink($this->client); + return ClientLink::class; } /** diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index e770f9027..1f58f8304 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -16,17 +16,17 @@ class CustomerEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Customer + public static function getResourceClass(): string { - return new Customer($this->client); + return Customer::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): CustomerCollection + protected function getResourceCollectionClass(): string { - return new CustomerCollection($this->client, $count, $_links); + return CustomerCollection::class; } /** diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index 376fdc7ea..e62382811 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -15,17 +15,17 @@ class CustomerPaymentsEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Payment + public static function getResourceClass(): string { - return new Payment($this->client); + return Payment::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection + protected function getResourceCollectionClass(): string { - return new PaymentCollection($this->client, $count, $_links); + return PaymentCollection::class; } /** diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php index a9052e8ab..55415c816 100644 --- a/src/Endpoints/EndpointCollection.php +++ b/src/Endpoints/EndpointCollection.php @@ -62,23 +62,21 @@ protected function getMergedFilters(array $filters = [], ?string $from = null, ? protected function buildResultCollection(object $result): BaseCollection { - /** @var BaseCollection $collection */ - $collection = $this->getResourceCollectionObject($result->count, $result->_links); + $collectionClass = $this->getResourceCollectionClass(); - foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { - $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject()); - } - - return $collection; + return ResourceFactory::createBaseResourceCollection( + $this->client, + $this->getResourceClass(), + $result->_embedded->{$collectionClass::getCollectionResourceName()}, + $result->_links, + $collectionClass + ); } /** - * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. + * Get the collection class that is used by this API endpoint. Every API endpoint uses one type of collection object. * - * @param int $count - * @param \stdClass $_links - * - * @return BaseCollection + * @return string */ - abstract protected function getResourceCollectionObject(int $count, object $_links): BaseCollection; + abstract protected function getResourceCollectionClass(): string; } diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index 4ce260890..aed5dc804 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -14,17 +14,17 @@ class InvoiceEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Invoice + public static function getResourceClass(): string { - return new Invoice($this->client); + return Invoice::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): InvoiceCollection + protected function getResourceCollectionClass(): string { - return new InvoiceCollection($this->client, $count, $_links); + return InvoiceCollection::class; } /** diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index f3df75936..6ec8a1ef5 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -14,17 +14,17 @@ class MandateEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Mandate + public static function getResourceClass(): string { - return new Mandate($this->client); + return Mandate::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): MandateCollection + protected function getResourceCollectionClass(): string { - return new MandateCollection($this->client, $count, $_links); + return MandateCollection::class; } /** diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 4ada2e2a9..3f5a29b76 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -13,17 +13,17 @@ class MethodEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Method + public static function getResourceClass(): string { - return new Method($this->client); + return Method::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): MethodCollection + protected function getResourceCollectionClass(): string { - return new MethodCollection($count, $_links); + return MethodCollection::class; } /** diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index 557225214..0d6dd9f57 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -13,9 +13,9 @@ class OnboardingEndpoint extends RestEndpoint implements SingleResourceEndpointC /** * @inheritDoc */ - protected function getResourceObject(): Onboarding + public static function getResourceClass(): string { - return new Onboarding($this->client); + return Onboarding::class; } /** diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 8c7a6dac5..cff26a380 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -16,17 +16,17 @@ class OrderEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Order + public static function getResourceClass(): string { - return new Order($this->client); + return Order::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): OrderCollection + protected function getResourceCollectionClass(): string { - return new OrderCollection($this->client, $count, $_links); + return OrderCollection::class; } /** diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 6ee5aec35..b85d5f6ec 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -17,17 +17,17 @@ class OrderLineEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): OrderLine + public static function getResourceClass(): string { - return new OrderLine($this->client); + return OrderLine::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): OrderLineCollection + protected function getResourceCollectionClass(): string { - return new OrderLineCollection($count, $_links); + return OrderLineCollection::class; } /** @@ -59,7 +59,7 @@ public function update(string $orderId, string $orderlineId, array $data = []): } /** @var Order */ - return ResourceFactory::createFromApiResult($response->decode(), new Order($this->client)); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), Order::class); } /** @@ -87,7 +87,7 @@ public function updateMultiple(string $orderId, array $operations, array $parame ); /** @var Order */ - return ResourceFactory::createFromApiResult($result->decode(), new Order($this->client)); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), Order::class); } /** diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index ef56872ca..861f3c9f7 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -13,17 +13,17 @@ class OrderPaymentEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Payment + public static function getResourceClass(): string { - return new Payment($this->client); + return Payment::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection + protected function getResourceCollectionClass(): string { - return new PaymentCollection($this->client, $count, $_links); + return PaymentCollection::class; } /** diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index f080f2afb..7137863d4 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -13,17 +13,17 @@ class OrderRefundEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Refund + public static function getResourceClass(): string { - return new Refund($this->client); + return Refund::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): RefundCollection + protected function getResourceCollectionClass(): string { - return new RefundCollection($this->client, $count, $_links); + return RefundCollection::class; } /** diff --git a/src/Endpoints/OrderShipmentEndpoint.php b/src/Endpoints/OrderShipmentEndpoint.php index 36f2ca52f..863fc530d 100644 --- a/src/Endpoints/OrderShipmentEndpoint.php +++ b/src/Endpoints/OrderShipmentEndpoint.php @@ -16,17 +16,17 @@ class OrderShipmentEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Shipment + public static function getResourceClass(): string { - return new Shipment($this->client); + return Shipment::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ShipmentCollection + protected function getResourceCollectionClass(): string { - return new ShipmentCollection($count, $_links); + return ShipmentCollection::class; } /** diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index 4a1a8b75e..c87e3d4f2 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -12,9 +12,9 @@ class OrganizationEndpoint extends RestEndpoint /** * @inheritDoc */ - protected function getResourceObject(): Organization + public static function getResourceClass(): string { - return new Organization($this->client); + return Organization::class; } /** diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index cc3f90aa5..1cbe72207 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -13,9 +13,9 @@ class OrganizationPartnerEndpoint extends RestEndpoint implements SingleResource /** * @inheritDoc */ - protected function getResourceObject(): Partner + public static function getResourceClass(): string { - return new Partner($this->client); + return Partner::class; } /** diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 8df4a6b67..72643d6fa 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -14,17 +14,17 @@ class PaymentCaptureEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Capture + public static function getResourceClass(): string { - return new Capture($this->client); + return Capture::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): CaptureCollection + protected function getResourceCollectionClass(): string { - return new CaptureCollection($this->client, $count, $_links); + return CaptureCollection::class; } /** diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index f64f0ed56..a23a8b81f 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -14,17 +14,17 @@ class PaymentChargebackEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Chargeback + public static function getResourceClass(): string { - return new Chargeback($this->client); + return Chargeback::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection + protected function getResourceCollectionClass(): string { - return new ChargebackCollection($this->client, $count, $_links); + return ChargebackCollection::class; } /** diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index acd84a13d..235643af4 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -7,6 +7,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; +use Mollie\Api\Resources\ResourceFactory; class PaymentEndpoint extends EndpointCollection { @@ -17,17 +18,17 @@ class PaymentEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Payment + public static function getResourceClass(): string { - return new Payment($this->client); + return Payment::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection + protected function getResourceCollectionClass(): string { - return new PaymentCollection($this->client, $count, $_links); + return PaymentCollection::class; } /** @@ -163,7 +164,16 @@ public function iterator(?string $from = null, ?int $limit = null, array $parame */ public function refund(Payment $payment, $data = []): Refund { - return (new PaymentRefundEndpoint($this->client)) - ->createFor($payment, $data); + $resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds"; + + $body = null; + if (($data === null ? 0 : count($data)) > 0) { + $body = json_encode($data); + } + + $result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body); + + /** @var Refund */ + return ResourceFactory::createFromApiResult($this->client, $result, Refund::class); } } diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index 9bc8fe0ae..8c463cf4f 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -16,17 +16,17 @@ class PaymentLinkEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): PaymentLink + public static function getResourceClass(): string { - return new PaymentLink($this->client); + return PaymentLink::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PaymentLinkCollection + protected function getResourceCollectionClass(): string { - return new PaymentLinkCollection($this->client, $count, $_links); + return PaymentLinkCollection::class; } /** diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 969c84b8c..0ac1d20e9 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -14,17 +14,17 @@ class PaymentRefundEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Refund + public static function getResourceClass(): string { - return new Refund($this->client); + return Refund::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): RefundCollection + protected function getResourceCollectionClass(): string { - return new RefundCollection($this->client, $count, $_links); + return RefundCollection::class; } /** diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index ed4078881..b78cf0319 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -12,9 +12,9 @@ class PaymentRouteEndpoint extends RestEndpoint /** * @inheritDoc */ - protected function getResourceObject(): Route + public static function getResourceClass(): string { - return new Route($this->client); + return Route::class; } /** diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index f7af61305..098cef3a5 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -13,17 +13,17 @@ class PermissionEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Permission + public static function getResourceClass(): string { - return new Permission($this->client); + return Permission::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PermissionCollection + protected function getResourceCollectionClass(): string { - return new PermissionCollection($count, $_links); + return PermissionCollection::class; } /** diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index ff7887cb9..c6e4a9bf9 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -19,17 +19,17 @@ class ProfileEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Profile + public static function getResourceClass(): string { - return new $this->resourceClass($this->client); + return $this->resourceClass; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ProfileCollection + protected function getResourceCollectionClass(): string { - return new ProfileCollection($this->client, $count, $_links); + return ProfileCollection::class; } /** diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index dd3ed3c2c..2c8995e37 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -14,17 +14,17 @@ class ProfileMethodEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Method + public static function getResourceClass(): string { - return new Method($this->client); + return Method::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): MethodCollection + protected function getResourceCollectionClass(): string { - return new MethodCollection($count, $_links); + return MethodCollection::class; } /** @@ -48,7 +48,7 @@ public function createForId(string $profileId, string $methodId, array $data = [ ); /** @var Method */ - return ResourceFactory::createFromApiResult($result->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), $this->getResourceClass()); } /** diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 45a1dc74a..fa7754d18 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -14,17 +14,17 @@ class RefundEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Refund + public static function getResourceClass(): string { - return new Refund($this->client); + return Refund::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): RefundCollection + protected function getResourceCollectionClass(): string { - return new RefundCollection($this->client, $count, $_links); + return RefundCollection::class; } /** diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index 8ce5da49c..2dac8cd99 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -32,7 +32,7 @@ protected function createResource(array $body, array $filters): BaseResource $this->parseRequestBody($body) ); - return ResourceFactory::createFromApiResult($result->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), $this->getResourceClass()); } /** @@ -58,7 +58,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource return null; } - return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); } /** @@ -81,7 +81,7 @@ protected function readResource(string $id, array $filters): BaseResource $this->getPathToSingleResource($id) . $this->buildQueryString($filters) ); - return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); } /** @@ -110,7 +110,7 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource return null; } - return ResourceFactory::createFromApiResult($response->decode(), $this->getResourceObject()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); } protected function guardAgainstInvalidId(string $id): void @@ -128,8 +128,7 @@ protected function guardAgainstInvalidId(string $id): void public function getResourceType(): string { - $resourceClass = $this->getResourceObject()::class; - $classBasename = basename(str_replace("\\", "/", $resourceClass)); + $classBasename = basename(str_replace("\\", "/", $this->getResourceClass())); return strtolower($classBasename); } @@ -137,7 +136,7 @@ public function getResourceType(): string /** * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. * - * @return BaseResource + * @return string */ - abstract protected function getResourceObject(): BaseResource; + abstract public static function getResourceClass(): string; } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 15a3b04dd..2618e0776 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -15,17 +15,17 @@ class SettlementCaptureEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Capture + public static function getResourceClass(): string { - return new Capture($this->client); + return Capture::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): CaptureCollection + protected function getResourceCollectionClass(): string { - return new CaptureCollection($this->client, $count, $_links); + return CaptureCollection::class; } /** diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 860aae3de..9c87f59c1 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -15,17 +15,17 @@ class SettlementChargebackEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Chargeback + public static function getResourceClass(): string { - return new Chargeback($this->client); + return Chargeback::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): ChargebackCollection + protected function getResourceCollectionClass(): string { - return new ChargebackCollection($this->client, $count, $_links); + return ChargebackCollection::class; } /** diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index f9eeeae77..81d1c4352 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -13,17 +13,17 @@ class SettlementPaymentEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Payment + public static function getResourceClass(): string { - return new Payment($this->client); + return Payment::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): PaymentCollection + protected function getResourceCollectionClass(): string { - return new PaymentCollection($this->client, $count, $_links); + return PaymentCollection::class; } /** diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 53f683231..f7196ee94 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -15,17 +15,17 @@ class SettlementRefundEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Refund + public static function getResourceClass(): string { - return new Refund($this->client); + return Refund::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): RefundCollection + protected function getResourceCollectionClass(): string { - return new RefundCollection($this->client, $count, $_links); + return RefundCollection::class; } /** diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index e7a08bc59..341ed39ea 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -14,17 +14,17 @@ class SettlementsEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Settlement + public static function getResourceClass(): string { - return new Settlement($this->client); + return Settlement::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): SettlementCollection + protected function getResourceCollectionClass(): string { - return new SettlementCollection($this->client, $count, $_links); + return SettlementCollection::class; } /** diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 31a822b2a..c0fd9b98a 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -17,17 +17,17 @@ class SubscriptionEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Subscription + public static function getResourceClass(): string { - return new Subscription($this->client); + return Subscription::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): SubscriptionCollection + protected function getResourceCollectionClass(): string { - return new SubscriptionCollection($this->client, $count, $_links); + return SubscriptionCollection::class; } /** diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 5f1aa0e54..d86f3a3e4 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -16,17 +16,17 @@ class TerminalEndpoint extends EndpointCollection /** * @inheritDoc */ - protected function getResourceObject(): Terminal + public static function getResourceClass(): string { - return new Terminal($this->client); + return Terminal::class; } /** * @inheritDoc */ - protected function getResourceCollectionObject(int $count, object $_links): TerminalCollection + protected function getResourceCollectionClass(): string { - return new TerminalCollection($this->client, $count, $_links); + return TerminalCollection::class; } /** diff --git a/src/Http/Response.php b/src/Http/Response.php index b3be4d5c6..b38bd016e 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -24,11 +24,6 @@ class Response implements ResponseContract */ protected ?\stdClass $decoded = null; - /** - * HTTP status code for an empty ok response. - */ - public const HTTP_NO_CONTENT = 204; - public function __construct( int $statusCode = 200, array $headers = [], @@ -62,7 +57,7 @@ public function decode(): \stdClass return (object)[]; } - if (! $this->decoded) { + if (!$this->decoded) { $this->decoded = @json_decode($body); if (json_last_error() !== JSON_ERROR_NONE) { @@ -91,26 +86,4 @@ public function getReasonPhrase(): string return $this->reasonPhrase; } - - public function getHeaders(): array - { - return $this->headers; - } - - public function hasHeader(string $name): bool - { - return isset($this->headers[$name]); - } - - public function getHeader(string $name): array - { - return $this->hasHeader($name) - ? $this->headers[$name] - : []; - } - - public function getHeaderLine(string $name): string - { - return implode(', ', $this->getHeader($name)); - } } diff --git a/src/Idempotency/DefaultIdempotencyKeyGenerator.php b/src/Idempotency/DefaultIdempotencyKeyGenerator.php index 190d0bfc3..0aa49212c 100644 --- a/src/Idempotency/DefaultIdempotencyKeyGenerator.php +++ b/src/Idempotency/DefaultIdempotencyKeyGenerator.php @@ -1,4 +1,5 @@ length; diff --git a/src/Idempotency/FakeIdempotencyKeyGenerator.php b/src/Idempotency/FakeIdempotencyKeyGenerator.php index 95871939f..92e638a40 100644 --- a/src/Idempotency/FakeIdempotencyKeyGenerator.php +++ b/src/Idempotency/FakeIdempotencyKeyGenerator.php @@ -7,14 +7,14 @@ class FakeIdempotencyKeyGenerator implements IdempotencyKeyGeneratorContract { /** @var string */ - private $fakeKey; + private string $fakeKey; - public function setFakeKey($fakeKey) + public function setFakeKey($fakeKey): void { $this->fakeKey = $fakeKey; } - public function generate() + public function generate(): string { return $this->fakeKey; } diff --git a/src/Idempotency/IdempotencyKeyGeneratorContract.php b/src/Idempotency/IdempotencyKeyGeneratorContract.php index 6ffe80ca6..80d3ffd6a 100644 --- a/src/Idempotency/IdempotencyKeyGeneratorContract.php +++ b/src/Idempotency/IdempotencyKeyGeneratorContract.php @@ -1,7 +1,8 @@ client); + return Balance::class; } } diff --git a/src/Resources/BalanceTransactionCollection.php b/src/Resources/BalanceTransactionCollection.php index 923b12c70..1b734621d 100644 --- a/src/Resources/BalanceTransactionCollection.php +++ b/src/Resources/BalanceTransactionCollection.php @@ -9,7 +9,7 @@ class BalanceTransactionCollection extends CursorCollection /** * @inheritDoc */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "balance_transactions"; } @@ -17,8 +17,8 @@ public function getCollectionResourceName(): string /** * @inheritDoc */ - protected function createResourceObject(): BalanceTransaction + public static function getResourceClass(): string { - return new BalanceTransaction($this->client); + return BalanceTransaction::class; } } diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 2f07e278b..441bdb65b 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -2,34 +2,30 @@ namespace Mollie\Api\Resources; +use Mollie\Api\MollieApiClient; + abstract class BaseCollection extends \ArrayObject { - /** - * Total number of retrieved objects. - * - * @var int - */ - public int $count; + protected MollieApiClient $client; /** * @var \stdClass|null */ - public ?\stdClass $_links; + public ?\stdClass $_links = null; /** - * @param int $count + * @param MollieApiClient $client + * @param array|object $items * @param \stdClass|null $_links */ - public function __construct(int $count, ?\stdClass $_links) + public function __construct(MollieApiClient $client, $items = [], ?\stdClass $_links = null) { - $this->count = $count; - $this->_links = $_links; + parent::__construct($items); - parent::__construct(); + $this->_links = $_links; + $this->client = $client; } - abstract public function getCollectionResourceName(): ?string; - public function contains(callable $callback): bool { foreach ($this as $item) { @@ -40,4 +36,15 @@ public function contains(callable $callback): bool return false; } + + public function filter(callable $callback): static + { + $filteredItems = array_filter($this->getArrayCopy(), $callback); + + /** @phpstan-ignore-next-line */ + return new static($this->client, $filteredItems, $this->_links); + } + + + abstract public static function getCollectionResourceName(): ?string; } diff --git a/src/Resources/CaptureCollection.php b/src/Resources/CaptureCollection.php index 55e270a9b..ab2179d74 100644 --- a/src/Resources/CaptureCollection.php +++ b/src/Resources/CaptureCollection.php @@ -7,16 +7,16 @@ class CaptureCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "captures"; } /** - * @return Capture + * @return string */ - protected function createResourceObject(): Capture + public static function getResourceClass(): string { - return new Capture($this->client); + return Capture::class; } } diff --git a/src/Resources/ChargebackCollection.php b/src/Resources/ChargebackCollection.php index 7f802df67..579a77807 100644 --- a/src/Resources/ChargebackCollection.php +++ b/src/Resources/ChargebackCollection.php @@ -7,16 +7,16 @@ class ChargebackCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "chargebacks"; } /** - * @return Chargeback + * @return string */ - protected function createResourceObject(): Chargeback + public static function getResourceClass(): string { - return new Chargeback($this->client); + return Chargeback::class; } } diff --git a/src/Resources/Client.php b/src/Resources/Client.php index ed226421b..4559e7bf5 100644 --- a/src/Resources/Client.php +++ b/src/Resources/Client.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Resources; -class Client extends BaseResource +use Mollie\Api\Contracts\EmbeddedResourcesContract; + +class Client extends BaseResource implements EmbeddedResourcesContract { /** * The unique identifier of the client, which corresponds to the ID of the organization @@ -33,4 +35,11 @@ class Client extends BaseResource * @var \stdClass|null */ public $commission; + + public function getEmbeddedResourcesMap(): array + { + return [ + // test if is correct as it's no collection + ] + } } diff --git a/src/Resources/ClientCollection.php b/src/Resources/ClientCollection.php index 49657c828..68e8165e7 100644 --- a/src/Resources/ClientCollection.php +++ b/src/Resources/ClientCollection.php @@ -7,16 +7,16 @@ class ClientCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "clients"; } /** - * @return Client + * @return string */ - protected function createResourceObject(): Client + public static function getResourceClass(): string { - return new Client($this->client); + return Client::class; } } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 597f495c9..67f7d522d 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -9,21 +9,7 @@ abstract class CursorCollection extends BaseCollection { - protected MollieApiClient $client; - - /** - * @param MollieApiClient $client - * @param int $count - * @param \stdClass|null $_links - */ - final public function __construct(MollieApiClient $client, int $count, ?\stdClass $_links) - { - parent::__construct($count, $_links); - - $this->client = $client; - } - - abstract protected function createResourceObject(): BaseResource; + abstract public static function getResourceClass(): string; /** * Return the next set of resources when available @@ -67,13 +53,12 @@ private function fetchCollection(string $url): CursorCollection $data = $response->decode(); - $collection = new static($this->client, $data->count, $data->_links); - - foreach ($data->_embedded->{$collection->getCollectionResourceName()} as $dataResult) { - $collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject()); - } - - return $collection; + return ResourceFactory::createCursorResourceCollection( + $this->client, + $data->_embedded->{$this->getCollectionResourceName()}, + static::getResourceClass(), + $data->_links + ); } /** @@ -123,18 +108,4 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection } }); } - - public function filter(callable $callback): static - { - $collection = new static($this->client, 0, $this->_links); - - foreach ($this as $item) { - if ($callback($item)) { - $collection[] = $item; - $collection->count++; - } - } - - return $collection; - } } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index aa62879c0..46a797e79 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -6,6 +6,8 @@ class Customer extends BaseResource { + use HasPresetOptions; + /** * Id of the customer. * @@ -208,30 +210,4 @@ public function hasValidMandateForMethod($method): bool return $this->mandates() ->contains(fn (Mandate $mandate) => $mandate->isValid() && $mandate->method === $method); } - - /** - * When accessed by oAuth we want to pass the testmode by default - * - * @return array - */ - private function getPresetOptions(): array - { - $options = []; - if ($this->client->usesOAuth()) { - $options["testmode"] = $this->mode === "test" ? true : false; - } - - return $options; - } - - /** - * Apply the preset options. - * - * @param array $options - * @return array - */ - private function withPresetOptions(array $options): array - { - return array_merge($this->getPresetOptions(), $options); - } } diff --git a/src/Resources/CustomerCollection.php b/src/Resources/CustomerCollection.php index 5ffabdd93..8204a2594 100644 --- a/src/Resources/CustomerCollection.php +++ b/src/Resources/CustomerCollection.php @@ -7,16 +7,16 @@ class CustomerCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "customers"; } /** - * @return Customer + * @return string */ - protected function createResourceObject(): Customer + public static function getResourceClass(): string { - return new Customer($this->client); + return Customer::class; } } diff --git a/src/Resources/HasPresetOptions.php b/src/Resources/HasPresetOptions.php new file mode 100644 index 000000000..546b54b29 --- /dev/null +++ b/src/Resources/HasPresetOptions.php @@ -0,0 +1,36 @@ +client->usesOAuth()) { + $options["testmode"] = $this->mode === "test" ? true : false; + } + + return $options; + } + + /** + * Apply the preset options. + * + * @param array $options + * @return array + */ + protected function withPresetOptions(array $options): array + { + return array_merge($this->getPresetOptions(), $options); + } +} diff --git a/src/Resources/InvoiceCollection.php b/src/Resources/InvoiceCollection.php index bf0a358c5..20d3c2148 100644 --- a/src/Resources/InvoiceCollection.php +++ b/src/Resources/InvoiceCollection.php @@ -7,16 +7,16 @@ class InvoiceCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "invoices"; } /** - * @return Invoice + * @return string */ - protected function createResourceObject(): Invoice + public static function getResourceClass(): string { - return new Invoice($this->client); + return Invoice::class; } } diff --git a/src/Resources/IssuerCollection.php b/src/Resources/IssuerCollection.php index 338896795..19f7ff9c9 100644 --- a/src/Resources/IssuerCollection.php +++ b/src/Resources/IssuerCollection.php @@ -7,7 +7,7 @@ class IssuerCollection extends BaseCollection /** * @return null */ - public function getCollectionResourceName(): null + public static function getCollectionResourceName(): null { return null; } diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index 1824a07c6..efd4582d4 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -110,6 +110,6 @@ public function revoke(): ?Mandate /** @var null|Mandate */ return $result->isEmpty() ? null - : ResourceFactory::createFromApiResult($result->decode(), new self($this->client)); + : ResourceFactory::createFromApiResult($this->client, $result->decode(), self::class); } } diff --git a/src/Resources/MandateCollection.php b/src/Resources/MandateCollection.php index e362a17aa..3a351600c 100644 --- a/src/Resources/MandateCollection.php +++ b/src/Resources/MandateCollection.php @@ -7,17 +7,17 @@ class MandateCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "mandates"; } /** - * @return Mandate + * @return string */ - protected function createResourceObject(): Mandate + public static function getResourceClass(): string { - return new Mandate($this->client); + return Mandate::class; } /** diff --git a/src/Resources/MethodCollection.php b/src/Resources/MethodCollection.php index 78cb3e9cd..b2c294fd2 100644 --- a/src/Resources/MethodCollection.php +++ b/src/Resources/MethodCollection.php @@ -7,7 +7,7 @@ class MethodCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "methods"; } diff --git a/src/Resources/MethodPriceCollection.php b/src/Resources/MethodPriceCollection.php index 93dcac557..6726b14de 100644 --- a/src/Resources/MethodPriceCollection.php +++ b/src/Resources/MethodPriceCollection.php @@ -7,7 +7,7 @@ class MethodPriceCollection extends BaseCollection /** * @return null */ - public function getCollectionResourceName(): null + public static function getCollectionResourceName(): null { return null; } diff --git a/src/Resources/Order.php b/src/Resources/Order.php index a1bcb251c..a3225825c 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -2,11 +2,14 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Types\OrderStatus; -class Order extends BaseResource +class Order extends BaseResource implements EmbeddedResourcesContract { + use HasPresetOptions; + /** * Id of the order. * @@ -221,6 +224,15 @@ class Order extends BaseResource */ public $_embedded; + public function getEmbeddedResourcesMap(): array + { + return [ + 'payments' => PaymentCollection::class, + 'refunds' => RefundCollection::class, + 'shipments' => ShipmentCollection::class, + ]; + } + /** * Is this order created? * @@ -519,30 +531,4 @@ public function payments(): ?PaymentCollection Payment::class ); } - - /** - * When accessed by oAuth we want to pass the testmode by default - * - * @return array - */ - private function getPresetOptions(): array - { - $options = []; - if ($this->client->usesOAuth()) { - $options["testmode"] = $this->mode === "test" ? true : false; - } - - return $options; - } - - /** - * Apply the preset options. - * - * @param array $options - * @return array - */ - private function withPresetOptions(array $options): array - { - return array_merge($this->getPresetOptions(), $options); - } } diff --git a/src/Resources/OrderCollection.php b/src/Resources/OrderCollection.php index 3733669af..986e183ad 100644 --- a/src/Resources/OrderCollection.php +++ b/src/Resources/OrderCollection.php @@ -7,16 +7,16 @@ class OrderCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "orders"; } /** - * @return Order + * @return string */ - protected function createResourceObject(): Order + public static function getResourceClass(): string { - return new Order($this->client); + return Order::class; } } diff --git a/src/Resources/OrderLine.php b/src/Resources/OrderLine.php index 13a727aaa..b8da61009 100644 --- a/src/Resources/OrderLine.php +++ b/src/Resources/OrderLine.php @@ -379,7 +379,7 @@ public function update(): ?Order $result = $this->client->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); /** @var Order */ - return ResourceFactory::createFromApiResult($result, new Order($this->client)); + return ResourceFactory::createFromApiResult($this->client, $result, Order::class); } /** diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php index 749ad0bfe..9c2b3090a 100644 --- a/src/Resources/OrderLineCollection.php +++ b/src/Resources/OrderLineCollection.php @@ -7,7 +7,7 @@ class OrderLineCollection extends BaseCollection /** * @return null */ - public function getCollectionResourceName(): null + public static function getCollectionResourceName(): null { return null; } diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 441199a96..62dd15054 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -2,13 +2,16 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; -class Payment extends BaseResource +class Payment extends BaseResource implements EmbeddedResourcesContract { + use HasPresetOptions; + /** * Id of the payment (on the Mollie platform). * @@ -376,6 +379,15 @@ class Payment extends BaseResource */ public $countryCode; + public function getEmbeddedResourcesMap(): array + { + return [ + 'captures' => CaptureCollection::class, + 'refunds' => RefundCollection::class, + 'chargebacks' => ChargebackCollection::class, + ]; + } + /** * Is this payment canceled? * @@ -433,7 +445,7 @@ public function isAuthorized(): bool */ public function isPaid(): bool { - return ! empty($this->paidAt); + return !empty($this->paidAt); } /** @@ -443,7 +455,7 @@ public function isPaid(): bool */ public function hasRefunds(): bool { - return ! empty($this->_links->refunds); + return !empty($this->_links->refunds); } /** @@ -453,7 +465,7 @@ public function hasRefunds(): bool */ public function hasChargebacks(): bool { - return ! empty($this->_links->chargebacks); + return !empty($this->_links->chargebacks); } /** @@ -586,7 +598,7 @@ public function getAmountChargedBack(): float */ public function hasSplitPayments(): bool { - return ! empty($this->routing); + return !empty($this->routing); } /** @@ -597,8 +609,8 @@ public function hasSplitPayments(): bool */ public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->client, 0, null); + if (!isset($this->_links->refunds->href)) { + return new RefundCollection($this->client); } $result = $this->client->performHttpCallToFullUrl( @@ -652,8 +664,8 @@ public function listRefunds(array $parameters = []): RefundCollection */ public function captures(): CaptureCollection { - if (! isset($this->_links->captures->href)) { - return new CaptureCollection($this->client, 0, null); + if (!isset($this->_links->captures->href)) { + return new CaptureCollection($this->client); } $result = $this->client->performHttpCallToFullUrl( @@ -694,8 +706,8 @@ public function getCapture($captureId, array $parameters = []): Capture */ public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->client, 0, null); + if (!isset($this->_links->chargebacks->href)) { + return new ChargebackCollection($this->client); } $result = $this->client->performHttpCallToFullUrl( @@ -767,32 +779,6 @@ public function update(): ?Payment ); } - /** - * When accessed by oAuth we want to pass the testmode by default - * - * @return array - */ - private function getPresetOptions(): array - { - $options = []; - if ($this->client->usesOAuth()) { - $options["testmode"] = $this->mode === "test" ? true : false; - } - - return $options; - } - - /** - * Apply the preset options. - * - * @param array $options - * @return array - */ - private function withPresetOptions(array $options): array - { - return array_merge($this->getPresetOptions(), $options); - } - /** * The total amount that is already captured for this payment. Only available * when this payment supports captures. diff --git a/src/Resources/PaymentCollection.php b/src/Resources/PaymentCollection.php index 4b968169b..5109e3b4b 100644 --- a/src/Resources/PaymentCollection.php +++ b/src/Resources/PaymentCollection.php @@ -7,16 +7,16 @@ class PaymentCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "payments"; } /** - * @return Payment + * @return string */ - protected function createResourceObject(): Payment + public static function getResourceClass(): string { - return new Payment($this->client); + return Payment::class; } } diff --git a/src/Resources/PaymentLinkCollection.php b/src/Resources/PaymentLinkCollection.php index 0e6a41df6..598457bd1 100644 --- a/src/Resources/PaymentLinkCollection.php +++ b/src/Resources/PaymentLinkCollection.php @@ -7,16 +7,16 @@ class PaymentLinkCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "payment_links"; } /** - * @return PaymentLink + * @return string */ - protected function createResourceObject(): PaymentLink + public static function getResourceClass(): string { - return new PaymentLink($this->client); + return PaymentLink::class; } } diff --git a/src/Resources/PermissionCollection.php b/src/Resources/PermissionCollection.php index d99da739c..78aa24b87 100644 --- a/src/Resources/PermissionCollection.php +++ b/src/Resources/PermissionCollection.php @@ -7,7 +7,7 @@ class PermissionCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "permissions"; } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 88b5be756..731454ae5 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -129,8 +129,8 @@ public function update(): ?Profile */ public function chargebacks(): ChargebackCollection { - if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->client, 0, null); + if (!isset($this->_links->chargebacks->href)) { + return new ChargebackCollection($this->client); } $result = $this @@ -155,8 +155,8 @@ public function chargebacks(): ChargebackCollection */ public function methods(): MethodCollection { - if (! isset($this->_links->methods->href)) { - return new MethodCollection(0, null); + if (!isset($this->_links->methods->href)) { + return new MethodCollection($this->client); } $result = $this @@ -207,8 +207,8 @@ public function disableMethod($methodId, array $data = []): ?Method */ public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->client, 0, null); + if (!isset($this->_links->payments->href)) { + return new PaymentCollection($this->client); } $result = $this @@ -233,8 +233,8 @@ public function payments(): PaymentCollection */ public function refunds(): RefundCollection { - if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->client, 0, null); + if (!isset($this->_links->refunds->href)) { + return new RefundCollection($this->client); } $result = $this diff --git a/src/Resources/ProfileCollection.php b/src/Resources/ProfileCollection.php index fcf3d05bc..969aaccfe 100644 --- a/src/Resources/ProfileCollection.php +++ b/src/Resources/ProfileCollection.php @@ -7,16 +7,16 @@ class ProfileCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "profiles"; } /** - * @return Profile + * @return string */ - protected function createResourceObject(): Profile + public static function getResourceClass(): string { - return new Profile($this->client); + return Profile::class; } } diff --git a/src/Resources/RefundCollection.php b/src/Resources/RefundCollection.php index 73b711ff5..df27ce026 100644 --- a/src/Resources/RefundCollection.php +++ b/src/Resources/RefundCollection.php @@ -7,16 +7,16 @@ class RefundCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "refunds"; } /** - * @return Refund + * @return string */ - protected function createResourceObject(): Refund + public static function getResourceClass(): string { - return new Refund($this->client); + return Refund::class; } } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index f997bffce..63ee9e357 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] @@ -10,49 +11,87 @@ class ResourceFactory /** * Create resource object from Api result * + * @param MollieApiClient $client * @param object $response - * @param BaseResource $resource + * @param string $resourceClass * @return BaseResource */ - public static function createFromApiResult(object $response, BaseResource $resource): BaseResource + public static function createFromApiResult(MollieApiClient $client, object $response, string $resourceClass): BaseResource { + /** @var BaseResource $resource */ + $resource = new $resourceClass($client); + foreach ($response as $property => $value) { - $resource->{$property} = $value; + if ($property === '_embedded' && $resource instanceof EmbeddedResourcesContract) { + $resource->_embedded = new \stdClass(); + + foreach ($value as $embeddedResourceName => $embeddedResourceData) { + $resource->_embedded->{$embeddedResourceName} = self::createEmbeddedCollection( + $client, + $resource, + $embeddedResourceName, + $embeddedResourceData + ); + } + } else { + $resource->{$property} = $value; + } } return $resource; } + /** + * @param MollieApiClient $client + * @param $data + * @return BaseCollection + */ + private static function createEmbeddedCollection( + MollieApiClient $client, + EmbeddedResourcesContract $resource, + string $collectionKey, + $data + ): BaseCollection { + $collectionClass = $resource->getEmbeddedResourcesMap()[$collectionKey] ?? BaseCollection::class; + + return self::instantiateBaseCollection( + $client, + $collectionClass, + self::mapToResourceObjects( + $client, + $data, + $collectionClass::getResourceClass() + ), + null + ); + } + /** * @param MollieApiClient $client * @param string $resourceClass - * @param array $data - * @param null $_links - * @param string $resourceCollectionClass + * @param null|array|\ArrayObject $data + * @param object|null $_links + * @param string|null $resourceCollectionClass * @return BaseCollection */ public static function createBaseResourceCollection( MollieApiClient $client, string $resourceClass, - ?array $data = null, + $data = null, ?object $_links = null, ?string $resourceCollectionClass = null ): BaseCollection { - $resourceCollectionClass = $resourceCollectionClass ?: $resourceClass . 'Collection'; - $data = $data ?: []; - - /** @var BaseCollection $result */ - $result = new $resourceCollectionClass(count($data), $_links); - foreach ($data as $item) { - $result[] = static::createFromApiResult($item, new $resourceClass($client)); - } - - return $result; + return self::instantiateBaseCollection( + $client, + self::determineCollectionClass($resourceClass, $resourceCollectionClass), + self::mapToResourceObjects($client, $data ?? [], $resourceClass), + $_links + ); } /** * @param MollieApiClient $client - * @param array $input + * @param array|\ArrayObject $data * @param string $resourceClass * @param null $_links * @param null $resourceCollectionClass @@ -60,21 +99,52 @@ public static function createBaseResourceCollection( */ public static function createCursorResourceCollection( MollieApiClient $client, - array $input, + $data, string $resourceClass, ?object $_links = null, ?string $resourceCollectionClass = null ): CursorCollection { - if (null === $resourceCollectionClass) { - $resourceCollectionClass = $resourceClass . 'Collection'; - } + /** @var CursorCollection */ + return self::createBaseResourceCollection( + $client, + $resourceClass, + $data, + $_links, + $resourceCollectionClass + ); + } - /** @var CursorCollection $data */ - $data = new $resourceCollectionClass($client, count($input), $_links); - foreach ($input as $item) { - $data[] = static::createFromApiResult($item, new $resourceClass($client)); - } + /** + * @param string $collectionClass + * @param array $items + * @param object|null $_links + * @return BaseCollection + */ + private static function instantiateBaseCollection(MollieApiClient $client, string $collectionClass, array $items, ?object $_links): BaseCollection + { + return new $collectionClass($client, $items, $_links); + } - return $data; + /** + * @param MollieApiClient $client + * @param array|\ArrayObject $data + * @param string $resourceClass + * @return array + */ + private static function mapToResourceObjects(MollieApiClient $client, $data, string $resourceClass): array + { + return array_map( + fn (\stdClass $item) => static::createFromApiResult( + $client, + $item, + $resourceClass + ), + (array) $data + ); + } + + private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string + { + return $resourceCollectionClass ?: $resourceClass . 'Collection'; } } diff --git a/src/Resources/SettlementCollection.php b/src/Resources/SettlementCollection.php index f69ded6a6..21367a1d4 100644 --- a/src/Resources/SettlementCollection.php +++ b/src/Resources/SettlementCollection.php @@ -7,16 +7,16 @@ class SettlementCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "settlements"; } /** - * @return Settlement + * @return string */ - protected function createResourceObject(): Settlement + public static function getResourceClass(): string { - return new Settlement($this->client); + return Settlement::class; } } diff --git a/src/Resources/ShipmentCollection.php b/src/Resources/ShipmentCollection.php index b8b8bb776..d2c52c52d 100644 --- a/src/Resources/ShipmentCollection.php +++ b/src/Resources/ShipmentCollection.php @@ -7,7 +7,7 @@ class ShipmentCollection extends BaseCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return 'shipments'; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 6d69d88ab..e678b97a6 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -187,7 +187,7 @@ public function isCompleted(): bool */ public function cancel(): ?Subscription { - if (! isset($this->_links->self->href)) { + if (!isset($this->_links->self->href)) { return $this; } @@ -209,7 +209,7 @@ public function cancel(): ?Subscription } /** @var Subscription */ - return ResourceFactory::createFromApiResult($result->decode(), new Subscription($this->client)); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), Subscription::class); } /** @@ -220,8 +220,8 @@ public function cancel(): ?Subscription */ public function payments(): PaymentCollection { - if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->client, 0, null); + if (!isset($this->_links->payments->href)) { + return new PaymentCollection($this->client); } $result = $this->client->performHttpCallToFullUrl( diff --git a/src/Resources/SubscriptionCollection.php b/src/Resources/SubscriptionCollection.php index b020b77eb..d4288d6f9 100644 --- a/src/Resources/SubscriptionCollection.php +++ b/src/Resources/SubscriptionCollection.php @@ -7,16 +7,16 @@ class SubscriptionCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "subscriptions"; } /** - * @return Subscription + * @return string */ - protected function createResourceObject(): Subscription + public static function getResourceClass(): string { - return new Subscription($this->client); + return Subscription::class; } } diff --git a/src/Resources/TerminalCollection.php b/src/Resources/TerminalCollection.php index 1640178dd..ad198fca4 100644 --- a/src/Resources/TerminalCollection.php +++ b/src/Resources/TerminalCollection.php @@ -7,16 +7,16 @@ class TerminalCollection extends CursorCollection /** * @return string */ - public function getCollectionResourceName(): string + public static function getCollectionResourceName(): string { return "terminals"; } /** - * @return Terminal + * @return string */ - protected function createResourceObject(): Terminal + public static function getResourceClass(): string { - return new Terminal($this->client); + return Terminal::class; } } diff --git a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php index c2b14129b..0a987c5aa 100644 --- a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php @@ -132,7 +132,7 @@ public function testListBalances() $balances = $this->apiClient->balances->page(); $this->assertInstanceOf(BalanceCollection::class, $balances); - $this->assertEquals(2, $balances->count); + $this->assertEquals(2, $balances->count()); $this->assertCount(2, $balances); $this->assertLinkObject( diff --git a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php index 55237ae85..1e4034590 100644 --- a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php @@ -336,7 +336,7 @@ private function assertTransactions(BaseCollection $transactions) { $this->assertInstanceOf(BalanceTransactionCollection::class, $transactions); $this->assertCount(2, $transactions); - $this->assertEquals(2, $transactions->count); + $this->assertEquals(2, $transactions->count()); $this->assertLinkObject( "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", "application/hal+json", diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index 44fb3b568..2aded943d 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -110,7 +110,7 @@ public function testListChargebacks() $chargebacks = $this->apiClient->chargebacks->page(); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals(2, $chargebacks->count); + $this->assertEquals(2, $chargebacks->count()); $this->assertCount(2, $chargebacks); $this->assertLinkObject( diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php index 4aaff5539..bdf9ae393 100644 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientEndpointTest.php @@ -122,7 +122,7 @@ public function testGetClientsPage() $clients = $this->apiClient->clients->page(); $this->assertInstanceOf(ClientCollection::class, $clients); - $this->assertEquals(1, $clients->count); + $this->assertEquals(1, $clients->count()); $this->assertCount(1, $clients); $client = $clients[0]; diff --git a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php index f0e31a3c2..7dc563c07 100644 --- a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php @@ -277,7 +277,7 @@ public function testListCustomerPayments() $payments = $customer->payments(); $this->assertInstanceOf(PaymentCollection::class, $payments); - $this->assertEquals(3, $payments->count); + $this->assertEquals(3, $payments->count()); $this->assertEquals(3, count($payments)); $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", "type" => "text/html"]; diff --git a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php index 902044d0f..1737ccf4b 100644 --- a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php @@ -106,7 +106,7 @@ public function testListWorks() $result = $subscription->payments(); $this->assertInstanceOf(PaymentCollection::class, $result); - $this->assertEquals(1, $result->count); + $this->assertEquals(1, $result->count()); $this->assertEquals('Some subscription 19 sep. 2018', $result[0]->description); } } diff --git a/tests/Mollie/API/Endpoints/MethodEndpointTest.php b/tests/Mollie/API/Endpoints/MethodEndpointTest.php index b26ab8898..6cca99c96 100644 --- a/tests/Mollie/API/Endpoints/MethodEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodEndpointTest.php @@ -449,7 +449,7 @@ public function testListAllActiveMethods() $methods = $this->apiClient->methods->allActive(); $this->assertInstanceOf(MethodCollection::class, $methods); - $this->assertEquals(4, $methods->count); + $this->assertEquals(4, $methods->count()); $this->assertCount(4, $methods); $documentationLink = (object)[ @@ -610,7 +610,7 @@ public function testListAllAvailableMethods() $methods = $this->apiClient->methods->allAvailable(['include' => 'pricing']); $this->assertInstanceOf(MethodCollection::class, $methods); - $this->assertEquals(4, $methods->count); + $this->assertEquals(4, $methods->count()); $this->assertCount(4, $methods); $this->assertLinkObject( diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index b1a2b5674..0caed434f 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -542,7 +542,7 @@ public function testListOrders() $orders = $this->apiClient->orders->page(); $this->assertInstanceOf(OrderCollection::class, $orders); - $this->assertEquals(3, $orders->count); + $this->assertEquals(3, $orders->count()); $this->assertEquals(3, count($orders)); $this->assertNull($orders->_links->previous); diff --git a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php index 1ac3c40a7..9a261416f 100644 --- a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php @@ -182,7 +182,7 @@ public function testListOrderRefunds() $refunds = $order->refunds(); $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count); + $this->assertEquals(1, $refunds->count()); $this->assertCount(1, $refunds); $this->assertOrderRefund($refunds[0], 're_4qqhO89gsT'); diff --git a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php index ce41a62eb..acdb1162d 100644 --- a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php @@ -118,7 +118,7 @@ public function testListCapturesOnPaymentResource() $captures = $this->getPayment('tr_WDqYK6vllg')->captures(); - $this->assertEquals(1, $captures->count); + $this->assertEquals(1, $captures->count()); $this->assertLinkObject( 'https://docs.mollie.com/reference/v2/captures-api/list-captures', diff --git a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php index b1d71199d..904df9f69 100644 --- a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php @@ -104,7 +104,7 @@ public function testListChargebacksOnPaymentResource() $chargebacks = $this->getPayment()->chargebacks(); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals(2, $chargebacks->count); + $this->assertEquals(2, $chargebacks->count()); $this->assertCount(2, $chargebacks); $this->assertLinkObject( diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index 344f1b922..a539b58ff 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -478,7 +478,7 @@ public function testListPayment() $payments = $this->apiClient->payments->page(null, 3); $this->assertInstanceOf(PaymentCollection::class, $payments); - $this->assertEquals(3, $payments->count); + $this->assertEquals(3, $payments->count()); $this->assertEquals(3, count($payments)); $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/list-payments", "type" => "text/html"]; diff --git a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php index 34bdd4df2..7fb2f6048 100644 --- a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php @@ -374,7 +374,7 @@ public function testGetRefundsOnPaymentResource() $refunds = $this->getPayment()->refunds(); $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count); + $this->assertEquals(1, $refunds->count()); $this->assertCount(1, $refunds); $refund = $refunds[0]; @@ -494,7 +494,7 @@ public function testListRefundsOnPaymentResource() $this->assertInstanceOf(RefundCollection::class, $refunds); /** @var RefundCollection $refunds */ - $this->assertEquals(2, $refunds->count); + $this->assertEquals(2, $refunds->count()); $this->assertCount(2, $refunds); $refund = $refunds[0]; diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php index 61a81731b..e70694dd6 100644 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php @@ -368,7 +368,7 @@ public function testListProfiles() $profiles = $this->apiClient->profiles->page(); $this->assertInstanceOf(ProfileCollection::class, $profiles); - $this->assertEquals(2, $profiles->count); + $this->assertEquals(2, $profiles->count()); foreach ($profiles as $profile) { $this->assertInstanceOf(Profile::class, $profile); diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php index 351e2b461..bcd483341 100644 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/RefundEndpointTest.php @@ -72,7 +72,7 @@ public function testListRefunds() $refunds = $this->apiClient->refunds->page(); $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count); + $this->assertEquals(1, $refunds->count()); $this->assertCount(1, $refunds); $refund = $refunds[0]; diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php index f5ccb3f9f..5890d7927 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php @@ -216,7 +216,7 @@ public function testListWorks() $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); - $this->assertEquals(count($subscriptions), $subscriptions->count); + $this->assertEquals(count($subscriptions), $subscriptions->count()); $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions", "type" => "text/html"]; $this->assertEquals($documentationLink, $subscriptions->_links->documentation); diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index fc4494e10..6a5cbf98d 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -180,7 +180,7 @@ public function testListTerminal() $terminals = $this->apiClient->terminals->page(null, 3); $this->assertInstanceOf(TerminalCollection::class, $terminals); - $this->assertEquals(3, $terminals->count); + $this->assertEquals(3, $terminals->count()); $this->assertEquals(3, count($terminals)); $this->assertLinkObject('https://docs.mollie.com/reference/v2/terminals-api/list-terminals', 'text/html', $terminals->_links->documentation); diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index 8ad487f52..cff003ad0 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -32,7 +32,7 @@ public function testCanGetNextCollectionResultWhenNextLinkIsAvailable() $collection = new OrderCollection( $mockedClient, - 1, + [], $this->arrayToObject([ 'next' => [ 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', @@ -54,7 +54,7 @@ public function testWillReturnNullIfNoNextResultIsAvailable() $mockedClient = $this->createMock(MollieApiClient::class); $collection = new OrderCollection( $mockedClient, - 1, + [], (object) [] ); @@ -85,7 +85,7 @@ public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() $collection = new OrderCollection( $mockedClient, - 1, + [], $this->arrayToObject([ 'previous' => [ 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', @@ -107,7 +107,7 @@ public function testWillReturnNullIfNoPreviousResultIsAvailable() $mockedClient = $this->createMock(MollieApiClient::class); $collection = new OrderCollection( $mockedClient, - 1, + [], (object) [] ); @@ -119,7 +119,7 @@ public function testAutoPaginatorReturnsLazyCollection() { $collection = new OrderCollection( $this->createMock(MollieApiClient::class), - 1, + [], (object) [] ); @@ -181,7 +181,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() $collection = new OrderCollection( $mockedClient, - 0, + [], $this->arrayToObject([ 'next' => [ 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', @@ -205,7 +205,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() */ private function arrayToObject($data) { - if (! is_array($data)) { + if (!is_array($data)) { return $data; } diff --git a/tests/Mollie/API/Resources/MandateCollectionTest.php b/tests/Mollie/API/Resources/MandateCollectionTest.php index 14b707127..bae0f8044 100644 --- a/tests/Mollie/API/Resources/MandateCollectionTest.php +++ b/tests/Mollie/API/Resources/MandateCollectionTest.php @@ -24,13 +24,14 @@ protected function setUp(): void public function testWhereStatus() { - $collection = new MandateCollection($this->client, 6, null); - $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::VALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::INVALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::INVALID); - $collection[] = $this->getMandateWithStatus(MandateStatus::PENDING); + $collection = new MandateCollection($this->client, [ + $this->getMandateWithStatus(MandateStatus::VALID), + $this->getMandateWithStatus(MandateStatus::VALID), + $this->getMandateWithStatus(MandateStatus::VALID), + $this->getMandateWithStatus(MandateStatus::INVALID), + $this->getMandateWithStatus(MandateStatus::INVALID), + $this->getMandateWithStatus(MandateStatus::PENDING), + ], null); $valid = $collection->whereStatus(MandateStatus::VALID); $invalid = $collection->whereStatus(MandateStatus::INVALID); @@ -42,13 +43,13 @@ public function testWhereStatus() $this->assertInstanceOf(MandateCollection::class, $pending); $this->assertCount(6, $collection); - $this->assertEquals(6, $collection->count); + $this->assertEquals(6, $collection->count()); $this->assertCount(3, $valid); - $this->assertEquals(3, $valid->count); + $this->assertEquals(3, $valid->count()); $this->assertCount(2, $invalid); - $this->assertEquals(2, $invalid->count); + $this->assertEquals(2, $invalid->count()); $this->assertCount(1, $pending); - $this->assertEquals(1, $pending->count); + $this->assertEquals(1, $pending->count()); } /** diff --git a/tests/Mollie/API/Resources/OrderLineCollectionTest.php b/tests/Mollie/API/Resources/OrderLineCollectionTest.php index c81460cd9..cb874f58f 100644 --- a/tests/Mollie/API/Resources/OrderLineCollectionTest.php +++ b/tests/Mollie/API/Resources/OrderLineCollectionTest.php @@ -11,7 +11,6 @@ class OrderLineCollectionTest extends \PHPUnit\Framework\TestCase public function testCanGetOrderLine() { $mockApi = $this->createMock(MollieApiClient::class); - $lines = new OrderLineCollection(3, null); $line1 = new OrderLine($mockApi); $line1->id = 'odl_aaaaaaaaaaa1'; @@ -22,9 +21,11 @@ public function testCanGetOrderLine() $line3 = new OrderLine($mockApi); $line3->id = 'odl_aaaaaaaaaaa3'; - $lines[] = $line1; - $lines[] = $line2; - $lines[] = $line3; + $lines = new OrderLineCollection($mockApi, [ + $line1, + $line2, + $line3, + ], null); $this->assertNull($lines->get('odl_not_existent')); diff --git a/tests/Mollie/API/Resources/ResourceFactoryTest.php b/tests/Mollie/API/Resources/ResourceFactoryTest.php index 388ae2e55..4e4cfe397 100644 --- a/tests/Mollie/API/Resources/ResourceFactoryTest.php +++ b/tests/Mollie/API/Resources/ResourceFactoryTest.php @@ -4,6 +4,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; +use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; class ResourceFactoryTest extends \PHPUnit\Framework\TestCase @@ -21,7 +22,7 @@ public function testCreateFromApiResponseWorks() } }'); - $payment = ResourceFactory::createFromApiResult($apiResult, new Payment($this->createMock(MollieApiClient::class))); + $payment = ResourceFactory::createFromApiResult($this->createMock(MollieApiClient::class), $apiResult, Payment::class); $this->assertInstanceOf(Payment::class, $payment); $this->assertEquals("payment", $payment->resource); @@ -30,4 +31,40 @@ public function testCreateFromApiResponseWorks() $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt); $this->assertEquals((object) ["value" => "20.00", "currency" => "EUR"], $payment->amount); } + + public function testEmbeddedResourcesAreTypeCasted() + { + $apiResult = json_decode('{ + "resource":"payment", + "id":"tr_44aKxzEbr8", + "mode":"test", + "createdAt":"2018-03-13T14:02:29+00:00", + "amount":{ + "value":"20.00", + "currency":"EUR" + }, + "_embedded": { + "refunds": [ + { + "resource": "refund", + "id": "re_4qqhO89gsT", + "amount": { + "value": "20.00", + "currency": "EUR" + } + } + ] + } + }'); + + /** @var Payment $payment */ + $payment = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Payment::class + ); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertInstanceOf(RefundCollection::class, $payment->_embedded->refunds); + } } From c4f62a05e7e43599c6ca4a1114f67edbde941bfa Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 28 Jun 2024 17:22:15 +0200 Subject: [PATCH 021/131] typecast embedded resources --- src/Endpoints/ProfileEndpoint.php | 6 +- ...EmbeddedResourcesNotParseableException.php | 7 ++ src/Http/Adapter/CurlMollieHttpAdapter.php | 2 +- src/Http/PsrResponseHandler.php | 3 +- src/Http/Response.php | 4 - src/Resources/Client.php | 5 +- src/Resources/ResourceFactory.php | 83 ++++++++++++++----- .../API/Resources/CursorCollectionTest.php | 2 +- .../API/Resources/ResourceFactoryTest.php | 43 +++++++++- 9 files changed, 120 insertions(+), 35 deletions(-) create mode 100644 src/Exceptions/EmbeddedResourcesNotParseableException.php diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index c6e4a9bf9..8e9f470c4 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -12,7 +12,7 @@ class ProfileEndpoint extends EndpointCollection { protected string $resourcePath = "profiles"; - protected $resourceClass = Profile::class; + protected static $resourceClass = Profile::class; protected static string $resourceIdPrefix = 'pfl_'; @@ -21,7 +21,7 @@ class ProfileEndpoint extends EndpointCollection */ public static function getResourceClass(): string { - return $this->resourceClass; + return static::$resourceClass; } /** @@ -96,7 +96,7 @@ public function update(string $profileId, array $data = []): ?Profile */ public function getCurrent(array $parameters = []): CurrentProfile { - $this->resourceClass = CurrentProfile::class; + static::$resourceClass = CurrentProfile::class; /** @var CurrentProfile */ return $this->readResource('me', $parameters); diff --git a/src/Exceptions/EmbeddedResourcesNotParseableException.php b/src/Exceptions/EmbeddedResourcesNotParseableException.php new file mode 100644 index 000000000..7042278fb --- /dev/null +++ b/src/Exceptions/EmbeddedResourcesNotParseableException.php @@ -0,0 +1,7 @@ +extractResponseDetails($curl, $response); curl_close($curl); - return new Response($statusCode, $headers, $content, ''); + return new Response($statusCode, $content, ''); } private function initializeCurl(string $url) diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php index 4f718ddf1..05bd9d93d 100644 --- a/src/Http/PsrResponseHandler.php +++ b/src/Http/PsrResponseHandler.php @@ -41,7 +41,7 @@ public function handle( return ResponseHandler::noResponse(); } - if (! $psrResponse instanceof ResponseInterface) { + if (!$psrResponse instanceof ResponseInterface) { throw new RuntimeException("Response must be an instance of ResponseInterface."); } @@ -49,7 +49,6 @@ public function handle( $response = new Response( $code, - $psrResponse->getHeaders(), $body ); diff --git a/src/Http/Response.php b/src/Http/Response.php index b38bd016e..56d434437 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -11,8 +11,6 @@ class Response implements ResponseContract private int $statusCode; - private array $headers; - private ?string $body = null; private string $reasonPhrase; @@ -26,12 +24,10 @@ class Response implements ResponseContract public function __construct( int $statusCode = 200, - array $headers = [], ?string $body = null, string $reasonPhrase = '' ) { $this->statusCode = $statusCode; - $this->headers = $headers; $this->body = $body; $this->reasonPhrase = $reasonPhrase; } diff --git a/src/Resources/Client.php b/src/Resources/Client.php index 4559e7bf5..4b3e143d8 100644 --- a/src/Resources/Client.php +++ b/src/Resources/Client.php @@ -39,7 +39,8 @@ class Client extends BaseResource implements EmbeddedResourcesContract public function getEmbeddedResourcesMap(): array { return [ - // test if is correct as it's no collection - ] + 'organization' => Organization::class, + 'onboarding' => Onboarding::class, + ]; } } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 63ee9e357..e23c45108 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\EmbeddedResourcesContract; +use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] @@ -22,38 +23,77 @@ public static function createFromApiResult(MollieApiClient $client, object $resp $resource = new $resourceClass($client); foreach ($response as $property => $value) { - if ($property === '_embedded' && $resource instanceof EmbeddedResourcesContract) { - $resource->_embedded = new \stdClass(); - - foreach ($value as $embeddedResourceName => $embeddedResourceData) { - $resource->_embedded->{$embeddedResourceName} = self::createEmbeddedCollection( - $client, - $resource, - $embeddedResourceName, - $embeddedResourceData - ); - } - } else { - $resource->{$property} = $value; - } + $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) + ? self::parseEmbeddedResources($client, $resource, $value) + : $value; } return $resource; } + /** + * Check if the resource holds embedded resources + * + * @param object $resource + * @param string $key + * @param array|\ArrayAccess $value + * @return boolean + */ + private static function holdsEmbeddedResources(object $resource, string $key, $value): bool + { + return $key === '_embedded' + && !is_null($value) + && $resource instanceof EmbeddedResourcesContract; + } + + /** + * Parses embedded resources into their respective resource objects or collections. + * + * @param MollieApiClient $client + * @param object $resource + * @param object $embedded + * @return object + */ + private static function parseEmbeddedResources(MollieApiClient $client, object $resource, object $embedded): object + { + $result = new \stdClass(); + + foreach ($embedded as $resourceKey => $resourceData) { + $collectionOrResourceClass = $resource->getEmbeddedResourcesMap()[$resourceKey] ?? null; + + if (is_null($collectionOrResourceClass)) { + throw new EmbeddedResourcesNotParseableException( + "Resource " . $resource::class . " does not have a mapping for embedded resource {$resourceKey}" + ); + } + + $result->{$resourceKey} = is_subclass_of($collectionOrResourceClass, BaseResource::class) + ? self::createFromApiResult( + $client, + $resourceData, + $collectionOrResourceClass + ) + : self::createEmbeddedResourceCollection( + $client, + $collectionOrResourceClass, + $resourceData + ); + } + + return $result; + } + /** * @param MollieApiClient $client - * @param $data + * @param string $collectionClass + * @param array|\ArrayObject $data * @return BaseCollection */ - private static function createEmbeddedCollection( + private static function createEmbeddedResourceCollection( MollieApiClient $client, - EmbeddedResourcesContract $resource, - string $collectionKey, + string $collectionClass, $data ): BaseCollection { - $collectionClass = $resource->getEmbeddedResourcesMap()[$collectionKey] ?? BaseCollection::class; - return self::instantiateBaseCollection( $client, $collectionClass, @@ -115,6 +155,7 @@ public static function createCursorResourceCollection( } /** + * @param MollieApiClient $client * @param string $collectionClass * @param array $items * @param object|null $_links @@ -134,7 +175,7 @@ private static function instantiateBaseCollection(MollieApiClient $client, strin private static function mapToResourceObjects(MollieApiClient $client, $data, string $resourceClass): array { return array_map( - fn (\stdClass $item) => static::createFromApiResult( + fn ($item) => static::createFromApiResult( $client, $item, $resourceClass diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index cff003ad0..c859d6049 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -220,7 +220,7 @@ private function arrayToObject($data) private function objectToResponse(object $obj): Response { - return new Response(200, [], json_encode($obj)); + return new Response(200, json_encode($obj)); } private function arrayToResponse($data): Response diff --git a/tests/Mollie/API/Resources/ResourceFactoryTest.php b/tests/Mollie/API/Resources/ResourceFactoryTest.php index 4e4cfe397..d4b4576cb 100644 --- a/tests/Mollie/API/Resources/ResourceFactoryTest.php +++ b/tests/Mollie/API/Resources/ResourceFactoryTest.php @@ -3,6 +3,8 @@ namespace Tests\Mollie\Api\Resources; use Mollie\Api\MollieApiClient; +use Mollie\Api\Resources\Client; +use Mollie\Api\Resources\Onboarding; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; @@ -32,7 +34,7 @@ public function testCreateFromApiResponseWorks() $this->assertEquals((object) ["value" => "20.00", "currency" => "EUR"], $payment->amount); } - public function testEmbeddedResourcesAreTypeCasted() + public function testEmbeddedCollectionsAreTypeCasted() { $apiResult = json_decode('{ "resource":"payment", @@ -65,6 +67,45 @@ public function testEmbeddedResourcesAreTypeCasted() ); $this->assertInstanceOf(Payment::class, $payment); + /** @phpstan-ignore-next-line */ $this->assertInstanceOf(RefundCollection::class, $payment->_embedded->refunds); } + + /** @test */ + public function testEmbeddedResourcesAreTypeCasted() + { + $apiResult = json_decode('{ + "resource": "client", + "id": "org_1337", + "organizationCreatedAt": "2018-03-21T13:13:37+00:00", + "commission": { + "count": 200, + "totalAmount": { + "currency": "EUR", + "value": "10.00" + } + }, + "_embedded": { + "onboarding": { + "resource": "onboarding", + "name": "Mollie B.V.", + "signedUpAt": "2018-12-20T10:49:08+00:00", + "status": "completed", + "canReceivePayments": true, + "canReceiveSettlements": true + } + } + }'); + + /** @var Client $client */ + $client = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Client::class + ); + + $this->assertInstanceOf(Client::class, $client); + /** @phpstan-ignore-next-line */ + $this->assertInstanceOf(Onboarding::class, $client->_embedded->onboarding); + } } From 1bd03e3daaad42f5404f512ba272df6cc1157cb1 Mon Sep 17 00:00:00 2001 From: Naoray Date: Fri, 28 Jun 2024 15:23:51 +0000 Subject: [PATCH 022/131] Fix styling --- src/Http/PsrResponseHandler.php | 2 +- src/Http/Response.php | 2 +- src/Resources/Payment.php | 14 +++++++------- src/Resources/Profile.php | 8 ++++---- src/Resources/ResourceFactory.php | 4 ++-- src/Resources/Subscription.php | 4 ++-- .../Mollie/API/Resources/CursorCollectionTest.php | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php index 05bd9d93d..d71e32deb 100644 --- a/src/Http/PsrResponseHandler.php +++ b/src/Http/PsrResponseHandler.php @@ -41,7 +41,7 @@ public function handle( return ResponseHandler::noResponse(); } - if (!$psrResponse instanceof ResponseInterface) { + if (! $psrResponse instanceof ResponseInterface) { throw new RuntimeException("Response must be an instance of ResponseInterface."); } diff --git a/src/Http/Response.php b/src/Http/Response.php index 56d434437..338e368cf 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -53,7 +53,7 @@ public function decode(): \stdClass return (object)[]; } - if (!$this->decoded) { + if (! $this->decoded) { $this->decoded = @json_decode($body); if (json_last_error() !== JSON_ERROR_NONE) { diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 62dd15054..2364ac259 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -445,7 +445,7 @@ public function isAuthorized(): bool */ public function isPaid(): bool { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** @@ -455,7 +455,7 @@ public function isPaid(): bool */ public function hasRefunds(): bool { - return !empty($this->_links->refunds); + return ! empty($this->_links->refunds); } /** @@ -465,7 +465,7 @@ public function hasRefunds(): bool */ public function hasChargebacks(): bool { - return !empty($this->_links->chargebacks); + return ! empty($this->_links->chargebacks); } /** @@ -598,7 +598,7 @@ public function getAmountChargedBack(): float */ public function hasSplitPayments(): bool { - return !empty($this->routing); + return ! empty($this->routing); } /** @@ -609,7 +609,7 @@ public function hasSplitPayments(): bool */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client); } @@ -664,7 +664,7 @@ public function listRefunds(array $parameters = []): RefundCollection */ public function captures(): CaptureCollection { - if (!isset($this->_links->captures->href)) { + if (! isset($this->_links->captures->href)) { return new CaptureCollection($this->client); } @@ -706,7 +706,7 @@ public function getCapture($captureId, array $parameters = []): Capture */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client); } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 731454ae5..e3dafe0ef 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -129,7 +129,7 @@ public function update(): ?Profile */ public function chargebacks(): ChargebackCollection { - if (!isset($this->_links->chargebacks->href)) { + if (! isset($this->_links->chargebacks->href)) { return new ChargebackCollection($this->client); } @@ -155,7 +155,7 @@ public function chargebacks(): ChargebackCollection */ public function methods(): MethodCollection { - if (!isset($this->_links->methods->href)) { + if (! isset($this->_links->methods->href)) { return new MethodCollection($this->client); } @@ -207,7 +207,7 @@ public function disableMethod($methodId, array $data = []): ?Method */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client); } @@ -233,7 +233,7 @@ public function payments(): PaymentCollection */ public function refunds(): RefundCollection { - if (!isset($this->_links->refunds->href)) { + if (! isset($this->_links->refunds->href)) { return new RefundCollection($this->client); } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index e23c45108..458fcf416 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -37,12 +37,12 @@ public static function createFromApiResult(MollieApiClient $client, object $resp * @param object $resource * @param string $key * @param array|\ArrayAccess $value - * @return boolean + * @return bool */ private static function holdsEmbeddedResources(object $resource, string $key, $value): bool { return $key === '_embedded' - && !is_null($value) + && ! is_null($value) && $resource instanceof EmbeddedResourcesContract; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index e678b97a6..5685a61e5 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -187,7 +187,7 @@ public function isCompleted(): bool */ public function cancel(): ?Subscription { - if (!isset($this->_links->self->href)) { + if (! isset($this->_links->self->href)) { return $this; } @@ -220,7 +220,7 @@ public function cancel(): ?Subscription */ public function payments(): PaymentCollection { - if (!isset($this->_links->payments->href)) { + if (! isset($this->_links->payments->href)) { return new PaymentCollection($this->client); } diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index c859d6049..b726c8790 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -205,7 +205,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() */ private function arrayToObject($data) { - if (!is_array($data)) { + if (! is_array($data)) { return $data; } From 2efbacf4459add2f15d205b304cfb58b27dc52d2 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Fri, 21 Jun 2024 13:57:03 +0200 Subject: [PATCH 023/131] wip --- phpunit.xml | 8 +++- .../API/Endpoints/PaymentLinkEndpointTest.php | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php diff --git a/phpunit.xml b/phpunit.xml index eb7a8f95d..f566b1d94 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,11 @@ - + src/ diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php new file mode 100644 index 000000000..b7e6cd3c4 --- /dev/null +++ b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php @@ -0,0 +1,38 @@ +markTestIncomplete('To be implemented'); + } + + /** @test */ + public function testGetPaymentLink() + { + $this->markTestIncomplete('To be implemented'); + } + + /** @test */ + public function testCreatePaymentLink() + { + $this->markTestIncomplete('To be implemented'); + } + + /** @test */ + public function testUpdatePaymentLink() + { + $this->markTestIncomplete('To be implemented'); + } + + /** @test */ + public function testDeletePaymentLink() + { + $this->markTestIncomplete('To be implemented'); + } +} \ No newline at end of file From bbefe745226d902c74d9e9727f631d1f60bed4ed Mon Sep 17 00:00:00 2001 From: sandervanhooft Date: Fri, 21 Jun 2024 11:57:32 +0000 Subject: [PATCH 024/131] Fix styling --- tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php index b7e6cd3c4..c09b2030f 100644 --- a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php @@ -35,4 +35,4 @@ public function testDeletePaymentLink() { $this->markTestIncomplete('To be implemented'); } -} \ No newline at end of file +} From acbeadd0258c6fd90c6a6434ff3212adc866eeaa Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Fri, 21 Jun 2024 15:17:39 +0200 Subject: [PATCH 025/131] wip --- .../API/Endpoints/PaymentLinkEndpointTest.php | 325 +++++++++++++++++- 1 file changed, 320 insertions(+), 5 deletions(-) diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php index c09b2030f..7a8daa20d 100644 --- a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php @@ -4,35 +4,350 @@ namespace Tests\Mollie\API\Endpoints; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Response; +use Mollie\Api\Resources\PaymentLink; + class PaymentLinkEndpointTest extends BaseEndpointTest { /** @test */ public function testListPaymentLinks() { - $this->markTestIncomplete('To be implemented'); + $this->mockApiCall( + new Request( + "GET", + "/v2/payment-links", + [], + '' + ), + new Response( + 200, + [], + '{ + "count": 1, + "_embedded": { + "payment_links": [ + { + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56+00:00", + "expiresAt": "2023-06-06T11:00:00+00:00", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payment-links/", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payment-links?from=pl_ayGNzD4TYuQtUaxNyu8aH&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/list-payment-links", + "type": "text/html" + } + } + }' + ) + ); + + $paymentLinks = $this->apiClient->paymentLinks->page(); + $this->assertEquals(1, $paymentLinks->count()); + $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLinks[0]->id); + // No need to test all attributes as these are mapped dynamically. + } + + /** @test */ + public function testIteratePaymentLinks() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/payment-links", + [], + '' + ), + new Response( + 200, + [], + '{ + "count": 1, + "_embedded": { + "payment_links": [ + { + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56+00:00", + "expiresAt": "2023-06-06T11:00:00+00:00", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payment-links/", + "type": "application/hal+json" + }, + "previous": null, + "next": null, + "documentation": { + "href": "https://docs.mollie.com/reference/list-payment-links", + "type": "text/html" + } + } + }' + ) + ); + foreach ($this->apiClient->paymentLinks->iterator() as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals("payment-link", $paymentLink->resource); + // No need to test all attributes as these are mapped dynamically. + } } /** @test */ public function testGetPaymentLink() { - $this->markTestIncomplete('To be implemented'); + $this->mockApiCall( + new Request( + "GET", + "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", + [], + '' + ), + new Response( + 200, + [], + '{ + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56+00:00", + "expiresAt": "2023-06-06T11:00:00+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/get-payment-link", + "type": "text/html" + } + } + }' + ) + ); + + $paymentLink = $this->apiClient->paymentLinks->get("pl_4Y0eZitmBnQ6IDoMqZQKh", ["testmode" => true]); + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals("payment-link", $paymentLink->resource); + $this->assertEquals("pl_4Y0eZitmBnQ6IDoMqZQKh", $paymentLink->id); + // No need to test all attributes as these are mapped dynamically. } /** @test */ public function testCreatePaymentLink() { - $this->markTestIncomplete('To be implemented'); + $this->mockApiCall( + new Request( + "POST", + "/v2/payment-links", + [], + '{ + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "webhookUrl": "https://webshop.example.org/payment-links/webhook/", + "redirectUrl": "https://webshop.example.org/thanks", + "expiresAt": "2023-06-06T11:00:00+00:00" + }' + ), + new Response( + 201, + [], + '{ + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56+00:00", + "expiresAt": "2023-06-06T11:00:00+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/create-payment-link", + "type": "text/html" + } + } + }' + ) + ); + + $paymentLink = $this->apiClient->paymentLinks->create([ + "description" => "Bicycle tires", + "amount" => [ + "currency" => "EUR", + "value" => "24.95", + ], + "webhookUrl" => "https://webshop.example.org/payment-links/webhook/", + "redirectUrl" => "https://webshop.example.org/thanks", + "expiresAt" => "2023-06-06T11:00:00+00:00", + ]); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLink->id); + // No need to test all attributes as these are mapped dynamically. } /** @test */ public function testUpdatePaymentLink() { - $this->markTestIncomplete('To be implemented'); + $this->mockApiCall( + new Request( + "PATCH", + "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh", + [], + '{ + "description":"Bicycle tires", + "archived": true + }' + ), + new Response( + 200, + [], + '{ + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": true, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56+00:00", + "expiresAt": "2023-06-06T11:00:00+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/update-payment-link", + "type": "text/html" + } + } + }' + ) + ); + + $paymentLink = $this->apiClient->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', [ + 'description' => 'Bicycle tires', + 'archived' => true, + ]); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $paymentLink->resource = 'payment-link'; + $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; + $paymentLink->archived = true; + // No need to test all attributes as these are mapped dynamically. } /** @test */ public function testDeletePaymentLink() { - $this->markTestIncomplete('To be implemented'); + $this->mockApiCall( + new Request( + "DELETE", + "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh" + ), + new Response( + 204, + [], + null + ) + ); + + $this->assertNull($this->apiClient->paymentLinks->delete('pl_4Y0eZitmBnQ6IDoMqZQKh')); } } From cf26b85259d2a3907e145031712be70dd086b431 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Fri, 21 Jun 2024 15:59:54 +0200 Subject: [PATCH 026/131] wip --- src/Resources/PaymentLink.php | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index c98e5bf0b..efee98427 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -124,4 +124,63 @@ public function getCheckoutUrl(): ?string return $this->_links->paymentLink->href; } + + /** + * Persist the current local Payment Link state to the Mollie API. + * + * @return mixed|\Mollie\Api\Resources\BaseResource + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function update() + { + $body = $this->withPresetOptions([ + 'description' => $this->description, + 'archived' => $this->archived, + ]); + + $result = $this->client->paymentLinks->update($this->id, $body); + + return ResourceFactory::createFromApiResult($result, new PaymentLink($this->client)); + } + + /** + * Archive this Payment Link. + * + * @return \Mollie\Api\Resources\PaymentLink + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function archive() + { + $data = $this->withPresetOptions([ + 'archived' => true, + ]); + + return $this->client->paymentLinks->update($this->id, $data); + } + + /** + * When accessed by oAuth we want to pass the testmode by default + * + * @return array + */ + private function getPresetOptions() + { + $options = []; + if ($this->client->usesOAuth()) { + $options["testmode"] = $this->mode === "test"; + } + + return $options; + } + + /** + * Apply the preset options. + * + * @param array $options + * @return array + */ + private function withPresetOptions(array $options) + { + return array_merge($this->getPresetOptions(), $options); + } } From 837aa04a0d123baf0a53395230458a3bc452a395 Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Fri, 21 Jun 2024 16:28:39 +0200 Subject: [PATCH 027/131] wip --- tests/Mollie/API/Endpoints/BaseEndpointTest.php | 3 ++- tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Mollie/API/Endpoints/BaseEndpointTest.php b/tests/Mollie/API/Endpoints/BaseEndpointTest.php index 37ce668a2..cb8a02e42 100644 --- a/tests/Mollie/API/Endpoints/BaseEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BaseEndpointTest.php @@ -6,8 +6,9 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Mollie\Api\MollieApiClient; +use PHPUnit\Framework\TestCase; -abstract class BaseEndpointTest extends \PHPUnit\Framework\TestCase +abstract class BaseEndpointTest extends TestCase { /** * @var Client|\PHPUnit\Framework\MockObject\MockObject diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php index 7a8daa20d..db3c11cd9 100644 --- a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tests\Mollie\API\Endpoints; +namespace Tests\Mollie\Api\Endpoints; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; From a4a92772e141f3e41602109591afa67472fb241c Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Mon, 24 Jun 2024 13:52:46 +0200 Subject: [PATCH 028/131] Update version number --- src/MollieApiClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 0c38f459e..ee5ce954e 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -263,7 +263,7 @@ public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -283,7 +283,7 @@ public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (! preg_match('/^access_\w+$/', $accessToken)) { + if (!preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } From e122737ec083d7c680e6a595a7d22b59ac8ffc74 Mon Sep 17 00:00:00 2001 From: Naoray Date: Sun, 30 Jun 2024 13:07:32 +0000 Subject: [PATCH 029/131] Fix styling --- src/MollieApiClient.php | 4 ++-- src/Resources/PaymentLink.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index ee5ce954e..0c38f459e 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -263,7 +263,7 @@ public function setApiKey(string $apiKey): self { $apiKey = trim($apiKey); - if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { + if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); } @@ -283,7 +283,7 @@ public function setAccessToken(string $accessToken): self { $accessToken = trim($accessToken); - if (!preg_match('/^access_\w+$/', $accessToken)) { + if (! preg_match('/^access_\w+$/', $accessToken)) { throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); } diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index b5ffa6522..b18f52a31 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -108,7 +108,7 @@ class PaymentLink extends BaseResource */ public function isPaid(): bool { - return !empty($this->paidAt); + return ! empty($this->paidAt); } /** From 85e59093fffe65c423e84cb25592e2050db6e192 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:08:04 +0200 Subject: [PATCH 030/131] update github actions --- .github/workflows/check_php_syntax.yml | 4 ++-- .github/workflows/tests.yml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check_php_syntax.yml b/.github/workflows/check_php_syntax.yml index ed5868e85..152dc6545 100644 --- a/.github/workflows/check_php_syntax.yml +++ b/.github/workflows/check_php_syntax.yml @@ -3,14 +3,14 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: "0 0 * * *" jobs: tests: runs-on: ubuntu-latest strategy: fail-fast: true matrix: - php: [ 7.2 ] + php: [7.4] name: Check PHP ${{ matrix.php }} syntax steps: - name: Checkout code diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c4b3b3dd1..d05532f84 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,6 @@ jobs: run: | composer update --prefer-dist --no-interaction --no-progress - name: PHPStan - if: ${{ matrix.php >= 7.3 }} run: | composer require "phpstan/phpstan:1.9.2" vendor/bin/phpstan analyse --no-progress From db7a507ec9526db925a71166fb25af3a5a395701 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:09:34 +0200 Subject: [PATCH 031/131] add php7.4 compatible invade dependency/ --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c1296d2a1..694559528 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,7 @@ "guzzlehttp/guzzle": "^7.6", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.6", - "spatie/invade": "^2.0" + "spatie/invade": "^1.0|^2.0" }, "suggest": { "mollie/oauth2-mollie-php": "Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information." From c743574df233d6c4fbc1be7450314e10701ae9e5 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:20:36 +0200 Subject: [PATCH 032/131] remove spatie/invade dependency --- composer.json | 3 +- src/Resources/BaseCollection.php | 2 +- .../GuzzleMollieHttpAdapterTest.php | 6 ++-- tests/Mollie/API/MollieApiClientTest.php | 33 ++++++++++++++----- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 694559528..b613efd4a 100644 --- a/composer.json +++ b/composer.json @@ -58,8 +58,7 @@ "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.6", - "spatie/invade": "^1.0|^2.0" + "phpunit/phpunit": "^9.6" }, "suggest": { "mollie/oauth2-mollie-php": "Use OAuth to authenticate with the Mollie API. This is needed for some endpoints. Visit https://docs.mollie.com/ for more information." diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 441bdb65b..f31fbc129 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -37,7 +37,7 @@ public function contains(callable $callback): bool return false; } - public function filter(callable $callback): static + public function filter(callable $callback) { $filteredItems = array_filter($this->getArrayCopy(), $callback); diff --git a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php index 9f7b14184..af3bcc03e 100644 --- a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php @@ -54,8 +54,7 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - /** @phpstan-ignore-next-line */ - $this->assertInstanceOf(RequestInterface::class, invade($e)->request); + $this->assertInstanceOf(RequestInterface::class, $e->getRequest()); } } @@ -86,8 +85,7 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() '{ "foo": "bar" }' ); } catch (ApiException $e) { - /** @phpstan-ignore-next-line */ - $this->assertNull(invade($e)->request); + $this->assertNull($e->getRequest()); } } } diff --git a/tests/Mollie/API/MollieApiClientTest.php b/tests/Mollie/API/MollieApiClientTest.php index 2d0c0b28c..f06792b73 100644 --- a/tests/Mollie/API/MollieApiClientTest.php +++ b/tests/Mollie/API/MollieApiClientTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; use GuzzleHttp\Psr7\Response; +use Mollie\Api\Contracts\MollieHttpAdapterContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; @@ -78,7 +79,7 @@ public function testPerformHttpCallCreatesApiExceptionCorrectly() ->willReturn($response); try { - $parsedResponse = $this->mollieApiClient->performHttpCall('GET', ''); + $this->mollieApiClient->performHttpCall('GET', ''); } catch (ApiException $e) { $this->assertEquals('recurringType', $e->getField()); $this->assertEquals('https://docs.mollie.com/guides/handling-errors', $e->getDocumentationUrl()); @@ -118,18 +119,19 @@ public function testPerformHttpCallCreatesApiExceptionWithoutFieldAndDocumentati public function testCanBeSerializedAndUnserialized() { - $this->mollieApiClient->setApiEndpoint("https://mymollieproxy.local"); - $serialized = \serialize($this->mollieApiClient); + $client = new FakeMollieApiClient($this->createMock(Client::class)); + + $client->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); + $client->setApiEndpoint("https://mymollieproxy.local"); + $serialized = \serialize($client); $this->assertStringNotContainsString('test_foobarfoobarfoobarfoobarfoobar', $serialized, "API key should not be in serialized data or it will end up in caches."); - /** @var MollieApiClient $client_copy */ - $client_copy = invade(unserialize($serialized)); + /** @var FakeMollieApiClient $client_copy */ + $client_copy = unserialize($serialized); - /** @phpstan-ignore-next-line */ - $this->assertEmpty($client_copy->apiKey, "API key should not have been remembered"); - /** @phpstan-ignore-next-line */ - $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->httpClient, "A Guzzle client should have been set."); + $this->assertEmpty($client_copy->getApiKey(), "API key should not have been remembered"); + $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->getHttpClient(), "A Guzzle client should have been set."); $this->assertNull($client_copy->usesOAuth()); $this->assertEquals("https://mymollieproxy.local", $client_copy->getApiEndpoint(), "The API endpoint should be remembered"); @@ -321,3 +323,16 @@ private function assertIdempotencyKeyIsUsedForMethod($httpMethod) $this->assertEquals('idempotentFooBar', $fakeAdapter->getUsedHeaders()['Idempotency-Key']); } } + +class FakeMollieApiClient extends MollieApiClient +{ + public function getApiKey(): string + { + return $this->apiKey; + } + + public function getHttpClient(): MollieHttpAdapterContract + { + return $this->httpClient; + } +} From 3fa1abc711101177c44976728147507a7f9673f2 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:24:10 +0200 Subject: [PATCH 033/131] change return types to be php7.4 compatible --- src/Resources/IssuerCollection.php | 4 ++-- src/Resources/MethodPriceCollection.php | 4 ++-- src/Resources/OrderLineCollection.php | 4 ++-- src/Resources/ResourceFactory.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Resources/IssuerCollection.php b/src/Resources/IssuerCollection.php index 19f7ff9c9..520d1446f 100644 --- a/src/Resources/IssuerCollection.php +++ b/src/Resources/IssuerCollection.php @@ -5,9 +5,9 @@ class IssuerCollection extends BaseCollection { /** - * @return null + * @return null|string */ - public static function getCollectionResourceName(): null + public static function getCollectionResourceName(): ?string { return null; } diff --git a/src/Resources/MethodPriceCollection.php b/src/Resources/MethodPriceCollection.php index 6726b14de..22e83a1f3 100644 --- a/src/Resources/MethodPriceCollection.php +++ b/src/Resources/MethodPriceCollection.php @@ -5,9 +5,9 @@ class MethodPriceCollection extends BaseCollection { /** - * @return null + * @return null|string */ - public static function getCollectionResourceName(): null + public static function getCollectionResourceName(): ?string { return null; } diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php index 9c2b3090a..bf9d76b75 100644 --- a/src/Resources/OrderLineCollection.php +++ b/src/Resources/OrderLineCollection.php @@ -5,9 +5,9 @@ class OrderLineCollection extends BaseCollection { /** - * @return null + * @return null|string */ - public static function getCollectionResourceName(): null + public static function getCollectionResourceName(): ?string { return null; } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 458fcf416..4c67582ac 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -42,7 +42,7 @@ public static function createFromApiResult(MollieApiClient $client, object $resp private static function holdsEmbeddedResources(object $resource, string $key, $value): bool { return $key === '_embedded' - && ! is_null($value) + && !is_null($value) && $resource instanceof EmbeddedResourcesContract; } @@ -63,7 +63,7 @@ private static function parseEmbeddedResources(MollieApiClient $client, object $ if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - "Resource " . $resource::class . " does not have a mapping for embedded resource {$resourceKey}" + "Resource " . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" ); } From a80141419da11eefa2d0076ebbf2c77895aa22b5 Mon Sep 17 00:00:00 2001 From: Naoray Date: Sun, 30 Jun 2024 13:24:26 +0000 Subject: [PATCH 034/131] Fix styling --- src/Resources/ResourceFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 4c67582ac..4fb290b40 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -42,7 +42,7 @@ public static function createFromApiResult(MollieApiClient $client, object $resp private static function holdsEmbeddedResources(object $resource, string $key, $value): bool { return $key === '_embedded' - && !is_null($value) + && ! is_null($value) && $resource instanceof EmbeddedResourcesContract; } From 41e3dfafa1ee5dabe2d57025bc8404bfab421d52 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:25:26 +0200 Subject: [PATCH 035/131] wip --- src/Endpoints/WalletEndpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/WalletEndpoint.php b/src/Endpoints/WalletEndpoint.php index 5db82e297..4af80c2ff 100644 --- a/src/Endpoints/WalletEndpoint.php +++ b/src/Endpoints/WalletEndpoint.php @@ -14,7 +14,7 @@ class WalletEndpoint extends BaseEndpoint * @return false|string * @throws \Mollie\Api\Exceptions\ApiException */ - public function requestApplePayPaymentSession($domain, $validationUrl, $parameters = []): string|false + public function requestApplePayPaymentSession($domain, $validationUrl, $parameters = []) { $body = $this->parseRequestBody(array_merge([ 'domain' => $domain, From 0b135db306274347917c38d0fb869ec266c32dcb Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Sun, 30 Jun 2024 15:28:38 +0200 Subject: [PATCH 036/131] update github action versions --- .github/workflows/check_php_syntax.yml | 2 +- .github/workflows/createzip.yml | 4 ++-- .github/workflows/php-cs-fixer.yml | 4 ++-- .github/workflows/tests.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check_php_syntax.yml b/.github/workflows/check_php_syntax.yml index 152dc6545..93af72e0a 100644 --- a/.github/workflows/check_php_syntax.yml +++ b/.github/workflows/check_php_syntax.yml @@ -14,7 +14,7 @@ jobs: name: Check PHP ${{ matrix.php }} syntax steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: diff --git a/.github/workflows/createzip.yml b/.github/workflows/createzip.yml index 95f58243c..b4f189120 100644 --- a/.github/workflows/createzip.yml +++ b/.github/workflows/createzip.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -38,7 +38,7 @@ jobs: sed -i.bak 's/autoload.php/composer-autoload.php/g' build/vendor/scoper-autoload.php mv build/vendor/scoper-autoload.php build/vendor/autoload.php - name: Install zip - uses: montudor/action-zip@v0.1.1 + uses: montudor/action-zip@v1 - name: Finally, create a zip file with all built files. run: zip -r mollie-api-php.zip examples src vendor composer.json LICENSE README.md working-directory: build diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index a83d7080b..76ac93480 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: ${{ github.head_ref }} @@ -18,6 +18,6 @@ jobs: args: --config=.php-cs-fixer.dist.php --allow-risky=yes - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Fix styling diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d05532f84..acfad9f8c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: name: PHP - ${{ matrix.php }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: From 7e45e92db5d5dd31e1225904da6ee474f95f9fec Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 10 Jul 2024 12:26:09 +0200 Subject: [PATCH 037/131] wip --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index acfad9f8c..aede4b0b7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,7 +27,7 @@ jobs: composer update --prefer-dist --no-interaction --no-progress - name: PHPStan run: | - composer require "phpstan/phpstan:1.9.2" + composer require "phpstan/phpstan" --dev vendor/bin/phpstan analyse --no-progress - name: Execute tests run: vendor/bin/paratest --verbose From ad8930f35188aac14ca2bdb368955e671b63819e Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 16 Jul 2024 15:21:58 +0200 Subject: [PATCH 038/131] wip --- src/Endpoints/MandateEndpoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index 6ec8a1ef5..fad15da2b 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -16,7 +16,7 @@ class MandateEndpoint extends EndpointCollection */ public static function getResourceClass(): string { - return Mandate::class; + return Mandate::class; } /** From 6144f6a6c875c83727d237dc9871dae46494dfcf Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 17 Jul 2024 16:38:23 +0200 Subject: [PATCH 039/131] remove static resource and collection methods --- src/Endpoints/BalanceEndpoint.php | 33 ++++++++++++------- src/Endpoints/BalanceReportEndpoint.php | 16 +++++---- src/Endpoints/BalanceTransactionEndpoint.php | 23 +++++++------ src/Endpoints/BaseEndpoint.php | 5 +++ src/Endpoints/ChargebackEndpoint.php | 23 +++++++------ src/Endpoints/ClientEndpoint.php | 23 +++++++------ src/Endpoints/ClientLinkEndpoint.php | 14 +++++--- src/Endpoints/CustomerEndpoint.php | 29 ++++++++++------ src/Endpoints/CustomerPaymentsEndpoint.php | 23 +++++++------ src/Endpoints/EndpointCollection.php | 19 +++++++++-- src/Endpoints/InvoiceEndpoint.php | 23 +++++++------ src/Endpoints/MandateEndpoint.php | 23 +++++++------ src/Endpoints/MethodEndpoint.php | 23 +++++++------ src/Endpoints/MethodIssuerEndpoint.php | 17 +++++++--- src/Endpoints/OnboardingEndpoint.php | 14 +++++--- src/Endpoints/OrderEndpoint.php | 29 ++++++++++------ src/Endpoints/OrderLineEndpoint.php | 32 +++++++++--------- src/Endpoints/OrderPaymentEndpoint.php | 23 +++++++------ src/Endpoints/OrderRefundEndpoint.php | 23 +++++++------ src/Endpoints/OrderShipmentEndpoint.php | 29 ++++++++++------ src/Endpoints/OrganizationEndpoint.php | 14 +++++--- src/Endpoints/OrganizationPartnerEndpoint.php | 14 +++++--- src/Endpoints/PaymentCaptureEndpoint.php | 23 +++++++------ src/Endpoints/PaymentChargebackEndpoint.php | 23 +++++++------ src/Endpoints/PaymentEndpoint.php | 29 ++++++++++------ src/Endpoints/PaymentLinkEndpoint.php | 29 ++++++++++------ src/Endpoints/PaymentLinkPaymentEndpoint.php | 25 +++++++++----- src/Endpoints/PaymentRefundEndpoint.php | 23 +++++++------ src/Endpoints/PaymentRouteEndpoint.php | 14 +++++--- src/Endpoints/PermissionEndpoint.php | 23 +++++++------ src/Endpoints/ProfileEndpoint.php | 33 +++++++++++-------- src/Endpoints/ProfileMethodEndpoint.php | 25 +++++++------- src/Endpoints/RefundEndpoint.php | 23 +++++++------ src/Endpoints/RestEndpoint.php | 22 +++++-------- src/Endpoints/SettlementCaptureEndpoint.php | 23 +++++++------ .../SettlementChargebackEndpoint.php | 23 +++++++------ src/Endpoints/SettlementPaymentEndpoint.php | 23 +++++++------ src/Endpoints/SettlementRefundEndpoint.php | 23 +++++++------ src/Endpoints/SettlementsEndpoint.php | 23 +++++++------ src/Endpoints/SubscriptionEndpoint.php | 29 ++++++++++------ src/Endpoints/SubscriptionPaymentEndpoint.php | 29 ++++++++++------ src/Endpoints/TerminalEndpoint.php | 29 ++++++++++------ src/InteractsWithResource.php | 22 +++++++++++++ src/Resources/BalanceCollection.php | 20 ++++++----- .../BalanceTransactionCollection.php | 18 +++++----- src/Resources/BaseCollection.php | 15 ++++++++- src/Resources/CaptureCollection.php | 18 +++++----- src/Resources/ChargebackCollection.php | 18 +++++----- src/Resources/ClientCollection.php | 18 +++++----- src/Resources/CursorCollection.php | 11 ++++--- src/Resources/CustomerCollection.php | 18 +++++----- src/Resources/InvoiceCollection.php | 18 +++++----- src/Resources/IssuerCollection.php | 7 ---- src/Resources/MandateCollection.php | 18 +++++----- src/Resources/MethodCollection.php | 9 +++-- src/Resources/MethodPriceCollection.php | 7 ---- src/Resources/OrderCollection.php | 18 +++++----- src/Resources/OrderLineCollection.php | 8 ----- src/Resources/PaymentCollection.php | 18 +++++----- src/Resources/PaymentLinkCollection.php | 18 +++++----- src/Resources/PermissionCollection.php | 9 +++-- src/Resources/ProfileCollection.php | 18 +++++----- src/Resources/RefundCollection.php | 18 +++++----- src/Resources/SettlementCollection.php | 18 +++++----- src/Resources/ShipmentCollection.php | 9 +++-- src/Resources/SubscriptionCollection.php | 18 +++++----- src/Resources/TerminalCollection.php | 18 +++++----- 67 files changed, 772 insertions(+), 581 deletions(-) create mode 100644 src/InteractsWithResource.php diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index ffaa0087c..047ceca62 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -9,25 +9,34 @@ class BalanceEndpoint extends EndpointCollection { - protected static string $resourceIdPrefix = 'bal_'; + /** + * Resource class name. + * + * @var string + */ + public static string $resource = Balance::class; - protected string $resourcePath = "balances"; + /** + * The resource collection class name. + * + * @var string + */ + public static string $resourceCollection = BalanceCollection::class; /** - * @inheritDoc + * Resource id prefix. + * Used to validate resource id's. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return BalanceCollection::class; - } + protected static string $resourceIdPrefix = 'bal_'; /** - * @inheritDoc + * The resource path. + * + * @var string */ - public static function getResourceClass(): string - { - return Balance::class; - } + protected string $resourcePath = "balances"; /** * Retrieve a single balance from Mollie. diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php index dda3798ab..5ee35c454 100644 --- a/src/Endpoints/BalanceReportEndpoint.php +++ b/src/Endpoints/BalanceReportEndpoint.php @@ -10,15 +10,19 @@ class BalanceReportEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "balances_report"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return BalanceReport::class; - } + public static string $resource = BalanceReport::class; /** * Retrieve a balance report for the provided balance id and parameters. @@ -43,7 +47,7 @@ public function getForId(string $balanceId, array $parameters = []): ?BalanceRep } /** @var BalanceReport */ - return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); } /** diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 24265c49d..187858c2e 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -11,23 +11,26 @@ class BalanceTransactionEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "balances_transactions"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return BalanceTransactionCollection::class; - } + public static string $resource = BalanceTransaction::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - public static function getResourceClass(): string - { - return BalanceTransaction::class; - } + public static string $resourceCollection = BalanceTransactionCollection::class; /** * List the transactions for a specific Balance. diff --git a/src/Endpoints/BaseEndpoint.php b/src/Endpoints/BaseEndpoint.php index 9c8f45c37..8a209bb47 100644 --- a/src/Endpoints/BaseEndpoint.php +++ b/src/Endpoints/BaseEndpoint.php @@ -16,6 +16,11 @@ abstract class BaseEndpoint protected MollieApiClient $client; + /** + * The resource path. + * + * @var string + */ protected string $resourcePath; protected ?string $parentId; diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index 5ed652bf0..6571b3b7f 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -9,23 +9,26 @@ class ChargebackEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "chargebacks"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Chargeback::class; - } + public static string $resource = Chargeback::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ChargebackCollection::class; - } + public static string $resourceCollection = ChargebackCollection::class; /** * Retrieves a collection of Chargebacks from Mollie. diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 3a6d56b2c..19263b4a9 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -9,23 +9,26 @@ class ClientEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "clients"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Client::class; - } + public static string $resource = Client::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ClientCollection::class; - } + public static string $resourceCollection = ClientCollection::class; /** * Retrieve a client from Mollie. diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php index a3686e5da..0aba4d358 100644 --- a/src/Endpoints/ClientLinkEndpoint.php +++ b/src/Endpoints/ClientLinkEndpoint.php @@ -7,15 +7,19 @@ class ClientLinkEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "client-links"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return ClientLink::class; - } + public static string $resource = ClientLink::class; /** * Creates a client link in Mollie. diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 1f58f8304..1aff77f44 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -9,25 +9,34 @@ class CustomerEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "customers"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'cst_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Customer::class; - } + public static string $resource = Customer::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return CustomerCollection::class; - } + public static string $resourceCollection = CustomerCollection::class; /** * Creates a customer in Mollie. diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index e62382811..b4d851d05 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -10,23 +10,26 @@ class CustomerPaymentsEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "customers_payments"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Payment::class; - } + public static string $resource = Payment::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + public static string $resourceCollection = PaymentCollection::class; /** * Create a subscription for a Customer diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php index 55415c816..1df3252a6 100644 --- a/src/Endpoints/EndpointCollection.php +++ b/src/Endpoints/EndpointCollection.php @@ -7,9 +7,17 @@ use Mollie\Api\Resources\CursorCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceFactory; +use RuntimeException; abstract class EndpointCollection extends RestEndpoint { + /** + * The resource collection class name. + * + * @var string + */ + public static string $resourceCollection = ''; + /** * Get a collection of objects from the REST API. * @@ -66,7 +74,7 @@ protected function buildResultCollection(object $result): BaseCollection return ResourceFactory::createBaseResourceCollection( $this->client, - $this->getResourceClass(), + static::getResourceClass(), $result->_embedded->{$collectionClass::getCollectionResourceName()}, $result->_links, $collectionClass @@ -78,5 +86,12 @@ protected function buildResultCollection(object $result): BaseCollection * * @return string */ - abstract protected function getResourceCollectionClass(): string; + private function getResourceCollectionClass(): string + { + if (!isset(static::$resourceCollection)) { + throw new RuntimeException("The resource collection class is not set on the endpoint."); + } + + return static::$resourceCollection; + } } diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index aed5dc804..8ea206fe8 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -9,23 +9,26 @@ class InvoiceEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "invoices"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Invoice::class; - } + public static string $resource = Invoice::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return InvoiceCollection::class; - } + public static string $resourceCollection = InvoiceCollection::class; /** * Retrieve an Invoice from Mollie. diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index fad15da2b..e07857f18 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -9,23 +9,26 @@ class MandateEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "customers_mandates"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Mandate::class; - } + public static string $resource = Mandate::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return MandateCollection::class; - } + public static string $resourceCollection = MandateCollection::class; /** * @param Customer $customer diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index 3f5a29b76..a1ed6acaa 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -8,23 +8,26 @@ class MethodEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "methods"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Method::class; - } + public static string $resource = Method::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return MethodCollection::class; - } + public static string $resourceCollection = MethodCollection::class; /** * Retrieve all active methods. In test mode, this includes pending methods. The results are not paginated. diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php index cdaf497ef..61947a449 100644 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -9,17 +9,24 @@ class MethodIssuerEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = 'profiles_methods_issuers'; + /** + * Resource class name. + * + * @var string + */ + public static string $resource = Issuer::class; + protected $profileId = null; protected $methodId = null; protected $issuerId = null; - public static function getResourceClass(): string - { - return Issuer::class; - } - /** * @param string $profileId * @param string $methodId diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php index add58b44e..2a5f0bf6b 100644 --- a/src/Endpoints/OnboardingEndpoint.php +++ b/src/Endpoints/OnboardingEndpoint.php @@ -8,15 +8,19 @@ class OnboardingEndpoint extends RestEndpoint implements SingleResourceEndpointContract { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "onboarding/me"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Onboarding::class; - } + public static string $resource = Onboarding::class; /** * Retrieve the organization's onboarding status from Mollie. diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index cff26a380..dbfedcdcb 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -9,25 +9,34 @@ class OrderEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "orders"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'ord_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Order::class; - } + public static string $resource = Order::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return OrderCollection::class; - } + public static string $resourceCollection = OrderCollection::class; /** * Creates a order in Mollie. diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index b85d5f6ec..98f3af026 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -5,30 +5,31 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Order; use Mollie\Api\Resources\OrderLine; -use Mollie\Api\Resources\OrderLineCollection; use Mollie\Api\Resources\ResourceFactory; -class OrderLineEndpoint extends EndpointCollection +class OrderLineEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "orders_lines"; - protected static string $resourceIdPrefix = 'odl_'; - /** - * @inheritDoc + * Resource id prefix. + * Used to validate resource id's. + * + * @var string */ - public static function getResourceClass(): string - { - return OrderLine::class; - } + protected static string $resourceIdPrefix = 'odl_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return OrderLineCollection::class; - } + public static string $resource = OrderLine::class; /** * Update a specific OrderLine resource. @@ -119,9 +120,10 @@ public function cancelFor(Order $order, array $data): void */ public function cancelForId(string $orderId, array $data): void { - if (! isset($data['lines']) || ! is_array($data['lines'])) { + if (!isset($data['lines']) || !is_array($data['lines'])) { throw new ApiException("A lines array is required."); } + $this->parentId = $orderId; $this->client->performHttpCall( diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php index 861f3c9f7..0eaa527c6 100644 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ b/src/Endpoints/OrderPaymentEndpoint.php @@ -8,23 +8,26 @@ class OrderPaymentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "orders_payments"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Payment::class; - } + public static string $resource = Payment::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + public static string $resourceCollection = PaymentCollection::class; /** * Creates a payment in Mollie for a specific order. diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php index 7137863d4..7c3da894c 100644 --- a/src/Endpoints/OrderRefundEndpoint.php +++ b/src/Endpoints/OrderRefundEndpoint.php @@ -8,23 +8,26 @@ class OrderRefundEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "orders_refunds"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Refund::class; - } + public static string $resource = Refund::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return RefundCollection::class; - } + public static string $resourceCollection = RefundCollection::class; /** * Refund some order lines. You can provide an empty array for the diff --git a/src/Endpoints/OrderShipmentEndpoint.php b/src/Endpoints/OrderShipmentEndpoint.php index 863fc530d..872e82928 100644 --- a/src/Endpoints/OrderShipmentEndpoint.php +++ b/src/Endpoints/OrderShipmentEndpoint.php @@ -9,25 +9,34 @@ class OrderShipmentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "orders_shipments"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'shp_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Shipment::class; - } + public static string $resource = Shipment::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ShipmentCollection::class; - } + public static string $resourceCollection = ShipmentCollection::class; /** * Create a shipment for some order lines. You can provide an empty array for the diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php index c87e3d4f2..ea826c88c 100644 --- a/src/Endpoints/OrganizationEndpoint.php +++ b/src/Endpoints/OrganizationEndpoint.php @@ -7,15 +7,19 @@ class OrganizationEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "organizations"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Organization::class; - } + public static string $resource = Organization::class; /** * Retrieve an organization from Mollie. diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php index 1cbe72207..b885ced54 100644 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ b/src/Endpoints/OrganizationPartnerEndpoint.php @@ -8,15 +8,19 @@ class OrganizationPartnerEndpoint extends RestEndpoint implements SingleResourceEndpointContract { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "organizations/me/partner"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Partner::class; - } + public static string $resource = Partner::class; /** * Retrieve details about the partner status of the currently authenticated organization. diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 72643d6fa..8f429fb3d 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -9,23 +9,26 @@ class PaymentCaptureEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payments_captures"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Capture::class; - } + public static string $resource = Capture::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return CaptureCollection::class; - } + public static string $resourceCollection = CaptureCollection::class; /** * Creates a payment capture in Mollie. diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index a23a8b81f..e7b9cc5d8 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -9,23 +9,26 @@ class PaymentChargebackEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payments_chargebacks"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Chargeback::class; - } + public static string $resource = Chargeback::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ChargebackCollection::class; - } + public static string $resourceCollection = ChargebackCollection::class; /** * @param Payment $payment diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index 235643af4..d6bb0d96f 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -11,25 +11,34 @@ class PaymentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payments"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'tr_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Payment::class; - } + public static string $resource = Payment::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + public static string $resourceCollection = PaymentCollection::class; /** * Creates a payment in Mollie. diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index fffc1b6df..067cbcb96 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -9,25 +9,34 @@ class PaymentLinkEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payment-links"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'pl_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return PaymentLink::class; - } + public static string $resource = PaymentLink::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PaymentLinkCollection::class; - } + public static string $resourceCollection = PaymentLinkCollection::class; /** * Creates a payment link in Mollie. diff --git a/src/Endpoints/PaymentLinkPaymentEndpoint.php b/src/Endpoints/PaymentLinkPaymentEndpoint.php index b37db7094..99b9eee1d 100644 --- a/src/Endpoints/PaymentLinkPaymentEndpoint.php +++ b/src/Endpoints/PaymentLinkPaymentEndpoint.php @@ -11,17 +11,26 @@ class PaymentLinkPaymentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = 'payment-links_payments'; - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + /** + * Resource class name. + * + * @var string + */ + public static string $resource = Payment::class; - public static function getResourceClass(): string - { - return Payment::class; - } + /** + * The resource collection class name. + * + * @var string + */ + public static string $resourceCollection = PaymentCollection::class; public function pageForId(string $paymentLinkId, string $from = null, int $limit = null, array $filters = []) { diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index ee039734b..9b0548ce7 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -9,23 +9,26 @@ class PaymentRefundEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payments_refunds"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Refund::class; - } + public static string $resource = Refund::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return RefundCollection::class; - } + public static string $resourceCollection = RefundCollection::class; /** * @param Payment $payment diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php index b78cf0319..c1607682a 100644 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ b/src/Endpoints/PaymentRouteEndpoint.php @@ -7,15 +7,19 @@ class PaymentRouteEndpoint extends RestEndpoint { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "payments_routes"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Route::class; - } + public static string $resource = Route::class; /** * @param Payment $payment diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php index 098cef3a5..3e8fe4139 100644 --- a/src/Endpoints/PermissionEndpoint.php +++ b/src/Endpoints/PermissionEndpoint.php @@ -8,23 +8,26 @@ class PermissionEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "permissions"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Permission::class; - } + public static string $resource = Permission::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PermissionCollection::class; - } + public static string $resourceCollection = PermissionCollection::class; /** * Retrieve a single Permission from Mollie. diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index 8e9f470c4..a83f48e31 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -10,27 +10,34 @@ class ProfileEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "profiles"; - protected static $resourceClass = Profile::class; - + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'pfl_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return static::$resourceClass; - } + public static string $resource = Profile::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ProfileCollection::class; - } + public static string $resourceCollection = ProfileCollection::class; /** * Creates a Profile in Mollie. @@ -96,7 +103,7 @@ public function update(string $profileId, array $data = []): ?Profile */ public function getCurrent(array $parameters = []): CurrentProfile { - static::$resourceClass = CurrentProfile::class; + static::$resource = CurrentProfile::class; /** @var CurrentProfile */ return $this->readResource('me', $parameters); diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 2c8995e37..4929f571b 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -9,23 +9,26 @@ class ProfileMethodEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "profiles_methods"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Method::class; - } + public static string $resource = Method::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return MethodCollection::class; - } + public static string $resourceCollection = MethodCollection::class; /** * Enable a method for the provided Profile ID. @@ -48,7 +51,7 @@ public function createForId(string $profileId, string $methodId, array $data = [ ); /** @var Method */ - return ResourceFactory::createFromApiResult($this->client, $result->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), static::getResourceClass()); } /** diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index fa7754d18..b6f4623ac 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -9,23 +9,26 @@ class RefundEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "refunds"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Refund::class; - } + public static string $resource = Refund::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return RefundCollection::class; - } + public static string $resourceCollection = RefundCollection::class; /** * Retrieves a collection of Refunds from Mollie. diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index 2dac8cd99..ad9db7306 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -4,12 +4,15 @@ use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\InteractsWithResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\ResourceFactory; use RuntimeException; abstract class RestEndpoint extends BaseEndpoint { + use InteractsWithResource; + /** * Resource id prefix. * Used to validate resource id's. @@ -32,7 +35,7 @@ protected function createResource(array $body, array $filters): BaseResource $this->parseRequestBody($body) ); - return ResourceFactory::createFromApiResult($this->client, $result->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $result->decode(), static::getResourceClass()); } /** @@ -58,7 +61,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource return null; } - return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); } /** @@ -71,7 +74,7 @@ protected function updateResource(string $id, array $body = []): ?BaseResource */ protected function readResource(string $id, array $filters): BaseResource { - if (! $this instanceof SingleResourceEndpointContract && empty($id)) { + if (!$this instanceof SingleResourceEndpointContract && empty($id)) { throw new ApiException("Invalid resource id."); } @@ -81,7 +84,7 @@ protected function readResource(string $id, array $filters): BaseResource $this->getPathToSingleResource($id) . $this->buildQueryString($filters) ); - return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); } /** @@ -110,7 +113,7 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource return null; } - return ResourceFactory::createFromApiResult($this->client, $response->decode(), $this->getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); } protected function guardAgainstInvalidId(string $id): void @@ -128,15 +131,8 @@ protected function guardAgainstInvalidId(string $id): void public function getResourceType(): string { - $classBasename = basename(str_replace("\\", "/", $this->getResourceClass())); + $classBasename = basename(str_replace("\\", "/", static::getResourceClass())); return strtolower($classBasename); } - - /** - * Get the object that is used by this API endpoint. Every API endpoint uses one type of object. - * - * @return string - */ - abstract public static function getResourceClass(): string; } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 2618e0776..d9bc198ea 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -10,23 +10,26 @@ class SettlementCaptureEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "settlements_captures"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Capture::class; - } + public static string $resource = Capture::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return CaptureCollection::class; - } + public static string $resourceCollection = CaptureCollection::class; /** * Retrieves a collection of Settlement Captures from Mollie. diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 9c87f59c1..a3b3c82b0 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -10,23 +10,26 @@ class SettlementChargebackEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "settlements_chargebacks"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Chargeback::class; - } + public static string $resource = Chargeback::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return ChargebackCollection::class; - } + public static string $resourceCollection = ChargebackCollection::class; /** * Retrieves a collection of Settlement Chargebacks from Mollie. diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index 81d1c4352..b600582da 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -8,23 +8,26 @@ class SettlementPaymentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "settlements_payments"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Payment::class; - } + public static string $resource = Payment::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + public static string $resourceCollection = PaymentCollection::class; /** * Retrieves a collection of Payments from Mollie. diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index f7196ee94..a3f376088 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -10,23 +10,26 @@ class SettlementRefundEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "settlements_refunds"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Refund::class; - } + public static string $resource = Refund::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return RefundCollection::class; - } + public static string $resourceCollection = RefundCollection::class; /** * Retrieves a collection of Settlement Refunds from Mollie. diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 341ed39ea..150fa39ad 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -9,23 +9,26 @@ class SettlementsEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "settlements"; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Settlement::class; - } + public static string $resource = Settlement::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return SettlementCollection::class; - } + public static string $resourceCollection = SettlementCollection::class; /** * Retrieve a single settlement from Mollie. diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index c0fd9b98a..7bdda8897 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -10,25 +10,34 @@ class SubscriptionEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "customers_subscriptions"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'sub_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Subscription::class; - } + public static string $resource = Subscription::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return SubscriptionCollection::class; - } + public static string $resourceCollection = SubscriptionCollection::class; /** * Create a subscription for a Customer diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index b24766ac2..cf870e055 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -10,21 +10,30 @@ class SubscriptionPaymentEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "customers_subscriptions_payments"; - protected $customerId = null; + /** + * Resource class name. + * + * @var string + */ + public static string $resource = Payment::class; - protected $subscriptionId = null; + /** + * The resource collection class name. + * + * @var string + */ + public static string $resourceCollection = PaymentCollection::class; - protected function getResourceCollectionClass(): string - { - return PaymentCollection::class; - } + protected $customerId = null; - public static function getResourceClass(): string - { - return Payment::class; - } + protected $subscriptionId = null; /** * Retrieves a paginated collection of Subscription Payments from Mollie. diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index d86f3a3e4..5a55b67d2 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -9,25 +9,34 @@ class TerminalEndpoint extends EndpointCollection { + /** + * The resource path. + * + * @var string + */ protected string $resourcePath = "terminals"; + /** + * Resource id prefix. + * Used to validate resource id's. + * + * @var string + */ protected static string $resourceIdPrefix = 'term_'; /** - * @inheritDoc + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Terminal::class; - } + public static string $resource = Terminal::class; /** - * @inheritDoc + * The resource collection class name. + * + * @var string */ - protected function getResourceCollectionClass(): string - { - return TerminalCollection::class; - } + public static string $resourceCollection = TerminalCollection::class; /** * Retrieve terminal from Mollie. diff --git a/src/InteractsWithResource.php b/src/InteractsWithResource.php new file mode 100644 index 000000000..b6a5b5198 --- /dev/null +++ b/src/InteractsWithResource.php @@ -0,0 +1,22 @@ +client, $filteredItems, $this->_links); } + public static function getCollectionResourceName(): string + { + if (empty(static::$collectionName)) { + throw new \RuntimeException('Collection name not set'); + } - abstract public static function getCollectionResourceName(): ?string; + return static::$collectionName; + } } diff --git a/src/Resources/CaptureCollection.php b/src/Resources/CaptureCollection.php index ab2179d74..61e8e641a 100644 --- a/src/Resources/CaptureCollection.php +++ b/src/Resources/CaptureCollection.php @@ -5,18 +5,16 @@ class CaptureCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "captures"; - } + public static string $collectionName = "captures"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Capture::class; - } + public static string $resource = Capture::class; } diff --git a/src/Resources/ChargebackCollection.php b/src/Resources/ChargebackCollection.php index 579a77807..7a1c0410e 100644 --- a/src/Resources/ChargebackCollection.php +++ b/src/Resources/ChargebackCollection.php @@ -5,18 +5,16 @@ class ChargebackCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "chargebacks"; - } + public static string $collectionName = "chargebacks"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Chargeback::class; - } + public static string $resource = Chargeback::class; } diff --git a/src/Resources/ClientCollection.php b/src/Resources/ClientCollection.php index 68e8165e7..b2eee4856 100644 --- a/src/Resources/ClientCollection.php +++ b/src/Resources/ClientCollection.php @@ -5,18 +5,16 @@ class ClientCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "clients"; - } + public static string $collectionName = "clients"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Client::class; - } + public static string $resource = Client::class; } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 67f7d522d..2b4c398ec 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -5,11 +5,12 @@ use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\ResponseStatusCode; +use Mollie\Api\InteractsWithResource; use Mollie\Api\MollieApiClient; abstract class CursorCollection extends BaseCollection { - abstract public static function getResourceClass(): string; + use InteractsWithResource; /** * Return the next set of resources when available @@ -19,7 +20,7 @@ abstract public static function getResourceClass(): string; */ final public function next(): ?CursorCollection { - if (! $this->hasNext()) { + if (!$this->hasNext()) { return null; } @@ -34,7 +35,7 @@ final public function next(): ?CursorCollection */ final public function previous(): ?CursorCollection { - if (! $this->hasPrevious()) { + if (!$this->hasPrevious()) { return null; } @@ -55,7 +56,7 @@ private function fetchCollection(string $url): CursorCollection return ResourceFactory::createCursorResourceCollection( $this->client, - $data->_embedded->{$this->getCollectionResourceName()}, + $data->_embedded->{static::getCollectionResourceName()}, static::getResourceClass(), $data->_links ); @@ -98,7 +99,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { break; } diff --git a/src/Resources/CustomerCollection.php b/src/Resources/CustomerCollection.php index 8204a2594..cc3513b89 100644 --- a/src/Resources/CustomerCollection.php +++ b/src/Resources/CustomerCollection.php @@ -5,18 +5,16 @@ class CustomerCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "customers"; - } + public static string $collectionName = "customers"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Customer::class; - } + public static string $resource = Customer::class; } diff --git a/src/Resources/InvoiceCollection.php b/src/Resources/InvoiceCollection.php index 20d3c2148..89de8f59b 100644 --- a/src/Resources/InvoiceCollection.php +++ b/src/Resources/InvoiceCollection.php @@ -5,18 +5,16 @@ class InvoiceCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "invoices"; - } + public static string $collectionName = "invoices"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Invoice::class; - } + public static string $resource = Invoice::class; } diff --git a/src/Resources/IssuerCollection.php b/src/Resources/IssuerCollection.php index 520d1446f..c7223b8a7 100644 --- a/src/Resources/IssuerCollection.php +++ b/src/Resources/IssuerCollection.php @@ -4,11 +4,4 @@ class IssuerCollection extends BaseCollection { - /** - * @return null|string - */ - public static function getCollectionResourceName(): ?string - { - return null; - } } diff --git a/src/Resources/MandateCollection.php b/src/Resources/MandateCollection.php index 3a351600c..8bf5fc74b 100644 --- a/src/Resources/MandateCollection.php +++ b/src/Resources/MandateCollection.php @@ -5,20 +5,18 @@ class MandateCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "mandates"; - } + public static string $collectionName = "mandates"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Mandate::class; - } + public static string $resource = Mandate::class; /** * @param string $status diff --git a/src/Resources/MethodCollection.php b/src/Resources/MethodCollection.php index b2c294fd2..0194f862c 100644 --- a/src/Resources/MethodCollection.php +++ b/src/Resources/MethodCollection.php @@ -5,10 +5,9 @@ class MethodCollection extends BaseCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "methods"; - } + public static string $collectionName = "methods"; } diff --git a/src/Resources/MethodPriceCollection.php b/src/Resources/MethodPriceCollection.php index 22e83a1f3..68ea66c14 100644 --- a/src/Resources/MethodPriceCollection.php +++ b/src/Resources/MethodPriceCollection.php @@ -4,11 +4,4 @@ class MethodPriceCollection extends BaseCollection { - /** - * @return null|string - */ - public static function getCollectionResourceName(): ?string - { - return null; - } } diff --git a/src/Resources/OrderCollection.php b/src/Resources/OrderCollection.php index 986e183ad..a5889220a 100644 --- a/src/Resources/OrderCollection.php +++ b/src/Resources/OrderCollection.php @@ -5,18 +5,16 @@ class OrderCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "orders"; - } + public static string $collectionName = "orders"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Order::class; - } + public static string $resource = Order::class; } diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php index bf9d76b75..aad7e387e 100644 --- a/src/Resources/OrderLineCollection.php +++ b/src/Resources/OrderLineCollection.php @@ -4,14 +4,6 @@ class OrderLineCollection extends BaseCollection { - /** - * @return null|string - */ - public static function getCollectionResourceName(): ?string - { - return null; - } - /** * Get a specific order line. * Returns null if the order line cannot be found. diff --git a/src/Resources/PaymentCollection.php b/src/Resources/PaymentCollection.php index 5109e3b4b..f31b78f8d 100644 --- a/src/Resources/PaymentCollection.php +++ b/src/Resources/PaymentCollection.php @@ -5,18 +5,16 @@ class PaymentCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "payments"; - } + public static string $collectionName = "payments"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Payment::class; - } + public static string $resource = Payment::class; } diff --git a/src/Resources/PaymentLinkCollection.php b/src/Resources/PaymentLinkCollection.php index 598457bd1..1113b60dd 100644 --- a/src/Resources/PaymentLinkCollection.php +++ b/src/Resources/PaymentLinkCollection.php @@ -5,18 +5,16 @@ class PaymentLinkCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "payment_links"; - } + public static string $collectionName = "payment_links"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return PaymentLink::class; - } + public static string $resource = PaymentLink::class; } diff --git a/src/Resources/PermissionCollection.php b/src/Resources/PermissionCollection.php index 78aa24b87..08fa05dee 100644 --- a/src/Resources/PermissionCollection.php +++ b/src/Resources/PermissionCollection.php @@ -5,10 +5,9 @@ class PermissionCollection extends BaseCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "permissions"; - } + public static string $collectionName = "permissions"; } diff --git a/src/Resources/ProfileCollection.php b/src/Resources/ProfileCollection.php index 969aaccfe..fbe586e55 100644 --- a/src/Resources/ProfileCollection.php +++ b/src/Resources/ProfileCollection.php @@ -5,18 +5,16 @@ class ProfileCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "profiles"; - } + public static string $collectionName = "profiles"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Profile::class; - } + public static string $resource = Profile::class; } diff --git a/src/Resources/RefundCollection.php b/src/Resources/RefundCollection.php index df27ce026..0d1cd3c97 100644 --- a/src/Resources/RefundCollection.php +++ b/src/Resources/RefundCollection.php @@ -5,18 +5,16 @@ class RefundCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "refunds"; - } + public static string $collectionName = "refunds"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Refund::class; - } + public static string $resource = Refund::class; } diff --git a/src/Resources/SettlementCollection.php b/src/Resources/SettlementCollection.php index 21367a1d4..dd759f684 100644 --- a/src/Resources/SettlementCollection.php +++ b/src/Resources/SettlementCollection.php @@ -5,18 +5,16 @@ class SettlementCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "settlements"; - } + public static string $collectionName = "settlements"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Settlement::class; - } + public static string $resource = Settlement::class; } diff --git a/src/Resources/ShipmentCollection.php b/src/Resources/ShipmentCollection.php index d2c52c52d..5bf66633c 100644 --- a/src/Resources/ShipmentCollection.php +++ b/src/Resources/ShipmentCollection.php @@ -5,10 +5,9 @@ class ShipmentCollection extends BaseCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return 'shipments'; - } + public static string $collectionName = 'shipments'; } diff --git a/src/Resources/SubscriptionCollection.php b/src/Resources/SubscriptionCollection.php index d4288d6f9..f1799621a 100644 --- a/src/Resources/SubscriptionCollection.php +++ b/src/Resources/SubscriptionCollection.php @@ -5,18 +5,16 @@ class SubscriptionCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "subscriptions"; - } + public static string $collectionName = "subscriptions"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Subscription::class; - } + public static string $resource = Subscription::class; } diff --git a/src/Resources/TerminalCollection.php b/src/Resources/TerminalCollection.php index ad198fca4..6aa47ce9a 100644 --- a/src/Resources/TerminalCollection.php +++ b/src/Resources/TerminalCollection.php @@ -5,18 +5,16 @@ class TerminalCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. + * + * @var string */ - public static function getCollectionResourceName(): string - { - return "terminals"; - } + public static string $collectionName = "terminals"; /** - * @return string + * Resource class name. + * + * @var string */ - public static function getResourceClass(): string - { - return Terminal::class; - } + public static string $resource = Terminal::class; } From 4f0346a88c041de4033554f652d46bc90025bb80 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 17 Jul 2024 23:55:32 +0200 Subject: [PATCH 040/131] wip --- src/Endpoints/IsDependableOnParent.php | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/Endpoints/IsDependableOnParent.php diff --git a/src/Endpoints/IsDependableOnParent.php b/src/Endpoints/IsDependableOnParent.php deleted file mode 100644 index 0aeeda76f..000000000 --- a/src/Endpoints/IsDependableOnParent.php +++ /dev/null @@ -1,18 +0,0 @@ -parentId; - } -} From 2543eefe86819a85127c21af30aa55604eb34b22 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 17 Jul 2024 23:57:13 +0200 Subject: [PATCH 041/131] wip --- src/Endpoints/MethodIssuerEndpoint.php | 1 + src/Endpoints/SubscriptionPaymentEndpoint.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php index 61947a449..ad90f4aa1 100644 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ b/src/Endpoints/MethodIssuerEndpoint.php @@ -40,6 +40,7 @@ public function enable(string $profileId, string $methodId, string $issuerId) $this->methodId = $methodId; $this->issuerId = $issuerId; + /** @var Issuer */ $response = $this->createResource([], []); $this->resetResourceIds(); diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php index cf870e055..92485a0ec 100644 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ b/src/Endpoints/SubscriptionPaymentEndpoint.php @@ -57,6 +57,7 @@ public function pageForIds( $this->customerId = $customerId; $this->subscriptionId = $subscriptionId; + /** @var PaymentCollection */ return $this->fetchCollection($from, $limit, $parameters); } From 987185a4836e0df47fa92d2de3fb08399db6b1c9 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 18 Jul 2024 10:54:36 +0200 Subject: [PATCH 042/131] add changelog action --- .github/workflows/update-changelog.yml | 28 ++++++++++++++++++++++++++ CHANGELOG.md | 8 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 .github/workflows/update-changelog.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 000000000..0cdea2336 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..20456c3d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased](https://github.com/mollie/mollie-api-php/compare/v3.0.0...HEAD) From c8300c71a92a7f965af7e5c78fdfa173bfd94e92 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 18 Jul 2024 17:10:25 +0200 Subject: [PATCH 043/131] wip --- src/Contracts/HasBody.php | 13 ++ src/Contracts/IsIteratable.php | 10 ++ src/Http/BaseEndpointCollection.php | 119 ++++++++++++++++++ .../BalanceEndpointCollection.php | 20 +++ .../PaymentEndpointCollection.php | 77 ++++++++++++ .../PaymentRefundEndpointCollection.php | 25 ++++ src/Http/Request.php | 53 ++++++++ .../Requests/GetPaginatedBalancesRequest.php | 34 +++++ .../GetPaginatedPaymentRefundsRequest.php | 40 ++++++ .../Requests/GetPaginatedPaymentsRequest.php | 36 ++++++ src/Http/Requests/GetPaymentRequest.php | 52 ++++++++ src/Http/Requests/HasJsonBody.php | 13 ++ src/Http/Requests/IsIteratableRequest.php | 34 +++++ src/Http/Requests/IsPaginatedRequest.php | 30 +++++ src/Http/Requests/RefundPaymentRequest.php | 38 ++++++ src/MollieApiClient.php | 15 ++- 16 files changed, 606 insertions(+), 3 deletions(-) create mode 100644 src/Contracts/HasBody.php create mode 100644 src/Contracts/IsIteratable.php create mode 100644 src/Http/BaseEndpointCollection.php create mode 100644 src/Http/EndpointCollection/BalanceEndpointCollection.php create mode 100644 src/Http/EndpointCollection/PaymentEndpointCollection.php create mode 100644 src/Http/EndpointCollection/PaymentRefundEndpointCollection.php create mode 100644 src/Http/Request.php create mode 100644 src/Http/Requests/GetPaginatedBalancesRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentRefundsRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentsRequest.php create mode 100644 src/Http/Requests/GetPaymentRequest.php create mode 100644 src/Http/Requests/HasJsonBody.php create mode 100644 src/Http/Requests/IsIteratableRequest.php create mode 100644 src/Http/Requests/IsPaginatedRequest.php create mode 100644 src/Http/Requests/RefundPaymentRequest.php diff --git a/src/Contracts/HasBody.php b/src/Contracts/HasBody.php new file mode 100644 index 000000000..41def4b49 --- /dev/null +++ b/src/Contracts/HasBody.php @@ -0,0 +1,13 @@ +client = $client; + } + + public function send(Request $request): mixed + { + $path = $request->resolveResourcePath() + . $this->buildQueryString($request->getQuery()); + + $body = $request instanceof HasBody + ? $request->getBody() + : null; + + $result = $this->client->performHttpCall( + $request->getMethod(), + $path, + $body + ); + + if ($result->isEmpty()) { + return null; + } + + $targetResourceClass = $request->getTargetResourceClass(); + + if (is_subclass_of($targetResourceClass, BaseCollection::class)) { + $collection = $this->buildResultCollection($result->decode(), $targetResourceClass); + + if ($request instanceof IsIteratable && $request->iteratorEnabled()) { + /** @var CursorCollection $collection */ + return $collection->getAutoIterator($request->iteratesBackwards()); + } + + return $collection; + } + + if (is_subclass_of($targetResourceClass, BaseResource::class)) { + return ResourceFactory::createFromApiResult($this->client, $result->decode(), $targetResourceClass); + } + + return null; + } + + protected function buildResultCollection(object $result, string $targetCollectionClass): BaseCollection + { + return ResourceFactory::createBaseResourceCollection( + $this->client, + ($targetCollectionClass)::getResourceClass(), + $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, + $result->_links, + $targetCollectionClass + ); + } + + /** + * Create a generator for iterating over a resource's collection using REST API calls. + * + * This function fetches paginated data from a RESTful resource endpoint and returns a generator + * that allows you to iterate through the items in the collection one by one. It supports forward + * and backward iteration, pagination, and filtering. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $filters + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * @return LazyCollection + */ + protected function createIterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + /** @var CursorCollection $page */ + $page = $this->fetchCollection($from, $limit, $filters); + + return $page->getAutoIterator($iterateBackwards); + } + + /** + * @param array $filters + * @return string + */ + protected function buildQueryString(array $filters): string + { + if (empty($filters)) { + return ""; + } + + foreach ($filters as $key => $value) { + if ($value === true) { + $filters[$key] = "true"; + } + + if ($value === false) { + $filters[$key] = "false"; + } + } + + return "?" . http_build_query($filters, "", "&"); + } +} diff --git a/src/Http/EndpointCollection/BalanceEndpointCollection.php b/src/Http/EndpointCollection/BalanceEndpointCollection.php new file mode 100644 index 000000000..288f17bad --- /dev/null +++ b/src/Http/EndpointCollection/BalanceEndpointCollection.php @@ -0,0 +1,20 @@ +send(new GetPaginatedBalancesRequest($from, $limit, $parameters)); + } +} diff --git a/src/Http/EndpointCollection/PaymentEndpointCollection.php b/src/Http/EndpointCollection/PaymentEndpointCollection.php new file mode 100644 index 000000000..fec8d3102 --- /dev/null +++ b/src/Http/EndpointCollection/PaymentEndpointCollection.php @@ -0,0 +1,77 @@ +send(new GetPaginatedPaymentsRequest($from, $limit, $filters)); + } + + /** + * Retrieve a single payment from Mollie. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * + * @param string $paymentId + * @param array $filters + * + * @return Payment + * @throws ApiException + */ + public function get(string $paymentId, array $filters = []): Payment + { + return $this->send(new GetPaymentRequest($paymentId, $filters)); + } + + /** + * Issue a refund for the given payment. + * + * The $data parameter may either be an array of endpoint parameters, a float value to + * initiate a partial refund, or empty to do a full refund. + * + * @param Payment $payment + * @param array|float|null $data + * + * @return Refund + * @throws ApiException + */ + public function refund(Payment $payment, $data = []): Refund + { + return $this->send(new RefundPaymentRequest($payment->id, $data)); + } + + /** + * Create an iterator for iterating over payments retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $filters + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return LazyCollection + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + return $this->send( + (new GetPaginatedPaymentsRequest($from, $limit, $filters)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php b/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php new file mode 100644 index 000000000..b74aa3750 --- /dev/null +++ b/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php @@ -0,0 +1,25 @@ +send(new GetPaginatedPaymentRefundsRequest( + $paymentId, + $filters + )); + } +} diff --git a/src/Http/Request.php b/src/Http/Request.php new file mode 100644 index 000000000..b0dfe4a90 --- /dev/null +++ b/src/Http/Request.php @@ -0,0 +1,53 @@ +method)) { + throw new LogicException('Your request is missing a HTTP method. You must add a method property like [protected Method $method = Method::GET]'); + } + + return $this->method; + } + + public function getQuery(): array + { + return []; + } + + public static function getTargetResourceClass(): string + { + if (empty(static::$targetResourceClass)) { + throw new \RuntimeException('Resource class is not set.'); + } + + return static::$targetResourceClass; + } + + /** + * Resolve the resource path. + * + * @return string + */ + abstract public function resolveResourcePath(): string; +} diff --git a/src/Http/Requests/GetPaginatedBalancesRequest.php b/src/Http/Requests/GetPaginatedBalancesRequest.php new file mode 100644 index 000000000..9339e2291 --- /dev/null +++ b/src/Http/Requests/GetPaginatedBalancesRequest.php @@ -0,0 +1,34 @@ +paymentId = $paymentId; + $this->filters = $filters; + } + + public function resolveResourcePath(): string + { + $id = urlencode($this->paymentId); + + return "payments/{$id}/refunds"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php new file mode 100644 index 000000000..03e2dc075 --- /dev/null +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -0,0 +1,36 @@ +paymentId = $paymentId; + $this->filters = $filters; + } + + /** + * Resolve the resource path. + * + * @return string + */ + public function resolveResourcePath(): string + { + $id = urlencode($this->paymentId); + + return "payments/{$id}"; + } + + public function getQuery(): array + { + return $this->filters; + } +} diff --git a/src/Http/Requests/HasJsonBody.php b/src/Http/Requests/HasJsonBody.php new file mode 100644 index 000000000..684abe73e --- /dev/null +++ b/src/Http/Requests/HasJsonBody.php @@ -0,0 +1,13 @@ +body); + } +} diff --git a/src/Http/Requests/IsIteratableRequest.php b/src/Http/Requests/IsIteratableRequest.php new file mode 100644 index 000000000..e428021ba --- /dev/null +++ b/src/Http/Requests/IsIteratableRequest.php @@ -0,0 +1,34 @@ +iteratorEnabled; + } + + public function iteratesBackwards(): bool + { + return $this->iterateBackwards; + } + + public function useIterator(): self + { + $this->iteratorEnabled = true; + + return $this; + } + + public function setIterationDirection(bool $iterateBackwards = false): self + { + $this->iterateBackwards = $iterateBackwards; + + return $this; + } +} diff --git a/src/Http/Requests/IsPaginatedRequest.php b/src/Http/Requests/IsPaginatedRequest.php new file mode 100644 index 000000000..b3d5c02ad --- /dev/null +++ b/src/Http/Requests/IsPaginatedRequest.php @@ -0,0 +1,30 @@ +from = $from; + $this->limit = $limit; + $this->filters = $filters; + } + + public function getQuery(): array + { + return array_merge([ + 'from' => $this->from, + 'limit' => $this->limit, + ], $this->filters); + } +} diff --git a/src/Http/Requests/RefundPaymentRequest.php b/src/Http/Requests/RefundPaymentRequest.php new file mode 100644 index 000000000..d45e19c31 --- /dev/null +++ b/src/Http/Requests/RefundPaymentRequest.php @@ -0,0 +1,38 @@ +paymentId = $paymentId; + $this->body = $data; + } + + public function resolveResourcePath(): string + { + $id = urlencode($this->paymentId); + + return "payments/{$id}/refunds"; + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index f5dd3db07..cf9ce6bd3 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -48,7 +48,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\IncompatiblePlatform; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; +use Mollie\Api\Http\EndpointCollection\BalanceEndpointCollection; +use Mollie\Api\Http\EndpointCollection\PaymentEndpointCollection; +use Mollie\Api\Contracts\HasBody; +use Mollie\Api\Http\EndpointCollection\PaymentRefundEndpointCollection; use Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract; +use Mollie\Api\Http\Request; /** * @property BalanceEndpoint $balances @@ -177,7 +182,11 @@ public function __construct( private function initializeEndpoints(): void { $endpointClasses = [ - 'balances' => BalanceEndpoint::class, + 'balances' => BalanceEndpointCollection::class, + 'payments' => PaymentEndpointCollection::class, + 'paymentRefunds' => PaymentRefundEndpointCollection::class, + + // 'balances' => BalanceEndpoint::class, 'balanceReports' => BalanceReportEndpoint::class, 'balanceTransactions' => BalanceTransactionEndpoint::class, 'chargebacks' => ChargebackEndpoint::class, @@ -200,9 +209,9 @@ private function initializeEndpoints(): void 'paymentChargebacks' => PaymentChargebackEndpoint::class, 'paymentLinks' => PaymentLinkEndpoint::class, 'paymentLinkPayments' => PaymentLinkPaymentEndpoint::class, - 'paymentRefunds' => PaymentRefundEndpoint::class, + // 'paymentRefunds' => PaymentRefundEndpoint::class, 'paymentRoutes' => PaymentRouteEndpoint::class, - 'payments' => PaymentEndpoint::class, + // 'payments' => PaymentEndpoint::class, 'permissions' => PermissionEndpoint::class, 'profiles' => ProfileEndpoint::class, 'profileMethods' => ProfileMethodEndpoint::class, From 6f004b8c062138f27319f9453b40dc2c17f3e983 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 18 Jul 2024 17:14:22 +0200 Subject: [PATCH 044/131] wip --- src/Http/BaseEndpointCollection.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/Http/BaseEndpointCollection.php b/src/Http/BaseEndpointCollection.php index 232a7fd9a..24004ca14 100644 --- a/src/Http/BaseEndpointCollection.php +++ b/src/Http/BaseEndpointCollection.php @@ -73,27 +73,6 @@ protected function buildResultCollection(object $result, string $targetCollectio ); } - /** - * Create a generator for iterating over a resource's collection using REST API calls. - * - * This function fetches paginated data from a RESTful resource endpoint and returns a generator - * that allows you to iterate through the items in the collection one by one. It supports forward - * and backward iteration, pagination, and filtering. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $filters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * @return LazyCollection - */ - protected function createIterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection - { - /** @var CursorCollection $page */ - $page = $this->fetchCollection($from, $limit, $filters); - - return $page->getAutoIterator($iterateBackwards); - } - /** * @param array $filters * @return string From c477530aadd978d4454e285d6dd9c0b59ea60cf4 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 26 Aug 2024 16:55:52 +0200 Subject: [PATCH 045/131] wip --- composer.json | 1 + src/Contracts/Rule.php | 10 ++ src/Contracts/ValidatableData.php | 8 ++ src/Http/BaseEndpointCollection.php | 98 ------------------- src/Http/Endpoint.php | 45 +++++++++ .../BalanceEndpointCollection.php | 30 +++++- .../PaymentEndpointCollection.php | 81 +++++++++++---- .../PaymentRefundEndpointCollection.php | 3 +- src/Http/HandlesQueries.php | 28 ++++++ src/Http/HandlesResourceBuilding.php | 65 ++++++++++++ src/Http/HandlesValidation.php | 39 ++++++++ src/Http/Requests/CreatePaymentRequest.php | 32 ++++++ ...est.php => CreateRefundPaymentRequest.php} | 15 +-- .../Requests/GetPaginatedBalancesRequest.php | 11 +-- .../GetPaginatedPaymentRefundsRequest.php | 17 +--- .../Requests/GetPaginatedPaymentsRequest.php | 16 +-- src/Http/Requests/GetPaymentRequest.php | 4 +- src/Http/Requests/JsonPostRequest.php | 26 +++++ ...inatedRequest.php => PaginatedRequest.php} | 13 ++- src/Http/{ => Requests}/Request.php | 2 +- src/Http/Requests/UpdatePaymentRequest.php | 27 +++++ src/Http/Rules/InvalidIdRule.php | 35 +++++++ src/MollieApiClient.php | 11 +-- src/Resources/Payment.php | 7 ++ 24 files changed, 434 insertions(+), 190 deletions(-) create mode 100644 src/Contracts/Rule.php create mode 100644 src/Contracts/ValidatableData.php delete mode 100644 src/Http/BaseEndpointCollection.php create mode 100644 src/Http/Endpoint.php create mode 100644 src/Http/HandlesQueries.php create mode 100644 src/Http/HandlesResourceBuilding.php create mode 100644 src/Http/HandlesValidation.php create mode 100644 src/Http/Requests/CreatePaymentRequest.php rename src/Http/Requests/{RefundPaymentRequest.php => CreateRefundPaymentRequest.php} (63%) create mode 100644 src/Http/Requests/JsonPostRequest.php rename src/Http/Requests/{IsPaginatedRequest.php => PaginatedRequest.php} (70%) rename src/Http/{ => Requests}/Request.php (96%) create mode 100644 src/Http/Requests/UpdatePaymentRequest.php create mode 100644 src/Http/Rules/InvalidIdRule.php diff --git a/composer.json b/composer.json index b613efd4a..08b80df5a 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,7 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", + "laravel/pint": "^1.17", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.6" }, diff --git a/src/Contracts/Rule.php b/src/Contracts/Rule.php new file mode 100644 index 000000000..7e2219679 --- /dev/null +++ b/src/Contracts/Rule.php @@ -0,0 +1,10 @@ +client = $client; - } - - public function send(Request $request): mixed - { - $path = $request->resolveResourcePath() - . $this->buildQueryString($request->getQuery()); - - $body = $request instanceof HasBody - ? $request->getBody() - : null; - - $result = $this->client->performHttpCall( - $request->getMethod(), - $path, - $body - ); - - if ($result->isEmpty()) { - return null; - } - - $targetResourceClass = $request->getTargetResourceClass(); - - if (is_subclass_of($targetResourceClass, BaseCollection::class)) { - $collection = $this->buildResultCollection($result->decode(), $targetResourceClass); - - if ($request instanceof IsIteratable && $request->iteratorEnabled()) { - /** @var CursorCollection $collection */ - return $collection->getAutoIterator($request->iteratesBackwards()); - } - - return $collection; - } - - if (is_subclass_of($targetResourceClass, BaseResource::class)) { - return ResourceFactory::createFromApiResult($this->client, $result->decode(), $targetResourceClass); - } - - return null; - } - - protected function buildResultCollection(object $result, string $targetCollectionClass): BaseCollection - { - return ResourceFactory::createBaseResourceCollection( - $this->client, - ($targetCollectionClass)::getResourceClass(), - $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, - $result->_links, - $targetCollectionClass - ); - } - - /** - * @param array $filters - * @return string - */ - protected function buildQueryString(array $filters): string - { - if (empty($filters)) { - return ""; - } - - foreach ($filters as $key => $value) { - if ($value === true) { - $filters[$key] = "true"; - } - - if ($value === false) { - $filters[$key] = "false"; - } - } - - return "?" . http_build_query($filters, "", "&"); - } -} diff --git a/src/Http/Endpoint.php b/src/Http/Endpoint.php new file mode 100644 index 000000000..125b3c498 --- /dev/null +++ b/src/Http/Endpoint.php @@ -0,0 +1,45 @@ +client = $client; + } + + public function send(Request $request): mixed + { + $this->validate($request); + + $path = $request->resolveResourcePath() + .$this->buildQueryString($request->getQuery()); + + $body = $request instanceof HasBody + ? $request->getBody() + : null; + + $result = $this->client->performHttpCall( + $request->getMethod(), + $path, + $body + ); + + if ($result->isEmpty()) { + return null; + } + + return $this->build($request, $result); + } +} diff --git a/src/Http/EndpointCollection/BalanceEndpointCollection.php b/src/Http/EndpointCollection/BalanceEndpointCollection.php index 288f17bad..3bca16c6f 100644 --- a/src/Http/EndpointCollection/BalanceEndpointCollection.php +++ b/src/Http/EndpointCollection/BalanceEndpointCollection.php @@ -2,19 +2,41 @@ namespace Mollie\Api\Http\EndpointCollection; -use Mollie\Api\Http\BaseEndpointCollection; use Mollie\Api\Http\Requests\GetPaginatedBalancesRequest; +use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; -class BalanceEndpointCollection extends BaseEndpointCollection +class BalanceEndpointCollection extends Endpoint { /** * Get the balance endpoint. * - * @return BalanceEndpoint + * @return BalanceCollection */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection { - return $this->send(new GetPaginatedBalancesRequest($from, $limit, $parameters)); + return $this->send(new GetPaginatedBalancesRequest( + filters: $parameters, + from: $from, + limit: $limit + )); + } + + /** + * Retrieve a single balance from Mollie. + * + * Will throw an ApiException if the balance id is invalid or the resource cannot be found. + * + * @param string $balanceId + * @param array $parameters + * @return Balance + * @throws ApiException + */ + public function get(string $balanceId, array $parameters = []): Balance + { + $this->guardAgainstInvalidId($balanceId); + + /** @var Balance */ + return $this->readResource($balanceId, $parameters); } } diff --git a/src/Http/EndpointCollection/PaymentEndpointCollection.php b/src/Http/EndpointCollection/PaymentEndpointCollection.php index fec8d3102..4e365a34f 100644 --- a/src/Http/EndpointCollection/PaymentEndpointCollection.php +++ b/src/Http/EndpointCollection/PaymentEndpointCollection.php @@ -2,25 +2,61 @@ namespace Mollie\Api\Http\EndpointCollection; -use Mollie\Api\Http\BaseEndpointCollection; +use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Endpoint; +use Mollie\Api\Http\Requests\CreatePaymentRequest; +use Mollie\Api\Http\Requests\CreateRefundPaymentRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest; use Mollie\Api\Http\Requests\GetPaymentRequest; -use Mollie\Api\Http\Requests\RefundPaymentRequest; +use Mollie\Api\Http\Requests\UpdatePaymentRequest; +use Mollie\Api\Http\Rules\InvalidIdRule; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -class PaymentEndpointCollection extends BaseEndpointCollection +class PaymentEndpointCollection extends Endpoint { /** - * Get the balance endpoint. + * Creates a payment in Mollie. + * + * @param array $data An array containing details on the payment. * - * @return PaymentCollection + * @throws ApiException + */ + public function create(array $data = [], array $filters = []): Payment + { + /** @var Payment */ + return $this->send(new CreatePaymentRequest($data, $filters)); + } + + /** + * Update the given Payment. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * + * @param string $paymentId + * + * @throws ApiException + */ + public function update($paymentId, array $data = []): ?Payment + { + /** @var null|Payment */ + return $this + ->validateWith(new InvalidIdRule(id: $paymentId, prefix: Payment::$resourceIdPrefix)) + ->send(new UpdatePaymentRequest($paymentId, $data)); + } + + /** + * Get the balance endpoint. */ public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { - return $this->send(new GetPaginatedPaymentsRequest($from, $limit, $filters)); + return $this->send(new GetPaginatedPaymentsRequest( + filters: $filters, + from: $from, + limit: $limit + )); } /** @@ -28,15 +64,14 @@ public function page(?string $from = null, ?int $limit = null, array $filters = * * Will throw a ApiException if the payment id is invalid or the resource cannot be found. * - * @param string $paymentId - * @param array $filters * - * @return Payment * @throws ApiException */ public function get(string $paymentId, array $filters = []): Payment { - return $this->send(new GetPaymentRequest($paymentId, $filters)); + return $this + ->validateWith(new InvalidIdRule(id: $paymentId, prefix: Payment::$resourceIdPrefix)) + ->send(new GetPaymentRequest($paymentId, $filters)); } /** @@ -45,33 +80,37 @@ public function get(string $paymentId, array $filters = []): Payment * The $data parameter may either be an array of endpoint parameters, a float value to * initiate a partial refund, or empty to do a full refund. * - * @param Payment $payment - * @param array|float|null $data + * @param array|float|null $data * - * @return Refund * @throws ApiException */ public function refund(Payment $payment, $data = []): Refund { - return $this->send(new RefundPaymentRequest($payment->id, $data)); + return $this->send(new CreateRefundPaymentRequest($payment->id, $data)); } /** * Create an iterator for iterating over payments retrieved from Mollie. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $filters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { return $this->send( - (new GetPaginatedPaymentsRequest($from, $limit, $filters)) + (new GetPaginatedPaymentsRequest(filters: $filters, from: $from, limit: $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ); } + + /** + * @todo: Implement the rules method. Standardize request ids! + */ + protected function rules(Request $request): array + { + return [ + new InvalidIdRule(id: $request->getId(), prefix: Payment::$resourceIdPrefix), + ]; + } } diff --git a/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php b/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php index b74aa3750..d24fb6e2d 100644 --- a/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php @@ -2,11 +2,10 @@ namespace Mollie\Api\Http\EndpointCollection; -use Mollie\Api\Http\BaseEndpointCollection; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Resources\RefundCollection; -class PaymentRefundEndpointCollection extends BaseEndpointCollection +class PaymentRefundEndpointCollection extends Endpoint { /** * @param string $paymentId diff --git a/src/Http/HandlesQueries.php b/src/Http/HandlesQueries.php new file mode 100644 index 000000000..4be333906 --- /dev/null +++ b/src/Http/HandlesQueries.php @@ -0,0 +1,28 @@ + $value) { + if ($value === true) { + $filters[$key] = 'true'; + } + + if ($value === false) { + $filters[$key] = 'false'; + } + } + + return '?'.http_build_query($filters, '', '&'); + } +} diff --git a/src/Http/HandlesResourceBuilding.php b/src/Http/HandlesResourceBuilding.php new file mode 100644 index 000000000..046b9b252 --- /dev/null +++ b/src/Http/HandlesResourceBuilding.php @@ -0,0 +1,65 @@ +decode(); + $targetResourceClass = $request->getTargetResourceClass(); + + if ($this->isCollectionTarget($targetResourceClass)) { + $collection = $this->buildResultCollection($decodedResponse, $targetResourceClass); + + return $this->unwrapIterator($request, $collection); + } + + if ($this->isResourceTarget($targetResourceClass)) { + return ResourceFactory::createFromApiResult($this->client, $decodedResponse, $targetResourceClass); + } + + return null; + } + + private function unwrapIterator(Request $request, BaseCollection $collection): BaseCollection|LazyCollection + { + if ($request instanceof IsIteratable && $request->iteratorEnabled()) { + /** @var CursorCollection $collection */ + return $collection->getAutoIterator($request->iteratesBackwards()); + } + + return $collection; + } + + private function buildResultCollection(object $result, string $targetCollectionClass): BaseCollection + { + return ResourceFactory::createBaseResourceCollection( + $this->client, + ($targetCollectionClass)::getResourceClass(), + $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, + $result->_links, + $targetCollectionClass + ); + } + + private function isCollectionTarget(string $targetResourceClass): bool + { + return is_subclass_of($targetResourceClass, BaseCollection::class); + } + + private function isResourceTarget(string $targetResourceClass): bool + { + return is_subclass_of($targetResourceClass, BaseResource::class); + } +} diff --git a/src/Http/HandlesValidation.php b/src/Http/HandlesValidation.php new file mode 100644 index 000000000..cf834f330 --- /dev/null +++ b/src/Http/HandlesValidation.php @@ -0,0 +1,39 @@ +rules = $rules; + + return $this; + } + + protected function validate(Request $request): void + { + /** @var Rule $rule */ + foreach ($this->rules as $rule) { + $rule->validate($request); + } + } + + protected function rules(): array + { + return []; + } + + private function getRules(): array + { + return array_merge($this->rules(), $this->rules); + } +} diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php new file mode 100644 index 000000000..7696fc71f --- /dev/null +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -0,0 +1,32 @@ +body = $body; + $this->include = $include; + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return 'payments'; + } +} diff --git a/src/Http/Requests/RefundPaymentRequest.php b/src/Http/Requests/CreateRefundPaymentRequest.php similarity index 63% rename from src/Http/Requests/RefundPaymentRequest.php rename to src/Http/Requests/CreateRefundPaymentRequest.php index d45e19c31..d81d587ac 100644 --- a/src/Http/Requests/RefundPaymentRequest.php +++ b/src/Http/Requests/CreateRefundPaymentRequest.php @@ -2,20 +2,10 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Contracts\HasBody; -use Mollie\Api\Http\Request; -use Mollie\Api\MollieApiClient; - -class RefundPaymentRequest extends Request implements HasBody +class CreateRefundPaymentRequest extends JsonPostRequest { - use HasJsonBody; - - protected string $method = MollieApiClient::HTTP_POST; - /** * The resource class the request should be casted to. - * - * @var string */ public static string $targetResourceClass = \Mollie\Api\Resources\Refund::class; @@ -25,8 +15,9 @@ public function __construct( string $paymentId, array $data ) { + parent::__construct(data: $data); + $this->paymentId = $paymentId; - $this->body = $data; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedBalancesRequest.php b/src/Http/Requests/GetPaginatedBalancesRequest.php index 9339e2291..4f668b2ec 100644 --- a/src/Http/Requests/GetPaginatedBalancesRequest.php +++ b/src/Http/Requests/GetPaginatedBalancesRequest.php @@ -2,19 +2,10 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\MollieApiClient; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\BalanceCollection; -class GetPaginatedBalancesRequest extends Request +class GetPaginatedBalancesRequest extends PaginatedRequest { - use IsPaginatedRequest; - - /** - * Define the HTTP method. - */ - protected string $method = MollieApiClient::HTTP_GET; - /** * The resource class the request should be casted to. * diff --git a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php index bb90840eb..7ffd267c4 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -2,22 +2,10 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; -use Mollie\Api\MollieApiClient; - -class GetPaginatedPaymentRefundsRequest extends Request +class GetPaginatedPaymentRefundsRequest extends PaginatedRequest { - use IsPaginatedRequest; - - /** - * Define the HTTP method. - */ - protected string $method = MollieApiClient::HTTP_GET; - /** * The resource class the request should be casted to. - * - * @var string */ public static string $targetResourceClass = \Mollie\Api\Resources\RefundCollection::class; @@ -27,8 +15,9 @@ public function __construct( string $paymentId, array $filters = [] ) { + parent::__construct(filters: $filters); + $this->paymentId = $paymentId; - $this->filters = $filters; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php index 03e2dc075..edaa2d600 100644 --- a/src/Http/Requests/GetPaginatedPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -3,34 +3,22 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\MollieApiClient; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\PaymentCollection; -class GetPaginatedPaymentsRequest extends Request implements IsIteratable +class GetPaginatedPaymentsRequest extends PaginatedRequest implements IsIteratable { - use IsPaginatedRequest; use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected string $method = MollieApiClient::HTTP_GET; - /** * The resource class the request should be casted to. - * - * @var string */ public static string $targetResourceClass = PaymentCollection::class; /** * Resolve the resource path. - * - * @return string */ public function resolveResourcePath(): string { - return "payments"; + return 'payments'; } } diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 88a134700..5f89e053f 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; +use Mollie\Api\Http\Requests\Request; use Mollie\Api\MollieApiClient; class GetPaymentRequest extends Request @@ -27,8 +27,6 @@ public function __construct( string $paymentId, array $filters = [] ) { - // add guard method - $this->paymentId = $paymentId; $this->filters = $filters; } diff --git a/src/Http/Requests/JsonPostRequest.php b/src/Http/Requests/JsonPostRequest.php new file mode 100644 index 000000000..3f9e630d3 --- /dev/null +++ b/src/Http/Requests/JsonPostRequest.php @@ -0,0 +1,26 @@ +body = $data; + } + + public function getBody(): string + { + return json_encode($this->body); + } +} diff --git a/src/Http/Requests/IsPaginatedRequest.php b/src/Http/Requests/PaginatedRequest.php similarity index 70% rename from src/Http/Requests/IsPaginatedRequest.php rename to src/Http/Requests/PaginatedRequest.php index b3d5c02ad..ab875d469 100644 --- a/src/Http/Requests/IsPaginatedRequest.php +++ b/src/Http/Requests/PaginatedRequest.php @@ -2,8 +2,15 @@ namespace Mollie\Api\Http\Requests; -trait IsPaginatedRequest +use Mollie\Api\MollieApiClient; + +abstract class PaginatedRequest extends Request { + /** + * Define the HTTP method. + */ + protected string $method = MollieApiClient::HTTP_GET; + public ?string $from = null; public ?int $limit = null; @@ -11,13 +18,13 @@ trait IsPaginatedRequest public array $filters = []; public function __construct( + array $filters = [], ?string $from = null, ?int $limit = null, - array $filters = [] ) { + $this->filters = $filters; $this->from = $from; $this->limit = $limit; - $this->filters = $filters; } public function getQuery(): array diff --git a/src/Http/Request.php b/src/Http/Requests/Request.php similarity index 96% rename from src/Http/Request.php rename to src/Http/Requests/Request.php index b0dfe4a90..710efe3cc 100644 --- a/src/Http/Request.php +++ b/src/Http/Requests/Request.php @@ -1,6 +1,6 @@ paymentId = $paymentId; + $this->body = $body; + } + + public function resolveResourcePath(): string + { + $id = urlencode($this->paymentId); + + return "payments/{$id}"; + } +} diff --git a/src/Http/Rules/InvalidIdRule.php b/src/Http/Rules/InvalidIdRule.php new file mode 100644 index 000000000..319811b77 --- /dev/null +++ b/src/Http/Rules/InvalidIdRule.php @@ -0,0 +1,35 @@ +id = $id; + $this->prefix = $prefix; + } + + public function validate(Request $request): void { + if (strpos($this->id, $this->prefix) !== 0) { + $resourceType = $this->getResourceType($request); + + throw new ApiException("Invalid {$resourceType} ID: '{$this->id}'. A resource ID should start with '" . $this->prefix . "'."); + } + } + + public function getResourceType(Request $request): string + { + $classBasename = basename(str_replace("\\", "/", $request::getTargetResourceClass())); + + return strtolower($classBasename); + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index cf9ce6bd3..91149291a 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -5,7 +5,6 @@ use Mollie\Api\Contracts\MollieHttpAdapterContract; use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; use Mollie\Api\Contracts\ResponseContract as Response; -use Mollie\Api\Endpoints\BalanceEndpoint; use Mollie\Api\Endpoints\BalanceReportEndpoint; use Mollie\Api\Endpoints\BalanceTransactionEndpoint; use Mollie\Api\Endpoints\ChargebackEndpoint; @@ -27,10 +26,8 @@ use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; use Mollie\Api\Endpoints\PaymentCaptureEndpoint; use Mollie\Api\Endpoints\PaymentChargebackEndpoint; -use Mollie\Api\Endpoints\PaymentEndpoint; use Mollie\Api\Endpoints\PaymentLinkEndpoint; use Mollie\Api\Endpoints\PaymentLinkPaymentEndpoint; -use Mollie\Api\Endpoints\PaymentRefundEndpoint; use Mollie\Api\Endpoints\PaymentRouteEndpoint; use Mollie\Api\Endpoints\PermissionEndpoint; use Mollie\Api\Endpoints\ProfileEndpoint; @@ -50,13 +47,11 @@ use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Http\EndpointCollection\BalanceEndpointCollection; use Mollie\Api\Http\EndpointCollection\PaymentEndpointCollection; -use Mollie\Api\Contracts\HasBody; use Mollie\Api\Http\EndpointCollection\PaymentRefundEndpointCollection; use Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract; -use Mollie\Api\Http\Request; /** - * @property BalanceEndpoint $balances + * @property BalanceEndpointCollection $balances * @property BalanceReportEndpoint $balanceReports * @property BalanceTransactionEndpoint $balanceTransactions * @property ChargebackEndpoint $chargebacks @@ -75,12 +70,12 @@ * @property OrderRefundEndpoint $orderRefunds * @property OrganizationEndpoint $organizations * @property OrganizationPartnerEndpoint $organizationPartners - * @property PaymentEndpoint $payments + * @property PaymentEndpointCollection $payments * @property PaymentCaptureEndpoint $paymentCaptures * @property PaymentChargebackEndpoint $paymentChargebacks * @property PaymentLinkEndpoint $paymentLinks * @property PaymentLinkPaymentEndpoint $paymentLinkPayments - * @property PaymentRefundEndpoint $paymentRefunds + * @property PaymentRefundEndpointCollection $paymentRefunds * @property PaymentRouteEndpoint $paymentRoutes * @property PermissionEndpoint $permissions * @property ProfileEndpoint $profiles diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 2364ac259..463870f0a 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -12,6 +12,13 @@ class Payment extends BaseResource implements EmbeddedResourcesContract { use HasPresetOptions; + /** + * Resource id prefix. Used to validate resource id's. + * + * @var string + */ + public static string $resourceIdPrefix = 'tr_'; + /** * Id of the payment (on the Mollie platform). * From 36b6e6533404142016086e1a37d1656ae5d95743 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 6 Sep 2024 09:08:11 +0200 Subject: [PATCH 046/131] wip --- composer.json | 6 +- src/CompatibilityChecker.php | 14 +- src/Contracts/ArrayRepository.php | 22 + src/Contracts/Arrayable.php | 8 + src/Contracts/Authenticatable.php | 12 + src/Contracts/Authenticator.php | 10 + src/Contracts/BodyRepository.php | 24 + src/Contracts/Connector.php | 22 + src/Contracts/DataProvider.php | 8 + src/Contracts/DataResolver.php | 8 + src/Contracts/Factory.php | 10 + src/Contracts/HasBody.php | 13 - src/Contracts/HasPayload.php | 8 + ...erContract.php => HttpAdapterContract.php} | 18 +- src/Contracts/IdempotencyContract.php | 10 + .../IdempotencyKeyGeneratorContract.php | 2 +- src/Contracts/JsonBodyRepository.php | 10 + .../MollieHttpAdapterPickerContract.php | 6 +- src/Contracts/Rule.php | 4 +- src/Contracts/SupportsTestmode.php | 8 + src/Contracts/ValidatableData.php | 8 - src/Contracts/ValidatableDataProvider.php | 8 + .../BalanceEndpointCollection.php | 80 +++ .../BalanceReportEndpointCollection.php | 51 ++ .../BalanceTransactionEndpointCollection.php | 99 ++++ .../ChargebackEndpointCollection.php | 53 ++ .../ClientEndpointCollection.php | 69 +++ .../ClientLinkEndpointCollection.php | 30 ++ src/EndpointCollection/EndpointCollection.php | 21 + .../PaymentEndpointCollection.php | 183 +++++++ .../PaymentRefundEndpointCollection.php | 29 ++ src/Endpoints/BalanceEndpoint.php | 104 ---- src/Endpoints/BalanceReportEndpoint.php | 80 --- src/Endpoints/BalanceTransactionEndpoint.php | 126 ----- src/Endpoints/BaseEndpoint.php | 38 +- src/Endpoints/ChargebackEndpoint.php | 63 --- src/Endpoints/ClientEndpoint.php | 85 --- src/Endpoints/ClientLinkEndpoint.php | 37 -- src/Endpoints/PaymentEndpoint.php | 188 ------- src/Endpoints/RestEndpoint.php | 36 +- src/Exceptions/ApiException.php | 94 +--- src/Exceptions/RequestValidationException.php | 5 + src/Factories/ApplicationFeeFactory.php | 16 + .../CreateClientLinkPayloadFactory.php | 21 + src/Factories/CreatePaymentPayloadFactory.php | 50 ++ .../CreateRefundPaymentPayloadFactory.php | 25 + src/Factories/Factory.php | 44 ++ .../GetBalanceReportQueryFactory.php | 23 + .../GetPaginatedBalanceQueryFactory.php | 21 + .../GetPaginatedChargebackQueryFactory.php | 19 + .../GetPaginatedClientQueryFactory.php | 17 + .../GetPaginatedPaymentRefundQueryFactory.php | 18 + src/Factories/GetPaymentQueryFactory.php | 17 + src/Factories/MoneyFactory.php | 20 + src/Factories/OrderLineCollectionFactory.php | 16 + src/Factories/OrderLineFactory.php | 27 + src/Factories/PaginatedQueryFactory.php | 19 + .../PaymentRouteCollectionFactory.php | 32 ++ .../RecurringBillingCycleFactory.php | 20 + .../RefundRouteCollectionFactory.php | 26 + .../SortablePaginatedQueryFactory.php | 21 + src/Factories/UpdatePaymentPayloadFactory.php | 26 + src/Helpers.php | 109 ++++ src/Helpers/Arr.php | 85 +++ src/Helpers/Factories.php | 31 ++ src/Helpers/Handlers.php | 31 ++ src/Helpers/MiddlewareHandlers.php | 55 ++ src/Helpers/Url.php | 53 ++ src/Helpers/Validator.php | 72 +++ src/Http/Adapter/CurlMollieHttpAdapter.php | 105 ++-- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 85 +-- src/Http/Adapter/MollieHttpAdapterPicker.php | 17 +- src/Http/Adapter/PSR18MollieHttpAdapter.php | 112 ++-- src/Http/Auth/AccessTokenAuthenticator.php | 18 + src/Http/Auth/ApiKeyAuthenticator.php | 18 + src/Http/Auth/BearerTokenAuthenticator.php | 22 + src/Http/EmptyResponse.php | 28 - src/Http/Endpoint.php | 45 -- .../BalanceEndpointCollection.php | 42 -- .../PaymentEndpointCollection.php | 116 ----- .../PaymentRefundEndpointCollection.php | 24 - src/Http/HandlesQueries.php | 28 - src/Http/HandlesValidation.php | 39 -- src/Http/HasHttpPhrases.php | 72 --- src/Http/Middleware/ApplyIdempotencyKey.php | 39 ++ src/Http/Middleware/GuardResponse.php | 32 ++ src/Http/Middleware/ResetIdempotencyKey.php | 13 + .../ThrowExceptionIfRequestFailed.php | 48 ++ src/Http/Payload/Address.php | 81 +++ src/Http/Payload/ApplicationFee.php | 26 + src/Http/Payload/CreateClientLink.php | 41 ++ src/Http/Payload/CreatePayment.php | 140 +++++ src/Http/Payload/CreateRefundPayment.php | 53 ++ src/Http/Payload/DataBag.php | 21 + src/Http/Payload/DataCollection.php | 66 +++ src/Http/Payload/Metadata.php | 20 + src/Http/Payload/Money.php | 28 + src/Http/Payload/OrderLine.php | 95 ++++ src/Http/Payload/Owner.php | 41 ++ src/Http/Payload/OwnerAddress.php | 46 ++ src/Http/Payload/PaymentRoute.php | 26 + src/Http/Payload/RecurringBillingCycle.php | 56 ++ src/Http/Payload/RefundRoute.php | 29 ++ src/Http/Payload/UpdatePayment.php | 70 +++ src/Http/PendingRequest.php | 113 ++++ .../PendingRequest/AuthenticateRequest.php | 31 ++ .../PendingRequest/MergeRequestProperties.php | 26 + src/Http/PendingRequest/SetBody.php | 28 + src/Http/PendingRequest/SetUserAgent.php | 25 + .../PendingRequest/ValidateProperties.php | 21 + src/Http/PsrResponseHandler.php | 72 --- src/Http/Query/CreatePaymentQuery.php | 34 ++ src/Http/Query/GetBalanceReportQuery.php | 38 ++ src/Http/Query/GetPaginatedBalanceQuery.php | 29 ++ .../Query/GetPaginatedChargebackQuery.php | 34 ++ src/Http/Query/GetPaginatedClientQuery.php | 39 ++ .../Query/GetPaginatedPaymentRefundQuery.php | 29 ++ src/Http/Query/GetPaymentQuery.php | 43 ++ src/Http/Query/PaginatedQuery.php | 31 ++ src/Http/Query/Query.php | 12 + src/Http/Query/SortablePaginatedQuery.php | 38 ++ src/Http/{Requests => }/Request.php | 27 +- src/Http/Requests/CancelPaymentRequest.php | 50 ++ src/Http/Requests/CreateClientLinkRequest.php | 39 ++ src/Http/Requests/CreatePaymentRequest.php | 38 +- .../Requests/CreateRefundPaymentRequest.php | 45 +- src/Http/Requests/DynamicDeleteRequest.php | 32 ++ src/Http/Requests/DynamicGetRequest.php | 13 + src/Http/Requests/DynamicRequest.php | 32 ++ src/Http/Requests/GetBalanceReportRequest.php | 44 ++ src/Http/Requests/GetBalanceRequest.php | 45 ++ src/Http/Requests/GetClientRequest.php | 52 ++ ...est.php => GetPaginatedBalanceRequest.php} | 12 +- .../GetPaginatedBalanceTransactionRequest.php | 34 ++ .../GetPaginatedChargebacksRequest.php | 22 + .../Requests/GetPaginatedClientRequest.php | 22 + .../GetPaginatedPaymentRefundsRequest.php | 21 +- .../Requests/GetPaginatedPaymentsRequest.php | 3 +- src/Http/Requests/GetPaymentRequest.php | 46 +- src/Http/Requests/HasJsonBody.php | 13 - src/Http/Requests/JsonPostRequest.php | 26 - src/Http/Requests/PaginatedRequest.php | 27 +- .../Requests/SortablePaginatedRequest.php | 14 + src/Http/Requests/UpdatePaymentRequest.php | 37 +- src/Http/Response.php | 128 +++-- src/Http/ResponseHandler.php | 110 ---- src/Http/Rules/InvalidIdRule.php | 35 -- .../DefaultIdempotencyKeyGenerator.php | 5 +- .../FakeIdempotencyKeyGenerator.php | 3 +- src/MollieApiClient.php | 394 +++----------- src/Repositories/ArrayStore.php | 64 +++ src/Repositories/JsonBodyRepository.php | 56 ++ src/Resources/Balance.php | 8 + src/Resources/BaseCollection.php | 27 +- src/Resources/BaseResource.php | 20 +- src/Resources/CurrentProfile.php | 14 +- src/Resources/CursorCollection.php | 43 +- src/Resources/Customer.php | 66 ++- src/Resources/Mandate.php | 41 +- src/Resources/Method.php | 8 +- src/Resources/Order.php | 107 ++-- src/Resources/OrderLine.php | 43 +- src/Resources/Payment.php | 190 +++---- src/Resources/PaymentLink.php | 50 +- src/Resources/Profile.php | 126 ++--- src/Resources/Refund.php | 28 +- src/Resources/ResourceFactory.php | 119 ++--- src/Resources/Settlement.php | 38 +- src/Resources/Shipment.php | 24 +- src/Resources/Subscription.php | 80 +-- src/Rules/Id.php | 42 ++ src/Rules/Included.php | 48 ++ src/Rules/Matches.php | 25 + src/Rules/Max.php | 33 ++ src/Rules/Min.php | 33 ++ src/Traits/ComposableFromArray.php | 11 + src/Traits/HandlesAuthentication.php | 42 ++ src/{ => Traits}/HandlesDebugging.php | 5 +- src/{ => Traits}/HandlesIdempotency.php | 73 +-- .../HandlesResourceCreation.php} | 27 +- src/Traits/HandlesTestmode.php | 22 + src/Traits/HandlesVersions.php | 38 ++ src/Traits/HasDefaultFactories.php | 27 + src/Traits/HasEndpoints.php | 143 +++++ src/Traits/HasHeaders.php | 20 + src/Traits/HasJsonPayload.php | 20 + src/Traits/HasMiddleware.php | 15 + src/Traits/HasQuery.php | 20 + src/Traits/HasRequestProperties.php | 9 + src/Traits/HasRules.php | 11 + src/Traits/Initializable.php | 22 + src/{ => Traits}/InteractsWithResource.php | 4 +- src/{Http => Traits}/IsDebuggable.php | 10 +- .../IsIteratableRequest.php | 2 +- src/Traits/Makeable.php | 11 + src/Traits/ManagesPsrRequests.php | 60 +++ src/Traits/ResolvesUri.php | 44 ++ src/Traits/ResolvesValues.php | 28 + src/Traits/SendsRequests.php | 30 ++ src/Traits/ValidatesProperties.php | 104 ++++ src/Types/ClientQuery.php | 10 + src/Types/Method.php | 24 + src/Types/PaymentQuery.php | 27 + .../API => }/CompatibilityCheckerTest.php | 17 +- .../BalanceEndpointCollectionTest.php | 181 +++++++ tests/Fixtures/MockClient.php | 18 + tests/Fixtures/MockResponse.php | 82 +++ tests/Fixtures/Responses/balance-get.json | 42 ++ tests/Fixtures/Responses/balance-list.json | 98 ++++ .../Responses/empty-balance-list.json | 18 + .../unprocessable-entity-with-field.json | 12 + .../Responses/unprocessable-entity.json | 5 + .../Traits}/AmountObjectTestHelpers.php | 2 +- .../Traits}/LinkObjectTestHelpers.php | 2 +- tests/Helpers/ArrTest.php | 60 +++ tests/Helpers/MiddlewareHandlersTest.php | 44 ++ tests/Helpers/UrlTest.php | 42 ++ tests/Helpers/ValidatorTest.php | 124 +++++ .../Adapter}/GuzzleMollieHttpAdapterTest.php | 31 +- tests/Http/Adapter/MockMollieHttpAdapter.php | 51 ++ .../Adapter}/MollieHttpAdapterPickerTest.php | 2 +- .../Adapter}/RetryMiddlewareFactoryTest.php | 22 +- .../Auth/BearetTokenAuthenticatorTest.php | 58 +++ .../API/Endpoints/BalanceEndpointTest.php | 487 ------------------ .../Endpoints/BalanceReportEndpointTest.php | 100 ++-- .../BalanceTransactionEndpointTest.php | 60 +-- .../API/Endpoints/ChargebackEndpointTest.php | 44 +- .../API/Endpoints/ClientEndpointTest.php | 6 +- .../API/Endpoints/ClientLinkEndpointTest.php | 38 +- ...ustomerSubscriptionPaymentEndpointTest.php | 2 +- .../API/Endpoints/MethodEndpointTest.php | 18 +- .../API/Endpoints/OrderEndpointTest.php | 350 ++++++------- .../Endpoints/OrderPaymentEndpointTest.php | 14 +- .../API/Endpoints/OrderRefundEndpointTest.php | 30 +- .../Endpoints/OrganizationEndpointTest.php | 6 +- .../Endpoints/PaymentCaptureEndpointTest.php | 11 +- .../PaymentChargebackEndpointTest.php | 54 +- .../API/Endpoints/PaymentEndpointTest.php | 138 ++--- .../API/Endpoints/PermissionEndpointTest.php | 12 +- .../Endpoints/ProfileMethodEndpointTest.php | 34 +- .../API/Endpoints/ShipmentEndpointTest.php | 70 +-- .../API/Endpoints/TerminalEndpointTest.php | 20 +- .../API/Exceptions/ApiExceptionTest.php | 52 -- .../API/HttpAdapter/MockMollieHttpAdapter.php | 44 -- .../API/Resources/CursorCollectionTest.php | 9 +- tests/Mollie/API/Resources/InvoiceTest.php | 43 -- tests/Mollie/API/Resources/OnboardingTest.php | 42 -- tests/Mollie/API/Resources/OrderLineTest.php | 172 ------- tests/Mollie/API/Resources/ProfileTest.php | 42 -- tests/Mollie/API/Resources/RefundTest.php | 86 ---- tests/Mollie/API/Resources/SettlementTest.php | 50 -- .../Mollie/API/Resources/SubscriptionTest.php | 60 --- tests/Mollie/TestHelpers/FakeHttpAdapter.php | 88 ---- .../{Mollie/API => }/MollieApiClientTest.php | 188 ++----- tests/Resources/InvoiceTest.php | 43 ++ .../API => }/Resources/LazyCollectionTest.php | 3 +- .../Resources/MandateCollectionTest.php | 4 +- .../{Mollie/API => }/Resources/MethodTest.php | 2 +- tests/Resources/OnboardingTest.php | 42 ++ .../Resources/OrderLineCollectionTest.php | 2 +- tests/Resources/OrderLineTest.php | 172 +++++++ .../{Mollie/API => }/Resources/OrderTest.php | 198 +++---- .../API => }/Resources/PaymentTest.php | 147 +++--- tests/Resources/ProfileTest.php | 42 ++ tests/Resources/RefundTest.php | 86 ++++ .../Resources/ResourceFactoryTest.php | 12 +- tests/Resources/SettlementTest.php | 50 ++ .../API => }/Resources/ShipmentTest.php | 2 +- tests/Resources/SubscriptionTest.php | 60 +++ tests/Rules/IdTest.php | 76 +++ tests/Rules/IncludedTest.php | 63 +++ tests/Rules/MatchesTest.php | 42 ++ tests/Rules/MaxTest.php | 86 ++++ tests/Rules/MinTest.php | 74 +++ tests/Traits/ResolvesValuesTest.php | 90 ++++ .../API => }/Types/MandateMethodTest.php | 7 +- 276 files changed, 8219 insertions(+), 4935 deletions(-) create mode 100644 src/Contracts/ArrayRepository.php create mode 100644 src/Contracts/Arrayable.php create mode 100644 src/Contracts/Authenticatable.php create mode 100644 src/Contracts/Authenticator.php create mode 100644 src/Contracts/BodyRepository.php create mode 100644 src/Contracts/Connector.php create mode 100644 src/Contracts/DataProvider.php create mode 100644 src/Contracts/DataResolver.php create mode 100644 src/Contracts/Factory.php delete mode 100644 src/Contracts/HasBody.php create mode 100644 src/Contracts/HasPayload.php rename src/Contracts/{MollieHttpAdapterContract.php => HttpAdapterContract.php} (51%) create mode 100644 src/Contracts/IdempotencyContract.php rename src/{Idempotency => Contracts}/IdempotencyKeyGeneratorContract.php (73%) create mode 100644 src/Contracts/JsonBodyRepository.php create mode 100644 src/Contracts/SupportsTestmode.php delete mode 100644 src/Contracts/ValidatableData.php create mode 100644 src/Contracts/ValidatableDataProvider.php create mode 100644 src/EndpointCollection/BalanceEndpointCollection.php create mode 100644 src/EndpointCollection/BalanceReportEndpointCollection.php create mode 100644 src/EndpointCollection/BalanceTransactionEndpointCollection.php create mode 100644 src/EndpointCollection/ChargebackEndpointCollection.php create mode 100644 src/EndpointCollection/ClientEndpointCollection.php create mode 100644 src/EndpointCollection/ClientLinkEndpointCollection.php create mode 100644 src/EndpointCollection/EndpointCollection.php create mode 100644 src/EndpointCollection/PaymentEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentRefundEndpointCollection.php delete mode 100644 src/Endpoints/BalanceEndpoint.php delete mode 100644 src/Endpoints/BalanceReportEndpoint.php delete mode 100644 src/Endpoints/BalanceTransactionEndpoint.php delete mode 100644 src/Endpoints/ChargebackEndpoint.php delete mode 100644 src/Endpoints/ClientEndpoint.php delete mode 100644 src/Endpoints/ClientLinkEndpoint.php delete mode 100644 src/Endpoints/PaymentEndpoint.php create mode 100644 src/Exceptions/RequestValidationException.php create mode 100644 src/Factories/ApplicationFeeFactory.php create mode 100644 src/Factories/CreateClientLinkPayloadFactory.php create mode 100644 src/Factories/CreatePaymentPayloadFactory.php create mode 100644 src/Factories/CreateRefundPaymentPayloadFactory.php create mode 100644 src/Factories/Factory.php create mode 100644 src/Factories/GetBalanceReportQueryFactory.php create mode 100644 src/Factories/GetPaginatedBalanceQueryFactory.php create mode 100644 src/Factories/GetPaginatedChargebackQueryFactory.php create mode 100644 src/Factories/GetPaginatedClientQueryFactory.php create mode 100644 src/Factories/GetPaginatedPaymentRefundQueryFactory.php create mode 100644 src/Factories/GetPaymentQueryFactory.php create mode 100644 src/Factories/MoneyFactory.php create mode 100644 src/Factories/OrderLineCollectionFactory.php create mode 100644 src/Factories/OrderLineFactory.php create mode 100644 src/Factories/PaginatedQueryFactory.php create mode 100644 src/Factories/PaymentRouteCollectionFactory.php create mode 100644 src/Factories/RecurringBillingCycleFactory.php create mode 100644 src/Factories/RefundRouteCollectionFactory.php create mode 100644 src/Factories/SortablePaginatedQueryFactory.php create mode 100644 src/Factories/UpdatePaymentPayloadFactory.php create mode 100644 src/Helpers.php create mode 100644 src/Helpers/Arr.php create mode 100644 src/Helpers/Factories.php create mode 100644 src/Helpers/Handlers.php create mode 100644 src/Helpers/MiddlewareHandlers.php create mode 100644 src/Helpers/Url.php create mode 100644 src/Helpers/Validator.php create mode 100644 src/Http/Auth/AccessTokenAuthenticator.php create mode 100644 src/Http/Auth/ApiKeyAuthenticator.php create mode 100644 src/Http/Auth/BearerTokenAuthenticator.php delete mode 100644 src/Http/EmptyResponse.php delete mode 100644 src/Http/Endpoint.php delete mode 100644 src/Http/EndpointCollection/BalanceEndpointCollection.php delete mode 100644 src/Http/EndpointCollection/PaymentEndpointCollection.php delete mode 100644 src/Http/EndpointCollection/PaymentRefundEndpointCollection.php delete mode 100644 src/Http/HandlesQueries.php delete mode 100644 src/Http/HandlesValidation.php delete mode 100644 src/Http/HasHttpPhrases.php create mode 100644 src/Http/Middleware/ApplyIdempotencyKey.php create mode 100644 src/Http/Middleware/GuardResponse.php create mode 100644 src/Http/Middleware/ResetIdempotencyKey.php create mode 100644 src/Http/Middleware/ThrowExceptionIfRequestFailed.php create mode 100644 src/Http/Payload/Address.php create mode 100644 src/Http/Payload/ApplicationFee.php create mode 100644 src/Http/Payload/CreateClientLink.php create mode 100644 src/Http/Payload/CreatePayment.php create mode 100644 src/Http/Payload/CreateRefundPayment.php create mode 100644 src/Http/Payload/DataBag.php create mode 100644 src/Http/Payload/DataCollection.php create mode 100644 src/Http/Payload/Metadata.php create mode 100644 src/Http/Payload/Money.php create mode 100644 src/Http/Payload/OrderLine.php create mode 100644 src/Http/Payload/Owner.php create mode 100644 src/Http/Payload/OwnerAddress.php create mode 100644 src/Http/Payload/PaymentRoute.php create mode 100644 src/Http/Payload/RecurringBillingCycle.php create mode 100644 src/Http/Payload/RefundRoute.php create mode 100644 src/Http/Payload/UpdatePayment.php create mode 100644 src/Http/PendingRequest.php create mode 100644 src/Http/PendingRequest/AuthenticateRequest.php create mode 100644 src/Http/PendingRequest/MergeRequestProperties.php create mode 100644 src/Http/PendingRequest/SetBody.php create mode 100644 src/Http/PendingRequest/SetUserAgent.php create mode 100644 src/Http/PendingRequest/ValidateProperties.php delete mode 100644 src/Http/PsrResponseHandler.php create mode 100644 src/Http/Query/CreatePaymentQuery.php create mode 100644 src/Http/Query/GetBalanceReportQuery.php create mode 100644 src/Http/Query/GetPaginatedBalanceQuery.php create mode 100644 src/Http/Query/GetPaginatedChargebackQuery.php create mode 100644 src/Http/Query/GetPaginatedClientQuery.php create mode 100644 src/Http/Query/GetPaginatedPaymentRefundQuery.php create mode 100644 src/Http/Query/GetPaymentQuery.php create mode 100644 src/Http/Query/PaginatedQuery.php create mode 100644 src/Http/Query/Query.php create mode 100644 src/Http/Query/SortablePaginatedQuery.php rename src/Http/{Requests => }/Request.php (64%) create mode 100644 src/Http/Requests/CancelPaymentRequest.php create mode 100644 src/Http/Requests/CreateClientLinkRequest.php create mode 100644 src/Http/Requests/DynamicDeleteRequest.php create mode 100644 src/Http/Requests/DynamicGetRequest.php create mode 100644 src/Http/Requests/DynamicRequest.php create mode 100644 src/Http/Requests/GetBalanceReportRequest.php create mode 100644 src/Http/Requests/GetBalanceRequest.php create mode 100644 src/Http/Requests/GetClientRequest.php rename src/Http/Requests/{GetPaginatedBalancesRequest.php => GetPaginatedBalanceRequest.php} (61%) create mode 100644 src/Http/Requests/GetPaginatedBalanceTransactionRequest.php create mode 100644 src/Http/Requests/GetPaginatedChargebacksRequest.php create mode 100644 src/Http/Requests/GetPaginatedClientRequest.php delete mode 100644 src/Http/Requests/HasJsonBody.php delete mode 100644 src/Http/Requests/JsonPostRequest.php create mode 100644 src/Http/Requests/SortablePaginatedRequest.php delete mode 100644 src/Http/ResponseHandler.php delete mode 100644 src/Http/Rules/InvalidIdRule.php create mode 100644 src/Repositories/ArrayStore.php create mode 100644 src/Repositories/JsonBodyRepository.php create mode 100644 src/Rules/Id.php create mode 100644 src/Rules/Included.php create mode 100644 src/Rules/Matches.php create mode 100644 src/Rules/Max.php create mode 100644 src/Rules/Min.php create mode 100644 src/Traits/ComposableFromArray.php create mode 100644 src/Traits/HandlesAuthentication.php rename src/{ => Traits}/HandlesDebugging.php (90%) rename src/{ => Traits}/HandlesIdempotency.php (51%) rename src/{Http/HandlesResourceBuilding.php => Traits/HandlesResourceCreation.php} (69%) create mode 100644 src/Traits/HandlesTestmode.php create mode 100644 src/Traits/HandlesVersions.php create mode 100644 src/Traits/HasDefaultFactories.php create mode 100644 src/Traits/HasEndpoints.php create mode 100644 src/Traits/HasHeaders.php create mode 100644 src/Traits/HasJsonPayload.php create mode 100644 src/Traits/HasMiddleware.php create mode 100644 src/Traits/HasQuery.php create mode 100644 src/Traits/HasRequestProperties.php create mode 100644 src/Traits/HasRules.php create mode 100644 src/Traits/Initializable.php rename src/{ => Traits}/InteractsWithResource.php (88%) rename src/{Http => Traits}/IsDebuggable.php (82%) rename src/{Http/Requests => Traits}/IsIteratableRequest.php (94%) create mode 100644 src/Traits/Makeable.php create mode 100644 src/Traits/ManagesPsrRequests.php create mode 100644 src/Traits/ResolvesUri.php create mode 100644 src/Traits/ResolvesValues.php create mode 100644 src/Traits/SendsRequests.php create mode 100644 src/Traits/ValidatesProperties.php create mode 100644 src/Types/ClientQuery.php create mode 100644 src/Types/Method.php create mode 100644 src/Types/PaymentQuery.php rename tests/{Mollie/API => }/CompatibilityCheckerTest.php (78%) create mode 100644 tests/EndpointCollection/BalanceEndpointCollectionTest.php create mode 100644 tests/Fixtures/MockClient.php create mode 100644 tests/Fixtures/MockResponse.php create mode 100644 tests/Fixtures/Responses/balance-get.json create mode 100644 tests/Fixtures/Responses/balance-list.json create mode 100644 tests/Fixtures/Responses/empty-balance-list.json create mode 100644 tests/Fixtures/Responses/unprocessable-entity-with-field.json create mode 100644 tests/Fixtures/Responses/unprocessable-entity.json rename tests/{Mollie/TestHelpers => Fixtures/Traits}/AmountObjectTestHelpers.php (92%) rename tests/{Mollie/TestHelpers => Fixtures/Traits}/LinkObjectTestHelpers.php (94%) create mode 100644 tests/Helpers/ArrTest.php create mode 100644 tests/Helpers/MiddlewareHandlersTest.php create mode 100644 tests/Helpers/UrlTest.php create mode 100644 tests/Helpers/ValidatorTest.php rename tests/{Mollie/API/HttpAdapter => Http/Adapter}/GuzzleMollieHttpAdapterTest.php (76%) create mode 100644 tests/Http/Adapter/MockMollieHttpAdapter.php rename tests/{Mollie/API/HttpAdapter => Http/Adapter}/MollieHttpAdapterPickerTest.php (97%) rename tests/{Mollie/Guzzle => Http/Adapter}/RetryMiddlewareFactoryTest.php (75%) create mode 100644 tests/Http/Auth/BearetTokenAuthenticatorTest.php delete mode 100644 tests/Mollie/API/Endpoints/BalanceEndpointTest.php delete mode 100644 tests/Mollie/API/Exceptions/ApiExceptionTest.php delete mode 100644 tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php delete mode 100644 tests/Mollie/API/Resources/InvoiceTest.php delete mode 100644 tests/Mollie/API/Resources/OnboardingTest.php delete mode 100644 tests/Mollie/API/Resources/OrderLineTest.php delete mode 100644 tests/Mollie/API/Resources/ProfileTest.php delete mode 100644 tests/Mollie/API/Resources/RefundTest.php delete mode 100644 tests/Mollie/API/Resources/SettlementTest.php delete mode 100644 tests/Mollie/API/Resources/SubscriptionTest.php delete mode 100644 tests/Mollie/TestHelpers/FakeHttpAdapter.php rename tests/{Mollie/API => }/MollieApiClientTest.php (58%) create mode 100644 tests/Resources/InvoiceTest.php rename tests/{Mollie/API => }/Resources/LazyCollectionTest.php (98%) rename tests/{Mollie/API => }/Resources/MandateCollectionTest.php (96%) rename tests/{Mollie/API => }/Resources/MethodTest.php (93%) create mode 100644 tests/Resources/OnboardingTest.php rename tests/{Mollie/API => }/Resources/OrderLineCollectionTest.php (95%) create mode 100644 tests/Resources/OrderLineTest.php rename tests/{Mollie/API => }/Resources/OrderTest.php (54%) rename tests/{Mollie/API => }/Resources/PaymentTest.php (59%) create mode 100644 tests/Resources/ProfileTest.php create mode 100644 tests/Resources/RefundTest.php rename tests/{Mollie/API => }/Resources/ResourceFactoryTest.php (89%) create mode 100644 tests/Resources/SettlementTest.php rename tests/{Mollie/API => }/Resources/ShipmentTest.php (98%) create mode 100644 tests/Resources/SubscriptionTest.php create mode 100644 tests/Rules/IdTest.php create mode 100644 tests/Rules/IncludedTest.php create mode 100644 tests/Rules/MatchesTest.php create mode 100644 tests/Rules/MaxTest.php create mode 100644 tests/Rules/MinTest.php create mode 100644 tests/Traits/ResolvesValuesTest.php rename tests/{Mollie/API => }/Types/MandateMethodTest.php (91%) diff --git a/composer.json b/composer.json index 08b80df5a..75f12b7e1 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,11 @@ "ext-curl": "*", "ext-json": "*", "ext-openssl": "*", - "composer/ca-bundle": "^1.4" + "composer/ca-bundle": "^1.4", + "nyholm/psr7": "^1.8", + "psr/http-factory": "^1.1", + "psr/http-message": "^2.0", + "saloonphp/saloon": "^3.10" }, "require-dev": { "brianium/paratest": "^6.11", diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index 40127dac6..79d9b1bff 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -3,23 +3,27 @@ namespace Mollie\Api; use Mollie\Api\Exceptions\IncompatiblePlatform; +use Mollie\Api\Traits\Makeable; class CompatibilityChecker { + use Makeable; + /** * @var string */ - public const MIN_PHP_VERSION = "7.4"; + public const MIN_PHP_VERSION = '7.4'; /** - * @throws IncompatiblePlatform * @return void + * + * @throws IncompatiblePlatform */ public function checkCompatibility() { if (! $this->satisfiesPhpVersion()) { throw new IncompatiblePlatform( - "The client requires PHP version >= " . self::MIN_PHP_VERSION . ", you have " . PHP_VERSION . ".", + 'The client requires PHP version >= '.self::MIN_PHP_VERSION.', you have '.PHP_VERSION.'.', IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION ); } @@ -34,15 +38,17 @@ public function checkCompatibility() /** * @return bool + * * @codeCoverageIgnore */ public function satisfiesPhpVersion() { - return (bool)version_compare(PHP_VERSION, self::MIN_PHP_VERSION, ">="); + return (bool) version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>='); } /** * @return bool + * * @codeCoverageIgnore */ public function satisfiesJsonExtension() diff --git a/src/Contracts/ArrayRepository.php b/src/Contracts/ArrayRepository.php new file mode 100644 index 000000000..0bbda611a --- /dev/null +++ b/src/Contracts/ArrayRepository.php @@ -0,0 +1,22 @@ +send(new GetBalanceRequest($id, $testmode)); + } + + /** + * Retrieve the primary balance from Mollie. + * + * Will throw an ApiException if the balance id is invalid or the resource cannot be found. + * + * @throws ApiException + */ + public function primary(array $testmode = []): Balance + { + /** @var Balance */ + return $this->get('primary', $testmode); + } + + /** + * Get the balance endpoint. + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): BalanceCollection + { + $query = GetPaginatedBalanceQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send(new GetPaginatedBalanceRequest($query)); + } + + /** + * Create an iterator for iterating over balances retrieved from Mollie. + * + * @param string $from The first Balance ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = GetPaginatedBalanceQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedBalanceRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/BalanceReportEndpointCollection.php b/src/EndpointCollection/BalanceReportEndpointCollection.php new file mode 100644 index 000000000..40aa9b4e6 --- /dev/null +++ b/src/EndpointCollection/BalanceReportEndpointCollection.php @@ -0,0 +1,51 @@ +create(); + + /** @var BalanceReport */ + return $this->send(new GetBalanceReportRequest($balanceId, $query)); + } + + /** + * Retrieve the primary balance. + * This is the balance of your account’s primary currency, where all payments are settled to by default. + * + * @param array|GetBalanceReportQuery $query + * + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function getForPrimary($query = []): BalanceReport + { + return $this->getForId('primary', $query); + } + + /** + * Retrieve a balance report for the provided balance resource and parameters. + * + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function getFor(Balance $balance, array $parameters = []): BalanceReport + { + return $this->getForId($balance->id, $parameters); + } +} diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php new file mode 100644 index 000000000..17941845c --- /dev/null +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -0,0 +1,99 @@ +listForId($balance->id, $query); + } + + /** + * Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie. + * + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false): LazyCollection + { + return $this->iteratorForId($balance->id, $parameters, $iterateBackwards); + } + + /** + * List the transactions for the primary Balance. + * + * @param array|PaginatedQuery $query + * + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function listForPrimary($query = []): BalanceTransactionCollection + { + /** @var BalanceTransactionCollection */ + return $this->listForId('primary', $query); + } + + /** + * Create an iterator for iterating over transactions for the primary balance retrieved from Mollie. + * + * @param array|PaginatedQuery $query + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForPrimary($query = [], bool $iterateBackwards = false): LazyCollection + { + return $this->iteratorForId('primary', $query, $iterateBackwards); + } + + /** + * List the transactions for a specific Balance ID. + * + * @param array|PaginatedQuery $query + * + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function listForId(string $balanceId, $query = []): BalanceTransactionCollection + { + if (! $query instanceof PaginatedQuery) { + $query = PaginatedQueryFactory::new($query) + ->create(); + } + + /** @var BalanceTransactionCollection */ + return $this->send(new GetPaginatedBalanceTransactionRequest($balanceId, $query)); + } + + /** + * Create an iterator for iterating over balance transactions for the given balance id retrieved from Mollie. + * + * @param array|PaginatedQuery $query + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId(string $balanceId, $query = [], bool $iterateBackwards = false): LazyCollection + { + if (! $query instanceof PaginatedQuery) { + $query = PaginatedQueryFactory::new($query) + ->create(); + } + + return $this->send( + (new GetPaginatedBalanceTransactionRequest($balanceId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/ChargebackEndpointCollection.php b/src/EndpointCollection/ChargebackEndpointCollection.php new file mode 100644 index 000000000..737b8213b --- /dev/null +++ b/src/EndpointCollection/ChargebackEndpointCollection.php @@ -0,0 +1,53 @@ + $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var ChargebackCollection */ + return $this->send(new GetPaginatedChargebacksRequest($query)); + } + + /** + * Create an iterator for iterating over chargeback retrieved from Mollie. + * + * @param string $from The first chargevback ID you want to include in your list. + * @param array $filters + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = GetPaginatedChargebackQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedChargebacksRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/ClientEndpointCollection.php b/src/EndpointCollection/ClientEndpointCollection.php new file mode 100644 index 000000000..fe14921c3 --- /dev/null +++ b/src/EndpointCollection/ClientEndpointCollection.php @@ -0,0 +1,69 @@ +send(new GetClientRequest($id, $embed)); + } + + /** + * Retrieves a page of clients from Mollie. + * + * @param string $from The first client ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): ClientCollection + { + $query = GetPaginatedClientQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var ClientCollection */ + return $this->send(new GetPaginatedClientRequest($query)); + } + + /** + * Create an iterator for iterating over clients retrieved from Mollie. + * + * @param string $from The first client ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = GetPaginatedClientQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedClientRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/ClientLinkEndpointCollection.php b/src/EndpointCollection/ClientLinkEndpointCollection.php new file mode 100644 index 000000000..92eac90f5 --- /dev/null +++ b/src/EndpointCollection/ClientLinkEndpointCollection.php @@ -0,0 +1,30 @@ +create(); + } + + /** @var ClientLink */ + return $this->send(new CreateClientLinkRequest($data)); + } +} diff --git a/src/EndpointCollection/EndpointCollection.php b/src/EndpointCollection/EndpointCollection.php new file mode 100644 index 000000000..46a419ef6 --- /dev/null +++ b/src/EndpointCollection/EndpointCollection.php @@ -0,0 +1,21 @@ +connector = $connector; + } + + protected function send(Request $request): mixed + { + return $this->connector->send($request); + } +} diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php new file mode 100644 index 000000000..1adff35ed --- /dev/null +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -0,0 +1,183 @@ +create(); + } + + return $this->send(new GetPaymentRequest($paymentId, $query)); + } + + /** + * Creates a payment in Mollie. + * + * @param CreatePayment|array $data An array containing details on the payment. + * @param CreatePaymentQuery|array|string $query An array of strings or a single string containing the details to include. + * + * @throws ApiException + */ + public function create($data = [], $query = []): Payment + { + if (! $data instanceof CreatePayment) { + $data = CreatePaymentPayloadFactory::new($data) + ->create(); + } + + if (! $query instanceof CreatePaymentQuery) { + $query = CreatePaymentQuery::fromArray(Arr::wrap($query)); + } + + /** @var Payment */ + return $this->send(new CreatePaymentRequest($data, $query)); + } + + /** + * Update the given Payment. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * + * @param string $id + * @param array|UpdatePayment $data + * + * @throws ApiException + */ + public function update($id, $data = []): ?Payment + { + if (! $data instanceof UpdatePayment) { + $data = UpdatePaymentPayloadFactory::new($data) + ->create(); + } + + /** @var null|Payment */ + return $this->send(new UpdatePaymentRequest($id, $data)); + } + + /** + * Deletes the given Payment. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * Returns with HTTP status No Content (204) if successful. + * + * + * @throws ApiException + */ + public function delete(string $id, $data = []): ?Payment + { + return $this->cancel($id, $data); + } + + /** + * Cancel the given Payment. This is just an alias of the 'delete' method. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * Returns with HTTP status No Content (204) if successful. + * + * @param array|bool $data + * + * @throws ApiException + */ + public function cancel(string $id, $data = []): ?Payment + { + $testmode = is_bool($data) + ? $data + : Arr::get($data, 'testmode', false); + + /** @var null|Payment */ + return $this->send(new CancelPaymentRequest($id, $testmode)); + } + + /** + * Issue a refund for the given payment. + * + * The $data parameter may either be an array of endpoint + * parameters, or an instance of CreateRefundPaymentData. + * + * @param array|CreateRefundPayment $payload + * + * @throws ApiException + */ + public function refund(Payment $payment, $payload = []): Refund + { + if (! $payload instanceof CreateRefundPayment) { + $payload = CreateRefundPaymentPayloadFactory::new($payload) + ->create(); + } + + return $this->send(new CreateRefundPaymentRequest( + $payment->id, + $payload + )); + } + + /** + * Get the balance endpoint. + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection + { + $query = SortablePaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send(new GetPaginatedPaymentsRequest($query)); + } + + /** + * Create an iterator for iterating over payments retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = SortablePaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedPaymentsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php new file mode 100644 index 000000000..d9194b159 --- /dev/null +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -0,0 +1,29 @@ +create(); + } + + return $this->send(new GetPaginatedPaymentRefundsRequest( + $paymentId, + $query + )); + } +} diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php deleted file mode 100644 index 047ceca62..000000000 --- a/src/Endpoints/BalanceEndpoint.php +++ /dev/null @@ -1,104 +0,0 @@ -guardAgainstInvalidId($balanceId); - - /** @var Balance */ - return $this->readResource($balanceId, $parameters); - } - - /** - * Retrieve the primary balance from Mollie. - * - * Will throw an ApiException if the balance id is invalid or the resource cannot be found. - * - * @param array $parameters - * @return \Mollie\Api\Resources\Balance - * @throws ApiException - */ - public function primary(array $parameters = []): Balance - { - /** @var Balance */ - return $this->readResource("primary", $parameters); - } - - /** - * Retrieves a collection of Balances from Mollie. - * - * @param string|null $from The first Balance ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * - * @return BalanceCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): BalanceCollection - { - /** @var BalanceCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over balances retrieved from Mollie. - * - * @param string $from The first Balance ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/BalanceReportEndpoint.php b/src/Endpoints/BalanceReportEndpoint.php deleted file mode 100644 index 5ee35c454..000000000 --- a/src/Endpoints/BalanceReportEndpoint.php +++ /dev/null @@ -1,80 +0,0 @@ -parentId = $balanceId; - - $response = $this->client->performHttpCall( - self::REST_READ, - $this->getResourcePath() . $this->buildQueryString($parameters) - ); - - if ($response->isEmpty()) { - return null; - } - - /** @var BalanceReport */ - return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); - } - - /** - * Retrieve the primary balance. - * This is the balance of your account’s primary currency, where all payments are settled to by default. - * - * @param array $parameters - * - * @return BalanceReport - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForPrimary(array $parameters = []): BalanceReport - { - return $this->getForId("primary", $parameters); - } - - - /** - * Retrieve a balance report for the provided balance resource and parameters. - * - * @param Balance $balance - * @param array $parameters - * @return BalanceReport - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getFor(Balance $balance, array $parameters = []): BalanceReport - { - return $this->getForId($balance->id, $parameters); - } -} diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php deleted file mode 100644 index 187858c2e..000000000 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ /dev/null @@ -1,126 +0,0 @@ -listForId($balance->id, $parameters); - } - - /** - * Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie. - * - * @param Balance $balance - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->iteratorForId($balance->id, $parameters, $iterateBackwards); - } - - /** - * List the transactions for a specific Balance ID. - * - * @param string $balanceId - * @param array $parameters - * @return BalanceTransactionCollection - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $balanceId, array $parameters = []): BalanceTransactionCollection - { - $this->parentId = $balanceId; - - /** @var BalanceTransactionCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Create an iterator for iterating over balance transactions for the given balance id retrieved from Mollie. - * - * @param string $balanceId - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId(string $balanceId, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - $this->parentId = $balanceId; - - return $this->createIterator(null, null, $parameters, $iterateBackwards); - } - - /** - * List the transactions for the primary Balance. - * - * @param array $parameters - * @return BalanceTransactionCollection - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForPrimary(array $parameters = []): BalanceTransactionCollection - { - $this->parentId = "primary"; - - /** @var BalanceTransactionCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Create an iterator for iterating over transactions for the primary balance retrieved from Mollie. - * - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForPrimary(array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - $this->parentId = "primary"; - - return $this->createIterator(null, null, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/BaseEndpoint.php b/src/Endpoints/BaseEndpoint.php index 8a209bb47..a32862fda 100644 --- a/src/Endpoints/BaseEndpoint.php +++ b/src/Endpoints/BaseEndpoint.php @@ -5,21 +5,24 @@ use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; +use Mollie\Api\Types\Method; abstract class BaseEndpoint { - public const REST_CREATE = MollieApiClient::HTTP_POST; - public const REST_UPDATE = MollieApiClient::HTTP_PATCH; - public const REST_READ = MollieApiClient::HTTP_GET; - public const REST_LIST = MollieApiClient::HTTP_GET; - public const REST_DELETE = MollieApiClient::HTTP_DELETE; + public const REST_CREATE = Method::POST; + + public const REST_UPDATE = Method::PATCH; + + public const REST_READ = Method::GET; + + public const REST_LIST = Method::GET; + + public const REST_DELETE = Method::DELETE; protected MollieApiClient $client; /** * The resource path. - * - * @var string */ protected string $resourcePath; @@ -30,37 +33,32 @@ public function __construct(MollieApiClient $api) $this->client = $api; } - /** - * @param array $filters - * @return string - */ protected function buildQueryString(array $filters): string { if (empty($filters)) { - return ""; + return ''; } foreach ($filters as $key => $value) { if ($value === true) { - $filters[$key] = "true"; + $filters[$key] = 'true'; } if ($value === false) { - $filters[$key] = "false"; + $filters[$key] = 'false'; } } - return "?" . http_build_query($filters, "", "&"); + return '?'.http_build_query($filters, '', '&'); } /** - * @return string * @throws ApiException */ public function getResourcePath(): string { - if (strpos($this->resourcePath, "_") !== false) { - [$parentResource, $childResource] = explode("_", $this->resourcePath, 2); + if (strpos($this->resourcePath, '_') !== false) { + [$parentResource, $childResource] = explode('_', $this->resourcePath, 2); $this->guardAgainstMissingParentId($parentResource); @@ -79,10 +77,6 @@ protected function getPathToSingleResource(string $id): string return "{$this->getResourcePath()}/{$id}"; } - /** - * @param array $body - * @return null|string - */ protected function parseRequestBody(array $body): ?string { if (empty($body)) { diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php deleted file mode 100644 index 6571b3b7f..000000000 --- a/src/Endpoints/ChargebackEndpoint.php +++ /dev/null @@ -1,63 +0,0 @@ -fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over chargeback retrieved from Mollie. - * - * @param string $from The first chargevback ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php deleted file mode 100644 index 19263b4a9..000000000 --- a/src/Endpoints/ClientEndpoint.php +++ /dev/null @@ -1,85 +0,0 @@ -readResource($clientId, $parameters); - } - - /** - * Retrieves a page of clients from Mollie. - * - * @param string $from The first client ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return ClientCollection - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): ClientCollection - { - /** @var ClientCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over clients retrieved from Mollie. - * - * @param string $from The first client ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/ClientLinkEndpoint.php b/src/Endpoints/ClientLinkEndpoint.php deleted file mode 100644 index 0aba4d358..000000000 --- a/src/Endpoints/ClientLinkEndpoint.php +++ /dev/null @@ -1,37 +0,0 @@ -createResource($data, []); - } -} diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php deleted file mode 100644 index d6bb0d96f..000000000 --- a/src/Endpoints/PaymentEndpoint.php +++ /dev/null @@ -1,188 +0,0 @@ -createResource($data, $filters); - } - - /** - * Update the given Payment. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * - * @param string $paymentId - * @param array $data - * - * @return null|Payment - * @throws ApiException - */ - public function update($paymentId, array $data = []): ?Payment - { - $this->guardAgainstInvalidId($paymentId); - - /** @var null|Payment */ - return $this->updateResource($paymentId, $data); - } - - /** - * Retrieve a single payment from Mollie. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * - * @param string $paymentId - * @param array $parameters - * - * @return Payment - * @throws ApiException - */ - public function get($paymentId, array $parameters = []): Payment - { - $this->guardAgainstInvalidId($paymentId); - - /** @var Payment */ - return $this->readResource($paymentId, $parameters); - } - - /** - * Deletes the given Payment. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * Returns with HTTP status No Content (204) if successful. - * - * @param string $paymentId - * @param array $data - * - * @return Payment - * @throws ApiException - */ - public function delete(string $paymentId, array $data = []): ?Payment - { - return $this->cancel($paymentId, $data); - } - - /** - * Cancel the given Payment. This is just an alias of the 'delete' method. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * Returns with HTTP status No Content (204) if successful. - * - * @param string $paymentId - * @param array $data - * - * @return null|Payment - * @throws ApiException - */ - public function cancel(string $paymentId, array $data = []): ?Payment - { - /** @var null|Payment */ - return $this->deleteResource($paymentId, $data); - } - - /** - * Retrieves a collection of Payments from Mollie. - * - * @param string $from The first payment ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return PaymentCollection - * @throws ApiException - */ - public function page(string $from = null, int $limit = null, array $parameters = []): PaymentCollection - { - /** @var PaymentCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over payments retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } - - /** - * Issue a refund for the given payment. - * - * The $data parameter may either be an array of endpoint parameters, a float value to - * initiate a partial refund, or empty to do a full refund. - * - * @param Payment $payment - * @param array|float|null $data - * - * @return Refund - * @throws ApiException - */ - public function refund(Payment $payment, $data = []): Refund - { - $resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds"; - - $body = null; - if (($data === null ? 0 : count($data)) > 0) { - $body = json_encode($data); - } - - $result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body); - - /** @var Refund */ - return ResourceFactory::createFromApiResult($this->client, $result, Refund::class); - } -} diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index ad9db7306..b900cd020 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -4,34 +4,29 @@ use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\InteractsWithResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\ResourceFactory; +use Mollie\Api\Traits\InteractsWithResource as TraitsInteractsWithResource; use RuntimeException; abstract class RestEndpoint extends BaseEndpoint { - use InteractsWithResource; + use TraitsInteractsWithResource; /** * Resource id prefix. * Used to validate resource id's. - * - * @var string */ protected static string $resourceIdPrefix; /** - * @param array $body - * @param array $filters - * @return BaseResource * @throws ApiException */ protected function createResource(array $body, array $filters): BaseResource { $result = $this->client->performHttpCall( self::REST_CREATE, - $this->getResourcePath() . $this->buildQueryString($filters), + $this->getResourcePath().$this->buildQueryString($filters), $this->parseRequestBody($body) ); @@ -41,10 +36,7 @@ protected function createResource(array $body, array $filters): BaseResource /** * Sends a PATCH request to a single Mollie API object. * - * @param string $id - * @param array $body * - * @return null|BaseResource * @throws ApiException */ protected function updateResource(string $id, array $body = []): ?BaseResource @@ -67,21 +59,20 @@ protected function updateResource(string $id, array $body = []): ?BaseResource /** * Retrieves a single object from the REST API. * - * @param string $id Id of the object to retrieve. - * @param array $filters - * @return BaseResource + * @param string $id Id of the object to retrieve. + * * @throws ApiException */ protected function readResource(string $id, array $filters): BaseResource { - if (!$this instanceof SingleResourceEndpointContract && empty($id)) { - throw new ApiException("Invalid resource id."); + if (! $this instanceof SingleResourceEndpointContract && empty($id)) { + throw new ApiException('Invalid resource id.'); } $id = urlencode($id); $response = $this->client->performHttpCall( self::REST_READ, - $this->getPathToSingleResource($id) . $this->buildQueryString($filters) + $this->getPathToSingleResource($id).$this->buildQueryString($filters) ); return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); @@ -90,16 +81,13 @@ protected function readResource(string $id, array $filters): BaseResource /** * Sends a DELETE request to a single Mollie API object. * - * @param string $id - * @param array $body * - * @return null|BaseResource * @throws ApiException */ protected function deleteResource(string $id, array $body = []): ?BaseResource { if (empty($id)) { - throw new ApiException("Invalid resource id."); + throw new ApiException('Invalid resource id.'); } $id = urlencode($id); @@ -119,19 +107,19 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource protected function guardAgainstInvalidId(string $id): void { if (empty(static::$resourceIdPrefix)) { - throw new RuntimeException("Resource ID prefix is not set."); + throw new RuntimeException('Resource ID prefix is not set.'); } if (empty($id) || strpos($id, static::$resourceIdPrefix) !== 0) { $resourceType = $this->getResourceType(); - throw new ApiException("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '" . static::$resourceIdPrefix . "'."); + throw new ApiException("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '".static::$resourceIdPrefix."'."); } } public function getResourceType(): string { - $classBasename = basename(str_replace("\\", "/", static::getResourceClass())); + $classBasename = basename(str_replace('\\', '/', static::getResourceClass())); return strtolower($classBasename); } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 02936b93d..b4e8b0ecb 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -9,49 +9,26 @@ class ApiException extends \Exception { - /** - * @var string - */ protected ?string $field = null; - /** - * @var string - */ protected string $plainMessage; - /** - * @var RequestInterface|null - */ protected ?RequestInterface $request; - /** - * @var ResponseInterface|null - */ protected ?ResponseInterface $response; /** * ISO8601 representation of the moment this exception was thrown - * - * @var \DateTimeImmutable */ protected \DateTimeImmutable $raisedAt; - /** - * @var array - */ protected array $links = []; /** - * @param string $message - * @param int $code - * @param string|null $field - * @param RequestInterface|null $request - * @param ResponseInterface|null $response - * @param Throwable|null $previous * @throws ApiException */ public function __construct( - string $message = "", + string $message = '', int $code = 0, ?string $field = null, ?RequestInterface $request = null, @@ -60,13 +37,13 @@ public function __construct( ) { $this->plainMessage = $message; - $this->raisedAt = new \DateTimeImmutable(); + $this->raisedAt = new \DateTimeImmutable; $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); - $message = "[{$formattedRaisedAt}] " . $message; + $message = "[{$formattedRaisedAt}] ".$message; if (! empty($field)) { - $this->field = (string)$field; + $this->field = (string) $field; $message .= ". Field: {$this->field}"; } @@ -98,75 +75,33 @@ public function __construct( parent::__construct($message, $code, $previous); } - /** - * @param ResponseInterface $response - * @param ?RequestInterface $request - * @param Throwable|null $previous - * @return ApiException - * @throws ApiException - */ - public static function createFromResponse(ResponseInterface $response, ?RequestInterface $request = null, ?Throwable $previous = null): self - { - $object = static::parseResponseBody($response); - - $field = null; - if (! empty($object->field)) { - $field = $object->field; - } - - return new self( - "Error executing API call ({$object->status}: {$object->title}): {$object->detail}", - $response->getStatusCode(), - $field, - $request, - $response, - $previous - ); - } - - /** - * @return string|null - */ public function getField(): ?string { return $this->field; } - /** - * @return string|null - */ public function getDocumentationUrl(): ?string { return $this->getUrl('documentation'); } - /** - * @return string|null - */ public function getDashboardUrl(): ?string { return $this->getUrl('dashboard'); } - /** - * @return ResponseInterface|null - */ public function getResponse(): ?ResponseInterface { return $this->response; } - /** - * @return bool - */ public function hasResponse(): bool { - return ! ! $this->response; + return (bool) $this->response; } /** - * @param string $key - * @return bool + * @param string $key */ public function hasLink($key): bool { @@ -174,8 +109,7 @@ public function hasLink($key): bool } /** - * @param string $key - * @return \stdClass|null + * @param string $key */ public function getLink($key): ?\stdClass { @@ -187,8 +121,7 @@ public function getLink($key): ?\stdClass } /** - * @param string $key - * @return string|null + * @param string $key */ public function getUrl($key): ?string { @@ -199,9 +132,6 @@ public function getUrl($key): ?string return null; } - /** - * @return null|RequestInterface - */ public function getRequest(): ?RequestInterface { return $this->request; @@ -209,8 +139,6 @@ public function getRequest(): ?RequestInterface /** * Get the ISO8601 representation of the moment this exception was thrown - * - * @return \DateTimeImmutable */ public function getRaisedAt(): \DateTimeImmutable { @@ -218,8 +146,8 @@ public function getRaisedAt(): \DateTimeImmutable } /** - * @param ResponseInterface $response - * @return \stdClass + * @param ResponseInterface $response + * * @throws ApiException */ protected static function parseResponseBody($response): \stdClass @@ -237,8 +165,6 @@ protected static function parseResponseBody($response): \stdClass /** * Retrieve the plain exception message. - * - * @return string */ public function getPlainMessage(): string { diff --git a/src/Exceptions/RequestValidationException.php b/src/Exceptions/RequestValidationException.php new file mode 100644 index 000000000..f9d4bc202 --- /dev/null +++ b/src/Exceptions/RequestValidationException.php @@ -0,0 +1,5 @@ +data['amount'])->create(), + $this->data['description'], + ); + } +} diff --git a/src/Factories/CreateClientLinkPayloadFactory.php b/src/Factories/CreateClientLinkPayloadFactory.php new file mode 100644 index 000000000..9135ca6a5 --- /dev/null +++ b/src/Factories/CreateClientLinkPayloadFactory.php @@ -0,0 +1,21 @@ +get('owner')), + $this->get('name'), + OwnerAddress::fromArray($this->get('address')), + $this->get('registrationNumber'), + $this->get('vatNumber') + ); + } +} diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php new file mode 100644 index 000000000..d84e5b384 --- /dev/null +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -0,0 +1,50 @@ +get('description'), + MoneyFactory::new($this->get('amount'))->create(), + $this->get('redirectUrl'), + $this->get('cancelUrl'), + $this->get('webhookUrl'), + $this + ->mapIfNotNull( + 'lines', + fn (array $items) => OrderLineCollectionFactory::new($items)->create() + ), + $this->mapIfNotNull('billingAddress', fn (array $item) => Address::fromArray($item)), + $this->mapIfNotNull('shippingAddress', fn (array $item) => Address::fromArray($item)), + $this->get('locale'), + $this->get('method'), + $this->get('issuer'), + $this->get('restrictPaymentMethodsToCountry'), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('captureMode'), + $this->get('captureDelay'), + $this->mapIfNotNull( + 'applicationFee', + fn (array $item) => ApplicationFeeFactory::new($item)->create() + ), + $this->mapIfNotNull( + 'routing', + fn (array $items) => PaymentRouteCollectionFactory::new($items)->create() + ), + $this->get('sequenceType'), + $this->get('mandateId'), + $this->get('customerId'), + $this->get('profileId'), + $this->get('additional') ?? Helpers::filterByProperties(CreatePayment::class, $this->data), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php new file mode 100644 index 000000000..822293f3b --- /dev/null +++ b/src/Factories/CreateRefundPaymentPayloadFactory.php @@ -0,0 +1,25 @@ +get('description'), + MoneyFactory::new($this->data['amount'])->create(), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('reverseRouting'), + $this + ->mapIfNotNull( + 'routingReversals', + fn (array $items) => RefundRouteCollectionFactory::new($items)->create() + ), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php new file mode 100644 index 000000000..b666f4d2d --- /dev/null +++ b/src/Factories/Factory.php @@ -0,0 +1,44 @@ +data = $data; + } + + public static function new(array $data): static + { + return new static($data); + } + + protected function get(string $key, $default = null): mixed + { + return Arr::get($this->data, $key, $default); + } + + protected function has($keys): bool + { + return Arr::has($this->data, $keys); + } + + /** + * Map a value to a new form if it is not null. + * + * @param string $key The key to retrieve the value from the data array. + * @param callable|string $composable A callable function to transform the value, or the name of a class to instantiate. + * @return mixed The transformed value, a new class instance, or null if the value is null. + */ + protected function mapIfNotNull(string $key, $composable): mixed + { + return Helpers::compose($this->get($key), $composable); + } +} diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php new file mode 100644 index 000000000..a5c1c0a42 --- /dev/null +++ b/src/Factories/GetBalanceReportQueryFactory.php @@ -0,0 +1,23 @@ +has(['from', 'unitl'])) { + throw new \InvalidArgumentException('The "from" and "until" fields are required.'); + } + + return new GetBalanceReportQuery( + DateTime::createFromFormat('Y-m-d', $this->get('from')), + DateTime::createFromFormat('Y-m-d', $this->get('until')), + $this->get('grouping'), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/GetPaginatedBalanceQueryFactory.php b/src/Factories/GetPaginatedBalanceQueryFactory.php new file mode 100644 index 000000000..30782dd84 --- /dev/null +++ b/src/Factories/GetPaginatedBalanceQueryFactory.php @@ -0,0 +1,21 @@ +get('filters.testmode'); + $currency = $this->get('filters.currency'); + + return new GetPaginatedBalanceQuery( + $this->get('currency', $currency), + $this->get('from'), + $this->get('limit'), + $this->get('testmode', $testmode) + ); + } +} diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php new file mode 100644 index 000000000..0814cf1c3 --- /dev/null +++ b/src/Factories/GetPaginatedChargebackQueryFactory.php @@ -0,0 +1,19 @@ +has('includePayment') || $this->get('filters.include') === 'payment', + $this->get('profileId', $this->get('filters.profileId')), + $this->get('from'), + $this->get('limit'), + $this->get('testmode', $this->get('filters.testmode')) + ); + } +} diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php new file mode 100644 index 000000000..5eb21c62d --- /dev/null +++ b/src/Factories/GetPaginatedClientQueryFactory.php @@ -0,0 +1,17 @@ +get('embed', $this->get('filters.embed', [])), + $this->get('from'), + $this->get('limit'), + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php new file mode 100644 index 000000000..b512f12b6 --- /dev/null +++ b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php @@ -0,0 +1,18 @@ +has('includePayment') || $this->get('filters.include') === 'payment', + $this->get('from'), + $this->get('limit'), + $this->get('testmode', $this->get('filters.testmode')) + ); + } +} diff --git a/src/Factories/GetPaymentQueryFactory.php b/src/Factories/GetPaymentQueryFactory.php new file mode 100644 index 000000000..6245ffb0e --- /dev/null +++ b/src/Factories/GetPaymentQueryFactory.php @@ -0,0 +1,17 @@ +get('embed', []), + $this->get('include', []), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/MoneyFactory.php b/src/Factories/MoneyFactory.php new file mode 100644 index 000000000..fb9fd2f10 --- /dev/null +++ b/src/Factories/MoneyFactory.php @@ -0,0 +1,20 @@ +has(['currency', 'value'])) { + throw new \InvalidArgumentException('Invalid Money data provided'); + } + + return new Money( + $this->get('currency'), + $this->get('value') + ); + } +} diff --git a/src/Factories/OrderLineCollectionFactory.php b/src/Factories/OrderLineCollectionFactory.php new file mode 100644 index 000000000..1af655510 --- /dev/null +++ b/src/Factories/OrderLineCollectionFactory.php @@ -0,0 +1,16 @@ + OrderLineFactory::new($item)->create(), + $this->data + )); + } +} diff --git a/src/Factories/OrderLineFactory.php b/src/Factories/OrderLineFactory.php new file mode 100644 index 000000000..e8920704e --- /dev/null +++ b/src/Factories/OrderLineFactory.php @@ -0,0 +1,27 @@ +get('description'), + $this->get('quantity'), + MoneyFactory::new($this->get('unitPrice'))->create(), + MoneyFactory::new($this->get('totalAmount'))->create(), + $this->get('type'), + $this->get('quantityUnit'), + $this->mapIfNotNull('discountAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('recurring', fn (array $item) => RecurringBillingCycleFactory::new($item)->create()), + $this->get('vatRate'), + $this->mapIfNotNull('vatAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->get('sku'), + $this->get('imageUrl'), + $this->get('productUrl'), + ); + } +} diff --git a/src/Factories/PaginatedQueryFactory.php b/src/Factories/PaginatedQueryFactory.php new file mode 100644 index 000000000..3afa55dca --- /dev/null +++ b/src/Factories/PaginatedQueryFactory.php @@ -0,0 +1,19 @@ +get('filters.testmode'); + + return new PaginatedQuery( + $this->get('from'), + $this->get('limit'), + $this->get('testmode', $testmode) + ); + } +} diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php new file mode 100644 index 000000000..10bcb665f --- /dev/null +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -0,0 +1,32 @@ +has(['amount', 'destination.organizationId'])) { + throw new \InvalidArgumentException('Invalid PaymentRoute data provided'); + } + + return new PaymentRoute( + MoneyFactory::new(Arr::get($item, 'amount'))->create(), + Arr::get($item, 'destination.organizationId'), + Helpers::compose( + Arr::get($item, 'delayUntil'), + fn ($value) => DateTime::createFromFormat('Y-m-d', $value) + ) + ); + }, $this->data); + + return new DataCollection($paymentRoutes); + } +} diff --git a/src/Factories/RecurringBillingCycleFactory.php b/src/Factories/RecurringBillingCycleFactory.php new file mode 100644 index 000000000..88cb22bb8 --- /dev/null +++ b/src/Factories/RecurringBillingCycleFactory.php @@ -0,0 +1,20 @@ +get('interval'), + $this->get('descriptipn'), + $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->get('times'), + $this->mapIfNotNull('startDate', fn (string $item) => DateTime::createFromFormat('Y-m-d', $item)), + ); + } +} diff --git a/src/Factories/RefundRouteCollectionFactory.php b/src/Factories/RefundRouteCollectionFactory.php new file mode 100644 index 000000000..7bb613e1e --- /dev/null +++ b/src/Factories/RefundRouteCollectionFactory.php @@ -0,0 +1,26 @@ +has(['amount', 'source.organizationId'])) { + throw new \InvalidArgumentException('Invalid RefundRoute data provided'); + } + + return new RefundRoute( + MoneyFactory::new(Arr::get($item, 'amount'))->create(), + Arr::get($item, 'source.organizationId') + ); + }, $this->data); + + return new DataCollection($refundRoutes); + } +} diff --git a/src/Factories/SortablePaginatedQueryFactory.php b/src/Factories/SortablePaginatedQueryFactory.php new file mode 100644 index 000000000..53a16c2db --- /dev/null +++ b/src/Factories/SortablePaginatedQueryFactory.php @@ -0,0 +1,21 @@ +get('filters.sort'); + $testmode = $this->get('filters.testmode'); + + return new SortablePaginatedQuery( + $this->get('from'), + $this->get('limit'), + $this->get('sort', $sort), + $this->get('testmode', $testmode) + ); + } +} diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php new file mode 100644 index 000000000..2e7ee1510 --- /dev/null +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -0,0 +1,26 @@ +get('description'), + $this->get('redirectUrl'), + $this->get('cancelUrl'), + $this->get('webhookUrl'), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('method'), + $this->get('locale'), + $this->get('restrictPaymentMethodsToCountry'), + $this->get('additional') ?? Helpers::filterByProperties(UpdatePayment::class, $this->data), + $this->get('testmode') + ); + } +} diff --git a/src/Helpers.php b/src/Helpers.php new file mode 100644 index 000000000..624bbdc7c --- /dev/null +++ b/src/Helpers.php @@ -0,0 +1,109 @@ + + */ + public static function classUsesRecursive(object|string $class): array + { + if (is_object($class)) { + $class = get_class($class); + } + + $results = []; + + foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) { + $results += static::traitUsesRecursive($class); + } + + return array_unique($results); + } + + /** + * Returns all traits used by a trait and its traits. + * + * @param class-string $trait + * @return array + */ + public static function traitUsesRecursive(string $trait): array + { + /** @var array $traits */ + $traits = class_uses($trait) ?: []; + + foreach ($traits as $trait) { + $traits += static::traitUsesRecursive($trait); + } + + return $traits; + } + + /** + * Get the properties of a class. + * + * @param int $flag + * @return ReflectionProperty[] + */ + public static function getProperties(string|object $class, $flag = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE): array + { + $reflection = new ReflectionClass($class); + + return $reflection->getProperties($flag); + } + + /** + * Filter out the properties that are not part of the given class. + */ + public static function filterByProperties(string|object $class, array $array): array + { + $properties = array_map( + fn (ReflectionProperty $prop) => $prop->getName(), + static::getProperties($class) + ); + + // Filter out the properties that are not part of the CreatePaymentData object + return array_filter( + $array, + fn ($key) => ! in_array($key, $properties, true), + ARRAY_FILTER_USE_KEY + ); + } + + /** + * Compose a value to a new form if it is truthy. + * + * @param mixed $value + * @param string|callable $composable + * @param mixed $default + * @return mixed + */ + public static function compose($value, $composable, $default = null) + { + $composable = is_callable($composable) + ? $composable + : fn ($value) => new $composable($value); + + return (bool) $value ? $composable($value) : $default; + } + + /** + * Extract a boolean value if not already a boolean. + * + * @param mixed $value + */ + public static function extractBool($value, string $key, bool $default = false): bool + { + return is_bool($value) + ? $value + : Arr::get($value, $key, $default); + } +} diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php new file mode 100644 index 000000000..b5d4d6c55 --- /dev/null +++ b/src/Helpers/Arr.php @@ -0,0 +1,85 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->streamFactory = $streamFactory; + $this->uriFactory = $uriFactory; + } +} diff --git a/src/Helpers/Handlers.php b/src/Helpers/Handlers.php new file mode 100644 index 000000000..9a2593d7d --- /dev/null +++ b/src/Helpers/Handlers.php @@ -0,0 +1,31 @@ +handlers[] = $handler; + } + + /** + * Execute the handlers + * + * @param PendingRequest|Response $payload + * @return PendingRequest|Response + */ + public function execute($payload) + { + foreach ($this->handlers as $handler) { + $payload = $handler($payload); + } + + return $payload; + } +} diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Helpers/MiddlewareHandlers.php new file mode 100644 index 000000000..1ef858ade --- /dev/null +++ b/src/Helpers/MiddlewareHandlers.php @@ -0,0 +1,55 @@ +onRequest = new Handlers; + $this->onResponse = new Handlers; + } + + public function onRequest(callable $callback): static + { + $this->onRequest->add(static function (PendingRequest $pendingRequest) use ($callback): PendingRequest { + $result = $callback($pendingRequest); + + if ($result instanceof PendingRequest) { + return $result; + } + + return $pendingRequest; + }); + + return $this; + } + + public function onResponse(callable $callback): static + { + $this->onResponse->add(static function (Response $response) use ($callback): Response { + $result = $callback($response); + + return $result instanceof Response ? $result : $response; + }); + + return $this; + } + + public function executeOnRequest(PendingRequest $pendingRequest): PendingRequest + { + return $this->onRequest->execute($pendingRequest); + } + + public function executeOnResponse(Response $response): Response + { + return $this->onResponse->execute($response); + } +} diff --git a/src/Helpers/Url.php b/src/Helpers/Url.php new file mode 100644 index 000000000..ee343d0b6 --- /dev/null +++ b/src/Helpers/Url.php @@ -0,0 +1,53 @@ + + */ + public static function parseQuery(string $query): array + { + if ($query === '') { + return []; + } + + $parameters = []; + + foreach (explode('&', $query) as $parameter) { + $name = urldecode((string) strtok($parameter, '=')); + $value = urldecode((string) strtok('=')); + + if (! $name || str_starts_with($parameter, '=')) { + continue; + } + + $parameters[$name] = $value; + } + + return $parameters; + } +} diff --git a/src/Helpers/Validator.php b/src/Helpers/Validator.php new file mode 100644 index 000000000..fc35e1ab2 --- /dev/null +++ b/src/Helpers/Validator.php @@ -0,0 +1,72 @@ +rules(); + + [$validatableProperties, $propsWithRules] = $this->extractValidatableAndRules($provider, $rules); + + // Validate validatable properties + foreach ($validatableProperties as $property) { + $this->validate($property); + } + + // Merge additional rules with the rulesWithValues array + foreach ($additional as $key => $value) { + if (array_key_exists($key, $rules)) { + $propsWithRules[$key] = $value; + } + } + + // Validate properties with rules + foreach ($propsWithRules as $key => $value) { + $rules[$key]->validate($value, $provider, static fn (string $message) => throw new RequestValidationException($message)); + } + } + + private function extractValidatableAndRules($provider, array $rules): array + { + $validatableProperties = []; + $propsWithRules = []; + + /** @var ReflectionProperty $property */ + foreach (Helpers::getProperties($provider) as $property) { + if ($property->isStatic() || ! $property->isInitialized($provider)) { + continue; + } + + $value = $this->extractValue($provider, $property); + + if ($value === null) { + continue; + } + + if ($value instanceof ValidatableDataProvider) { + $validatableProperties[] = $value; + } elseif (array_key_exists($property->getName(), $rules)) { + $propsWithRules[$property->getName()] = $value; + } + } + + return [$validatableProperties, $propsWithRules]; + } + + private function extractValue($provider, ReflectionProperty $property) + { + $property->setAccessible(true); + + return $property->getValue($provider); + } +} diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index cd27d0eaf..dc394df38 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -3,16 +3,19 @@ namespace Mollie\Api\Http\Adapter; use Composer\CaBundle\CaBundle; -use Mollie\Api\Contracts\MollieHttpAdapterContract; -use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\CurlConnectTimeoutException; +use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Http\ResponseHandler; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Traits\HasDefaultFactories; +use Mollie\Api\Types\Method; +use Throwable; -final class CurlMollieHttpAdapter implements MollieHttpAdapterContract +final class CurlMollieHttpAdapter implements HttpAdapterContract { + use HasDefaultFactories; + /** * Default response timeout (in seconds). */ @@ -34,48 +37,58 @@ final class CurlMollieHttpAdapter implements MollieHttpAdapterContract public const DELAY_INCREASE_MS = 1000; /** - * @param string $method - * @param string $url - * @param array $headers - * @param string $body - * @return ResponseContract * @throws \Mollie\Api\Exceptions\ApiException * @throws \Mollie\Api\Exceptions\CurlConnectTimeoutException */ - public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract + public function sendRequest(PendingRequest $pendingRequest): Response { for ($i = 0; $i <= self::MAX_RETRIES; $i++) { usleep($i * self::DELAY_INCREASE_MS); try { - return ResponseHandler::create() - ->handle( - $this->attemptRequest($method, $url, $headers, $body), - $body - ); + [$headers, $body, $statusCode] = $this->send($pendingRequest); + + return $this->createResponse($pendingRequest, $statusCode, $headers, $body); } catch (CurlConnectTimeoutException $e) { - return ResponseHandler::noResponse(); + return $this->createResponse($pendingRequest, 504, [], null, $e); } } throw new CurlConnectTimeoutException( - "Unable to connect to Mollie. Maximum number of retries (" . self::MAX_RETRIES . ") reached." + 'Unable to connect to Mollie. Maximum number of retries ('.self::MAX_RETRIES.') reached.' + ); + } + + protected function createResponse(PendingRequest $pendingRequest, int $statusCode, $headers = [], $body = null, ?Throwable $error = null): Response + { + $factoryCollection = $pendingRequest->getFactoryCollection(); + $responseFactory = $factoryCollection->responseFactory; + + $response = $responseFactory->createResponse($statusCode) + ->withBody($factoryCollection->streamFactory->createStream($body)); + + foreach ($headers as $key => $value) { + $response = $response->withHeader($key, $value); + } + + return new Response( + $response, + $pendingRequest->createPsrRequest(), + $pendingRequest, + $error ); } /** - * @param string $method - * @param string $url - * @param array $headers - * @param string $body - * @return Response * @throws \Mollie\Api\Exceptions\ApiException */ - protected function attemptRequest(string $method, string $url, array $headers = [], ?string $body = null): Response + protected function send(PendingRequest $pendingRequest): array { - $curl = $this->initializeCurl($url); - $this->setCurlHeaders($curl, $headers); - $this->setCurlMethodOptions($curl, $method, $body); + $request = $pendingRequest->createPsrRequest(); + + $curl = $this->initializeCurl($request->getUri()); + $this->setCurlHeaders($curl, $pendingRequest->headers()->all()); + $this->setCurlMethodOptions($curl, $pendingRequest->method(), $request->getBody()); $startTime = microtime(true); $response = curl_exec($curl); @@ -88,13 +101,12 @@ protected function attemptRequest(string $method, string $url, array $headers = [$headers, $content, $statusCode] = $this->extractResponseDetails($curl, $response); curl_close($curl); - return new Response($statusCode, $content, ''); + return [$headers, $content, $statusCode]; } private function initializeCurl(string $url) { $curl = curl_init($url); - $headerValues["Content-Type"] = "application/json"; curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); @@ -108,7 +120,7 @@ private function initializeCurl(string $url) private function setCurlHeaders($curl, array $headers) { - $headers["Content-Type"] = "application/json"; + $headers['Content-Type'] = 'application/json'; curl_setopt($curl, CURLOPT_HTTPHEADER, $this->parseHeaders($headers)); } @@ -116,28 +128,28 @@ private function setCurlHeaders($curl, array $headers) private function setCurlMethodOptions($curl, string $method, ?string $body): void { switch ($method) { - case MollieApiClient::HTTP_POST: + case Method::POST: curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; - case MollieApiClient::HTTP_PATCH: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_PATCH); + case Method::PATCH: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, Method::PATCH); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; - case MollieApiClient::HTTP_DELETE: - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, MollieApiClient::HTTP_DELETE); + case Method::DELETE: + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, Method::DELETE); curl_setopt($curl, CURLOPT_POSTFIELDS, $body); break; - case MollieApiClient::HTTP_GET: + case Method::GET: default: - if ($method !== MollieApiClient::HTTP_GET) { - throw new \InvalidArgumentException("Invalid HTTP method: " . $method); + if ($method !== Method::GET) { + throw new \InvalidArgumentException('Invalid HTTP method: '.$method); } break; @@ -147,10 +159,10 @@ private function setCurlMethodOptions($curl, string $method, ?string $body): voi private function handleCurlError($curl, float $executionTime): void { $curlErrorNumber = curl_errno($curl); - $curlErrorMessage = "Curl error: " . curl_error($curl); + $curlErrorMessage = 'Curl error: '.curl_error($curl); if ($this->isConnectTimeoutError($curlErrorNumber, $executionTime)) { - throw new CurlConnectTimeoutException("Unable to connect to Mollie. " . $curlErrorMessage); + throw new CurlConnectTimeoutException('Unable to connect to Mollie. '.$curlErrorMessage); } throw new ApiException($curlErrorMessage); @@ -167,7 +179,7 @@ private function extractResponseDetails($curl, string $response): array $headerLines = explode("\r\n", $headerValues); foreach ($headerLines as $headerLine) { if (strpos($headerLine, ':') !== false) { - list($key, $value) = explode(': ', $headerLine, 2); + [$key, $value] = explode(': ', $headerLine, 2); $headers[$key] = $value; } } @@ -176,9 +188,7 @@ private function extractResponseDetails($curl, string $response): array } /** - * @param int $curlErrorNumber - * @param string|float $executionTime - * @return bool + * @param string|float $executionTime */ protected function isConnectTimeoutError(int $curlErrorNumber, $executionTime): bool { @@ -191,7 +201,7 @@ protected function isConnectTimeoutError(int $curlErrorNumber, $executionTime): if (isset($connectErrors[$curlErrorNumber])) { return true; - }; + } if ($curlErrorNumber === \CURLE_OPERATION_TIMEOUTED) { if ($executionTime > self::DEFAULT_TIMEOUT) { @@ -209,7 +219,7 @@ private function parseHeaders(array $headers): array $result = []; foreach ($headers as $key => $value) { - $result[] = $key . ': ' . $value; + $result[] = $key.': '.$value; } return $result; @@ -217,9 +227,8 @@ private function parseHeaders(array $headers): array /** * The version number for the underlying http client, if available. - * @example Guzzle/6.3 * - * @return string + * @example Guzzle/6.3 */ public function version(): string { diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index c2d872132..6f9b2dc3e 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -5,18 +5,24 @@ use Composer\CaBundle\CaBundle; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7\HttpFactory; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions as GuzzleRequestOptions; -use Mollie\Api\Contracts\MollieHttpAdapterContract; -use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\IsDebuggable; -use Mollie\Api\Http\PsrResponseHandler; - -final class GuzzleMollieHttpAdapter implements MollieHttpAdapterContract, SupportsDebuggingContract +use Mollie\Api\Helpers\Factories; +use Mollie\Api\Http\PendingRequest; +use Mollie\Api\Http\Response; +use Mollie\Api\Traits\IsDebuggable; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Throwable; + +final class GuzzleMollieHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { use IsDebuggable; @@ -35,9 +41,6 @@ final class GuzzleMollieHttpAdapter implements MollieHttpAdapterContract, Suppor */ public const HTTP_NO_CONTENT = 204; - /** - * @var \GuzzleHttp\ClientInterface - */ protected ClientInterface $httpClient; public function __construct(ClientInterface $httpClient) @@ -45,10 +48,20 @@ public function __construct(ClientInterface $httpClient) $this->httpClient = $httpClient; } + public function factories(): Factories + { + $factory = new HttpFactory; + + return new Factories( + requestFactory: $factory, + responseFactory: $factory, + streamFactory: $factory, + uriFactory: $factory, + ); + } + /** * Instantiate a default adapter with sane configuration for Guzzle 6 or 7. - * - * @return self */ public static function createDefault(): self { @@ -69,37 +82,47 @@ public static function createDefault(): self /** * Send a request to the specified Mollie api url. * - * @param string $method - * @param string $url - * @param array $headers - * @param string $body - * @return ResponseContract * @throws \Mollie\Api\Exceptions\ApiException */ - public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract + public function sendRequest(PendingRequest $pendingRequest): Response { - $request = new Request($method, $url, $headers, $body); + $request = $pendingRequest->createPsrRequest(); try { $response = $this->httpClient->send($request, ['http_errors' => false]); - } catch (GuzzleException $e) { - // Prevent sensitive request data from ending up in exception logs unintended + + return $this->createResponse($response, $request, $pendingRequest); + } catch (ConnectException $e) { if (! $this->debug) { $request = null; } - // Not all Guzzle Exceptions implement hasResponse() / getResponse() - if (method_exists($e, 'hasResponse') && method_exists($e, 'getResponse')) { - if ($e->hasResponse()) { - throw ApiException::createFromResponse($e->getResponse(), $request); - } + throw new ApiException($e->getMessage(), $e->getCode(), null, $request, null); + } catch (RequestException $e) { + // Prevent sensitive request data from ending up in exception logs unintended + if (! $this->debug) { + $request = null; } - throw new ApiException($e->getMessage(), $e->getCode(), null, $request, null); + return $this->createResponse($e->getResponse(), $request, $pendingRequest, $e); } + } - return PsrResponseHandler::create() - ->handle($request, $response, $response->getStatusCode(), $body); + /** + * Create a response. + */ + protected function createResponse( + ResponseInterface $psrResponse, + RequestInterface $psrRequest, + PendingRequest $pendingRequest, + ?Throwable $exception = null + ): Response { + return new Response( + $psrResponse, + $psrRequest, + $pendingRequest, + $exception + ); } /** @@ -107,11 +130,9 @@ public function send(string $method, string $url, $headers, ?string $body = null * This is used to report the UserAgent to Mollie, for convenient support. * * @example Guzzle/7.0 - * - * @return string */ public function version(): string { - return "Guzzle/" . ClientInterface::MAJOR_VERSION; + return 'Guzzle/'.ClientInterface::MAJOR_VERSION; } } diff --git a/src/Http/Adapter/MollieHttpAdapterPicker.php b/src/Http/Adapter/MollieHttpAdapterPicker.php index b709e1d29..77261d1eb 100644 --- a/src/Http/Adapter/MollieHttpAdapterPicker.php +++ b/src/Http/Adapter/MollieHttpAdapterPicker.php @@ -2,19 +2,18 @@ namespace Mollie\Api\Http\Adapter; -use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; use Mollie\Api\Exceptions\UnrecognizedClientException; class MollieHttpAdapterPicker implements MollieHttpAdapterPickerContract { /** - * @param \GuzzleHttp\ClientInterface|MollieHttpAdapterContract|null|\stdClass $httpClient + * @param \GuzzleHttp\ClientInterface|HttpAdapterContract|null|\stdClass $httpClient * - * @return MollieHttpAdapterContract * @throws \Mollie\Api\Exceptions\UnrecognizedClientException */ - public function pickHttpAdapter($httpClient): MollieHttpAdapterContract + public function pickHttpAdapter($httpClient): HttpAdapterContract { if (! $httpClient) { if ($this->guzzleIsDetected()) { @@ -28,7 +27,7 @@ public function pickHttpAdapter($httpClient): MollieHttpAdapterContract return new CurlMollieHttpAdapter; } - if ($httpClient instanceof MollieHttpAdapterContract) { + if ($httpClient instanceof HttpAdapterContract) { return $httpClient; } @@ -39,17 +38,11 @@ public function pickHttpAdapter($httpClient): MollieHttpAdapterContract throw new UnrecognizedClientException('The provided http client or adapter was not recognized.'); } - /** - * @return bool - */ private function guzzleIsDetected(): bool { - return interface_exists('\\' . \GuzzleHttp\ClientInterface::class); + return interface_exists('\\'.\GuzzleHttp\ClientInterface::class); } - /** - * @return int|null - */ private function guzzleMajorVersionNumber(): ?int { // Guzzle 7 diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 7afda88d5..d5513ab35 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -2,71 +2,83 @@ namespace Mollie\Api\Http\Adapter; -use Mollie\Api\Contracts\MollieHttpAdapterContract; -use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\IsDebuggable; -use Mollie\Api\Http\PsrResponseHandler; +use Mollie\Api\Helpers\Factories; +use Mollie\Api\Http\PendingRequest; +use Mollie\Api\Http\Response; +use Mollie\Api\Traits\IsDebuggable; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UriFactoryInterface; -final class PSR18MollieHttpAdapter implements MollieHttpAdapterContract, SupportsDebuggingContract +final class PSR18MollieHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { use IsDebuggable; - /** - * @var ClientInterface - */ private ClientInterface $httpClient; - /** - * @var RequestFactoryInterface - */ private RequestFactoryInterface $requestFactory; - /** - * @var StreamFactoryInterface - */ + private ResponseFactoryInterface $responseFactory; + private StreamFactoryInterface $streamFactory; + private UriFactoryInterface $uriFactory; + /** * PSR18MollieHttpAdapter constructor. - * - * @param ClientInterface $httpClient - * @param RequestFactoryInterface $requestFactory - * @param StreamFactoryInterface $streamFactory */ public function __construct( ClientInterface $httpClient, RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory + ResponseFactoryInterface $responseFactory, + StreamFactoryInterface $streamFactory, + UriFactoryInterface $uriFactory ) { $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; $this->streamFactory = $streamFactory; + $this->uriFactory = $uriFactory; + } + + public function factories(): Factories + { + return new Factories( + requestFactory: $this->requestFactory, + responseFactory: $this->responseFactory, + streamFactory: $this->streamFactory, + uriFactory: $this->uriFactory, + ); } /** * {@inheritdoc} */ - public function send(string $method, string $url, $headers, ?string $body = null): ResponseContract + public function sendRequest(PendingRequest $pendingRequest): Response { + $request = $pendingRequest->createPsrRequest(); + try { - $request = $this->createRequest($method, $url, $headers, $body ?? ''); $response = $this->httpClient->sendRequest($request); - return PsrResponseHandler::create() - ->handle($request, $response, $response->getStatusCode(), $body); - } catch (\Exception $e) { + return new Response( + $response, + $request, + $pendingRequest + ); + } catch (ClientExceptionInterface $e) { if (! $this->debug) { $request = null; } throw new ApiException( - "Error while sending request to Mollie API: " . $e->getMessage(), + 'Error while sending request to Mollie API: '.$e->getMessage(), 0, $e, $request, @@ -82,52 +94,4 @@ public function version(): string { return 'PSR18MollieHttpAdapter'; } - - /** - * Create a PSR-7 request. - * - * @param string $httpMethod - * @param string $url - * @param string|array $headers - * @param string $httpBody - * @return RequestInterface - */ - private function createRequest(string $httpMethod, string $url, $headers, ?string $httpBody): RequestInterface - { - $stream = $this->streamFactory->createStream($httpBody); - - $request = $this - ->requestFactory - ->createRequest($httpMethod, $url) - ->withBody($stream); - - return $this->addHeadersToRequest($request, $headers); - } - - /** - * Parse and add headers to request. - * - * @param RequestInterface $request - * @param string|array $headers - * @return RequestInterface - */ - private function addHeadersToRequest(RequestInterface $request, $headers): RequestInterface - { - if (is_array($headers)) { - foreach ($headers as $name => $value) { - $request = $request->withHeader($name, $value); - } - } - - if (is_string($headers)) { - $headerLines = explode("\r\n", $headers); - - foreach ($headerLines as $line) { - list($name, $value) = explode(': ', $line, 2); - $request = $request->withHeader($name, $value); - } - } - - return $request; - } } diff --git a/src/Http/Auth/AccessTokenAuthenticator.php b/src/Http/Auth/AccessTokenAuthenticator.php new file mode 100644 index 000000000..1b5f0c8e9 --- /dev/null +++ b/src/Http/Auth/AccessTokenAuthenticator.php @@ -0,0 +1,18 @@ +token = trim($token); + } + + public function authenticate(PendingRequest $pendingRequest): void + { + $pendingRequest->headers()->add('Authorization', "Bearer {$this->token}"); + } +} diff --git a/src/Http/EmptyResponse.php b/src/Http/EmptyResponse.php deleted file mode 100644 index ef40374e3..000000000 --- a/src/Http/EmptyResponse.php +++ /dev/null @@ -1,28 +0,0 @@ -client = $client; - } - - public function send(Request $request): mixed - { - $this->validate($request); - - $path = $request->resolveResourcePath() - .$this->buildQueryString($request->getQuery()); - - $body = $request instanceof HasBody - ? $request->getBody() - : null; - - $result = $this->client->performHttpCall( - $request->getMethod(), - $path, - $body - ); - - if ($result->isEmpty()) { - return null; - } - - return $this->build($request, $result); - } -} diff --git a/src/Http/EndpointCollection/BalanceEndpointCollection.php b/src/Http/EndpointCollection/BalanceEndpointCollection.php deleted file mode 100644 index 3bca16c6f..000000000 --- a/src/Http/EndpointCollection/BalanceEndpointCollection.php +++ /dev/null @@ -1,42 +0,0 @@ -send(new GetPaginatedBalancesRequest( - filters: $parameters, - from: $from, - limit: $limit - )); - } - - /** - * Retrieve a single balance from Mollie. - * - * Will throw an ApiException if the balance id is invalid or the resource cannot be found. - * - * @param string $balanceId - * @param array $parameters - * @return Balance - * @throws ApiException - */ - public function get(string $balanceId, array $parameters = []): Balance - { - $this->guardAgainstInvalidId($balanceId); - - /** @var Balance */ - return $this->readResource($balanceId, $parameters); - } -} diff --git a/src/Http/EndpointCollection/PaymentEndpointCollection.php b/src/Http/EndpointCollection/PaymentEndpointCollection.php deleted file mode 100644 index 4e365a34f..000000000 --- a/src/Http/EndpointCollection/PaymentEndpointCollection.php +++ /dev/null @@ -1,116 +0,0 @@ -send(new CreatePaymentRequest($data, $filters)); - } - - /** - * Update the given Payment. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * - * @param string $paymentId - * - * @throws ApiException - */ - public function update($paymentId, array $data = []): ?Payment - { - /** @var null|Payment */ - return $this - ->validateWith(new InvalidIdRule(id: $paymentId, prefix: Payment::$resourceIdPrefix)) - ->send(new UpdatePaymentRequest($paymentId, $data)); - } - - /** - * Get the balance endpoint. - */ - public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection - { - return $this->send(new GetPaginatedPaymentsRequest( - filters: $filters, - from: $from, - limit: $limit - )); - } - - /** - * Retrieve a single payment from Mollie. - * - * Will throw a ApiException if the payment id is invalid or the resource cannot be found. - * - * - * @throws ApiException - */ - public function get(string $paymentId, array $filters = []): Payment - { - return $this - ->validateWith(new InvalidIdRule(id: $paymentId, prefix: Payment::$resourceIdPrefix)) - ->send(new GetPaymentRequest($paymentId, $filters)); - } - - /** - * Issue a refund for the given payment. - * - * The $data parameter may either be an array of endpoint parameters, a float value to - * initiate a partial refund, or empty to do a full refund. - * - * @param array|float|null $data - * - * @throws ApiException - */ - public function refund(Payment $payment, $data = []): Refund - { - return $this->send(new CreateRefundPaymentRequest($payment->id, $data)); - } - - /** - * Create an iterator for iterating over payments retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->send( - (new GetPaginatedPaymentsRequest(filters: $filters, from: $from, limit: $limit)) - ->useIterator() - ->setIterationDirection($iterateBackwards) - ); - } - - /** - * @todo: Implement the rules method. Standardize request ids! - */ - protected function rules(Request $request): array - { - return [ - new InvalidIdRule(id: $request->getId(), prefix: Payment::$resourceIdPrefix), - ]; - } -} diff --git a/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php b/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php deleted file mode 100644 index d24fb6e2d..000000000 --- a/src/Http/EndpointCollection/PaymentRefundEndpointCollection.php +++ /dev/null @@ -1,24 +0,0 @@ -send(new GetPaginatedPaymentRefundsRequest( - $paymentId, - $filters - )); - } -} diff --git a/src/Http/HandlesQueries.php b/src/Http/HandlesQueries.php deleted file mode 100644 index 4be333906..000000000 --- a/src/Http/HandlesQueries.php +++ /dev/null @@ -1,28 +0,0 @@ - $value) { - if ($value === true) { - $filters[$key] = 'true'; - } - - if ($value === false) { - $filters[$key] = 'false'; - } - } - - return '?'.http_build_query($filters, '', '&'); - } -} diff --git a/src/Http/HandlesValidation.php b/src/Http/HandlesValidation.php deleted file mode 100644 index cf834f330..000000000 --- a/src/Http/HandlesValidation.php +++ /dev/null @@ -1,39 +0,0 @@ -rules = $rules; - - return $this; - } - - protected function validate(Request $request): void - { - /** @var Rule $rule */ - foreach ($this->rules as $rule) { - $rule->validate($request); - } - } - - protected function rules(): array - { - return []; - } - - private function getRules(): array - { - return array_merge($this->rules(), $this->rules); - } -} diff --git a/src/Http/HasHttpPhrases.php b/src/Http/HasHttpPhrases.php deleted file mode 100644 index 7b12f2f90..000000000 --- a/src/Http/HasHttpPhrases.php +++ /dev/null @@ -1,72 +0,0 @@ - 'Continue', - 101 => 'Switching Protocols', - 102 => 'Processing', - 103 => 'Early Hints', - 200 => 'OK', - 201 => 'Created', - 202 => 'Accepted', - 203 => 'Non-Authoritative Information', - 204 => 'No Content', - 205 => 'Reset Content', - 206 => 'Partial Content', - 207 => 'Multi-Status', - 208 => 'Already Reported', - 226 => 'IM Used', - 300 => 'Multiple Choices', - 301 => 'Moved Permanently', - 302 => 'Found', - 303 => 'See Other', - 304 => 'Not Modified', - 305 => 'Use Proxy', - 306 => 'Switch Proxy', - 307 => 'Temporary Redirect', - 308 => 'Permanent Redirect', - 400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Payload Too Large', - 414 => 'URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Range Not Satisfiable', - 417 => 'Expectation Failed', - 418 => "I'm a teapot", - 421 => 'Misdirected Request', - 422 => 'Unprocessable Entity', - 423 => 'Locked', - 424 => 'Failed Dependency', - 425 => 'Too Early', - 426 => 'Upgrade Required', - 428 => 'Precondition Required', - 429 => 'Too Many Requests', - 431 => 'Request Header Fields Too Large', - 451 => 'Unavailable For Legal Reasons', - 500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported', - 506 => 'Variant Also Negotiates', - 507 => 'Insufficient Storage', - 508 => 'Loop Detected', - 510 => 'Not Extended', - 511 => 'Network Authentication Required', - ]; -} diff --git a/src/Http/Middleware/ApplyIdempotencyKey.php b/src/Http/Middleware/ApplyIdempotencyKey.php new file mode 100644 index 000000000..a11db03d9 --- /dev/null +++ b/src/Http/Middleware/ApplyIdempotencyKey.php @@ -0,0 +1,39 @@ +isMutatingRequest($pendingRequest)) { + $pendingRequest->headers()->remove(self::IDEMPOTENCY_KEY_HEADER); + + return $pendingRequest; + } + + $idempotencyKey = $pendingRequest->getConnector()->getIdempotencyKey(); + $idempotencyKeyGenerator = $pendingRequest->getConnector()->getIdempotencyKeyGenerator(); + + if ($idempotencyKey === null && $idempotencyKeyGenerator === null) { + return $pendingRequest; + } + + $pendingRequest->headers()->add( + self::IDEMPOTENCY_KEY_HEADER, + $idempotencyKey ?? $idempotencyKeyGenerator->generate() + ); + + return $pendingRequest; + } + + private function isMutatingRequest(PendingRequest $pendingRequest): bool + { + return in_array($pendingRequest->method(), [Method::POST, Method::PATCH, Method::DELETE]); + } +} diff --git a/src/Http/Middleware/GuardResponse.php b/src/Http/Middleware/GuardResponse.php new file mode 100644 index 000000000..b942996fe --- /dev/null +++ b/src/Http/Middleware/GuardResponse.php @@ -0,0 +1,32 @@ +body()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { + throw new ApiException('No response body found.'); + } + + if (empty($response->body())) { + return; + } + + $response->json(); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new ApiException("Unable to decode Mollie response: '{$response->body()}'."); + } + + // @todo check if this is still necessary as it seems to be from api v1 + if (isset($response->json()->error)) { + throw new ApiException($response->json()->error->message); + } + } +} diff --git a/src/Http/Middleware/ResetIdempotencyKey.php b/src/Http/Middleware/ResetIdempotencyKey.php new file mode 100644 index 000000000..b72cb56ff --- /dev/null +++ b/src/Http/Middleware/ResetIdempotencyKey.php @@ -0,0 +1,13 @@ +getConnector()->resetIdempotencyKey(); + } +} diff --git a/src/Http/Middleware/ThrowExceptionIfRequestFailed.php b/src/Http/Middleware/ThrowExceptionIfRequestFailed.php new file mode 100644 index 000000000..669f96c17 --- /dev/null +++ b/src/Http/Middleware/ThrowExceptionIfRequestFailed.php @@ -0,0 +1,48 @@ +successful()) { + return; + } + + $body = $response->json(); + + $message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}"; + + $field = null; + + if (! empty($body->field)) { + $field = $body->field; + } + + if (isset($body->_links, $body->_links->documentation)) { + $message .= ". Documentation: {$body->_links->documentation->href}"; + } + + if ($response->getPendingRequest()->body()) { + $streamFactory = $response + ->getPendingRequest() + ->getFactoryCollection() + ->streamFactory; + + $message .= ". Request body: {$response->getPendingRequest()->body()->toStream($streamFactory)->getContents()}"; + } + + throw new ApiException( + $message, + $response->status(), + $field, + $response->getPsrRequest(), + $response->getPsrResponse(), + $response->getSenderException() + ); + } +} diff --git a/src/Http/Payload/Address.php b/src/Http/Payload/Address.php new file mode 100644 index 000000000..0efd5fb17 --- /dev/null +++ b/src/Http/Payload/Address.php @@ -0,0 +1,81 @@ +title = $title; + $this->givenName = $givenName; + $this->familyName = $familyName; + $this->organizationName = $organizationName; + $this->streetAndNumber = $streetAndNumber; + $this->streetAdditional = $streetAdditional; + $this->postalCode = $postalCode; + $this->email = $email; + $this->phone = $phone; + $this->city = $city; + $this->region = $region; + $this->country = $country; + } + + public function data(): mixed + { + return array_filter([ + 'title' => $this->title, + 'givenName' => $this->givenName, + 'familyName' => $this->familyName, + 'organizationName' => $this->organizationName, + 'streetAndNumber' => $this->streetAndNumber, + 'streetAdditional' => $this->streetAdditional, + 'postalCode' => $this->postalCode, + 'email' => $this->email, + 'phone' => $this->phone, + 'city' => $this->city, + 'region' => $this->region, + 'country' => $this->country, + ]); + } +} diff --git a/src/Http/Payload/ApplicationFee.php b/src/Http/Payload/ApplicationFee.php new file mode 100644 index 000000000..870e42516 --- /dev/null +++ b/src/Http/Payload/ApplicationFee.php @@ -0,0 +1,26 @@ +amount = $amount; + $this->description = $description; + } + + public function data(): array + { + return [ + 'amount' => $this->amount, + 'description' => $this->description, + ]; + } +} diff --git a/src/Http/Payload/CreateClientLink.php b/src/Http/Payload/CreateClientLink.php new file mode 100644 index 000000000..2c84005c4 --- /dev/null +++ b/src/Http/Payload/CreateClientLink.php @@ -0,0 +1,41 @@ +owner = $owner; + $this->name = $name; + $this->address = $address; + $this->registrationNumber = $registrationNumber; + $this->vatNumber = $vatNumber; + } + + public function data(): array + { + return [ + 'owner' => $this->owner, + 'name' => $this->name, + 'address' => $this->address, + 'registrationNumber' => $this->registrationNumber, + 'vatNumber' => $this->vatNumber, + ]; + } +} diff --git a/src/Http/Payload/CreatePayment.php b/src/Http/Payload/CreatePayment.php new file mode 100644 index 000000000..29cc363e4 --- /dev/null +++ b/src/Http/Payload/CreatePayment.php @@ -0,0 +1,140 @@ +|null + */ + public ?DataCollection $lines; + + public ?Address $billingAddress; + + public ?Address $shippingAddress; + + public ?string $locale; + + public ?string $method; + + public ?string $issuer; + + public ?string $restrictPaymentMethodsToCountry; + + public ?Metadata $metadata; + + public ?string $captureMode; + + public ?string $captureDelay; + + public ?ApplicationFee $applicationFee; + + /** + * @var DataCollection|null + */ + public ?DataCollection $routing; + + public ?string $sequenceType; + + public ?string $mandateId; + + public ?string $customerId; + + public ?string $profileId; + + public ?bool $testmode; + + /** + * Method specific data. + * + * s. https://docs.mollie.com/reference/extra-payment-parameters#payment-creation-request-parameters + */ + public array $additional = []; + + public function __construct( + string $description, + Money $amount, + ?string $redirectUrl = null, + ?string $cancelUrl = null, + ?string $webhookUrl = null, + ?DataCollection $lines = null, + ?Address $billingAddress = null, + ?Address $shippingAddress = null, + ?string $locale = null, + ?string $method = null, + ?string $issuer = null, + ?string $restrictPaymentMethodsToCountry = null, + ?Metadata $metadata = null, + ?string $captureMode = null, + ?string $captureDelay = null, + ?ApplicationFee $applicationFee = null, + ?DataCollection $routing = null, + ?string $sequenceType = null, + ?string $mandateId = null, + ?string $customerId = null, + ?string $profileId = null, + ?bool $testmode = null, + array $additional = [], + ) { + $this->description = $description; + $this->amount = $amount; + $this->redirectUrl = $redirectUrl; + $this->cancelUrl = $cancelUrl; + $this->webhookUrl = $webhookUrl; + $this->lines = $lines; + $this->billingAddress = $billingAddress; + $this->shippingAddress = $shippingAddress; + $this->locale = $locale; + $this->method = $method; + $this->issuer = $issuer; + $this->restrictPaymentMethodsToCountry = $restrictPaymentMethodsToCountry; + $this->metadata = $metadata; + $this->captureMode = $captureMode; + $this->captureDelay = $captureDelay; + $this->applicationFee = $applicationFee; + $this->routing = $routing; + $this->sequenceType = $sequenceType; + $this->mandateId = $mandateId; + $this->customerId = $customerId; + $this->profileId = $profileId; + $this->additional = $additional; + $this->testmode = $testmode; + } + + public function data(): mixed + { + return array_merge([ + 'description' => $this->description, + 'amount' => $this->amount, + 'redirectUrl' => $this->redirectUrl, + 'cancelUrl' => $this->cancelUrl, + 'webhookUrl' => $this->webhookUrl, + 'lines' => $this->lines, + 'billingAddress' => $this->billingAddress, + 'shippingAddress' => $this->shippingAddress, + 'locale' => $this->locale, + 'method' => $this->method, + 'issuer' => $this->issuer, + 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, + 'metadata' => $this->metadata, + 'captureMode' => $this->captureMode, + 'captureDelay' => $this->captureDelay, + 'applicationFee' => $this->applicationFee, + 'routing' => $this->routing, + 'sequenceType' => $this->sequenceType, + 'mandateId' => $this->mandateId, + 'customerId' => $this->customerId, + 'profileId' => $this->profileId, + ], $this->additional); + } +} diff --git a/src/Http/Payload/CreateRefundPayment.php b/src/Http/Payload/CreateRefundPayment.php new file mode 100644 index 000000000..108a51f48 --- /dev/null +++ b/src/Http/Payload/CreateRefundPayment.php @@ -0,0 +1,53 @@ + + */ + public ?DataCollection $routingReversals = null; + + public ?bool $testmode = null; + + public function __construct( + string $description, + Money $amount, + ?Metadata $metadata = null, + ?bool $reverseRouting = null, + ?DataCollection $routingReversals = null, + ?bool $testmode = null + ) { + $this->description = $description; + $this->amount = $amount; + $this->metadata = $metadata; + $this->reverseRouting = $reverseRouting; + $this->routingReversals = $routingReversals; + $this->testmode = $testmode; + } + + public function data(): mixed + { + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'metadata' => $this->metadata, + 'reverseRouting' => $this->reverseRouting, + 'routingReversals' => $this->routingReversals, + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Payload/DataBag.php b/src/Http/Payload/DataBag.php new file mode 100644 index 000000000..6e75bcf98 --- /dev/null +++ b/src/Http/Payload/DataBag.php @@ -0,0 +1,21 @@ +resolve(); + } +} diff --git a/src/Http/Payload/DataCollection.php b/src/Http/Payload/DataCollection.php new file mode 100644 index 000000000..a2155e886 --- /dev/null +++ b/src/Http/Payload/DataCollection.php @@ -0,0 +1,66 @@ + + */ + public array $items; + + /** + * @param array $items + */ + public function __construct(array $items) + { + $this->items = $items; + } + + public static function wrap(object $subject): static + { + if ($subject instanceof static) { + return $subject; + } + + if ($subject instanceof DataProvider) { + return new static($subject->data()); + } + + if ($subject instanceof Arrayable) { + return new static($subject->toArray()); + } + + return new static((array) $subject); + } + + public function data(): mixed + { + return $this->toArray(); + } + + public function toArray(): array + { + return $this->items; + } + + public function map(callable $callback): static + { + return new static(array_map($callback, $this->items)); + } + + public function filter(): static + { + return new static(array_filter($this->items)); + } +} diff --git a/src/Http/Payload/Metadata.php b/src/Http/Payload/Metadata.php new file mode 100644 index 000000000..2fdd7b49d --- /dev/null +++ b/src/Http/Payload/Metadata.php @@ -0,0 +1,20 @@ +metadata = $metadata; + } + + public function data(): string + { + return @json_encode($this->metadata); + } +} diff --git a/src/Http/Payload/Money.php b/src/Http/Payload/Money.php new file mode 100644 index 000000000..45214ba38 --- /dev/null +++ b/src/Http/Payload/Money.php @@ -0,0 +1,28 @@ +currency = $currency; + $this->value = $value; + } + + public function data(): array + { + return [ + 'currency' => $this->currency, + 'value' => $this->value, + ]; + } +} diff --git a/src/Http/Payload/OrderLine.php b/src/Http/Payload/OrderLine.php new file mode 100644 index 000000000..967d2856f --- /dev/null +++ b/src/Http/Payload/OrderLine.php @@ -0,0 +1,95 @@ +description = $description; + $this->quantity = $quantity; + $this->unitPrice = $unitPrice; + $this->totalAmount = $totalAmount; + $this->type = $type; + $this->quantityUnit = $quantityUnit; + $this->discountAmount = $discountAmount; + $this->recurring = $recurring; + $this->vatRate = $vatRate; + $this->vatAmount = $vatAmount; + $this->sku = $sku; + $this->imageUrl = $imageUrl; + $this->productUrl = $productUrl; + } + + public function data(): mixed + { + return [ + 'description' => $this->description, + 'quantity' => $this->quantity, + 'unitPrice' => $this->unitPrice, + 'totalAmount' => $this->totalAmount, + 'type' => $this->type, + 'quantityUnit' => $this->quantityUnit, + 'discountAmount' => $this->discountAmount, + 'recurring' => $this->recurring, + 'vatRate' => $this->vatRate, + 'vatAmount' => $this->vatAmount, + 'sku' => $this->sku, + 'imageUrl' => $this->imageUrl, + 'productUrl' => $this->productUrl, + ]; + } + + public function rules(): array + { + return [ + 'type' => Included::in(OrderLineType::class), + 'quantity' => Min::value(1), + 'sku' => Max::value(64), + ]; + } +} diff --git a/src/Http/Payload/Owner.php b/src/Http/Payload/Owner.php new file mode 100644 index 000000000..be4287710 --- /dev/null +++ b/src/Http/Payload/Owner.php @@ -0,0 +1,41 @@ +email = $email; + $this->givenName = $givenName; + $this->familyName = $familyName; + $this->locale = $locale; + } + + public function data(): array + { + return [ + 'email' => $this->email, + 'givenName' => $this->givenName, + 'familyName' => $this->familyName, + 'locale' => $this->locale, + ]; + } +} diff --git a/src/Http/Payload/OwnerAddress.php b/src/Http/Payload/OwnerAddress.php new file mode 100644 index 000000000..f80c8027c --- /dev/null +++ b/src/Http/Payload/OwnerAddress.php @@ -0,0 +1,46 @@ +country = $country; + $this->streetAndNumber = $streetAndNumber; + $this->postalCode = $postalCode; + $this->city = $city; + $this->region = $region; + } + + public function data(): array + { + return [ + 'streetAndNumber' => $this->streetAndNumber, + 'postalCode' => $this->postalCode, + 'city' => $this->city, + 'region' => $this->region, + 'country' => $this->country, + ]; + } +} diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php new file mode 100644 index 000000000..f11dd678e --- /dev/null +++ b/src/Http/Payload/PaymentRoute.php @@ -0,0 +1,26 @@ + $this->amount, + 'destination' => [ + 'type' => 'organization', + 'organizationId' => $this->organizationId, + ], + 'delayUntil' => $this->delayUntil?->format('Y-m-d'), + ]; + } +} diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php new file mode 100644 index 000000000..f69be4b51 --- /dev/null +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -0,0 +1,56 @@ +interval = $interval; + $this->description = $description; + $this->amount = $amount; + $this->times = $times; + $this->startDate = $startDate; + } + + public function data(): mixed + { + return [ + 'interval' => $this->interval, + 'description' => $this->description, + 'amount' => $this->amount, + 'times' => $this->times, + 'startDate' => $this->startDate->format('Y-m-d'), + ]; + } + + public function rules(): array + { + return [ + 'interval' => Matches::pattern('/^\d+ (months|weeks|days)$/'), + ]; + } +} diff --git a/src/Http/Payload/RefundRoute.php b/src/Http/Payload/RefundRoute.php new file mode 100644 index 000000000..50f396ecd --- /dev/null +++ b/src/Http/Payload/RefundRoute.php @@ -0,0 +1,29 @@ +amount = $amount; + $this->organizationId = $organizationId; + } + + public function data(): mixed + { + return [ + 'amount' => $this->amount, + 'source' => [ + 'type' => 'organization', + 'organizationId' => $this->organizationId, + ], + ]; + } +} diff --git a/src/Http/Payload/UpdatePayment.php b/src/Http/Payload/UpdatePayment.php new file mode 100644 index 000000000..0df9d6b70 --- /dev/null +++ b/src/Http/Payload/UpdatePayment.php @@ -0,0 +1,70 @@ +description = $description; + $this->redirectUrl = $redirectUrl; + $this->cancelUrl = $cancelUrl; + $this->webhookUrl = $webhookUrl; + $this->metadata = $metadata; + $this->method = $method; + $this->locale = $locale; + $this->restrictPaymentMethodsToCountry = $restrictPaymentMethodsToCountry; + $this->additional = $additional; + $this->testmode = $testmode; + } + + public function data(): array + { + return array_merge([ + 'description' => $this->description, + 'redirectUrl' => $this->redirectUrl, + 'cancelUrl' => $this->cancelUrl, + 'webhookUrl' => $this->webhookUrl, + 'metadata' => $this->metadata, + 'method' => $this->method, + 'locale' => $this->locale, + 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, + 'testmode' => $this->testmode, + ], $this->additional); + } +} diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php new file mode 100644 index 000000000..841905303 --- /dev/null +++ b/src/Http/PendingRequest.php @@ -0,0 +1,113 @@ +factoryCollection = $connector->getHttpClient()->factories(); + + $this->connector = $connector; + $this->request = $request; + + $this->method = $request->getMethod(); + $this->url = Url::join($connector->resolveBaseUrl(), $request->resolveResourcePath()); + + $this + ->tap(new MergeRequestProperties) + ->tap(new ValidateProperties) + ->tap(new SetBody) + ->tap(new SetUserAgent) + ->tap(new AuthenticateRequest); + + $this + ->middleware() + ->onRequest(new ApplyIdempotencyKey) + ->onResponse(new ResetIdempotencyKey) + ->onResponse(new GuardResponse) + ->onResponse(new ThrowExceptionIfRequestFailed); + } + + public function setPayload(BodyRepository $bodyRepository): static + { + $this->body = $bodyRepository; + + return $this; + } + + public function body(): ?BodyRepository + { + return $this->body; + } + + public function url(): string + { + return $this->url; + } + + public function method(): string + { + return $this->method; + } + + public function getConnector(): Connector + { + return $this->connector; + } + + public function getRequest(): Request + { + return $this->request; + } + + public function executeRequestHandlers(): self + { + return $this->middleware()->executeOnRequest($this); + } + + public function executeResponseHandlers(Response $response): Response + { + return $this->middleware()->executeOnResponse($response); + } + + protected function tap(callable $callable): static + { + $callable($this); + + return $this; + } +} diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php new file mode 100644 index 000000000..9679e2b32 --- /dev/null +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -0,0 +1,31 @@ +getConnector()->getAuthenticator(); + + if (! $authenticator) { + throw new ApiException('You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.'); + } + + /** + * Remove testmode parameter from the request if authenticated via ApiKey. + */ + if ($authenticator instanceof ApiKeyAuthenticator) { + $pendingRequest->query()->remove('testmode'); + $pendingRequest->body()?->remove('testmode'); + } + + $authenticator->authenticate($pendingRequest); + + return $pendingRequest; + } +} diff --git a/src/Http/PendingRequest/MergeRequestProperties.php b/src/Http/PendingRequest/MergeRequestProperties.php new file mode 100644 index 000000000..81c681ecc --- /dev/null +++ b/src/Http/PendingRequest/MergeRequestProperties.php @@ -0,0 +1,26 @@ +getConnector(); + $request = $pendingRequest->getRequest(); + + $pendingRequest->headers()->merge( + $client->headers()->all(), + $request->headers()->all() + ); + + $pendingRequest->query()->merge( + $client->query()->all(), + $request->query()->all() + ); + + return $pendingRequest; + } +} diff --git a/src/Http/PendingRequest/SetBody.php b/src/Http/PendingRequest/SetBody.php new file mode 100644 index 000000000..3c71bc7b8 --- /dev/null +++ b/src/Http/PendingRequest/SetBody.php @@ -0,0 +1,28 @@ +getRequest(); + + if (! $request instanceof HasPayload) { + return $pendingRequest; + } + + $body = $request->payload(); + + $pendingRequest->setPayload($body); + + if (! $pendingRequest->headers()->get('Content-Type')) { + $pendingRequest->headers()->add('Content-Type', 'application/json'); + } + + return $pendingRequest; + } +} diff --git a/src/Http/PendingRequest/SetUserAgent.php b/src/Http/PendingRequest/SetUserAgent.php new file mode 100644 index 000000000..678b7c091 --- /dev/null +++ b/src/Http/PendingRequest/SetUserAgent.php @@ -0,0 +1,25 @@ +getConnector()->getVersionStrings(), ' '); + + $authenticator = $pendingRequest->getConnector()->getAuthenticator(); + + if ($authenticator instanceof AccessTokenAuthenticator) { + $userAgent .= ' Auth/Token'; + } + + $pendingRequest->headers()->add('User-Agent', $userAgent); + + return $pendingRequest; + } +} diff --git a/src/Http/PendingRequest/ValidateProperties.php b/src/Http/PendingRequest/ValidateProperties.php new file mode 100644 index 000000000..04010e9a3 --- /dev/null +++ b/src/Http/PendingRequest/ValidateProperties.php @@ -0,0 +1,21 @@ +getRequest(); + + Validator::make()->validate( + $request, + $pendingRequest->query()->all() + ); + + return $pendingRequest; + } +} diff --git a/src/Http/PsrResponseHandler.php b/src/Http/PsrResponseHandler.php deleted file mode 100644 index d71e32deb..000000000 --- a/src/Http/PsrResponseHandler.php +++ /dev/null @@ -1,72 +0,0 @@ -responseHandler = $responseHandler; - } - - public static function create(): self - { - return new self(new ResponseHandler()); - } - - /** - * Undocumented function - * - * @param RequestInterface|null $psrResponse - * @param ResponseInterface|null $psrResponse - * @param int $code - * @param string|null $requestBody - * @return ResponseContract - */ - public function handle( - ?RequestInterface $prsRequest = null, - ?ResponseInterface $psrResponse = null, - int $code = 200, - ?string $requestBody = null - ): ResponseContract { - if ($psrResponse === null) { - return ResponseHandler::noResponse(); - } - - if (! $psrResponse instanceof ResponseInterface) { - throw new RuntimeException("Response must be an instance of ResponseInterface."); - } - - $body = (string) $psrResponse->getBody(); - - $response = new Response( - $code, - $body - ); - - $this->responseHandler->guard($response); - - try { - $this->responseHandler->throwExceptionIfRequestFailed($response, $requestBody); - } catch (ApiException $e) { - throw new ApiException( - $e->getMessage(), - $e->getCode(), - $e->getField(), - $prsRequest, - $psrResponse, - $e->getPrevious() - ); - } - - return $response; - } -} diff --git a/src/Http/Query/CreatePaymentQuery.php b/src/Http/Query/CreatePaymentQuery.php new file mode 100644 index 000000000..cd0835a73 --- /dev/null +++ b/src/Http/Query/CreatePaymentQuery.php @@ -0,0 +1,34 @@ +include = $include; + } + + public function toArray(): array + { + return [ + 'include' => $this->include, + ]; + } + + public function rules(): array + { + return [ + 'include' => Included::in([PaymentQuery::INCLUDE_QR_CODE]), + ]; + } +} diff --git a/src/Http/Query/GetBalanceReportQuery.php b/src/Http/Query/GetBalanceReportQuery.php new file mode 100644 index 000000000..9ac9cb07e --- /dev/null +++ b/src/Http/Query/GetBalanceReportQuery.php @@ -0,0 +1,38 @@ +from = $from; + $this->until = $until; + $this->grouping = $grouping; + $this->testmode = $testmode; + } + + public function toArray(): array + { + return [ + 'from' => $this->from->format('Y-m-d'), + 'until' => $this->until->format('Y-m-d'), + 'grouping' => $this->grouping, + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Query/GetPaginatedBalanceQuery.php b/src/Http/Query/GetPaginatedBalanceQuery.php new file mode 100644 index 000000000..14e5315d8 --- /dev/null +++ b/src/Http/Query/GetPaginatedBalanceQuery.php @@ -0,0 +1,29 @@ +currency = $currency; + } + + public function toArray(): array + { + return array_merge( + parent::toArray(), + [ + 'currency' => $this->currency, + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedChargebackQuery.php b/src/Http/Query/GetPaginatedChargebackQuery.php new file mode 100644 index 000000000..4e96ef5ee --- /dev/null +++ b/src/Http/Query/GetPaginatedChargebackQuery.php @@ -0,0 +1,34 @@ +includePayment = $includePayment; + $this->profileId = $profileId; + } + + public function toArray(): array + { + return array_merge( + parent::toArray(), + [ + 'include' => $this->includePayment ? 'payment' : null, + 'profileId' => $this->profileId, + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php new file mode 100644 index 000000000..4d24f7404 --- /dev/null +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -0,0 +1,39 @@ +embed = $embed; + } + + public function toArray(): array + { + return array_merge( + parent::toArray(), + [ + 'embed' => Arr::join($this->embed), + ] + ); + } + + public function rules(): array + { + return [ + 'embed' => Included::in(ClientQuery::class), + ]; + } +} diff --git a/src/Http/Query/GetPaginatedPaymentRefundQuery.php b/src/Http/Query/GetPaginatedPaymentRefundQuery.php new file mode 100644 index 000000000..a3d3cd74e --- /dev/null +++ b/src/Http/Query/GetPaginatedPaymentRefundQuery.php @@ -0,0 +1,29 @@ +includePayment = $includePayment; + } + + public function toArray(): array + { + return array_merge( + parent::toArray(), + [ + 'include' => $this->includePayment ? 'payment' : null, + ] + ); + } +} diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php new file mode 100644 index 000000000..47926356a --- /dev/null +++ b/src/Http/Query/GetPaymentQuery.php @@ -0,0 +1,43 @@ +embed = $embed; + $this->include = $include; + $this->testmode = $testmode; + } + + public function toArray(): array + { + return [ + 'embed' => Arr::join($this->embed), + 'include' => Arr::join($this->include), + 'testmode' => $this->testmode, + ]; + } + + public function rules(): array + { + return [ + 'embed' => Included::in(PaymentQuery::EMBEDS), + 'include' => Included::in(PaymentQuery::INCLUDES), + ]; + } +} diff --git a/src/Http/Query/PaginatedQuery.php b/src/Http/Query/PaginatedQuery.php new file mode 100644 index 000000000..3efc932e6 --- /dev/null +++ b/src/Http/Query/PaginatedQuery.php @@ -0,0 +1,31 @@ +from = $from; + $this->limit = $limit; + $this->testmode = $testmode; + } + + public function toArray(): array + { + return [ + 'from' => $this->from, + 'limit' => $this->limit, + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Query/Query.php b/src/Http/Query/Query.php new file mode 100644 index 000000000..420dbaea2 --- /dev/null +++ b/src/Http/Query/Query.php @@ -0,0 +1,12 @@ +sort = $sort; + } + + public function toArray(): array + { + return array_merge( + parent::toArray(), + [ + 'sort' => $this->sort, + ] + ); + } + + public function rules(): array + { + return [ + 'sort' => Included::in(['asc', 'desc']), + ]; + } +} diff --git a/src/Http/Requests/Request.php b/src/Http/Request.php similarity index 64% rename from src/Http/Requests/Request.php rename to src/Http/Request.php index 710efe3cc..cc4ef43c9 100644 --- a/src/Http/Requests/Request.php +++ b/src/Http/Request.php @@ -1,20 +1,24 @@ method)) { + if (! isset(static::$method)) { throw new LogicException('Your request is missing a HTTP method. You must add a method property like [protected Method $method = Method::GET]'); } - return $this->method; - } - - public function getQuery(): array - { - return []; + return static::$method; } - public static function getTargetResourceClass(): string + public function getTargetResourceClass(): string { if (empty(static::$targetResourceClass)) { throw new \RuntimeException('Resource class is not set.'); @@ -46,8 +45,6 @@ public static function getTargetResourceClass(): string /** * Resolve the resource path. - * - * @return string */ abstract public function resolveResourcePath(): string; } diff --git a/src/Http/Requests/CancelPaymentRequest.php b/src/Http/Requests/CancelPaymentRequest.php new file mode 100644 index 000000000..e402ddf21 --- /dev/null +++ b/src/Http/Requests/CancelPaymentRequest.php @@ -0,0 +1,50 @@ +id = $id; + $this->testmode = $testmode; + } + + protected function defaultQuery(): array + { + return [ + 'testmode' => $this->testmode, + ]; + } + + public function rules(): array + { + return [ + 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), + ]; + } + + public function resolveResourcePath(): string + { + return "payments/{$this->id}"; + } +} diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php new file mode 100644 index 000000000..a0a8e39f2 --- /dev/null +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -0,0 +1,39 @@ +payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->data(); + } + + public function resolveResourcePath(): string + { + + return 'client-links'; + } +} diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index 7696fc71f..baa563afe 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -2,24 +2,46 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Http\Payload\CreatePayment; +use Mollie\Api\Http\Query\CreatePaymentQuery; +use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; +use Mollie\Api\Traits\HasJsonPayload; +use Mollie\Api\Types\Method; -class CreatePaymentRequest extends JsonPostRequest +class CreatePaymentRequest extends Request implements HasPayload { + use HasJsonPayload; + /** - * The resource class the request should be casted to. + * Define the HTTP method. */ - public static string $targetResourceClass = Payment::class; + protected static string $method = Method::POST; /** - * The request filters. + * The resource class the request should be casted to. */ - protected array $include; + public static string $targetResourceClass = Payment::class; + + private CreatePayment $payload; + + private ?CreatePaymentQuery $query = null; + + public function __construct(CreatePayment $payload, ?CreatePaymentQuery $query = null) + { + $this->payload = $payload; + $this->query = $query; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } - public function __construct(array $body, array $include = []) + protected function defaultQuery(): array { - $this->body = $body; - $this->include = $include; + return $this->query?->toArray() ?? []; } /** diff --git a/src/Http/Requests/CreateRefundPaymentRequest.php b/src/Http/Requests/CreateRefundPaymentRequest.php index d81d587ac..f9336225d 100644 --- a/src/Http/Requests/CreateRefundPaymentRequest.php +++ b/src/Http/Requests/CreateRefundPaymentRequest.php @@ -2,28 +2,55 @@ namespace Mollie\Api\Http\Requests; -class CreateRefundPaymentRequest extends JsonPostRequest +use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Contracts\SupportsTestmode; +use Mollie\Api\Http\Payload\CreateRefundPayment; +use Mollie\Api\Http\Request; +use Mollie\Api\Resources\Payment; +use Mollie\Api\Rules\Id; +use Mollie\Api\Traits\HasJsonPayload; +use Mollie\Api\Types\Method; + +class CreateRefundPaymentRequest extends Request implements HasPayload, SupportsTestmode { + use HasJsonPayload; + + /** + * Define the HTTP method. + */ + protected static string $method = Method::POST; + /** * The resource class the request should be casted to. */ public static string $targetResourceClass = \Mollie\Api\Resources\Refund::class; - public string $paymentId; + private string $paymentId; + + private CreateRefundPayment $payload; public function __construct( - string $paymentId, - array $data + string $identifier, + CreateRefundPayment $payload ) { - parent::__construct(data: $data); + $this->paymentId = $identifier; + $this->payload = $payload; + } - $this->paymentId = $paymentId; + protected function defaultPayload(): array + { + return $this->payload->toArray(); } - public function resolveResourcePath(): string + public function rules(): array { - $id = urlencode($this->paymentId); + return [ + 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), + ]; + } - return "payments/{$id}/refunds"; + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/refunds"; } } diff --git a/src/Http/Requests/DynamicDeleteRequest.php b/src/Http/Requests/DynamicDeleteRequest.php new file mode 100644 index 000000000..a448445e0 --- /dev/null +++ b/src/Http/Requests/DynamicDeleteRequest.php @@ -0,0 +1,32 @@ +testmode = $testmode; + } + + protected function defaultQuery(): array + { + return [ + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Requests/DynamicGetRequest.php b/src/Http/Requests/DynamicGetRequest.php new file mode 100644 index 000000000..7fc24b426 --- /dev/null +++ b/src/Http/Requests/DynamicGetRequest.php @@ -0,0 +1,13 @@ +url = $url; + $this->resourceClass = $resourceClass; + } + + public function getTargetResourceClass(): string + { + return $this->resourceClass; + } + + public function resolveResourcePath(): string + { + return $this->url; + } +} diff --git a/src/Http/Requests/GetBalanceReportRequest.php b/src/Http/Requests/GetBalanceReportRequest.php new file mode 100644 index 000000000..a955f5774 --- /dev/null +++ b/src/Http/Requests/GetBalanceReportRequest.php @@ -0,0 +1,44 @@ +balanceId = $balanceId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "balances/{$this->balanceId}/report"; + } +} diff --git a/src/Http/Requests/GetBalanceRequest.php b/src/Http/Requests/GetBalanceRequest.php new file mode 100644 index 000000000..9922b7716 --- /dev/null +++ b/src/Http/Requests/GetBalanceRequest.php @@ -0,0 +1,45 @@ +id = $id; + $this->testmode = $testmode; + } + + protected function defaultQuery(): array + { + return [ + 'testmode' => $this->testmode, + ]; + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "balances/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php new file mode 100644 index 000000000..ebd0a9f40 --- /dev/null +++ b/src/Http/Requests/GetClientRequest.php @@ -0,0 +1,52 @@ +id = $id; + $this->embed = $embed; + } + + protected function defaultQuery(): array + { + return [ + 'embed' => Arr::join($this->embed), + ]; + } + + public function rules(): array + { + return [ + 'embed' => Included::in(ClientQuery::class), + ]; + } + + public function resolveResourcePath(): string + { + return "clients/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetPaginatedBalancesRequest.php b/src/Http/Requests/GetPaginatedBalanceRequest.php similarity index 61% rename from src/Http/Requests/GetPaginatedBalancesRequest.php rename to src/Http/Requests/GetPaginatedBalanceRequest.php index 4f668b2ec..46a1e416f 100644 --- a/src/Http/Requests/GetPaginatedBalancesRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceRequest.php @@ -2,24 +2,24 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Resources\BalanceCollection; +use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedBalancesRequest extends PaginatedRequest +class GetPaginatedBalanceRequest extends PaginatedRequest implements IsIteratable { + use IsIteratableRequest; + /** * The resource class the request should be casted to. - * - * @var string */ public static string $targetResourceClass = BalanceCollection::class; /** * Resolve the resource path. - * - * @return string */ public function resolveResourcePath(): string { - return "balances"; + return 'balances'; } } diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php new file mode 100644 index 000000000..4b85f3345 --- /dev/null +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -0,0 +1,34 @@ +balanceId = $balanceId; + } + + public function resolveResourcePath(): string + { + return "balances/{$this->balanceId}/transactions"; + } +} diff --git a/src/Http/Requests/GetPaginatedChargebacksRequest.php b/src/Http/Requests/GetPaginatedChargebacksRequest.php new file mode 100644 index 000000000..78382661d --- /dev/null +++ b/src/Http/Requests/GetPaginatedChargebacksRequest.php @@ -0,0 +1,22 @@ +paymentId = $paymentId; } - public function resolveResourcePath(): string + public function rules(): array { - $id = urlencode($this->paymentId); + return [ + 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), + ]; + } - return "payments/{$id}/refunds"; + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/refunds"; } } diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php index edaa2d600..eacdceeb7 100644 --- a/src/Http/Requests/GetPaginatedPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -4,8 +4,9 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Resources\PaymentCollection; +use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedPaymentsRequest extends PaginatedRequest implements IsIteratable +class GetPaginatedPaymentsRequest extends SortablePaginatedRequest implements IsIteratable { use IsIteratableRequest; diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 5f89e053f..63cdd56ed 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -2,49 +2,53 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Requests\Request; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Query\GetPaymentQuery; +use Mollie\Api\Http\Request; +use Mollie\Api\Resources\Payment; +use Mollie\Api\Rules\Id; +use Mollie\Api\Types\Method; class GetPaymentRequest extends Request { /** * Define the HTTP method. */ - protected string $method = MollieApiClient::HTTP_GET; + protected static string $method = Method::GET; /** * The resource class the request should be casted to. - * - * @var string */ public static string $targetResourceClass = \Mollie\Api\Resources\Payment::class; - public string $paymentId; + private string $id; - public array $filters; + private GetPaymentQuery $query; public function __construct( - string $paymentId, - array $filters = [] + string $id, + GetPaymentQuery $query, ) { - $this->paymentId = $paymentId; - $this->filters = $filters; + $this->id = $id; + $this->query = $query; } - /** - * Resolve the resource path. - * - * @return string - */ - public function resolveResourcePath(): string + protected function defaultQuery(): array { - $id = urlencode($this->paymentId); + return $this->query->toArray(); + } - return "payments/{$id}"; + public function rules(): array + { + return [ + 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), + ]; } - public function getQuery(): array + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string { - return $this->filters; + return "payments/{$this->id}"; } } diff --git a/src/Http/Requests/HasJsonBody.php b/src/Http/Requests/HasJsonBody.php deleted file mode 100644 index 684abe73e..000000000 --- a/src/Http/Requests/HasJsonBody.php +++ /dev/null @@ -1,13 +0,0 @@ -body); - } -} diff --git a/src/Http/Requests/JsonPostRequest.php b/src/Http/Requests/JsonPostRequest.php deleted file mode 100644 index 3f9e630d3..000000000 --- a/src/Http/Requests/JsonPostRequest.php +++ /dev/null @@ -1,26 +0,0 @@ -body = $data; - } - - public function getBody(): string - { - return json_encode($this->body); - } -} diff --git a/src/Http/Requests/PaginatedRequest.php b/src/Http/Requests/PaginatedRequest.php index ab875d469..3f858eba2 100644 --- a/src/Http/Requests/PaginatedRequest.php +++ b/src/Http/Requests/PaginatedRequest.php @@ -2,36 +2,27 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Request; +use Mollie\Api\Types\Method; abstract class PaginatedRequest extends Request { /** * Define the HTTP method. */ - protected string $method = MollieApiClient::HTTP_GET; + protected static string $method = Method::GET; - public ?string $from = null; - - public ?int $limit = null; - - public array $filters = []; + private ?PaginatedQuery $query = null; public function __construct( - array $filters = [], - ?string $from = null, - ?int $limit = null, + ?PaginatedQuery $query = null ) { - $this->filters = $filters; - $this->from = $from; - $this->limit = $limit; + $this->query = $query; } - public function getQuery(): array + protected function defaultQuery(): array { - return array_merge([ - 'from' => $this->from, - 'limit' => $this->limit, - ], $this->filters); + return $this->query?->toArray() ?? []; } } diff --git a/src/Http/Requests/SortablePaginatedRequest.php b/src/Http/Requests/SortablePaginatedRequest.php new file mode 100644 index 000000000..a5a11e636 --- /dev/null +++ b/src/Http/Requests/SortablePaginatedRequest.php @@ -0,0 +1,14 @@ +paymentId = $paymentId; - $this->body = $body; + $this->id = $id; + $this->payload = $payload; } - public function resolveResourcePath(): string + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function rules(): array { - $id = urlencode($this->paymentId); + return [ + 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), + ]; + } - return "payments/{$id}"; + public function resolveResourcePath(): string + { + return "payments/{$this->id}"; } } diff --git a/src/Http/Response.php b/src/Http/Response.php index 338e368cf..e3c593553 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -2,84 +2,134 @@ namespace Mollie\Api\Http; -use Mollie\Api\Contracts\ResponseContract; +use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; +use stdClass; +use Throwable; -class Response implements ResponseContract +class Response { - use HasHttpPhrases; + protected ResponseInterface $psrResponse; - private int $statusCode; + protected RequestInterface $psrRequest; - private ?string $body = null; + protected PendingRequest $pendingRequest; - private string $reasonPhrase; + protected ?Throwable $senderException = null; /** * The decoded JSON response. - * - * @var \stdClass */ protected ?\stdClass $decoded = null; public function __construct( - int $statusCode = 200, - ?string $body = null, - string $reasonPhrase = '' + ResponseInterface $psrResponse, + RequestInterface $psrRequest, + PendingRequest $pendingRequest, + ?Throwable $senderException = null ) { - $this->statusCode = $statusCode; - $this->body = $body; - $this->reasonPhrase = $reasonPhrase; + $this->psrResponse = $psrResponse; + $this->psrRequest = $psrRequest; + $this->pendingRequest = $pendingRequest; + $this->senderException = $senderException; } /** - * Get the body of the response. - * - * @return string + * Get the JSON decoded body of the response as an array or scalar value. */ - public function body(): string + public function json(): stdClass + { + if (! $this->decoded) { + $this->decoded = @json_decode($body = $this->body() ?: '[]'); + + if (json_last_error() !== JSON_ERROR_NONE) { + throw new ApiException("Unable to decode Mollie response: '{$body}'."); + } + } + + return $this->decoded; + } + + public function getConnector(): Connector + { + return $this->pendingRequest->getConnector(); + } + + public function getPendingRequest(): PendingRequest + { + return $this->pendingRequest; + } + + public function getRequest(): Request + { + return $this->pendingRequest->getRequest(); + } + + public function getPsrRequest(): RequestInterface + { + return $this->psrRequest; + } + + public function getPsrResponse(): ResponseInterface { - return $this->body; + return $this->psrResponse; + } + + public function getSenderException(): ?Throwable + { + return $this->senderException; } /** - * Get the JSON decoded body of the response as an array or scalar value. - * - * @return \stdClass + * Get the body of the response as string. */ - public function decode(): \stdClass + public function body(): string { - if (empty($body = $this->body())) { - return (object)[]; + $stream = $this->stream(); + + $contents = $stream->getContents(); + + if ($stream->isSeekable()) { + $stream->rewind(); } - if (! $this->decoded) { - $this->decoded = @json_decode($body); + return $contents; + } - if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$body}'."); - } + /** + * Get the body as a stream. + */ + public function stream(): StreamInterface + { + $stream = $this->psrResponse->getBody(); + + if ($stream->isSeekable()) { + $stream->rewind(); } - return $this->decoded; + return $stream; } public function status(): int { - return $this->statusCode; + return $this->psrResponse->getStatusCode(); } - public function isEmpty(): bool + public function successful(): bool { - return empty($this->body()); + return $this->status() >= 200 && $this->status() < 300; } - public function getReasonPhrase(): string + public function isUnprocessable(): bool { - if (empty($this->reasonPhrase) && isset(static::$phrases[$this->statusCode])) { - return static::$phrases[$this->statusCode]; - } + return $this->status() === ResponseStatusCode::HTTP_UNPROCESSABLE_ENTITY; + } - return $this->reasonPhrase; + public function isEmpty(): bool + { + return empty($this->body()); } } diff --git a/src/Http/ResponseHandler.php b/src/Http/ResponseHandler.php deleted file mode 100644 index d7ff9e4a7..000000000 --- a/src/Http/ResponseHandler.php +++ /dev/null @@ -1,110 +0,0 @@ -guard($response); - - $this->throwExceptionIfRequestFailed($response, $requestBody); - - return $response; - } - - public static function create(): self - { - return new self(); - } - - public static function noResponse(): ResponseContract - { - return (new self())->handle(null); - } - - public function guard(ResponseContract $response): void - { - $this->guardNoContentWithBody($response); - - if (empty($response->body())) { - return; - } - - $this->guardJsonNotDecodable($response); - - // @todo check if this is still necessary as it seems to be from api v1 - if (isset($response->decode()->error)) { - throw new ApiException($response->decode()->error->message); - } - } - - protected function guardNoContentWithBody(ResponseContract $response): void - { - if (empty($response->body()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { - throw new ApiException("No response body found."); - } - } - - protected function guardJsonNotDecodable(ResponseContract $response): void - { - $response->decode(); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$response->body()}'."); - } - } - - public function throwExceptionIfRequestFailed(ResponseContract $response, ?string $requestBody): void - { - if ($this->requestSucceeded($response->status())) { - return; - } - - $body = $response->decode(); - - $message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}"; - - $field = null; - - if (! empty($body->field)) { - $field = $body->field; - } - - if (isset($body->_links, $body->_links->documentation)) { - $message .= ". Documentation: {$body->_links->documentation->href}"; - } - - if ($requestBody) { - $message .= ". Request body: {$requestBody}"; - } - - throw new ApiException( - $message, - $response->status(), - $field, - ); - } - - /** - * Determine if the response indicates a client or server error occurred. - * - * @return bool - */ - private function requestSucceeded(int $status) - { - return $status < ResponseStatusCode::HTTP_BAD_REQUEST; - } -} diff --git a/src/Http/Rules/InvalidIdRule.php b/src/Http/Rules/InvalidIdRule.php deleted file mode 100644 index 319811b77..000000000 --- a/src/Http/Rules/InvalidIdRule.php +++ /dev/null @@ -1,35 +0,0 @@ -id = $id; - $this->prefix = $prefix; - } - - public function validate(Request $request): void { - if (strpos($this->id, $this->prefix) !== 0) { - $resourceType = $this->getResourceType($request); - - throw new ApiException("Invalid {$resourceType} ID: '{$this->id}'. A resource ID should start with '" . $this->prefix . "'."); - } - } - - public function getResourceType(Request $request): string - { - $classBasename = basename(str_replace("\\", "/", $request::getTargetResourceClass())); - - return strtolower($classBasename); - } -} diff --git a/src/Idempotency/DefaultIdempotencyKeyGenerator.php b/src/Idempotency/DefaultIdempotencyKeyGenerator.php index 0aa49212c..18a449900 100644 --- a/src/Idempotency/DefaultIdempotencyKeyGenerator.php +++ b/src/Idempotency/DefaultIdempotencyKeyGenerator.php @@ -2,15 +2,13 @@ namespace Mollie\Api\Idempotency; +use Mollie\Api\Contracts\IdempotencyKeyGeneratorContract; use Mollie\Api\Exceptions\IncompatiblePlatform; class DefaultIdempotencyKeyGenerator implements IdempotencyKeyGeneratorContract { const DEFAULT_LENGTH = 16; - /** - * @var int - */ protected int $length; public function __construct($length = self::DEFAULT_LENGTH) @@ -20,7 +18,6 @@ public function __construct($length = self::DEFAULT_LENGTH) /** * @throws \Mollie\Api\Exceptions\IncompatiblePlatform - * @return string */ public function generate(): string { diff --git a/src/Idempotency/FakeIdempotencyKeyGenerator.php b/src/Idempotency/FakeIdempotencyKeyGenerator.php index 92e638a40..fa9a4587b 100644 --- a/src/Idempotency/FakeIdempotencyKeyGenerator.php +++ b/src/Idempotency/FakeIdempotencyKeyGenerator.php @@ -4,9 +4,10 @@ namespace Mollie\Api\Idempotency; +use Mollie\Api\Contracts\IdempotencyKeyGeneratorContract; + class FakeIdempotencyKeyGenerator implements IdempotencyKeyGeneratorContract { - /** @var string */ private string $fakeKey; public function setFakeKey($fakeKey): void diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 91149291a..9f434ba47 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -2,14 +2,17 @@ namespace Mollie\Api; -use Mollie\Api\Contracts\MollieHttpAdapterContract; +use Mollie\Api\Contracts\Connector; +use Mollie\Api\Contracts\HttpAdapterContract; +use Mollie\Api\Contracts\IdempotencyKeyGeneratorContract; use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; -use Mollie\Api\Contracts\ResponseContract as Response; -use Mollie\Api\Endpoints\BalanceReportEndpoint; -use Mollie\Api\Endpoints\BalanceTransactionEndpoint; -use Mollie\Api\Endpoints\ChargebackEndpoint; -use Mollie\Api\Endpoints\ClientEndpoint; -use Mollie\Api\Endpoints\ClientLinkEndpoint; +use Mollie\Api\EndpointCollection\BalanceEndpointCollection; +use Mollie\Api\EndpointCollection\BalanceReportEndpointCollection; +use Mollie\Api\EndpointCollection\ChargebackEndpointCollection; +use Mollie\Api\EndpointCollection\ClientEndpointCollection; +use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; use Mollie\Api\Endpoints\CustomerEndpoint; use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; @@ -42,21 +45,26 @@ use Mollie\Api\Endpoints\SubscriptionPaymentEndpoint; use Mollie\Api\Endpoints\TerminalEndpoint; use Mollie\Api\Endpoints\WalletEndpoint; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Exceptions\IncompatiblePlatform; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; -use Mollie\Api\Http\EndpointCollection\BalanceEndpointCollection; -use Mollie\Api\Http\EndpointCollection\PaymentEndpointCollection; -use Mollie\Api\Http\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract; +use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; +use Mollie\Api\Resources\BalanceTransactionCollection; +use Mollie\Api\Traits\HandlesAuthentication; +use Mollie\Api\Traits\HandlesDebugging; +use Mollie\Api\Traits\HandlesIdempotency; +use Mollie\Api\Traits\HandlesTestmode; +use Mollie\Api\Traits\HandlesVersions; +use Mollie\Api\Traits\HasEndpoints; +use Mollie\Api\Traits\HasRequestProperties; +use Mollie\Api\Traits\Initializable; +use Mollie\Api\Traits\SendsRequests; /** * @property BalanceEndpointCollection $balances - * @property BalanceReportEndpoint $balanceReports - * @property BalanceTransactionEndpoint $balanceTransactions - * @property ChargebackEndpoint $chargebacks - * @property ClientEndpoint $clients - * @property ClientLinkEndpoint $clientLinks + * @property BalanceReportEndpointCollection $balanceReports + * @property BalanceTransactionCollection $balanceTransactions + * @property ChargebackEndpointCollection $chargebacks + * @property ClientEndpointCollection $clients + * @property ClientLinkEndpointCollection $clientLinks * @property CustomerPaymentsEndpoint $customerPayments * @property CustomerEndpoint $customers * @property InvoiceEndpoint $invoices @@ -91,71 +99,43 @@ * @property SubscriptionPaymentEndpoint $subscriptionPayments * @property TerminalEndpoint $terminals * @property WalletEndpoint $wallets + * @property HttpAdapterContract $httpClient */ -class MollieApiClient +class MollieApiClient implements Connector { - use HandlesIdempotency; + use HandlesAuthentication; use HandlesDebugging; + use HandlesIdempotency; + use HandlesTestmode; + use HandlesVersions; + use HasEndpoints; + use HasRequestProperties; + use Initializable; + use SendsRequests; /** * Version of our client. */ - public const CLIENT_VERSION = "3.0.0"; + public const CLIENT_VERSION = '3.0.0'; /** * Endpoint of the remote API. */ - public const API_ENDPOINT = "https://api.mollie.com"; + public const API_ENDPOINT = 'https://api.mollie.com'; /** * Version of the remote API. */ - public const API_VERSION = "v2"; - - /** - * HTTP Methods - */ - public const HTTP_GET = "GET"; - public const HTTP_POST = "POST"; - public const HTTP_DELETE = "DELETE"; - public const HTTP_PATCH = "PATCH"; - - /** - * @var MollieHttpAdapterContract - */ - protected MollieHttpAdapterContract $httpClient; + public const API_VERSION = 'v2'; /** - * @var string + * Http client used to perform requests. */ - protected string $apiEndpoint = self::API_ENDPOINT; + protected HttpAdapterContract $httpClient; /** - * @var string - */ - protected string $apiKey = ''; - - /** - * True if an OAuth access token is set as API key. + * @param \GuzzleHttp\ClientInterface|\Mollie\Api\Contracts\HttpAdapterContract|null $client * - * @var null|bool - */ - protected ?bool $oauthAccess = null; - - /** - * @var array - */ - protected array $versionStrings = []; - - /** - * @var array - */ - protected array $endpoints = []; - - /** - * @param \GuzzleHttp\ClientInterface|\Mollie\Api\Contracts\MollieHttpAdapterContract|null $client - * @param MollieHttpAdapterPickerContract|null $adapterPicker, - * @param IdempotencyKeyGeneratorContract|null $idempotencyKeyGenerator, * @throws \Mollie\Api\Exceptions\IncompatiblePlatform|\Mollie\Api\Exceptions\UnrecognizedClientException */ public function __construct( @@ -166,292 +146,48 @@ public function __construct( $adapterPicker = $adapterPicker ?: new MollieHttpAdapterPicker; $this->httpClient = $adapterPicker->pickHttpAdapter($client); - $compatibilityChecker = new CompatibilityChecker; - $compatibilityChecker->checkCompatibility(); - - $this->initializeEndpoints(); - $this->initializeVersionStrings(); - $this->initializeIdempotencyKeyGenerator($idempotencyKeyGenerator); - } - - private function initializeEndpoints(): void - { - $endpointClasses = [ - 'balances' => BalanceEndpointCollection::class, - 'payments' => PaymentEndpointCollection::class, - 'paymentRefunds' => PaymentRefundEndpointCollection::class, - - // 'balances' => BalanceEndpoint::class, - 'balanceReports' => BalanceReportEndpoint::class, - 'balanceTransactions' => BalanceTransactionEndpoint::class, - 'chargebacks' => ChargebackEndpoint::class, - 'clients' => ClientEndpoint::class, - 'clientLinks' => ClientLinkEndpoint::class, - 'customerPayments' => CustomerPaymentsEndpoint::class, - 'customers' => CustomerEndpoint::class, - 'invoices' => InvoiceEndpoint::class, - 'mandates' => MandateEndpoint::class, - 'methods' => MethodEndpoint::class, - 'methodIssuers' => MethodIssuerEndpoint::class, - 'onboarding' => OnboardingEndpoint::class, - 'orderLines' => OrderLineEndpoint::class, - 'orderPayments' => OrderPaymentEndpoint::class, - 'orderRefunds' => OrderRefundEndpoint::class, - 'orders' => OrderEndpoint::class, - 'organizationPartners' => OrganizationPartnerEndpoint::class, - 'organizations' => OrganizationEndpoint::class, - 'paymentCaptures' => PaymentCaptureEndpoint::class, - 'paymentChargebacks' => PaymentChargebackEndpoint::class, - 'paymentLinks' => PaymentLinkEndpoint::class, - 'paymentLinkPayments' => PaymentLinkPaymentEndpoint::class, - // 'paymentRefunds' => PaymentRefundEndpoint::class, - 'paymentRoutes' => PaymentRouteEndpoint::class, - // 'payments' => PaymentEndpoint::class, - 'permissions' => PermissionEndpoint::class, - 'profiles' => ProfileEndpoint::class, - 'profileMethods' => ProfileMethodEndpoint::class, - 'refunds' => RefundEndpoint::class, - 'settlementCaptures' => SettlementCaptureEndpoint::class, - 'settlementChargebacks' => SettlementChargebackEndpoint::class, - 'settlementPayments' => SettlementPaymentEndpoint::class, - 'settlementRefunds' => SettlementRefundEndpoint::class, - 'settlements' => SettlementsEndpoint::class, - 'shipments' => OrderShipmentEndpoint::class, - 'subscriptions' => SubscriptionEndpoint::class, - 'subscriptionPayments' => SubscriptionPaymentEndpoint::class, - 'terminals' => TerminalEndpoint::class, - 'wallets' => WalletEndpoint::class, - ]; - - foreach ($endpointClasses as $name => $class) { - $this->endpoints[$name] = $class; - } - } - - private function initializeVersionStrings(): void - { - $this->addVersionString("Mollie/" . self::CLIENT_VERSION); - $this->addVersionString("PHP/" . phpversion()); - - if ($clientVersion = $this->httpClient->version()) { - $this->addVersionString($clientVersion); - } - } - - /** - * @param string $url - * - * @return self - */ - public function setApiEndpoint($url): self - { - $this->apiEndpoint = rtrim(trim($url), '/'); + CompatibilityChecker::make()->checkCompatibility(); - return $this; - } + $this->idempotencyKeyGenerator = $idempotencyKeyGenerator ?? new DefaultIdempotencyKeyGenerator; - /** - * @return string - */ - public function getApiEndpoint(): string - { - return $this->apiEndpoint; + $this->initializeTraits(); } - /** - * @return array - */ - public function getVersionStrings(): array + protected function defaultHeaders(): array { - return $this->versionStrings; - } - - /** - * @param string $apiKey The Mollie API key, starting with 'test_' or 'live_' - * - * @return MollieApiClient - * @throws ApiException - */ - public function setApiKey(string $apiKey): self - { - $apiKey = trim($apiKey); - - if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) { - throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); - } - - $this->apiKey = $apiKey; - $this->oauthAccess = false; - - return $this; - } - - /** - * @param string $accessToken OAuth access token, starting with 'access_' - * - * @return MollieApiClient - * @throws ApiException - */ - public function setAccessToken(string $accessToken): self - { - $accessToken = trim($accessToken); - - if (!preg_match('/^access_\w+$/', $accessToken)) { - throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'."); - } - - $this->apiKey = $accessToken; - $this->oauthAccess = true; - - return $this; - } - - /** - * Returns null if no API key has been set yet. - * - * @return bool|null - */ - public function usesOAuth(): ?bool - { - return $this->oauthAccess; - } - - /** - * @param string $versionString - * - * @return MollieApiClient - */ - public function addVersionString($versionString): self - { - $this->versionStrings[] = str_replace([" ", "\t", "\n", "\r"], '-', $versionString); - - return $this; - } - - /** - * Perform an HTTP call. This method is used by the resource-specific classes. - * - * @param string $method - * @param string $path - * @param string|null $body - * - * @return Response - * @throws ApiException - */ - public function performHttpCall(string $method, string $path, ?string $body = null): Response - { - $url = $this->buildApiUrl($path); - - return $this->performHttpCallToFullUrl($method, $url, $body); - } - - /** - * Perform an HTTP call to a full URL. This method is used by the resource-specific classes. - * - * @param string $method - * @param string $url - * @param string|null $body - * - * @return Response - * @throws ApiException - */ - public function performHttpCallToFullUrl(string $method, string $url, ?string $body = null): Response - { - $this->ensureApiKeyIsSet(); - - $headers = $this->prepareHeaders($method, $body); - $response = $this->httpClient->send($method, $url, $headers, $body); - - $this->resetIdempotencyKey(); - - return $response; - } - - /** - * Build the full API URL for a given method. - * - * @param string $path - * @return string - */ - private function buildApiUrl(string $path): string - { - return rtrim($this->apiEndpoint, '/') . '/' . self::API_VERSION . '/' . ltrim($path, '/'); - } - - /** - * Ensure that the API key is set. - * - * @throws ApiException - */ - protected function ensureApiKeyIsSet(): void - { - if (empty($this->apiKey)) { - throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key."); - } + return [ + 'X-Mollie-Client-Info' => php_uname(), + 'Accept' => 'application/json', + ]; } - /** - * Prepare the headers for the HTTP request. - * - * @param string $method - * @param string|null $body - * @return array - */ - protected function prepareHeaders(string $method, ?string $body): array + public function getHttpClient(): HttpAdapterContract { - $userAgent = implode(' ', $this->versionStrings) - . ($this->usesOAuth() ? " OAuth/2.0" : ""); - - $headers = [ - 'Accept' => "application/json", - 'Authorization' => "Bearer {$this->apiKey}", - 'User-Agent' => $userAgent, - ]; - - if ($body !== null) { - $headers['Content-Type'] = "application/json"; - } - - if (function_exists("php_uname")) { - $headers['X-Mollie-Client-Info'] = php_uname(); - } - - return $this->applyIdempotencyKey($headers, $method); + return $this->httpClient; } - /** - * Magic getter to access the endpoints. - * - * @param string $name - * - * @return mixed - * @throws \Exception - */ - public function __get(string $name) + public function resolveBaseUrl(): string { - if (isset($this->endpoints[$name])) { - return new $this->endpoints[$name]($this); - } - - throw new \Exception("Undefined endpoint: $name"); + return rtrim($this->apiEndpoint, '/').'/'.self::API_VERSION; } - /** - * @return array - */ public function __serialize(): array { - return ['apiEndpoint' => $this->apiEndpoint]; + return [ + 'apiEndpoint' => $this->apiEndpoint, + 'httpClient' => $this->httpClient, + 'idempotencyKeyGenerator' => $this->idempotencyKeyGenerator, + 'testmode' => $this->testmode, + 'versionStrings' => $this->versionStrings, + ]; } - /** - * @param array $data - * @return void - * @throws IncompatiblePlatform - */ public function __unserialize(array $data): void { - $this->__construct(); $this->apiEndpoint = $data['apiEndpoint']; + $this->httpClient = $data['httpClient']; + $this->idempotencyKeyGenerator = $data['idempotencyKeyGenerator']; + $this->testmode = $data['testmode']; + $this->versionStrings = $data['versionStrings']; } } diff --git a/src/Repositories/ArrayStore.php b/src/Repositories/ArrayStore.php new file mode 100644 index 000000000..fcfb5e64d --- /dev/null +++ b/src/Repositories/ArrayStore.php @@ -0,0 +1,64 @@ +store = $data; + } + + public function set(array $data): static + { + $this->store = $data; + + return $this; + } + + public function get(string $key, mixed $default = null): mixed + { + return $this->store[$key] ?? $default; + } + + public function add(string $key, $value): static + { + $this->store[$key] = $value; + + return $this; + } + + public function has(string $key): bool + { + return Arr::has($this->store, $key); + } + + public function merge(array ...$data): static + { + $this->store = array_merge($this->store, ...$data); + + return $this; + } + + public function remove(string $key): static + { + unset($this->store[$key]); + + return $this; + } + + public function all(): array + { + return array_filter($this->store, fn ($value) => ! empty($value)); + } + + public function isEmpty(): bool + { + return empty($this->store); + } +} diff --git a/src/Repositories/JsonBodyRepository.php b/src/Repositories/JsonBodyRepository.php new file mode 100644 index 000000000..ee5829b39 --- /dev/null +++ b/src/Repositories/JsonBodyRepository.php @@ -0,0 +1,56 @@ +set($data); + } + + public function set(mixed $value): static + { + $this->store = $value; + + return $this; + } + + public function all(): mixed + { + return $this->store; + } + + public function remove(string $key): static + { + unset($this->store[$key]); + + return $this; + } + + public function isEmpty(): bool + { + return empty($this->store); + } + + public function isNotEmpty(): bool + { + return ! $this->isEmpty(); + } + + public function __toString(): string + { + return @json_encode($this->store); + } + + public function toStream(StreamFactoryInterface $streamFactory): StreamInterface + { + return $streamFactory->createStream((string) $this); + } +} diff --git a/src/Resources/Balance.php b/src/Resources/Balance.php index c84ad5678..f09dd5da6 100644 --- a/src/Resources/Balance.php +++ b/src/Resources/Balance.php @@ -4,6 +4,11 @@ class Balance extends BaseResource { + /** + * Resource id prefix. Used to validate resource id's. + */ + public static string $resourceIdPrefix = 'bal_'; + /** * Indicates this is a balance resource. The value will always be "balance" here. * @@ -23,6 +28,7 @@ class Balance extends BaseResource * The identifier uniquely referring this balance. Mollie assigns this identifier at balance creation. * * @example bal_gVMhHKqSSRYJyPsuoPABC + * * @var string */ public $id; @@ -31,6 +37,7 @@ class Balance extends BaseResource * UTC datetime the balance was created in ISO-8601 format. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -67,6 +74,7 @@ class Balance extends BaseResource /** * The total amount that is in the process of being transferred from your balance to your verified bank account. + * * @var \stdClass */ public $outgoingAmount; diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 39ef1d52a..94d32c8b6 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -2,35 +2,36 @@ namespace Mollie\Api\Resources; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Contracts\Connector; +use Mollie\Api\Http\Response; abstract class BaseCollection extends \ArrayObject { - protected MollieApiClient $client; + protected Connector $connector; + + protected ?Response $response = null; /** * The name of the collection resource in Mollie's API. - * - * @var string */ public static string $collectionName = ''; - /** - * @var \stdClass|null - */ public ?\stdClass $_links = null; /** - * @param MollieApiClient $client - * @param array|object $items - * @param \stdClass|null $_links + * @param array|object $items */ - public function __construct(MollieApiClient $client, $items = [], ?\stdClass $_links = null) + public function __construct(Connector $connector, Response $response, $items = [], ?\stdClass $_links = null) { parent::__construct($items); $this->_links = $_links; - $this->client = $client; + $this->connector = $connector; + } + + public function getResponse(): ?Response + { + return $this->response; } public function contains(callable $callback): bool @@ -49,7 +50,7 @@ public function filter(callable $callback) $filteredItems = array_filter($this->getArrayCopy(), $callback); /** @phpstan-ignore-next-line */ - return new static($this->client, $filteredItems, $this->_links); + return new static($this->connector, $filteredItems, $this->_links); } public static function getCollectionResourceName(): string diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index ea015227f..856568b64 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -2,12 +2,15 @@ namespace Mollie\Api\Resources; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Contracts\Connector; +use Mollie\Api\Http\Response; #[\AllowDynamicProperties] abstract class BaseResource { - protected MollieApiClient $client; + protected Connector $connector; + + protected ?Response $response; /** * Indicates the type of resource. @@ -18,11 +21,14 @@ abstract class BaseResource */ public $resource; - /** - * @param MollieApiClient $client - */ - public function __construct(MollieApiClient $client) + public function __construct(Connector $connector, ?Response $response = null) + { + $this->connector = $connector; + $this->response = $response; + } + + public function getResponse(): Response { - $this->client = $client; + return $this->response; } } diff --git a/src/Resources/CurrentProfile.php b/src/Resources/CurrentProfile.php index 984672455..b75d20936 100644 --- a/src/Resources/CurrentProfile.php +++ b/src/Resources/CurrentProfile.php @@ -9,26 +9,24 @@ class CurrentProfile extends Profile /** * Enable a payment method for this profile. * - * @param string $methodId - * @param array $data - * @return Method + * @param string $methodId + * * @throws ApiException */ public function enableMethod($methodId, array $data = []): Method { - return $this->client->profileMethods->createForCurrentProfile($methodId, $data); + return $this->connector->profileMethods->createForCurrentProfile($methodId, $data); } /** * Disable a payment method for this profile. * - * @param string $methodId - * @param array $data - * @return Method + * @param string $methodId + * * @throws ApiException */ public function disableMethod($methodId, array $data = []): ?Method { - return $this->client->profileMethods->deleteForCurrentProfile($methodId, $data); + return $this->connector->profileMethods->deleteForCurrentProfile($methodId, $data); } } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 2b4c398ec..5a7b41e29 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -3,24 +3,21 @@ namespace Mollie\Api\Resources; use Generator; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\ResponseStatusCode; -use Mollie\Api\InteractsWithResource; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Traits\InteractsWithResource as TraitsInteractsWithResource; abstract class CursorCollection extends BaseCollection { - use InteractsWithResource; + use TraitsInteractsWithResource; /** * Return the next set of resources when available * - * @return CursorCollection|null * @throws \Mollie\Api\Exceptions\ApiException */ final public function next(): ?CursorCollection { - if (!$this->hasNext()) { + if (! $this->hasNext()) { return null; } @@ -30,12 +27,11 @@ final public function next(): ?CursorCollection /** * Return the previous set of resources when available * - * @return CursorCollection|null * @throws \Mollie\Api\Exceptions\ApiException */ final public function previous(): ?CursorCollection { - if (!$this->hasPrevious()) { + if (! $this->hasPrevious()) { return null; } @@ -44,28 +40,13 @@ final public function previous(): ?CursorCollection private function fetchCollection(string $url): CursorCollection { - $response = $this - ->client - ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $url); - - if ($response->status() !== ResponseStatusCode::HTTP_OK) { - throw new ApiException($response->body(), $response->status()); - } - - $data = $response->decode(); - - return ResourceFactory::createCursorResourceCollection( - $this->client, - $data->_embedded->{static::getCollectionResourceName()}, - static::getResourceClass(), - $data->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest($url, static::class)); } /** * Determine whether the collection has a next page available. - * - * @return bool */ public function hasNext(): bool { @@ -74,8 +55,6 @@ public function hasNext(): bool /** * Determine whether the collection has a previous page available. - * - * @return bool */ public function hasPrevious(): bool { @@ -84,10 +63,6 @@ public function hasPrevious(): bool /** * Iterate over a CursorCollection and yield its elements. - * - * @param bool $iterateBackwards - * - * @return LazyCollection */ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection { @@ -99,7 +74,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 46a797e79..644138694 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -58,135 +58,129 @@ class Customer extends BaseResource public $_links; /** - * @return null|Customer * @throws ApiException */ public function update(): ?Customer { $body = [ - "name" => $this->name, - "email" => $this->email, - "locale" => $this->locale, - "metadata" => $this->metadata, + 'name' => $this->name, + 'email' => $this->email, + 'locale' => $this->locale, + 'metadata' => $this->metadata, ]; /** @var null|Customer */ - return $this->client->customers->update($this->id, $body); + return $this->connector->customers->update($this->id, $body); } /** - * @param array $options - * @param array $filters - * * @return Payment + * * @throws ApiException */ public function createPayment(array $options = [], array $filters = []) { - return $this->client->customerPayments->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->customerPayments->createFor($this, $this->withPresetOptions($options), $filters); } /** * Get all payments for this customer * * @return PaymentCollection + * * @throws ApiException */ public function payments() { - return $this->client->customerPayments->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->customerPayments->listFor($this, null, null, $this->getPresetOptions()); } /** - * @param array $options - * @param array $filters - * * @return Subscription + * * @throws ApiException */ public function createSubscription(array $options = [], array $filters = []) { - return $this->client->subscriptions->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->subscriptions->createFor($this, $this->withPresetOptions($options), $filters); } /** - * @param string $subscriptionId - * @param array $parameters - * + * @param string $subscriptionId * @return Subscription + * * @throws ApiException */ public function getSubscription($subscriptionId, array $parameters = []) { - return $this->client->subscriptions->getFor($this, $subscriptionId, $this->withPresetOptions($parameters)); + return $this->connector->subscriptions->getFor($this, $subscriptionId, $this->withPresetOptions($parameters)); } /** - * @param string $subscriptionId - * + * @param string $subscriptionId * @return null + * * @throws ApiException */ public function cancelSubscription($subscriptionId) { - return $this->client->subscriptions->cancelFor($this, $subscriptionId, $this->getPresetOptions()); + return $this->connector->subscriptions->cancelFor($this, $subscriptionId, $this->getPresetOptions()); } /** * Get all subscriptions for this customer * * @return SubscriptionCollection + * * @throws ApiException */ public function subscriptions() { - return $this->client->subscriptions->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->subscriptions->listFor($this, null, null, $this->getPresetOptions()); } /** - * @param array $options - * @param array $filters - * * @return Mandate + * * @throws ApiException */ public function createMandate(array $options = [], array $filters = []) { - return $this->client->mandates->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->mandates->createFor($this, $this->withPresetOptions($options), $filters); } /** - * @param string $mandateId - * @param array $parameters - * + * @param string $mandateId * @return Mandate + * * @throws ApiException */ public function getMandate($mandateId, array $parameters = []) { - return $this->client->mandates->getFor($this, $mandateId, $parameters); + return $this->connector->mandates->getFor($this, $mandateId, $parameters); } /** - * @param string $mandateId - * + * @param string $mandateId * @return null + * * @throws ApiException */ public function revokeMandate($mandateId) { - return $this->client->mandates->revokeFor($this, $mandateId, $this->getPresetOptions()); + return $this->connector->mandates->revokeFor($this, $mandateId, $this->getPresetOptions()); } /** * Get all mandates for this customer * * @return MandateCollection + * * @throws ApiException */ public function mandates() { - return $this->client->mandates->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->mandates->listFor($this, null, null, $this->getPresetOptions()); } /** @@ -202,8 +196,6 @@ public function hasValidMandate() /** * Helper function to check for specific payment method mandate with status valid - * - * @return bool */ public function hasValidMandateForMethod($method): bool { diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index efd4582d4..640ebc623 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Resources; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicDeleteRequest; use Mollie\Api\Types\MandateStatus; class Mandate extends BaseResource @@ -59,25 +59,16 @@ class Mandate extends BaseResource */ public $_links; - /** - * @return bool - */ public function isValid(): bool { return $this->status === MandateStatus::VALID; } - /** - * @return bool - */ public function isPending(): bool { return $this->status === MandateStatus::PENDING; } - /** - * @return bool - */ public function isInvalid(): bool { return $this->status === MandateStatus::INVALID; @@ -85,8 +76,6 @@ public function isInvalid(): bool /** * Revoke the mandate - * - * @return null|Mandate */ public function revoke(): ?Mandate { @@ -94,22 +83,16 @@ public function revoke(): ?Mandate return $this; } - $body = null; - if ($this->client->usesOAuth()) { - $body = json_encode([ - "testmode" => $this->mode === "test" ? true : false, - ]); - } - - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_DELETE, - $this->_links->self->href, - $body - ); - - /** @var null|Mandate */ - return $result->isEmpty() - ? null - : ResourceFactory::createFromApiResult($this->client, $result->decode(), self::class); + $body = [ + 'testmode' => $this->mode === 'test' ? true : false, + ]; + + return $this + ->connector + ->send(new DynamicDeleteRequest( + $this->_links->self->href, + self::class, + $this->mode === 'test' + )); } } diff --git a/src/Resources/Method.php b/src/Resources/Method.php index a0d21ff77..81d8ed6a3 100644 --- a/src/Resources/Method.php +++ b/src/Resources/Method.php @@ -72,14 +72,12 @@ class Method extends BaseResource /** * Get the issuer value objects - * - * @return IssuerCollection */ public function issuers(): IssuerCollection { /** @var IssuerCollection */ return ResourceFactory::createBaseResourceCollection( - $this->client, + $this->connector, Issuer::class, $this->issuers ); @@ -87,14 +85,12 @@ public function issuers(): IssuerCollection /** * Get the method price value objects. - * - * @return MethodPriceCollection */ public function pricing(): MethodPriceCollection { /** @var MethodPriceCollection */ return ResourceFactory::createBaseResourceCollection( - $this->client, + $this->connector, MethodPrice::class, $this->pricing ); diff --git a/src/Resources/Order.php b/src/Resources/Order.php index a3225825c..82fc35f89 100644 --- a/src/Resources/Order.php +++ b/src/Resources/Order.php @@ -14,6 +14,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * Id of the order. * * @example ord_8wmqcHMN4U + * * @var string */ public $id; @@ -22,6 +23,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * The profile ID this order belongs to. * * @example pfl_xH2kP6Nc6X + * * @var string */ public $profileId; @@ -70,7 +72,9 @@ class Order extends BaseResource implements EmbeddedResourcesContract /** * The date of birth of your customer, if available. + * * @example 1976-08-21 + * * @var string|null */ public $consumerDateOfBirth; @@ -93,6 +97,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * The payment method last used when paying for the order. * * @see Method + * * @var string */ public $method; @@ -144,6 +149,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime the order was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $createdAt; @@ -152,6 +158,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime the order the order will expire in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $expiresAt; @@ -160,6 +167,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime if the order is expired, the time of expiration will be present in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $expiredAt; @@ -168,6 +176,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime if the order has been paid, the time of payment will be present in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $paidAt; @@ -176,6 +185,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime if the order has been authorized, the time of authorization will be present in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $authorizedAt; @@ -184,6 +194,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime if the order has been canceled, the time of cancellation will be present in ISO 8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $canceledAt; @@ -192,6 +203,7 @@ class Order extends BaseResource implements EmbeddedResourcesContract * UTC datetime if the order is completed, the time of completion will be present in ISO 8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $completedAt; @@ -235,8 +247,6 @@ public function getEmbeddedResourcesMap(): array /** * Is this order created? - * - * @return bool */ public function isCreated(): bool { @@ -245,8 +255,6 @@ public function isCreated(): bool /** * Is this order paid for? - * - * @return bool */ public function isPaid(): bool { @@ -255,8 +263,6 @@ public function isPaid(): bool /** * Is this order authorized? - * - * @return bool */ public function isAuthorized(): bool { @@ -265,8 +271,6 @@ public function isAuthorized(): bool /** * Is this order canceled? - * - * @return bool */ public function isCanceled(): bool { @@ -275,8 +279,6 @@ public function isCanceled(): bool /** * Is this order shipping? - * - * @return bool */ public function isShipping(): bool { @@ -285,8 +287,6 @@ public function isShipping(): bool /** * Is this order completed? - * - * @return bool */ public function isCompleted(): bool { @@ -295,8 +295,6 @@ public function isCompleted(): bool /** * Is this order expired? - * - * @return bool */ public function isExpired(): bool { @@ -305,8 +303,6 @@ public function isExpired(): bool /** * Is this order completed? - * - * @return bool */ public function isPending(): bool { @@ -321,11 +317,12 @@ public function isPending(): bool * be found. * * @return Order + * * @throws \Mollie\Api\Exceptions\ApiException */ public function cancel() { - return $this->client->orders->cancel($this->id, $this->getPresetOptions()); + return $this->connector->orders->cancel($this->id, $this->getPresetOptions()); } /** @@ -334,40 +331,36 @@ public function cancel() * You can pass an empty lines array if you want to cancel all eligible lines. * Returns null if successful. * - * @param array $data - * @return void * @throws \Mollie\Api\Exceptions\ApiException */ public function cancelLines(array $data): void { - $this->client->orderLines->cancelFor($this, $data); + $this->connector->orderLines->cancelFor($this, $data); } /** * Cancels all eligible lines for this order. * Returns null if successful. * - * @param array $data - * @return void + * @param array $data + * * @throws \Mollie\Api\Exceptions\ApiException */ public function cancelAllLines($data = []): void { $data['lines'] = []; - $this->client->orderLines->cancelFor($this, $data); + $this->connector->orderLines->cancelFor($this, $data); } /** * Get the line value objects - * - * @return OrderLineCollection */ public function lines(): OrderLineCollection { /** @var OrderLineCollection */ return ResourceFactory::createBaseResourceCollection( - $this->client, + $this->connector, OrderLine::class, $this->lines ); @@ -377,22 +370,16 @@ public function lines(): OrderLineCollection * Create a shipment for some order lines. You can provide an empty array for the * "lines" option to include all unshipped lines for this order. * - * @param array $options * - * @return Shipment * @throws ApiException */ public function createShipment(array $options = []): Shipment { - return $this->client->shipments->createFor($this, $this->withPresetOptions($options)); + return $this->connector->shipments->createFor($this, $this->withPresetOptions($options)); } /** * Create a shipment for all unshipped order lines. - * - * @param array $options - * - * @return Shipment */ public function shipAll(array $options = []): Shipment { @@ -404,34 +391,29 @@ public function shipAll(array $options = []): Shipment /** * Retrieve a specific shipment for this order. * - * @param string $shipmentId - * @param array $parameters - * + * @param string $shipmentId * @return Shipment + * * @throws ApiException */ public function getShipment($shipmentId, array $parameters = []) { - return $this->client->shipments->getFor($this, $shipmentId, $this->withPresetOptions($parameters)); + return $this->connector->shipments->getFor($this, $shipmentId, $this->withPresetOptions($parameters)); } /** * Get all shipments for this order. * - * @param array $parameters * - * @return ShipmentCollection * @throws ApiException */ public function shipments(array $parameters = []): ShipmentCollection { - return $this->client->shipments->listFor($this, $this->withPresetOptions($parameters)); + return $this->connector->shipments->listFor($this, $this->withPresetOptions($parameters)); } /** * Get the checkout URL where the customer can complete the payment. - * - * @return string|null */ public function getCheckoutUrl(): ?string { @@ -445,20 +427,15 @@ public function getCheckoutUrl(): ?string /** * Refund specific order lines. * - * @param array $data - * @return Refund * @throws ApiException */ public function refund(array $data): Refund { - return $this->client->orderRefunds->createFor($this, $this->withPresetOptions($data)); + return $this->connector->orderRefunds->createFor($this, $this->withPresetOptions($data)); } /** * Refund all eligible order lines. - * - * @param array $data - * @return Refund */ public function refundAll(array $data = []): Refund { @@ -470,53 +447,49 @@ public function refundAll(array $data = []): Refund /** * Retrieves all refunds associated with this order * - * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ public function refunds(): RefundCollection { - return $this->client->orderRefunds->pageFor($this); + return $this->connector->orderRefunds->pageFor($this); } /** * Saves the order's updated billingAddress and/or shippingAddress. * - * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?Order { $body = [ - "billingAddress" => $this->billingAddress, - "shippingAddress" => $this->shippingAddress, - "orderNumber" => $this->orderNumber, - "redirectUrl" => $this->redirectUrl, - "cancelUrl" => $this->cancelUrl, - "webhookUrl" => $this->webhookUrl, + 'billingAddress' => $this->billingAddress, + 'shippingAddress' => $this->shippingAddress, + 'orderNumber' => $this->orderNumber, + 'redirectUrl' => $this->redirectUrl, + 'cancelUrl' => $this->cancelUrl, + 'webhookUrl' => $this->webhookUrl, ]; /** @var null|Order */ - return $this->client->orders->update($this->id, $body); + return $this->connector->orders->update($this->id, $body); } /** * Create a new payment for this Order. * - * @param array $data - * @param array $filters - * @return Payment + * @param array $data + * @param array $filters + * * @throws \Mollie\Api\Exceptions\ApiException */ public function createPayment($data, $filters = []): Payment { - return $this->client->orderPayments->createFor($this, $data, $filters); + return $this->connector->orderPayments->createFor($this, $data, $filters); } /** * Retrieve the payments for this order. * Requires the order to be retrieved using the embed payments parameter. - * - * @return null|PaymentCollection */ public function payments(): ?PaymentCollection { @@ -525,10 +498,10 @@ public function payments(): ?PaymentCollection } /** @var PaymentCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, + return ResourceFactory::createBaseResourceCollection( + $this->connector, + Payment::class, $this->_embedded->payments, - Payment::class ); } } diff --git a/src/Resources/OrderLine.php b/src/Resources/OrderLine.php index b8da61009..ff47b91f7 100644 --- a/src/Resources/OrderLine.php +++ b/src/Resources/OrderLine.php @@ -25,6 +25,7 @@ class OrderLine extends BaseResource * The ID of the order this line belongs to. * * @example ord_kEn1PlbGa + * * @var string */ public $orderId; @@ -33,6 +34,7 @@ class OrderLine extends BaseResource * The type of product bought. * * @example physical + * * @var string */ public $type; @@ -41,6 +43,7 @@ class OrderLine extends BaseResource * A description of the order line. * * @example LEGO 4440 Forest Police Station + * * @var string */ public $name; @@ -156,6 +159,7 @@ class OrderLine extends BaseResource * passed. * * @example "21.00" + * * @var string */ public $vatRate; @@ -200,6 +204,7 @@ class OrderLine extends BaseResource * The order line's date and time of creation, in ISO 8601 format. * * @example 2018-08-02T09:29:56+00:00 + * * @var string */ public $createdAt; @@ -225,8 +230,6 @@ public function getProductUrl() /** * Get the image URL of the product sold. - * - * @return string|null */ public function getImageUrl(): ?string { @@ -239,8 +242,6 @@ public function getImageUrl(): ?string /** * Is this order line created? - * - * @return bool */ public function isCreated(): bool { @@ -249,8 +250,6 @@ public function isCreated(): bool /** * Is this order line paid for? - * - * @return bool */ public function isPaid(): bool { @@ -259,8 +258,6 @@ public function isPaid(): bool /** * Is this order line authorized? - * - * @return bool */ public function isAuthorized(): bool { @@ -269,8 +266,6 @@ public function isAuthorized(): bool /** * Is this order line canceled? - * - * @return bool */ public function isCanceled(): bool { @@ -279,8 +274,6 @@ public function isCanceled(): bool /** * Is this order line shipping? - * - * @return bool */ public function isShipping(): bool { @@ -289,8 +282,6 @@ public function isShipping(): bool /** * Is this order line completed? - * - * @return bool */ public function isCompleted(): bool { @@ -299,8 +290,6 @@ public function isCompleted(): bool /** * Is this order line for a physical product? - * - * @return bool */ public function isPhysical(): bool { @@ -309,8 +298,6 @@ public function isPhysical(): bool /** * Is this order line for applying a discount? - * - * @return bool */ public function isDiscount(): bool { @@ -319,8 +306,6 @@ public function isDiscount(): bool /** * Is this order line for a digital product? - * - * @return bool */ public function isDigital(): bool { @@ -329,8 +314,6 @@ public function isDigital(): bool /** * Is this order line for applying a shipping fee? - * - * @return bool */ public function isShippingFee(): bool { @@ -339,8 +322,6 @@ public function isShippingFee(): bool /** * Is this order line for store credit? - * - * @return bool */ public function isStoreCredit(): bool { @@ -349,8 +330,6 @@ public function isStoreCredit(): bool /** * Is this order line for a gift card? - * - * @return bool */ public function isGiftCard(): bool { @@ -359,8 +338,6 @@ public function isGiftCard(): bool /** * Is this order line for a surcharge? - * - * @return bool */ public function isSurcharge(): bool { @@ -370,27 +347,21 @@ public function isSurcharge(): bool /** * Update an orderline by supplying one or more parameters in the data array * - * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?Order { /** @var null|Order */ - $result = $this->client->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); - - /** @var Order */ - return ResourceFactory::createFromApiResult($this->client, $result, Order::class); + return $this->connector->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); } /** * Get sanitized array of order line data - * - * @return array */ public function getUpdateData(): array { $data = [ - "name" => $this->name, + 'name' => $this->name, 'imageUrl' => $this->imageUrl, 'productUrl' => $this->productUrl, 'metadata' => $this->metadata, diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 463870f0a..d4b6b23ea 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; @@ -14,8 +14,6 @@ class Payment extends BaseResource implements EmbeddedResourcesContract /** * Resource id prefix. Used to validate resource id's. - * - * @var string */ public static string $resourceIdPrefix = 'tr_'; @@ -89,6 +87,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * method. * * @see Method + * * @var string|null */ public $method; @@ -104,6 +103,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * UTC datetime the payment was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $createdAt; @@ -112,6 +112,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * UTC datetime the payment was paid in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $paidAt; @@ -120,6 +121,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * UTC datetime the payment was canceled in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $canceledAt; @@ -144,6 +146,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * UTC due date for the banktransfer payment in ISO-8601 format. * * @example "2021-01-19" + * * @var string|null */ public $dueDate; @@ -153,7 +156,9 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * Please note: the payment instructions will be sent immediately when creating the payment. * * @example "user@mollie.com" + * * @var string|null + * * @deprecated 2024-06-01 The billingEmail field is deprecated. Use the "billingAddress" field instead. */ public $billingEmail; @@ -162,6 +167,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * The profile ID this payment belongs to. * * @example pfl_xH2kP6Nc6X + * * @var string */ public $profileId; @@ -198,6 +204,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * The mandate ID this payment is performed with. * * @example mdt_pXm1g3ND + * * @var string|null */ public $mandateId; @@ -206,6 +213,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * The subscription ID this payment belongs to. * * @example sub_rVKGtNd6s3 + * * @var string|null */ public $subscriptionId; @@ -214,6 +222,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * The order ID this payment belongs to. * * @example ord_pbjz8x + * * @var string|null */ public $orderId; @@ -243,6 +252,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * The settlement ID this payment belongs to. * * @example stl_jDk30akdN + * * @var string|null */ public $settlementId; @@ -318,7 +328,9 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * will be added to the date and time the payment became authorized. * * Possible values: ... hours ... days + * * @example 8 hours + * * @var string|null */ public $captureDelay; @@ -328,6 +340,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * ISO-8601 format. This parameter is omitted if the payment is not authorized (yet). * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $captureBefore; @@ -355,6 +368,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * parameter is omitted if the payment is not authorized (yet). * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $authorizedAt; @@ -364,6 +378,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * parameter is omitted if the payment did not expire (yet). * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $expiredAt; @@ -373,6 +388,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract * be available here as well. * * @example cst_XPn78q9CfT + * * @var string|null */ public $customerId; @@ -397,8 +413,6 @@ public function getEmbeddedResourcesMap(): array /** * Is this payment canceled? - * - * @return bool */ public function isCanceled(): bool { @@ -407,8 +421,6 @@ public function isCanceled(): bool /** * Is this payment expired? - * - * @return bool */ public function isExpired(): bool { @@ -417,8 +429,6 @@ public function isExpired(): bool /** * Is this payment still open / ongoing? - * - * @return bool */ public function isOpen(): bool { @@ -427,8 +437,6 @@ public function isOpen(): bool /** * Is this payment pending? - * - * @return bool */ public function isPending(): bool { @@ -437,8 +445,6 @@ public function isPending(): bool /** * Is this payment authorized? - * - * @return bool */ public function isAuthorized(): bool { @@ -447,8 +453,6 @@ public function isAuthorized(): bool /** * Is this payment paid for? - * - * @return bool */ public function isPaid(): bool { @@ -457,8 +461,6 @@ public function isPaid(): bool /** * Does the payment have refunds - * - * @return bool */ public function hasRefunds(): bool { @@ -467,8 +469,6 @@ public function hasRefunds(): bool /** * Does this payment has chargebacks - * - * @return bool */ public function hasChargebacks(): bool { @@ -477,8 +477,6 @@ public function hasChargebacks(): bool /** * Is this payment failing? - * - * @return bool */ public function isFailed(): bool { @@ -489,8 +487,6 @@ public function isFailed(): bool * Check whether 'sequenceType' is set to 'first'. If a 'first' payment has been * completed successfully, the consumer's account may be charged automatically * using recurring payments. - * - * @return bool */ public function hasSequenceTypeFirst(): bool { @@ -501,8 +497,6 @@ public function hasSequenceTypeFirst(): bool * Check whether 'sequenceType' is set to 'recurring'. This type of payment is * processed without involving * the consumer. - * - * @return bool */ public function hasSequenceTypeRecurring(): bool { @@ -511,8 +505,6 @@ public function hasSequenceTypeRecurring(): bool /** * Get the checkout URL where the customer can complete the payment. - * - * @return string|null */ public function getCheckoutUrl(): ?string { @@ -525,8 +517,6 @@ public function getCheckoutUrl(): ?string /** * Get the mobile checkout URL where the customer can complete the payment. - * - * @return string|null */ public function getMobileAppCheckoutUrl(): ?string { @@ -537,17 +527,11 @@ public function getMobileAppCheckoutUrl(): ?string return $this->_links->mobileAppCheckout->href; } - /** - * @return bool - */ public function canBeRefunded(): bool { return $this->amountRemaining !== null; } - /** - * @return bool - */ public function canBePartiallyRefunded(): bool { return $this->canBeRefunded(); @@ -555,13 +539,11 @@ public function canBePartiallyRefunded(): bool /** * Get the amount that is already refunded - * - * @return float */ public function getAmountRefunded(): float { if ($this->amountRefunded) { - return (float)$this->amountRefunded->value; + return (float) $this->amountRefunded->value; } return 0.0; @@ -571,13 +553,11 @@ public function getAmountRefunded(): float * Get the remaining amount that can be refunded. For some payment methods this * amount can be higher than the payment amount. This is possible to reimburse * the costs for a return shipment to your customer for example. - * - * @return float */ public function getAmountRemaining(): float { if ($this->amountRemaining) { - return (float)$this->amountRemaining->value; + return (float) $this->amountRemaining->value; } return 0.0; @@ -586,13 +566,11 @@ public function getAmountRemaining(): float /** * Get the total amount that was charged back for this payment. Only available when the * total charged back amount is not zero. - * - * @return float */ public function getAmountChargedBack(): float { if ($this->amountChargedBack) { - return (float)$this->amountChargedBack->value; + return (float) $this->amountChargedBack->value; } return 0.0; @@ -600,8 +578,6 @@ public function getAmountChargedBack(): float /** * Does the payment have split payments - * - * @return bool */ public function hasSplitPayments(): bool { @@ -611,51 +587,39 @@ public function hasSplitPayments(): bool /** * Retrieves all refunds associated with this payment * - * @return RefundCollection * @throws ApiException */ public function refunds(): RefundCollection { if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->client); + return new RefundCollection($this->connector); } - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_GET, - $this->_links->refunds->href - )->decode(); - - /** @var RefundCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->refunds, - Refund::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->refunds->href, + RefundCollection::class + )); } /** - * @param string $refundId - * @param array $parameters + * @param string $refundId * - * @return Refund * @throws ApiException */ public function getRefund($refundId, array $parameters = []): Refund { - return $this->client->paymentRefunds->getFor($this, $refundId, $this->withPresetOptions($parameters)); + return $this->connector->paymentRefunds->getFor($this, $refundId, $this->withPresetOptions($parameters)); } /** - * @param array $parameters - * - * @return RefundCollection * @throws ApiException */ public function listRefunds(array $parameters = []): RefundCollection { return $this - ->client + ->connector ->paymentRefunds ->listFor( $this, @@ -666,39 +630,30 @@ public function listRefunds(array $parameters = []): RefundCollection /** * Retrieves all captures associated with this payment * - * @return CaptureCollection * @throws ApiException */ public function captures(): CaptureCollection { if (! isset($this->_links->captures->href)) { - return new CaptureCollection($this->client); + return new CaptureCollection($this->connector); } - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_GET, - $this->_links->captures->href - )->decode(); - - /** @var CaptureCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->captures, - Capture::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->captures->href, + CaptureCollection::class + )); } /** - * @param string $captureId - * @param array $parameters + * @param string $captureId * - * @return Capture * @throws ApiException */ public function getCapture($captureId, array $parameters = []): Capture { - return $this->client->paymentCaptures->getFor( + return $this->connector->paymentCaptures->getFor( $this, $captureId, $this->withPresetOptions($parameters) @@ -708,41 +663,32 @@ public function getCapture($captureId, array $parameters = []): Capture /** * Retrieves all chargebacks associated with this payment * - * @return ChargebackCollection * @throws ApiException */ public function chargebacks(): ChargebackCollection { if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->client); + return new ChargebackCollection($this->connector); } - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_GET, - $this->_links->chargebacks->href - )->decode(); - - /** @var ChargebackCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->chargebacks, - Chargeback::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->chargebacks->href, + ChargebackCollection::class + )); } /** * Retrieves a specific chargeback for this payment. * - * @param string $chargebackId - * @param array $parameters + * @param string $chargebackId * - * @return Chargeback * @throws ApiException */ public function getChargeback($chargebackId, array $parameters = []): Chargeback { - return $this->client->paymentChargebacks->getFor( + return $this->connector->paymentChargebacks->getFor( $this, $chargebackId, $this->withPresetOptions($parameters) @@ -752,35 +698,33 @@ public function getChargeback($chargebackId, array $parameters = []): Chargeback /** * Issue a refund for this payment. * - * @param array $data + * @param array $data * - * @return \Mollie\Api\Resources\Refund * @throws ApiException */ public function refund($data): Refund { - return $this->client->paymentRefunds->createFor($this, $data); + return $this->connector->paymentRefunds->createFor($this, $data); } /** - * @return Payment * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?Payment { $body = [ - "description" => $this->description, - "cancelUrl" => $this->cancelUrl, - "redirectUrl" => $this->redirectUrl, - "webhookUrl" => $this->webhookUrl, - "metadata" => $this->metadata, - "restrictPaymentMethodsToCountry" => $this->restrictPaymentMethodsToCountry, - "locale" => $this->locale, - "dueDate" => $this->dueDate, + 'description' => $this->description, + 'cancelUrl' => $this->cancelUrl, + 'redirectUrl' => $this->redirectUrl, + 'webhookUrl' => $this->webhookUrl, + 'metadata' => $this->metadata, + 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, + 'locale' => $this->locale, + 'dueDate' => $this->dueDate, ]; /** @var null|Payment */ - return $this->client->payments->update( + return $this->connector->payments->update( $this->id, $this->withPresetOptions($body) ); @@ -789,13 +733,11 @@ public function update(): ?Payment /** * The total amount that is already captured for this payment. Only available * when this payment supports captures. - * - * @return float */ public function getAmountCaptured(): float { if ($this->amountCaptured) { - return (float)$this->amountCaptured->value; + return (float) $this->amountCaptured->value; } return 0.0; @@ -803,13 +745,11 @@ public function getAmountCaptured(): float /** * The amount that has been settled. - * - * @return float */ public function getSettlementAmount(): float { if ($this->settlementAmount) { - return (float)$this->settlementAmount->value; + return (float) $this->settlementAmount->value; } return 0.0; @@ -818,13 +758,11 @@ public function getSettlementAmount(): float /** * The total amount that is already captured for this payment. Only available * when this payment supports captures. - * - * @return float */ public function getApplicationFeeAmount(): float { if ($this->applicationFee) { - return (float)$this->applicationFee->amount->value; + return (float) $this->applicationFee->amount->value; } return 0.0; diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index e63d2aa27..c35a6df6d 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -23,6 +23,7 @@ class PaymentLink extends BaseResource * The profile ID this payment link belongs to. * * @example pfl_QkEhN94Ba + * * @var string */ public $profileId; @@ -31,6 +32,7 @@ class PaymentLink extends BaseResource * UTC datetime the payment link was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $createdAt; @@ -39,6 +41,7 @@ class PaymentLink extends BaseResource * UTC datetime the payment was paid in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $paidAt; @@ -55,6 +58,7 @@ class PaymentLink extends BaseResource * UTC datetime the payment link was updated in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $updatedAt; @@ -63,6 +67,7 @@ class PaymentLink extends BaseResource * UTC datetime - the expiry date of the payment link in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $expiresAt; @@ -103,8 +108,6 @@ class PaymentLink extends BaseResource /** * Is this payment paid for? - * - * @return bool */ public function isPaid(): bool { @@ -113,8 +116,6 @@ public function isPaid(): bool /** * Get the checkout URL where the customer can complete the payment. - * - * @return string|null */ public function getCheckoutUrl(): ?string { @@ -128,75 +129,58 @@ public function getCheckoutUrl(): ?string /** * Persist the current local Payment Link state to the Mollie API. * - * @return null|PaymentLink * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?PaymentLink { - $body = $this->withPresetOptions([ + $body = $this->withTestmode([ 'description' => $this->description, 'archived' => $this->archived, ]); - return $this->client->paymentLinks->update($this->id, $body); + return $this->connector->paymentLinks->update($this->id, $body); } /** * Archive this Payment Link. * * @return \Mollie\Api\Resources\PaymentLink + * * @throws \Mollie\Api\Exceptions\ApiException */ public function archive() { - $data = $this->withPresetOptions([ + $data = $this->withTestmode([ 'archived' => true, ]); - return $this->client->paymentLinks->update($this->id, $data); + return $this->connector->paymentLinks->update($this->id, $data); } /** * Retrieve a paginated list of payments associated with this payment link. * - * @param string|null $from - * @param int|null $limit - * @param array $filters * @return mixed|\Mollie\Api\Resources\BaseCollection */ - public function payments(string $from = null, int $limit = null, array $filters = []) + public function payments(?string $from = null, ?int $limit = null, array $filters = []) { - return $this->client->paymentLinkPayments->pageFor( + return $this->connector->paymentLinkPayments->pageFor( $this, $from, $limit, - $this->withPresetOptions($filters) + $this->withTestmode($filters) ); } - /** - * When accessed by oAuth we want to pass the testmode by default - * - * @return array - */ - private function getPresetOptions() - { - $options = []; - if ($this->client->usesOAuth()) { - $options["testmode"] = $this->mode === "test"; - } - - return $options; - } - /** * Apply the preset options. * - * @param array $options * @return array */ - private function withPresetOptions(array $options) + private function withTestmode(array $options) { - return array_merge($this->getPresetOptions(), $options); + return array_merge([ + 'testmode' => $this->mode === 'test', + ], $options); } } diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index e3dafe0ef..36b2866dc 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Resources; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\ProfileStatus; class Profile extends BaseResource @@ -45,6 +45,7 @@ class Profile extends BaseResource * This parameter is deprecated and will be removed in 2022. Please use the businessCategory parameter instead. * * @deprecated + * * @var int|null */ public $categoryCode; @@ -70,6 +71,7 @@ class Profile extends BaseResource * UTC datetime the profile was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -79,175 +81,135 @@ class Profile extends BaseResource */ public $_links; - /** - * @return bool - */ public function isUnverified(): bool { return $this->status == ProfileStatus::UNVERIFIED; } - /** - * @return bool - */ public function isVerified(): bool { return $this->status == ProfileStatus::VERIFIED; } - /** - * @return bool - */ public function isBlocked(): bool { return $this->status == ProfileStatus::BLOCKED; } /** - * @return null|Profile * @throws ApiException */ public function update(): ?Profile { $body = [ - "name" => $this->name, - "website" => $this->website, - "email" => $this->email, - "phone" => $this->phone, - "businessCategory" => $this->businessCategory, - "mode" => $this->mode, + 'name' => $this->name, + 'website' => $this->website, + 'email' => $this->email, + 'phone' => $this->phone, + 'businessCategory' => $this->businessCategory, + 'mode' => $this->mode, ]; - return $this->client->profiles->update($this->id, $body); + return $this->connector->profiles->update($this->id, $body); } /** * Retrieves all chargebacks associated with this profile * - * @return ChargebackCollection * @throws ApiException */ public function chargebacks(): ChargebackCollection { if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->client); + return new ChargebackCollection($this->connector); } - $result = $this - ->client - ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href) - ->decode(); - - /** @var ChargebackCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->chargebacks, - Chargeback::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->chargebacks->href, + ChargebackCollection::class + )); } /** * Retrieves all methods activated on this profile * - * @return MethodCollection * @throws ApiException */ public function methods(): MethodCollection { if (! isset($this->_links->methods->href)) { - return new MethodCollection($this->client); + return new MethodCollection($this->connector); } - $result = $this - ->client - ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->methods->href) - ->decode(); - - /** @var MethodCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->methods, - Method::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->methods->href, + MethodCollection::class + )); } /** * Enable a payment method for this profile. * - * @param string $methodId - * @param array $data - * @return Method + * @param string $methodId + * * @throws ApiException */ public function enableMethod($methodId, array $data = []): Method { - return $this->client->profileMethods->createFor($this, $methodId, $data); + return $this->connector->profileMethods->createFor($this, $methodId, $data); } /** * Disable a payment method for this profile. * - * @param string $methodId - * @param array $data - * @return Method + * @param string $methodId + * * @throws ApiException */ public function disableMethod($methodId, array $data = []): ?Method { - return $this->client->profileMethods->deleteFor($this, $methodId, $data); + return $this->connector->profileMethods->deleteFor($this, $methodId, $data); } /** * Retrieves all payments associated with this profile * - * @return PaymentCollection * @throws ApiException */ public function payments(): PaymentCollection { if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->client); + return new PaymentCollection($this->connector); } - $result = $this - ->client - ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->payments->href) - ->decode(); - - /** @var PaymentCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->methods, - Method::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->payments->href, + PaymentCollection::class + )); } /** * Retrieves all refunds associated with this profile * - * @return RefundCollection * @throws ApiException */ public function refunds(): RefundCollection { if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->client); + return new RefundCollection($this->connector); } - $result = $this - ->client - ->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href) - ->decode(); - - /** @var RefundCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->refunds, - Refund::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->refunds->href, + RefundCollection::class + )); } } diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index fd8bee67c..a5eed1e15 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Resources; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicDeleteRequest; use Mollie\Api\Types\RefundStatus; class Refund extends BaseResource @@ -25,6 +25,7 @@ class Refund extends BaseResource * UTC datetime the payment was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -90,9 +91,6 @@ class Refund extends BaseResource */ public $metadata; - /** - * @return bool - */ public function canBeCanceled(): bool { return $this->isQueued() || $this->isPending(); @@ -100,8 +98,6 @@ public function canBeCanceled(): bool /** * Is this refund queued? - * - * @return bool */ public function isQueued(): bool { @@ -110,8 +106,6 @@ public function isQueued(): bool /** * Is this refund pending? - * - * @return bool */ public function isPending(): bool { @@ -120,8 +114,6 @@ public function isPending(): bool /** * Is this refund processing? - * - * @return bool */ public function isProcessing(): bool { @@ -130,8 +122,6 @@ public function isProcessing(): bool /** * Is this refund transferred to consumer? - * - * @return bool */ public function isTransferred(): bool { @@ -140,8 +130,6 @@ public function isTransferred(): bool /** * Is this refund failed? - * - * @return bool */ public function isFailed(): bool { @@ -150,8 +138,6 @@ public function isFailed(): bool /** * Is this refund canceled? - * - * @return bool */ public function isCanceled(): bool { @@ -161,14 +147,14 @@ public function isCanceled(): bool /** * Cancel the refund. * - * @return void * @throws \Mollie\Api\Exceptions\ApiException */ public function cancel(): void { - $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_DELETE, - $this->_links->self->href - ); + $this + ->connector + ->send(new DynamicDeleteRequest( + $this->_links->self->href + )); } } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 4fb290b40..b3fe0d57a 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -2,29 +2,25 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Contracts\Connector; use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Response; #[\AllowDynamicProperties] class ResourceFactory { /** * Create resource object from Api result - * - * @param MollieApiClient $client - * @param object $response - * @param string $resourceClass - * @return BaseResource */ - public static function createFromApiResult(MollieApiClient $client, object $response, string $resourceClass): BaseResource + public static function createFromApiResult(Connector $connector, ?Response $response, string $resourceClass): BaseResource { /** @var BaseResource $resource */ - $resource = new $resourceClass($client); + $resource = new $resourceClass($connector, $response); - foreach ($response as $property => $value) { + foreach ($response->json() as $property => $value) { $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) - ? self::parseEmbeddedResources($client, $resource, $value) + ? self::parseEmbeddedResources($connector, $resource, $value) : $value; } @@ -34,10 +30,7 @@ public static function createFromApiResult(MollieApiClient $client, object $resp /** * Check if the resource holds embedded resources * - * @param object $resource - * @param string $key - * @param array|\ArrayAccess $value - * @return bool + * @param array|\ArrayAccess $value */ private static function holdsEmbeddedResources(object $resource, string $key, $value): bool { @@ -48,33 +41,29 @@ private static function holdsEmbeddedResources(object $resource, string $key, $v /** * Parses embedded resources into their respective resource objects or collections. - * - * @param MollieApiClient $client - * @param object $resource - * @param object $embedded - * @return object */ - private static function parseEmbeddedResources(MollieApiClient $client, object $resource, object $embedded): object + private static function parseEmbeddedResources(Connector $connector, object $resource, object $embedded): object { - $result = new \stdClass(); + $result = new \stdClass; foreach ($embedded as $resourceKey => $resourceData) { $collectionOrResourceClass = $resource->getEmbeddedResourcesMap()[$resourceKey] ?? null; if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - "Resource " . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" + 'Resource '.get_class($resource)." does not have a mapping for embedded resource {$resourceKey}" ); } $result->{$resourceKey} = is_subclass_of($collectionOrResourceClass, BaseResource::class) ? self::createFromApiResult( - $client, + $connector, + null, $resourceData, $collectionOrResourceClass ) : self::createEmbeddedResourceCollection( - $client, + $connector, $collectionOrResourceClass, $resourceData ); @@ -84,99 +73,63 @@ private static function parseEmbeddedResources(MollieApiClient $client, object $ } /** - * @param MollieApiClient $client - * @param string $collectionClass - * @param array|\ArrayObject $data - * @return BaseCollection + * @param array|\ArrayObject $data */ private static function createEmbeddedResourceCollection( - MollieApiClient $client, + Connector $connector, string $collectionClass, $data ): BaseCollection { return self::instantiateBaseCollection( - $client, + $connector, $collectionClass, self::mapToResourceObjects( - $client, + $connector, $data, $collectionClass::getResourceClass() ), - null ); } /** - * @param MollieApiClient $client - * @param string $resourceClass - * @param null|array|\ArrayObject $data - * @param object|null $_links - * @param string|null $resourceCollectionClass - * @return BaseCollection + * @param null|array|\ArrayObject $data */ public static function createBaseResourceCollection( - MollieApiClient $client, + Connector $connector, string $resourceClass, $data = null, + ?Response $response = null, ?object $_links = null, ?string $resourceCollectionClass = null ): BaseCollection { return self::instantiateBaseCollection( - $client, + $connector, self::determineCollectionClass($resourceClass, $resourceCollectionClass), - self::mapToResourceObjects($client, $data ?? [], $resourceClass), - $_links - ); - } - - /** - * @param MollieApiClient $client - * @param array|\ArrayObject $data - * @param string $resourceClass - * @param null $_links - * @param null $resourceCollectionClass - * @return CursorCollection - */ - public static function createCursorResourceCollection( - MollieApiClient $client, - $data, - string $resourceClass, - ?object $_links = null, - ?string $resourceCollectionClass = null - ): CursorCollection { - /** @var CursorCollection */ - return self::createBaseResourceCollection( - $client, - $resourceClass, - $data, + self::mapToResourceObjects($connector, $data ?? [], $resourceClass, $response), $_links, - $resourceCollectionClass + $response ); } - /** - * @param MollieApiClient $client - * @param string $collectionClass - * @param array $items - * @param object|null $_links - * @return BaseCollection - */ - private static function instantiateBaseCollection(MollieApiClient $client, string $collectionClass, array $items, ?object $_links): BaseCollection - { - return new $collectionClass($client, $items, $_links); + private static function instantiateBaseCollection( + Connector $connector, + string $collectionClass, + array $items, + ?object $_links = null, + ?Response $response = null + ): BaseCollection { + return new $collectionClass($connector, $response, $items, $_links); } /** - * @param MollieApiClient $client - * @param array|\ArrayObject $data - * @param string $resourceClass - * @return array + * @param array|\ArrayObject $data */ - private static function mapToResourceObjects(MollieApiClient $client, $data, string $resourceClass): array + private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, ?Response $response = null): array { return array_map( fn ($item) => static::createFromApiResult( - $client, + $connector, + $response, $item, $resourceClass ), @@ -186,6 +139,6 @@ private static function mapToResourceObjects(MollieApiClient $client, $data, str private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string { - return $resourceCollectionClass ?: $resourceClass . 'Collection'; + return $resourceCollectionClass ?: $resourceClass.'Collection'; } } diff --git a/src/Resources/Settlement.php b/src/Resources/Settlement.php index 41a980aeb..e514f777c 100644 --- a/src/Resources/Settlement.php +++ b/src/Resources/Settlement.php @@ -25,6 +25,7 @@ class Settlement extends BaseResource * UTC datetime the payment was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -33,6 +34,7 @@ class Settlement extends BaseResource * The date on which the settlement was settled, in ISO 8601 format. When requesting the open settlement or next settlement the return value is null. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $settledAt; @@ -72,8 +74,6 @@ class Settlement extends BaseResource /** * Is this settlement still open? - * - * @return bool */ public function isOpen(): bool { @@ -82,8 +82,6 @@ public function isOpen(): bool /** * Is this settlement pending? - * - * @return bool */ public function isPending(): bool { @@ -92,8 +90,6 @@ public function isPending(): bool /** * Is this settlement paid out? - * - * @return bool */ public function isPaidout(): bool { @@ -102,8 +98,6 @@ public function isPaidout(): bool /** * Has this settlement failed? - * - * @return bool */ public function isFailed(): bool { @@ -113,14 +107,11 @@ public function isFailed(): bool /** * Retrieve the first page of payments associated with this settlement. * - * @param int|null $limit - * @param array $parameters - * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function payments(int $limit = null, array $parameters = []): PaymentCollection + public function payments(?int $limit = null, array $parameters = []): PaymentCollection { - return $this->client->settlementPayments->pageForId( + return $this->connector->settlementPayments->pageForId( $this->id, null, $limit, @@ -131,14 +122,11 @@ public function payments(int $limit = null, array $parameters = []): PaymentColl /** * Retrieve the first page of refunds associated with this settlement. * - * @param int|null $limit - * @param array $parameters - * @return RefundCollection * @throws ApiException */ - public function refunds(int $limit = null, array $parameters = []): RefundCollection + public function refunds(?int $limit = null, array $parameters = []): RefundCollection { - return $this->client->settlementRefunds->pageForId( + return $this->connector->settlementRefunds->pageForId( $this->id, null, $limit, @@ -149,14 +137,11 @@ public function refunds(int $limit = null, array $parameters = []): RefundCollec /** * Retrieve the first page of chargebacks associated with this settlement. * - * @param int|null $limit - * @param array $parameters - * @return ChargebackCollection * @throws ApiException */ - public function chargebacks(int $limit = null, array $parameters = []): ChargebackCollection + public function chargebacks(?int $limit = null, array $parameters = []): ChargebackCollection { - return $this->client->settlementChargebacks->pageForId( + return $this->connector->settlementChargebacks->pageForId( $this->id, null, $limit, @@ -167,14 +152,11 @@ public function chargebacks(int $limit = null, array $parameters = []): Chargeba /** * Retrieve the first page of cap associated with this settlement. * - * @param int|null $limit - * @param array $parameters - * @return CaptureCollection * @throws ApiException */ - public function captures(int $limit = null, array $parameters = []): CaptureCollection + public function captures(?int $limit = null, array $parameters = []): CaptureCollection { - return $this->client->settlementCaptures->pageForId( + return $this->connector->settlementCaptures->pageForId( $this->id, null, $limit, diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index 5e15ec1b5..602dd38c3 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -8,6 +8,7 @@ class Shipment extends BaseResource * The shipment’s unique identifier, * * @example shp_3wmsgCJN4U + * * @var string */ public $id; @@ -16,6 +17,7 @@ class Shipment extends BaseResource * Id of the order. * * @example ord_8wmqcHMN4U + * * @var string */ public $orderId; @@ -24,32 +26,34 @@ class Shipment extends BaseResource * UTC datetime the shipment was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $createdAt; /** * The order object lines contain the actual things the customer bought. + * * @var array|object[] */ public $lines; /** * An object containing tracking details for the shipment, if available. + * * @var \stdClass|null */ public $tracking; /** * An object with several URL objects relevant to the customer. Every URL object will contain an href and a type field. + * * @var \stdClass */ public $_links; /** * Does this shipment offer track and trace? - * - * @return bool */ public function hasTracking(): bool { @@ -58,8 +62,6 @@ public function hasTracking(): bool /** * Does this shipment offer a track and trace code? - * - * @return bool */ public function hasTrackingUrl(): bool { @@ -68,8 +70,6 @@ public function hasTrackingUrl(): bool /** * Retrieve the track and trace url. Returns null if there is no url available. - * - * @return string|null */ public function getTrackingUrl(): ?string { @@ -82,14 +82,12 @@ public function getTrackingUrl(): ?string /** * Get the line value objects - * - * @return OrderLineCollection */ public function lines(): OrderLineCollection { /** @var OrderLineCollection */ return ResourceFactory::createBaseResourceCollection( - $this->client, + $this->connector, OrderLine::class, $this->lines ); @@ -98,26 +96,24 @@ public function lines(): OrderLineCollection /** * Get the Order object for this shipment * - * @return Order * @throws \Mollie\Api\Exceptions\ApiException */ public function order(): Order { - return $this->client->orders->get($this->orderId); + return $this->connector->orders->get($this->orderId); } /** * Save changes made to this shipment. * - * @return null|Shipment * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?Shipment { $body = [ - "tracking" => $this->tracking, + 'tracking' => $this->tracking, ]; - return $this->client->shipments->update($this->orderId, $this->id, $body); + return $this->connector->shipments->update($this->orderId, $this->id, $body); } } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 5685a61e5..9410f98f9 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -2,7 +2,8 @@ namespace Mollie\Api\Resources; -use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Requests\DynamicDeleteRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\SubscriptionStatus; class Subscription extends BaseResource @@ -110,29 +111,26 @@ class Subscription extends BaseResource public $_links; /** - * @return null|Subscription * @throws \Mollie\Api\Exceptions\ApiException */ public function update(): ?Subscription { $body = [ - "amount" => $this->amount, - "times" => $this->times, - "startDate" => $this->startDate, - "webhookUrl" => $this->webhookUrl, - "description" => $this->description, - "mandateId" => $this->mandateId, - "metadata" => $this->metadata, - "interval" => $this->interval, + 'amount' => $this->amount, + 'times' => $this->times, + 'startDate' => $this->startDate, + 'webhookUrl' => $this->webhookUrl, + 'description' => $this->description, + 'mandateId' => $this->mandateId, + 'metadata' => $this->metadata, + 'interval' => $this->interval, ]; - return $this->client->subscriptions->update($this->customerId, $this->id, $body); + return $this->connector->subscriptions->update($this->customerId, $this->id, $body); } /** * Returns whether the Subscription is active or not. - * - * @return bool */ public function isActive(): bool { @@ -141,8 +139,6 @@ public function isActive(): bool /** * Returns whether the Subscription is pending or not. - * - * @return bool */ public function isPending(): bool { @@ -151,8 +147,6 @@ public function isPending(): bool /** * Returns whether the Subscription is canceled or not. - * - * @return bool */ public function isCanceled(): bool { @@ -161,8 +155,6 @@ public function isCanceled(): bool /** * Returns whether the Subscription is suspended or not. - * - * @return bool */ public function isSuspended(): bool { @@ -171,8 +163,6 @@ public function isSuspended(): bool /** * Returns whether the Subscription is completed or not. - * - * @return bool */ public function isCompleted(): bool { @@ -182,7 +172,6 @@ public function isCompleted(): bool /** * Cancels this subscription * - * @return null|Subscription * @throws \Mollie\Api\Exceptions\ApiException */ public function cancel(): ?Subscription @@ -191,50 +180,31 @@ public function cancel(): ?Subscription return $this; } - $body = null; - if ($this->client->usesOAuth()) { - $body = json_encode([ - "testmode" => $this->mode === "test" ? true : false, - ]); - } - - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_DELETE, - $this->_links->self->href, - $body - ); - - if ($result->isEmpty()) { - return null; - } - - /** @var Subscription */ - return ResourceFactory::createFromApiResult($this->client, $result->decode(), Subscription::class); + return $this + ->connector + ->send(new DynamicDeleteRequest( + $this->_links->self->href, + self::class, + $this->mode === 'test' + )); } /** * Get subscription payments * - * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ public function payments(): PaymentCollection { if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->client); + return new PaymentCollection($this->connector); } - $result = $this->client->performHttpCallToFullUrl( - MollieApiClient::HTTP_GET, - $this->_links->payments->href - )->decode(); - - /** @var PaymentCollection */ - return ResourceFactory::createCursorResourceCollection( - $this->client, - $result->_embedded->payments, - Payment::class, - $result->_links - ); + return $this + ->connector + ->send(new DynamicGetRequest( + $this->_links->payments->href, + PaymentCollection::class + )); } } diff --git a/src/Rules/Id.php b/src/Rules/Id.php new file mode 100644 index 000000000..1ebc4e412 --- /dev/null +++ b/src/Rules/Id.php @@ -0,0 +1,42 @@ +prefix = $prefix; + } + + public static function startsWithPrefix(string $prefix): self + { + return new self($prefix); + } + + public function validate($id, $context, Closure $fail): void + { + if (! $context instanceof Request) { + $fail('The Id rule can only be used on a Request instance.'); + } + + if (strpos($id, $this->prefix) !== 0) { + $resourceType = $this->getResourceType($context); + + $fail("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '".$this->prefix."'."); + } + } + + public function getResourceType(Request $request): string + { + $classBasename = basename(str_replace('\\', '/', $request->getTargetResourceClass())); + + return strtolower($classBasename); + } +} diff --git a/src/Rules/Included.php b/src/Rules/Included.php new file mode 100644 index 000000000..f54403884 --- /dev/null +++ b/src/Rules/Included.php @@ -0,0 +1,48 @@ +allowed = $allowed; + } + + /** + * @param string|array $classOrArray + */ + public static function in($classOrArray): self + { + if (is_array($classOrArray)) { + return new self($classOrArray); + } + + $reflection = new ReflectionClass($classOrArray); + + return new self($reflection->getConstants()); + } + + public function validate($value, $context, Closure $fail): void + { + $values = explode(',', $value); + + foreach ($values as $value) { + if (! in_array($value, $this->allowed)) { + $fail("Invalid include: '{$value}'. Allowed are: ".implode(', ', $this->allowed).'.'); + } + } + } +} diff --git a/src/Rules/Matches.php b/src/Rules/Matches.php new file mode 100644 index 000000000..b12f37b39 --- /dev/null +++ b/src/Rules/Matches.php @@ -0,0 +1,25 @@ +pattern, $value)) { + $fail("The value {$value} does not match the pattern: {$this->pattern}"); + } + } +} diff --git a/src/Rules/Max.php b/src/Rules/Max.php new file mode 100644 index 000000000..035451d6f --- /dev/null +++ b/src/Rules/Max.php @@ -0,0 +1,33 @@ +max = $max; + } + + public static function value(int $max): self + { + return new self($max); + } + + public function validate($value, $context, Closure $fail): void + { + $length = is_numeric($value) ? $value : strlen($value); + + if ($length > $this->max) { + $fail("The value must not exceed {$this->max}."); + } + } +} diff --git a/src/Rules/Min.php b/src/Rules/Min.php new file mode 100644 index 000000000..1974453f5 --- /dev/null +++ b/src/Rules/Min.php @@ -0,0 +1,33 @@ +min = $min; + } + + public static function value(int $min): self + { + return new self($min); + } + + public function validate($value, $context, Closure $fail): void + { + $length = is_numeric($value) ? $value : strlen($value); + + if ($length < $this->min) { + $fail("The value must be at least {$this->min}."); + } + } +} diff --git a/src/Traits/ComposableFromArray.php b/src/Traits/ComposableFromArray.php new file mode 100644 index 000000000..1d379aa87 --- /dev/null +++ b/src/Traits/ComposableFromArray.php @@ -0,0 +1,11 @@ +authenticator = new ApiKeyAuthenticator($apiKey); + + return $this; + } + + /** + * @param string $accessToken OAuth access token, starting with 'access_' + * + * @throws ApiException + */ + public function setAccessToken(string $accessToken): self + { + $this->authenticator = new AccessTokenAuthenticator($accessToken); + + return $this; + } + + public function getAuthenticator(): ?Authenticator + { + return $this->authenticator; + } +} diff --git a/src/HandlesDebugging.php b/src/Traits/HandlesDebugging.php similarity index 90% rename from src/HandlesDebugging.php rename to src/Traits/HandlesDebugging.php index ec4933896..f30e98e43 100644 --- a/src/HandlesDebugging.php +++ b/src/Traits/HandlesDebugging.php @@ -1,6 +1,6 @@ httpClient instanceof SupportsDebuggingContract) { throw new HttpAdapterDoesNotSupportDebuggingException( - "Debugging is not supported by " . get_class($this->httpClient) . "." + 'Debugging is not supported by '.get_class($this->httpClient).'.' ); } diff --git a/src/HandlesIdempotency.php b/src/Traits/HandlesIdempotency.php similarity index 51% rename from src/HandlesIdempotency.php rename to src/Traits/HandlesIdempotency.php index 8e36ca3d2..bf26aa2f6 100644 --- a/src/HandlesIdempotency.php +++ b/src/Traits/HandlesIdempotency.php @@ -1,43 +1,29 @@ idempotencyKeyGenerator = $generator ? $generator : new DefaultIdempotencyKeyGenerator(); - } + protected ?string $idempotencyKey = null; /** * Set the idempotency key used on the next request. The idempotency key is a unique string ensuring a request to a * mutating Mollie endpoint is processed only once. The idempotency key resets to null after each request. Using * the setIdempotencyKey method supersedes the IdempotencyKeyGenerator. * - * @param $key * @return $this */ public function setIdempotencyKey($key): self @@ -51,14 +37,17 @@ public function setIdempotencyKey($key): self * Retrieve the idempotency key. The idempotency key is a unique string ensuring a request to a * mutating Mollie endpoint is processed only once. Note that the idempotency key gets reset to null after each * request. - * - * @return string|null */ public function getIdempotencyKey(): ?string { return $this->idempotencyKey; } + public function getIdempotencyKeyGenerator(): ?IdempotencyKeyGeneratorContract + { + return $this->idempotencyKeyGenerator; + } + /** * Reset the idempotency key. Note that the idempotency key automatically resets to null after each request. * @@ -72,8 +61,8 @@ public function resetIdempotencyKey(): self } /** - * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator - * @return \Mollie\Api\MollieApiClient + * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator + * @return \Mollie\Api\Contracts\Connector */ public function setIdempotencyKeyGenerator($generator): self { @@ -83,7 +72,7 @@ public function setIdempotencyKeyGenerator($generator): self } /** - * @return \Mollie\Api\MollieApiClient + * @return \Mollie\Api\Contracts\Connector */ public function clearIdempotencyKeyGenerator(): self { @@ -91,36 +80,4 @@ public function clearIdempotencyKeyGenerator(): self return $this; } - - /** - * Conditionally apply the idempotency key to the request headers - * - * @param array $headers - * @param string $httpMethod - * @return array - */ - protected function applyIdempotencyKey(array $headers, string $httpMethod) - { - if (! in_array($httpMethod, [MollieApiClient::HTTP_POST, MollieApiClient::HTTP_PATCH, MollieApiClient::HTTP_DELETE])) { - unset($headers['Idempotency-Key']); - - return $headers; - } - - if ($this->idempotencyKey) { - $headers['Idempotency-Key'] = $this->idempotencyKey; - - return $headers; - } - - if ($this->idempotencyKeyGenerator) { - $headers['Idempotency-Key'] = $this->idempotencyKeyGenerator->generate(); - - return $headers; - } - - unset($headers['Idempotency-Key']); - - return $headers; - } } diff --git a/src/Http/HandlesResourceBuilding.php b/src/Traits/HandlesResourceCreation.php similarity index 69% rename from src/Http/HandlesResourceBuilding.php rename to src/Traits/HandlesResourceCreation.php index 046b9b252..4bce5eabc 100644 --- a/src/Http/HandlesResourceBuilding.php +++ b/src/Traits/HandlesResourceCreation.php @@ -1,35 +1,33 @@ decode(); $targetResourceClass = $request->getTargetResourceClass(); if ($this->isCollectionTarget($targetResourceClass)) { - $collection = $this->buildResultCollection($decodedResponse, $targetResourceClass); + $collection = $this->buildResultCollection($response, $targetResourceClass); return $this->unwrapIterator($request, $collection); } if ($this->isResourceTarget($targetResourceClass)) { - return ResourceFactory::createFromApiResult($this->client, $decodedResponse, $targetResourceClass); + return ResourceFactory::createFromApiResult($this, $response, $targetResourceClass); } - return null; + return $response; } private function unwrapIterator(Request $request, BaseCollection $collection): BaseCollection|LazyCollection @@ -42,12 +40,15 @@ private function unwrapIterator(Request $request, BaseCollection $collection): B return $collection; } - private function buildResultCollection(object $result, string $targetCollectionClass): BaseCollection + private function buildResultCollection(Response $response, string $targetCollectionClass): BaseCollection { + $result = $response->json(); + return ResourceFactory::createBaseResourceCollection( - $this->client, + $this, ($targetCollectionClass)::getResourceClass(), $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, + $response, $result->_links, $targetCollectionClass ); diff --git a/src/Traits/HandlesTestmode.php b/src/Traits/HandlesTestmode.php new file mode 100644 index 000000000..40127f6a1 --- /dev/null +++ b/src/Traits/HandlesTestmode.php @@ -0,0 +1,22 @@ +testmode = true; + + return $this; + } + + public function disableTestmode(): static + { + $this->testmode = false; + + return $this; + } +} diff --git a/src/Traits/HandlesVersions.php b/src/Traits/HandlesVersions.php new file mode 100644 index 000000000..7f2c15a9b --- /dev/null +++ b/src/Traits/HandlesVersions.php @@ -0,0 +1,38 @@ +addVersionString('Mollie/'.MollieApiClient::CLIENT_VERSION); + $this->addVersionString('PHP/'.phpversion()); + + if ($clientVersion = $this->httpClient->version()) { + $this->addVersionString($clientVersion); + } + } + + /** + * @param string $versionString + */ + public function addVersionString($versionString): self + { + $this->versionStrings[] = str_replace([' ', "\t", "\n", "\r"], '-', $versionString); + + return $this; + } + + public function getVersionStrings(): array + { + return $this->versionStrings; + } +} diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php new file mode 100644 index 000000000..a1dd65fa7 --- /dev/null +++ b/src/Traits/HasDefaultFactories.php @@ -0,0 +1,27 @@ + BalanceEndpointCollection::class, + 'balanceReports' => BalanceEndpointCollection::class, + 'balanceTransactions' => BalanceTransactionCollection::class, + 'chargebacks' => ChargebackEndpointCollection::class, + 'clients' => ClientEndpointCollection::class, + 'clientLinks' => ClientLinkEndpointCollection::class, + 'payments' => PaymentEndpointCollection::class, + 'paymentRefunds' => PaymentRefundEndpointCollection::class, + + // old + 'customerPayments' => CustomerPaymentsEndpoint::class, + 'customers' => CustomerEndpoint::class, + 'invoices' => InvoiceEndpoint::class, + 'mandates' => MandateEndpoint::class, + 'methods' => MethodEndpoint::class, + 'methodIssuers' => MethodIssuerEndpoint::class, + 'onboarding' => OnboardingEndpoint::class, + 'orderLines' => OrderLineEndpoint::class, + 'orderPayments' => OrderPaymentEndpoint::class, + 'orderRefunds' => OrderRefundEndpoint::class, + 'orders' => OrderEndpoint::class, + 'organizationPartners' => OrganizationPartnerEndpoint::class, + 'organizations' => OrganizationEndpoint::class, + 'paymentCaptures' => PaymentCaptureEndpoint::class, + 'paymentChargebacks' => PaymentChargebackEndpoint::class, + 'paymentLinks' => PaymentLinkEndpoint::class, + 'paymentLinkPayments' => PaymentLinkPaymentEndpoint::class, + 'paymentRoutes' => PaymentRouteEndpoint::class, + 'permissions' => PermissionEndpoint::class, + 'profiles' => ProfileEndpoint::class, + 'profileMethods' => ProfileMethodEndpoint::class, + 'refunds' => RefundEndpoint::class, + 'settlementCaptures' => SettlementCaptureEndpoint::class, + 'settlementChargebacks' => SettlementChargebackEndpoint::class, + 'settlementPayments' => SettlementPaymentEndpoint::class, + 'settlementRefunds' => SettlementRefundEndpoint::class, + 'shipments' => OrderShipmentEndpoint::class, + 'settlements' => SettlementsEndpoint::class, + 'subscriptions' => SubscriptionEndpoint::class, + 'subscriptionPayments' => SubscriptionPaymentEndpoint::class, + 'terminals' => TerminalEndpoint::class, + 'wallets' => WalletEndpoint::class, + ]; + + foreach ($endpointClasses as $name => $class) { + static::$endpoints[$name] = $class; + } + } + + /** + * @param string $url + */ + public function setApiEndpoint($url): self + { + $this->apiEndpoint = rtrim(trim($url), '/'); + + return $this; + } + + public function getApiEndpoint(): string + { + return $this->apiEndpoint; + } + + /** + * Magic getter to access the endpoints. + * + * + * @return mixed + * + * @throws \Exception + */ + public function __get(string $name) + { + if (isset(static::$endpoints[$name])) { + return new static::$endpoints[$name]($this); + } + + throw new \Exception("Undefined endpoint: $name"); + } +} diff --git a/src/Traits/HasHeaders.php b/src/Traits/HasHeaders.php new file mode 100644 index 000000000..b57c0249d --- /dev/null +++ b/src/Traits/HasHeaders.php @@ -0,0 +1,20 @@ +headers ??= new ArrayStore($this->defaultHeaders()); + } + + protected function defaultHeaders(): array + { + return []; + } +} diff --git a/src/Traits/HasJsonPayload.php b/src/Traits/HasJsonPayload.php new file mode 100644 index 000000000..63281a5c9 --- /dev/null +++ b/src/Traits/HasJsonPayload.php @@ -0,0 +1,20 @@ +body ??= new JsonBodyRepository($this->defaultPayload()); + } + + protected function defaultPayload(): array + { + return []; + } +} diff --git a/src/Traits/HasMiddleware.php b/src/Traits/HasMiddleware.php new file mode 100644 index 000000000..53bd5cf5d --- /dev/null +++ b/src/Traits/HasMiddleware.php @@ -0,0 +1,15 @@ +middleware ??= new MiddlewareHandlers; + } +} diff --git a/src/Traits/HasQuery.php b/src/Traits/HasQuery.php new file mode 100644 index 000000000..5ed36c53b --- /dev/null +++ b/src/Traits/HasQuery.php @@ -0,0 +1,20 @@ +queryStore ??= new ArrayStore($this->defaultQuery()); + } + + protected function defaultQuery(): array + { + return []; + } +} diff --git a/src/Traits/HasRequestProperties.php b/src/Traits/HasRequestProperties.php new file mode 100644 index 000000000..8e50e688b --- /dev/null +++ b/src/Traits/HasRequestProperties.php @@ -0,0 +1,9 @@ +getShortName(); + + if (method_exists($this, $method)) { + $this->{$method}(); + } + } + } +} diff --git a/src/InteractsWithResource.php b/src/Traits/InteractsWithResource.php similarity index 88% rename from src/InteractsWithResource.php rename to src/Traits/InteractsWithResource.php index b6a5b5198..a763d2d52 100644 --- a/src/InteractsWithResource.php +++ b/src/Traits/InteractsWithResource.php @@ -1,13 +1,11 @@ debug = true; @@ -32,7 +32,7 @@ public function enableDebugging(): MollieHttpAdapterContract * * @return $this */ - public function disableDebugging(): MollieHttpAdapterContract + public function disableDebugging(): HttpAdapterContract { $this->debug = false; @@ -43,8 +43,6 @@ public function disableDebugging(): MollieHttpAdapterContract * Whether debugging is enabled. If debugging mode is enabled, the request will * be included in the ApiException. By default, debugging is disabled to prevent * sensitive request data from leaking into exception logs. - * - * @return bool */ public function debuggingIsActive(): bool { diff --git a/src/Http/Requests/IsIteratableRequest.php b/src/Traits/IsIteratableRequest.php similarity index 94% rename from src/Http/Requests/IsIteratableRequest.php rename to src/Traits/IsIteratableRequest.php index e428021ba..6a1f09c5e 100644 --- a/src/Http/Requests/IsIteratableRequest.php +++ b/src/Traits/IsIteratableRequest.php @@ -1,6 +1,6 @@ factoryCollection; + + $request = $factories->requestFactory->createRequest( + method: $this->method(), + uri: $this->getUri(), + ); + + foreach ($this->headers()->all() as $headerName => $headerValue) { + $request = $request->withHeader($headerName, $headerValue); + } + + if ($this->body() instanceof BodyRepository) { + $request = $request->withBody($this->body()->toStream($factories->streamFactory)); + } + + return $request; + } + + public function getUri(): UriInterface + { + $uri = $this + ->factoryCollection + ->uriFactory + ->createUri($this->url()); + + $existingQuery = Url::parseQuery($uri->getQuery()); + + return $uri->withQuery( + http_build_query(array_merge($existingQuery, $this->query()->all())) + ); + } + + /** + * Get the factory collection + */ + public function getFactoryCollection(): Factories + { + return $this->factoryCollection; + } +} diff --git a/src/Traits/ResolvesUri.php b/src/Traits/ResolvesUri.php new file mode 100644 index 000000000..01427b73b --- /dev/null +++ b/src/Traits/ResolvesUri.php @@ -0,0 +1,44 @@ +resolveResourcePath(); + + $query = $this->buildQuery($request->query()); + + return $path.$query; + } + + private function buildQuery(ArrayRepository $query): string + { + if ($query->isEmpty()) { + return ''; + } + + $query = $this->transformQuery($query->all()); + + return '?'.http_build_query($query, '', '&'); + } + + private function transformQuery(array $query): array + { + return array_map(function ($value) { + if ($value === true) { + return 'true'; + } + + if ($value === false) { + return 'false'; + } + + return $value; + }, $query); + } +} diff --git a/src/Traits/ResolvesValues.php b/src/Traits/ResolvesValues.php new file mode 100644 index 000000000..87ba78821 --- /dev/null +++ b/src/Traits/ResolvesValues.php @@ -0,0 +1,28 @@ +map(function ($value) { + if ($value instanceof DataResolver) { + return $value->resolve(); + } + + if ($value instanceof DataProvider) { + return $value->data(); + } + + return $value; + }) + ->filter() + ->toArray(); + } +} diff --git a/src/Traits/SendsRequests.php b/src/Traits/SendsRequests.php new file mode 100644 index 000000000..d80c64483 --- /dev/null +++ b/src/Traits/SendsRequests.php @@ -0,0 +1,30 @@ +executeRequestHandlers(); + + $response = $this->httpClient->sendRequest($pendingRequest); + + // Execute response middleware + $response = $pendingRequest->executeResponseHandlers($response); + + return $this->createResource($request, $response); + } +} diff --git a/src/Traits/ValidatesProperties.php b/src/Traits/ValidatesProperties.php new file mode 100644 index 000000000..28a16ddf6 --- /dev/null +++ b/src/Traits/ValidatesProperties.php @@ -0,0 +1,104 @@ +rules(); + + [$validatableProperties, $rulesWithValues] = $this->getValidatableAndRules($rules); + + // Perform validation using the returned arrays + foreach ($validatableProperties as $property) { + $property->validate(); + } + + foreach ($rulesWithValues as [$rule, $value]) { + $rule->validate($this, $value); + } + } + + private function getValidatableAndRules(array $rules = []): array + { + $validatableProperties = []; + $rulesWithValues = []; + + /** @var ReflectionProperty $property */ + foreach (Helpers::getProperties($this) as $property) { + if ($property->isStatic() || ! $property->isInitialized($this)) { + continue; + } + + $value = $this->extractValue($property); + + if ($value === null) { + continue; + } + + if ($value instanceof Validatable) { + $validatableProperties[] = $value; + } elseif (array_key_exists($property->getName(), $rules)) { + $rulesWithValues[] = [$rules[$property->getName()], $value]; + } + } + + return [$validatableProperties, $rulesWithValues]; + } + + private function validateProperties(array $rules = []): void + { + /** @var ReflectionProperty $property */ + foreach (Helpers::getProperties($this) as $property) { + if ($property->isStatic() || ! $property->isInitialized($this)) { + continue; + } + + $value = $this->extractValue($property); + + if ($value === null) { + continue; + } + + if ($value instanceof Validatable) { + $value->validate(); + } elseif (array_key_exists($property->getName(), $rules)) { + $rules[$property->getName()]->validate($this, $value); + } + } + } + + private function extractValue(ReflectionProperty $property): mixed + { + return $property->getValue($this); + } + + private function validateQuery(array $rules = []): void + { + if (empty($rules)) { + return; + } + + $nonNullValues = array_filter($this->query()->all()); + + $queryToValidate = array_filter( + $nonNullValues, + fn ($_, $key) => array_key_exists($key, $rules), + ARRAY_FILTER_USE_BOTH + ); + + foreach ($queryToValidate as $property => $value) { + $rules[$property]->validate($this, $value); + } + } + + public function rules(): array + { + return []; + } +} diff --git a/src/Types/ClientQuery.php b/src/Types/ClientQuery.php new file mode 100644 index 000000000..68d3d1aa5 --- /dev/null +++ b/src/Types/ClientQuery.php @@ -0,0 +1,10 @@ +checker = $this->getMockBuilder(CompatibilityChecker::class) ->setMethods([ - "satisfiesPhpVersion", - "satisfiesJsonExtension", + 'satisfiesPhpVersion', + 'satisfiesJsonExtension', ]) ->getMock(); } @@ -26,11 +27,11 @@ public function testCheckCompatibilityThrowsExceptionOnPhpVersion() { $this->expectException(\Mollie\Api\Exceptions\IncompatiblePlatform::class); $this->checker->expects($this->once()) - ->method("satisfiesPhpVersion") + ->method('satisfiesPhpVersion') ->will($this->returnValue(false)); // Fail $this->checker->expects($this->never()) - ->method("satisfiesJsonExtension"); + ->method('satisfiesJsonExtension'); $this->checker->checkCompatibility(); } @@ -39,11 +40,11 @@ public function testCheckCompatibilityThrowsExceptionOnJsonExtension() { $this->expectException(\Mollie\Api\Exceptions\IncompatiblePlatform::class); $this->checker->expects($this->once()) - ->method("satisfiesPhpVersion") + ->method('satisfiesPhpVersion') ->will($this->returnValue(true)); $this->checker->expects($this->once()) - ->method("satisfiesJsonExtension") + ->method('satisfiesJsonExtension') ->will($this->returnValue(false)); // Fail $this->checker->checkCompatibility(); diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php new file mode 100644 index 000000000..8d473f4a6 --- /dev/null +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -0,0 +1,181 @@ + new MockResponse(200, 'balance-list'), + ]); + + /** @var BalanceCollection $balances */ + $balances = $client->balances->page(); + + $this->assertInstanceOf(BalanceCollection::class, $balances); + $this->assertEquals(2, $balances->count()); + $this->assertCount(2, $balances); + + $this->assertLinkObject( + 'https://docs.mollie.com/reference/v2/balances-api/list-balances', + 'text/html', + $balances->_links->documentation + ); + + $this->assertLinkObject( + 'https://api.mollie.com/v2/balances?limit=5', + 'application/hal+json', + $balances->_links->self + ); + + $this->assertLinkObject( + 'https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5', + 'application/hal+json', + $balances->_links->next + ); + + /** @var Balance $balanceA */ + $balanceA = $balances[0]; + + /** @var Balance $balanceB */ + $balanceB = $balances[1]; + + $this->assertBalance( + $balanceA, + 'bal_gVMhHKqSSRYJyPsuoPNFH', + '2019-01-10T12:06:28+00:00', + BalanceTransferFrequency::DAILY, + '40.00', + (object) [ + 'type' => 'bank-account', + 'beneficiaryName' => 'Jack Bauer', + 'bankAccount' => 'NL53INGB0654422370', + 'bankAccountId' => 'bnk_jrty3f', + ] + ); + $this->assertBalance( + $balanceB, + 'bal_gVMhHKqSSRYJyPsuoPABC', + '2019-01-10T10:23:41+00:00', + BalanceTransferFrequency::TWICE_A_MONTH, + '5.00', + (object) [ + 'type' => 'bank-account', + 'beneficiaryName' => 'Jack Bauer', + 'bankAccount' => 'NL97MOLL6351480700', + 'bankAccountId' => 'bnk_jrty3e', + ] + ); + } + + public function testIterateBalances() + { + $client = new MockClient([ + GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-balance-list'), + ]); + + foreach ($client->balances->iterator() as $balance) { + $this->assertInstanceOf(Balance::class, $balance); + } + } + + public function testGetBalance() + { + $client = new MockClient([ + GetBalanceRequest::class => new MockResponse(200, 'balance-get'), + ]); + + /** @var Balance $balance */ + $balance = $client->balances->get('bal_gVMhHKqSSRYJyPsuoPNFH'); + + $this->assertBalance( + $balance, + 'bal_gVMhHKqSSRYJyPsuoPNFH', + '2019-01-10T10:23:41+00:00', + BalanceTransferFrequency::TWICE_A_MONTH, + '5.00', + (object) [ + 'type' => 'bank-account', + 'beneficiaryName' => 'Jack Bauer', + 'bankAccount' => 'NL53INGB0654422370', + 'bankAccountId' => 'bnk_jrty3f', + ] + ); + } + + public function testGetPrimaryBalance() + { + $client = new MockClient([ + GetBalanceRequest::class => new MockResponse(200, 'balance-get'), + ]); + + /** @var Balance $balance */ + $balance = $client->balances->primary(); + + $this->assertBalance( + $balance, + 'bal_gVMhHKqSSRYJyPsuoPNFH', + '2019-01-10T10:23:41+00:00', + BalanceTransferFrequency::TWICE_A_MONTH, + '5.00', + (object) [ + 'type' => 'bank-account', + 'beneficiaryName' => 'Jack Bauer', + 'bankAccount' => 'NL53INGB0654422370', + 'bankAccountId' => 'bnk_jrty3f', + ] + ); + } + + /** + * @return void + */ + protected function assertBalance( + Balance $balance, + string $balanceId, + string $createdAt, + string $transferFrequency, + string $thresholdValue, + \stdClass $destination + ) { + $this->assertInstanceOf(Balance::class, $balance); + $this->assertEquals('balance', $balance->resource); + $this->assertEquals($balanceId, $balance->id); + + $this->assertEquals('live', $balance->mode); + $this->assertEquals($createdAt, $balance->createdAt); + $this->assertEquals('EUR', $balance->currency); + $this->assertAmountObject('0.00', 'EUR', $balance->availableAmount); + $this->assertAmountObject('0.00', 'EUR', $balance->incomingAmount); + $this->assertAmountObject('0.00', 'EUR', $balance->outgoingAmount); + $this->assertEquals($transferFrequency, $balance->transferFrequency); + $this->assertAmountObject($thresholdValue, 'EUR', $balance->transferThreshold); + $this->assertEquals('Mollie payout', $balance->transferReference); + $this->assertEquals($destination, $balance->transferDestination); + + $this->assertLinkObject( + "https://api.mollie.com/v2/balances/{$balanceId}", + 'application/hal+json', + $balance->_links->self + ); + } +} diff --git a/tests/Fixtures/MockClient.php b/tests/Fixtures/MockClient.php new file mode 100644 index 000000000..9d6e00ce5 --- /dev/null +++ b/tests/Fixtures/MockClient.php @@ -0,0 +1,18 @@ +httpClient = new MockMollieHttpAdapter($expectedResponses); + + $this->setApiKey('test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + } +} diff --git a/tests/Fixtures/MockResponse.php b/tests/Fixtures/MockResponse.php new file mode 100644 index 000000000..795ca4c75 --- /dev/null +++ b/tests/Fixtures/MockResponse.php @@ -0,0 +1,82 @@ +status = $status; + $this->headers = $headers; + $this->body = $body; + } + + public function createPsrResponse(): ResponseInterface + { + $psrResponse = $this + ->factories() + ->responseFactory + ->createResponse($this->status); + + $body = $this + ->factories() + ->streamFactory + ->createStream($this->body()); + + return $psrResponse->withBody($body); + } + + public function body(): string + { + if (empty($body = $this->body)) { + return ''; + } + + if ($this->isJson($body)) { + return $body; + } + + $path = Arr::join([ + __DIR__, + 'Responses', + $body.'.json', + ], DIRECTORY_SEPARATOR); + + return file_get_contents($path); + } + + public function assertResponseBodyEquals(ResponseInterface $response): void + { + $body = $response->getBody(); + $body->rewind(); + + Assert::assertEquals( + $body->getContents(), + $this->createPsrResponse()->getBody()->getContents(), + 'Response does not match' + ); + } + + private function isJson($string): bool + { + json_decode($string); + + return json_last_error() == JSON_ERROR_NONE; + } +} diff --git a/tests/Fixtures/Responses/balance-get.json b/tests/Fixtures/Responses/balance-get.json new file mode 100644 index 000000000..81d26f94b --- /dev/null +++ b/tests/Fixtures/Responses/balance-get.json @@ -0,0 +1,42 @@ +{ + "resource": "balance", + "id": "bal_gVMhHKqSSRYJyPsuoPNFH", + "mode": "live", + "createdAt": "2019-01-10T10:23:41+00:00", + "currency": "EUR", + "status": "active", + "availableAmount": { + "value": "0.00", + "currency": "EUR" + }, + "incomingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "outgoingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "transferFrequency": "twice-a-month", + "transferThreshold": { + "value": "5.00", + "currency": "EUR" + }, + "transferReference": "Mollie payout", + "transferDestination": { + "type": "bank-account", + "beneficiaryName": "Jack Bauer", + "bankAccount": "NL53INGB0654422370", + "bankAccountId": "bnk_jrty3f" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/get-balance", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/balance-list.json b/tests/Fixtures/Responses/balance-list.json new file mode 100644 index 000000000..a636e2f9e --- /dev/null +++ b/tests/Fixtures/Responses/balance-list.json @@ -0,0 +1,98 @@ +{ + "count": 2, + "_embedded": { + "balances": [ + { + "resource": "balance", + "id": "bal_gVMhHKqSSRYJyPsuoPNFH", + "mode": "live", + "createdAt": "2019-01-10T12:06:28+00:00", + "currency": "EUR", + "status": "active", + "availableAmount": { + "value": "0.00", + "currency": "EUR" + }, + "incomingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "outgoingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "transferFrequency": "daily", + "transferThreshold": { + "value": "40.00", + "currency": "EUR" + }, + "transferReference": "Mollie payout", + "transferDestination": { + "type": "bank-account", + "beneficiaryName": "Jack Bauer", + "bankAccount": "NL53INGB0654422370", + "bankAccountId": "bnk_jrty3f" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", + "type": "application/hal+json" + } + } + }, + { + "resource": "balance", + "id": "bal_gVMhHKqSSRYJyPsuoPABC", + "mode": "live", + "createdAt": "2019-01-10T10:23:41+00:00", + "status": "active", + "currency": "EUR", + "availableAmount": { + "value": "0.00", + "currency": "EUR" + }, + "incomingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "outgoingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "transferFrequency": "twice-a-month", + "transferThreshold": { + "value": "5.00", + "currency": "EUR" + }, + "transferReference": "Mollie payout", + "transferDestination": { + "type": "bank-account", + "beneficiaryName": "Jack Bauer", + "bankAccount": "NL97MOLL6351480700", + "bankAccountId": "bnk_jrty3e" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPABC", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/balances?limit=5", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5", + "type": "application/hal+json" + } + } +} diff --git a/tests/Fixtures/Responses/empty-balance-list.json b/tests/Fixtures/Responses/empty-balance-list.json new file mode 100644 index 000000000..ae9dd93fc --- /dev/null +++ b/tests/Fixtures/Responses/empty-balance-list.json @@ -0,0 +1,18 @@ +{ + "count": 2, + "_embedded": { + "balances": [] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/balances?limit=5", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } +} diff --git a/tests/Fixtures/Responses/unprocessable-entity-with-field.json b/tests/Fixtures/Responses/unprocessable-entity-with-field.json new file mode 100644 index 000000000..5c0668cf4 --- /dev/null +++ b/tests/Fixtures/Responses/unprocessable-entity-with-field.json @@ -0,0 +1,12 @@ +{ + "status": 422, + "title": "Unprocessable Entity", + "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?", + "field": "recurringType", + "_links": { + "documentation": { + "href": "https://docs.mollie.com/guides/handling-errors", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/unprocessable-entity.json b/tests/Fixtures/Responses/unprocessable-entity.json new file mode 100644 index 000000000..1a1617c56 --- /dev/null +++ b/tests/Fixtures/Responses/unprocessable-entity.json @@ -0,0 +1,5 @@ +{ + "status": 422, + "title": "Unprocessable Entity", + "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?" +} diff --git a/tests/Mollie/TestHelpers/AmountObjectTestHelpers.php b/tests/Fixtures/Traits/AmountObjectTestHelpers.php similarity index 92% rename from tests/Mollie/TestHelpers/AmountObjectTestHelpers.php rename to tests/Fixtures/Traits/AmountObjectTestHelpers.php index 65dcebc01..b9f937c7e 100644 --- a/tests/Mollie/TestHelpers/AmountObjectTestHelpers.php +++ b/tests/Fixtures/Traits/AmountObjectTestHelpers.php @@ -1,6 +1,6 @@ ['bar' => 'baz']]; + + $this->assertEquals('baz', Arr::get($array, 'foo.bar')); + $this->assertEquals(null, Arr::get($array, 'foo.baz')); + $this->assertEquals('default', Arr::get($array, 'foo.baz', 'default')); + } + + /** @test */ + public function has(): void + { + $array = ['foo' => ['bar' => 'baz']]; + + $this->assertTrue(Arr::has($array, 'foo')); + $this->assertTrue(Arr::has($array, 'foo.bar')); + $this->assertFalse(Arr::has($array, 'foo.baz')); + $this->assertFalse(Arr::has($array, 'baz')); + } + + /** @test */ + public function exists(): void + { + $array = ['foo' => 'bar']; + + $this->assertTrue(Arr::exists($array, 'foo')); + $this->assertFalse(Arr::exists($array, 'bar')); + } + + /** @test */ + public function join(): void + { + $array = ['foo', 'bar', 'baz']; + + $this->assertEquals('foo, bar, baz', Arr::join($array)); + $this->assertEquals('foo-bar-baz', Arr::join($array, '-')); + } + + /** @test */ + public function wrap(): void + { + $value = 'foo'; + + $this->assertEquals(['foo'], Arr::wrap($value)); + + $array = ['foo', 'bar']; + + $this->assertEquals($array, Arr::wrap($array)); + } +} diff --git a/tests/Helpers/MiddlewareHandlersTest.php b/tests/Helpers/MiddlewareHandlersTest.php new file mode 100644 index 000000000..b74378bf2 --- /dev/null +++ b/tests/Helpers/MiddlewareHandlersTest.php @@ -0,0 +1,44 @@ +onRequest(function (PendingRequest $pendingRequest) { + $pendingRequest->headers()->add('Foo', 'Bar'); + + return $pendingRequest; + }); + + $result = $middlewareHandlers->executeOnRequest(new PendingRequest); + + $this->assertEquals('Bar', $result->headers()->get('Foo')); + } + + /** + * @test + */ + public function it_can_add_response_middleware_and_execute_it(): void + { + $middlewareHandlers = new MiddlewareHandlers; + + $middlewareHandlers->onResponse(function (Response $response) { + $this->assertTrue($response->successful()); + + return $response; + }); + + $result = $middlewareHandlers->executeOnRequest(new PendingRequest); + } +} diff --git a/tests/Helpers/UrlTest.php b/tests/Helpers/UrlTest.php new file mode 100644 index 000000000..5d5ab7af1 --- /dev/null +++ b/tests/Helpers/UrlTest.php @@ -0,0 +1,42 @@ +assertEquals($expected, $result); + } + + public function testIsValid() + { + $validUrl = 'https://example.com'; + $invalidUrl = 'example.com'; + + $this->assertTrue(Url::isValid($validUrl)); + $this->assertFalse(Url::isValid($invalidUrl)); + } + + public function testParseQuery() + { + $query = 'param1=value1¶m2=value2'; + + $expected = [ + 'param1' => 'value1', + 'param2' => 'value2', + ]; + $result = Url::parseQuery($query); + + $this->assertEquals($expected, $result); + } +} diff --git a/tests/Helpers/ValidatorTest.php b/tests/Helpers/ValidatorTest.php new file mode 100644 index 000000000..9054b18b3 --- /dev/null +++ b/tests/Helpers/ValidatorTest.php @@ -0,0 +1,124 @@ +expectException(RequestValidationException::class); + $this->expectExceptionMessage("Invalid foo ID: 'bar_123'. A resource ID should start with 'foo'."); + + $foo = new HasProperties('bar_123'); + $validator = new Validator; + + $validator->validate($foo); + } + + /** @test */ + public function it_validates_all_validatable_properties_by_deferring_to_their_validate_methods() + { + $this->expectException(RequestValidationException::class); + $this->expectExceptionMessage("Invalid include: 'foo'. Allowed are: bar."); + + $foo = new HasValidatableProperties(new ValidatableData('foo')); + $validator = new Validator; + + $validator->validate($foo); + } + + /** @test */ + public function it_does_not_validate_null_validatable_properties() + { + $foo = new HasValidatableProperties(null); // ValidatableData is null + $validator = new Validator; + + // No exception should be thrown because the ValidatableData is null + $validator->validate($foo); + + $this->assertTrue(true); // If no exception is thrown, the test passes + } + + /** @test */ + public function it_validates_additional_properties_without_overriding_provider_data() + { + $this->expectException(RequestValidationException::class); + $this->expectExceptionMessage("Invalid foo ID: 'bar_123'. A resource ID should start with 'foo'."); + + $foo = new HasProperties('foo_123'); // Valid ID from provider + $validator = new Validator; + + $additional = ['extra_id' => 'bar_123']; // Invalid additional ID with a different key + + $validator->validate($foo, $additional); + } +} + +class HasProperties extends Request +{ + protected string $id; + + /** + * The resource class the request should be casted to. + */ + public static string $targetResourceClass = 'foo'; + + public function __construct(string $id) + { + $this->id = $id; + } + + public function resolveResourcePath(): string + { + return 'foo'; + } + + public function rules(): array + { + return [ + 'id' => Id::startsWithPrefix('foo'), + 'extra_id' => Id::startsWithPrefix('foo'), // New rule for extra_id + ]; + } +} + +class HasValidatableProperties implements ValidatableDataProvider +{ + protected ?ValidatableData $validatableData; + + public function __construct(?ValidatableData $validatableData) + { + $this->validatableData = $validatableData; + } + + public function rules(): array + { + return []; + } +} + +class ValidatableData implements ValidatableDataProvider +{ + protected string $included; + + public function __construct(string $included) + { + $this->included = $included; + } + + public function rules(): array + { + return [ + 'included' => Included::make(['bar']), + ]; + } +} diff --git a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php similarity index 76% rename from tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php rename to tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index af3bcc03e..d98db72dd 100644 --- a/tests/Mollie/API/HttpAdapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -1,6 +1,6 @@ expects($this->once()) ->method('send') - ->with($this->isInstanceOf(Request::class)) + ->with($this->isInstanceOf(RequestInterface::class)) ->willThrowException( new ConnectException( 'Mock exception', @@ -45,14 +48,11 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() $adapter = new GuzzleMollieHttpAdapter($guzzleClient); $adapter->enableDebugging(); + $request = new DynamicGetRequest('https://api.mollie.com/v2/payments'); + $pendingRequest = new PendingRequest(new MockClient, $request); + try { - $adapter->send( - 'POST', - 'https://api.mollie.com/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact', - [], - /** @lang JSON */ - '{ "foo": "bar" }' - ); + $adapter->sendRequest($pendingRequest); } catch (ApiException $e) { $this->assertInstanceOf(RequestInterface::class, $e->getRequest()); } @@ -65,7 +65,7 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() $guzzleClient ->expects($this->once()) ->method('send') - ->with($this->isInstanceOf(Request::class)) + ->with($this->isInstanceOf(RequestInterface::class)) ->willThrowException( new ConnectException( 'Mock exception', @@ -76,14 +76,11 @@ public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() $adapter = new GuzzleMollieHttpAdapter($guzzleClient); $this->assertFalse($adapter->debuggingIsActive()); + $request = new DynamicGetRequest('https://api.mollie.com/v2/payments'); + $pendingRequest = new PendingRequest(new MockClient, $request); + try { - $adapter->send( - 'POST', - 'https://api.mollie.com/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact', - [], - /** @lang JSON */ - '{ "foo": "bar" }' - ); + $adapter->sendRequest($pendingRequest); } catch (ApiException $e) { $this->assertNull($e->getRequest()); } diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php new file mode 100644 index 000000000..e53932e55 --- /dev/null +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -0,0 +1,51 @@ + + */ + private array $expectedResponses; + + public function __construct(array $expectedResponses = []) + { + $this->expectedResponses = $expectedResponses; + } + + /** + * {@inheritDoc} + */ + public function sendRequest(PendingRequest $pendingRequest): Response + { + if (! Arr::has($this->expectedResponses, $pendingRequest->getRequest()::class)) { + throw new \RuntimeException('The request class '.$pendingRequest->getRequest()::class.' is not expected.'); + } + + $mockedResponse = $this->expectedResponses[$pendingRequest->getRequest()::class]; + + return new Response( + $mockedResponse->createPsrResponse(), + $pendingRequest->createPsrRequest(), + $pendingRequest, + ); + } + + /** + * {@inheritDoc} + */ + public function version(): string + { + return 'mock-client/2.0'; + } +} diff --git a/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php similarity index 97% rename from tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php rename to tests/Http/Adapter/MollieHttpAdapterPickerTest.php index a7fd93f8b..29ce12f7a 100644 --- a/tests/Mollie/API/HttpAdapter/MollieHttpAdapterPickerTest.php +++ b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php @@ -1,6 +1,6 @@ 'Bar']), ] ); @@ -39,12 +39,12 @@ public function testRetryLimit() $mock = new MockHandler( [ - new ConnectException("Error 1", new Request('GET', 'test')), - new ConnectException("Error 2", new Request('GET', 'test')), - new ConnectException("Error 3", new Request('GET', 'test')), - new ConnectException("Error 4", new Request('GET', 'test')), - new ConnectException("Error 5", new Request('GET', 'test')), - new ConnectException("Error 6", new Request('GET', 'test')), + new ConnectException('Error 1', new Request('GET', 'test')), + new ConnectException('Error 2', new Request('GET', 'test')), + new ConnectException('Error 3', new Request('GET', 'test')), + new ConnectException('Error 4', new Request('GET', 'test')), + new ConnectException('Error 5', new Request('GET', 'test')), + new ConnectException('Error 6', new Request('GET', 'test')), ] ); @@ -53,7 +53,7 @@ public function testRetryLimit() $client = new Client(['handler' => $handler]); $this->expectException(ConnectException::class); - $this->expectExceptionMessage("Error 6"); + $this->expectExceptionMessage('Error 6'); $client->request('GET', '/')->getStatusCode(); } @@ -64,8 +64,8 @@ public function testRetryDelay() $mock = new MockHandler( [ - new ConnectException("+1 second delay", new Request('GET', 'test')), - new ConnectException("+2 second delay", new Request('GET', 'test')), + new ConnectException('+1 second delay', new Request('GET', 'test')), + new ConnectException('+2 second delay', new Request('GET', 'test')), new Response(200), ] ); diff --git a/tests/Http/Auth/BearetTokenAuthenticatorTest.php b/tests/Http/Auth/BearetTokenAuthenticatorTest.php new file mode 100644 index 000000000..79027398d --- /dev/null +++ b/tests/Http/Auth/BearetTokenAuthenticatorTest.php @@ -0,0 +1,58 @@ +createMock(ArrayStore::class); + $headers + ->expects($this->once()) + ->method('add') + ->with('Authorization', "Bearer {$token}"); + + $pendingRequest = $this->createMock(PendingRequest::class); + $pendingRequest + ->expects($this->once()) + ->method('headers') + ->willReturn($headers); + + $authenticator->authenticate($pendingRequest); + } + + /** + * @test + */ + public function authenticate_with_token_trimming() + { + $token = ' test_token_with_spaces '; + $trimmedToken = 'test_token_with_spaces'; + $authenticator = new BearerTokenAuthenticator($token); + + $headers = $this->createMock(ArrayStore::class); + $headers + ->expects($this->once()) + ->method('add') + ->with('Authorization', "Bearer {$trimmedToken}"); + + $pendingRequest = $this->createMock(PendingRequest::class); + $pendingRequest + ->expects($this->once()) + ->method('headers') + ->willReturn($headers); + + $authenticator->authenticate($pendingRequest); + } +} diff --git a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php deleted file mode 100644 index 0a987c5aa..000000000 --- a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php +++ /dev/null @@ -1,487 +0,0 @@ -mockApiCall( - new Request( - "GET", - "/v2/balances" - ), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balances": [ - { - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPNFH", - "mode": "live", - "createdAt": "2019-01-10T12:06:28+00:00", - "currency": "EUR", - "status": "active", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "daily", - "transferThreshold": { - "value": "40.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL53INGB0654422370", - "bankAccountId": "bnk_jrty3f" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", - "type": "application/hal+json" - } - } - }, - { - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPABC", - "mode": "live", - "createdAt": "2019-01-10T10:23:41+00:00", - "status": "active", - "currency": "EUR", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "twice-a-month", - "transferThreshold": { - "value": "5.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL97MOLL6351480700", - "bankAccountId": "bnk_jrty3e" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPABC", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5", - "type": "application/hal+json" - } - } - }' - ) - ); - - /** @var BalanceCollection $balances */ - $balances = $this->apiClient->balances->page(); - - $this->assertInstanceOf(BalanceCollection::class, $balances); - $this->assertEquals(2, $balances->count()); - $this->assertCount(2, $balances); - - $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/balances-api/list-balances", - "text/html", - $balances->_links->documentation - ); - - $this->assertLinkObject( - "https://api.mollie.com/v2/balances?limit=5", - "application/hal+json", - $balances->_links->self - ); - - $this->assertLinkObject( - "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5", - "application/hal+json", - $balances->_links->next - ); - - /** @var Balance $balanceA */ - $balanceA = $balances[0]; - - /** @var Balance $balanceB */ - $balanceB = $balances[1]; - - $this->assertBalance( - $balanceA, - "bal_gVMhHKqSSRYJyPsuoPNFH", - "2019-01-10T12:06:28+00:00", - BalanceTransferFrequency::DAILY, - "40.00", - (object) [ - "type" => "bank-account", - "beneficiaryName" => "Jack Bauer", - "bankAccount" => "NL53INGB0654422370", - "bankAccountId" => "bnk_jrty3f", - ] - ); - $this->assertBalance( - $balanceB, - "bal_gVMhHKqSSRYJyPsuoPABC", - "2019-01-10T10:23:41+00:00", - BalanceTransferFrequency::TWICE_A_MONTH, - "5.00", - (object) [ - "type" => "bank-account", - "beneficiaryName" => "Jack Bauer", - "bankAccount" => "NL97MOLL6351480700", - "bankAccountId" => "bnk_jrty3e", - ] - ); - } - - public function testIterateBalances() - { - $this->mockApiCall( - new Request( - "GET", - "/v2/balances" - ), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balances": [ - { - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPNFH", - "mode": "live", - "createdAt": "2019-01-10T12:06:28+00:00", - "currency": "EUR", - "status": "active", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "daily", - "transferThreshold": { - "value": "40.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL53INGB0654422370", - "bankAccountId": "bnk_jrty3f" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", - "type": "application/hal+json" - } - } - }, - { - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPABC", - "mode": "live", - "createdAt": "2019-01-10T10:23:41+00:00", - "status": "active", - "currency": "EUR", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "twice-a-month", - "transferThreshold": { - "value": "5.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL97MOLL6351480700", - "bankAccountId": "bnk_jrty3e" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPABC", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - foreach ($this->apiClient->balances->iterator() as $balance) { - $this->assertInstanceOf(Balance::class, $balance); - } - } - - public function testGetBalance() - { - $this->mockApiCall( - new Request( - "GET", - "/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH" - ), - new Response( - 200, - [], - '{ - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPNFH", - "mode": "live", - "createdAt": "2019-01-10T10:23:41+00:00", - "currency": "EUR", - "status": "active", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "twice-a-month", - "transferThreshold": { - "value": "5.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL53INGB0654422370", - "bankAccountId": "bnk_jrty3f" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/get-balance", - "type": "text/html" - } - } - }' - ) - ); - - /** @var Balance $balance */ - $balance = $this->apiClient->balances->get("bal_gVMhHKqSSRYJyPsuoPNFH"); - - $this->assertBalance( - $balance, - "bal_gVMhHKqSSRYJyPsuoPNFH", - "2019-01-10T10:23:41+00:00", - BalanceTransferFrequency::TWICE_A_MONTH, - "5.00", - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL53INGB0654422370', - 'bankAccountId' => 'bnk_jrty3f', - ] - ); - } - - public function testGetPrimaryBalance() - { - $this->mockApiCall( - new Request( - "GET", - "/v2/balances/primary" - ), - new Response( - 200, - [], - '{ - "resource": "balance", - "id": "bal_gVMhHKqSSRYJyPsuoPNFH", - "mode": "live", - "createdAt": "2019-01-10T10:23:41+00:00", - "currency": "EUR", - "status": "active", - "availableAmount": { - "value": "0.00", - "currency": "EUR" - }, - "incomingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "outgoingAmount": { - "value": "0.00", - "currency": "EUR" - }, - "transferFrequency": "twice-a-month", - "transferThreshold": { - "value": "5.00", - "currency": "EUR" - }, - "transferReference": "Mollie payout", - "transferDestination": { - "type": "bank-account", - "beneficiaryName": "Jack Bauer", - "bankAccount": "NL53INGB0654422370", - "bankAccountId": "bnk_jrty3f" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/get-balance", - "type": "text/html" - } - } - }' - ) - ); - - /** @var Balance $balance */ - $balance = $this->apiClient->balances->primary(); - - $this->assertBalance( - $balance, - "bal_gVMhHKqSSRYJyPsuoPNFH", - "2019-01-10T10:23:41+00:00", - BalanceTransferFrequency::TWICE_A_MONTH, - "5.00", - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL53INGB0654422370', - 'bankAccountId' => 'bnk_jrty3f', - ] - ); - } - - /** - * @param \Mollie\Api\Resources\Balance $balance - * @param string $balanceId - * @param string $createdAt - * @param string $transferFrequency - * @param string $thresholdValue - * @param \stdClass $destination - * @return void - */ - protected function assertBalance( - Balance $balance, - string $balanceId, - string $createdAt, - string $transferFrequency, - string $thresholdValue, - \stdClass $destination - ) { - $this->assertInstanceOf(Balance::class, $balance); - $this->assertEquals("balance", $balance->resource); - $this->assertEquals($balanceId, $balance->id); - - $this->assertEquals("live", $balance->mode); - $this->assertEquals($createdAt, $balance->createdAt); - $this->assertEquals("EUR", $balance->currency); - $this->assertAmountObject("0.00", "EUR", $balance->availableAmount); - $this->assertAmountObject("0.00", "EUR", $balance->incomingAmount); - $this->assertAmountObject("0.00", "EUR", $balance->outgoingAmount); - $this->assertEquals($transferFrequency, $balance->transferFrequency); - $this->assertAmountObject($thresholdValue, "EUR", $balance->transferThreshold); - $this->assertEquals("Mollie payout", $balance->transferReference); - $this->assertEquals($destination, $balance->transferDestination); - - $this->assertLinkObject( - "https://api.mollie.com/v2/balances/{$balanceId}", - "application/hal+json", - $balance->_links->self - ); - } -} diff --git a/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php index 32d1a9988..a8b414065 100644 --- a/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php @@ -8,8 +8,8 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class BalanceReportEndpointTest extends BaseEndpointTest { @@ -20,8 +20,8 @@ public function testCanGetReportThroughBalanceReportEndpoint() { $this->mockApiCall( new Request( - "GET", - "/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories" + 'GET', + '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories' ), new Response( 200, @@ -31,12 +31,12 @@ public function testCanGetReportThroughBalanceReportEndpoint() ); $balance = new Balance($this->apiClient); - $balance->id = "bal_gVMhHKqSSRYJyPsuoPNFH"; + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; $report = $this->apiClient->balanceReports->getFor($balance, [ - "from" => "2021-01-01", - "until" => "2021-02-01", - "grouping" => "transaction-categories", + 'from' => '2021-01-01', + 'until' => '2021-02-01', + 'grouping' => 'transaction-categories', ]); $this->assertBalanceReport($report); @@ -46,8 +46,8 @@ public function testCanGetPrimaryBalanceReportThroughBalanceReportEndpoint() { $this->mockApiCall( new Request( - "GET", - "/v2/balances/primary/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories" + 'GET', + '/v2/balances/primary/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories' ), new Response( 200, @@ -57,9 +57,9 @@ public function testCanGetPrimaryBalanceReportThroughBalanceReportEndpoint() ); $report = $this->apiClient->balanceReports->getForPrimary([ - "from" => "2021-01-01", - "until" => "2021-02-01", - "grouping" => "transaction-categories", + 'from' => '2021-01-01', + 'until' => '2021-02-01', + 'grouping' => 'transaction-categories', ]); $this->assertBalanceReport($report); @@ -274,12 +274,12 @@ private function getBalanceReportStub() private function assertBalanceReport($report) { $this->assertInstanceOf(BalanceReport::class, $report); - $this->assertEquals("balance-report", $report->resource); - $this->assertEquals("bal_gVMhHKqSSRYJyPsuoPNFH", $report->balanceId); - $this->assertEquals("Europe/Amsterdam", $report->timeZone); - $this->assertEquals($report->from, "2021-01-01"); - $this->assertEquals($report->until, "2021-01-31"); - $this->assertEquals($report->grouping, "transaction-categories"); + $this->assertEquals('balance-report', $report->resource); + $this->assertEquals('bal_gVMhHKqSSRYJyPsuoPNFH', $report->balanceId); + $this->assertEquals('Europe/Amsterdam', $report->timeZone); + $this->assertEquals($report->from, '2021-01-01'); + $this->assertEquals($report->until, '2021-01-31'); + $this->assertEquals($report->grouping, 'transaction-categories'); $this->assertAmountObject('0.00', 'EUR', $report->totals->open->available->amount); $this->assertAmountObject('0.00', 'EUR', $report->totals->open->pending->amount); $this->assertAmountObject( @@ -298,7 +298,7 @@ private function assertBalanceReport($report) $report->totals->payments->pending->subtotals[0]->amount ); $this->assertEquals( - "payment", + 'payment', $report->totals->payments->pending->subtotals[0]->transactionType ); $this->assertEquals( @@ -306,8 +306,8 @@ private function assertBalanceReport($report) $report->totals->payments->pending->subtotals[0]->count ); $this->assertAmountObject( - "4.98", - "EUR", + '4.98', + 'EUR', $report->totals->payments->pending->subtotals[0]->subtotals[0]->amount ); $this->assertEquals( @@ -315,12 +315,12 @@ private function assertBalanceReport($report) $report->totals->payments->pending->subtotals[0]->subtotals[0]->count ); $this->assertEquals( - "ideal", + 'ideal', $report->totals->payments->pending->subtotals[0]->subtotals[0]->method ); $this->assertAmountObject( - "0.00", - "EUR", + '0.00', + 'EUR', $report->totals->payments->movedToAvailable->amount ); $this->assertEquals(new \stdClass, $report->totals->refunds); @@ -329,69 +329,69 @@ private function assertBalanceReport($report) $this->assertEquals(new \stdClass, $report->totals->transfers); $this->assertAmountObject( - "0.00", - "EUR", - $report->totals->{"fee-prepayments"}->immediatelyAvailable->amount + '0.00', + 'EUR', + $report->totals->{'fee-prepayments'}->immediatelyAvailable->amount ); - $movedToAvailable = $report->totals->{"fee-prepayments"}->movedToAvailable; + $movedToAvailable = $report->totals->{'fee-prepayments'}->movedToAvailable; $this->assertAmountObject( - "-0.36", - "EUR", + '-0.36', + 'EUR', $movedToAvailable->amount ); $this->assertAmountObject( - "-0.29", - "EUR", + '-0.29', + 'EUR', $movedToAvailable->subtotals[0]->amount ); $this->assertEquals(1, $movedToAvailable->subtotals[0]->count); - $this->assertEquals("fee", $movedToAvailable->subtotals[0]->prepaymentPartType); + $this->assertEquals('fee', $movedToAvailable->subtotals[0]->prepaymentPartType); $this->assertAmountObject( - "-0.29", - "EUR", + '-0.29', + 'EUR', $movedToAvailable->subtotals[0]->subtotals[0]->amount ); $this->assertEquals(1, $movedToAvailable->subtotals[0]->subtotals[0]->count); - $this->assertEquals("payment-fee", $movedToAvailable->subtotals[0]->subtotals[0]->feeType); + $this->assertEquals('payment-fee', $movedToAvailable->subtotals[0]->subtotals[0]->feeType); $this->assertAmountObject( - "-0.29", - "EUR", + '-0.29', + 'EUR', $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->amount ); $this->assertEquals(1, $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->count); - $this->assertEquals("ideal", $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->method); + $this->assertEquals('ideal', $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->method); $this->assertAmountObject( - "-0.0609", - "EUR", + '-0.0609', + 'EUR', $movedToAvailable->subtotals[1]->amount ); - $this->assertEquals("fee-vat", $movedToAvailable->subtotals[1]->prepaymentPartType); + $this->assertEquals('fee-vat', $movedToAvailable->subtotals[1]->prepaymentPartType); $this->assertAmountObject( - "-0.0091", - "EUR", + '-0.0091', + 'EUR', $movedToAvailable->subtotals[2]->amount ); - $this->assertEquals("fee-rounding-compensation", $movedToAvailable->subtotals[2]->prepaymentPartType); + $this->assertEquals('fee-rounding-compensation', $movedToAvailable->subtotals[2]->prepaymentPartType); // etc. $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/balances-api/get-balance-report", - "text/html", + 'https://docs.mollie.com/reference/v2/balances-api/get-balance-report', + 'text/html', $report->_links->documentation ); $this->assertLinkObject( - "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories", - "application/hal+json", + 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories', + 'application/hal+json', $report->_links->self ); } diff --git a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php index 1e4034590..c7ef795b4 100644 --- a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php @@ -10,18 +10,18 @@ use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Resources\BaseCollection; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class BalanceTransactionEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testGetBalanceTransactionsThroughEndpoint() { $this->mockApiCall( - new Request("GET", "/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions"), + new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), new Response( 200, [], @@ -91,7 +91,7 @@ public function testGetBalanceTransactionsThroughEndpoint() ); $balance = new Balance($this->apiClient); - $balance->id = "bal_gVMhHKqSSRYJyPsuoPNFH"; + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; $transactions = $this->apiClient->balanceTransactions->listFor($balance); @@ -101,7 +101,7 @@ public function testGetBalanceTransactionsThroughEndpoint() public function testIteratorForBalanceTransactionsThroughEndpoint() { $this->mockApiCall( - new Request("GET", "/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions"), + new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), new Response( 200, [], @@ -171,7 +171,7 @@ public function testIteratorForBalanceTransactionsThroughEndpoint() ); $balance = new Balance($this->apiClient); - $balance->id = "bal_gVMhHKqSSRYJyPsuoPNFH"; + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; foreach ($this->apiClient->balanceTransactions->iteratorFor($balance) as $balanceTransactions) { $this->assertInstanceOf(BalanceTransaction::class, $balanceTransactions); @@ -181,7 +181,7 @@ public function testIteratorForBalanceTransactionsThroughEndpoint() public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() { $this->mockApiCall( - new Request("GET", "/v2/balances/primary/transactions"), + new Request('GET', '/v2/balances/primary/transactions'), new Response( 200, [], @@ -258,7 +258,7 @@ public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoi public function testIteratorForPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() { $this->mockApiCall( - new Request("GET", "/v2/balances/primary/transactions"), + new Request('GET', '/v2/balances/primary/transactions'), new Response( 200, [], @@ -338,13 +338,13 @@ private function assertTransactions(BaseCollection $transactions) $this->assertCount(2, $transactions); $this->assertEquals(2, $transactions->count()); $this->assertLinkObject( - "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", - "application/hal+json", + 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5', + 'application/hal+json', $transactions->_links->self ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", - "text/html", + 'https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions', + 'text/html', $transactions->_links->documentation ); $this->assertNull($transactions->_links->next); @@ -357,24 +357,24 @@ private function assertTransactions(BaseCollection $transactions) $transactionB = $transactions[1]; // Transaction A - $this->assertEquals("balance_transaction", $transactionA->resource); - $this->assertEquals("baltr_QM24QwzUWR4ev4Xfgyt29A", $transactionA->id); - $this->assertEquals("refund", $transactionA->type); - $this->assertAmountObject("-10.25", "EUR", $transactionA->resultAmount); - $this->assertAmountObject("-10.00", "EUR", $transactionA->initialAmount); - $this->assertAmountObject("-0.25", "EUR", $transactionA->deductions); - $this->assertEquals("2021-01-10T12:06:28+00:00", $transactionA->createdAt); - $this->assertEquals("tr_7UhSN1zuXS", $transactionA->context->paymentId); - $this->assertEquals("re_4qqhO89gsT", $transactionA->context->refundId); + $this->assertEquals('balance_transaction', $transactionA->resource); + $this->assertEquals('baltr_QM24QwzUWR4ev4Xfgyt29A', $transactionA->id); + $this->assertEquals('refund', $transactionA->type); + $this->assertAmountObject('-10.25', 'EUR', $transactionA->resultAmount); + $this->assertAmountObject('-10.00', 'EUR', $transactionA->initialAmount); + $this->assertAmountObject('-0.25', 'EUR', $transactionA->deductions); + $this->assertEquals('2021-01-10T12:06:28+00:00', $transactionA->createdAt); + $this->assertEquals('tr_7UhSN1zuXS', $transactionA->context->paymentId); + $this->assertEquals('re_4qqhO89gsT', $transactionA->context->refundId); // Transaction B - $this->assertEquals("balance_transaction", $transactionB->resource); - $this->assertEquals("baltr_QM24QwzUWR4ev4Xfgyt29B", $transactionB->id); - $this->assertEquals("payment", $transactionB->type); - $this->assertAmountObject("9.71", "EUR", $transactionB->resultAmount); - $this->assertAmountObject("10.00", "EUR", $transactionB->initialAmount); - $this->assertAmountObject("-0.29", "EUR", $transactionB->deductions); - $this->assertEquals("2021-01-10T12:06:28+00:00", $transactionB->createdAt); - $this->assertEquals("tr_7UhSN1zuXS", $transactionB->context->paymentId); + $this->assertEquals('balance_transaction', $transactionB->resource); + $this->assertEquals('baltr_QM24QwzUWR4ev4Xfgyt29B', $transactionB->id); + $this->assertEquals('payment', $transactionB->type); + $this->assertAmountObject('9.71', 'EUR', $transactionB->resultAmount); + $this->assertAmountObject('10.00', 'EUR', $transactionB->initialAmount); + $this->assertAmountObject('-0.29', 'EUR', $transactionB->deductions); + $this->assertEquals('2021-01-10T12:06:28+00:00', $transactionB->createdAt); + $this->assertEquals('tr_7UhSN1zuXS', $transactionB->context->paymentId); } } diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index 2aded943d..6f769d520 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -6,20 +6,20 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class ChargebackEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testListChargebacks() { $this->mockApiCall( new Request( - "GET", - "/v2/chargebacks" + 'GET', + '/v2/chargebacks' ), new Response( 200, @@ -114,27 +114,27 @@ public function testListChargebacks() $this->assertCount(2, $chargebacks); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", - "text/html", + 'https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks', + 'text/html', $chargebacks->_links->documentation ); $this->assertLinkObject( - "https://api.mollie.com/v2/chargebacks", - "application/hal+json", + 'https://api.mollie.com/v2/chargebacks', + 'application/hal+json', $chargebacks->_links->self ); - $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00", "AC01"); - $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', "-0.37", null); + $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00', 'AC01'); + $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', '-0.37', null); } public function testIterateChargebacks() { $this->mockApiCall( new Request( - "GET", - "/v2/chargebacks" + 'GET', + '/v2/chargebacks' ), new Response( 200, @@ -230,37 +230,37 @@ public function testIterateChargebacks() protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount, $reasonCode) { $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals("chargeback", $chargeback->resource); + $this->assertEquals('chargeback', $chargeback->resource); $this->assertEquals($chargebackId, $chargeback->id); - $this->assertAmountObject($amount, "EUR", $chargeback->amount); - $this->assertAmountObject($amount, "EUR", $chargeback->settlementAmount); + $this->assertAmountObject($amount, 'EUR', $chargeback->amount); + $this->assertAmountObject($amount, 'EUR', $chargeback->settlementAmount); - $this->assertEquals("2018-03-28T11:44:32+00:00", $chargeback->createdAt); + $this->assertEquals('2018-03-28T11:44:32+00:00', $chargeback->createdAt); $this->assertEquals($paymentId, $chargeback->paymentId); $this->assertNull($chargeback->reversedAt); if ($reasonCode === null) { $this->assertNull($chargeback->reason); } else { - $this->assertReasonObject($reasonCode, "", $chargeback->reason); + $this->assertReasonObject($reasonCode, '', $chargeback->reason); } $this->assertLinkObject( "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}", - "application/hal+json", + 'application/hal+json', $chargeback->_links->self ); $this->assertLinkObject( "https://api.mollie.com/v2/payments/{$paymentId}", - "application/hal+json", + 'application/hal+json', $chargeback->_links->payment ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "text/html", + 'https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback', + 'text/html', $chargeback->_links->documentation ); } diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php index bdf9ae393..0fed72aec 100644 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientEndpointTest.php @@ -6,7 +6,7 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class ClientEndpointTest extends BaseEndpointTest { @@ -15,7 +15,7 @@ class ClientEndpointTest extends BaseEndpointTest public function testGetClient() { $this->mockApiCall( - new Request("GET", "/v2/clients/org_1337"), + new Request('GET', '/v2/clients/org_1337'), new Response( 200, [], @@ -60,7 +60,7 @@ public function testGetClient() public function testGetClientsPage() { $this->mockApiCall( - new Request("GET", "/v2/clients", [], ''), + new Request('GET', '/v2/clients', [], ''), new Response( 200, [], diff --git a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php b/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php index e32c41663..755526d47 100644 --- a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php @@ -4,7 +4,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class ClientLinkEndpointTest extends BaseEndpointTest { @@ -17,8 +17,8 @@ public function testCreateClientLink(string $client_link_id, string $app_id, str { $this->mockApiCall( new Request( - "POST", - "/v2/client-links", + 'POST', + '/v2/client-links', [], '{ "owner": { @@ -46,26 +46,26 @@ public function testCreateClientLink(string $client_link_id, string $app_id, str ); $clientLink = $this->apiClient->clientLinks->create([ - "owner" => [ - "email" => "foo@test.com", - "givenName" => "foo", - "familyName" => "bar", - "locale" => "nl_NL", + 'owner' => [ + 'email' => 'foo@test.com', + 'givenName' => 'foo', + 'familyName' => 'bar', + 'locale' => 'nl_NL', ], - "name" => "Foo Company", - "address" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", + 'name' => 'Foo Company', + 'address' => [ + 'streetAndNumber' => 'Keizersgracht 313', + 'postalCode' => '1016 EE', + 'city' => 'Amsterdam', + 'country' => 'nl', ], - "registrationNumber" => "30204462", - "vatNumber" => "NL123456789B01", + 'registrationNumber' => '30204462', + 'vatNumber' => 'NL123456789B01', ]); $this->assertEquals($clientLink->id, $client_link_id); - $this->assertLinkObject("https://my.mollie.com/dashboard/client-link/finalize/{$client_link_id}", "text/html", $clientLink->_links->clientLink); - $this->assertLinkObject("https://docs.mollie.com/reference/v2/clients-api/create-client-link", "text/html", $clientLink->_links->documentation); + $this->assertLinkObject("https://my.mollie.com/dashboard/client-link/finalize/{$client_link_id}", 'text/html', $clientLink->_links->clientLink); + $this->assertLinkObject('https://docs.mollie.com/reference/v2/clients-api/create-client-link', 'text/html', $clientLink->_links->documentation); $redirectLink = $clientLink->getRedirectUrl($app_id, $state, $scopes, $approval_prompt); $this->assertEquals("https://my.mollie.com/dashboard/client-link/finalize/{$client_link_id}?{$expected_url_query}", $redirectLink); @@ -75,7 +75,7 @@ protected function getClientLinkResponseFixture(string $client_link_id) { return str_replace( [ - "<>", + '<>', ], [ $client_link_id, diff --git a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php index 1737ccf4b..4b8b4c07c 100644 --- a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php @@ -6,7 +6,7 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class CustomerSubscriptionPaymentEndpointTest extends BaseEndpointTest { diff --git a/tests/Mollie/API/Endpoints/MethodEndpointTest.php b/tests/Mollie/API/Endpoints/MethodEndpointTest.php index 6cca99c96..b585fed05 100644 --- a/tests/Mollie/API/Endpoints/MethodEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodEndpointTest.php @@ -11,13 +11,13 @@ use Mollie\Api\Resources\MethodPrice; use Mollie\Api\Resources\MethodPriceCollection; use stdClass; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class MethodEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testGetMethod() { @@ -312,17 +312,17 @@ public function testGetTranslatedMethod() $this->assertAmountObject(0.01, 'EUR', $method->minimumAmount); $this->assertAmountObject(50000, 'EUR', $method->maximumAmount); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->size1x = 'https://www.mollie.com/images/payscreen/methods/sofort.png'; $amount->size2x = 'https://www.mollie.com/images/payscreen/methods/sofort%402x.png'; - $selfLink = (object)[ + $selfLink = (object) [ 'href' => 'https://api.mollie.com/v2/methods/sofort', 'type' => 'application/hal+json', ]; $this->assertEquals($selfLink, $method->_links->self); - $documentationLink = (object)[ + $documentationLink = (object) [ 'href' => 'https://docs.mollie.com/reference/v2/methods-api/get-method', 'type' => 'text/html', ]; @@ -452,13 +452,13 @@ public function testListAllActiveMethods() $this->assertEquals(4, $methods->count()); $this->assertCount(4, $methods); - $documentationLink = (object)[ + $documentationLink = (object) [ 'href' => 'https://docs.mollie.com/reference/v2/methods-api/list-methods', 'type' => 'text/html', ]; $this->assertEquals($documentationLink, $methods->_links->documentation); - $selfLink = (object)[ + $selfLink = (object) [ 'href' => 'http://api.mollie.com/v2/methods', 'type' => 'application/hal+json', ]; @@ -474,7 +474,7 @@ public function testListAllActiveMethods() $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard.png', $creditcardMethod->image->size1x); $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard%402x.png', $creditcardMethod->image->size2x); - $selfLink = (object)[ + $selfLink = (object) [ 'href' => 'https://api.mollie.com/v2/methods/creditcard', 'type' => 'application/hal+json', ]; diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index 0caed434f..79364fea0 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -14,20 +14,20 @@ use Mollie\Api\Types\OrderLineType; use Mollie\Api\Types\OrderStatus; use stdClass; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class OrderEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testCreateOrder() { $this->mockApiCall( new Request( - "POST", - "/v2/orders", + 'POST', + '/v2/orders', [], '{ "amount": { @@ -116,89 +116,89 @@ public function testCreateOrder() new Response( 201, [], - $this->getOrderResponseFixture("ord_pbjz8x") + $this->getOrderResponseFixture('ord_pbjz8x') ) ); $order = $this->apiClient->orders->create([ - "amount" => [ - "value" => "1027.99", - "currency" => "EUR", + 'amount' => [ + 'value' => '1027.99', + 'currency' => 'EUR', ], - "billingAddress" => [ - "organizationName" => "Organization Name LTD.", - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", + 'billingAddress' => [ + 'organizationName' => 'Organization Name LTD.', + 'streetAndNumber' => 'Keizersgracht 313', + 'postalCode' => '1016 EE', + 'city' => 'Amsterdam', + 'country' => 'nl', + 'givenName' => 'Luke', + 'familyName' => 'Skywalker', + 'email' => 'luke@skywalker.com', ], - "shippingAddress" => [ - "organizationName" => "Organization Name LTD.", - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", + 'shippingAddress' => [ + 'organizationName' => 'Organization Name LTD.', + 'streetAndNumber' => 'Keizersgracht 313', + 'postalCode' => '1016 EE', + 'city' => 'Amsterdam', + 'country' => 'nl', + 'givenName' => 'Luke', + 'familyName' => 'Skywalker', + 'email' => 'luke@skywalker.com', ], - "metadata" => [ - "order_id" => "1337", - "description" => "Lego cars", + 'metadata' => [ + 'order_id' => '1337', + 'description' => 'Lego cars', ], - "consumerDateOfBirth" => "1958-01-31", - "locale" => "nl_NL", - "orderNumber" => "1337", - "redirectUrl" => "https://example.org/redirect", - "webhookUrl" => "https://example.org/webhook", - "method" => "klarnapaylater", - "lines" => [ + 'consumerDateOfBirth' => '1958-01-31', + 'locale' => 'nl_NL', + 'orderNumber' => '1337', + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + 'method' => 'klarnapaylater', + 'lines' => [ [ - "sku" => "5702016116977", - "name" => "LEGO 42083 Bugatti Chiron", - "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - "quantity" => 2, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "399.00", + 'sku' => '5702016116977', + 'name' => 'LEGO 42083 Bugatti Chiron', + 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', + 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '399.00', ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "698.00", + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '698.00', ], - "discountAmount" => [ - "currency" => "EUR", - "value" => "100.00", + 'discountAmount' => [ + 'currency' => 'EUR', + 'value' => '100.00', ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "121.14", + 'vatAmount' => [ + 'currency' => 'EUR', + 'value' => '121.14', ], ], [ - "type" => "digital", - "sku" => "5702015594028", - "name" => "LEGO 42056 Porsche 911 GT3 RS", - "productUrl" => "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', - "quantity" => 1, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "329.99", + 'type' => 'digital', + 'sku' => '5702015594028', + 'name' => 'LEGO 42056 Porsche 911 GT3 RS', + 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', + 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '329.99', ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "329.99", + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '329.99', ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "57.27", + 'vatAmount' => [ + 'currency' => 'EUR', + 'value' => '57.27', ], ], ], @@ -211,13 +211,13 @@ public function testGetOrderDirectly() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x" + 'GET', + '/v2/orders/ord_pbjz8x' ), new Response( 200, [], - $this->getOrderResponseFixture("ord_pbjz8x") + $this->getOrderResponseFixture('ord_pbjz8x') ) ); @@ -230,8 +230,8 @@ public function testGetOrderDirectlyIncludingPayments() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_kEn1PlbGa?embed=payments" + 'GET', + '/v2/orders/ord_kEn1PlbGa?embed=payments' ), new Response( 200, @@ -488,17 +488,17 @@ public function testGetOrderOnShipmentResource() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x" + 'GET', + '/v2/orders/ord_pbjz8x' ), new Response( 200, [], - $this->getOrderResponseFixture("ord_pbjz8x") + $this->getOrderResponseFixture('ord_pbjz8x') ) ); - $shipment = $this->getShipment("shp_3wmsgCJN4U", "ord_pbjz8x"); + $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x'); $order = $shipment->order(); $this->assertOrder($order, 'ord_pbjz8x'); @@ -507,7 +507,7 @@ public function testGetOrderOnShipmentResource() public function testListOrders() { $this->mockApiCall( - new Request("GET", "/v2/orders"), + new Request('GET', '/v2/orders'), new Response( 200, [], @@ -515,9 +515,9 @@ public function testListOrders() "count": 3, "_embedded": { "orders": [ - ' . $this->getOrderResponseFixture("ord_pbjz1x") . ', - ' . $this->getOrderResponseFixture("ord_pbjz2y") . ', - ' . $this->getOrderResponseFixture("ord_pbjz3z") . ' + '.$this->getOrderResponseFixture('ord_pbjz1x').', + '.$this->getOrderResponseFixture('ord_pbjz2y').', + '.$this->getOrderResponseFixture('ord_pbjz3z').' ] }, "_links": { @@ -547,20 +547,20 @@ public function testListOrders() $this->assertNull($orders->_links->previous); $selfLink = $this->createLinkObject( - "https://api.mollie.com/v2/orders", - "application/hal+json" + 'https://api.mollie.com/v2/orders', + 'application/hal+json' ); $this->assertEquals($selfLink, $orders->_links->self); $nextLink = $this->createLinkObject( - "https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS", - "application/hal+json" + 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + 'application/hal+json' ); $this->assertEquals($nextLink, $orders->_links->next); $documentationLink = $this->createLinkObject( - "https://docs.mollie.com/reference/v2/orders-api/list-orders", - "text/html" + 'https://docs.mollie.com/reference/v2/orders-api/list-orders', + 'text/html' ); $this->assertEquals($documentationLink, $orders->_links->documentation); @@ -572,7 +572,7 @@ public function testListOrders() public function testIterateOrders() { $this->mockApiCall( - new Request("GET", "/v2/orders"), + new Request('GET', '/v2/orders'), new Response( 200, [], @@ -580,9 +580,9 @@ public function testIterateOrders() "count": 3, "_embedded": { "orders": [ - ' . $this->getOrderResponseFixture("ord_pbjz1x") . ', - ' . $this->getOrderResponseFixture("ord_pbjz2y") . ', - ' . $this->getOrderResponseFixture("ord_pbjz3z") . ' + '.$this->getOrderResponseFixture('ord_pbjz1x').', + '.$this->getOrderResponseFixture('ord_pbjz2y').', + '.$this->getOrderResponseFixture('ord_pbjz3z').' ] }, "_links": { @@ -609,7 +609,7 @@ public function testIterateOrders() public function testCancelOrderDirectly() { $this->mockApiCall( - new Request("DELETE", "/v2/orders/ord_pbjz1x"), + new Request('DELETE', '/v2/orders/ord_pbjz1x'), new Response( 200, [], @@ -626,7 +626,7 @@ public function testCancelOrderDirectly() public function testCancelOrderOnResource() { $this->mockApiCall( - new Request("DELETE", "/v2/orders/ord_pbjz1x"), + new Request('DELETE', '/v2/orders/ord_pbjz1x'), new Response( 200, [], @@ -645,8 +645,8 @@ public function testCancelOrderLines() { $this->mockApiCall( new Request( - "DELETE", - "/v2/orders/ord_8wmqcHMN4U/lines", + 'DELETE', + '/v2/orders/ord_8wmqcHMN4U/lines', [], '{ "lines": [ @@ -678,8 +678,8 @@ public function testCancelAllOrderLines() { $this->mockApiCall( new Request( - "DELETE", - "/v2/orders/ord_8wmqcHMN4U/lines", + 'DELETE', + '/v2/orders/ord_8wmqcHMN4U/lines', [], '{ "lines": [], @@ -703,8 +703,8 @@ public function testUpdateOrder() { $this->mockApiCall( new Request( - "PATCH", - "/v2/orders/ord_pbjz8x", + 'PATCH', + '/v2/orders/ord_pbjz8x', [], '{ "billingAddress": { @@ -740,42 +740,42 @@ public function testUpdateOrder() 200, [], $this->getOrderResponseFixture( - "ord_pbjz8x", + 'ord_pbjz8x', OrderStatus::CREATED, - "16738" + '16738' ) ) ); /** @var Order $order */ - $order = $this->getOrder("ord_pbjz8x"); + $order = $this->getOrder('ord_pbjz8x'); - $order->billingAddress->organizationName = "Organization Name LTD."; - $order->billingAddress->streetAndNumber = "Keizersgracht 313"; - $order->billingAddress->city = "Amsterdam"; - $order->billingAddress->region = "Noord-Holland"; - $order->billingAddress->postalCode = "1234AB"; - $order->billingAddress->country = "NL"; - $order->billingAddress->title = "Dhr"; - $order->billingAddress->givenName = "Piet"; - $order->billingAddress->familyName = "Mondriaan"; - $order->billingAddress->email = "piet@mondriaan.com"; - $order->billingAddress->phone = "+31208202070"; - $order->orderNumber = "16738"; - $order->redirectUrl = "https://example.org/updated-redirect"; - $order->cancelUrl = "https://example.org/updated-cancel-url"; - $order->webhookUrl = "https://example.org/updated-webhook"; + $order->billingAddress->organizationName = 'Organization Name LTD.'; + $order->billingAddress->streetAndNumber = 'Keizersgracht 313'; + $order->billingAddress->city = 'Amsterdam'; + $order->billingAddress->region = 'Noord-Holland'; + $order->billingAddress->postalCode = '1234AB'; + $order->billingAddress->country = 'NL'; + $order->billingAddress->title = 'Dhr'; + $order->billingAddress->givenName = 'Piet'; + $order->billingAddress->familyName = 'Mondriaan'; + $order->billingAddress->email = 'piet@mondriaan.com'; + $order->billingAddress->phone = '+31208202070'; + $order->orderNumber = '16738'; + $order->redirectUrl = 'https://example.org/updated-redirect'; + $order->cancelUrl = 'https://example.org/updated-cancel-url'; + $order->webhookUrl = 'https://example.org/updated-webhook'; $order = $order->update(); - $this->assertOrder($order, "ord_pbjz8x", OrderStatus::CREATED, "16738"); + $this->assertOrder($order, 'ord_pbjz8x', OrderStatus::CREATED, '16738'); } public function testUpdateOrderLine() { $this->mockApiCall( new Request( - "PATCH", - "/v2/orders/ord_pbjz8x/lines/odl_dgtxyl", + 'PATCH', + '/v2/orders/ord_pbjz8x/lines/odl_dgtxyl', [], '{ "name": "LEGO 71043 Hogwartsâ„¢ Castle", @@ -828,7 +828,7 @@ public function testUpdateOrderLine() $this->assertOrder($result, 'ord_pbjz8x'); } - protected function assertOrder($order, $order_id, $order_status = OrderStatus::CREATED, $orderNumber = "1337") + protected function assertOrder($order, $order_id, $order_status = OrderStatus::CREATED, $orderNumber = '1337') { $this->assertInstanceOf(Order::class, $order); $this->assertEquals('order', $order->resource); @@ -850,37 +850,37 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::C $this->assertEquals($order_status, $order->status); - $billingAddress = new stdClass(); - $billingAddress->organizationName = "Organization Name LTD."; - $billingAddress->streetAndNumber = "Keizersgracht 313"; - $billingAddress->postalCode = "1016 EE"; - $billingAddress->city = "Amsterdam"; - $billingAddress->country = "nl"; - $billingAddress->givenName = "Luke"; - $billingAddress->familyName = "Skywalker"; - $billingAddress->email = "luke@skywalker.com"; + $billingAddress = new stdClass; + $billingAddress->organizationName = 'Organization Name LTD.'; + $billingAddress->streetAndNumber = 'Keizersgracht 313'; + $billingAddress->postalCode = '1016 EE'; + $billingAddress->city = 'Amsterdam'; + $billingAddress->country = 'nl'; + $billingAddress->givenName = 'Luke'; + $billingAddress->familyName = 'Skywalker'; + $billingAddress->email = 'luke@skywalker.com'; $this->assertEquals($billingAddress, $order->billingAddress); - $shippingAddress = new stdClass(); - $shippingAddress->organizationName = "Organization Name LTD."; - $shippingAddress->streetAndNumber = "Keizersgracht 313"; - $shippingAddress->postalCode = "1016 EE"; - $shippingAddress->city = "Amsterdam"; - $shippingAddress->country = "nl"; - $shippingAddress->givenName = "Luke"; - $shippingAddress->familyName = "Skywalker"; - $shippingAddress->email = "luke@skywalker.com"; + $shippingAddress = new stdClass; + $shippingAddress->organizationName = 'Organization Name LTD.'; + $shippingAddress->streetAndNumber = 'Keizersgracht 313'; + $shippingAddress->postalCode = '1016 EE'; + $shippingAddress->city = 'Amsterdam'; + $shippingAddress->country = 'nl'; + $shippingAddress->givenName = 'Luke'; + $shippingAddress->familyName = 'Skywalker'; + $shippingAddress->email = 'luke@skywalker.com'; $this->assertEquals($shippingAddress, $order->shippingAddress); $this->assertEquals($orderNumber, $order->orderNumber); $this->assertEquals('nl_NL', $order->locale); - $this->assertEquals("https://example.org/redirect", $order->redirectUrl); - $this->assertEquals("https://example.org/webhook", $order->webhookUrl); + $this->assertEquals('https://example.org/redirect', $order->redirectUrl); + $this->assertEquals('https://example.org/webhook', $order->webhookUrl); - $links = (object)[ + $links = (object) [ 'self' => $this->createLinkObject( - 'https://api.mollie.com/v2/orders/' . $order_id, + 'https://api.mollie.com/v2/orders/'.$order_id, 'application/hal+json' ), 'checkout' => $this->createLinkObject( @@ -894,43 +894,43 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::C ]; $this->assertEquals($links, $order->_links); - $line1 = new stdClass(); - $line1->resource = "orderline"; - $line1->id = "odl_dgtxyl"; + $line1 = new stdClass; + $line1->resource = 'orderline'; + $line1->id = 'odl_dgtxyl'; $line1->orderId = $order_id; - $line1->name = "LEGO 42083 Bugatti Chiron"; - $line1->productUrl = "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083"; + $line1->name = 'LEGO 42083 Bugatti Chiron'; + $line1->productUrl = 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083'; $line1->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$'; - $line1->sku = "5702016116977"; + $line1->sku = '5702016116977'; $line1->type = OrderLineType::PHYSICAL; $line1->status = OrderLineStatus::CREATED; $line1->isCancelable = true; $line1->quantity = 2; - $line1->unitPrice = $this->createAmountObject("399.00", "EUR"); - $line1->vatRate = "21.00"; - $line1->vatAmount = $this->createAmountObject("121.14", "EUR"); - $line1->discountAmount = $this->createAmountObject("100.00", "EUR"); - $line1->totalAmount = $this->createAmountObject("698.00", "EUR"); - $line1->createdAt = "2018-08-02T09:29:56+00:00"; + $line1->unitPrice = $this->createAmountObject('399.00', 'EUR'); + $line1->vatRate = '21.00'; + $line1->vatAmount = $this->createAmountObject('121.14', 'EUR'); + $line1->discountAmount = $this->createAmountObject('100.00', 'EUR'); + $line1->totalAmount = $this->createAmountObject('698.00', 'EUR'); + $line1->createdAt = '2018-08-02T09:29:56+00:00'; $this->assertEquals($line1, $order->lines[0]); - $line2 = new stdClass(); - $line2->resource = "orderline"; - $line2->id = "odl_jp31jz"; + $line2 = new stdClass; + $line2->resource = 'orderline'; + $line2->id = 'odl_jp31jz'; $line2->orderId = $order_id; - $line2->name = "LEGO 42056 Porsche 911 GT3 RS"; - $line2->productUrl = "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056"; + $line2->name = 'LEGO 42056 Porsche 911 GT3 RS'; + $line2->productUrl = 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056'; $line2->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$'; - $line2->sku = "5702015594028"; + $line2->sku = '5702015594028'; $line2->type = OrderLineType::DIGITAL; $line2->status = OrderLineStatus::CREATED; $line2->isCancelable = true; $line2->quantity = 1; - $line2->unitPrice = $this->createAmountObject("329.99", "EUR"); - $line2->vatRate = "21.00"; - $line2->vatAmount = $this->createAmountObject("57.27", "EUR"); - $line2->totalAmount = $this->createAmountObject("329.99", "EUR"); - $line2->createdAt = "2018-08-02T09:29:56+00:00"; + $line2->unitPrice = $this->createAmountObject('329.99', 'EUR'); + $line2->vatRate = '21.00'; + $line2->vatAmount = $this->createAmountObject('57.27', 'EUR'); + $line2->totalAmount = $this->createAmountObject('329.99', 'EUR'); + $line2->createdAt = '2018-08-02T09:29:56+00:00'; $this->assertEquals($line2, $order->lines[1]); $this->assertNull($order->payments()); @@ -947,8 +947,8 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu { return str_replace( [ - "<>", - "<>", + '<>', + '<>', ], [ $order_id, @@ -970,7 +970,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu "value": "0.00", "currency": "EUR" }, - "status": "' . $order_status . '", + "status": "'.$order_status.'", "metadata": { "order_id": "1337", "description": "Lego cars" @@ -1098,9 +1098,9 @@ protected function getShipmentResponseFixture($shipmentId, $orderId, $orderlineS { return str_replace( [ - "<>", - "<>", - "<>", + '<>', + '<>', + '<>', ], [ $orderId, diff --git a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php index 361d0b176..40fce6bc7 100644 --- a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php @@ -10,20 +10,20 @@ use Mollie\Api\Types\PaymentMethod; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class OrderPaymentEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testCreateOrderPayment() { $this->mockApiCall( new Request( - "POST", - "/v2/orders/ord_stTC2WHAuS/payments", + 'POST', + '/v2/orders/ord_stTC2WHAuS/payments', [], '{ "method": "banktransfer", @@ -153,7 +153,7 @@ protected function getOrder($id) protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( - "<>", + '<>', $order_id, '{ "resource": "order", @@ -171,7 +171,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu "value": "0.00", "currency": "EUR" }, - "status": "' . $order_status . '", + "status": "'.$order_status.'", "metadata": { "order_id": "1337", "description": "Lego cars" diff --git a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php index 9a261416f..59c97498e 100644 --- a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php @@ -9,20 +9,20 @@ use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Types\OrderStatus; use Mollie\Api\Types\RefundStatus; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class OrderRefundEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testCreatePartialOrderRefund() { $this->mockApiCall( new Request( - "POST", - "/v2/orders/ord_stTC2WHAuS/refunds", + 'POST', + '/v2/orders/ord_stTC2WHAuS/refunds', [], '{ "lines": [ @@ -58,8 +58,8 @@ public function testCreateCompleteOrderRefund() { $this->mockApiCall( new Request( - "POST", - "/v2/orders/ord_stTC2WHAuS/refunds", + 'POST', + '/v2/orders/ord_stTC2WHAuS/refunds', [], '{ "lines": [] @@ -83,8 +83,8 @@ public function testListOrderRefunds() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_stTC2WHAuS/refunds" + 'GET', + '/v2/orders/ord_stTC2WHAuS/refunds' ), new Response( 200, @@ -195,9 +195,9 @@ protected function assertOrderRefund($refund, $refund_id, $refund_status = Refun $this->assertAmountObject('698.00', 'EUR', $refund->amount); $this->assertEquals($refund_status, $refund->status); - $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt); - $this->assertEquals("Item not in stock, refunding", $refund->description); - $this->assertEquals("tr_WDqYK6vllg", $refund->paymentId); + $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); + $this->assertEquals('Item not in stock, refunding', $refund->description); + $this->assertEquals('tr_WDqYK6vllg', $refund->paymentId); $this->assertLinkObject( "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/{$refund_id}", @@ -215,7 +215,7 @@ protected function assertOrderRefund($refund, $refund_id, $refund_status = Refun protected function getOrderRefundResponseFixture($refund_id, $order_id) { return str_replace( - ["<>", "<>"], + ['<>', '<>'], [$refund_id, $order_id], '{ "resource": "refund", @@ -293,7 +293,7 @@ protected function getOrder($id) protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( - "<>", + '<>', $order_id, '{ "resource": "order", @@ -311,7 +311,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu "value": "0.00", "currency": "EUR" }, - "status": "' . $order_status . '", + "status": "'.$order_status.'", "metadata": { "order_id": "1337", "description": "Lego cars" diff --git a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php b/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php index 21cb3f07b..abba0d5dd 100644 --- a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php @@ -5,7 +5,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Organization; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class OrganizationEndpointTest extends BaseEndpointTest { @@ -14,7 +14,7 @@ class OrganizationEndpointTest extends BaseEndpointTest public function testGetOrganization() { $this->mockApiCall( - new Request("GET", "/v2/organizations/org_12345678"), + new Request('GET', '/v2/organizations/org_12345678'), new Response( 200, [], @@ -54,7 +54,7 @@ public function testGetOrganization() public function testGetCurrentOrganization() { $this->mockApiCall( - new Request("GET", "/v2/organizations/me"), + new Request('GET', '/v2/organizations/me'), new Response( 200, [], diff --git a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php index acdb1162d..5b5e1d457 100644 --- a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php @@ -6,15 +6,14 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\Payment; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class PaymentCaptureEndpointTest extends BaseEndpointTest { use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testCreateCaptureForPaymentResource() { $this->mockApiCall( @@ -33,8 +32,8 @@ public function testCreateCaptureForPaymentResource() $this->getPayment('tr_WDqYK6vllg'), [ 'amount' => [ - "value" => "1027.99", - "currency" => "EUR", + 'value' => '1027.99', + 'currency' => 'EUR', ], ] ); @@ -96,7 +95,7 @@ public function testListCapturesOnPaymentResource() '{ "_embedded": { "captures": [ - ' . $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT') . ' + '.$this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT').' ] }, "count": 1, diff --git a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php index 904df9f69..d1e0f0ac2 100644 --- a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php @@ -7,20 +7,20 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Payment; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class PaymentChargebackEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testListChargebacksOnPaymentResource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/chargebacks" + 'GET', + '/v2/payments/tr_44aKxzEbr8/chargebacks' ), new Response( 200, @@ -108,27 +108,27 @@ public function testListChargebacksOnPaymentResource() $this->assertCount(2, $chargebacks); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", - "text/html", + 'https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks', + 'text/html', $chargebacks->_links->documentation ); $this->assertLinkObject( - "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks", - "application/hal+json", + 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks', + 'application/hal+json', $chargebacks->_links->self ); - $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00"); - $this->assertChargeback($chargebacks[1], 'tr_44aKxzEbr8', 'chb_6cqlwf', "-0.37"); + $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00'); + $this->assertChargeback($chargebacks[1], 'tr_44aKxzEbr8', 'chb_6cqlwf', '-0.37'); } public function testGetChargebackOnPaymentResource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp" + 'GET', + '/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp' ), new Response( 200, @@ -164,17 +164,17 @@ public function testGetChargebackOnPaymentResource() ) ); - $chargeback = $this->getPayment()->getChargeback("chb_n9z0tp"); + $chargeback = $this->getPayment()->getChargeback('chb_n9z0tp'); - $this->assertChargeback($chargeback, 'tr_44aKxzEbr8', 'chb_n9z0tp', "-13.00"); + $this->assertChargeback($chargeback, 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00'); } public function testPaymentChargebacksListForIdPaymentChargebackEndpoint() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/chargebacks" + 'GET', + '/v2/payments/tr_44aKxzEbr8/chargebacks' ), new Response( 200, @@ -242,8 +242,8 @@ public function testPaymentChargebacksListForPaymentChargebackEndpoint() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/chargebacks" + 'GET', + '/v2/payments/tr_44aKxzEbr8/chargebacks' ), new Response( 200, @@ -310,30 +310,30 @@ public function testPaymentChargebacksListForPaymentChargebackEndpoint() protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount) { $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals("chargeback", $chargeback->resource); + $this->assertEquals('chargeback', $chargeback->resource); $this->assertEquals($chargebackId, $chargeback->id); - $this->assertAmountObject($amount, "EUR", $chargeback->amount); - $this->assertAmountObject($amount, "EUR", $chargeback->settlementAmount); + $this->assertAmountObject($amount, 'EUR', $chargeback->amount); + $this->assertAmountObject($amount, 'EUR', $chargeback->settlementAmount); - $this->assertEquals("2018-03-28T11:44:32+00:00", $chargeback->createdAt); + $this->assertEquals('2018-03-28T11:44:32+00:00', $chargeback->createdAt); $this->assertEquals($paymentId, $chargeback->paymentId); $this->assertLinkObject( "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}", - "application/hal+json", + 'application/hal+json', $chargeback->_links->self ); $this->assertLinkObject( "https://api.mollie.com/v2/payments/{$paymentId}", - "application/hal+json", + 'application/hal+json', $chargeback->_links->payment ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "text/html", + 'https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback', + 'text/html', $chargeback->_links->documentation ); } diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index a539b58ff..08a8b3f3f 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -9,7 +9,7 @@ use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; use stdClass; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class PaymentEndpointTest extends BaseEndpointTest { @@ -19,8 +19,8 @@ public function testCreatePayment() { $this->mockApiCall( new Request( - "POST", - "/v2/payments", + 'POST', + '/v2/payments', [], '{ "amount":{ @@ -79,47 +79,47 @@ public function testCreatePayment() ); $payment = $this->apiClient->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "20.00", + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', ], - "description" => "My first API payment", - "redirectUrl" => "https://example.org/redirect", - "webhookUrl" => "https://example.org/webhook", - "metadata" => [ - "order_id" => "1234", + 'description' => 'My first API payment', + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + 'metadata' => [ + 'order_id' => '1234', ], ]); $this->assertInstanceOf(Payment::class, $payment); $this->assertEquals('tr_44aKxzEbr8', $payment->id); $this->assertEquals('test', $payment->mode); - $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt); + $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); $amount = new Stdclass(); $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $payment->amount); $this->assertEquals('My first API payment', $payment->description); $this->assertNull($payment->method); - $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); + $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); $this->assertEquals(PaymentStatus::OPEN, $payment->status); $this->assertFalse($payment->isCancelable); - $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt); + $this->assertEquals('2018-03-13T14:17:29+00:00', $payment->expiresAt); $this->assertNull($payment->details); - $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); + $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); - $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); + $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); + $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $payment->_links->self); - $checkoutLink = (object)["href" => "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type" => "text/html"]; + $checkoutLink = (object) ['href' => 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', 'type' => 'text/html']; $this->assertEquals($checkoutLink, $payment->_links->checkout); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/create-payment", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/create-payment', 'type' => 'text/html']; $this->assertEquals($documentationLink, $payment->_links->documentation); } @@ -127,8 +127,8 @@ public function testUpdatePayment() { $this->mockApiCall( new Request( - "PATCH", - "/v2/payments/tr_7UhSN1zuXS", + 'PATCH', + '/v2/payments/tr_7UhSN1zuXS', [], '{ "description":"Order #98765", @@ -188,48 +188,48 @@ public function testUpdatePayment() // Get Payment stub $payment = new Payment($this->apiClient); - $payment->id = "tr_7UhSN1zuXS"; + $payment->id = 'tr_7UhSN1zuXS'; $payment->_links = $this->createNamedLinkObject( - "self", - "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", - "application/json" + 'self', + 'https://api.mollie.com/v2/payments/tr_7UhSN1zuXS', + 'application/json' ); // Modify fields - $payment->description = "Order #98765"; - $payment->redirectUrl = "https://example.org/webshop/order/98765/"; - $payment->webhookUrl = "https://example.org/webshop/payments/webhook/"; - $payment->metadata = ["order_id" => "98765"]; - $payment->cancelUrl = "https://example.org/webshop/order/98765/canceled/"; + $payment->description = 'Order #98765'; + $payment->redirectUrl = 'https://example.org/webshop/order/98765/'; + $payment->webhookUrl = 'https://example.org/webshop/payments/webhook/'; + $payment->metadata = ['order_id' => '98765']; + $payment->cancelUrl = 'https://example.org/webshop/order/98765/canceled/'; $payment = $payment->update(); - $this->assertEquals("payment", $payment->resource); - $this->assertEquals("tr_7UhSN1zuXS", $payment->id); + $this->assertEquals('payment', $payment->resource); + $this->assertEquals('tr_7UhSN1zuXS', $payment->id); - $this->assertEquals("Order #98765", $payment->description); - $this->assertEquals("https://example.org/webshop/order/98765/", $payment->redirectUrl); - $this->assertEquals("https://example.org/webshop/payments/webhook/", $payment->webhookUrl); - $this->assertEquals((object) ["order_id" => "98765"], $payment->metadata); - $this->assertEquals("oneoff", $payment->sequenceType); - $this->assertEquals("pfl_QkEhN94Ba", $payment->profileId); + $this->assertEquals('Order #98765', $payment->description); + $this->assertEquals('https://example.org/webshop/order/98765/', $payment->redirectUrl); + $this->assertEquals('https://example.org/webshop/payments/webhook/', $payment->webhookUrl); + $this->assertEquals((object) ['order_id' => '98765'], $payment->metadata); + $this->assertEquals('oneoff', $payment->sequenceType); + $this->assertEquals('pfl_QkEhN94Ba', $payment->profileId); $this->assertNull($payment->details); $this->assertLinkObject( - "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", - "application/json", + 'https://api.mollie.com/v2/payments/tr_7UhSN1zuXS', + 'application/json', $payment->_links->self ); $this->assertLinkObject( - "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "text/html", + 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', + 'text/html', $payment->_links->checkout ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/payments-api/update-payment", - "text/html", + 'https://docs.mollie.com/reference/v2/payments-api/update-payment', + 'text/html', $payment->_links->documentation ); } @@ -238,8 +238,8 @@ public function testGetPayment() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8?testmode=true", + 'GET', + '/v2/payments/tr_44aKxzEbr8?testmode=true', [], '' ), @@ -299,49 +299,49 @@ public function testGetPayment() ) ); - $payment = $this->apiClient->payments->get("tr_44aKxzEbr8", ["testmode" => true]); + $payment = $this->apiClient->payments->get('tr_44aKxzEbr8', ['testmode' => true]); $this->assertInstanceOf(Payment::class, $payment); $this->assertEquals('tr_44aKxzEbr8', $payment->id); $this->assertEquals('test', $payment->mode); - $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt); + $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); $amount = new Stdclass(); $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $payment->amount); $this->assertEquals('My first API payment', $payment->description); - $this->assertEquals("ideal", $payment->method); - $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); + $this->assertEquals('ideal', $payment->method); + $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); $this->assertEquals(PaymentStatus::PAID, $payment->status); $amountRefunded = new Stdclass(); $amountRefunded->value = '0.00'; - $amountRefunded->currency = "EUR"; + $amountRefunded->currency = 'EUR'; $this->assertEquals($amountRefunded, $payment->amountRefunded); $amountRemaining = new Stdclass(); $amountRemaining->value = '20.00'; - $amountRemaining->currency = "EUR"; + $amountRemaining->currency = 'EUR'; $this->assertEquals($amountRemaining, $payment->amountRemaining); - $details = (object)[ + $details = (object) [ 'consumerName' => 'T. TEST', 'consumerAccount' => 'NL17RABO0213698412', 'consumerBic' => 'TESTNL99', ]; $this->assertEquals($details, $payment->details); - $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); + $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); - $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); + $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); + $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $payment->_links->self); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/get-payment", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/get-payment', 'type' => 'text/html']; $this->assertEquals($documentationLink, $payment->_links->documentation); } @@ -349,8 +349,8 @@ public function testListPayment() { $this->mockApiCall( new Request( - "GET", - "/v2/payments?limit=3", + 'GET', + '/v2/payments?limit=3', [], '' ), @@ -481,15 +481,15 @@ public function testListPayment() $this->assertEquals(3, $payments->count()); $this->assertEquals(3, count($payments)); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/payments-api/list-payments", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/list-payments', 'type' => 'text/html']; $this->assertEquals($documentationLink, $payments->_links->documentation); - $selfLink = (object)["href" => "http://api.mollie.com/v2/payments?limit=3", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'http://api.mollie.com/v2/payments?limit=3', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $payments->_links->self); $this->assertNull($payments->_links->previous); - $nextLink = (object)["href" => "http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3", "type" => "application/hal+json"]; + $nextLink = (object) ['href' => 'http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3', 'type' => 'application/hal+json']; $this->assertEquals($nextLink, $payments->_links->next); } @@ -497,8 +497,8 @@ public function testIteratePayment() { $this->mockApiCall( new Request( - "GET", - "/v2/payments", + 'GET', + '/v2/payments', [], '' ), @@ -622,7 +622,7 @@ public function testIteratePayment() foreach ($this->apiClient->payments->iterator() as $payment) { $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals("payment", $payment->resource); + $this->assertEquals('payment', $payment->resource); } } } diff --git a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php b/tests/Mollie/API/Endpoints/PermissionEndpointTest.php index d745482c1..3aa2b8e39 100644 --- a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PermissionEndpointTest.php @@ -6,32 +6,32 @@ use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class PermissionEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; /** - * @param string $permissionId + * @param string $permissionId * * @dataProvider dpTestGetPermissionIds */ public function testGetPermissionIds($permissionId) { $this->mockApiCall( - new Request('GET', '/v2/permissions/' . $permissionId), + new Request('GET', '/v2/permissions/'.$permissionId), new Response( 200, [], '{ "resource": "permission", - "id": "' . $permissionId . '", + "id": "'.$permissionId.'", "description": "Some dummy permission description", "granted": true, "_links": { "self": { - "href": "https://api.mollie.com/v2/permissions/' . $permissionId . '", + "href": "https://api.mollie.com/v2/permissions/'.$permissionId.'", "type": "application/hal+json" }, "documentation": { @@ -86,7 +86,7 @@ protected function assertPermission($permission, $permissionId) $this->assertTrue($permission->granted); $this->assertLinkObject( - 'https://api.mollie.com/v2/permissions/' . $permissionId, + 'https://api.mollie.com/v2/permissions/'.$permissionId, 'application/hal+json', $permission->_links->self ); diff --git a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php index 31ef34114..0be48de8a 100644 --- a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\CurrentProfile; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\Profile; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class ProfileMethodEndpointTest extends BaseEndpointTest { @@ -17,8 +17,8 @@ public function testEnableProfileMethod() { $this->mockApiCall( new Request( - "POST", - "/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact" + 'POST', + '/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact' ), new Response( 201, @@ -57,14 +57,14 @@ public function testEnableProfileMethod() $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg); $this->assertLinkObject( - "https://api.mollie.com/v2/methods/bancontact", - "application/hal+json", + 'https://api.mollie.com/v2/methods/bancontact', + 'application/hal+json', $method->_links->self ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/profiles-api/activate-method", - "text/html", + 'https://docs.mollie.com/reference/v2/profiles-api/activate-method', + 'text/html', $method->_links->documentation ); } @@ -73,8 +73,8 @@ public function testDisableProfileMethod() { $this->mockApiCall( new Request( - "DELETE", - "/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact" + 'DELETE', + '/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact' ), new Response(204) ); @@ -89,8 +89,8 @@ public function testEnableCurrentProfileMethod() { $this->mockApiCall( new Request( - "POST", - "/v2/profiles/me/methods/bancontact" + 'POST', + '/v2/profiles/me/methods/bancontact' ), new Response( 201, @@ -129,14 +129,14 @@ public function testEnableCurrentProfileMethod() $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg); $this->assertLinkObject( - "https://api.mollie.com/v2/methods/bancontact", - "application/hal+json", + 'https://api.mollie.com/v2/methods/bancontact', + 'application/hal+json', $method->_links->self ); $this->assertLinkObject( - "https://docs.mollie.com/reference/v2/profiles-api/activate-method", - "text/html", + 'https://docs.mollie.com/reference/v2/profiles-api/activate-method', + 'text/html', $method->_links->documentation ); } @@ -145,8 +145,8 @@ public function testDisableCurrentProfileMethod() { $this->mockApiCall( new Request( - "DELETE", - "/v2/profiles/me/methods/bancontact" + 'DELETE', + '/v2/profiles/me/methods/bancontact' ), new Response(204) ); diff --git a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php b/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php index 299417b8e..006c89bb8 100644 --- a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php @@ -9,20 +9,20 @@ use Mollie\Api\Resources\ShipmentCollection; use Mollie\Api\Types\OrderLineStatus; use Mollie\Api\Types\OrderStatus; -use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\AmountObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class ShipmentEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; public function testCreateShipment() { $this->mockApiCall( new Request( - "POST", - "/v2/orders/ord_pbjz8x/shipments", + 'POST', + '/v2/orders/ord_pbjz8x/shipments', [], '{ "lines": [ @@ -39,7 +39,7 @@ public function testCreateShipment() new Response( 201, [], - $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") + $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') ) ); @@ -63,8 +63,8 @@ public function testCreateShipmentUsingShorthand() { $this->mockApiCall( new Request( - "POST", - "/v2/orders/ord_pbjz8x/shipments", + 'POST', + '/v2/orders/ord_pbjz8x/shipments', [], '{ "lines": [] @@ -73,7 +73,7 @@ public function testCreateShipmentUsingShorthand() new Response( 201, [], - $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") + $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') ) ); @@ -87,18 +87,18 @@ public function testGetShipment() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U" + 'GET', + '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U' ), new Response( 200, [], - $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") + $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') ) ); $order = $this->getOrder('ord_pbjz8x'); - $shipment = $this->apiClient->shipments->getFor($order, "shp_3wmsgCJN4U"); + $shipment = $this->apiClient->shipments->getFor($order, 'shp_3wmsgCJN4U'); $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); } @@ -107,13 +107,13 @@ public function testGetShipmentOnOrderResource() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U" + 'GET', + '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U' ), new Response( 200, [], - $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") + $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') ) ); @@ -127,8 +127,8 @@ public function testListShipmentsViaShipmentEndpoint() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x/shipments" + 'GET', + '/v2/orders/ord_pbjz8x/shipments' ), new Response( 200, @@ -137,8 +137,8 @@ public function testListShipmentsViaShipmentEndpoint() "count": 2, "_embedded": { "shipments": [ - ' . $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") . ', - ' . $this->getShipmentResponseFixture("shp_kjh234CASX", "ord_pbjz8x") . ' + '.$this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x').', + '.$this->getShipmentResponseFixture('shp_kjh234CASX', 'ord_pbjz8x').' ] }, "_links": { @@ -167,8 +167,8 @@ public function testListShipmentsOnOrderResource() { $this->mockApiCall( new Request( - "GET", - "/v2/orders/ord_pbjz8x/shipments" + 'GET', + '/v2/orders/ord_pbjz8x/shipments' ), new Response( 200, @@ -177,8 +177,8 @@ public function testListShipmentsOnOrderResource() "count": 2, "_embedded": { "shipments": [ - ' . $this->getShipmentResponseFixture("shp_3wmsgCJN4U", "ord_pbjz8x") . ', - ' . $this->getShipmentResponseFixture("shp_kjh234CASX", "ord_pbjz8x") . ' + '.$this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x').', + '.$this->getShipmentResponseFixture('shp_kjh234CASX', 'ord_pbjz8x').' ] }, "_links": { @@ -208,8 +208,8 @@ public function testUpdateShipmentTrackingInfo() { $this->mockApiCall( new Request( - "PATCH", - "/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U", + 'PATCH', + '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U', [], '{ "tracking": { @@ -223,8 +223,8 @@ public function testUpdateShipmentTrackingInfo() 200, [], $this->getShipmentResponseFixture( - "shp_3wmsgCJN4U", - "ord_pbjz8x", + 'shp_3wmsgCJN4U', + 'ord_pbjz8x', OrderLineStatus::SHIPPING, '"tracking": { "carrier": "PostNL", @@ -256,7 +256,7 @@ public function testUpdateShipmentTrackingInfo() protected function assertShipment($shipment, $shipment_id, $order_id) { $this->assertInstanceOf(Shipment::class, $shipment); - $this->assertEquals("shipment", $shipment->resource); + $this->assertEquals('shipment', $shipment->resource); $this->assertEquals($shipment_id, $shipment->id); $this->assertEquals($order_id, $shipment->orderId); $this->assertEquals('2018-08-02T09:29:56+00:00', $shipment->createdAt); @@ -329,7 +329,7 @@ protected function getShipment($shipment_id, $order_id, $orderLineStatus = Order protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) { return str_replace( - "<>", + '<>', $order_id, '{ "resource": "order", @@ -346,7 +346,7 @@ protected function getOrderResponseFixture($order_id, $order_status = OrderStatu "value": "0.00", "currency": "EUR" }, - "status": "' . $order_status . '", + "status": "'.$order_status.'", "metadata": { "order_id": "1337", "description": "Lego cars" @@ -469,10 +469,10 @@ protected function getShipmentResponseFixture($shipment_id, $order_id, $orderlin { return str_replace( [ - "<>", - "<>", - "<>", - "<>", + '<>', + '<>', + '<>', + '<>', ], [ $order_id, diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index 6a5cbf98d..37480592b 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; use Mollie\Api\Types\TerminalStatus; -use Tests\Mollie\TestHelpers\LinkObjectTestHelpers; +use Tests\Fixtures\Traits\LinkObjectTestHelpers; class TerminalEndpointTest extends BaseEndpointTest { @@ -17,8 +17,8 @@ public function testGetTerminal() { $this->mockApiCall( new Request( - "GET", - "/v2/terminals/term_7MgL4wea46qkRcoTZjWEH?testmode=true", + 'GET', + '/v2/terminals/term_7MgL4wea46qkRcoTZjWEH?testmode=true', [], '' ), @@ -53,7 +53,7 @@ public function testGetTerminal() ) ); - $terminal = $this->apiClient->terminals->get("term_7MgL4wea46qkRcoTZjWEH", ["testmode" => true]); + $terminal = $this->apiClient->terminals->get('term_7MgL4wea46qkRcoTZjWEH', ['testmode' => true]); $this->assertInstanceOf(Terminal::class, $terminal); $this->assertEquals('term_7MgL4wea46qkRcoTZjWEH', $terminal->id); @@ -70,7 +70,7 @@ public function testGetTerminal() $this->assertEquals('2022-11-15T13:32:11+00:00', $terminal->updatedAt); $this->assertEquals('2022-02-12T12:13:35.0Z', $terminal->activatedAt); - $this->assertLinkObject("https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", 'application/hal+json', $terminal->_links->self); + $this->assertLinkObject('https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH', 'application/hal+json', $terminal->_links->self); $this->assertLinkObject('https://docs.mollie.com/reference/v2/terminals-api/get-terminal', 'text/html', $terminal->_links->documentation); } @@ -78,8 +78,8 @@ public function testListTerminal() { $this->mockApiCall( new Request( - "GET", - "/v2/terminals?limit=3", + 'GET', + '/v2/terminals?limit=3', [], '' ), @@ -194,8 +194,8 @@ public function testIterateTerminal() { $this->mockApiCall( new Request( - "GET", - "/v2/terminals", + 'GET', + '/v2/terminals', [], '' ), @@ -292,7 +292,7 @@ public function testIterateTerminal() foreach ($this->apiClient->terminals->iterator() as $terminal) { $this->assertInstanceOf(Terminal::class, $terminal); - $this->assertEquals("terminal", $terminal->resource); + $this->assertEquals('terminal', $terminal->resource); } } } diff --git a/tests/Mollie/API/Exceptions/ApiExceptionTest.php b/tests/Mollie/API/Exceptions/ApiExceptionTest.php deleted file mode 100644 index c9d8a4896..000000000 --- a/tests/Mollie/API/Exceptions/ApiExceptionTest.php +++ /dev/null @@ -1,52 +0,0 @@ -assertJsonStringEqualsJsonString(/** @lang JSON */'{ "foo": "bar" }', $exception->getRequest()->getBody()->__toString()); - $this->assertStringEndsWith('Error executing API call (422: Unprocessable Entity): Can not enable Credit card via the API. Please go to the dashboard to enable this payment method.. Documentation: https://docs.mollie.com/guides/handling-errors. Request body: { "foo": "bar" }', $exception->getMessage()); - $this->assertEquals('Error executing API call (422: Unprocessable Entity): Can not enable Credit card via the API. Please go to the dashboard to enable this payment method.', $exception->getPlainMessage()); - } -} diff --git a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php b/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php deleted file mode 100644 index 859db24c1..000000000 --- a/tests/Mollie/API/HttpAdapter/MockMollieHttpAdapter.php +++ /dev/null @@ -1,44 +0,0 @@ - 'bar']; - } - - public function status(): int - { - return 200; - } - - public function body(): string - { - return 'foo'; - } - - public function isEmpty(): bool - { - return false; - } - }; - } - - /** - * @inheritDoc - */ - public function version(): string - { - return 'mock-client/1.0'; - } -} diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php index b726c8790..0d7385c8f 100644 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ b/tests/Mollie/API/Resources/CursorCollectionTest.php @@ -11,11 +11,12 @@ class CursorCollectionTest extends TestCase { - public function testCanGetNextCollectionResultWhenNextLinkIsAvailable() + /** @test */ + public function can_get_next_collection_result_when_next_link_is_available() { $mockedClient = $this->createMock(MollieApiClient::class); $mockedClient->expects($this->once()) - ->method('performHttpCallToFullUrl') + ->method('send') ->willReturn($this->arrayToResponse([ 'count' => 1, '_links' => [ @@ -200,7 +201,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() /** * Convert an array to an object recursively. * - * @param mixed $data + * @param mixed $data * @return mixed */ private function arrayToObject($data) @@ -209,7 +210,7 @@ private function arrayToObject($data) return $data; } - $obj = new stdClass(); + $obj = new stdClass; foreach ($data as $key => $value) { $obj->$key = $this->arrayToObject($value); diff --git a/tests/Mollie/API/Resources/InvoiceTest.php b/tests/Mollie/API/Resources/InvoiceTest.php deleted file mode 100644 index 15abef3cb..000000000 --- a/tests/Mollie/API/Resources/InvoiceTest.php +++ /dev/null @@ -1,43 +0,0 @@ -createMock(MollieApiClient::class)); - $invoice->status = $status; - - $this->assertEquals($expected_boolean, $invoice->{$function}()); - } - - public function dpTestInvoiceStatuses() - { - return [ - [InvoiceStatus::PAID, "isPaid", true], - [InvoiceStatus::PAID, "isOpen", false], - [InvoiceStatus::PAID, "isOverdue", false], - - [InvoiceStatus::OPEN, "isPaid", false], - [InvoiceStatus::OPEN, "isOpen", true], - [InvoiceStatus::OPEN, "isOverdue", false], - - [InvoiceStatus::OVERDUE, "isPaid", false], - [InvoiceStatus::OVERDUE, "isOpen", false], - [InvoiceStatus::OVERDUE, "isOverdue", true], - ]; - } -} diff --git a/tests/Mollie/API/Resources/OnboardingTest.php b/tests/Mollie/API/Resources/OnboardingTest.php deleted file mode 100644 index af9d9ddde..000000000 --- a/tests/Mollie/API/Resources/OnboardingTest.php +++ /dev/null @@ -1,42 +0,0 @@ -createMock(MollieApiClient::class)); - $orderLine->status = $status; - - $this->assertEquals($expected_boolean, $orderLine->{$function}()); - } - - public function dpTestOnboardingStatuses() - { - return [ - [OnboardingStatus::NEEDS_DATA, "needsData", true], - [OnboardingStatus::NEEDS_DATA, "isInReview", false], - [OnboardingStatus::NEEDS_DATA, "isCompleted", false], - - [OnboardingStatus::IN_REVIEW, "needsData", false], - [OnboardingStatus::IN_REVIEW, "isInReview", true], - [OnboardingStatus::IN_REVIEW, "isCompleted", false], - - [OnboardingStatus::COMPLETED, "needsData", false], - [OnboardingStatus::COMPLETED, "isInReview", false], - [OnboardingStatus::COMPLETED, "isCompleted", true], - ]; - } -} diff --git a/tests/Mollie/API/Resources/OrderLineTest.php b/tests/Mollie/API/Resources/OrderLineTest.php deleted file mode 100644 index 373e1152c..000000000 --- a/tests/Mollie/API/Resources/OrderLineTest.php +++ /dev/null @@ -1,172 +0,0 @@ -createMock(MollieApiClient::class)); - $orderLine->status = $status; - - $this->assertEquals($expected_boolean, $orderLine->{$function}()); - } - - /** - * @param string $type - * @param string $function - * @param bool $expected_boolean - * - * @dataProvider dpTestOrderLineTypes - */ - public function testOrderLineTypes($type, $function, $expected_boolean) - { - $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); - $orderLine->type = $type; - - $this->assertEquals($expected_boolean, $orderLine->{$function}()); - } - - /** - * @param string $vatRate - * @param bool $expected_boolean - * - * @dataProvider dpTestUpdateVatRate - */ - public function testUpdateVatRate($vatRate, $expected_boolean) - { - $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); - $orderLine->vatRate = $vatRate; - - $this->assertEquals(isset($orderLine->getUpdateData()['vatRate']), $expected_boolean); - } - - public function dpTestUpdateVatRate() - { - return [ - [0, true], - ['0', true], - [null, false], - ]; - } - - public function dpTestOrderLineTypes() - { - return [ - [OrderLineType::PHYSICAL, "isPhysical", true], - [OrderLineType::PHYSICAL, "isDiscount", false], - [OrderLineType::PHYSICAL, "isDigital", false], - [OrderLineType::PHYSICAL, "isShippingFee", false], - [OrderLineType::PHYSICAL, "isStoreCredit", false], - [OrderLineType::PHYSICAL, "isGiftCard", false], - [OrderLineType::PHYSICAL, "isSurcharge", false], - - [OrderLineType::DISCOUNT, "isPhysical", false], - [OrderLineType::DISCOUNT, "isDiscount", true], - [OrderLineType::DISCOUNT, "isDigital", false], - [OrderLineType::DISCOUNT, "isShippingFee", false], - [OrderLineType::DISCOUNT, "isStoreCredit", false], - [OrderLineType::DISCOUNT, "isGiftCard", false], - [OrderLineType::DISCOUNT, "isSurcharge", false], - - [OrderLineType::DIGITAL, "isPhysical", false], - [OrderLineType::DIGITAL, "isDiscount", false], - [OrderLineType::DIGITAL, "isDigital", true], - [OrderLineType::DIGITAL, "isShippingFee", false], - [OrderLineType::DIGITAL, "isStoreCredit", false], - [OrderLineType::DIGITAL, "isGiftCard", false], - [OrderLineType::DIGITAL, "isSurcharge", false], - - [OrderLineType::SHIPPING_FEE, "isPhysical", false], - [OrderLineType::SHIPPING_FEE, "isDiscount", false], - [OrderLineType::SHIPPING_FEE, "isDigital", false], - [OrderLineType::SHIPPING_FEE, "isShippingFee", true], - [OrderLineType::SHIPPING_FEE, "isStoreCredit", false], - [OrderLineType::SHIPPING_FEE, "isGiftCard", false], - [OrderLineType::SHIPPING_FEE, "isSurcharge", false], - - [OrderLineType::STORE_CREDIT, "isPhysical", false], - [OrderLineType::STORE_CREDIT, "isDiscount", false], - [OrderLineType::STORE_CREDIT, "isDigital", false], - [OrderLineType::STORE_CREDIT, "isShippingFee", false], - [OrderLineType::STORE_CREDIT, "isStoreCredit", true], - [OrderLineType::STORE_CREDIT, "isGiftCard", false], - [OrderLineType::STORE_CREDIT, "isSurcharge", false], - - [OrderLineType::GIFT_CARD, "isPhysical", false], - [OrderLineType::GIFT_CARD, "isDiscount", false], - [OrderLineType::GIFT_CARD, "isDigital", false], - [OrderLineType::GIFT_CARD, "isShippingFee", false], - [OrderLineType::GIFT_CARD, "isStoreCredit", false], - [OrderLineType::GIFT_CARD, "isGiftCard", true], - [OrderLineType::GIFT_CARD, "isSurcharge", false], - - [OrderLineType::SURCHARGE, "isPhysical", false], - [OrderLineType::SURCHARGE, "isDiscount", false], - [OrderLineType::SURCHARGE, "isDigital", false], - [OrderLineType::SURCHARGE, "isShippingFee", false], - [OrderLineType::SURCHARGE, "isStoreCredit", false], - [OrderLineType::SURCHARGE, "isGiftCard", false], - [OrderLineType::SURCHARGE, "isSurcharge", true], - ]; - } - - public function dpTestOrderLineStatuses() - { - return [ - [OrderLineStatus::CREATED, "isCreated", true], - [OrderLineStatus::CREATED, "isPaid", false], - [OrderLineStatus::CREATED, "isAuthorized", false], - [OrderLineStatus::CREATED, "isCanceled", false], - [OrderLineStatus::CREATED, "isShipping", false], - [OrderLineStatus::CREATED, "isCompleted", false], - - [OrderLineStatus::PAID, "isCreated", false], - [OrderLineStatus::PAID, "isPaid", true], - [OrderLineStatus::PAID, "isAuthorized", false], - [OrderLineStatus::PAID, "isCanceled", false], - [OrderLineStatus::PAID, "isShipping", false], - [OrderLineStatus::PAID, "isCompleted", false], - - [OrderLineStatus::AUTHORIZED, "isCreated", false], - [OrderLineStatus::AUTHORIZED, "isPaid", false], - [OrderLineStatus::AUTHORIZED, "isAuthorized", true], - [OrderLineStatus::AUTHORIZED, "isCanceled", false], - [OrderLineStatus::AUTHORIZED, "isShipping", false], - [OrderLineStatus::AUTHORIZED, "isCompleted", false], - - [OrderLineStatus::CANCELED, "isCreated", false], - [OrderLineStatus::CANCELED, "isPaid", false], - [OrderLineStatus::CANCELED, "isAuthorized", false], - [OrderLineStatus::CANCELED, "isCanceled", true], - [OrderLineStatus::CANCELED, "isShipping", false], - [OrderLineStatus::CANCELED, "isCompleted", false], - - [OrderLineStatus::SHIPPING, "isCreated", false], - [OrderLineStatus::SHIPPING, "isPaid", false], - [OrderLineStatus::SHIPPING, "isAuthorized", false], - [OrderLineStatus::SHIPPING, "isCanceled", false], - [OrderLineStatus::SHIPPING, "isShipping", true], - [OrderLineStatus::SHIPPING, "isCompleted", false], - - [OrderLineStatus::COMPLETED, "isCreated", false], - [OrderLineStatus::COMPLETED, "isPaid", false], - [OrderLineStatus::COMPLETED, "isAuthorized", false], - [OrderLineStatus::COMPLETED, "isCanceled", false], - [OrderLineStatus::COMPLETED, "isShipping", false], - [OrderLineStatus::COMPLETED, "isCompleted", true], - ]; - } -} diff --git a/tests/Mollie/API/Resources/ProfileTest.php b/tests/Mollie/API/Resources/ProfileTest.php deleted file mode 100644 index 57af90667..000000000 --- a/tests/Mollie/API/Resources/ProfileTest.php +++ /dev/null @@ -1,42 +0,0 @@ -createMock(MollieApiClient::class)); - $profile->status = $status; - - $this->assertEquals($expected_boolean, $profile->{$function}()); - } - - public function dpTestProfileStatusses() - { - return [ - [ProfileStatus::BLOCKED, "isBlocked", true], - [ProfileStatus::BLOCKED, "isVerified", false], - [ProfileStatus::BLOCKED, "isUnverified", false], - - [ProfileStatus::VERIFIED, "isBlocked", false], - [ProfileStatus::VERIFIED, "isVerified", true], - [ProfileStatus::VERIFIED, "isUnverified", false], - - [ProfileStatus::UNVERIFIED, "isBlocked", false], - [ProfileStatus::UNVERIFIED, "isVerified", false], - [ProfileStatus::UNVERIFIED, "isUnverified", true], - ]; - } -} diff --git a/tests/Mollie/API/Resources/RefundTest.php b/tests/Mollie/API/Resources/RefundTest.php deleted file mode 100644 index 1f95bb39d..000000000 --- a/tests/Mollie/API/Resources/RefundTest.php +++ /dev/null @@ -1,86 +0,0 @@ -createMock(MollieApiClient::class)); - $refund->status = $status; - - $this->assertEquals($expected_boolean, $refund->{$function}()); - } - - /** - * @param string $status - * @param bool $expected_boolean - * - * @dataProvider dpTestRefundCanBeCanceled - */ - public function testRefundCanBeCanceled($status, $expected_boolean) - { - $refund = new Refund($this->createMock(MollieApiClient::class)); - $refund->status = $status; - - $this->assertEquals($expected_boolean, $refund->canBeCanceled()); - } - - public function dpTestRefundStatuses() - { - return [ - [RefundStatus::PENDING, "isPending", true], - [RefundStatus::PENDING, "isProcessing", false], - [RefundStatus::PENDING, "isQueued", false], - [RefundStatus::PENDING, "isTransferred", false], - [RefundStatus::PENDING, "isFailed", false], - - [RefundStatus::PROCESSING, "isPending", false], - [RefundStatus::PROCESSING, "isProcessing", true], - [RefundStatus::PROCESSING, "isQueued", false], - [RefundStatus::PROCESSING, "isTransferred", false], - [RefundStatus::PROCESSING, "isFailed", false], - - [RefundStatus::QUEUED, "isPending", false], - [RefundStatus::QUEUED, "isProcessing", false], - [RefundStatus::QUEUED, "isQueued", true], - [RefundStatus::QUEUED, "isTransferred", false], - [RefundStatus::QUEUED, "isFailed", false], - - [RefundStatus::REFUNDED, "isPending", false], - [RefundStatus::REFUNDED, "isProcessing", false], - [RefundStatus::REFUNDED, "isQueued", false], - [RefundStatus::REFUNDED, "isTransferred", true], - [RefundStatus::REFUNDED, "isFailed", false], - - [RefundStatus::FAILED, "isPending", false], - [RefundStatus::FAILED, "isProcessing", false], - [RefundStatus::FAILED, "isQueued", false], - [RefundStatus::FAILED, "isTransferred", false], - [RefundStatus::FAILED, "isFailed", true], - ]; - } - - public function dpTestRefundCanBeCanceled() - { - return [ - [RefundStatus::PENDING, true], - [RefundStatus::PROCESSING, false], - [RefundStatus::QUEUED, true], - [RefundStatus::REFUNDED, false], - [RefundStatus::FAILED, false], - [RefundStatus::CANCELED, false], - ]; - } -} diff --git a/tests/Mollie/API/Resources/SettlementTest.php b/tests/Mollie/API/Resources/SettlementTest.php deleted file mode 100644 index 060b81c5b..000000000 --- a/tests/Mollie/API/Resources/SettlementTest.php +++ /dev/null @@ -1,50 +0,0 @@ -createMock(MollieApiClient::class)); - $settlement->status = $status; - - $this->assertEquals($expected_boolean, $settlement->{$function}()); - } - - public function dpTestSettlementStatuses() - { - return [ - [SettlementStatus::PENDING, "isPending", true], - [SettlementStatus::PENDING, "isOpen", false], - [SettlementStatus::PENDING, "isPaidout", false], - [SettlementStatus::PENDING, "isFailed", false], - - [SettlementStatus::OPEN, "isPending", false], - [SettlementStatus::OPEN, "isOpen", true], - [SettlementStatus::OPEN, "isPaidout", false], - [SettlementStatus::OPEN, "isFailed", false], - - [SettlementStatus::PAIDOUT, "isPending", false], - [SettlementStatus::PAIDOUT, "isOpen", false], - [SettlementStatus::PAIDOUT, "isPaidout", true], - [SettlementStatus::PAIDOUT, "isFailed", false], - - [SettlementStatus::FAILED, "isPending", false], - [SettlementStatus::FAILED, "isOpen", false], - [SettlementStatus::FAILED, "isPaidout", false], - [SettlementStatus::FAILED, "isFailed", true], - ]; - } -} diff --git a/tests/Mollie/API/Resources/SubscriptionTest.php b/tests/Mollie/API/Resources/SubscriptionTest.php deleted file mode 100644 index 9f5fb08b5..000000000 --- a/tests/Mollie/API/Resources/SubscriptionTest.php +++ /dev/null @@ -1,60 +0,0 @@ -createMock(MollieApiClient::class)); - $subscription->status = $status; - - $this->assertEquals($expected_boolean, $subscription->{$function}()); - } - - public function dpTestSubscriptionStatuses() - { - return [ - [SubscriptionStatus::PENDING, "isPending", true], - [SubscriptionStatus::PENDING, "isCanceled", false], - [SubscriptionStatus::PENDING, "isCompleted", false], - [SubscriptionStatus::PENDING, "isSuspended", false], - [SubscriptionStatus::PENDING, "isActive", false], - - [SubscriptionStatus::CANCELED, "isPending", false], - [SubscriptionStatus::CANCELED, "isCanceled", true], - [SubscriptionStatus::CANCELED, "isCompleted", false], - [SubscriptionStatus::CANCELED, "isSuspended", false], - [SubscriptionStatus::CANCELED, "isActive", false], - - [SubscriptionStatus::COMPLETED, "isPending", false], - [SubscriptionStatus::COMPLETED, "isCanceled", false], - [SubscriptionStatus::COMPLETED, "isCompleted", true], - [SubscriptionStatus::COMPLETED, "isSuspended", false], - [SubscriptionStatus::COMPLETED, "isActive", false], - - [SubscriptionStatus::SUSPENDED, "isPending", false], - [SubscriptionStatus::SUSPENDED, "isCanceled", false], - [SubscriptionStatus::SUSPENDED, "isCompleted", false], - [SubscriptionStatus::SUSPENDED, "isSuspended", true], - [SubscriptionStatus::SUSPENDED, "isActive", false], - - [SubscriptionStatus::ACTIVE, "isPending", false], - [SubscriptionStatus::ACTIVE, "isCanceled", false], - [SubscriptionStatus::ACTIVE, "isCompleted", false], - [SubscriptionStatus::ACTIVE, "isSuspended", false], - [SubscriptionStatus::ACTIVE, "isActive", true], - ]; - } -} diff --git a/tests/Mollie/TestHelpers/FakeHttpAdapter.php b/tests/Mollie/TestHelpers/FakeHttpAdapter.php deleted file mode 100644 index 0a2866d92..000000000 --- a/tests/Mollie/TestHelpers/FakeHttpAdapter.php +++ /dev/null @@ -1,88 +0,0 @@ -response = $response; - } - - /** - * @param string $method - * @param string $url - * @param array $headers - * @param string $body - * @return ResponseContract - */ - public function send(string $method, string $url, $headers, ?string $body): ResponseContract - { - $this->usedMethod = $method; - $this->usedUrl = $url; - $this->usedHeaders = $headers; - $this->usedBody = $body; - - return PsrResponseHandler::create() - ->handle(null, $this->response, 200, $body); - } - - /** - * @return string - */ - public function version(): string - { - return 'fake'; - } - - /** - * @return mixed - */ - public function getUsedMethod() - { - return $this->usedMethod; - } - - /** - * @return mixed - */ - public function getUsedUrl() - { - return $this->usedUrl; - } - - /** - * @return mixed - */ - public function getUsedHeaders() - { - return $this->usedHeaders; - } - - /** - * @return mixed - */ - public function getUsedBody() - { - return $this->usedBody; - } -} diff --git a/tests/Mollie/API/MollieApiClientTest.php b/tests/MollieApiClientTest.php similarity index 58% rename from tests/Mollie/API/MollieApiClientTest.php rename to tests/MollieApiClientTest.php index f06792b73..601b13a7a 100644 --- a/tests/Mollie/API/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -1,117 +1,79 @@ guzzleClient = $this->createMock(Client::class); - $this->mollieApiClient = new MollieApiClient($this->guzzleClient); - - $this->mollieApiClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - } - - public function testPerformHttpCallReturnsBodyAsObject() - { - $response = new Response(200, [], '{"resource": "payment"}'); - - $this->guzzleClient - ->expects($this->once()) - ->method('send') - ->willReturn($response); + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), + ]); - - $parsedResponse = $this->mollieApiClient->performHttpCall('GET', ''); + $response = $client->send(new DynamicGetRequest('')); $this->assertEquals( - (object)['resource' => 'payment'], - $parsedResponse->decode() + (object) ['resource' => 'payment'], + $response->json() ); } - public function testPerformHttpCallCreatesApiExceptionCorrectly() + public function testSendCreatesApiExceptionCorrectly() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); $this->expectExceptionCode(422); - $response = new Response(422, [], '{ - "status": 422, - "title": "Unprocessable Entity", - "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?", - "field": "recurringType", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/guides/handling-errors", - "type": "text/html" - } - } - }'); - - $this->guzzleClient - ->expects($this->once()) - ->method('send') - ->willReturn($response); + $client = new MockClient([ + DynamicGetRequest::class => $mockResponse = new MockResponse(422, 'unprocessable-entity-with-field'), + ]); try { - $this->mollieApiClient->performHttpCall('GET', ''); + $client->send(new DynamicGetRequest('')); } catch (ApiException $e) { $this->assertEquals('recurringType', $e->getField()); $this->assertEquals('https://docs.mollie.com/guides/handling-errors', $e->getDocumentationUrl()); - $this->assertEquals($response, $e->getResponse()); + + $mockResponse->assertResponseBodyEquals($e->getResponse()); throw $e; } } - public function testPerformHttpCallCreatesApiExceptionWithoutFieldAndDocumentationUrl() + public function testSendCreatesApiExceptionWithoutFieldAndDocumentationUrl() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); $this->expectExceptionCode(422); - $response = new Response(422, [], '{ - "status": 422, - "title": "Unprocessable Entity", - "detail": "Non-existent parameter \"recurringType\" for this API call. Did you mean: \"sequenceType\"?" - }'); - - $this->guzzleClient - ->expects($this->once()) - ->method('send') - ->willReturn($response); + $client = new MockClient([ + DynamicGetRequest::class => $mockResponse = new MockResponse(422, 'unprocessable-entity'), + ]); try { - $parsedResponse = $this->mollieApiClient->performHttpCall('GET', ''); + $client->send(new DynamicGetRequest('')); } catch (ApiException $e) { $this->assertNull($e->getField()); $this->assertNull($e->getDocumentationUrl()); - $this->assertEquals($response, $e->getResponse()); + $mockResponse->assertResponseBodyEquals($e->getResponse()); throw $e; } @@ -119,21 +81,20 @@ public function testPerformHttpCallCreatesApiExceptionWithoutFieldAndDocumentati public function testCanBeSerializedAndUnserialized() { - $client = new FakeMollieApiClient($this->createMock(Client::class)); + $client = new MollieApiClient($this->createMock(Client::class)); $client->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $client->setApiEndpoint("https://mymollieproxy.local"); + $client->setApiEndpoint('https://mymollieproxy.local'); $serialized = \serialize($client); - $this->assertStringNotContainsString('test_foobarfoobarfoobarfoobarfoobar', $serialized, "API key should not be in serialized data or it will end up in caches."); + $this->assertStringNotContainsString('test_foobarfoobarfoobarfoobarfoobar', $serialized, 'API key should not be in serialized data or it will end up in caches.'); - /** @var FakeMollieApiClient $client_copy */ + /** @var MollieApiClient $client_copy */ $client_copy = unserialize($serialized); - $this->assertEmpty($client_copy->getApiKey(), "API key should not have been remembered"); - $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->getHttpClient(), "A Guzzle client should have been set."); - $this->assertNull($client_copy->usesOAuth()); - $this->assertEquals("https://mymollieproxy.local", $client_copy->getApiEndpoint(), "The API endpoint should be remembered"); + $this->assertEmpty($client_copy->getAuthenticator(), 'Authenticator should not have been remembered'); + $this->assertInstanceOf(GuzzleMollieHttpAdapter::class, $client_copy->getHttpClient(), 'A Guzzle client should have been set.'); + $this->assertEquals('https://mymollieproxy.local', $client_copy->getApiEndpoint(), 'The API endpoint should be remembered'); $this->assertNotEmpty($client_copy->customerPayments); $this->assertNotEmpty($client_copy->payments); @@ -141,31 +102,6 @@ public function testCanBeSerializedAndUnserialized() // no need to assert them all. } - public function testResponseBodyCanBeReadMultipleTimesIfMiddlewareReadsItFirst() - { - $response = new Response(200, [], '{"resource": "payment"}'); - - // Before the MollieApiClient gets the response, some middleware reads the body first. - $bodyAsReadFromMiddleware = (string) $response->getBody(); - - $this->guzzleClient - ->expects($this->once()) - ->method('send') - ->willReturn($response); - - $parsedResponse = $this->mollieApiClient->performHttpCall('GET', ''); - - $this->assertEquals( - '{"resource": "payment"}', - $bodyAsReadFromMiddleware - ); - - $this->assertEquals( - (object)['resource' => 'payment'], - $parsedResponse->decode() - ); - } - public function testEnablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSupportIt() { $this->expectException(HttpAdapterDoesNotSupportDebuggingException::class); @@ -190,25 +126,27 @@ public function testDisablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSuppo */ public function testCorrectRequestHeaders() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client = new MockClient([ + CreatePaymentRequest::class => new MockResponse(200, '{"resource": "payment"}'), + ]); - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); + $client->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $mollieClient->performHttpCallToFullUrl('GET', '', ''); + $response = $client->send(new CreatePaymentRequest(new CreatePayment( + 'test', + new Money('EUR', '100.00'), + ))); - $usedHeaders = $fakeAdapter->getUsedHeaders(); + $usedHeaders = $response->getResponse()->getPendingRequest()->headers()->all(); - # these change through environments - # just make sure its existing + // these change through environments + // just make sure its existing $this->assertArrayHasKey('User-Agent', $usedHeaders); $this->assertArrayHasKey('X-Mollie-Client-Info', $usedHeaders); - # these should be exactly the expected values + // these should be exactly the expected values $this->assertEquals('Bearer test_foobarfoobarfoobarfoobarfoobar', $usedHeaders['Authorization']); $this->assertEquals('application/json', $usedHeaders['Accept']); - $this->assertEquals('application/json', $usedHeaders['Content-Type']); } /** @@ -222,15 +160,14 @@ public function testCorrectRequestHeaders() */ public function testNoContentTypeWithoutProvidedBody() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); - - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(204, ''), + ]); - $mollieClient->performHttpCallToFullUrl('GET', ''); + /** @var HttpResponse $response */ + $response = $client->send(new DynamicGetRequest('')); - $this->assertEquals(false, isset($fakeAdapter->getUsedHeaders()['Content-Type'])); + $this->assertEquals(false, $response->getPendingRequest()->headers()->get('Content-Type')); } public function testIfNoIdempotencyKeyIsSetNoReferenceIsIncludedInTheRequestHeaders() @@ -302,8 +239,8 @@ public function testItUsesTheIdempotencyKeyGenerator() } /** - * @param $httpMethod * @return void + * * @throws \Mollie\Api\Exceptions\ApiException * @throws \Mollie\Api\Exceptions\IncompatiblePlatform * @throws \Mollie\Api\Exceptions\UnrecognizedClientException @@ -323,16 +260,3 @@ private function assertIdempotencyKeyIsUsedForMethod($httpMethod) $this->assertEquals('idempotentFooBar', $fakeAdapter->getUsedHeaders()['Idempotency-Key']); } } - -class FakeMollieApiClient extends MollieApiClient -{ - public function getApiKey(): string - { - return $this->apiKey; - } - - public function getHttpClient(): MollieHttpAdapterContract - { - return $this->httpClient; - } -} diff --git a/tests/Resources/InvoiceTest.php b/tests/Resources/InvoiceTest.php new file mode 100644 index 000000000..711b0f580 --- /dev/null +++ b/tests/Resources/InvoiceTest.php @@ -0,0 +1,43 @@ +createMock(MollieApiClient::class)); + $invoice->status = $status; + + $this->assertEquals($expected_boolean, $invoice->{$function}()); + } + + public function dpTestInvoiceStatuses() + { + return [ + [InvoiceStatus::PAID, 'isPaid', true], + [InvoiceStatus::PAID, 'isOpen', false], + [InvoiceStatus::PAID, 'isOverdue', false], + + [InvoiceStatus::OPEN, 'isPaid', false], + [InvoiceStatus::OPEN, 'isOpen', true], + [InvoiceStatus::OPEN, 'isOverdue', false], + + [InvoiceStatus::OVERDUE, 'isPaid', false], + [InvoiceStatus::OVERDUE, 'isOpen', false], + [InvoiceStatus::OVERDUE, 'isOverdue', true], + ]; + } +} diff --git a/tests/Mollie/API/Resources/LazyCollectionTest.php b/tests/Resources/LazyCollectionTest.php similarity index 98% rename from tests/Mollie/API/Resources/LazyCollectionTest.php rename to tests/Resources/LazyCollectionTest.php index 726c76bc5..74164fbcd 100644 --- a/tests/Mollie/API/Resources/LazyCollectionTest.php +++ b/tests/Resources/LazyCollectionTest.php @@ -1,6 +1,6 @@ every(function ($value, $key) { $this->assertEquals($value, $this->collection->get($key) * 2); diff --git a/tests/Mollie/API/Resources/MandateCollectionTest.php b/tests/Resources/MandateCollectionTest.php similarity index 96% rename from tests/Mollie/API/Resources/MandateCollectionTest.php rename to tests/Resources/MandateCollectionTest.php index bae0f8044..834d6c9c4 100644 --- a/tests/Mollie/API/Resources/MandateCollectionTest.php +++ b/tests/Resources/MandateCollectionTest.php @@ -1,6 +1,6 @@ createMock(MollieApiClient::class)); + $orderLine->status = $status; + + $this->assertEquals($expected_boolean, $orderLine->{$function}()); + } + + public function dpTestOnboardingStatuses() + { + return [ + [OnboardingStatus::NEEDS_DATA, 'needsData', true], + [OnboardingStatus::NEEDS_DATA, 'isInReview', false], + [OnboardingStatus::NEEDS_DATA, 'isCompleted', false], + + [OnboardingStatus::IN_REVIEW, 'needsData', false], + [OnboardingStatus::IN_REVIEW, 'isInReview', true], + [OnboardingStatus::IN_REVIEW, 'isCompleted', false], + + [OnboardingStatus::COMPLETED, 'needsData', false], + [OnboardingStatus::COMPLETED, 'isInReview', false], + [OnboardingStatus::COMPLETED, 'isCompleted', true], + ]; + } +} diff --git a/tests/Mollie/API/Resources/OrderLineCollectionTest.php b/tests/Resources/OrderLineCollectionTest.php similarity index 95% rename from tests/Mollie/API/Resources/OrderLineCollectionTest.php rename to tests/Resources/OrderLineCollectionTest.php index cb874f58f..d52ab3385 100644 --- a/tests/Mollie/API/Resources/OrderLineCollectionTest.php +++ b/tests/Resources/OrderLineCollectionTest.php @@ -1,6 +1,6 @@ createMock(MollieApiClient::class)); + $orderLine->status = $status; + + $this->assertEquals($expected_boolean, $orderLine->{$function}()); + } + + /** + * @param string $type + * @param string $function + * @param bool $expected_boolean + * + * @dataProvider dpTestOrderLineTypes + */ + public function testOrderLineTypes($type, $function, $expected_boolean) + { + $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); + $orderLine->type = $type; + + $this->assertEquals($expected_boolean, $orderLine->{$function}()); + } + + /** + * @param string $vatRate + * @param bool $expected_boolean + * + * @dataProvider dpTestUpdateVatRate + */ + public function testUpdateVatRate($vatRate, $expected_boolean) + { + $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); + $orderLine->vatRate = $vatRate; + + $this->assertEquals(isset($orderLine->getUpdateData()['vatRate']), $expected_boolean); + } + + public function dpTestUpdateVatRate() + { + return [ + [0, true], + ['0', true], + [null, false], + ]; + } + + public function dpTestOrderLineTypes() + { + return [ + [OrderLineType::PHYSICAL, 'isPhysical', true], + [OrderLineType::PHYSICAL, 'isDiscount', false], + [OrderLineType::PHYSICAL, 'isDigital', false], + [OrderLineType::PHYSICAL, 'isShippingFee', false], + [OrderLineType::PHYSICAL, 'isStoreCredit', false], + [OrderLineType::PHYSICAL, 'isGiftCard', false], + [OrderLineType::PHYSICAL, 'isSurcharge', false], + + [OrderLineType::DISCOUNT, 'isPhysical', false], + [OrderLineType::DISCOUNT, 'isDiscount', true], + [OrderLineType::DISCOUNT, 'isDigital', false], + [OrderLineType::DISCOUNT, 'isShippingFee', false], + [OrderLineType::DISCOUNT, 'isStoreCredit', false], + [OrderLineType::DISCOUNT, 'isGiftCard', false], + [OrderLineType::DISCOUNT, 'isSurcharge', false], + + [OrderLineType::DIGITAL, 'isPhysical', false], + [OrderLineType::DIGITAL, 'isDiscount', false], + [OrderLineType::DIGITAL, 'isDigital', true], + [OrderLineType::DIGITAL, 'isShippingFee', false], + [OrderLineType::DIGITAL, 'isStoreCredit', false], + [OrderLineType::DIGITAL, 'isGiftCard', false], + [OrderLineType::DIGITAL, 'isSurcharge', false], + + [OrderLineType::SHIPPING_FEE, 'isPhysical', false], + [OrderLineType::SHIPPING_FEE, 'isDiscount', false], + [OrderLineType::SHIPPING_FEE, 'isDigital', false], + [OrderLineType::SHIPPING_FEE, 'isShippingFee', true], + [OrderLineType::SHIPPING_FEE, 'isStoreCredit', false], + [OrderLineType::SHIPPING_FEE, 'isGiftCard', false], + [OrderLineType::SHIPPING_FEE, 'isSurcharge', false], + + [OrderLineType::STORE_CREDIT, 'isPhysical', false], + [OrderLineType::STORE_CREDIT, 'isDiscount', false], + [OrderLineType::STORE_CREDIT, 'isDigital', false], + [OrderLineType::STORE_CREDIT, 'isShippingFee', false], + [OrderLineType::STORE_CREDIT, 'isStoreCredit', true], + [OrderLineType::STORE_CREDIT, 'isGiftCard', false], + [OrderLineType::STORE_CREDIT, 'isSurcharge', false], + + [OrderLineType::GIFT_CARD, 'isPhysical', false], + [OrderLineType::GIFT_CARD, 'isDiscount', false], + [OrderLineType::GIFT_CARD, 'isDigital', false], + [OrderLineType::GIFT_CARD, 'isShippingFee', false], + [OrderLineType::GIFT_CARD, 'isStoreCredit', false], + [OrderLineType::GIFT_CARD, 'isGiftCard', true], + [OrderLineType::GIFT_CARD, 'isSurcharge', false], + + [OrderLineType::SURCHARGE, 'isPhysical', false], + [OrderLineType::SURCHARGE, 'isDiscount', false], + [OrderLineType::SURCHARGE, 'isDigital', false], + [OrderLineType::SURCHARGE, 'isShippingFee', false], + [OrderLineType::SURCHARGE, 'isStoreCredit', false], + [OrderLineType::SURCHARGE, 'isGiftCard', false], + [OrderLineType::SURCHARGE, 'isSurcharge', true], + ]; + } + + public function dpTestOrderLineStatuses() + { + return [ + [OrderLineStatus::CREATED, 'isCreated', true], + [OrderLineStatus::CREATED, 'isPaid', false], + [OrderLineStatus::CREATED, 'isAuthorized', false], + [OrderLineStatus::CREATED, 'isCanceled', false], + [OrderLineStatus::CREATED, 'isShipping', false], + [OrderLineStatus::CREATED, 'isCompleted', false], + + [OrderLineStatus::PAID, 'isCreated', false], + [OrderLineStatus::PAID, 'isPaid', true], + [OrderLineStatus::PAID, 'isAuthorized', false], + [OrderLineStatus::PAID, 'isCanceled', false], + [OrderLineStatus::PAID, 'isShipping', false], + [OrderLineStatus::PAID, 'isCompleted', false], + + [OrderLineStatus::AUTHORIZED, 'isCreated', false], + [OrderLineStatus::AUTHORIZED, 'isPaid', false], + [OrderLineStatus::AUTHORIZED, 'isAuthorized', true], + [OrderLineStatus::AUTHORIZED, 'isCanceled', false], + [OrderLineStatus::AUTHORIZED, 'isShipping', false], + [OrderLineStatus::AUTHORIZED, 'isCompleted', false], + + [OrderLineStatus::CANCELED, 'isCreated', false], + [OrderLineStatus::CANCELED, 'isPaid', false], + [OrderLineStatus::CANCELED, 'isAuthorized', false], + [OrderLineStatus::CANCELED, 'isCanceled', true], + [OrderLineStatus::CANCELED, 'isShipping', false], + [OrderLineStatus::CANCELED, 'isCompleted', false], + + [OrderLineStatus::SHIPPING, 'isCreated', false], + [OrderLineStatus::SHIPPING, 'isPaid', false], + [OrderLineStatus::SHIPPING, 'isAuthorized', false], + [OrderLineStatus::SHIPPING, 'isCanceled', false], + [OrderLineStatus::SHIPPING, 'isShipping', true], + [OrderLineStatus::SHIPPING, 'isCompleted', false], + + [OrderLineStatus::COMPLETED, 'isCreated', false], + [OrderLineStatus::COMPLETED, 'isPaid', false], + [OrderLineStatus::COMPLETED, 'isAuthorized', false], + [OrderLineStatus::COMPLETED, 'isCanceled', false], + [OrderLineStatus::COMPLETED, 'isShipping', false], + [OrderLineStatus::COMPLETED, 'isCompleted', true], + ]; + } +} diff --git a/tests/Mollie/API/Resources/OrderTest.php b/tests/Resources/OrderTest.php similarity index 54% rename from tests/Mollie/API/Resources/OrderTest.php rename to tests/Resources/OrderTest.php index 20be8eb5e..f4cb81748 100644 --- a/tests/Mollie/API/Resources/OrderTest.php +++ b/tests/Resources/OrderTest.php @@ -1,6 +1,6 @@ assertInstanceOf(OrderLine::class, $line); - $this->assertEquals("orderline", $line->resource); - $this->assertEquals("odl_dgtxyl", $line->id); + $this->assertEquals('orderline', $line->resource); + $this->assertEquals('odl_dgtxyl', $line->id); $this->assertEquals('ord_pbjz8x', $line->orderId); - $this->assertEquals("LEGO 42083 Bugatti Chiron", $line->name); - $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl); + $this->assertEquals('LEGO 42083 Bugatti Chiron', $line->name); + $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line->productUrl); $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); - $this->assertEquals("5702016116977", $line->sku); + $this->assertEquals('5702016116977', $line->sku); $this->assertEquals(OrderLineType::PHYSICAL, $line->type); $this->assertEquals(OrderLineStatus::CREATED, $line->status); $this->assertEquals(2, $line->quantity); - $this->assertAmountObject("399.00", "EUR", $line->unitPrice); - $this->assertEquals("21.00", $line->vatRate); - $this->assertAmountObject("121.14", "EUR", $line->vatAmount); - $this->assertAmountObject("100.00", "EUR", $line->discountAmount); - $this->assertAmountObject("698.00", "EUR", $line->totalAmount); - $this->assertEquals("2018-08-02T09:29:56+00:00", $line->createdAt); + $this->assertAmountObject('399.00', 'EUR', $line->unitPrice); + $this->assertEquals('21.00', $line->vatRate); + $this->assertAmountObject('121.14', 'EUR', $line->vatAmount); + $this->assertAmountObject('100.00', 'EUR', $line->discountAmount); + $this->assertAmountObject('698.00', 'EUR', $line->totalAmount); + $this->assertEquals('2018-08-02T09:29:56+00:00', $line->createdAt); } public function testCanGetPaymentsAsResourcesOnOrderResource() @@ -228,22 +228,22 @@ public function testCanGetPaymentsAsResourcesOnOrderResource() $this->assertInstanceOf(OrderLine::class, $line); - $this->assertEquals("orderline", $line->resource); - $this->assertEquals("odl_dgtxyl", $line->id); + $this->assertEquals('orderline', $line->resource); + $this->assertEquals('odl_dgtxyl', $line->id); $this->assertEquals('ord_pbjz8x', $line->orderId); - $this->assertEquals("LEGO 42083 Bugatti Chiron", $line->name); - $this->assertEquals("https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", $line->productUrl); + $this->assertEquals('LEGO 42083 Bugatti Chiron', $line->name); + $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line->productUrl); $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); - $this->assertEquals("5702016116977", $line->sku); + $this->assertEquals('5702016116977', $line->sku); $this->assertEquals(OrderLineType::PHYSICAL, $line->type); $this->assertEquals(OrderLineStatus::CREATED, $line->status); $this->assertEquals(2, $line->quantity); - $this->assertAmountObject("399.00", "EUR", $line->unitPrice); - $this->assertEquals("21.00", $line->vatRate); - $this->assertAmountObject("121.14", "EUR", $line->vatAmount); - $this->assertAmountObject("100.00", "EUR", $line->discountAmount); - $this->assertAmountObject("698.00", "EUR", $line->totalAmount); - $this->assertEquals("2018-08-02T09:29:56+00:00", $line->createdAt); + $this->assertAmountObject('399.00', 'EUR', $line->unitPrice); + $this->assertEquals('21.00', $line->vatRate); + $this->assertAmountObject('121.14', 'EUR', $line->vatAmount); + $this->assertAmountObject('100.00', 'EUR', $line->discountAmount); + $this->assertAmountObject('698.00', 'EUR', $line->totalAmount); + $this->assertEquals('2018-08-02T09:29:56+00:00', $line->createdAt); } public function testGetCheckoutUrlWorks() diff --git a/tests/Mollie/API/Resources/PaymentTest.php b/tests/Resources/PaymentTest.php similarity index 59% rename from tests/Mollie/API/Resources/PaymentTest.php rename to tests/Resources/PaymentTest.php index 5397919ed..2b1fbc33f 100644 --- a/tests/Mollie/API/Resources/PaymentTest.php +++ b/tests/Resources/PaymentTest.php @@ -1,6 +1,6 @@ createMock(MollieApiClient::class)); - $payment->paidAt = "2016-10-24"; + $payment->paidAt = '2016-10-24'; $this->assertTrue($payment->isPaid()); } @@ -90,8 +90,8 @@ public function testHasRefundsReturnsTrueWhenPaymentHasRefunds() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); - $payment->_links->refunds = (object) ["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds", "type" => "application/hal+json"]; + $payment->_links = new stdClass; + $payment->_links->refunds = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds', 'type' => 'application/hal+json']; $this->assertTrue($payment->hasRefunds()); } @@ -100,7 +100,7 @@ public function testHasRefundsReturnsFalseWhenPaymentHasNoRefunds() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); + $payment->_links = new stdClass; $this->assertFalse($payment->hasRefunds()); } @@ -108,8 +108,8 @@ public function testHasChargebacksReturnsTrueWhenPaymentHasChargebacks() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); - $payment->_links->chargebacks = (object) ["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks", "type" => "application/hal+json"]; + $payment->_links = new stdClass; + $payment->_links->chargebacks = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks', 'type' => 'application/hal+json']; $this->assertTrue($payment->hasChargebacks()); } @@ -118,7 +118,7 @@ public function testHasChargebacksReturnsFalseWhenPaymentHasNoChargebacks() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); + $payment->_links = new stdClass; $this->assertFalse($payment->hasChargebacks()); } @@ -153,32 +153,31 @@ public function testGetCheckoutUrlReturnsPaymentUrlFromLinksObject() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); - $payment->_links->checkout = new stdClass(); - $payment->_links->checkout->href = "https://example.com"; + $payment->_links = new stdClass; + $payment->_links->checkout = new stdClass; + $payment->_links->checkout->href = 'https://example.com'; - $this->assertSame($payment->getCheckoutUrl(), "https://example.com"); + $this->assertSame($payment->getCheckoutUrl(), 'https://example.com'); } public function testGetMobileAppCheckoutUrlReturnsPaymentUrlFromLinksObject() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); - $payment->_links->mobileAppCheckout = new stdClass(); - $payment->_links->mobileAppCheckout->href = "https://example-mobile-checkout.com"; + $payment->_links = new stdClass; + $payment->_links->mobileAppCheckout = new stdClass; + $payment->_links->mobileAppCheckout->href = 'https://example-mobile-checkout.com'; - - $this->assertSame($payment->getMobileAppCheckoutUrl(), "https://example-mobile-checkout.com"); + $this->assertSame($payment->getMobileAppCheckoutUrl(), 'https://example-mobile-checkout.com'); } public function testCanBeRefundedReturnsTrueWhenAmountRemainingIsSet() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $amountRemaining = new Stdclass(); + $amountRemaining = new Stdclass; $amountRemaining->value = '15.00'; - $amountRemaining->currency = "EUR"; + $amountRemaining->currency = 'EUR'; $payment->amountRemaining = $amountRemaining; $this->assertTrue($payment->canBeRefunded()); @@ -198,7 +197,7 @@ public function testGetAmountRefundedReturnsAmountRefundedAsFloat() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->amountRefunded = (object)["value" => 22.0, "currency" => "EUR"]; + $payment->amountRefunded = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountRefunded()); } @@ -214,7 +213,7 @@ public function testGetAmountRemainingReturnsAmountRemainingAsFloat() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->amountRemaining = (object)["value" => 22.0, "currency" => "EUR"]; + $payment->amountRemaining = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountRemaining()); } @@ -230,7 +229,7 @@ public function testGetAmountChargedBackReturnsAmountChargedBackAsFloat() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->amountChargedBack = (object)["value" => 22.0, "currency" => "EUR"]; + $payment->amountChargedBack = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountChargedBack()); } @@ -254,7 +253,7 @@ public function testGetSettlementAmountReturnsSettlementAmountAsFloat() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->settlementAmount = (object)["value" => 22.0, "currency" => "EUR"]; + $payment->settlementAmount = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getSettlementAmount()); } @@ -262,7 +261,7 @@ public function testHasSplitPaymentsReturnsFalseWhenPaymentHasNoSplit() { $payment = new Payment($this->createMock(MollieApiClient::class)); - $payment->_links = new stdClass(); + $payment->_links = new stdClass; $this->assertFalse($payment->hasSplitPayments()); } } diff --git a/tests/Resources/ProfileTest.php b/tests/Resources/ProfileTest.php new file mode 100644 index 000000000..eef7a3d9b --- /dev/null +++ b/tests/Resources/ProfileTest.php @@ -0,0 +1,42 @@ +createMock(MollieApiClient::class)); + $profile->status = $status; + + $this->assertEquals($expected_boolean, $profile->{$function}()); + } + + public function dpTestProfileStatusses() + { + return [ + [ProfileStatus::BLOCKED, 'isBlocked', true], + [ProfileStatus::BLOCKED, 'isVerified', false], + [ProfileStatus::BLOCKED, 'isUnverified', false], + + [ProfileStatus::VERIFIED, 'isBlocked', false], + [ProfileStatus::VERIFIED, 'isVerified', true], + [ProfileStatus::VERIFIED, 'isUnverified', false], + + [ProfileStatus::UNVERIFIED, 'isBlocked', false], + [ProfileStatus::UNVERIFIED, 'isVerified', false], + [ProfileStatus::UNVERIFIED, 'isUnverified', true], + ]; + } +} diff --git a/tests/Resources/RefundTest.php b/tests/Resources/RefundTest.php new file mode 100644 index 000000000..d8ecfc828 --- /dev/null +++ b/tests/Resources/RefundTest.php @@ -0,0 +1,86 @@ +createMock(MollieApiClient::class)); + $refund->status = $status; + + $this->assertEquals($expected_boolean, $refund->{$function}()); + } + + /** + * @param string $status + * @param bool $expected_boolean + * + * @dataProvider dpTestRefundCanBeCanceled + */ + public function testRefundCanBeCanceled($status, $expected_boolean) + { + $refund = new Refund($this->createMock(MollieApiClient::class)); + $refund->status = $status; + + $this->assertEquals($expected_boolean, $refund->canBeCanceled()); + } + + public function dpTestRefundStatuses() + { + return [ + [RefundStatus::PENDING, 'isPending', true], + [RefundStatus::PENDING, 'isProcessing', false], + [RefundStatus::PENDING, 'isQueued', false], + [RefundStatus::PENDING, 'isTransferred', false], + [RefundStatus::PENDING, 'isFailed', false], + + [RefundStatus::PROCESSING, 'isPending', false], + [RefundStatus::PROCESSING, 'isProcessing', true], + [RefundStatus::PROCESSING, 'isQueued', false], + [RefundStatus::PROCESSING, 'isTransferred', false], + [RefundStatus::PROCESSING, 'isFailed', false], + + [RefundStatus::QUEUED, 'isPending', false], + [RefundStatus::QUEUED, 'isProcessing', false], + [RefundStatus::QUEUED, 'isQueued', true], + [RefundStatus::QUEUED, 'isTransferred', false], + [RefundStatus::QUEUED, 'isFailed', false], + + [RefundStatus::REFUNDED, 'isPending', false], + [RefundStatus::REFUNDED, 'isProcessing', false], + [RefundStatus::REFUNDED, 'isQueued', false], + [RefundStatus::REFUNDED, 'isTransferred', true], + [RefundStatus::REFUNDED, 'isFailed', false], + + [RefundStatus::FAILED, 'isPending', false], + [RefundStatus::FAILED, 'isProcessing', false], + [RefundStatus::FAILED, 'isQueued', false], + [RefundStatus::FAILED, 'isTransferred', false], + [RefundStatus::FAILED, 'isFailed', true], + ]; + } + + public function dpTestRefundCanBeCanceled() + { + return [ + [RefundStatus::PENDING, true], + [RefundStatus::PROCESSING, false], + [RefundStatus::QUEUED, true], + [RefundStatus::REFUNDED, false], + [RefundStatus::FAILED, false], + [RefundStatus::CANCELED, false], + ]; + } +} diff --git a/tests/Mollie/API/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php similarity index 89% rename from tests/Mollie/API/Resources/ResourceFactoryTest.php rename to tests/Resources/ResourceFactoryTest.php index d4b4576cb..600a902b0 100644 --- a/tests/Mollie/API/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -1,6 +1,6 @@ createMock(MollieApiClient::class), $apiResult, Payment::class); $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals("payment", $payment->resource); - $this->assertEquals("tr_44aKxzEbr8", $payment->id); - $this->assertEquals("test", $payment->mode); - $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt); - $this->assertEquals((object) ["value" => "20.00", "currency" => "EUR"], $payment->amount); + $this->assertEquals('payment', $payment->resource); + $this->assertEquals('tr_44aKxzEbr8', $payment->id); + $this->assertEquals('test', $payment->mode); + $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); + $this->assertEquals((object) ['value' => '20.00', 'currency' => 'EUR'], $payment->amount); } public function testEmbeddedCollectionsAreTypeCasted() diff --git a/tests/Resources/SettlementTest.php b/tests/Resources/SettlementTest.php new file mode 100644 index 000000000..c8b626896 --- /dev/null +++ b/tests/Resources/SettlementTest.php @@ -0,0 +1,50 @@ +createMock(MollieApiClient::class)); + $settlement->status = $status; + + $this->assertEquals($expected_boolean, $settlement->{$function}()); + } + + public function dpTestSettlementStatuses() + { + return [ + [SettlementStatus::PENDING, 'isPending', true], + [SettlementStatus::PENDING, 'isOpen', false], + [SettlementStatus::PENDING, 'isPaidout', false], + [SettlementStatus::PENDING, 'isFailed', false], + + [SettlementStatus::OPEN, 'isPending', false], + [SettlementStatus::OPEN, 'isOpen', true], + [SettlementStatus::OPEN, 'isPaidout', false], + [SettlementStatus::OPEN, 'isFailed', false], + + [SettlementStatus::PAIDOUT, 'isPending', false], + [SettlementStatus::PAIDOUT, 'isOpen', false], + [SettlementStatus::PAIDOUT, 'isPaidout', true], + [SettlementStatus::PAIDOUT, 'isFailed', false], + + [SettlementStatus::FAILED, 'isPending', false], + [SettlementStatus::FAILED, 'isOpen', false], + [SettlementStatus::FAILED, 'isPaidout', false], + [SettlementStatus::FAILED, 'isFailed', true], + ]; + } +} diff --git a/tests/Mollie/API/Resources/ShipmentTest.php b/tests/Resources/ShipmentTest.php similarity index 98% rename from tests/Mollie/API/Resources/ShipmentTest.php rename to tests/Resources/ShipmentTest.php index 3ec2539e3..4c8b98841 100644 --- a/tests/Mollie/API/Resources/ShipmentTest.php +++ b/tests/Resources/ShipmentTest.php @@ -1,6 +1,6 @@ createMock(MollieApiClient::class)); + $subscription->status = $status; + + $this->assertEquals($expected_boolean, $subscription->{$function}()); + } + + public function dpTestSubscriptionStatuses() + { + return [ + [SubscriptionStatus::PENDING, 'isPending', true], + [SubscriptionStatus::PENDING, 'isCanceled', false], + [SubscriptionStatus::PENDING, 'isCompleted', false], + [SubscriptionStatus::PENDING, 'isSuspended', false], + [SubscriptionStatus::PENDING, 'isActive', false], + + [SubscriptionStatus::CANCELED, 'isPending', false], + [SubscriptionStatus::CANCELED, 'isCanceled', true], + [SubscriptionStatus::CANCELED, 'isCompleted', false], + [SubscriptionStatus::CANCELED, 'isSuspended', false], + [SubscriptionStatus::CANCELED, 'isActive', false], + + [SubscriptionStatus::COMPLETED, 'isPending', false], + [SubscriptionStatus::COMPLETED, 'isCanceled', false], + [SubscriptionStatus::COMPLETED, 'isCompleted', true], + [SubscriptionStatus::COMPLETED, 'isSuspended', false], + [SubscriptionStatus::COMPLETED, 'isActive', false], + + [SubscriptionStatus::SUSPENDED, 'isPending', false], + [SubscriptionStatus::SUSPENDED, 'isCanceled', false], + [SubscriptionStatus::SUSPENDED, 'isCompleted', false], + [SubscriptionStatus::SUSPENDED, 'isSuspended', true], + [SubscriptionStatus::SUSPENDED, 'isActive', false], + + [SubscriptionStatus::ACTIVE, 'isPending', false], + [SubscriptionStatus::ACTIVE, 'isCanceled', false], + [SubscriptionStatus::ACTIVE, 'isCompleted', false], + [SubscriptionStatus::ACTIVE, 'isSuspended', false], + [SubscriptionStatus::ACTIVE, 'isActive', true], + ]; + } +} diff --git a/tests/Rules/IdTest.php b/tests/Rules/IdTest.php new file mode 100644 index 000000000..d2a917f14 --- /dev/null +++ b/tests/Rules/IdTest.php @@ -0,0 +1,76 @@ +assertInstanceOf(Id::class, $rule); + } + + /** @test */ + public function validate_throws_exception_if_not_instance_of_request() + { + $rule = new Id('ord_'); + + $nonRequestContext = new \stdClass; // Generic object to simulate incorrect context + + $rule->validate('ord_12345', $nonRequestContext, function ($message) { + $this->assertEquals('The Id rule can only be used on a Request instance.', $message); + }); + } + + /** @test */ + public function validate_throws_exception_if_id_does_not_start_with_prefix() + { + $rule = new Id('ord_'); + $request = new TestRequest; + + $rule->validate('inv_12345', $request, function ($message) { + $this->assertEquals("Invalid order ID: 'inv_12345'. A resource ID should start with 'ord_'.", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_if_id_starts_with_prefix() + { + $rule = new Id('ord_'); + $request = new TestRequest; + + $rule->validate('ord_12345', $request, function () { + $this->fail('Callback should not be invoked for a valid ID.'); + }); + + $this->assertTrue(true); // If no exception is thrown, the test passes + } + + /** @test */ + public function get_resource_type_returns_lowercase_class_basename() + { + $rule = new Id('ord_'); + $request = new TestRequest; + + $resourceType = $rule->getResourceType($request); + + $this->assertEquals('order', $resourceType); + } +} + +class TestRequest extends Request +{ + public static string $targetResourceClass = 'Order'; + + public function resolveResourcePath(): string + { + return 'test'; + } +} diff --git a/tests/Rules/IncludedTest.php b/tests/Rules/IncludedTest.php new file mode 100644 index 000000000..fe3091580 --- /dev/null +++ b/tests/Rules/IncludedTest.php @@ -0,0 +1,63 @@ + 'value1', + 'VALUE2' => 'value2', + ]; + + $this->assertInstanceOf(Included::class, $rule); + $this->assertEquals($expectedAllowedValues, (new ReflectionClass(SampleClass::class))->getConstants()); + } + + /** @test */ + public function validate_invokes_callback_when_value_not_included() + { + $allowed = ['value1', 'value2']; + $rule = new Included($allowed); + + $rule->validate('invalid_value', null, function ($message) use ($allowed) { + $this->assertEquals("Invalid include: 'invalid_value'. Allowed are: ".implode(', ', $allowed).'.', $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_when_value_is_included() + { + $allowed = ['value1', 'value2']; + $rule = new Included($allowed); + + $rule->validate('value1', null, function () { + $this->fail('Callback should not be invoked for a valid value.'); + }); + + $rule->validate('value2', null, function () { + $this->fail('Callback should not be invoked for a valid value.'); + }); + + $rule->validate('value1,value2', null, function () { + $this->fail('Callback should not be invoked for a valid value.'); + }); + + $this->assertTrue(true); + } +} + +class SampleClass +{ + const VALUE1 = 'value1'; + + const VALUE2 = 'value2'; +} diff --git a/tests/Rules/MatchesTest.php b/tests/Rules/MatchesTest.php new file mode 100644 index 000000000..8c7915fd5 --- /dev/null +++ b/tests/Rules/MatchesTest.php @@ -0,0 +1,42 @@ +assertInstanceOf(Matches::class, $rule); + } + + /** @test */ + public function validate_invokes_callback_on_non_matching_value() + { + $pattern = '/^test$/'; + $rule = new Matches($pattern); + + $rule->validate('nonmatching', null, function ($message) use ($pattern) { + $this->assertEquals("The value nonmatching does not match the pattern: {$pattern}", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_on_matching_value() + { + $pattern = '/^test$/'; + $rule = new Matches($pattern); + + $rule->validate('test', null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $this->assertTrue(true); + } +} diff --git a/tests/Rules/MaxTest.php b/tests/Rules/MaxTest.php new file mode 100644 index 000000000..140fbd7f4 --- /dev/null +++ b/tests/Rules/MaxTest.php @@ -0,0 +1,86 @@ +assertInstanceOf(Max::class, $rule); + } + + /** @test */ + public function validate_invokes_callback_when_numeric_value_exceeds_max() + { + $max = 100; + $rule = new Max($max); + + $rule->validate(150, null, function ($message) use ($max) { + $this->assertEquals("The value must not exceed {$max}.", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_when_numeric_value_is_equal_to_or_less_than_max() + { + $max = 100; + $rule = new Max($max); + + // If no exception or callback is triggered, the test passes + $rule->validate(100, null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $rule->validate(50, null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $this->assertTrue(true); + } + + /** @test */ + public function validate_invokes_callback_when_string_length_exceeds_max() + { + $max = 5; + $rule = new Max($max); + + $rule->validate('exceeds', null, function ($message) use ($max) { + $this->assertEquals("The value must not exceed {$max}.", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_when_string_length_is_equal_to_or_less_than_max() + { + $max = 5; + $rule = new Max($max); + + $rule->validate('valid', null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $rule->validate('tiny', null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $this->assertTrue(true); + } + + /** @test */ + public function validate_invokes_callback_when_string_value_exceeds_max() + { + $max = 7; + $rule = new Max($max); + + $rule->validate('DE123124', null, function ($message) use ($max) { + $this->assertEquals("The value must not exceed {$max}.", $message); + }); + } +} diff --git a/tests/Rules/MinTest.php b/tests/Rules/MinTest.php new file mode 100644 index 000000000..42a4f1968 --- /dev/null +++ b/tests/Rules/MinTest.php @@ -0,0 +1,74 @@ +assertInstanceOf(Min::class, $rule); + } + + /** @test */ + public function validate_invokes_callback_when_numeric_value_is_less_than_min() + { + $min = 10; + $rule = new Min($min); + + $rule->validate(5, null, function ($message) use ($min) { + $this->assertEquals("The value must be at least {$min}.", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_when_numeric_value_is_equal_to_or_greater_than_min() + { + $min = 10; + $rule = new Min($min); + + $rule->validate(10, null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $rule->validate(15, null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $this->assertTrue(true); + } + + /** @test */ + public function validate_invokes_callback_when_string_length_is_less_than_min() + { + $min = 5; + $rule = new Min($min); + + $rule->validate('tiny', null, function ($message) use ($min) { + $this->assertEquals("The value must be at least {$min}.", $message); + }); + } + + /** @test */ + public function validate_does_not_invoke_callback_when_string_length_is_equal_to_or_greater_than_min() + { + $min = 5; + $rule = new Min($min); + + $rule->validate('valid', null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $rule->validate('longer', null, function () { + $this->fail('Callback should not be invoked.'); + }); + + $this->assertTrue(true); + } +} diff --git a/tests/Traits/ResolvesValuesTest.php b/tests/Traits/ResolvesValuesTest.php new file mode 100644 index 000000000..02536bf6f --- /dev/null +++ b/tests/Traits/ResolvesValuesTest.php @@ -0,0 +1,90 @@ +assertEquals([ + 'name' => 'foo', + 'bar' => [ + 'baz' => [ + 'value' => 'baz', + ], + ], + ], $fooData->resolve()); + } +} + +class FooData implements Arrayable +{ + use ResolvesValues; + + public Bar $bar; + + public string $name; + + public function __construct( + Bar $bar, + string $name, + ) { + $this->bar = $bar; + $this->name = $name; + } + + public function toArray(): array + { + return [ + 'name' => $this->name, + 'bar' => $this->bar, + ]; + } +} + +class Bar implements DataResolver +{ + use ResolvesValues; + + public Baz $baz; + + public function __construct(Baz $baz) + { + $this->baz = $baz; + } + + public function data(): array + { + return [ + 'baz' => $this->baz, + ]; + } +} + +class Baz implements DataProvider +{ + public string $value; + + public function __construct(string $value) + { + $this->value = $value; + } + + public function data(): array + { + return [ + 'value' => $this->value, + ]; + } +} diff --git a/tests/Mollie/API/Types/MandateMethodTest.php b/tests/Types/MandateMethodTest.php similarity index 91% rename from tests/Mollie/API/Types/MandateMethodTest.php rename to tests/Types/MandateMethodTest.php index 02b6f6cea..fe09c26c0 100644 --- a/tests/Mollie/API/Types/MandateMethodTest.php +++ b/tests/Types/MandateMethodTest.php @@ -1,6 +1,6 @@ Date: Fri, 6 Sep 2024 16:47:02 +0200 Subject: [PATCH 047/131] wip --- README.md | 182 ++------------ src/Contracts/ArrayRepository.php | 6 +- src/Contracts/BodyRepository.php | 10 +- src/Contracts/Connector.php | 5 +- src/Contracts/DataProvider.php | 5 +- src/Contracts/DataResolver.php | 5 +- src/Contracts/Factory.php | 5 +- src/Contracts/HasResponse.php | 10 + src/Contracts/Hydratable.php | 15 ++ src/Contracts/IdempotencyContract.php | 2 + src/Contracts/ResponseContract.php | 17 -- .../SingleResourceEndpointContract.php | 4 +- src/Contracts/ViableResponse.php | 11 + .../ClientLinkEndpointCollection.php | 4 +- .../CustomerEndpointCollection.php | 129 ++++++++++ src/EndpointCollection/EndpointCollection.php | 10 +- .../OrderEndpointCollection.php} | 41 +-- .../PaymentEndpointCollection.php | 23 +- src/Endpoints/CustomerEndpoint.php | 137 ---------- src/Endpoints/EndpointCollection.php | 37 ++- src/Endpoints/MethodEndpoint.php | 32 +-- src/Endpoints/OrderLineEndpoint.php | 33 +-- src/Endpoints/ProfileMethodEndpoint.php | 39 +-- src/Endpoints/RestEndpoint.php | 76 +++--- src/Endpoints/SubscriptionEndpoint.php | 90 +------ .../CreateClientLinkPayloadFactory.php | 6 +- .../CreateCustomerPayloadFactory.php | 20 ++ src/Factories/CreatePaymentPayloadFactory.php | 8 +- .../CreateRefundPaymentPayloadFactory.php | 6 +- .../UpdateCustomerPayloadFactory.php | 20 ++ src/Factories/UpdatePaymentPayloadFactory.php | 8 +- src/Helpers/Arr.php | 5 +- src/Helpers/Handler.php | 28 +++ src/Helpers/Handlers.php | 52 +++- src/Helpers/MiddlewareHandlers.php | 40 ++- src/Helpers/MiddlewarePriority.php | 12 + .../Middleware/EvaluateHydrationSetting.php | 13 + src/Http/Middleware/GuardResponse.php | 14 +- src/Http/Middleware/Hydrate.php | 20 ++ src/Http/Payload/Address.php | 2 +- ...ntLink.php => CreateClientLinkPayload.php} | 2 +- src/Http/Payload/CreateCustomerPayload.php | 41 +++ ...tePayment.php => CreatePaymentPayload.php} | 4 +- ...ent.php => CreateRefundPaymentPayload.php} | 4 +- src/Http/Payload/DataCollection.php | 2 +- src/Http/Payload/OrderLine.php | 2 +- src/Http/Payload/PaymentRoute.php | 2 +- src/Http/Payload/RecurringBillingCycle.php | 2 +- src/Http/Payload/RefundRoute.php | 2 +- src/Http/Payload/UpdateCustomerPayload.php | 8 + ...tePayment.php => UpdatePaymentPayload.php} | 2 +- src/Http/PendingRequest.php | 18 +- .../PendingRequest/AuthenticateRequest.php | 15 +- src/Http/Request.php | 7 + src/Http/Requests/CancelPaymentRequest.php | 26 +- src/Http/Requests/CreateClientLinkRequest.php | 6 +- src/Http/Requests/CreateCustomerRequest.php | 36 +++ src/Http/Requests/CreatePaymentRequest.php | 6 +- .../Requests/CreateRefundPaymentRequest.php | 6 +- src/Http/Requests/DeleteCustomerRequest.php | 26 ++ src/Http/Requests/DynamicDeleteRequest.php | 17 +- src/Http/Requests/DynamicGetRequest.php | 17 ++ src/Http/Requests/DynamicPatchRequest.php | 40 +++ src/Http/Requests/DynamicPostRequest.php | 43 ++++ src/Http/Requests/GetBalanceRequest.php | 26 +- src/Http/Requests/GetCustomerRequest.php | 29 +++ .../Requests/GetPaginatedCustomerRequest.php | 19 ++ src/Http/Requests/SimpleRequest.php | 25 ++ src/Http/Requests/UpdateCustomerRequest.php | 57 +++++ src/Http/Requests/UpdatePaymentRequest.php | 14 +- src/Http/Response.php | 11 + src/MollieApiClient.php | 12 +- src/Repositories/ArrayStore.php | 8 +- src/Repositories/JsonBodyRepository.php | 7 +- src/Resources/BaseCollection.php | 7 +- src/Resources/BaseResource.php | 11 +- src/Resources/Customer.php | 2 + src/Resources/LazyCollection.php | 26 +- src/Resources/ResourceFactory.php | 20 +- src/Traits/HandlesAutoHydration.php | 34 +++ src/Traits/HandlesResourceCreation.php | 13 +- src/Traits/HasEndpoints.php | 15 +- src/Traits/HasHeaders.php | 5 +- src/Traits/HasQuery.php | 5 +- src/Traits/SendsRequests.php | 12 +- src/Traits/ValidatesProperties.php | 104 -------- .../BalanceEndpointCollectionTest.php | 4 +- tests/Fixtures/MockResponse.php | 14 +- .../{balance-get.json => balance.json} | 0 .../Responses/cursor-collection-next.json | 18 ++ .../Fixtures/Responses/cursor-collection.json | 15 ++ tests/Fixtures/Responses/payment.json | 37 +++ tests/Fixtures/SequenceMockResponse.php | 33 +++ tests/Helpers/MiddlewareHandlersTest.php | 44 +++- tests/Http/Adapter/MockMollieHttpAdapter.php | 5 + tests/Http/Middleware/GuardResponseTest.php | 106 ++++++++ .../API/Resources/CursorCollectionTest.php | 233 ------------------ tests/MollieApiClientTest.php | 138 ++++++----- tests/Resources/CursorCollectionTest.php | 156 ++++++++++++ tests/Resources/ResourceFactoryTest.php | 3 +- 100 files changed, 1613 insertions(+), 1171 deletions(-) create mode 100644 src/Contracts/HasResponse.php create mode 100644 src/Contracts/Hydratable.php delete mode 100644 src/Contracts/ResponseContract.php create mode 100644 src/Contracts/ViableResponse.php create mode 100644 src/EndpointCollection/CustomerEndpointCollection.php rename src/{Endpoints/OrderEndpoint.php => EndpointCollection/OrderEndpointCollection.php} (73%) delete mode 100644 src/Endpoints/CustomerEndpoint.php create mode 100644 src/Factories/CreateCustomerPayloadFactory.php create mode 100644 src/Factories/UpdateCustomerPayloadFactory.php create mode 100644 src/Helpers/Handler.php create mode 100644 src/Helpers/MiddlewarePriority.php create mode 100644 src/Http/Middleware/EvaluateHydrationSetting.php create mode 100644 src/Http/Middleware/Hydrate.php rename src/Http/Payload/{CreateClientLink.php => CreateClientLinkPayload.php} (95%) create mode 100644 src/Http/Payload/CreateCustomerPayload.php rename src/Http/Payload/{CreatePayment.php => CreatePaymentPayload.php} (98%) rename src/Http/Payload/{CreateRefundPayment.php => CreateRefundPaymentPayload.php} (93%) create mode 100644 src/Http/Payload/UpdateCustomerPayload.php rename src/Http/Payload/{UpdatePayment.php => UpdatePaymentPayload.php} (97%) create mode 100644 src/Http/Requests/CreateCustomerRequest.php create mode 100644 src/Http/Requests/DeleteCustomerRequest.php create mode 100644 src/Http/Requests/DynamicPatchRequest.php create mode 100644 src/Http/Requests/DynamicPostRequest.php create mode 100644 src/Http/Requests/GetCustomerRequest.php create mode 100644 src/Http/Requests/GetPaginatedCustomerRequest.php create mode 100644 src/Http/Requests/SimpleRequest.php create mode 100644 src/Http/Requests/UpdateCustomerRequest.php create mode 100644 src/Traits/HandlesAutoHydration.php delete mode 100644 src/Traits/ValidatesProperties.php rename tests/Fixtures/Responses/{balance-get.json => balance.json} (100%) create mode 100644 tests/Fixtures/Responses/cursor-collection-next.json create mode 100644 tests/Fixtures/Responses/cursor-collection.json create mode 100644 tests/Fixtures/Responses/payment.json create mode 100644 tests/Fixtures/SequenceMockResponse.php create mode 100644 tests/Http/Middleware/GuardResponseTest.php delete mode 100644 tests/Mollie/API/Resources/CursorCollectionTest.php create mode 100644 tests/Resources/CursorCollectionTest.php diff --git a/README.md b/README.md index 23ff8b6cb..ed2c28211 100644 --- a/README.md +++ b/README.md @@ -93,165 +93,11 @@ With the `MollieApiClient` you can now access any of the following endpoints by Find our full documentation online on [docs.mollie.com](https://docs.mollie.com). -### Orders ### -#### Creating Orders #### -**[Create Order reference](https://docs.mollie.com/reference/v2/orders-api/create-order)** - -```php -$order = $mollie->orders->create([ - "amount" => [ - "value" => "1027.99", - "currency" => "EUR", - ], - "billingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "shippingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "metadata" => [ - "some" => "data", - ], - "consumerDateOfBirth" => "1958-01-31", - "locale" => "en_US", - "orderNumber" => "1234", - "redirectUrl" => "https://your_domain.com/return?some_other_info=foo", - "webhookUrl" => "https://your_domain.com/webhook", - "method" => "ideal", - "lines" => [ - [ - "sku" => "5702016116977", - "name" => "LEGO 42083 Bugatti Chiron", - "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - "quantity" => 2, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "399.00", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "698.00", - ], - "discountAmount" => [ - "currency" => "EUR", - "value" => "100.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "121.14", - ], - ], - // more order line items - ], -]); -``` - -_After creation, the order id is available in the `$order->id` property. You should store this id with your order._ - -After storing the order id you can send the customer off to complete the order payment using `$order->getCheckoutUrl()`. - -```php -header("Location: " . $order->getCheckoutUrl(), true, 303); -``` - -_This header location should always be a GET, thus we enforce 303 http response code_ - -For an order create example, see [Example - New Order](https://github.com/mollie/mollie-api-php/blob/master/examples/orders/create-order.php). - -#### Updating Orders #### -**[Update Order Documentation](https://docs.mollie.com/reference/v2/orders-api/update-order)** - -```php -$order = $mollie->orders->get("ord_kEn1PlbGa"); -$order->billingAddress->organizationName = "Mollie B.V."; -$order->billingAddress->streetAndNumber = "Keizersgracht 126"; -$order->billingAddress->city = "Amsterdam"; -$order->billingAddress->region = "Noord-Holland"; -$order->billingAddress->postalCode = "1234AB"; -$order->billingAddress->country = "NL"; -$order->billingAddress->title = "Dhr"; -$order->billingAddress->givenName = "Piet"; -$order->billingAddress->familyName = "Mondriaan"; -$order->billingAddress->email = "piet@mondriaan.com"; -$order->billingAddress->phone = "+31208202070"; -$order->update(); -``` - -#### Refunding Orders #### -##### Complete ##### -```php -$order = $mollie->orders->get('ord_8wmqcHMN4U'); -$refund = $order->refundAll(); - -echo 'Refund ' . $refund->id . ' was created for order ' . $order->id; -``` - -##### Partially ##### -When executing a partial refund you have to list all order line items that should be refunded. - -```php -$order = $mollie->orders->get('ord_8wmqcHMN4U'); -$refund = $order->refund([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - ], - "description" => "Required quantity not in stock, refunding one photo book.", -]); -``` - -#### Cancel Orders #### -**[Cancel Order Documentation](https://docs.mollie.com/reference/v2/orders-api/cancel-order)** - -_When canceling an order it is crucial to check if the order is cancelable before executing the cancel action. For more information see the [possible order statuses](https://docs.mollie.com/orders/status-changes#possible-statuses-for-orders)._ - -```php -$order = $mollie->orders->get("ord_pbjz8x"); - -if ($order->isCancelable) { - $canceledOrder = $order->cancel(); - echo "Your order " . $order->id . " has been canceled."; -} else { - echo "Unable to cancel your order " . $order->id . "."; -} -``` - -#### Order webhook #### -When the order status changes, the `webhookUrl` you specified during order creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/orders/webhook.php). - -### Payments ### -#### Payment Reception Process #### -**[Payment Reception Process documentation](https://docs.mollie.com/payments/accepting-payments#working-with-the-payments-api)** - -To ensure a successful payment reception, you should follow these steps: - -1. Utilize the Mollie API client to initiate a payment. Specify the desired amount, currency, description, and optionally, a payment method. It's crucial to define a unique redirect URL where the customer should be directed after completing the payment. - -2. Immediately upon payment completion, our platform will initiate an asynchronous request to the configured webhook. This enables you to retrieve payment details, ensuring you know precisely when to commence processing the customer's order. - -3. The customer is redirected to the URL from step (1) and should be pleased to find that the order has been paid and is now in the processing stage. - - #### Creating Payments #### **[Create Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/create-payment)** ```php +// old way of creating a payment $payment = $mollie->payments->create([ "amount" => [ "currency" => "EUR", @@ -261,6 +107,32 @@ $payment = $mollie->payments->create([ "redirectUrl" => "https://webshop.example.org/order/12345/", "webhookUrl" => "https://webshop.example.org/mollie-webhook/", ]); + +// newish way +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\CreatePaymentPayload; + +$payload = new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$payment = $mollie->payments->create($payload); + + +// newest ;-) +use Mollie\Api\Http\Requests\CreatePaymentRequest; + +$payload = new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$payment = $mollie->send($payload); ``` _After creation, the payment id is available in the `$payment->id` property. You should store this id with your order._ diff --git a/src/Contracts/ArrayRepository.php b/src/Contracts/ArrayRepository.php index 0bbda611a..c6caac677 100644 --- a/src/Contracts/ArrayRepository.php +++ b/src/Contracts/ArrayRepository.php @@ -6,7 +6,11 @@ interface ArrayRepository { public function set(array $data): static; - public function get(string $key, mixed $default = null): mixed; + /** + * @param mixed $default + * @return mixed + */ + public function get(string $key, $default = null); public function has(string $key): bool; diff --git a/src/Contracts/BodyRepository.php b/src/Contracts/BodyRepository.php index 3c3f9cd30..df0dd4e5b 100644 --- a/src/Contracts/BodyRepository.php +++ b/src/Contracts/BodyRepository.php @@ -7,9 +7,15 @@ interface BodyRepository { - public function set(mixed $value): static; + /** + * @param mixed $value + */ + public function set($value): static; - public function all(): mixed; + /** + * @return mixed + */ + public function all(); public function remove(string $key): static; diff --git a/src/Contracts/Connector.php b/src/Contracts/Connector.php index e922c5304..e70daf856 100644 --- a/src/Contracts/Connector.php +++ b/src/Contracts/Connector.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Contracts; +use Mollie\Api\Helpers\MiddlewareHandlers; use Mollie\Api\Http\Request; -interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract +interface Connector extends Authenticatable, Hydratable, IdempotencyContract, SupportsDebuggingContract { public function send(Request $request): ?object; @@ -14,6 +15,8 @@ public function headers(): ArrayRepository; public function query(): ArrayRepository; + public function middleware(): MiddlewareHandlers; + public function addVersionString($versionString): self; public function getVersionStrings(): array; diff --git a/src/Contracts/DataProvider.php b/src/Contracts/DataProvider.php index c6d0a9597..ae50396d8 100644 --- a/src/Contracts/DataProvider.php +++ b/src/Contracts/DataProvider.php @@ -4,5 +4,8 @@ interface DataProvider { - public function data(): mixed; + /** + * @return mixed + */ + public function data(); } diff --git a/src/Contracts/DataResolver.php b/src/Contracts/DataResolver.php index e076150d2..d660ce4ad 100644 --- a/src/Contracts/DataResolver.php +++ b/src/Contracts/DataResolver.php @@ -4,5 +4,8 @@ interface DataResolver { - public function resolve(): mixed; + /** + * @return mixed + */ + public function resolve(); } diff --git a/src/Contracts/Factory.php b/src/Contracts/Factory.php index 95105daba..fb532999c 100644 --- a/src/Contracts/Factory.php +++ b/src/Contracts/Factory.php @@ -6,5 +6,8 @@ interface Factory { public static function new(array $data): static; - public function create(): mixed; + /** + * @return mixed + */ + public function create(); } diff --git a/src/Contracts/HasResponse.php b/src/Contracts/HasResponse.php new file mode 100644 index 000000000..a802c2ad1 --- /dev/null +++ b/src/Contracts/HasResponse.php @@ -0,0 +1,10 @@ +create(); } diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php new file mode 100644 index 000000000..fa2050fb5 --- /dev/null +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -0,0 +1,129 @@ +create(); + } + + /** @var Customer */ + return $this->send(new CreateCustomerRequest($data)); + } + + /** + * Retrieve a single customer from Mollie. + * + * Will throw a ApiException if the customer id is invalid or the resource cannot be found. + * + * @throws ApiException + */ + public function get(string $id, $testmode = []): Customer + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + /** @var Customer */ + return $this->send(new GetCustomerRequest($id, $testmode)); + } + + /** + * Update a specific Customer resource. + * + * Will throw an ApiException if the customer id is invalid or the resource cannot be found. + * + * @throws ApiException + */ + public function update(string $id, $data = []): ?Customer + { + if (! $data instanceof UpdateCustomerPayload) { + $data = UpdateCustomerPayloadFactory::new($data)->create(); + } + + /** @var null|Customer */ + return $this->send(new UpdateCustomerRequest($id, $data)); + } + + /** + * Deletes the given Customer. + * + * Will throw a ApiException if the customer id is invalid or the resource cannot be found. + * Returns with HTTP status No Content (204) if successful. + * + * @param bool|array $testmode + * + * @throws ApiException + */ + public function delete(string $id, $testmode = []): ?Customer + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + /** @var null|Customer */ + return $this->send(new DeleteCustomerRequest($id, $testmode)); + } + + /** + * Retrieves a collection of Customers from Mollie. + * + * @param string $from The first customer ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): CustomerCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var CustomerCollection */ + return $this->send(new GetPaginatedCustomerRequest($query)); + } + + /** + * Create an iterator for iterating over customers retrieved from Mollie. + * + * @param string $from The first customer ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedCustomerRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/EndpointCollection.php b/src/EndpointCollection/EndpointCollection.php index 46a419ef6..4825f403b 100644 --- a/src/EndpointCollection/EndpointCollection.php +++ b/src/EndpointCollection/EndpointCollection.php @@ -12,9 +12,17 @@ abstract class EndpointCollection public function __construct(Connector $connector) { $this->connector = $connector; + + /** + * Default hydration decision to true to maintain legacy compatibility. + */ + $connector::shouldAutoHydrate(); } - protected function send(Request $request): mixed + /** + * @return mixed + */ + protected function send(Request $request) { return $this->connector->send($request); } diff --git a/src/Endpoints/OrderEndpoint.php b/src/EndpointCollection/OrderEndpointCollection.php similarity index 73% rename from src/Endpoints/OrderEndpoint.php rename to src/EndpointCollection/OrderEndpointCollection.php index dbfedcdcb..71a0984fb 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/EndpointCollection/OrderEndpointCollection.php @@ -1,50 +1,40 @@ create(); } @@ -74,13 +75,13 @@ public function create($data = [], $query = []): Payment * Will throw a ApiException if the payment id is invalid or the resource cannot be found. * * @param string $id - * @param array|UpdatePayment $data + * @param array|UpdatePaymentPayload $data * * @throws ApiException */ public function update($id, $data = []): ?Payment { - if (! $data instanceof UpdatePayment) { + if (! $data instanceof UpdatePaymentPayload) { $data = UpdatePaymentPayloadFactory::new($data) ->create(); } @@ -115,9 +116,7 @@ public function delete(string $id, $data = []): ?Payment */ public function cancel(string $id, $data = []): ?Payment { - $testmode = is_bool($data) - ? $data - : Arr::get($data, 'testmode', false); + $testmode = Helpers::extractBool($data, 'testmode', false); /** @var null|Payment */ return $this->send(new CancelPaymentRequest($id, $testmode)); @@ -129,13 +128,13 @@ public function cancel(string $id, $data = []): ?Payment * The $data parameter may either be an array of endpoint * parameters, or an instance of CreateRefundPaymentData. * - * @param array|CreateRefundPayment $payload + * @param array|CreateRefundPaymentPayload $payload * * @throws ApiException */ public function refund(Payment $payment, $payload = []): Refund { - if (! $payload instanceof CreateRefundPayment) { + if (! $payload instanceof CreateRefundPaymentPayload) { $payload = CreateRefundPaymentPayloadFactory::new($payload) ->create(); } diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php deleted file mode 100644 index 1aff77f44..000000000 --- a/src/Endpoints/CustomerEndpoint.php +++ /dev/null @@ -1,137 +0,0 @@ -createResource($data, $filters); - } - - /** - * Retrieve a single customer from Mollie. - * - * Will throw a ApiException if the customer id is invalid or the resource cannot be found. - * - * @param string $customerId - * @param array $parameters - * @return Customer - * @throws ApiException - */ - public function get(string $customerId, array $parameters = []): Customer - { - /** @var Customer */ - return $this->readResource($customerId, $parameters); - } - - /** - * Update a specific Customer resource. - * - * Will throw an ApiException if the customer id is invalid or the resource cannot be found. - * - * @param string $customerId - * @param array $data - * @return null|Customer - * @throws ApiException - */ - public function update(string $customerId, array $data = []): ?Customer - { - $this->guardAgainstInvalidId($customerId); - - /** @var null|Customer */ - return $this->updateResource($customerId, $data); - } - - /** - * Deletes the given Customer. - * - * Will throw a ApiException if the customer id is invalid or the resource cannot be found. - * Returns with HTTP status No Content (204) if successful. - * - * @param string $customerId - * @param array $data - * @return null|Customer - * @throws ApiException - */ - public function delete(string $customerId, array $data = []): ?Customer - { - /** @var null|Customer */ - return $this->deleteResource($customerId, $data); - } - - /** - * Retrieves a collection of Customers from Mollie. - * - * @param string $from The first customer ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return CustomerCollection - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): CustomerCollection - { - /** @var CustomerCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over customers retrieved from Mollie. - * - * @param string $from The first customer ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php index 1df3252a6..6b4135ec1 100644 --- a/src/Endpoints/EndpointCollection.php +++ b/src/Endpoints/EndpointCollection.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Endpoints; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\CursorCollection; use Mollie\Api\Resources\LazyCollection; @@ -13,33 +14,30 @@ abstract class EndpointCollection extends RestEndpoint { /** * The resource collection class name. - * - * @var string */ public static string $resourceCollection = ''; /** * Get a collection of objects from the REST API. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $filters + * @param string $from The first resource ID you want to include in your list. * - * @return BaseCollection * @throws ApiException */ protected function fetchCollection(?string $from = null, ?int $limit = null, array $filters = []): BaseCollection { - $apiPath = $this->getResourcePath() . $this->buildQueryString( + $apiPath = $this->getResourcePath().$this->buildQueryString( $this->getMergedFilters($filters, $from, $limit) ); - $result = $this->client->performHttpCall( - self::REST_LIST, - $apiPath - ); + $response = $this + ->client + ->send(new DynamicGetRequest( + $apiPath, + $this->getResourceCollectionClass(), + )); - return $this->buildResultCollection($result->decode()); + return $this->buildResultCollection($response->json()); } /** @@ -49,11 +47,8 @@ protected function fetchCollection(?string $from = null, ?int $limit = null, arr * that allows you to iterate through the items in the collection one by one. It supports forward * and backward iteration, pagination, and filtering. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $filters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ protected function createIterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { @@ -65,7 +60,7 @@ protected function createIterator(?string $from = null, ?int $limit = null, arra protected function getMergedFilters(array $filters = [], ?string $from = null, ?int $limit = null): array { - return array_merge(["from" => $from, "limit" => $limit], $filters); + return array_merge(['from' => $from, 'limit' => $limit], $filters); } protected function buildResultCollection(object $result): BaseCollection @@ -83,13 +78,11 @@ protected function buildResultCollection(object $result): BaseCollection /** * Get the collection class that is used by this API endpoint. Every API endpoint uses one type of collection object. - * - * @return string */ private function getResourceCollectionClass(): string { - if (!isset(static::$resourceCollection)) { - throw new RuntimeException("The resource collection class is not set on the endpoint."); + if (! isset(static::$resourceCollection)) { + throw new RuntimeException('The resource collection class is not set on the endpoint.'); } return static::$resourceCollection; diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php index a1ed6acaa..d2aa1a531 100644 --- a/src/Endpoints/MethodEndpoint.php +++ b/src/Endpoints/MethodEndpoint.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Endpoints; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; @@ -10,22 +11,16 @@ class MethodEndpoint extends EndpointCollection { /** * The resource path. - * - * @var string */ - protected string $resourcePath = "methods"; + protected string $resourcePath = 'methods'; /** * Resource class name. - * - * @var string */ public static string $resource = Method::class; /** * The resource collection class name. - * - * @var string */ public static string $resourceCollection = MethodCollection::class; @@ -33,9 +28,7 @@ class MethodEndpoint extends EndpointCollection * Retrieve all active methods. In test mode, this includes pending methods. The results are not paginated. * * @deprecated Use allActive() instead - * @param array $parameters * - * @return MethodCollection * @throws ApiException */ public function all(array $parameters = []): MethodCollection @@ -47,9 +40,7 @@ public function all(array $parameters = []): MethodCollection * Retrieve all active methods for the organization. In test mode, this includes pending methods. * The results are not paginated. * - * @param array $parameters * - * @return MethodCollection * @throws ApiException */ public function allActive(array $parameters = []): MethodCollection @@ -62,18 +53,20 @@ public function allActive(array $parameters = []): MethodCollection * Retrieve all available methods for the organization, including activated and not yet activated methods. The * results are not paginated. Make sure to include the profileId parameter if using an OAuth Access Token. * - * @param array $parameters Query string parameters. - * @return MethodCollection + * @param array $parameters Query string parameters. + * * @throws \Mollie\Api\Exceptions\ApiException */ public function allAvailable(array $parameters = []): MethodCollection { - $url = 'methods/all' . $this->buildQueryString($parameters); - - $result = $this->client->performHttpCall('GET', $url); + $url = 'methods/all'.$this->buildQueryString($parameters); - /** @var MethodCollection */ - return $this->buildResultCollection($result->decode()); + return $this + ->client + ->send(new DynamicGetRequest( + $url, + MethodCollection::class, + )); } /** @@ -81,9 +74,6 @@ public function allAvailable(array $parameters = []): MethodCollection * * Will throw a ApiException if the method id is invalid or the resource cannot be found. * - * @param string $methodId - * @param array $parameters - * @return Method * @throws ApiException */ public function get(string $methodId, array $parameters = []): Method diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php index 98f3af026..5cdaa86da 100644 --- a/src/Endpoints/OrderLineEndpoint.php +++ b/src/Endpoints/OrderLineEndpoint.php @@ -11,23 +11,17 @@ class OrderLineEndpoint extends RestEndpoint { /** * The resource path. - * - * @var string */ - protected string $resourcePath = "orders_lines"; + protected string $resourcePath = 'orders_lines'; /** * Resource id prefix. * Used to validate resource id's. - * - * @var string */ protected static string $resourceIdPrefix = 'odl_'; /** * Resource class name. - * - * @var string */ public static string $resource = OrderLine::class; @@ -36,11 +30,7 @@ class OrderLineEndpoint extends RestEndpoint * * Will throw an ApiException if the order line id is invalid or the resource cannot be found. * - * @param string $orderId - * @param string $orderlineId - * @param array $data * - * @return null|Order * @throws \Mollie\Api\Exceptions\ApiException */ public function update(string $orderId, string $orderlineId, array $data = []): ?Order @@ -60,21 +50,16 @@ public function update(string $orderId, string $orderlineId, array $data = []): } /** @var Order */ - return ResourceFactory::createFromApiResult($this->client, $response->decode(), Order::class); + return ResourceFactory::createFromApiResult($this->client, $response, Order::class); } /** - * @param string $orderId - * @param array $operations - * @param array $parameters - * - * @return Order * @throws \Mollie\Api\Exceptions\ApiException */ public function updateMultiple(string $orderId, array $operations, array $parameters = []): Order { if (empty($orderId)) { - throw new ApiException("Invalid resource id."); + throw new ApiException('Invalid resource id.'); } $this->parentId = $orderId; @@ -88,7 +73,7 @@ public function updateMultiple(string $orderId, array $operations, array $parame ); /** @var Order */ - return ResourceFactory::createFromApiResult($this->client, $result->decode(), Order::class); + return ResourceFactory::createFromApiResult($this->client, $result, Order::class); } /** @@ -96,10 +81,7 @@ public function updateMultiple(string $orderId, array $operations, array $parame * The data array must contain a lines array. * You can pass an empty lines array if you want to cancel all eligible lines. * - * @param Order $order - * @param array $data * - * @return void * @throws ApiException */ public function cancelFor(Order $order, array $data): void @@ -112,16 +94,13 @@ public function cancelFor(Order $order, array $data): void * The data array must contain a lines array. * You can pass an empty lines array if you want to cancel all eligible lines. * - * @param string $orderId - * @param array $data * - * @return void * @throws ApiException */ public function cancelForId(string $orderId, array $data): void { - if (!isset($data['lines']) || !is_array($data['lines'])) { - throw new ApiException("A lines array is required."); + if (! isset($data['lines']) || ! is_array($data['lines'])) { + throw new ApiException('A lines array is required.'); } $this->parentId = $orderId; diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php index 4929f571b..d2b867d26 100644 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ b/src/Endpoints/ProfileMethodEndpoint.php @@ -11,33 +11,23 @@ class ProfileMethodEndpoint extends EndpointCollection { /** * The resource path. - * - * @var string */ - protected string $resourcePath = "profiles_methods"; + protected string $resourcePath = 'profiles_methods'; /** * Resource class name. - * - * @var string */ public static string $resource = Method::class; /** * The resource collection class name. - * - * @var string */ public static string $resourceCollection = MethodCollection::class; /** * Enable a method for the provided Profile ID. * - * @param string $profileId - * @param string $methodId - * @param array $data * - * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ public function createForId(string $profileId, string $methodId, array $data = []): Method @@ -46,22 +36,18 @@ public function createForId(string $profileId, string $methodId, array $data = [ $result = $this->client->performHttpCall( self::REST_CREATE, - $this->getResourcePath() . '/' . urlencode($methodId), + $this->getResourcePath().'/'.urlencode($methodId), $this->parseRequestBody($data) ); /** @var Method */ - return ResourceFactory::createFromApiResult($this->client, $result->decode(), static::getResourceClass()); + return ResourceFactory::createFromApiResult($this->client, $result, static::getResourceClass()); } /** * Enable a method for the provided Profile object. * - * @param Profile $profile - * @param string $methodId - * @param array $data * - * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ public function createFor(Profile $profile, string $methodId, array $data = []): Method @@ -72,10 +58,7 @@ public function createFor(Profile $profile, string $methodId, array $data = []): /** * Enable a method for the current profile. * - * @param string $methodId - * @param array $data * - * @return Method * @throws \Mollie\Api\Exceptions\ApiException */ public function createForCurrentProfile(string $methodId, array $data = []): Method @@ -86,11 +69,9 @@ public function createForCurrentProfile(string $methodId, array $data = []): Met /** * Disable a method for the provided Profile ID. * - * @param string $profileId - * @param string $methodId - * @param array $data + * @param string $profileId + * @param string $methodId * - * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ public function deleteForId($profileId, $methodId, array $data = []): ?Method @@ -104,11 +85,9 @@ public function deleteForId($profileId, $methodId, array $data = []): ?Method /** * Disable a method for the provided Profile object. * - * @param Profile $profile - * @param string $methodId - * @param array $data + * @param Profile $profile + * @param string $methodId * - * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ public function deleteFor($profile, $methodId, array $data = []): ?Method @@ -119,10 +98,8 @@ public function deleteFor($profile, $methodId, array $data = []): ?Method /** * Disable a method for the current profile. * - * @param string $methodId - * @param array $data + * @param string $methodId * - * @return null|Method * @throws \Mollie\Api\Exceptions\ApiException */ public function deleteForCurrentProfile($methodId, array $data): ?Method diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php index b900cd020..7acf192bd 100644 --- a/src/Endpoints/RestEndpoint.php +++ b/src/Endpoints/RestEndpoint.php @@ -4,8 +4,11 @@ use Mollie\Api\Contracts\SingleResourceEndpointContract; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Requests\DynamicDeleteRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\DynamicPatchRequest; +use Mollie\Api\Http\Requests\DynamicPostRequest; use Mollie\Api\Resources\BaseResource; -use Mollie\Api\Resources\ResourceFactory; use Mollie\Api\Traits\InteractsWithResource as TraitsInteractsWithResource; use RuntimeException; @@ -24,13 +27,15 @@ abstract class RestEndpoint extends BaseEndpoint */ protected function createResource(array $body, array $filters): BaseResource { - $result = $this->client->performHttpCall( - self::REST_CREATE, - $this->getResourcePath().$this->buildQueryString($filters), - $this->parseRequestBody($body) - ); - - return ResourceFactory::createFromApiResult($this->client, $result->decode(), static::getResourceClass()); + return $this + ->client + ->send(new DynamicPostRequest( + $this->getResourcePath(), + static::getResourceClass(), + $body, + $filters + )) + ->toResource(); } /** @@ -43,17 +48,14 @@ protected function updateResource(string $id, array $body = []): ?BaseResource { $id = urlencode($id); - $response = $this->client->performHttpCall( - self::REST_UPDATE, - $this->getPathToSingleResource($id), - $this->parseRequestBody($body) - ); - - if ($response->isEmpty()) { - return null; - } - - return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); + return $this + ->client + ->send(new DynamicPatchRequest( + $this->getPathToSingleResource($id), + static::getResourceClass(), + $body + )) + ->toResource(); } /** @@ -69,13 +71,14 @@ protected function readResource(string $id, array $filters): BaseResource throw new ApiException('Invalid resource id.'); } - $id = urlencode($id); - $response = $this->client->performHttpCall( - self::REST_READ, - $this->getPathToSingleResource($id).$this->buildQueryString($filters) - ); - - return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); + return $this + ->client + ->send(new DynamicGetRequest( + $this->getPathToSingleResource($id), + static::getResourceClass(), + $filters + )) + ->toResource(); } /** @@ -90,18 +93,15 @@ protected function deleteResource(string $id, array $body = []): ?BaseResource throw new ApiException('Invalid resource id.'); } - $id = urlencode($id); - $response = $this->client->performHttpCall( - self::REST_DELETE, - $this->getPathToSingleResource($id), - $this->parseRequestBody($body) - ); - - if ($response->isEmpty()) { - return null; - } - - return ResourceFactory::createFromApiResult($this->client, $response->decode(), static::getResourceClass()); + return $this + ->client + ->send(new DynamicDeleteRequest( + $this->getPathToSingleResource($id), + static::getResourceClass(), + null, + $body + )) + ->toResource(); } protected function guardAgainstInvalidId(string $id): void diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 7bdda8897..19aeab70e 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -12,41 +12,29 @@ class SubscriptionEndpoint extends EndpointCollection { /** * The resource path. - * - * @var string */ - protected string $resourcePath = "customers_subscriptions"; + protected string $resourcePath = 'customers_subscriptions'; /** * Resource id prefix. * Used to validate resource id's. - * - * @var string */ protected static string $resourceIdPrefix = 'sub_'; /** * Resource class name. - * - * @var string */ public static string $resource = Subscription::class; /** * The resource collection class name. - * - * @var string */ public static string $resourceCollection = SubscriptionCollection::class; /** * Create a subscription for a Customer * - * @param Customer $customer - * @param array $options - * @param array $filters * - * @return Subscription * @throws ApiException */ public function createFor(Customer $customer, array $options = [], array $filters = []): Subscription @@ -57,11 +45,7 @@ public function createFor(Customer $customer, array $options = [], array $filter /** * Create a subscription for a Customer * - * @param string $customerId - * @param array $options - * @param array $filters * - * @return Subscription * @throws ApiException */ public function createForId(string $customerId, array $options = [], array $filters = []): Subscription @@ -77,12 +61,8 @@ public function createForId(string $customerId, array $options = [], array $filt * * Will throw an ApiException if the subscription id is invalid or the resource cannot be found. * - * @param string $subscriptionId - * @param string $customerId * - * @param array $data * - * @return null|Subscription * @throws ApiException */ public function update(string $customerId, string $subscriptionId, array $data = []): ?Subscription @@ -96,11 +76,6 @@ public function update(string $customerId, string $subscriptionId, array $data = } /** - * @param Customer $customer - * @param string $subscriptionId - * @param array $parameters - * - * @return Subscription * @throws ApiException */ public function getFor(Customer $customer, string $subscriptionId, array $parameters = []): Subscription @@ -109,11 +84,6 @@ public function getFor(Customer $customer, string $subscriptionId, array $parame } /** - * @param string $customerId - * @param string $subscriptionId - * @param array $parameters - * - * @return Subscription * @throws ApiException */ public function getForId(string $customerId, string $subscriptionId, array $parameters = []): Subscription @@ -125,12 +95,8 @@ public function getForId(string $customerId, string $subscriptionId, array $para } /** - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters + * @param string $from The first resource ID you want to include in your list. * - * @return SubscriptionCollection * @throws ApiException */ public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection @@ -141,13 +107,8 @@ public function listFor(Customer $customer, ?string $from = null, ?int $limit = /** * Create an iterator for iterating over subscriptions for the given customer, retrieved from Mollie. * - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorFor( Customer $customer, @@ -160,12 +121,9 @@ public function iteratorFor( } /** - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters + * @param string $customerId + * @param string $from The first resource ID you want to include in your list. * - * @return SubscriptionCollection * @throws ApiException */ public function listForId($customerId, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection @@ -179,13 +137,8 @@ public function listForId($customerId, ?string $from = null, ?int $limit = null, /** * Create an iterator for iterating over subscriptions for the given customer id, retrieved from Mollie. * - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorForId( string $customerId, @@ -200,11 +153,6 @@ public function iteratorForId( } /** - * @param Customer $customer - * @param string $subscriptionId - * @param array $data - * - * @return null|Subscription * @throws ApiException */ public function cancelFor(Customer $customer, string $subscriptionId, array $data = []): ?Subscription @@ -213,11 +161,6 @@ public function cancelFor(Customer $customer, string $subscriptionId, array $dat } /** - * @param string $customerId - * @param string $subscriptionId - * @param array $data - * - * @return null|Subscription * @throws ApiException */ public function cancelForId(string $customerId, string $subscriptionId, array $data = []): ?Subscription @@ -231,16 +174,13 @@ public function cancelForId(string $customerId, string $subscriptionId, array $d /** * Retrieves a collection of Subscriptions from Mollie. * - * @param string $from The first payment ID you want to include in your list. - * @param int $limit - * @param array $parameters + * @param string $from The first payment ID you want to include in your list. * - * @return SubscriptionCollection * @throws ApiException */ public function page(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection { - $apiPath = 'subscriptions' . $this->buildQueryString( + $apiPath = 'subscriptions'.$this->buildQueryString( $this->getMergedFilters($parameters, $from, $limit) ); @@ -250,18 +190,14 @@ public function page(?string $from = null, ?int $limit = null, array $parameters ); /** @var SubscriptionCollection */ - return $this->buildResultCollection($result->decode()); + return $this->buildResultCollection($result->json()); } /** * Create an iterator for iterating over subscriptions retrieved from Mollie. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { diff --git a/src/Factories/CreateClientLinkPayloadFactory.php b/src/Factories/CreateClientLinkPayloadFactory.php index 9135ca6a5..c532a7b4d 100644 --- a/src/Factories/CreateClientLinkPayloadFactory.php +++ b/src/Factories/CreateClientLinkPayloadFactory.php @@ -2,15 +2,15 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreateClientLink; +use Mollie\Api\Http\Payload\CreateClientLinkPayload; use Mollie\Api\Http\Payload\Owner; use Mollie\Api\Http\Payload\OwnerAddress; class CreateClientLinkPayloadFactory extends Factory { - public function create(): CreateClientLink + public function create(): CreateClientLinkPayload { - return new CreateClientLink( + return new CreateClientLinkPayload( Owner::fromArray($this->get('owner')), $this->get('name'), OwnerAddress::fromArray($this->get('address')), diff --git a/src/Factories/CreateCustomerPayloadFactory.php b/src/Factories/CreateCustomerPayloadFactory.php new file mode 100644 index 000000000..0e042b2e9 --- /dev/null +++ b/src/Factories/CreateCustomerPayloadFactory.php @@ -0,0 +1,20 @@ +get('name'), + $this->get('email'), + $this->get('locale'), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index d84e5b384..8a2464905 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -4,14 +4,14 @@ use Mollie\Api\Helpers; use Mollie\Api\Http\Payload\Address; -use Mollie\Api\Http\Payload\CreatePayment; +use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Payload\Metadata; class CreatePaymentPayloadFactory extends Factory { - public function create(): CreatePayment + public function create(): CreatePaymentPayload { - return new CreatePayment( + return new CreatePaymentPayload( $this->get('description'), MoneyFactory::new($this->get('amount'))->create(), $this->get('redirectUrl'), @@ -43,7 +43,7 @@ public function create(): CreatePayment $this->get('mandateId'), $this->get('customerId'), $this->get('profileId'), - $this->get('additional') ?? Helpers::filterByProperties(CreatePayment::class, $this->data), + $this->get('additional') ?? Helpers::filterByProperties(CreatePaymentPayload::class, $this->data), $this->get('testmode') ); } diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php index 822293f3b..9404a546c 100644 --- a/src/Factories/CreateRefundPaymentPayloadFactory.php +++ b/src/Factories/CreateRefundPaymentPayloadFactory.php @@ -2,14 +2,14 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreateRefundPayment; +use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; use Mollie\Api\Http\Payload\Metadata; class CreateRefundPaymentPayloadFactory extends Factory { - public function create(): CreateRefundPayment + public function create(): CreateRefundPaymentPayload { - return new CreateRefundPayment( + return new CreateRefundPaymentPayload( $this->get('description'), MoneyFactory::new($this->data['amount'])->create(), $this->mapIfNotNull('metadata', Metadata::class), diff --git a/src/Factories/UpdateCustomerPayloadFactory.php b/src/Factories/UpdateCustomerPayloadFactory.php new file mode 100644 index 000000000..5870b7c3d --- /dev/null +++ b/src/Factories/UpdateCustomerPayloadFactory.php @@ -0,0 +1,20 @@ +get('name'), + $this->get('email'), + $this->get('locale'), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php index 2e7ee1510..f28d7f092 100644 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -4,13 +4,13 @@ use Mollie\Api\Helpers; use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\UpdatePayment; +use Mollie\Api\Http\Payload\UpdatePaymentPayload; class UpdatePaymentPayloadFactory extends Factory { - public function create(): UpdatePayment + public function create(): UpdatePaymentPayload { - return new UpdatePayment( + return new UpdatePaymentPayload( $this->get('description'), $this->get('redirectUrl'), $this->get('cancelUrl'), @@ -19,7 +19,7 @@ public function create(): UpdatePayment $this->get('method'), $this->get('locale'), $this->get('restrictPaymentMethodsToCountry'), - $this->get('additional') ?? Helpers::filterByProperties(UpdatePayment::class, $this->data), + $this->get('additional') ?? Helpers::filterByProperties(UpdatePaymentPayload::class, $this->data), $this->get('testmode') ); } diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index b5d4d6c55..17b665c0f 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -6,8 +6,11 @@ class Arr { /** * Get all values for the given keys or return the default value. + * + * @param mixed $default + * @return mixed */ - public static function get(array $array, string $keys, mixed $default = null): mixed + public static function get(array $array, string $keys, $default = null) { $keys = explode('.', $keys); $value = $array; diff --git a/src/Helpers/Handler.php b/src/Helpers/Handler.php new file mode 100644 index 000000000..22ac935b9 --- /dev/null +++ b/src/Helpers/Handler.php @@ -0,0 +1,28 @@ +callback = $callback; + $this->priority = $priority; + } + + public function callback(): callable + { + return $this->callback; + } + + public function priority(): string + { + return $this->priority; + } +} diff --git a/src/Helpers/Handlers.php b/src/Helpers/Handlers.php index 9a2593d7d..3b40bf7ef 100644 --- a/src/Helpers/Handlers.php +++ b/src/Helpers/Handlers.php @@ -2,30 +2,72 @@ namespace Mollie\Api\Helpers; +use Mollie\Api\Contracts\ViableResponse; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; class Handlers { + /** + * @var array + */ protected array $handlers = []; - public function add(callable $handler): void + public function add(callable $handler, string $priority): void + { + $this->handlers[] = new Handler($handler, $priority); + } + + public function setHandlers(array $handlers): void { - $this->handlers[] = $handler; + $this->handlers = $handlers; + } + + public function getHandlers(): array + { + return $this->handlers; } /** * Execute the handlers * * @param PendingRequest|Response $payload - * @return PendingRequest|Response + * @return PendingRequest|Response|ViableResponse */ public function execute($payload) { - foreach ($this->handlers as $handler) { - $payload = $handler($payload); + /** @var Handler $handler */ + foreach ($this->sortHandlers() as $handler) { + $payload = call_user_func($handler->callback(), $payload); + + /** + * If the handler returns a value that is not an instance of PendingRequest or Response, + * we assume that the handler has transformed the payload in some way and we return the transformed value. + */ + if ($payload instanceof ViableResponse) { + return $payload; + } } return $payload; } + + protected function sortHandlers(): array + { + $highPriority = []; + $mediumPriority = []; + $lowPriority = []; + + $priorityMap = [ + MiddlewarePriority::HIGH => &$highPriority, + MiddlewarePriority::MEDIUM => &$mediumPriority, + MiddlewarePriority::LOW => &$lowPriority, + ]; + + foreach ($this->handlers as $handler) { + $priorityMap[$handler->priority()][] = $handler; + } + + return array_merge($highPriority, $mediumPriority, $lowPriority); + } } diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Helpers/MiddlewareHandlers.php index 1ef858ade..23bf595b3 100644 --- a/src/Helpers/MiddlewareHandlers.php +++ b/src/Helpers/MiddlewareHandlers.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Helpers; +use Mollie\Api\Contracts\ViableResponse; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; @@ -17,7 +18,7 @@ public function __construct() $this->onResponse = new Handlers; } - public function onRequest(callable $callback): static + public function onRequest(callable $callback, string $priority = MiddlewarePriority::MEDIUM): static { $this->onRequest->add(static function (PendingRequest $pendingRequest) use ($callback): PendingRequest { $result = $callback($pendingRequest); @@ -27,18 +28,21 @@ public function onRequest(callable $callback): static } return $pendingRequest; - }); + }, $priority); return $this; } - public function onResponse(callable $callback): static + public function onResponse(callable $callback, string $priority = MiddlewarePriority::MEDIUM): static { - $this->onResponse->add(static function (Response $response) use ($callback): Response { + $this->onResponse->add(static function (Response $response) use ($callback) { $result = $callback($response); - return $result instanceof Response ? $result : $response; - }); + return $result instanceof Response + || $result instanceof ViableResponse + ? $result + : $response; + }, $priority); return $this; } @@ -48,8 +52,30 @@ public function executeOnRequest(PendingRequest $pendingRequest): PendingRequest return $this->onRequest->execute($pendingRequest); } - public function executeOnResponse(Response $response): Response + /** + * @return Response|ViableResponse + */ + public function executeOnResponse(Response $response) { return $this->onResponse->execute($response); } + + public function merge(MiddlewareHandlers $handlers): static + { + $onRequestHandlers = array_merge( + $this->onRequest->getHandlers(), + $handlers->onRequest->getHandlers(), + ); + + $this->onRequest->setHandlers($onRequestHandlers); + + $onResponseHandlers = array_merge( + $this->onResponse->getHandlers(), + $handlers->onResponse->getHandlers(), + ); + + $this->onResponse->setHandlers($onResponseHandlers); + + return $this; + } } diff --git a/src/Helpers/MiddlewarePriority.php b/src/Helpers/MiddlewarePriority.php new file mode 100644 index 000000000..82345f214 --- /dev/null +++ b/src/Helpers/MiddlewarePriority.php @@ -0,0 +1,12 @@ +getConnector()->evaluateHydrationSetting(); + } +} diff --git a/src/Http/Middleware/GuardResponse.php b/src/Http/Middleware/GuardResponse.php index b942996fe..2bca2cb20 100644 --- a/src/Http/Middleware/GuardResponse.php +++ b/src/Http/Middleware/GuardResponse.php @@ -10,23 +10,19 @@ class GuardResponse { public function __invoke(Response $response) { - if (empty($response->body()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { + if ($isEmpty = $response->isEmpty() && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { throw new ApiException('No response body found.'); } - if (empty($response->body())) { + if ($isEmpty) { return; } - $response->json(); - - if (json_last_error() !== JSON_ERROR_NONE) { - throw new ApiException("Unable to decode Mollie response: '{$response->body()}'."); - } + $data = $response->json(); // @todo check if this is still necessary as it seems to be from api v1 - if (isset($response->json()->error)) { - throw new ApiException($response->json()->error->message); + if (isset($data->error)) { + throw new ApiException($data->error->message); } } } diff --git a/src/Http/Middleware/Hydrate.php b/src/Http/Middleware/Hydrate.php new file mode 100644 index 000000000..aa8a33a06 --- /dev/null +++ b/src/Http/Middleware/Hydrate.php @@ -0,0 +1,20 @@ +getRequest()::$shouldAutoHydrate) { + return $response; + } + + return $this->createResource($response->getRequest(), $response); + } +} diff --git a/src/Http/Payload/Address.php b/src/Http/Payload/Address.php index 0efd5fb17..28ef08310 100644 --- a/src/Http/Payload/Address.php +++ b/src/Http/Payload/Address.php @@ -61,7 +61,7 @@ public function __construct( $this->country = $country; } - public function data(): mixed + public function data(): array { return array_filter([ 'title' => $this->title, diff --git a/src/Http/Payload/CreateClientLink.php b/src/Http/Payload/CreateClientLinkPayload.php similarity index 95% rename from src/Http/Payload/CreateClientLink.php rename to src/Http/Payload/CreateClientLinkPayload.php index 2c84005c4..eb47645f8 100644 --- a/src/Http/Payload/CreateClientLink.php +++ b/src/Http/Payload/CreateClientLinkPayload.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Payload; -class CreateClientLink extends DataBag +class CreateClientLinkPayload extends DataBag { public Owner $owner; diff --git a/src/Http/Payload/CreateCustomerPayload.php b/src/Http/Payload/CreateCustomerPayload.php new file mode 100644 index 000000000..673be16b8 --- /dev/null +++ b/src/Http/Payload/CreateCustomerPayload.php @@ -0,0 +1,41 @@ +name = $name; + $this->email = $email; + $this->locale = $locale; + $this->metadata = $metadata; + $this->testmode = $testmode; + } + + public function data() + { + return [ + 'name' => $this->name, + 'email' => $this->email, + 'locale' => $this->locale, + 'metadata' => $this->metadata, + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Payload/CreatePayment.php b/src/Http/Payload/CreatePaymentPayload.php similarity index 98% rename from src/Http/Payload/CreatePayment.php rename to src/Http/Payload/CreatePaymentPayload.php index 29cc363e4..b670506b2 100644 --- a/src/Http/Payload/CreatePayment.php +++ b/src/Http/Payload/CreatePaymentPayload.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Payload; -class CreatePayment extends DataBag +class CreatePaymentPayload extends DataBag { public string $description; @@ -111,7 +111,7 @@ public function __construct( $this->testmode = $testmode; } - public function data(): mixed + public function data(): array { return array_merge([ 'description' => $this->description, diff --git a/src/Http/Payload/CreateRefundPayment.php b/src/Http/Payload/CreateRefundPaymentPayload.php similarity index 93% rename from src/Http/Payload/CreateRefundPayment.php rename to src/Http/Payload/CreateRefundPaymentPayload.php index 108a51f48..e16efd056 100644 --- a/src/Http/Payload/CreateRefundPayment.php +++ b/src/Http/Payload/CreateRefundPaymentPayload.php @@ -4,7 +4,7 @@ use Mollie\Api\Traits\Makeable; -class CreateRefundPayment extends DataBag +class CreateRefundPaymentPayload extends DataBag { use Makeable; @@ -39,7 +39,7 @@ public function __construct( $this->testmode = $testmode; } - public function data(): mixed + public function data(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/DataCollection.php b/src/Http/Payload/DataCollection.php index a2155e886..cce2c4be8 100644 --- a/src/Http/Payload/DataCollection.php +++ b/src/Http/Payload/DataCollection.php @@ -44,7 +44,7 @@ public static function wrap(object $subject): static return new static((array) $subject); } - public function data(): mixed + public function data(): array { return $this->toArray(); } diff --git a/src/Http/Payload/OrderLine.php b/src/Http/Payload/OrderLine.php index 967d2856f..f32fc66da 100644 --- a/src/Http/Payload/OrderLine.php +++ b/src/Http/Payload/OrderLine.php @@ -65,7 +65,7 @@ public function __construct( $this->productUrl = $productUrl; } - public function data(): mixed + public function data(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index f11dd678e..c8ce012c5 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -12,7 +12,7 @@ public function __construct( public readonly ?DateTime $delayUntil = null, ) {} - public function data(): mixed + public function data(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php index f69be4b51..1aa35947e 100644 --- a/src/Http/Payload/RecurringBillingCycle.php +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -36,7 +36,7 @@ public function __construct( $this->startDate = $startDate; } - public function data(): mixed + public function data(): array { return [ 'interval' => $this->interval, diff --git a/src/Http/Payload/RefundRoute.php b/src/Http/Payload/RefundRoute.php index 50f396ecd..c2dc24326 100644 --- a/src/Http/Payload/RefundRoute.php +++ b/src/Http/Payload/RefundRoute.php @@ -16,7 +16,7 @@ public function __construct( $this->organizationId = $organizationId; } - public function data(): mixed + public function data(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/UpdateCustomerPayload.php b/src/Http/Payload/UpdateCustomerPayload.php new file mode 100644 index 000000000..f40f7a120 --- /dev/null +++ b/src/Http/Payload/UpdateCustomerPayload.php @@ -0,0 +1,8 @@ +method = $request->getMethod(); $this->url = Url::join($connector->resolveBaseUrl(), $request->resolveResourcePath()); + $this->middleware()->merge($connector->middleware()); + $this ->tap(new MergeRequestProperties) ->tap(new ValidateProperties) @@ -56,10 +62,13 @@ public function __construct(Connector $connector, Request $request) $this ->middleware() + ->onRequest(new EvaluateHydrationSetting) ->onRequest(new ApplyIdempotencyKey) ->onResponse(new ResetIdempotencyKey) - ->onResponse(new GuardResponse) - ->onResponse(new ThrowExceptionIfRequestFailed); + ->onResponse(new GuardResponse, MiddlewarePriority::HIGH) + ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH) + ->onResponse(new Hydrate, MiddlewarePriority::LOW); + } public function setPayload(BodyRepository $bodyRepository): static @@ -99,7 +108,10 @@ public function executeRequestHandlers(): self return $this->middleware()->executeOnRequest($this); } - public function executeResponseHandlers(Response $response): Response + /** + * @return Response|HasResponse + */ + public function executeResponseHandlers(Response $response) { return $this->middleware()->executeOnResponse($response); } diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php index 9679e2b32..c71811972 100644 --- a/src/Http/PendingRequest/AuthenticateRequest.php +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Http\PendingRequest; +use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Auth\ApiKeyAuthenticator; use Mollie\Api\Http\PendingRequest; @@ -20,12 +21,22 @@ public function __invoke(PendingRequest $pendingRequest): PendingRequest * Remove testmode parameter from the request if authenticated via ApiKey. */ if ($authenticator instanceof ApiKeyAuthenticator) { - $pendingRequest->query()->remove('testmode'); - $pendingRequest->body()?->remove('testmode'); + $this->removeTestmode($pendingRequest); } $authenticator->authenticate($pendingRequest); return $pendingRequest; } + + private function removeTestmode(PendingRequest $pendingRequest): void + { + if ($pendingRequest->query()->has('testmode')) { + $pendingRequest->query()->remove('testmode'); + } + + if ($pendingRequest->getRequest() instanceof HasPayload) { + $pendingRequest->body()?->remove('testmode'); + } + } } diff --git a/src/Http/Request.php b/src/Http/Request.php index cc4ef43c9..408646613 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -22,6 +22,13 @@ abstract class Request implements ValidatableDataProvider */ public static string $targetResourceClass; + public static bool $shouldAutoHydrate = false; + + public static function hydrate(bool $shouldAutoHydrate = true): void + { + self::$shouldAutoHydrate = $shouldAutoHydrate; + } + /** * Get the method of the request. */ diff --git a/src/Http/Requests/CancelPaymentRequest.php b/src/Http/Requests/CancelPaymentRequest.php index e402ddf21..34a7daf16 100644 --- a/src/Http/Requests/CancelPaymentRequest.php +++ b/src/Http/Requests/CancelPaymentRequest.php @@ -2,40 +2,16 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; use Mollie\Api\Rules\Id; use Mollie\Api\Types\Method; -class CancelPaymentRequest extends Request +class CancelPaymentRequest extends SimpleRequest { - /** - * Define the HTTP method. - */ protected static string $method = Method::DELETE; - /** - * The resource class the request should be casted to. - */ public static string $targetResourceClass = Payment::class; - private string $id; - - private bool $testmode; - - public function __construct(string $id, bool $testmode = false) - { - $this->id = $id; - $this->testmode = $testmode; - } - - protected function defaultQuery(): array - { - return [ - 'testmode' => $this->testmode, - ]; - } - public function rules(): array { return [ diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index a0a8e39f2..ccc4079d2 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Payload\CreateClientLink; +use Mollie\Api\Http\Payload\CreateClientLinkPayload; use Mollie\Api\Http\Request; use Mollie\Api\Resources\ClientLink; use Mollie\Api\Types\Method; @@ -19,9 +19,9 @@ class CreateClientLinkRequest extends Request */ public static string $targetResourceClass = ClientLink::class; - private CreateClientLink $payload; + private CreateClientLinkPayload $payload; - public function __construct(CreateClientLink $payload) + public function __construct(CreateClientLinkPayload $payload) { $this->payload = $payload; } diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php new file mode 100644 index 000000000..347c6ba2b --- /dev/null +++ b/src/Http/Requests/CreateCustomerRequest.php @@ -0,0 +1,36 @@ +payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return 'customers'; + } +} diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index baa563afe..72479fbe2 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\CreatePayment; +use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; @@ -24,11 +24,11 @@ class CreatePaymentRequest extends Request implements HasPayload */ public static string $targetResourceClass = Payment::class; - private CreatePayment $payload; + private CreatePaymentPayload $payload; private ?CreatePaymentQuery $query = null; - public function __construct(CreatePayment $payload, ?CreatePaymentQuery $query = null) + public function __construct(CreatePaymentPayload $payload, ?CreatePaymentQuery $query = null) { $this->payload = $payload; $this->query = $query; diff --git a/src/Http/Requests/CreateRefundPaymentRequest.php b/src/Http/Requests/CreateRefundPaymentRequest.php index f9336225d..c86bb9bc6 100644 --- a/src/Http/Requests/CreateRefundPaymentRequest.php +++ b/src/Http/Requests/CreateRefundPaymentRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmode; -use Mollie\Api\Http\Payload\CreateRefundPayment; +use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; use Mollie\Api\Rules\Id; @@ -27,11 +27,11 @@ class CreateRefundPaymentRequest extends Request implements HasPayload, Supports private string $paymentId; - private CreateRefundPayment $payload; + private CreateRefundPaymentPayload $payload; public function __construct( string $identifier, - CreateRefundPayment $payload + CreateRefundPaymentPayload $payload ) { $this->paymentId = $identifier; $this->payload = $payload; diff --git a/src/Http/Requests/DeleteCustomerRequest.php b/src/Http/Requests/DeleteCustomerRequest.php new file mode 100644 index 000000000..55179f797 --- /dev/null +++ b/src/Http/Requests/DeleteCustomerRequest.php @@ -0,0 +1,26 @@ + Id::startsWithPrefix(Customer::$resourceIdPrefix), + ]; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->id}"; + } +} diff --git a/src/Http/Requests/DynamicDeleteRequest.php b/src/Http/Requests/DynamicDeleteRequest.php index a448445e0..35c06df70 100644 --- a/src/Http/Requests/DynamicDeleteRequest.php +++ b/src/Http/Requests/DynamicDeleteRequest.php @@ -2,10 +2,14 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class DynamicDeleteRequest extends DynamicRequest +class DynamicDeleteRequest extends DynamicRequest implements HasPayload { + use HasJsonPayload; + /** * Define the HTTP method. */ @@ -13,14 +17,18 @@ class DynamicDeleteRequest extends DynamicRequest private ?bool $testmode = null; + private array $body = []; + public function __construct( string $url, string $resourceClass = '', - ?bool $testmode = null + ?bool $testmode = null, + array $body = [], ) { parent::__construct($url, $resourceClass); $this->testmode = $testmode; + $this->body = $body; } protected function defaultQuery(): array @@ -29,4 +37,9 @@ protected function defaultQuery(): array 'testmode' => $this->testmode, ]; } + + protected function defaultPayload(): array + { + return $this->body; + } } diff --git a/src/Http/Requests/DynamicGetRequest.php b/src/Http/Requests/DynamicGetRequest.php index 7fc24b426..5a77d4ead 100644 --- a/src/Http/Requests/DynamicGetRequest.php +++ b/src/Http/Requests/DynamicGetRequest.php @@ -10,4 +10,21 @@ class DynamicGetRequest extends DynamicRequest * Define the HTTP method. */ protected static string $method = Method::GET; + + private array $query = []; + + public function __construct( + string $url, + string $resourceClass = '', + array $query = [] + ) { + parent::__construct($url, $resourceClass); + + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query; + } } diff --git a/src/Http/Requests/DynamicPatchRequest.php b/src/Http/Requests/DynamicPatchRequest.php new file mode 100644 index 000000000..2fbf178ff --- /dev/null +++ b/src/Http/Requests/DynamicPatchRequest.php @@ -0,0 +1,40 @@ +payload = $payload; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query; + } + + protected function defaultPayload(): array + { + return $this->payload; + } +} diff --git a/src/Http/Requests/DynamicPostRequest.php b/src/Http/Requests/DynamicPostRequest.php new file mode 100644 index 000000000..72d8bb250 --- /dev/null +++ b/src/Http/Requests/DynamicPostRequest.php @@ -0,0 +1,43 @@ +payload = $payload; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query; + } + + protected function defaultPayload(): array + { + return $this->payload; + } +} diff --git a/src/Http/Requests/GetBalanceRequest.php b/src/Http/Requests/GetBalanceRequest.php index 9922b7716..d47097261 100644 --- a/src/Http/Requests/GetBalanceRequest.php +++ b/src/Http/Requests/GetBalanceRequest.php @@ -2,39 +2,15 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Balance; use Mollie\Api\Types\Method; -class GetBalanceRequest extends Request +class GetBalanceRequest extends SimpleRequest { - /** - * Define the HTTP method. - */ protected static string $method = Method::GET; - /** - * The resource class the request should be casted to. - */ public static string $targetResourceClass = Balance::class; - private string $id; - - private bool $testmode; - - public function __construct(string $id, bool $testmode = false) - { - $this->id = $id; - $this->testmode = $testmode; - } - - protected function defaultQuery(): array - { - return [ - 'testmode' => $this->testmode, - ]; - } - /** * Resolve the resource path. */ diff --git a/src/Http/Requests/GetCustomerRequest.php b/src/Http/Requests/GetCustomerRequest.php new file mode 100644 index 000000000..19d1c4682 --- /dev/null +++ b/src/Http/Requests/GetCustomerRequest.php @@ -0,0 +1,29 @@ +id}"; + } + + public function rules(): array + { + return [ + 'id' => Id::startsWithPrefix(Customer::$resourceIdPrefix), + ]; + } +} diff --git a/src/Http/Requests/GetPaginatedCustomerRequest.php b/src/Http/Requests/GetPaginatedCustomerRequest.php new file mode 100644 index 000000000..843cabdd9 --- /dev/null +++ b/src/Http/Requests/GetPaginatedCustomerRequest.php @@ -0,0 +1,19 @@ +id = $id; + $this->testmode = $testmode; + } + + protected function defaultQuery(): array + { + return [ + 'testmode' => $this->testmode, + ]; + } +} diff --git a/src/Http/Requests/UpdateCustomerRequest.php b/src/Http/Requests/UpdateCustomerRequest.php new file mode 100644 index 000000000..6af5eab8f --- /dev/null +++ b/src/Http/Requests/UpdateCustomerRequest.php @@ -0,0 +1,57 @@ +id = $id; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + protected function defaultQuery(): array + { + return [ + 'testmode' => false, + ]; + } + + public function rules(): array + { + return [ + 'id' => Id::startsWithPrefix(Customer::$resourceIdPrefix), + ]; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->id}"; + } +} diff --git a/src/Http/Requests/UpdatePaymentRequest.php b/src/Http/Requests/UpdatePaymentRequest.php index 057dcc735..259f165eb 100644 --- a/src/Http/Requests/UpdatePaymentRequest.php +++ b/src/Http/Requests/UpdatePaymentRequest.php @@ -2,24 +2,30 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Payload\UpdatePayment; +use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; use Mollie\Api\Rules\Id; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class UpdatePaymentRequest extends Request +class UpdatePaymentRequest extends Request implements HasPayload { use HasJsonPayload; protected static string $method = Method::PATCH; + /** + * The resource class the request should be casted to. + */ + public static string $targetResourceClass = Payment::class; + private string $id; - private UpdatePayment $payload; + private UpdatePaymentPayload $payload; - public function __construct(string $id, UpdatePayment $payload) + public function __construct(string $id, UpdatePaymentPayload $payload) { $this->id = $id; $this->payload = $payload; diff --git a/src/Http/Response.php b/src/Http/Response.php index e3c593553..641224f91 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -4,6 +4,7 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Traits\HandlesResourceCreation; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -12,6 +13,8 @@ class Response { + use HandlesResourceCreation; + protected ResponseInterface $psrResponse; protected RequestInterface $psrRequest; @@ -37,6 +40,14 @@ public function __construct( $this->senderException = $senderException; } + /** + * @return mixed + */ + public function toResource() + { + return $this->createResource($this->getRequest(), $this); + } + /** * Get the JSON decoded body of the response as an array or scalar value. */ diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 9f434ba47..4815b17ed 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -11,16 +11,16 @@ use Mollie\Api\EndpointCollection\ChargebackEndpointCollection; use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; +use Mollie\Api\EndpointCollection\CustomerEndpointCollection; +use Mollie\Api\EndpointCollection\OrderEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Endpoints\CustomerEndpoint; use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; use Mollie\Api\Endpoints\MandateEndpoint; use Mollie\Api\Endpoints\MethodEndpoint; use Mollie\Api\Endpoints\MethodIssuerEndpoint; use Mollie\Api\Endpoints\OnboardingEndpoint; -use Mollie\Api\Endpoints\OrderEndpoint; use Mollie\Api\Endpoints\OrderLineEndpoint; use Mollie\Api\Endpoints\OrderPaymentEndpoint; use Mollie\Api\Endpoints\OrderRefundEndpoint; @@ -49,11 +49,13 @@ use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Traits\HandlesAuthentication; +use Mollie\Api\Traits\HandlesAutoHydration; use Mollie\Api\Traits\HandlesDebugging; use Mollie\Api\Traits\HandlesIdempotency; use Mollie\Api\Traits\HandlesTestmode; use Mollie\Api\Traits\HandlesVersions; use Mollie\Api\Traits\HasEndpoints; +use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; use Mollie\Api\Traits\SendsRequests; @@ -66,13 +68,13 @@ * @property ClientEndpointCollection $clients * @property ClientLinkEndpointCollection $clientLinks * @property CustomerPaymentsEndpoint $customerPayments - * @property CustomerEndpoint $customers + * @property CustomerEndpointCollection $customers * @property InvoiceEndpoint $invoices * @property MandateEndpoint $mandates * @property MethodEndpoint $methods * @property MethodIssuerEndpoint $methodIssuers * @property OnboardingEndpoint $onboarding - * @property OrderEndpoint $orders + * @property OrderEndpointCollection $orders * @property OrderLineEndpoint $orderLines * @property OrderPaymentEndpoint $orderPayments * @property OrderRefundEndpoint $orderRefunds @@ -104,11 +106,13 @@ class MollieApiClient implements Connector { use HandlesAuthentication; + use HandlesAutoHydration; use HandlesDebugging; use HandlesIdempotency; use HandlesTestmode; use HandlesVersions; use HasEndpoints; + use HasMiddleware; use HasRequestProperties; use Initializable; use SendsRequests; diff --git a/src/Repositories/ArrayStore.php b/src/Repositories/ArrayStore.php index fcfb5e64d..bca6975ae 100644 --- a/src/Repositories/ArrayStore.php +++ b/src/Repositories/ArrayStore.php @@ -21,7 +21,11 @@ public function set(array $data): static return $this; } - public function get(string $key, mixed $default = null): mixed + /** + * @param mixed $default + * @return mixed + */ + public function get(string $key, $default = null) { return $this->store[$key] ?? $default; } @@ -54,7 +58,7 @@ public function remove(string $key): static public function all(): array { - return array_filter($this->store, fn ($value) => ! empty($value)); + return $this->store; } public function isEmpty(): bool diff --git a/src/Repositories/JsonBodyRepository.php b/src/Repositories/JsonBodyRepository.php index ee5829b39..bcd03c0b6 100644 --- a/src/Repositories/JsonBodyRepository.php +++ b/src/Repositories/JsonBodyRepository.php @@ -15,14 +15,17 @@ public function __construct(array $data = []) $this->set($data); } - public function set(mixed $value): static + /** + * @param mixed $value + */ + public function set($value): static { $this->store = $value; return $this; } - public function all(): mixed + public function all(): array { return $this->store; } diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 94d32c8b6..4f7a5875c 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -2,10 +2,12 @@ namespace Mollie\Api\Resources; +use ArrayObject; use Mollie\Api\Contracts\Connector; +use Mollie\Api\Contracts\HasResponse; use Mollie\Api\Http\Response; -abstract class BaseCollection extends \ArrayObject +abstract class BaseCollection extends ArrayObject implements HasResponse { protected Connector $connector; @@ -21,12 +23,13 @@ abstract class BaseCollection extends \ArrayObject /** * @param array|object $items */ - public function __construct(Connector $connector, Response $response, $items = [], ?\stdClass $_links = null) + public function __construct(Connector $connector, $items = [], ?\stdClass $_links = null, ?Response $response = null) { parent::__construct($items); $this->_links = $_links; $this->connector = $connector; + $this->response = $response; } public function getResponse(): ?Response diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 856568b64..8a9c01cb8 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -3,10 +3,12 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\Connector; +use Mollie\Api\Contracts\HasResponse; +use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; #[\AllowDynamicProperties] -abstract class BaseResource +abstract class BaseResource implements HasResponse { protected Connector $connector; @@ -27,8 +29,13 @@ public function __construct(Connector $connector, ?Response $response = null) $this->response = $response; } - public function getResponse(): Response + public function getResponse(): ?Response { return $this->response; } + + public function getPendingRequest(): ?PendingRequest + { + return $this->response?->getPendingRequest(); + } } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 644138694..3110a710c 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -8,6 +8,8 @@ class Customer extends BaseResource { use HasPresetOptions; + public static string $resourceIdPrefix = 'cst_'; + /** * Id of the customer. * diff --git a/src/Resources/LazyCollection.php b/src/Resources/LazyCollection.php index 0fc90f081..2893e1e74 100644 --- a/src/Resources/LazyCollection.php +++ b/src/Resources/LazyCollection.php @@ -4,6 +4,7 @@ use Iterator; use IteratorAggregate; +use Mollie\Api\Contracts\ViableResponse; /** * @template TKey of array-key @@ -11,7 +12,7 @@ * * @implements IteratorAggregate */ -class LazyCollection implements IteratorAggregate +class LazyCollection implements IteratorAggregate, ViableResponse { /** * @var callable @@ -19,7 +20,7 @@ class LazyCollection implements IteratorAggregate private $source; /** - * @param callable $source + * @param callable $source */ public function __construct($source) { @@ -28,8 +29,6 @@ public function __construct($source) /** * Get all items in the collection. - * - * @return array */ public function all(): array { @@ -39,7 +38,7 @@ public function all(): array /** * Get an item from the collection by key. * - * @param TKey $key + * @param TKey $key * @return TValue|null */ public function get($key) @@ -56,8 +55,7 @@ public function get($key) /** * Run a filter over each of the items. * - * @param (callable(TValue, TKey): bool) $callback - * @return self + * @param (callable(TValue, TKey): bool) $callback */ public function filter(callable $callback): self { @@ -73,10 +71,10 @@ public function filter(callable $callback): self /** * Get the first item from the collection passing the given truth test. * - * @param (callable(TValue, TKey): bool)|null $callback + * @param (callable(TValue, TKey): bool)|null $callback * @return TValue|null */ - public function first(callable $callback = null) + public function first(?callable $callback = null) { $iterator = $this->getIterator(); @@ -102,7 +100,7 @@ public function first(callable $callback = null) * * @template TMapValue * - * @param callable(TValue, TKey): TMapValue $callback + * @param callable(TValue, TKey): TMapValue $callback * @return static */ public function map(callable $callback): self @@ -117,7 +115,6 @@ public function map(callable $callback): self /** * Take the first {$limit} items. * - * @param int $limit * @return static */ public function take(int $limit): self @@ -142,8 +139,7 @@ public function take(int $limit): self /** * Determine if all items pass the given truth test. * - * @param (callable(TValue, TKey): bool) $callback - * @return bool + * @param (callable(TValue, TKey): bool) $callback */ public function every(callable $callback): bool { @@ -160,8 +156,6 @@ public function every(callable $callback): bool /** * Count the number of items in the collection. - * - * @return int */ public function count(): int { @@ -184,7 +178,7 @@ public function getIterator(): Iterator * @template TIteratorKey of array-key * @template TIteratorValue * - * @param IteratorAggregate|(callable(): \Generator) $source + * @param IteratorAggregate|(callable(): \Generator) $source * @return Iterator */ protected function makeIterator($source): Iterator diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index b3fe0d57a..5b75a354b 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -13,12 +13,17 @@ class ResourceFactory /** * Create resource object from Api result */ - public static function createFromApiResult(Connector $connector, ?Response $response, string $resourceClass): BaseResource + public static function createFromApiResult(Connector $connector, $data, string $resourceClass, ?Response $response = null): BaseResource { + if ($data instanceof Response) { + $response = $data; + $data = $response->json(); + } + /** @var BaseResource $resource */ $resource = new $resourceClass($connector, $response); - foreach ($response->json() as $property => $value) { + foreach ($data as $property => $value) { $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) ? self::parseEmbeddedResources($connector, $resource, $value) : $value; @@ -58,7 +63,6 @@ private static function parseEmbeddedResources(Connector $connector, object $res $result->{$resourceKey} = is_subclass_of($collectionOrResourceClass, BaseResource::class) ? self::createFromApiResult( $connector, - null, $resourceData, $collectionOrResourceClass ) @@ -98,9 +102,9 @@ public static function createBaseResourceCollection( Connector $connector, string $resourceClass, $data = null, - ?Response $response = null, ?object $_links = null, - ?string $resourceCollectionClass = null + ?string $resourceCollectionClass = null, + ?Response $response = null, ): BaseCollection { return self::instantiateBaseCollection( $connector, @@ -118,7 +122,7 @@ private static function instantiateBaseCollection( ?object $_links = null, ?Response $response = null ): BaseCollection { - return new $collectionClass($connector, $response, $items, $_links); + return new $collectionClass($connector, $items, $_links, $response); } /** @@ -129,9 +133,9 @@ private static function mapToResourceObjects(Connector $connector, $data, string return array_map( fn ($item) => static::createFromApiResult( $connector, - $response, $item, - $resourceClass + $resourceClass, + $response, ), (array) $data ); diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php new file mode 100644 index 000000000..861b3d1f5 --- /dev/null +++ b/src/Traits/HandlesAutoHydration.php @@ -0,0 +1,34 @@ +getTargetResourceClass(); @@ -24,7 +27,7 @@ protected function createResource(Request $request, Response $response): mixed } if ($this->isResourceTarget($targetResourceClass)) { - return ResourceFactory::createFromApiResult($this, $response, $targetResourceClass); + return ResourceFactory::createFromApiResult($response->getConnector(), $response, $targetResourceClass); } return $response; @@ -45,12 +48,12 @@ private function buildResultCollection(Response $response, string $targetCollect $result = $response->json(); return ResourceFactory::createBaseResourceCollection( - $this, + $response->getConnector(), ($targetCollectionClass)::getResourceClass(), $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, - $response, $result->_links, - $targetCollectionClass + $targetCollectionClass, + $response, ); } diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index aad4ff762..05c686d6e 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -6,16 +6,16 @@ use Mollie\Api\EndpointCollection\ChargebackEndpointCollection; use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; +use Mollie\Api\EndpointCollection\CustomerEndpointCollection; +use Mollie\Api\EndpointCollection\OrderEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Endpoints\CustomerEndpoint; use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; use Mollie\Api\Endpoints\MandateEndpoint; use Mollie\Api\Endpoints\MethodEndpoint; use Mollie\Api\Endpoints\MethodIssuerEndpoint; use Mollie\Api\Endpoints\OnboardingEndpoint; -use Mollie\Api\Endpoints\OrderEndpoint; use Mollie\Api\Endpoints\OrderLineEndpoint; use Mollie\Api\Endpoints\OrderPaymentEndpoint; use Mollie\Api\Endpoints\OrderRefundEndpoint; @@ -59,19 +59,14 @@ protected function initializeHasEndpoints(): void } $endpointClasses = [ - // new 'balances' => BalanceEndpointCollection::class, 'balanceReports' => BalanceEndpointCollection::class, 'balanceTransactions' => BalanceTransactionCollection::class, 'chargebacks' => ChargebackEndpointCollection::class, 'clients' => ClientEndpointCollection::class, 'clientLinks' => ClientLinkEndpointCollection::class, - 'payments' => PaymentEndpointCollection::class, - 'paymentRefunds' => PaymentRefundEndpointCollection::class, - - // old 'customerPayments' => CustomerPaymentsEndpoint::class, - 'customers' => CustomerEndpoint::class, + 'customers' => CustomerEndpointCollection::class, 'invoices' => InvoiceEndpoint::class, 'mandates' => MandateEndpoint::class, 'methods' => MethodEndpoint::class, @@ -80,9 +75,11 @@ protected function initializeHasEndpoints(): void 'orderLines' => OrderLineEndpoint::class, 'orderPayments' => OrderPaymentEndpoint::class, 'orderRefunds' => OrderRefundEndpoint::class, - 'orders' => OrderEndpoint::class, + 'orders' => OrderEndpointCollection::class, 'organizationPartners' => OrganizationPartnerEndpoint::class, 'organizations' => OrganizationEndpoint::class, + 'payments' => PaymentEndpointCollection::class, + 'paymentRefunds' => PaymentRefundEndpointCollection::class, 'paymentCaptures' => PaymentCaptureEndpoint::class, 'paymentChargebacks' => PaymentChargebackEndpoint::class, 'paymentLinks' => PaymentLinkEndpoint::class, diff --git a/src/Traits/HasHeaders.php b/src/Traits/HasHeaders.php index b57c0249d..e7c5b8534 100644 --- a/src/Traits/HasHeaders.php +++ b/src/Traits/HasHeaders.php @@ -2,13 +2,14 @@ namespace Mollie\Api\Traits; +use Mollie\Api\Contracts\ArrayRepository; use Mollie\Api\Repositories\ArrayStore; trait HasHeaders { - protected ?ArrayStore $headers; + protected ArrayRepository $headers; - public function headers(): ArrayStore + public function headers(): ArrayRepository { return $this->headers ??= new ArrayStore($this->defaultHeaders()); } diff --git a/src/Traits/HasQuery.php b/src/Traits/HasQuery.php index 5ed36c53b..45a632237 100644 --- a/src/Traits/HasQuery.php +++ b/src/Traits/HasQuery.php @@ -2,13 +2,14 @@ namespace Mollie\Api\Traits; +use Mollie\Api\Contracts\ArrayRepository; use Mollie\Api\Repositories\ArrayStore; trait HasQuery { - protected ?ArrayStore $queryStore; + protected ArrayRepository $queryStore; - public function query(): ArrayStore + public function query(): ArrayRepository { return $this->queryStore ??= new ArrayStore($this->defaultQuery()); } diff --git a/src/Traits/SendsRequests.php b/src/Traits/SendsRequests.php index d80c64483..d0de39c52 100644 --- a/src/Traits/SendsRequests.php +++ b/src/Traits/SendsRequests.php @@ -11,20 +11,14 @@ */ trait SendsRequests { - use HandlesResourceCreation; - - public function send(Request $request): ?object + public function send(Request $request): object { $pendingRequest = new PendingRequest($this, $request); - // Execute request middleware - $pendingRequest->executeRequestHandlers(); + $pendingRequest = $pendingRequest->executeRequestHandlers(); $response = $this->httpClient->sendRequest($pendingRequest); - // Execute response middleware - $response = $pendingRequest->executeResponseHandlers($response); - - return $this->createResource($request, $response); + return $pendingRequest->executeResponseHandlers($response); } } diff --git a/src/Traits/ValidatesProperties.php b/src/Traits/ValidatesProperties.php deleted file mode 100644 index 28a16ddf6..000000000 --- a/src/Traits/ValidatesProperties.php +++ /dev/null @@ -1,104 +0,0 @@ -rules(); - - [$validatableProperties, $rulesWithValues] = $this->getValidatableAndRules($rules); - - // Perform validation using the returned arrays - foreach ($validatableProperties as $property) { - $property->validate(); - } - - foreach ($rulesWithValues as [$rule, $value]) { - $rule->validate($this, $value); - } - } - - private function getValidatableAndRules(array $rules = []): array - { - $validatableProperties = []; - $rulesWithValues = []; - - /** @var ReflectionProperty $property */ - foreach (Helpers::getProperties($this) as $property) { - if ($property->isStatic() || ! $property->isInitialized($this)) { - continue; - } - - $value = $this->extractValue($property); - - if ($value === null) { - continue; - } - - if ($value instanceof Validatable) { - $validatableProperties[] = $value; - } elseif (array_key_exists($property->getName(), $rules)) { - $rulesWithValues[] = [$rules[$property->getName()], $value]; - } - } - - return [$validatableProperties, $rulesWithValues]; - } - - private function validateProperties(array $rules = []): void - { - /** @var ReflectionProperty $property */ - foreach (Helpers::getProperties($this) as $property) { - if ($property->isStatic() || ! $property->isInitialized($this)) { - continue; - } - - $value = $this->extractValue($property); - - if ($value === null) { - continue; - } - - if ($value instanceof Validatable) { - $value->validate(); - } elseif (array_key_exists($property->getName(), $rules)) { - $rules[$property->getName()]->validate($this, $value); - } - } - } - - private function extractValue(ReflectionProperty $property): mixed - { - return $property->getValue($this); - } - - private function validateQuery(array $rules = []): void - { - if (empty($rules)) { - return; - } - - $nonNullValues = array_filter($this->query()->all()); - - $queryToValidate = array_filter( - $nonNullValues, - fn ($_, $key) => array_key_exists($key, $rules), - ARRAY_FILTER_USE_BOTH - ); - - foreach ($queryToValidate as $property => $value) { - $rules[$property]->validate($this, $value); - } - } - - public function rules(): array - { - return []; - } -} diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 8d473f4a6..582336dca 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -101,7 +101,7 @@ public function testIterateBalances() public function testGetBalance() { $client = new MockClient([ - GetBalanceRequest::class => new MockResponse(200, 'balance-get'), + GetBalanceRequest::class => new MockResponse(200, 'balance'), ]); /** @var Balance $balance */ @@ -125,7 +125,7 @@ public function testGetBalance() public function testGetPrimaryBalance() { $client = new MockClient([ - GetBalanceRequest::class => new MockResponse(200, 'balance-get'), + GetBalanceRequest::class => new MockResponse(200, 'balance'), ]); /** @var Balance $balance */ diff --git a/tests/Fixtures/MockResponse.php b/tests/Fixtures/MockResponse.php index 795ca4c75..afe19bfdb 100644 --- a/tests/Fixtures/MockResponse.php +++ b/tests/Fixtures/MockResponse.php @@ -13,17 +13,17 @@ class MockResponse private int $status; - private array $headers; + private string $resourceId; private string $body; public function __construct( int $status = 200, string $body = '', - array $headers = [], + string $resourceId = '', ) { $this->status = $status; - $this->headers = $headers; + $this->resourceId = $resourceId; $this->body = $body; } @@ -58,7 +58,13 @@ public function body(): string $body.'.json', ], DIRECTORY_SEPARATOR); - return file_get_contents($path); + $contents = file_get_contents($path); + + if (! empty($this->resourceId)) { + $contents = str_replace('{{ RESOURCE_ID }}', $this->resourceId, $contents); + } + + return $contents; } public function assertResponseBodyEquals(ResponseInterface $response): void diff --git a/tests/Fixtures/Responses/balance-get.json b/tests/Fixtures/Responses/balance.json similarity index 100% rename from tests/Fixtures/Responses/balance-get.json rename to tests/Fixtures/Responses/balance.json diff --git a/tests/Fixtures/Responses/cursor-collection-next.json b/tests/Fixtures/Responses/cursor-collection-next.json new file mode 100644 index 000000000..b376e4777 --- /dev/null +++ b/tests/Fixtures/Responses/cursor-collection-next.json @@ -0,0 +1,18 @@ +{ + "count": 1, + "_links": { + "self": { + "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + }, + "next": { + "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + } + }, + "_embedded": { + "orders": [ + { + "id": "{{ RESOURCE_ID }}" + } + ] + } +} diff --git a/tests/Fixtures/Responses/cursor-collection.json b/tests/Fixtures/Responses/cursor-collection.json new file mode 100644 index 000000000..f272c7ea2 --- /dev/null +++ b/tests/Fixtures/Responses/cursor-collection.json @@ -0,0 +1,15 @@ +{ + "count": 1, + "_links": { + "self": { + "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + } + }, + "_embedded": { + "orders": [ + { + "id": "{{ RESOURCE_ID }}" + } + ] + } +} diff --git a/tests/Fixtures/Responses/payment.json b/tests/Fixtures/Responses/payment.json new file mode 100644 index 000000000..c2f70d2b7 --- /dev/null +++ b/tests/Fixtures/Responses/payment.json @@ -0,0 +1,37 @@ +{ + "resource": "payment", + "id": "tr_44aKxzEbr8", + "mode": "test", + "createdAt": "2018-03-13T14:02:29+00:00", + "amount": { + "value": "20.00", + "currency": "EUR" + }, + "description": "My first API payment", + "method": null, + "metadata": { + "order_id": "1234" + }, + "status": "open", + "isCancelable": false, + "expiresAt": "2018-03-13T14:17:29+00:00", + "details": null, + "profileId": "pfl_2A1gacu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://example.org/redirect", + "webhookUrl": "https://example.org/webhook", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", + "type": "text/html" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/payments-api/create-payment", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/SequenceMockResponse.php b/tests/Fixtures/SequenceMockResponse.php new file mode 100644 index 000000000..f7d2bed1b --- /dev/null +++ b/tests/Fixtures/SequenceMockResponse.php @@ -0,0 +1,33 @@ + + */ + private array $responses; + + private int $index = 0; + + public function __construct(...$responses) + { + $this->responses = $responses; + } + + public function pop(): MockResponse + { + if (! isset($this->responses[$this->index])) { + throw new \RuntimeException('No more responses available.'); + } + + $response = $this->responses[$this->index]; + + unset($this->responses[$this->index]); + + $this->index++; + + return $response; + } +} diff --git a/tests/Helpers/MiddlewareHandlersTest.php b/tests/Helpers/MiddlewareHandlersTest.php index b74378bf2..4d8837684 100644 --- a/tests/Helpers/MiddlewareHandlersTest.php +++ b/tests/Helpers/MiddlewareHandlersTest.php @@ -3,8 +3,10 @@ namespace Mollie\Api\Helpers; use Mollie\Api\Http\PendingRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; +use Tests\Fixtures\MockClient; class MiddlewareHandlersTest extends TestCase { @@ -21,7 +23,9 @@ public function it_can_add_request_middleware_and_execute_it(): void return $pendingRequest; }); - $result = $middlewareHandlers->executeOnRequest(new PendingRequest); + $result = $middlewareHandlers->executeOnRequest( + new PendingRequest(new MockClient, new DynamicGetRequest('')) + ); $this->assertEquals('Bar', $result->headers()->get('Foo')); } @@ -39,6 +43,42 @@ public function it_can_add_response_middleware_and_execute_it(): void return $response; }); - $result = $middlewareHandlers->executeOnRequest(new PendingRequest); + // Create a mock response + $responseMock = $this->createMock(Response::class); + $responseMock->method('successful')->willReturn(true); + + $result = $middlewareHandlers->executeOnResponse($responseMock); + + $this->assertTrue($result->successful()); + } + + /** + * @test + */ + public function it_can_merge_middleware_handlers(): void + { + $middlewareHandlers1 = new MiddlewareHandlers; + $middlewareHandlers2 = new MiddlewareHandlers; + + $middlewareHandlers1->onRequest(function (PendingRequest $pendingRequest) { + $pendingRequest->headers()->add('Request-One', 'One'); + + return $pendingRequest; + }); + + $middlewareHandlers2->onRequest(function (PendingRequest $pendingRequest) { + $pendingRequest->headers()->add('Request-Two', 'Two'); + + return $pendingRequest; + }); + + $middlewareHandlers1->merge($middlewareHandlers2); + + $result = $middlewareHandlers1->executeOnRequest( + new PendingRequest(new MockClient, new DynamicGetRequest('')) + ); + + $this->assertEquals('One', $result->headers()->get('Request-One')); + $this->assertEquals('Two', $result->headers()->get('Request-Two')); } } diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index e53932e55..225b3b72f 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -8,6 +8,7 @@ use Mollie\Api\Http\Response; use Mollie\Api\Traits\HasDefaultFactories; use Tests\Fixtures\MockResponse; +use Tests\Fixtures\SequenceMockResponse; class MockMollieHttpAdapter implements HttpAdapterContract { @@ -34,6 +35,10 @@ public function sendRequest(PendingRequest $pendingRequest): Response $mockedResponse = $this->expectedResponses[$pendingRequest->getRequest()::class]; + if ($mockedResponse instanceof SequenceMockResponse) { + $mockedResponse = $mockedResponse->pop(); + } + return new Response( $mockedResponse->createPsrResponse(), $pendingRequest->createPsrRequest(), diff --git a/tests/Http/Middleware/GuardResponseTest.php b/tests/Http/Middleware/GuardResponseTest.php new file mode 100644 index 000000000..51e7d4fc0 --- /dev/null +++ b/tests/Http/Middleware/GuardResponseTest.php @@ -0,0 +1,106 @@ +createMock(Response::class); + + // Mock the status method to return a status other than HTTP_NO_CONTENT + $responseMock->expects($this->once()) + ->method('status') + ->willReturn(ResponseStatusCode::HTTP_OK); + + // Mock the body method to return an empty body + $responseMock->expects($this->once()) + ->method('isEmpty') + ->willReturn(true); + + $guardResponse = new GuardResponse; + + // Expect the ApiException to be thrown due to no response body + $this->expectException(ApiException::class); + $this->expectExceptionMessage('No response body found.'); + + $guardResponse($responseMock); + } + + /** + * @test + */ + public function it_does_not_throw_exception_if_http_no_content(): void + { + $responseMock = $this->createMock(Response::class); + + // Mock the status method to return HTTP_NO_CONTENT + $responseMock->expects($this->once()) + ->method('status') + ->willReturn(ResponseStatusCode::HTTP_NO_CONTENT); + + // Mock the body method to return an empty body + $responseMock->expects($this->once()) + ->method('isEmpty') + ->willReturn(true); + + $guardResponse = new GuardResponse; + + // No exception should be thrown + $guardResponse($responseMock); + + // If the test reaches here without exceptions, it passes + $this->assertTrue(true); + } + + /** + * @test + */ + public function it_throws_exception_if_response_contains_error_message(): void + { + $responseMock = $this->createMock(Response::class); + + // Mock the json method to return an error object + $responseMock->expects($this->once()) + ->method('json') + ->willReturn((object) ['error' => (object) ['message' => 'Some error occurred']]); + + $guardResponse = new GuardResponse; + + // Expect the ApiException to be thrown due to error in the response + $this->expectException(ApiException::class); + $this->expectExceptionMessage('Some error occurred'); + + $guardResponse($responseMock); + } + + /** + * @test + */ + public function it_passes_if_valid_json_and_no_error_message(): void + { + $responseMock = $this->createMock(Response::class); + + // Mock the json method to return valid data + $responseMock->expects($this->once()) + ->method('json') + ->willReturn((object) ['data' => 'valid']); + + $guardResponse = new GuardResponse; + + // No exception should be thrown + $guardResponse($responseMock); + + // If the test reaches here without exceptions, it passes + $this->assertTrue(true); + } +} diff --git a/tests/Mollie/API/Resources/CursorCollectionTest.php b/tests/Mollie/API/Resources/CursorCollectionTest.php deleted file mode 100644 index 0d7385c8f..000000000 --- a/tests/Mollie/API/Resources/CursorCollectionTest.php +++ /dev/null @@ -1,233 +0,0 @@ -createMock(MollieApiClient::class); - $mockedClient->expects($this->once()) - ->method('send') - ->willReturn($this->arrayToResponse([ - 'count' => 1, - '_links' => [ - 'self' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ], - '_embedded' => [ - 'orders' => [ - ['id' => 'ord_stTC2WHAuS'], - ], - ], - ])); - - $collection = new OrderCollection( - $mockedClient, - [], - $this->arrayToObject([ - 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ]) - ); - - $this->assertTrue($collection->hasNext()); - - $nextPage = $collection->next(); - - $this->assertEquals('ord_stTC2WHAuS', $nextPage[0]->id); - - $this->assertFalse($nextPage->hasNext()); - } - - public function testWillReturnNullIfNoNextResultIsAvailable() - { - $mockedClient = $this->createMock(MollieApiClient::class); - $collection = new OrderCollection( - $mockedClient, - [], - (object) [] - ); - - $this->assertFalse($collection->hasNext()); - $this->assertNull($collection->next()); - } - - public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() - { - $mockedClient = $this->createMock(MollieApiClient::class); - $mockedClient->expects($this->once()) - ->method('performHttpCallToFullUrl') - ->willReturn( - $this->arrayToResponse([ - 'count' => 1, - '_links' => [ - 'self' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ], - '_embedded' => [ - 'orders' => [ - ['id' => 'ord_stTC2WHAuS'], - ], - ], - ]) - ); - - $collection = new OrderCollection( - $mockedClient, - [], - $this->arrayToObject([ - 'previous' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ]) - ); - - $this->assertTrue($collection->hasPrevious()); - - $previousPage = $collection->previous(); - - $this->assertEquals('ord_stTC2WHAuS', $previousPage[0]->id); - - $this->assertFalse($previousPage->hasPrevious()); - } - - public function testWillReturnNullIfNoPreviousResultIsAvailable() - { - $mockedClient = $this->createMock(MollieApiClient::class); - $collection = new OrderCollection( - $mockedClient, - [], - (object) [] - ); - - $this->assertFalse($collection->hasPrevious()); - $this->assertNull($collection->previous()); - } - - public function testAutoPaginatorReturnsLazyCollection() - { - $collection = new OrderCollection( - $this->createMock(MollieApiClient::class), - [], - (object) [] - ); - - $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); - } - - public function testAutoPaginatorCanHandleConsecutiveCalls() - { - $mockedClient = $this->createMock(MollieApiClient::class); - $mockedClient->expects($this->exactly(3)) - ->method('performHttpCallToFullUrl') - ->willReturnOnConsecutiveCalls( - $this->arrayToResponse([ - 'count' => 1, - '_links' => [ - 'self' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ], - '_embedded' => [ - 'orders' => [ - ['id' => 'ord_stTC2WHAuS'], - ], - ], - ]), - $this->arrayToResponse([ - 'count' => 1, - '_links' => [ - 'self' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuF', - ], - 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuF', - ], - ], - '_embedded' => [ - 'orders' => [ - ['id' => 'ord_stTC2WHAuF'], - ], - ], - ]), - $this->arrayToResponse([ - 'count' => 1, - '_links' => [ - 'self' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuB', - ], - ], - '_embedded' => [ - 'orders' => [ - ['id' => 'ord_stTC2WHAuB'], - ], - ], - ]) - ); - - $collection = new OrderCollection( - $mockedClient, - [], - $this->arrayToObject([ - 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - ], - ]) - ); - - $orderIds = []; - foreach ($collection->getAutoIterator() as $order) { - $orderIds[] = $order->id; - } - - $this->assertEquals(['ord_stTC2WHAuS', 'ord_stTC2WHAuF', 'ord_stTC2WHAuB'], $orderIds); - } - - /** - * Convert an array to an object recursively. - * - * @param mixed $data - * @return mixed - */ - private function arrayToObject($data) - { - if (! is_array($data)) { - return $data; - } - - $obj = new stdClass; - - foreach ($data as $key => $value) { - $obj->$key = $this->arrayToObject($value); - } - - return $obj; - } - - private function objectToResponse(object $obj): Response - { - return new Response(200, json_encode($obj)); - } - - private function arrayToResponse($data): Response - { - $obj = $this->arrayToObject($data); - - return $this->objectToResponse($obj); - } -} diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index 601b13a7a..6217893d7 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -3,22 +3,24 @@ namespace Tests; use GuzzleHttp\Client; -use GuzzleHttp\Psr7\Response; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; -use Mollie\Api\Http\Payload\CreatePayment; +use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; +use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; +use Mollie\Api\Http\Requests\DynamicDeleteRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response as HttpResponse; use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\Mollie\TestHelpers\FakeHttpAdapter; class MollieApiClientTest extends TestCase { @@ -132,7 +134,7 @@ public function testCorrectRequestHeaders() $client->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $response = $client->send(new CreatePaymentRequest(new CreatePayment( + $response = $client->send(new CreatePaymentRequest(new CreatePaymentPayload( 'test', new Money('EUR', '100.00'), ))); @@ -167,96 +169,110 @@ public function testNoContentTypeWithoutProvidedBody() /** @var HttpResponse $response */ $response = $client->send(new DynamicGetRequest('')); - $this->assertEquals(false, $response->getPendingRequest()->headers()->get('Content-Type')); + $this->assertFalse($response->getPendingRequest()->headers()->has('Content-Type')); } - public function testIfNoIdempotencyKeyIsSetNoReferenceIsIncludedInTheRequestHeaders() + /** @test */ + public function no_idempotency_is_set_on_if_no_key_nor_generator_are_set() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client = new MockClient([ + DynamicDeleteRequest::class => new MockResponse(204, ''), + ]); + + $client->clearIdempotencyKeyGenerator(); + + /** @var HttpResponse $response */ + $response = $client->send(new DynamicDeleteRequest('')); + + $this->assertFalse($response->getPendingRequest()->headers()->has(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); + } - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); + /** + * @dataProvider providesMutatingRequests + * + * @test + */ + public function idempotency_key_is_used_on_mutating_requests($request, $response) + { + $client = new MockClient([ + $request::class => $response, + ]); - // ... Not setting an idempotency key here + $client->setIdempotencyKey('idempotentFooBar'); - $mollieClient->performHttpCallToFullUrl('GET', ''); + $response = $client->send($request); - $this->assertFalse(isset($fakeAdapter->getUsedHeaders()['Idempotency-Key'])); + $this->assertTrue($response->getPendingRequest()->headers()->has(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); + $this->assertEquals('idempotentFooBar', $response->getPendingRequest()->headers()->get(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); } - public function testIdempotencyKeyIsUsedOnMutatingRequests() + public static function providesMutatingRequests(): array { - $this->assertIdempotencyKeyIsUsedForMethod('POST'); - $this->assertIdempotencyKeyIsUsedForMethod('PATCH'); - $this->assertIdempotencyKeyIsUsedForMethod('DELETE'); + return [ + 'delete' => [ + new DynamicDeleteRequest(''), + new MockResponse(204, ''), + ], + 'post' => [ + new CreatePaymentRequest(new CreatePaymentPayload( + 'test', + new Money('EUR', '100.00'), + )), + new MockResponse(200, 'payment'), + ], + 'patch' => [ + new UpdatePaymentRequest('tr_payment-id', new UpdatePaymentPayload( + 'test', + )), + new MockResponse(200, 'payment'), + ], + ]; } public function testIdempotencyKeyIsNotUsedOnGetRequests() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(204), + ]); - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $mollieClient->setIdempotencyKey('idempotentFooBar'); + $client->setIdempotencyKey('idempotentFooBar'); - $mollieClient->performHttpCallToFullUrl('GET', ''); + $response = $client->send(new DynamicGetRequest('')); - $this->assertFalse(isset($fakeAdapter->getUsedHeaders()['Idempotency-Key'])); + $this->assertFalse($response->getPendingRequest()->headers()->has(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); } public function testIdempotencyKeyResetsAfterEachRequest() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client = new MockClient([ + DynamicDeleteRequest::class => new MockResponse(204), + ]); - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $mollieClient->setIdempotencyKey('idempotentFooBar'); - $this->assertEquals('idempotentFooBar', $mollieClient->getIdempotencyKey()); + $client->setIdempotencyKey('idempotentFooBar'); - $mollieClient->performHttpCallToFullUrl('POST', ''); + $this->assertEquals('idempotentFooBar', $client->getIdempotencyKey()); - $this->assertNull($mollieClient->getIdempotencyKey()); + $client->send(new DynamicDeleteRequest('')); + + $this->assertNull($client->getIdempotencyKey()); } public function testItUsesTheIdempotencyKeyGenerator() { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client = new MockClient([ + DynamicDeleteRequest::class => new MockResponse(204), + ]); + $fakeIdempotencyKeyGenerator = new FakeIdempotencyKeyGenerator; $fakeIdempotencyKeyGenerator->setFakeKey('fake-idempotency-key'); - $mollieClient = new MollieApiClient($fakeAdapter, null, $fakeIdempotencyKeyGenerator); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $this->assertNull($mollieClient->getIdempotencyKey()); - - $mollieClient->performHttpCallToFullUrl('POST', ''); - - $this->assertEquals('fake-idempotency-key', $fakeAdapter->getUsedHeaders()['Idempotency-Key']); - $this->assertNull($mollieClient->getIdempotencyKey()); - } - - /** - * @return void - * - * @throws \Mollie\Api\Exceptions\ApiException - * @throws \Mollie\Api\Exceptions\IncompatiblePlatform - * @throws \Mollie\Api\Exceptions\UnrecognizedClientException - */ - private function assertIdempotencyKeyIsUsedForMethod($httpMethod) - { - $response = new Response(200, [], '{"resource": "payment"}'); - $fakeAdapter = new FakeHttpAdapter($response); + $client->setIdempotencyKeyGenerator($fakeIdempotencyKeyGenerator); - $mollieClient = new MollieApiClient($fakeAdapter); - $mollieClient->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $mollieClient->setIdempotencyKey('idempotentFooBar'); + $this->assertNull($client->getIdempotencyKey()); - $mollieClient->performHttpCallToFullUrl($httpMethod, ''); + $response = $client->send(new DynamicDeleteRequest('')); - $this->assertTrue(isset($fakeAdapter->getUsedHeaders()['Idempotency-Key'])); - $this->assertEquals('idempotentFooBar', $fakeAdapter->getUsedHeaders()['Idempotency-Key']); + $this->assertEquals('fake-idempotency-key', $response->getPendingRequest()->headers()->get(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); + $this->assertNull($client->getIdempotencyKey()); } } diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php new file mode 100644 index 000000000..2aad2f64c --- /dev/null +++ b/tests/Resources/CursorCollectionTest.php @@ -0,0 +1,156 @@ + new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuS'), + ]); + + $collection = new OrderCollection( + $client, + [], + $this->arrayToObject([ + 'next' => [ + 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + ], + ]) + ); + + $this->assertTrue($collection->hasNext()); + + $nextPage = $collection->next(); + + $this->assertEquals('ord_stTC2WHAuS', $nextPage[0]->id); + + $this->assertFalse($nextPage->hasNext()); + } + + public function testWillReturnNullIfNoNextResultIsAvailable() + { + $client = new MockClient; + + $collection = new OrderCollection( + $client, + [], + (object) [] + ); + + $this->assertFalse($collection->hasNext()); + $this->assertNull($collection->next()); + } + + public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() + { + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuS'), + ]); + + $collection = new OrderCollection( + $client, + [], + $this->arrayToObject([ + 'previous' => [ + 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + ], + ]) + ); + + $this->assertTrue($collection->hasPrevious()); + + $previousPage = $collection->previous(); + + $this->assertEquals('ord_stTC2WHAuS', $previousPage[0]->id); + + $this->assertFalse($previousPage->hasPrevious()); + } + + public function testWillReturnNullIfNoPreviousResultIsAvailable() + { + $client = new MockClient; + + $collection = new OrderCollection( + $client, + [], + (object) [] + ); + + $this->assertFalse($collection->hasPrevious()); + $this->assertNull($collection->previous()); + } + + public function testAutoPaginatorReturnsLazyCollection() + { + $client = new MockClient; + + $collection = new OrderCollection( + $client, + [], + (object) [] + ); + + $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); + } + + public function testAutoPaginatorCanHandleConsecutiveCalls() + { + $client = new MockClient([ + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'cursor-collection-next', 'ord_stTC2WHAuF'), + new MockResponse(200, 'cursor-collection-next', 'ord_stTC2WHAuS'), + new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuB') + ), + ]); + + $collection = new OrderCollection( + $client, + [], + $this->arrayToObject([ + 'next' => [ + 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + ], + ]) + ); + + $orderIds = []; + foreach ($collection->getAutoIterator() as $order) { + $orderIds[] = $order->id; + } + + $this->assertEquals(['ord_stTC2WHAuF', 'ord_stTC2WHAuS', 'ord_stTC2WHAuB'], $orderIds); + } + + /** + * Convert an array to an object recursively. + * + * @param mixed $data + * @return mixed + */ + private function arrayToObject($data) + { + if (! is_array($data)) { + return $data; + } + + $obj = new stdClass; + + foreach ($data as $key => $value) { + $obj->$key = $this->arrayToObject($value); + } + + return $obj; + } +} diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 600a902b0..bb1e84eaf 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -8,8 +8,9 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; +use PHPUnit\Framework\TestCase; -class ResourceFactoryTest extends \PHPUnit\Framework\TestCase +class ResourceFactoryTest extends TestCase { public function testCreateFromApiResponseWorks() { From 0115efafdc00aad3cdd96d427a91af1231c68001 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:48:50 +0200 Subject: [PATCH 048/131] wip --- .../OrganizationEndpointCollection.php | 41 +++++++++++++ src/Endpoints/OrganizationEndpoint.php | 58 ------------------- src/Exceptions/ApiException.php | 8 +-- .../GetBalanceReportQueryFactory.php | 6 +- .../PaymentRouteCollectionFactory.php | 4 +- .../RecurringBillingCycleFactory.php | 4 +- src/Helpers/Handler.php | 10 +++- src/Helpers/Handlers.php | 22 ++++++- src/Helpers/MiddlewareHandlers.php | 42 ++++++++------ src/Http/Payload/PaymentRoute.php | 7 ++- src/Http/Payload/RecurringBillingCycle.php | 6 +- src/Http/PendingRequest.php | 10 ++-- src/Http/Query/GetBalanceReportQuery.php | 10 ++-- src/Http/Request.php | 2 + src/Http/Requests/GetOrganizationRequest.php | 18 ++++++ src/MollieApiClient.php | 4 +- src/Resources/Organization.php | 5 ++ src/Traits/HasEndpoints.php | 4 +- 18 files changed, 151 insertions(+), 110 deletions(-) create mode 100644 src/EndpointCollection/OrganizationEndpointCollection.php delete mode 100644 src/Endpoints/OrganizationEndpoint.php create mode 100644 src/Http/Requests/GetOrganizationRequest.php diff --git a/src/EndpointCollection/OrganizationEndpointCollection.php b/src/EndpointCollection/OrganizationEndpointCollection.php new file mode 100644 index 000000000..d7e1988a7 --- /dev/null +++ b/src/EndpointCollection/OrganizationEndpointCollection.php @@ -0,0 +1,41 @@ +send(new GetOrganizationRequest($id, $testmode)); + } + + /** + * Retrieve the current organization from Mollie. + * + * @param array|bool $testmode + * + * @throws ApiException + */ + public function current($testmode = []): Organization + { + /** @var Organization */ + return $this->get('me', $testmode); + } +} diff --git a/src/Endpoints/OrganizationEndpoint.php b/src/Endpoints/OrganizationEndpoint.php deleted file mode 100644 index ea826c88c..000000000 --- a/src/Endpoints/OrganizationEndpoint.php +++ /dev/null @@ -1,58 +0,0 @@ -readResource($organizationId, $parameters); - } - - /** - * Retrieve the current organization from Mollie. - * - * @param array $parameters - * - * @return Organization - * @throws ApiException - */ - public function current(array $parameters = []): Organization - { - /** @var Organization */ - return $this->readResource('me', $parameters); - } -} diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index b4e8b0ecb..6b4bbdb49 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Exceptions; -use DateTime; +use DateTimeImmutable; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Throwable; @@ -37,9 +37,9 @@ public function __construct( ) { $this->plainMessage = $message; - $this->raisedAt = new \DateTimeImmutable; + $this->raisedAt = new DateTimeImmutable; - $formattedRaisedAt = $this->raisedAt->format(DateTime::ATOM); + $formattedRaisedAt = $this->raisedAt->format(DateTimeImmutable::ATOM); $message = "[{$formattedRaisedAt}] ".$message; if (! empty($field)) { @@ -140,7 +140,7 @@ public function getRequest(): ?RequestInterface /** * Get the ISO8601 representation of the moment this exception was thrown */ - public function getRaisedAt(): \DateTimeImmutable + public function getRaisedAt(): DateTimeImmutable { return $this->raisedAt; } diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php index a5c1c0a42..387114e14 100644 --- a/src/Factories/GetBalanceReportQueryFactory.php +++ b/src/Factories/GetBalanceReportQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use DateTime; +use DateTimeImmutable; use Mollie\Api\Http\Query\GetBalanceReportQuery; class GetBalanceReportQueryFactory extends Factory @@ -14,8 +14,8 @@ public function create(): GetBalanceReportQuery } return new GetBalanceReportQuery( - DateTime::createFromFormat('Y-m-d', $this->get('from')), - DateTime::createFromFormat('Y-m-d', $this->get('until')), + DateTimeImmutable::createFromFormat('Y-m-d', $this->get('from')), + DateTimeImmutable::createFromFormat('Y-m-d', $this->get('until')), $this->get('grouping'), $this->get('testmode') ); diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index 10bcb665f..678714c80 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use DateTime; +use DateTimeImmutable; use Mollie\Api\Helpers; use Mollie\Api\Helpers\Arr; use Mollie\Api\Http\Payload\DataCollection; @@ -22,7 +22,7 @@ public function create(): DataCollection Arr::get($item, 'destination.organizationId'), Helpers::compose( Arr::get($item, 'delayUntil'), - fn ($value) => DateTime::createFromFormat('Y-m-d', $value) + fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) ) ); }, $this->data); diff --git a/src/Factories/RecurringBillingCycleFactory.php b/src/Factories/RecurringBillingCycleFactory.php index 88cb22bb8..0c0c9c208 100644 --- a/src/Factories/RecurringBillingCycleFactory.php +++ b/src/Factories/RecurringBillingCycleFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use DateTime; +use DateTimeImmutable; use Mollie\Api\Http\Payload\RecurringBillingCycle; class RecurringBillingCycleFactory extends Factory @@ -14,7 +14,7 @@ public function create(): RecurringBillingCycle $this->get('descriptipn'), $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), $this->get('times'), - $this->mapIfNotNull('startDate', fn (string $item) => DateTime::createFromFormat('Y-m-d', $item)), + $this->mapIfNotNull('startDate', fn (string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), ); } } diff --git a/src/Helpers/Handler.php b/src/Helpers/Handler.php index 22ac935b9..b5944a64d 100644 --- a/src/Helpers/Handler.php +++ b/src/Helpers/Handler.php @@ -8,11 +8,14 @@ class Handler { private Closure $callback; + private ?string $name; + private string $priority; - public function __construct(Closure $callback, string $priority) + public function __construct(Closure $callback, ?string $name, string $priority) { $this->callback = $callback; + $this->name = $name; $this->priority = $priority; } @@ -21,6 +24,11 @@ public function callback(): callable return $this->callback; } + public function name(): ?string + { + return $this->name; + } + public function priority(): string { return $this->priority; diff --git a/src/Helpers/Handlers.php b/src/Helpers/Handlers.php index 3b40bf7ef..c6b4cf5c4 100644 --- a/src/Helpers/Handlers.php +++ b/src/Helpers/Handlers.php @@ -13,9 +13,18 @@ class Handlers */ protected array $handlers = []; - public function add(callable $handler, string $priority): void + public function add(callable $handler, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): void { - $this->handlers[] = new Handler($handler, $priority); + if (in_array($name, [MiddlewarePriority::HIGH, MiddlewarePriority::MEDIUM, MiddlewarePriority::LOW])) { + $priority = $name; + $name = null; + } + + if (is_string($name) && $this->handlerExists($name)) { + throw new \InvalidArgumentException("Handler with name '{$name}' already exists."); + } + + $this->handlers[] = new Handler($handler, $name, $priority); } public function setHandlers(array $handlers): void @@ -70,4 +79,13 @@ protected function sortHandlers(): array return array_merge($highPriority, $mediumPriority, $lowPriority); } + + private function handlerExists(string $name): bool + { + foreach ($this->handlers as $handler) { + if ($handler->name() === $name) { + return true; + } + } + } } diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Helpers/MiddlewareHandlers.php index 23bf595b3..7a7ad5b95 100644 --- a/src/Helpers/MiddlewareHandlers.php +++ b/src/Helpers/MiddlewareHandlers.php @@ -18,7 +18,7 @@ public function __construct() $this->onResponse = new Handlers; } - public function onRequest(callable $callback, string $priority = MiddlewarePriority::MEDIUM): static + public function onRequest(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): static { $this->onRequest->add(static function (PendingRequest $pendingRequest) use ($callback): PendingRequest { $result = $callback($pendingRequest); @@ -28,12 +28,12 @@ public function onRequest(callable $callback, string $priority = MiddlewarePrior } return $pendingRequest; - }, $priority); + }, $name, $priority); return $this; } - public function onResponse(callable $callback, string $priority = MiddlewarePriority::MEDIUM): static + public function onResponse(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): static { $this->onResponse->add(static function (Response $response) use ($callback) { $result = $callback($response); @@ -42,7 +42,7 @@ public function onResponse(callable $callback, string $priority = MiddlewarePrio || $result instanceof ViableResponse ? $result : $response; - }, $priority); + }, $name, $priority); return $this; } @@ -60,21 +60,27 @@ public function executeOnResponse(Response $response) return $this->onResponse->execute($response); } - public function merge(MiddlewareHandlers $handlers): static + /** + * @param array ...$handlers + */ + public function merge(...$handlersCollection): static { - $onRequestHandlers = array_merge( - $this->onRequest->getHandlers(), - $handlers->onRequest->getHandlers(), - ); - - $this->onRequest->setHandlers($onRequestHandlers); - - $onResponseHandlers = array_merge( - $this->onResponse->getHandlers(), - $handlers->onResponse->getHandlers(), - ); - - $this->onResponse->setHandlers($onResponseHandlers); + /** @var MiddlewareHandlers $handlers */ + foreach ($handlersCollection as $handlers) { + $onRequestHandlers = array_merge( + $this->onRequest->getHandlers(), + $handlers->onRequest->getHandlers() + ); + + $this->onRequest->setHandlers($onRequestHandlers); + + $onResponseHandlers = array_merge( + $this->onResponse->getHandlers(), + $handlers->onResponse->getHandlers() + ); + + $this->onResponse->setHandlers($onResponseHandlers); + } return $this; } diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index c8ce012c5..0bad63dac 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -2,15 +2,16 @@ namespace Mollie\Api\Http\Payload; -use DateTime; +use DateTimeInterface; class PaymentRoute extends DataBag { public function __construct( public readonly Money $amount, public readonly string $organizationId, - public readonly ?DateTime $delayUntil = null, - ) {} + public readonly ?DateTimeInterface $delayUntil = null, + ) { + } public function data(): array { diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php index 1aa35947e..bf19ea4b4 100644 --- a/src/Http/Payload/RecurringBillingCycle.php +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Payload; -use DateTime; +use DateTimeInterface; use Mollie\Api\Rules\Matches; class RecurringBillingCycle extends DataBag @@ -20,14 +20,14 @@ class RecurringBillingCycle extends DataBag public ?int $times; - public ?DateTime $startDate; + public ?DateTimeInterface $startDate; public function __construct( string $interval, ?string $description = null, ?Money $amount = null, ?int $times = null, - ?DateTime $startDate = null, + ?DateTimeInterface $startDate = null, ) { $this->interval = $interval; $this->description = $description; diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index a177132e0..c41c8f3d7 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -51,7 +51,7 @@ public function __construct(Connector $connector, Request $request) $this->method = $request->getMethod(); $this->url = Url::join($connector->resolveBaseUrl(), $request->resolveResourcePath()); - $this->middleware()->merge($connector->middleware()); + $this->middleware()->merge($request->middleware(), $connector->middleware()); $this ->tap(new MergeRequestProperties) @@ -62,12 +62,12 @@ public function __construct(Connector $connector, Request $request) $this ->middleware() - ->onRequest(new EvaluateHydrationSetting) - ->onRequest(new ApplyIdempotencyKey) - ->onResponse(new ResetIdempotencyKey) + ->onRequest(new EvaluateHydrationSetting, 'hydration') + ->onRequest(new ApplyIdempotencyKey, 'idempotency') + ->onResponse(new ResetIdempotencyKey, 'idempotency') ->onResponse(new GuardResponse, MiddlewarePriority::HIGH) ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH) - ->onResponse(new Hydrate, MiddlewarePriority::LOW); + ->onResponse(new Hydrate, 'hydration', MiddlewarePriority::LOW); } diff --git a/src/Http/Query/GetBalanceReportQuery.php b/src/Http/Query/GetBalanceReportQuery.php index 9ac9cb07e..36f58928f 100644 --- a/src/Http/Query/GetBalanceReportQuery.php +++ b/src/Http/Query/GetBalanceReportQuery.php @@ -2,21 +2,21 @@ namespace Mollie\Api\Http\Query; -use DateTime; +use DateTimeInterface; class GetBalanceReportQuery extends Query { - public DateTime $from; + public DateTimeInterface $from; - public DateTime $until; + public DateTimeInterface $until; public ?string $grouping; public ?bool $testmode; public function __construct( - DateTime $from, - DateTime $until, + DateTimeInterface $from, + DateTimeInterface $until, ?string $grouping = null, ?bool $testmode = null ) { diff --git a/src/Http/Request.php b/src/Http/Request.php index 408646613..0ed2015a7 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -4,11 +4,13 @@ use LogicException; use Mollie\Api\Contracts\ValidatableDataProvider; +use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\HasRules; abstract class Request implements ValidatableDataProvider { + use HasMiddleware; use HasRequestProperties; use HasRules; diff --git a/src/Http/Requests/GetOrganizationRequest.php b/src/Http/Requests/GetOrganizationRequest.php new file mode 100644 index 000000000..b47c5a2bc --- /dev/null +++ b/src/Http/Requests/GetOrganizationRequest.php @@ -0,0 +1,18 @@ + OrderRefundEndpoint::class, 'orders' => OrderEndpointCollection::class, 'organizationPartners' => OrganizationPartnerEndpoint::class, - 'organizations' => OrganizationEndpoint::class, + 'organizations' => OrganizationEndpointCollection::class, 'payments' => PaymentEndpointCollection::class, 'paymentRefunds' => PaymentRefundEndpointCollection::class, 'paymentCaptures' => PaymentCaptureEndpoint::class, From 4cdbb756c8a2842ce0993d9b302447723c989a58 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:51:46 +0200 Subject: [PATCH 049/131] make v3 php7.4 compatible --- src/Factories/Factory.php | 2 +- src/Helpers.php | 9 ++++++--- src/Rules/Matches.php | 8 ++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index b666f4d2d..cc7f8d2f1 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -15,7 +15,7 @@ public function __construct(array $data) $this->data = $data; } - public static function new(array $data): static + public static function new(array $data): self { return new static($data); } diff --git a/src/Helpers.php b/src/Helpers.php index 624bbdc7c..e2524a190 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -14,7 +14,7 @@ class Helpers * @param object|class-string $class * @return array */ - public static function classUsesRecursive(object|string $class): array + public static function classUsesRecursive($class): array { if (is_object($class)) { $class = get_class($class); @@ -50,10 +50,11 @@ public static function traitUsesRecursive(string $trait): array /** * Get the properties of a class. * + * @param string|class-string $class * @param int $flag * @return ReflectionProperty[] */ - public static function getProperties(string|object $class, $flag = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE): array + public static function getProperties($class, $flag = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE): array { $reflection = new ReflectionClass($class); @@ -62,8 +63,10 @@ public static function getProperties(string|object $class, $flag = ReflectionPro /** * Filter out the properties that are not part of the given class. + * + * @param string|class-string $class */ - public static function filterByProperties(string|object $class, array $array): array + public static function filterByProperties($class, array $array): array { $properties = array_map( fn (ReflectionProperty $prop) => $prop->getName(), diff --git a/src/Rules/Matches.php b/src/Rules/Matches.php index b12f37b39..be318cd27 100644 --- a/src/Rules/Matches.php +++ b/src/Rules/Matches.php @@ -7,9 +7,13 @@ class Matches implements Rule { + private string $pattern; + public function __construct( - private string $pattern - ) {} + string $pattern + ) { + $this->pattern = $pattern; + } public static function pattern(string $pattern): self { From 4fad5bcd97d1ea71164c20f76d60a6930296f2a2 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:52:22 +0200 Subject: [PATCH 050/131] wip --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 75f12b7e1..4182465a7 100644 --- a/composer.json +++ b/composer.json @@ -54,8 +54,7 @@ "composer/ca-bundle": "^1.4", "nyholm/psr7": "^1.8", "psr/http-factory": "^1.1", - "psr/http-message": "^2.0", - "saloonphp/saloon": "^3.10" + "psr/http-message": "^2.0" }, "require-dev": { "brianium/paratest": "^6.11", From ec1b4ef377fd604300732fff9aecc3ba117a44a7 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:53:33 +0200 Subject: [PATCH 051/131] wip --- src/Resources/BaseResource.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 8a9c01cb8..6108cebc4 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -36,6 +36,8 @@ public function getResponse(): ?Response public function getPendingRequest(): ?PendingRequest { - return $this->response?->getPendingRequest(); + return $this->response + ? $this->response->getPendingRequest() + : null; } } From 44ddaa08d1606d333be0d80842ec66215206d8e8 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:54:34 +0200 Subject: [PATCH 052/131] wip --- src/Resources/ResourceFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 5b75a354b..b487ce198 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -104,7 +104,7 @@ public static function createBaseResourceCollection( $data = null, ?object $_links = null, ?string $resourceCollectionClass = null, - ?Response $response = null, + ?Response $response = null ): BaseCollection { return self::instantiateBaseCollection( $connector, From be99500cbbe4cb8bdd7fb04e599704f958cf6d30 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:56:02 +0200 Subject: [PATCH 053/131] wip --- src/Contracts/ArrayRepository.php | 8 ++++---- src/Contracts/BodyRepository.php | 4 ++-- src/Contracts/Factory.php | 2 +- src/Helpers/MiddlewareHandlers.php | 6 +++--- src/Http/Payload/DataCollection.php | 6 +++--- src/Http/PendingRequest.php | 4 ++-- src/Repositories/ArrayStore.php | 8 ++++---- src/Repositories/JsonBodyRepository.php | 4 ++-- src/Traits/ComposableFromArray.php | 2 +- src/Traits/HandlesAutoHydration.php | 2 +- src/Traits/HandlesTestmode.php | 4 ++-- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Contracts/ArrayRepository.php b/src/Contracts/ArrayRepository.php index c6caac677..f330c4661 100644 --- a/src/Contracts/ArrayRepository.php +++ b/src/Contracts/ArrayRepository.php @@ -4,7 +4,7 @@ interface ArrayRepository { - public function set(array $data): static; + public function set(array $data): self; /** * @param mixed $default @@ -14,11 +14,11 @@ public function get(string $key, $default = null); public function has(string $key): bool; - public function add(string $key, $value): static; + public function add(string $key, $value): self; - public function merge(array ...$data): static; + public function merge(array ...$data): self; - public function remove(string $key): static; + public function remove(string $key): self; public function all(): array; diff --git a/src/Contracts/BodyRepository.php b/src/Contracts/BodyRepository.php index df0dd4e5b..af8519b3c 100644 --- a/src/Contracts/BodyRepository.php +++ b/src/Contracts/BodyRepository.php @@ -10,14 +10,14 @@ interface BodyRepository /** * @param mixed $value */ - public function set($value): static; + public function set($value): self; /** * @return mixed */ public function all(); - public function remove(string $key): static; + public function remove(string $key): self; public function isEmpty(): bool; diff --git a/src/Contracts/Factory.php b/src/Contracts/Factory.php index fb532999c..c47d9e48e 100644 --- a/src/Contracts/Factory.php +++ b/src/Contracts/Factory.php @@ -4,7 +4,7 @@ interface Factory { - public static function new(array $data): static; + public static function new(array $data): self; /** * @return mixed diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Helpers/MiddlewareHandlers.php index 7a7ad5b95..e9e894fc5 100644 --- a/src/Helpers/MiddlewareHandlers.php +++ b/src/Helpers/MiddlewareHandlers.php @@ -18,7 +18,7 @@ public function __construct() $this->onResponse = new Handlers; } - public function onRequest(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): static + public function onRequest(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): self { $this->onRequest->add(static function (PendingRequest $pendingRequest) use ($callback): PendingRequest { $result = $callback($pendingRequest); @@ -33,7 +33,7 @@ public function onRequest(callable $callback, ?string $name = null, string $prio return $this; } - public function onResponse(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): static + public function onResponse(callable $callback, ?string $name = null, string $priority = MiddlewarePriority::MEDIUM): self { $this->onResponse->add(static function (Response $response) use ($callback) { $result = $callback($response); @@ -63,7 +63,7 @@ public function executeOnResponse(Response $response) /** * @param array ...$handlers */ - public function merge(...$handlersCollection): static + public function merge(...$handlersCollection): self { /** @var MiddlewareHandlers $handlers */ foreach ($handlersCollection as $handlers) { diff --git a/src/Http/Payload/DataCollection.php b/src/Http/Payload/DataCollection.php index cce2c4be8..186bb6e10 100644 --- a/src/Http/Payload/DataCollection.php +++ b/src/Http/Payload/DataCollection.php @@ -27,7 +27,7 @@ public function __construct(array $items) $this->items = $items; } - public static function wrap(object $subject): static + public static function wrap(object $subject): self { if ($subject instanceof static) { return $subject; @@ -54,12 +54,12 @@ public function toArray(): array return $this->items; } - public function map(callable $callback): static + public function map(callable $callback): self { return new static(array_map($callback, $this->items)); } - public function filter(): static + public function filter(): self { return new static(array_filter($this->items)); } diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index c41c8f3d7..3dc8d25ba 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -71,7 +71,7 @@ public function __construct(Connector $connector, Request $request) } - public function setPayload(BodyRepository $bodyRepository): static + public function setPayload(BodyRepository $bodyRepository): self { $this->body = $bodyRepository; @@ -116,7 +116,7 @@ public function executeResponseHandlers(Response $response) return $this->middleware()->executeOnResponse($response); } - protected function tap(callable $callable): static + protected function tap(callable $callable): self { $callable($this); diff --git a/src/Repositories/ArrayStore.php b/src/Repositories/ArrayStore.php index bca6975ae..aefc684d2 100644 --- a/src/Repositories/ArrayStore.php +++ b/src/Repositories/ArrayStore.php @@ -14,7 +14,7 @@ public function __construct(array $data) $this->store = $data; } - public function set(array $data): static + public function set(array $data): self { $this->store = $data; @@ -30,7 +30,7 @@ public function get(string $key, $default = null) return $this->store[$key] ?? $default; } - public function add(string $key, $value): static + public function add(string $key, $value): self { $this->store[$key] = $value; @@ -42,14 +42,14 @@ public function has(string $key): bool return Arr::has($this->store, $key); } - public function merge(array ...$data): static + public function merge(array ...$data): self { $this->store = array_merge($this->store, ...$data); return $this; } - public function remove(string $key): static + public function remove(string $key): self { unset($this->store[$key]); diff --git a/src/Repositories/JsonBodyRepository.php b/src/Repositories/JsonBodyRepository.php index bcd03c0b6..686da8058 100644 --- a/src/Repositories/JsonBodyRepository.php +++ b/src/Repositories/JsonBodyRepository.php @@ -18,7 +18,7 @@ public function __construct(array $data = []) /** * @param mixed $value */ - public function set($value): static + public function set($value): self { $this->store = $value; @@ -30,7 +30,7 @@ public function all(): array return $this->store; } - public function remove(string $key): static + public function remove(string $key): self { unset($this->store[$key]); diff --git a/src/Traits/ComposableFromArray.php b/src/Traits/ComposableFromArray.php index 1d379aa87..72954e3fd 100644 --- a/src/Traits/ComposableFromArray.php +++ b/src/Traits/ComposableFromArray.php @@ -4,7 +4,7 @@ trait ComposableFromArray { - public static function fromArray(array $data): static + public static function fromArray(array $data): self { return new static(...$data); } diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php index 861b3d1f5..b86ad52c8 100644 --- a/src/Traits/HandlesAutoHydration.php +++ b/src/Traits/HandlesAutoHydration.php @@ -27,7 +27,7 @@ public function evaluateHydrationSetting(): void { (is_callable(static::$hydrationSettingResolver) ? static::$hydrationSettingResolver - : static function () { + : self function () { return (bool) static::$hydrationSettingResolver; })(); } diff --git a/src/Traits/HandlesTestmode.php b/src/Traits/HandlesTestmode.php index 40127f6a1..315905ff5 100644 --- a/src/Traits/HandlesTestmode.php +++ b/src/Traits/HandlesTestmode.php @@ -6,14 +6,14 @@ trait HandlesTestmode { protected bool $testmode = false; - public function enableTestmode(): static + public function enableTestmode(): self { $this->testmode = true; return $this; } - public function disableTestmode(): static + public function disableTestmode(): self { $this->testmode = false; From bd15bf4d0959a36261a172b792fc0bf6c5e81044 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:57:47 +0200 Subject: [PATCH 054/131] wip --- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 8 ++++---- src/Http/Adapter/PSR18MollieHttpAdapter.php | 8 ++++---- src/Traits/HasDefaultFactories.php | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 6f9b2dc3e..3c58bb6a5 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -53,10 +53,10 @@ public function factories(): Factories $factory = new HttpFactory; return new Factories( - requestFactory: $factory, - responseFactory: $factory, - streamFactory: $factory, - uriFactory: $factory, + $factory, + $factory, + $factory, + $factory, ); } diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index d5513ab35..377abf546 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -50,10 +50,10 @@ public function __construct( public function factories(): Factories { return new Factories( - requestFactory: $this->requestFactory, - responseFactory: $this->responseFactory, - streamFactory: $this->streamFactory, - uriFactory: $this->uriFactory, + $this->requestFactory, + $this->responseFactory, + $this->streamFactory, + $this->uriFactory, ); } diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php index a1dd65fa7..5dc03e213 100644 --- a/src/Traits/HasDefaultFactories.php +++ b/src/Traits/HasDefaultFactories.php @@ -18,10 +18,10 @@ public function factories(): Factories $httpFactory = new Psr17Factory; return static::$factories = new Factories( - requestFactory: $httpFactory, - responseFactory: $httpFactory, - streamFactory: $httpFactory, - uriFactory: $httpFactory, + $httpFactory, + $httpFactory, + $httpFactory, + $httpFactory, ); } } From ca4a799ed5556fa33b3b9d5b6ff7af25a9e10d19 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 09:59:23 +0200 Subject: [PATCH 055/131] wip --- src/Http/Auth/AccessTokenAuthenticator.php | 2 +- src/Http/Auth/ApiKeyAuthenticator.php | 2 +- src/Http/Auth/BearerTokenAuthenticator.php | 2 +- src/Http/Payload/ApplicationFee.php | 2 +- src/Http/Payload/CreatePaymentPayload.php | 2 +- src/Http/Payload/OrderLine.php | 2 +- src/Http/Payload/PaymentRoute.php | 5 ++--- src/Http/Payload/RecurringBillingCycle.php | 2 +- src/Http/Payload/RefundRoute.php | 2 +- src/Http/Payload/UpdatePaymentPayload.php | 2 +- src/Http/Requests/DynamicDeleteRequest.php | 2 +- src/Http/Requests/GetPaginatedPaymentRefundsRequest.php | 2 +- src/Http/Requests/GetPaymentRequest.php | 2 +- 13 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Http/Auth/AccessTokenAuthenticator.php b/src/Http/Auth/AccessTokenAuthenticator.php index 1b5f0c8e9..2efd1b9d2 100644 --- a/src/Http/Auth/AccessTokenAuthenticator.php +++ b/src/Http/Auth/AccessTokenAuthenticator.php @@ -7,7 +7,7 @@ class AccessTokenAuthenticator extends BearerTokenAuthenticator { public function __construct( - string $token, + string $token ) { if (! preg_match('/^access_\w+$/', trim($token))) { throw new ApiException("Invalid OAuth access token: '{$token}'. An access token must start with 'access_'."); diff --git a/src/Http/Auth/ApiKeyAuthenticator.php b/src/Http/Auth/ApiKeyAuthenticator.php index a017e0a1b..6baaed1b2 100644 --- a/src/Http/Auth/ApiKeyAuthenticator.php +++ b/src/Http/Auth/ApiKeyAuthenticator.php @@ -7,7 +7,7 @@ class ApiKeyAuthenticator extends BearerTokenAuthenticator { public function __construct( - string $token, + string $token ) { if (! preg_match('/^(live|test)_\w{30,}$/', trim($token))) { throw new ApiException("Invalid API key: '{$token}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long."); diff --git a/src/Http/Auth/BearerTokenAuthenticator.php b/src/Http/Auth/BearerTokenAuthenticator.php index 4cf054280..f0c45ea3a 100644 --- a/src/Http/Auth/BearerTokenAuthenticator.php +++ b/src/Http/Auth/BearerTokenAuthenticator.php @@ -10,7 +10,7 @@ class BearerTokenAuthenticator implements Authenticator protected string $token; public function __construct( - string $token, + string $token ) { $this->token = trim($token); } diff --git a/src/Http/Payload/ApplicationFee.php b/src/Http/Payload/ApplicationFee.php index 870e42516..e2bf0b55a 100644 --- a/src/Http/Payload/ApplicationFee.php +++ b/src/Http/Payload/ApplicationFee.php @@ -10,7 +10,7 @@ class ApplicationFee extends DataBag public function __construct( Money $amount, - string $description, + string $description ) { $this->amount = $amount; $this->description = $description; diff --git a/src/Http/Payload/CreatePaymentPayload.php b/src/Http/Payload/CreatePaymentPayload.php index b670506b2..2aee4bf57 100644 --- a/src/Http/Payload/CreatePaymentPayload.php +++ b/src/Http/Payload/CreatePaymentPayload.php @@ -84,7 +84,7 @@ public function __construct( ?string $customerId = null, ?string $profileId = null, ?bool $testmode = null, - array $additional = [], + array $additional = [] ) { $this->description = $description; $this->amount = $amount; diff --git a/src/Http/Payload/OrderLine.php b/src/Http/Payload/OrderLine.php index f32fc66da..1de25c7c0 100644 --- a/src/Http/Payload/OrderLine.php +++ b/src/Http/Payload/OrderLine.php @@ -48,7 +48,7 @@ public function __construct( ?Money $vatAmount = null, ?string $sku = null, ?string $imageUrl = null, - ?string $productUrl = null, + ?string $productUrl = null ) { $this->description = $description; $this->quantity = $quantity; diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index 0bad63dac..6e759c1d4 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -9,9 +9,8 @@ class PaymentRoute extends DataBag public function __construct( public readonly Money $amount, public readonly string $organizationId, - public readonly ?DateTimeInterface $delayUntil = null, - ) { - } + public readonly ?DateTimeInterface $delayUntil = null + ) {} public function data(): array { diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php index bf19ea4b4..5b82812af 100644 --- a/src/Http/Payload/RecurringBillingCycle.php +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -27,7 +27,7 @@ public function __construct( ?string $description = null, ?Money $amount = null, ?int $times = null, - ?DateTimeInterface $startDate = null, + ?DateTimeInterface $startDate = null ) { $this->interval = $interval; $this->description = $description; diff --git a/src/Http/Payload/RefundRoute.php b/src/Http/Payload/RefundRoute.php index c2dc24326..240a55558 100644 --- a/src/Http/Payload/RefundRoute.php +++ b/src/Http/Payload/RefundRoute.php @@ -10,7 +10,7 @@ class RefundRoute extends DataBag public function __construct( Money $amount, - string $organizationId, + string $organizationId ) { $this->amount = $amount; $this->organizationId = $organizationId; diff --git a/src/Http/Payload/UpdatePaymentPayload.php b/src/Http/Payload/UpdatePaymentPayload.php index a5b5b497b..f5774907a 100644 --- a/src/Http/Payload/UpdatePaymentPayload.php +++ b/src/Http/Payload/UpdatePaymentPayload.php @@ -39,7 +39,7 @@ public function __construct( ?string $locale = null, ?string $restrictPaymentMethodsToCountry = null, ?bool $testmode = null, - array $additional = [], + array $additional = [] ) { $this->description = $description; $this->redirectUrl = $redirectUrl; diff --git a/src/Http/Requests/DynamicDeleteRequest.php b/src/Http/Requests/DynamicDeleteRequest.php index 35c06df70..4b8e85e0f 100644 --- a/src/Http/Requests/DynamicDeleteRequest.php +++ b/src/Http/Requests/DynamicDeleteRequest.php @@ -23,7 +23,7 @@ public function __construct( string $url, string $resourceClass = '', ?bool $testmode = null, - array $body = [], + array $body = [] ) { parent::__construct($url, $resourceClass); diff --git a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php index c531568eb..f776503c7 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -17,7 +17,7 @@ class GetPaginatedPaymentRefundsRequest extends PaginatedRequest public function __construct( string $paymentId, - ?GetPaginatedPaymentRefundQuery $query = null, + ?GetPaginatedPaymentRefundQuery $query = null ) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 63cdd56ed..da4dee8d1 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -26,7 +26,7 @@ class GetPaymentRequest extends Request public function __construct( string $id, - GetPaymentQuery $query, + GetPaymentQuery $query ) { $this->id = $id; $this->query = $query; From b74f99624cd1e1b5c8dd308e91d25983fda9444d Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:03:47 +0200 Subject: [PATCH 056/131] wip --- src/Contracts/HasPayload.php | 2 +- src/Contracts/JsonBodyRepository.php | 10 ---------- src/Contracts/JsonPayloadRepository.php | 10 ++++++++++ .../{BodyRepository.php => PayloadRepository.php} | 2 +- .../Middleware/ThrowExceptionIfRequestFailed.php | 4 ++-- src/Http/Payload/PaymentRoute.php | 4 +++- src/Http/PendingRequest.php | 12 ++++++------ src/Http/PendingRequest/AuthenticateRequest.php | 2 +- src/Http/Requests/CreatePaymentRequest.php | 2 +- src/Http/Requests/PaginatedRequest.php | 4 +++- ...nBodyRepository.php => JsonPayloadRepository.php} | 4 ++-- src/Traits/HasJsonPayload.php | 8 ++++---- src/Traits/ManagesPsrRequests.php | 6 +++--- 13 files changed, 37 insertions(+), 33 deletions(-) delete mode 100644 src/Contracts/JsonBodyRepository.php create mode 100644 src/Contracts/JsonPayloadRepository.php rename src/Contracts/{BodyRepository.php => PayloadRepository.php} (95%) rename src/Repositories/{JsonBodyRepository.php => JsonPayloadRepository.php} (87%) diff --git a/src/Contracts/HasPayload.php b/src/Contracts/HasPayload.php index 803a8bbba..4c5e3bfab 100644 --- a/src/Contracts/HasPayload.php +++ b/src/Contracts/HasPayload.php @@ -4,5 +4,5 @@ interface HasPayload { - public function payload(): BodyRepository; + public function payload(): PayloadRepository; } diff --git a/src/Contracts/JsonBodyRepository.php b/src/Contracts/JsonBodyRepository.php deleted file mode 100644 index 5fa8c218c..000000000 --- a/src/Contracts/JsonBodyRepository.php +++ /dev/null @@ -1,10 +0,0 @@ -_links->documentation->href}"; } - if ($response->getPendingRequest()->body()) { + if ($response->getPendingRequest()->payload()) { $streamFactory = $response ->getPendingRequest() ->getFactoryCollection() ->streamFactory; - $message .= ". Request body: {$response->getPendingRequest()->body()->toStream($streamFactory)->getContents()}"; + $message .= ". Request body: {$response->getPendingRequest()->payload()->toStream($streamFactory)->getContents()}"; } throw new ApiException( diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index 6e759c1d4..16d7a7b58 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -20,7 +20,9 @@ public function data(): array 'type' => 'organization', 'organizationId' => $this->organizationId, ], - 'delayUntil' => $this->delayUntil?->format('Y-m-d'), + 'delayUntil' => $this->delayUntil + ? $this->delayUntil->format('Y-m-d') + : null, ]; } } diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index 3dc8d25ba..63e986b91 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http; -use Mollie\Api\Contracts\BodyRepository; use Mollie\Api\Contracts\Connector; use Mollie\Api\Contracts\HasResponse; +use Mollie\Api\Contracts\PayloadRepository; use Mollie\Api\Helpers\MiddlewarePriority; use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; @@ -32,7 +32,7 @@ class PendingRequest protected Request $request; - protected ?BodyRepository $body = null; + protected ?PayloadRepository $payload = null; protected string $method; @@ -71,16 +71,16 @@ public function __construct(Connector $connector, Request $request) } - public function setPayload(BodyRepository $bodyRepository): self + public function setPayload(PayloadRepository $bodyRepository): self { - $this->body = $bodyRepository; + $this->payload = $bodyRepository; return $this; } - public function body(): ?BodyRepository + public function payload(): ?PayloadRepository { - return $this->body; + return $this->payload; } public function url(): string diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php index c71811972..f361e4547 100644 --- a/src/Http/PendingRequest/AuthenticateRequest.php +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -36,7 +36,7 @@ private function removeTestmode(PendingRequest $pendingRequest): void } if ($pendingRequest->getRequest() instanceof HasPayload) { - $pendingRequest->body()?->remove('testmode'); + $pendingRequest->payload()->remove('testmode'); } } } diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index 72479fbe2..f61c5cc7a 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -41,7 +41,7 @@ protected function defaultPayload(): array protected function defaultQuery(): array { - return $this->query?->toArray() ?? []; + return $this->query ? $this->query->toArray() : []; } /** diff --git a/src/Http/Requests/PaginatedRequest.php b/src/Http/Requests/PaginatedRequest.php index 3f858eba2..aab083b35 100644 --- a/src/Http/Requests/PaginatedRequest.php +++ b/src/Http/Requests/PaginatedRequest.php @@ -23,6 +23,8 @@ public function __construct( protected function defaultQuery(): array { - return $this->query?->toArray() ?? []; + return $this->query + ? $this->query->toArray() + : []; } } diff --git a/src/Repositories/JsonBodyRepository.php b/src/Repositories/JsonPayloadRepository.php similarity index 87% rename from src/Repositories/JsonBodyRepository.php rename to src/Repositories/JsonPayloadRepository.php index 686da8058..6bacedf52 100644 --- a/src/Repositories/JsonBodyRepository.php +++ b/src/Repositories/JsonPayloadRepository.php @@ -2,11 +2,11 @@ namespace Mollie\Api\Repositories; -use Mollie\Api\Contracts\JsonBodyRepository as JsonBodyRepositoryContract; +use Mollie\Api\Contracts\JsonPayloadRepository as JsonBodyRepositoryContract; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamInterface; -class JsonBodyRepository implements JsonBodyRepositoryContract +class JsonPayloadRepository implements JsonBodyRepositoryContract { private array $store = []; diff --git a/src/Traits/HasJsonPayload.php b/src/Traits/HasJsonPayload.php index 63281a5c9..1b25d3e66 100644 --- a/src/Traits/HasJsonPayload.php +++ b/src/Traits/HasJsonPayload.php @@ -2,15 +2,15 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Repositories\JsonBodyRepository; +use Mollie\Api\Repositories\JsonPayloadRepository; trait HasJsonPayload { - public ?JsonBodyRepository $body = null; + public ?JsonPayloadRepository $body = null; - public function payload(): JsonBodyRepository + public function payload(): JsonPayloadRepository { - return $this->body ??= new JsonBodyRepository($this->defaultPayload()); + return $this->body ??= new JsonPayloadRepository($this->defaultPayload()); } protected function defaultPayload(): array diff --git a/src/Traits/ManagesPsrRequests.php b/src/Traits/ManagesPsrRequests.php index ca4aa0a64..459b5fe72 100644 --- a/src/Traits/ManagesPsrRequests.php +++ b/src/Traits/ManagesPsrRequests.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Contracts\BodyRepository; +use Mollie\Api\Contracts\PayloadRepository; use Mollie\Api\Helpers\Factories; use Mollie\Api\Helpers\Url; use Mollie\Api\Http\PendingRequest; @@ -29,8 +29,8 @@ public function createPsrRequest(): RequestInterface $request = $request->withHeader($headerName, $headerValue); } - if ($this->body() instanceof BodyRepository) { - $request = $request->withBody($this->body()->toStream($factories->streamFactory)); + if ($this->payload() instanceof PayloadRepository) { + $request = $request->withBody($this->payload()->toStream($factories->streamFactory)); } return $request; From 8d0a3fd0fd8352d9a9b56a2cf14a9b194b9d972f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:05:11 +0200 Subject: [PATCH 057/131] wip --- src/Http/Payload/PaymentRoute.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index 16d7a7b58..cc9698dcc 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -6,11 +6,21 @@ class PaymentRoute extends DataBag { + public Money $amount; + + public string $organizationId; + + public ?DateTimeInterface $delayUntil; + public function __construct( - public readonly Money $amount, - public readonly string $organizationId, - public readonly ?DateTimeInterface $delayUntil = null - ) {} + Money $amount, + string $organizationId, + ?DateTimeInterface $delayUntil = null + ) { + $this->amount = $amount; + $this->organizationId = $organizationId; + $this->delayUntil = $delayUntil; + } public function data(): array { From e56a37a2e76fcdf6a1890f1d4d632e4c3319b18b Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:08:04 +0200 Subject: [PATCH 058/131] wip --- src/Helpers/Validator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Helpers/Validator.php b/src/Helpers/Validator.php index fc35e1ab2..33e852ea2 100644 --- a/src/Helpers/Validator.php +++ b/src/Helpers/Validator.php @@ -32,7 +32,9 @@ public function validate(ValidatableDataProvider $provider, array $additional = // Validate properties with rules foreach ($propsWithRules as $key => $value) { - $rules[$key]->validate($value, $provider, static fn (string $message) => throw new RequestValidationException($message)); + $rules[$key]->validate($value, $provider, static function (string $message) { + throw new RequestValidationException($message); + }); } } From 8298dffd12bdaaed20ef1613f821cae292d47a93 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:09:13 +0200 Subject: [PATCH 059/131] wip --- src/Traits/HandlesAutoHydration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php index b86ad52c8..861b3d1f5 100644 --- a/src/Traits/HandlesAutoHydration.php +++ b/src/Traits/HandlesAutoHydration.php @@ -27,7 +27,7 @@ public function evaluateHydrationSetting(): void { (is_callable(static::$hydrationSettingResolver) ? static::$hydrationSettingResolver - : self function () { + : static function () { return (bool) static::$hydrationSettingResolver; })(); } From a02a1d10f8b9277b11964d16eace3ab6ddda7c72 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:13:14 +0200 Subject: [PATCH 060/131] wip --- scoper.inc.php | 13 ------------- src/Traits/HandlesResourceCreation.php | 5 ++++- 2 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 scoper.inc.php diff --git a/scoper.inc.php b/scoper.inc.php deleted file mode 100644 index 88317a713..000000000 --- a/scoper.inc.php +++ /dev/null @@ -1,13 +0,0 @@ - [], // Finder[] - 'patchers' => [], // callable[] - 'whitelist' => [ - 'Mollie\\Api\\*', - ], -]; \ No newline at end of file diff --git a/src/Traits/HandlesResourceCreation.php b/src/Traits/HandlesResourceCreation.php index 06eb57d7f..cd38d9388 100644 --- a/src/Traits/HandlesResourceCreation.php +++ b/src/Traits/HandlesResourceCreation.php @@ -33,7 +33,10 @@ protected function createResource(Request $request, Response $response) return $response; } - private function unwrapIterator(Request $request, BaseCollection $collection): BaseCollection|LazyCollection + /** + * @return BaseCollection|LazyCollection + */ + private function unwrapIterator(Request $request, BaseCollection $collection) { if ($request instanceof IsIteratable && $request->iteratorEnabled()) { /** @var CursorCollection $collection */ From ae721ee58d5026160a9af7f1d415939d134cebf4 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:19:32 +0200 Subject: [PATCH 061/131] wip --- src/Traits/HandlesIdempotency.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Traits/HandlesIdempotency.php b/src/Traits/HandlesIdempotency.php index bf26aa2f6..bb8bbef72 100644 --- a/src/Traits/HandlesIdempotency.php +++ b/src/Traits/HandlesIdempotency.php @@ -9,8 +9,6 @@ */ trait HandlesIdempotency { - const IDEMPOTENCY_KEY_HEADER = 'Idempotency-Key'; - protected ?IdempotencyKeyGeneratorContract $idempotencyKeyGenerator; /** From bb1d96603eb3b4c4d2ba5125160a63f6047c7af8 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:21:46 +0200 Subject: [PATCH 062/131] wip --- src/Traits/ManagesPsrRequests.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/ManagesPsrRequests.php b/src/Traits/ManagesPsrRequests.php index 459b5fe72..cec2ba752 100644 --- a/src/Traits/ManagesPsrRequests.php +++ b/src/Traits/ManagesPsrRequests.php @@ -21,8 +21,8 @@ public function createPsrRequest(): RequestInterface $factories = $this->factoryCollection; $request = $factories->requestFactory->createRequest( - method: $this->method(), - uri: $this->getUri(), + $this->method(), + $this->getUri(), ); foreach ($this->headers()->all() as $headerName => $headerValue) { From 20317a8b10434e569a2ac2e538f9d9c6119011ea Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Mon, 9 Sep 2024 10:24:19 +0200 Subject: [PATCH 063/131] wip --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 4182465a7..81790c527 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,6 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", - "laravel/pint": "^1.17", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.6" }, From 5cbc383bad8ef622a2861c4f923fb5400de878ad Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 12 Nov 2024 12:01:14 +0100 Subject: [PATCH 064/131] wip --- src/Helpers/Handlers.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Helpers/Handlers.php b/src/Helpers/Handlers.php index c6b4cf5c4..d0081ca54 100644 --- a/src/Helpers/Handlers.php +++ b/src/Helpers/Handlers.php @@ -87,5 +87,7 @@ private function handlerExists(string $name): bool return true; } } + + return false; } } From e249f3e70a74a4e94fd0a8febde92d5fecab1f83 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 26 Nov 2024 16:32:10 +0100 Subject: [PATCH 065/131] wip --- .github/workflows/fix-codestyle.yml | 33 + .github/workflows/php-cs-fixer.yml | 23 - README.md | 2 +- UPGRADING.md | 115 +- examples/captures/create-capture.php | 14 +- examples/captures/get-capture.php | 8 +- examples/captures/list-captures.php | 8 +- examples/client-links/create-client-link.php | 36 +- .../create-customer-first-payment.php | 26 +- .../customers/create-customer-payment.php | 26 +- .../create-customer-recurring-payment.php | 26 +- examples/customers/create-customer.php | 14 +- examples/customers/delete-customer.php | 8 +- examples/customers/list-customer-payments.php | 28 +- examples/customers/update-customer.php | 14 +- examples/functions.php | 6 +- examples/initialize.php | 8 +- examples/initialize_with_oauth.php | 8 +- examples/invoices/list-invoices.php | 22 +- examples/mandates/create-mandate.php | 12 +- examples/mandates/list-mandates.php | 12 +- examples/mandates/revoke-mandate.php | 10 +- examples/orders/cancel-order-lines.php | 44 - examples/orders/cancel-order.php | 26 - examples/orders/create-order.php | 118 -- examples/orders/list-methods.php | 28 - examples/orders/list-orders.php | 48 - examples/orders/refund-order-completely.php | 25 - examples/orders/refund-order-partially.php | 33 - examples/orders/update-order-line.php | 44 - .../orders/update-order-lines-multiple.php | 70 - examples/orders/update-order.php | 45 - examples/orders/webhook.php | 50 - examples/pagination/backwards.php | 8 +- examples/pagination/basic_usage.php | 10 +- .../payment-links/create-payment-link.php | 18 +- examples/payment-links/list-payment-links.php | 22 +- .../payments/create-capturable-payment.php | 28 +- examples/payments/create-ideal-payment.php | 34 +- examples/payments/create-payment-oauth.php | 32 +- examples/payments/create-payment.php | 24 +- ...outed-payment-with-future-release-date.php | 44 +- examples/payments/create-routed-payment.php | 42 +- examples/payments/list-methods.php | 8 +- examples/payments/list-payments.php | 50 +- examples/payments/refund-payment.php | 40 +- examples/payments/return.php | 22 +- examples/payments/update-payment.php | 17 +- examples/payments/webhook.php | 6 +- examples/profiles/create-profile.php | 18 +- examples/profiles/delete-profile.php | 8 +- examples/profiles/list-profiles.php | 10 +- examples/profiles/update-profile.php | 12 +- examples/sessions/cancel-session.php | 6 +- examples/sessions/create-session.php | 28 +- examples/sessions/list-sessions.php | 17 +- examples/sessions/update-session.php | 30 +- examples/settlements/list-settlements.php | 32 +- examples/shipments/create-shipment-all.php | 27 - .../shipments/create-shipment-partial.php | 42 - examples/shipments/get-shipment.php | 27 - examples/shipments/list-shipments.php | 30 - examples/shipments/update-shipment.php | 40 - .../subscriptions/cancel-subscription.php | 6 +- .../subscriptions/create-subscription.php | 32 +- .../subscriptions/update-subscription.php | 12 +- src/Contracts/Connector.php | 2 +- src/Contracts/PayloadRepository.php | 2 + src/Contracts/Rule.php | 2 +- src/Contracts/SupportsResourceHydration.php | 8 + src/Contracts/SupportsTestmodeInPayload.php | 8 + src/Contracts/SupportsTestmodeInQuery.php | 8 + src/Contracts/Testable.php | 8 + src/Contracts/ValidatableDataProvider.php | 8 - .../BalanceEndpointCollection.php | 9 +- .../BalanceReportEndpointCollection.php | 5 +- .../BalanceTransactionEndpointCollection.php | 22 +- .../ChargebackEndpointCollection.php | 8 +- .../CustomerEndpointCollection.php | 20 +- .../CustomerPaymentsEndpointCollection.php | 120 ++ .../InvoiceEndpointCollection.php | 68 + .../MandateEndpointCollection.php | 179 +++ .../MethodEndpointCollection.php | 87 ++ .../MethodIssuerEndpointCollection.php | 31 + .../OnboardingEndpointCollection.php | 14 + .../OrganizationEndpointCollection.php | 14 +- .../OrganizationPartnerEndpointCollection.php | 17 + .../PaymentCaptureEndpointCollection.php | 148 ++ .../PaymentChargebackEndpointCollection.php | 115 ++ .../PaymentEndpointCollection.php | 31 +- .../PaymentLinkEndpointCollection.php | 131 ++ .../PaymentLinkPaymentEndpointCollection.php | 97 ++ .../PaymentRefundEndpointCollection.php | 132 +- .../PaymentRouteEndpointCollection.php | 42 + .../PermissionEndpointCollection.php | 41 + .../ProfileEndpointCollection.php | 149 +++ .../RefundEndpointCollection.php | 60 + .../SessionEndpointCollection.php | 129 ++ .../SettlementCaptureEndpointCollection.php | 89 ++ ...SettlementChargebackEndpointCollection.php | 89 ++ .../SettlementPaymentEndpointCollection.php | 80 ++ .../SettlementRefundEndpointCollection.php | 82 ++ .../SettlementsEndpointCollection.php | 80 ++ .../SubscriptionEndpointCollection.php | 219 +++ .../SubscriptionPaymentEndpointCollection.php | 89 ++ .../TerminalEndpointCollection.php | 77 ++ .../WalletEndpointCollection.php | 29 + src/Endpoints/CustomerPaymentsEndpoint.php | 141 -- src/Endpoints/InvoiceEndpoint.php | 93 -- src/Endpoints/MandateEndpoint.php | 194 --- src/Endpoints/MethodEndpoint.php | 84 -- src/Endpoints/MethodIssuerEndpoint.php | 88 -- src/Endpoints/OnboardingEndpoint.php | 68 - src/Endpoints/OrderEndpoint.php | 120 -- src/Endpoints/OrderLineEndpoint.php | 114 -- src/Endpoints/OrderPaymentEndpoint.php | 64 - src/Endpoints/OrderRefundEndpoint.php | 91 -- src/Endpoints/OrderShipmentEndpoint.php | 161 --- src/Endpoints/OrganizationPartnerEndpoint.php | 38 - src/Endpoints/PaymentCaptureEndpoint.php | 165 --- src/Endpoints/PaymentChargebackEndpoint.php | 133 -- src/Endpoints/PaymentLinkEndpoint.php | 135 -- src/Endpoints/PaymentLinkPaymentEndpoint.php | 96 -- src/Endpoints/PaymentRefundEndpoint.php | 210 --- src/Endpoints/PaymentRouteEndpoint.php | 57 - src/Endpoints/PermissionEndpoint.php | 61 - src/Endpoints/ProfileEndpoint.php | 164 --- src/Endpoints/RefundEndpoint.php | 67 - src/Endpoints/SessionEndpoint.php | 56 +- src/Endpoints/SettlementCaptureEndpoint.php | 75 -- .../SettlementChargebackEndpoint.php | 75 -- src/Endpoints/SettlementPaymentEndpoint.php | 73 - src/Endpoints/SettlementRefundEndpoint.php | 75 -- src/Endpoints/SettlementsEndpoint.php | 104 -- src/Endpoints/SubscriptionEndpoint.php | 208 --- src/Endpoints/SubscriptionPaymentEndpoint.php | 76 -- src/Endpoints/TerminalEndpoint.php | 94 -- src/Endpoints/WalletEndpoint.php | 32 - .../CurlConnectTimeoutException.php | 4 +- ...EmbeddedResourcesNotParseableException.php | 4 +- ...dapterDoesNotSupportDebuggingException.php | 4 +- src/Exceptions/IncompatiblePlatform.php | 4 + src/Exceptions/RequestValidationException.php | 5 - .../UnrecognizedClientException.php | 4 +- src/Exceptions/ValidationException.php | 5 + .../ApplePayPaymentSessionPayloadFactory.php | 17 + .../CreateCustomerPayloadFactory.php | 1 - src/Factories/CreateMandatePayloadFactory.php | 28 + .../CreatePaymentCapturePayloadFactory.php | 18 + .../CreatePaymentLinkPayloadFactory.php | 21 + src/Factories/CreatePaymentPayloadFactory.php | 1 - src/Factories/CreateProfilePayloadFactory.php | 21 + .../CreateRefundPaymentPayloadFactory.php | 1 - .../CreateSubscriptionPayloadFactory.php | 28 + src/Factories/Factory.php | 29 +- src/Factories/GetAllMethodsQueryFactory.php | 17 + ...tAllPaginatedSubscriptionsQueryFactory.php | 19 + .../GetBalanceReportQueryFactory.php | 1 - .../GetEnabledMethodsQueryFactory.php | 25 + .../GetPaginatedBalanceQueryFactory.php | 9 +- .../GetPaginatedChargebackQueryFactory.php | 16 +- .../GetPaginatedClientQueryFactory.php | 13 +- ...tPaginatedCustomerPaymentsQueryFactory.php | 16 + .../GetPaginatedInvoiceQueryFactory.php | 29 + ...etPaginatedPaymentCapturesQueryFactory.php | 18 + ...aginatedPaymentChargebacksQueryFactory.php | 18 + .../GetPaginatedPaymentRefundQueryFactory.php | 6 +- .../GetPaginatedRefundsQueryFactory.php | 17 + ...aginatedSettlementCapturesQueryFactory.php | 16 + ...natedSettlementChargebacksQueryFactory.php | 20 + ...PaginatedSettlementRefundsQueryFactory.php | 18 + .../GetPaginatedSettlementsQueryFactory.php | 21 + .../GetPaymentCaptureQueryFactory.php | 15 + .../GetPaymentChargebackQueryFactory.php | 16 + .../GetPaymentMethodQueryFactory.php | 18 + .../GetPaymentRefundQueryFactory.php | 1 - src/Factories/PaginatedQueryFactory.php | 3 - .../SortablePaginatedQueryFactory.php | 6 +- .../UpdatePaymentLinkPayloadFactory.php | 16 + src/Factories/UpdatePaymentPayloadFactory.php | 1 - .../UpdatePaymentRoutePayloadFactory.php | 16 + src/Factories/UpdateProfilePayloadFactory.php | 22 + .../UpdateSubscriptionPayloadFactory.php | 24 + src/Helpers/Validator.php | 74 - .../Adapter/GuzzleRetryMiddlewareFactory.php | 15 +- src/Http/Middleware/Hydrate.php | 3 +- src/Http/Payload/Address.php | 4 +- src/Http/Payload/CreateCustomerPayload.php | 7 +- src/Http/Payload/CreateMandatePayload.php | 58 + .../Payload/CreatePaymentCapturePayload.php | 31 + src/Http/Payload/CreatePaymentLinkPayload.php | 53 + src/Http/Payload/CreatePaymentPayload.php | 4 - src/Http/Payload/CreateProfilePayload.php | 51 + .../Payload/CreateRefundPaymentPayload.php | 5 - .../Payload/CreateSubscriptionPayload.php | 78 ++ src/Http/Payload/DataBag.php | 5 +- src/Http/Payload/OrderLine.php | 14 - src/Http/Payload/RecurringBillingCycle.php | 8 - .../RequestApplePayPaymentSessionPayload.php | 31 + src/Http/Payload/UpdatePaymentLinkPayload.php | 26 + src/Http/Payload/UpdatePaymentPayload.php | 5 - .../Payload/UpdatePaymentRoutePayload.php | 23 + src/Http/Payload/UpdateProfilePayload.php | 56 + .../Payload/UpdateSubscriptionPayload.php | 58 + src/Http/PendingRequest.php | 25 +- .../PendingRequest/AddTestmodeIfEnabled.php | 19 + .../PendingRequest/AuthenticateRequest.php | 18 - ...veTestmodeFromApiAuthenticatedRequests.php | 33 + .../PendingRequest/ValidateProperties.php | 21 - src/Http/Query/CreatePaymentQuery.php | 9 - src/Http/Query/GetAllMethodsQuery.php | 34 + .../GetAllPaginatedSubscriptionsQuery.php | 23 + src/Http/Query/GetBalanceReportQuery.php | 5 - src/Http/Query/GetEnabledMethodsQuery.php | 37 + src/Http/Query/GetPaginatedBalanceQuery.php | 15 +- .../Query/GetPaginatedChargebackQuery.php | 15 +- src/Http/Query/GetPaginatedClientQuery.php | 23 +- .../GetPaginatedCustomerPaymentsQuery.php | 28 + src/Http/Query/GetPaginatedInvoiceQuery.php | 33 + .../GetPaginatedPaymentCapturesQuery.php | 30 + .../GetPaginatedPaymentChargebacksQuery.php | 30 + .../Query/GetPaginatedPaymentRefundQuery.php | 15 +- src/Http/Query/GetPaginatedRefundsQuery.php | 35 + .../GetPaginatedSettlementCapturesQuery.php | 5 + ...GetPaginatedSettlementChargebacksQuery.php | 8 + .../GetPaginatedSettlementRefundsQuery.php | 8 + .../Query/GetPaginatedSettlementsQuery.php | 26 + src/Http/Query/GetPaymentCaptureQuery.php | 23 + src/Http/Query/GetPaymentChargebackQuery.php | 23 + src/Http/Query/GetPaymentMethodQuery.php | 25 + src/Http/Query/GetPaymentQuery.php | 15 - src/Http/Query/GetPaymentRefundQuery.php | 14 - src/Http/Query/PaginatedQuery.php | 5 - src/Http/Query/Query.php | 7 +- src/Http/Query/SortablePaginatedQuery.php | 12 +- src/Http/Request.php | 21 +- .../ApplePayPaymentSessionRequest.php | 33 + .../Requests/CancelPaymentRefundRequest.php | 19 +- src/Http/Requests/CancelPaymentRequest.php | 12 +- .../Requests/CancelSubscriptionRequest.php | 38 + src/Http/Requests/CreateClientLinkRequest.php | 8 +- .../Requests/CreateCustomerPaymentRequest.php | 46 + src/Http/Requests/CreateCustomerRequest.php | 4 +- src/Http/Requests/CreateMandateRequest.php | 45 + .../Requests/CreatePaymentCaptureRequest.php | 45 + .../Requests/CreatePaymentLinkRequest.php | 44 + .../Requests/CreatePaymentRefundRequest.php | 14 +- src/Http/Requests/CreatePaymentRequest.php | 4 +- src/Http/Requests/CreateProfileRequest.php | 45 + .../Requests/CreateSubscriptionRequest.php | 48 + src/Http/Requests/DeleteCustomerRequest.php | 14 +- .../Requests/DeletePaymentLinkRequest.php | 16 + src/Http/Requests/DeleteProfileRequest.php | 26 + .../Requests/DisableMethodIssuerRequest.php | 32 + src/Http/Requests/DynamicDeleteRequest.php | 45 - src/Http/Requests/DynamicPatchRequest.php | 40 - src/Http/Requests/DynamicPostRequest.php | 43 - src/Http/Requests/DynamicRequest.php | 4 +- .../Requests/EnableMethodIssuerRequest.php | 55 + src/Http/Requests/GetAllMethodsRequest.php | 37 + .../GetAllPaginatedSubscriptionsRequest.php | 26 + src/Http/Requests/GetBalanceReportRequest.php | 4 +- src/Http/Requests/GetBalanceRequest.php | 10 +- src/Http/Requests/GetClientRequest.php | 12 +- src/Http/Requests/GetCustomerRequest.php | 18 +- .../Requests/GetEnabledMethodsRequest.php | 32 + src/Http/Requests/GetInvoiceRequest.php | 28 + src/Http/Requests/GetMandateRequest.php | 35 + src/Http/Requests/GetOnboardingRequest.php | 18 + .../GetOrganizationPartnerStatusRequest.php | 18 + src/Http/Requests/GetOrganizationRequest.php | 3 +- .../Requests/GetPaginatedBalanceRequest.php | 3 +- .../GetPaginatedChargebacksRequest.php | 3 +- .../GetPaginatedCustomerPaymentsRequest.php | 35 + .../Requests/GetPaginatedCustomerRequest.php | 3 +- .../Requests/GetPaginatedInvoiceRequest.php | 22 + .../Requests/GetPaginatedMandateRequest.php | 33 + .../GetPaginatedPaymentCapturesRequest.php | 48 + .../GetPaginatedPaymentChargebacksRequest.php | 44 + ...GetPaginatedPaymentLinkPaymentsRequest.php | 35 + .../GetPaginatedPaymentLinksRequest.php | 29 + .../GetPaginatedPaymentRefundsRequest.php | 16 +- .../Requests/GetPaginatedPaymentsRequest.php | 3 +- .../Requests/GetPaginatedProfilesRequest.php | 31 + .../Requests/GetPaginatedRefundsRequest.php | 29 + .../GetPaginatedSettlementCapturesRequest.php | 38 + ...tPaginatedSettlementChargebacksRequest.php | 38 + .../GetPaginatedSettlementPaymentsRequest.php | 36 + .../GetPaginatedSettlementRefundsRequest.php | 38 + .../GetPaginatedSettlementsRequest.php | 25 + ...etPaginatedSubscriptionPaymentsRequest.php | 39 + .../GetPaginatedSubscriptionsRequest.php | 36 + .../Requests/GetPaginatedTerminalsRequest.php | 26 + .../Requests/GetPaymentCaptureRequest.php | 44 + .../Requests/GetPaymentChargebackRequest.php | 44 + src/Http/Requests/GetPaymentLinkRequest.php | 35 + src/Http/Requests/GetPaymentMethodRequest.php | 35 + src/Http/Requests/GetPaymentRefundRequest.php | 14 +- src/Http/Requests/GetPaymentRequest.php | 14 +- src/Http/Requests/GetPermissionRequest.php | 26 + src/Http/Requests/GetProfileRequest.php | 29 + src/Http/Requests/GetSettlementRequest.php | 26 + src/Http/Requests/GetSubscriptionRequest.php | 35 + src/Http/Requests/GetTerminalRequest.php | 29 + src/Http/Requests/ListPermissionsRequest.php | 21 + src/Http/Requests/PaginatedRequest.php | 9 +- .../Requests/ResourceHydratableRequest.php | 23 + src/Http/Requests/RevokeMandateRequest.php | 30 + src/Http/Requests/SimpleRequest.php | 12 +- .../Requests/SortablePaginatedRequest.php | 14 - src/Http/Requests/UpdateCustomerRequest.php | 18 +- .../Requests/UpdatePaymentLinkRequest.php | 42 + src/Http/Requests/UpdatePaymentRequest.php | 12 +- .../Requests/UpdatePaymentRouteRequest.php | 48 + src/Http/Requests/UpdateProfileRequest.php | 41 + .../Requests/UpdateSubscriptionRequest.php | 54 + src/Http/Response.php | 6 + src/Http/ResponseStatusCode.php | 62 + src/MollieApiClient.php | 3 +- src/Repositories/JsonPayloadRepository.php | 7 + src/Resources/BalanceCollection.php | 6 +- src/Resources/BalanceReport.php | 3 + src/Resources/BalanceTransaction.php | 3 + .../BalanceTransactionCollection.php | 6 +- src/Resources/Capture.php | 1 + src/Resources/CaptureCollection.php | 6 +- src/Resources/Chargeback.php | 2 + src/Resources/ChargebackCollection.php | 6 +- src/Resources/Client.php | 1 + src/Resources/ClientCollection.php | 6 +- src/Resources/ClientLink.php | 1 + src/Resources/CursorCollection.php | 4 +- src/Resources/Customer.php | 4 +- src/Resources/CustomerCollection.php | 6 +- src/Resources/HasPresetOptions.php | 7 +- src/Resources/Invoice.php | 12 +- src/Resources/InvoiceCollection.php | 6 +- src/Resources/Issuer.php | 1 + src/Resources/IssuerCollection.php | 4 +- src/Resources/Mandate.php | 17 +- src/Resources/MandateCollection.php | 9 +- src/Resources/MethodCollection.php | 4 +- src/Resources/MethodPrice.php | 1 + src/Resources/MethodPriceCollection.php | 4 +- src/Resources/Onboarding.php | 9 - src/Resources/Order.php | 513 ------- src/Resources/OrderCollection.php | 20 - src/Resources/OrderLine.php | 382 ------ src/Resources/OrderLineCollection.php | 3 +- src/Resources/PaymentCollection.php | 6 +- src/Resources/PaymentLink.php | 2 + src/Resources/PaymentLinkCollection.php | 6 +- src/Resources/Permission.php | 1 + src/Resources/PermissionCollection.php | 4 +- src/Resources/ProfileCollection.php | 6 +- src/Resources/Refund.php | 9 +- src/Resources/RefundCollection.php | 6 +- src/Resources/Route.php | 3 + src/Resources/Session.php | 8 +- src/Resources/SessionCollection.php | 2 +- src/Resources/Settlement.php | 2 + src/Resources/SettlementCollection.php | 6 +- src/Resources/Shipment.php | 119 -- src/Resources/ShipmentCollection.php | 2 - src/Resources/Subscription.php | 13 +- src/Resources/SubscriptionCollection.php | 6 +- src/Resources/Terminal.php | 21 +- src/Resources/TerminalCollection.php | 6 +- src/Rules/Id.php | 43 - src/Rules/Included.php | 48 - src/Rules/Matches.php | 29 - src/Rules/Max.php | 33 - src/Rules/Min.php | 33 - src/Traits/GetAllConstants.php | 13 + src/Traits/HandlesResourceCreation.php | 3 +- src/Traits/HandlesTestmode.php | 12 +- src/Traits/HasEndpoints.php | 105 +- src/Traits/HasRules.php | 11 - src/Types/ApprovalPrompt.php | 4 +- src/Types/BalanceTransferFrequency.php | 32 +- src/Types/BusinessCategory.php | 302 +++++ src/Types/CaptureMode.php | 5 +- src/Types/InvoiceStatus.php | 6 +- src/Types/MandateMethod.php | 10 +- src/Types/MandateStatus.php | 8 +- src/Types/MethodQuery.php | 42 + src/Types/OrderLineCategory.php | 27 + src/Types/OrderLineStatus.php | 12 +- src/Types/OrderLineType.php | 6 + src/Types/OrderLineUpdateOperationType.php | 1 + src/Types/OrderStatus.php | 46 - ...fundQuery.php => PaymentIncludesQuery.php} | 2 +- src/Types/PaymentMethod.php | 73 +- src/Types/PaymentMethodStatus.php | 10 +- src/Types/PaymentStatus.php | 14 +- src/Types/SequenceType.php | 8 +- src/Types/SessionStatus.php | 8 +- src/Types/SubscriptionStatus.php | 18 +- src/Types/TerminalStatus.php | 6 +- tests/CompatibilityCheckerTest.php | 4 +- .../BalanceEndpointCollectionTest.php | 8 +- tests/Helpers/UrlTest.php | 6 +- tests/Helpers/ValidatorTest.php | 124 -- .../Adapter/GuzzleMollieHttpAdapterTest.php | 6 +- .../Adapter/MollieHttpAdapterPickerTest.php | 8 +- .../Adapter/RetryMiddlewareFactoryTest.php | 6 +- .../Endpoints/BalanceReportEndpointTest.php | 4 +- .../BalanceTransactionEndpointTest.php | 8 +- .../Mollie/API/Endpoints/BaseEndpointTest.php | 10 +- .../API/Endpoints/ChargebackEndpointTest.php | 4 +- .../API/Endpoints/ClientEndpointTest.php | 4 +- .../API/Endpoints/ClientLinkEndpointTest.php | 2 +- .../API/Endpoints/CustomerEndpointTest.php | 52 +- .../Endpoints/CustomerPaymentEndpointTest.php | 56 +- ...ustomerSubscriptionPaymentEndpointTest.php | 2 +- .../API/Endpoints/InvoiceEndpointTest.php | 52 +- .../API/Endpoints/MandateEndpointTest.php | 62 +- .../API/Endpoints/MethodEndpointTest.php | 12 +- .../Endpoints/MethodIssuerEndpointTest.php | 4 +- .../API/Endpoints/OnboardingEndpointTest.php | 18 +- .../API/Endpoints/OrderEndpointTest.php | 1191 ----------------- .../API/Endpoints/OrderLineEndpointTest.php | 306 ----- .../Endpoints/OrderPaymentEndpointTest.php | 285 ---- .../API/Endpoints/OrderRefundEndpointTest.php | 427 ------ .../Endpoints/OrganizationEndpointTest.php | 4 +- .../OrganizationPartnerEndpointTest.php | 14 +- .../Endpoints/PaymentCaptureEndpointTest.php | 8 +- .../PaymentChargebackEndpointTest.php | 8 +- .../API/Endpoints/PaymentEndpointTest.php | 18 +- .../API/Endpoints/PaymentLinkEndpointTest.php | 58 +- .../PaymentLinkPaymentEndpointTest.php | 10 +- .../Endpoints/PaymentRefundEndpointTest.php | 203 ++- .../Endpoints/PaymentRouteEndpointTest.php | 8 +- .../API/Endpoints/PermissionEndpointTest.php | 4 +- .../API/Endpoints/ProfileEndpointTest.php | 90 +- .../Endpoints/ProfileMethodEndpointTest.php | 8 +- .../API/Endpoints/RefundEndpointTest.php | 36 +- .../API/Endpoints/SessionEndpointTest.php | 116 +- .../SettlementCaptureEndpointTest.php | 5 +- .../SettlementChargebackEndpointTest.php | 5 +- .../API/Endpoints/SettlementEndpointTest.php | 54 +- .../SettlementPaymentsEndpointTest.php | 4 +- .../SettlementRefundEndpointTest.php | 4 +- .../API/Endpoints/ShipmentEndpointTest.php | 564 -------- .../Endpoints/SubscriptionEndpointTest.php | 120 +- .../SubscriptionPaymentEndpointTest.php | 2 +- .../API/Endpoints/TerminalEndpointTest.php | 6 +- .../API/Endpoints/WalletEndpointTest.php | 6 +- tests/MollieApiClientTest.php | 22 +- tests/Resources/CursorCollectionTest.php | 44 +- tests/Resources/InvoiceTest.php | 2 +- tests/Resources/LazyCollectionTest.php | 18 +- tests/Resources/MandateCollectionTest.php | 2 +- tests/Resources/MethodTest.php | 2 +- tests/Resources/OnboardingTest.php | 2 +- tests/Resources/OrderLineCollectionTest.php | 2 +- tests/Resources/OrderLineTest.php | 172 --- tests/Resources/OrderTest.php | 293 ---- tests/Resources/PaymentTest.php | 44 +- tests/Resources/ProfileTest.php | 2 +- tests/Resources/RefundTest.php | 4 +- tests/Resources/ResourceFactoryTest.php | 6 +- tests/Resources/SettlementTest.php | 2 +- tests/Resources/ShipmentTest.php | 14 +- tests/Resources/SubscriptionTest.php | 2 +- tests/Rules/IdTest.php | 76 -- tests/Rules/IncludedTest.php | 63 - tests/Rules/MatchesTest.php | 42 - tests/Rules/MaxTest.php | 86 -- tests/Rules/MinTest.php | 74 - tests/Types/MandateMethodTest.php | 2 +- 471 files changed, 7812 insertions(+), 11083 deletions(-) create mode 100644 .github/workflows/fix-codestyle.yml delete mode 100644 .github/workflows/php-cs-fixer.yml delete mode 100644 examples/orders/cancel-order-lines.php delete mode 100644 examples/orders/cancel-order.php delete mode 100644 examples/orders/create-order.php delete mode 100644 examples/orders/list-methods.php delete mode 100644 examples/orders/list-orders.php delete mode 100644 examples/orders/refund-order-completely.php delete mode 100644 examples/orders/refund-order-partially.php delete mode 100644 examples/orders/update-order-line.php delete mode 100644 examples/orders/update-order-lines-multiple.php delete mode 100644 examples/orders/update-order.php delete mode 100644 examples/orders/webhook.php delete mode 100644 examples/shipments/create-shipment-all.php delete mode 100644 examples/shipments/create-shipment-partial.php delete mode 100644 examples/shipments/get-shipment.php delete mode 100644 examples/shipments/list-shipments.php delete mode 100644 examples/shipments/update-shipment.php create mode 100644 src/Contracts/SupportsResourceHydration.php create mode 100644 src/Contracts/SupportsTestmodeInPayload.php create mode 100644 src/Contracts/SupportsTestmodeInQuery.php create mode 100644 src/Contracts/Testable.php delete mode 100644 src/Contracts/ValidatableDataProvider.php create mode 100644 src/EndpointCollection/CustomerPaymentsEndpointCollection.php create mode 100644 src/EndpointCollection/InvoiceEndpointCollection.php create mode 100644 src/EndpointCollection/MandateEndpointCollection.php create mode 100644 src/EndpointCollection/MethodEndpointCollection.php create mode 100644 src/EndpointCollection/MethodIssuerEndpointCollection.php create mode 100644 src/EndpointCollection/OnboardingEndpointCollection.php create mode 100644 src/EndpointCollection/OrganizationPartnerEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentCaptureEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentChargebackEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentLinkEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php create mode 100644 src/EndpointCollection/PaymentRouteEndpointCollection.php create mode 100644 src/EndpointCollection/PermissionEndpointCollection.php create mode 100644 src/EndpointCollection/ProfileEndpointCollection.php create mode 100644 src/EndpointCollection/RefundEndpointCollection.php create mode 100644 src/EndpointCollection/SessionEndpointCollection.php create mode 100644 src/EndpointCollection/SettlementCaptureEndpointCollection.php create mode 100644 src/EndpointCollection/SettlementChargebackEndpointCollection.php create mode 100644 src/EndpointCollection/SettlementPaymentEndpointCollection.php create mode 100644 src/EndpointCollection/SettlementRefundEndpointCollection.php create mode 100644 src/EndpointCollection/SettlementsEndpointCollection.php create mode 100644 src/EndpointCollection/SubscriptionEndpointCollection.php create mode 100644 src/EndpointCollection/SubscriptionPaymentEndpointCollection.php create mode 100644 src/EndpointCollection/TerminalEndpointCollection.php create mode 100644 src/EndpointCollection/WalletEndpointCollection.php delete mode 100644 src/Endpoints/CustomerPaymentsEndpoint.php delete mode 100644 src/Endpoints/InvoiceEndpoint.php delete mode 100644 src/Endpoints/MandateEndpoint.php delete mode 100644 src/Endpoints/MethodEndpoint.php delete mode 100644 src/Endpoints/MethodIssuerEndpoint.php delete mode 100644 src/Endpoints/OnboardingEndpoint.php delete mode 100644 src/Endpoints/OrderEndpoint.php delete mode 100644 src/Endpoints/OrderLineEndpoint.php delete mode 100644 src/Endpoints/OrderPaymentEndpoint.php delete mode 100644 src/Endpoints/OrderRefundEndpoint.php delete mode 100644 src/Endpoints/OrderShipmentEndpoint.php delete mode 100644 src/Endpoints/OrganizationPartnerEndpoint.php delete mode 100644 src/Endpoints/PaymentCaptureEndpoint.php delete mode 100644 src/Endpoints/PaymentChargebackEndpoint.php delete mode 100644 src/Endpoints/PaymentLinkEndpoint.php delete mode 100644 src/Endpoints/PaymentLinkPaymentEndpoint.php delete mode 100644 src/Endpoints/PaymentRefundEndpoint.php delete mode 100644 src/Endpoints/PaymentRouteEndpoint.php delete mode 100644 src/Endpoints/PermissionEndpoint.php delete mode 100644 src/Endpoints/ProfileEndpoint.php delete mode 100644 src/Endpoints/RefundEndpoint.php delete mode 100644 src/Endpoints/SettlementCaptureEndpoint.php delete mode 100644 src/Endpoints/SettlementChargebackEndpoint.php delete mode 100644 src/Endpoints/SettlementPaymentEndpoint.php delete mode 100644 src/Endpoints/SettlementRefundEndpoint.php delete mode 100644 src/Endpoints/SettlementsEndpoint.php delete mode 100644 src/Endpoints/SubscriptionEndpoint.php delete mode 100644 src/Endpoints/SubscriptionPaymentEndpoint.php delete mode 100644 src/Endpoints/TerminalEndpoint.php delete mode 100644 src/Endpoints/WalletEndpoint.php delete mode 100644 src/Exceptions/RequestValidationException.php create mode 100644 src/Exceptions/ValidationException.php create mode 100644 src/Factories/ApplePayPaymentSessionPayloadFactory.php create mode 100644 src/Factories/CreateMandatePayloadFactory.php create mode 100644 src/Factories/CreatePaymentCapturePayloadFactory.php create mode 100644 src/Factories/CreatePaymentLinkPayloadFactory.php create mode 100644 src/Factories/CreateProfilePayloadFactory.php create mode 100644 src/Factories/CreateSubscriptionPayloadFactory.php create mode 100644 src/Factories/GetAllMethodsQueryFactory.php create mode 100644 src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php create mode 100644 src/Factories/GetEnabledMethodsQueryFactory.php create mode 100644 src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php create mode 100644 src/Factories/GetPaginatedInvoiceQueryFactory.php create mode 100644 src/Factories/GetPaginatedPaymentCapturesQueryFactory.php create mode 100644 src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php create mode 100644 src/Factories/GetPaginatedRefundsQueryFactory.php create mode 100644 src/Factories/GetPaginatedSettlementCapturesQueryFactory.php create mode 100644 src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php create mode 100644 src/Factories/GetPaginatedSettlementRefundsQueryFactory.php create mode 100644 src/Factories/GetPaginatedSettlementsQueryFactory.php create mode 100644 src/Factories/GetPaymentCaptureQueryFactory.php create mode 100644 src/Factories/GetPaymentChargebackQueryFactory.php create mode 100644 src/Factories/GetPaymentMethodQueryFactory.php create mode 100644 src/Factories/UpdatePaymentLinkPayloadFactory.php create mode 100644 src/Factories/UpdatePaymentRoutePayloadFactory.php create mode 100644 src/Factories/UpdateProfilePayloadFactory.php create mode 100644 src/Factories/UpdateSubscriptionPayloadFactory.php delete mode 100644 src/Helpers/Validator.php create mode 100644 src/Http/Payload/CreateMandatePayload.php create mode 100644 src/Http/Payload/CreatePaymentCapturePayload.php create mode 100644 src/Http/Payload/CreatePaymentLinkPayload.php create mode 100644 src/Http/Payload/CreateProfilePayload.php create mode 100644 src/Http/Payload/CreateSubscriptionPayload.php create mode 100644 src/Http/Payload/RequestApplePayPaymentSessionPayload.php create mode 100644 src/Http/Payload/UpdatePaymentLinkPayload.php create mode 100644 src/Http/Payload/UpdatePaymentRoutePayload.php create mode 100644 src/Http/Payload/UpdateProfilePayload.php create mode 100644 src/Http/Payload/UpdateSubscriptionPayload.php create mode 100644 src/Http/PendingRequest/AddTestmodeIfEnabled.php create mode 100644 src/Http/PendingRequest/RemoveTestmodeFromApiAuthenticatedRequests.php delete mode 100644 src/Http/PendingRequest/ValidateProperties.php create mode 100644 src/Http/Query/GetAllMethodsQuery.php create mode 100644 src/Http/Query/GetAllPaginatedSubscriptionsQuery.php create mode 100644 src/Http/Query/GetEnabledMethodsQuery.php create mode 100644 src/Http/Query/GetPaginatedCustomerPaymentsQuery.php create mode 100644 src/Http/Query/GetPaginatedInvoiceQuery.php create mode 100644 src/Http/Query/GetPaginatedPaymentCapturesQuery.php create mode 100644 src/Http/Query/GetPaginatedPaymentChargebacksQuery.php create mode 100644 src/Http/Query/GetPaginatedRefundsQuery.php create mode 100644 src/Http/Query/GetPaginatedSettlementCapturesQuery.php create mode 100644 src/Http/Query/GetPaginatedSettlementChargebacksQuery.php create mode 100644 src/Http/Query/GetPaginatedSettlementRefundsQuery.php create mode 100644 src/Http/Query/GetPaginatedSettlementsQuery.php create mode 100644 src/Http/Query/GetPaymentCaptureQuery.php create mode 100644 src/Http/Query/GetPaymentChargebackQuery.php create mode 100644 src/Http/Query/GetPaymentMethodQuery.php create mode 100644 src/Http/Requests/ApplePayPaymentSessionRequest.php create mode 100644 src/Http/Requests/CancelSubscriptionRequest.php create mode 100644 src/Http/Requests/CreateCustomerPaymentRequest.php create mode 100644 src/Http/Requests/CreateMandateRequest.php create mode 100644 src/Http/Requests/CreatePaymentCaptureRequest.php create mode 100644 src/Http/Requests/CreatePaymentLinkRequest.php create mode 100644 src/Http/Requests/CreateProfileRequest.php create mode 100644 src/Http/Requests/CreateSubscriptionRequest.php create mode 100644 src/Http/Requests/DeletePaymentLinkRequest.php create mode 100644 src/Http/Requests/DeleteProfileRequest.php create mode 100644 src/Http/Requests/DisableMethodIssuerRequest.php delete mode 100644 src/Http/Requests/DynamicDeleteRequest.php delete mode 100644 src/Http/Requests/DynamicPatchRequest.php delete mode 100644 src/Http/Requests/DynamicPostRequest.php create mode 100644 src/Http/Requests/EnableMethodIssuerRequest.php create mode 100644 src/Http/Requests/GetAllMethodsRequest.php create mode 100644 src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php create mode 100644 src/Http/Requests/GetEnabledMethodsRequest.php create mode 100644 src/Http/Requests/GetInvoiceRequest.php create mode 100644 src/Http/Requests/GetMandateRequest.php create mode 100644 src/Http/Requests/GetOnboardingRequest.php create mode 100644 src/Http/Requests/GetOrganizationPartnerStatusRequest.php create mode 100644 src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php create mode 100644 src/Http/Requests/GetPaginatedInvoiceRequest.php create mode 100644 src/Http/Requests/GetPaginatedMandateRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentCapturesRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php create mode 100644 src/Http/Requests/GetPaginatedPaymentLinksRequest.php create mode 100644 src/Http/Requests/GetPaginatedProfilesRequest.php create mode 100644 src/Http/Requests/GetPaginatedRefundsRequest.php create mode 100644 src/Http/Requests/GetPaginatedSettlementCapturesRequest.php create mode 100644 src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php create mode 100644 src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php create mode 100644 src/Http/Requests/GetPaginatedSettlementRefundsRequest.php create mode 100644 src/Http/Requests/GetPaginatedSettlementsRequest.php create mode 100644 src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php create mode 100644 src/Http/Requests/GetPaginatedSubscriptionsRequest.php create mode 100644 src/Http/Requests/GetPaginatedTerminalsRequest.php create mode 100644 src/Http/Requests/GetPaymentCaptureRequest.php create mode 100644 src/Http/Requests/GetPaymentChargebackRequest.php create mode 100644 src/Http/Requests/GetPaymentLinkRequest.php create mode 100644 src/Http/Requests/GetPaymentMethodRequest.php create mode 100644 src/Http/Requests/GetPermissionRequest.php create mode 100644 src/Http/Requests/GetProfileRequest.php create mode 100644 src/Http/Requests/GetSettlementRequest.php create mode 100644 src/Http/Requests/GetSubscriptionRequest.php create mode 100644 src/Http/Requests/GetTerminalRequest.php create mode 100644 src/Http/Requests/ListPermissionsRequest.php create mode 100644 src/Http/Requests/ResourceHydratableRequest.php create mode 100644 src/Http/Requests/RevokeMandateRequest.php delete mode 100644 src/Http/Requests/SortablePaginatedRequest.php create mode 100644 src/Http/Requests/UpdatePaymentLinkRequest.php create mode 100644 src/Http/Requests/UpdatePaymentRouteRequest.php create mode 100644 src/Http/Requests/UpdateProfileRequest.php create mode 100644 src/Http/Requests/UpdateSubscriptionRequest.php delete mode 100644 src/Resources/Order.php delete mode 100644 src/Resources/OrderCollection.php delete mode 100644 src/Resources/OrderLine.php delete mode 100644 src/Resources/Shipment.php delete mode 100644 src/Rules/Id.php delete mode 100644 src/Rules/Included.php delete mode 100644 src/Rules/Matches.php delete mode 100644 src/Rules/Max.php delete mode 100644 src/Rules/Min.php create mode 100644 src/Traits/GetAllConstants.php delete mode 100644 src/Traits/HasRules.php create mode 100644 src/Types/BusinessCategory.php create mode 100644 src/Types/MethodQuery.php create mode 100644 src/Types/OrderLineCategory.php delete mode 100644 src/Types/OrderStatus.php rename src/Types/{PaymentRefundQuery.php => PaymentIncludesQuery.php} (83%) delete mode 100644 tests/Helpers/ValidatorTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrderEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrderLineEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ShipmentEndpointTest.php delete mode 100644 tests/Resources/OrderLineTest.php delete mode 100644 tests/Resources/OrderTest.php delete mode 100644 tests/Rules/IdTest.php delete mode 100644 tests/Rules/IncludedTest.php delete mode 100644 tests/Rules/MatchesTest.php delete mode 100644 tests/Rules/MaxTest.php delete mode 100644 tests/Rules/MinTest.php diff --git a/.github/workflows/fix-codestyle.yml b/.github/workflows/fix-codestyle.yml new file mode 100644 index 000000000..367de127c --- /dev/null +++ b/.github/workflows/fix-codestyle.yml @@ -0,0 +1,33 @@ +name: Fix Code Style + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.3] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: json, dom, curl, libxml, mbstring + coverage: none + + - name: Install Pint + run: composer global require laravel/pint + + - name: Run Pint + run: pint + + - name: Commit linted files + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Fixes coding style" diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index 76ac93480..000000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check & fix styling - -on: [push] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php-cs-fixer.dist.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Fix styling diff --git a/README.md b/README.md index b0e657dea..97abdfb54 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

              +****

              diff --git a/UPGRADING.md b/UPGRADING.md index 0fb0286b4..57d09c1a2 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -23,23 +23,94 @@ This change should not have any impact on your code, but if you have a type hint - `Mollie\Api\Resources\OrganizationCollection` - `Mollie\Api\Resources\RouteCollection` - ### Removed deprecations The following was removed due to a deprecation - `Mollie\Api\Types\OrderStatus::REFUNDED` - `Mollie\Api\Types\OrderLineStatus::REFUNDED` +- all Orders related endpoints + - properties starting with `orders` prefix or related to any `Order*Endpoint` + - `orderPayments` + - `orderRefunds` + - `orderLines` + - `orderPayments` + - Shipments endpoint (all properties prefixed with `shipments` / `Shipment*Endpoint`) + +### Removed non-valid method params +**Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` + +**Mollie\Api\EndpointCollection\InvoiceEndpointCollection** +- `get()` removed second argument `$parameters` + +**Mollie\Api\EndpointCollection\MandateEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` -### Standardisation of function names -Accross the codebase we have had inconsistent namings like `listFor()` as well as `pageFor()` and `page()`. Those have been standardized. The following method names were changed. +**Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection** +- `createFor()` and `createForId()` removed third argument `$filters` -**Mollie\Api\Endpoints\BalanceTransactionEndpointCollection** -- `balanceTransactions->listFor()` into `balanceTransactions->page()` +### Removed methods +**Mollie\Api\EndpointCollection\InvoiceEndpointCollection** +- `all()` was removed -> use `page()` instead + +### change of function names +Accross the codebase we have had inconsistent namings like `listFor()` as well as `pageFor()` and `page()`. Those have been standardized. Endpoints that return a paginated response use the `page*()` naming while non-paginated endpoints use `list*()`. The following method names were changed. + +**Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection** +- `balanceTransactions->listFor()` into `balanceTransactions->pageFor()` - `balanceTransactions->listForId()` into `balanceTransactions->pageForId()` -**Mollie\Api\Endpoints\PaymentRefundEndpointCollection** +**Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection** +- `customerPayments->listFor()` into `customerPayments->pageFor()` +- `customerPayments->listForId()` into `customerPayments->pageForId()` + +**Mollie\Api\EndpointCollection\MandateEndpointCollection** +- `mandates->listFor()` into `mandates->pageFor()` +- `mandates->listForId()` into `mandates->pageForId()` + +**Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection** - `paymentRefunds->listFor()` into `paymentRefunds->pageFor()` - `paymentRefunds->listForId()` into `paymentRefunds->pageForId()` +**Mollie\Api\EndpointCollection\MethodEndpointCollection** +- `methods->allAvailable()` has been renamed into `methods->all()` now returns all available methods (both enabled and disabled) - previously returned only all enabled methods +- former `methods->all()` has been renamed to `methods->allEnabled()` +- `methods->allActive()` is deprecated + +The reasoning behind this change is to make the method names more intuitive: +- `all()` returns ALL methods (both enabled and disabled) +- `allEnabled()` returns only the enabled methods (previously called `allActive()`) +- The `allActive()` method is deprecated and will be removed in v4 + +**Mollie\Api\EndpointCollection\OnboardingEndpointCollection** +- `get()` was changed into `status()` +- depricated `submit()` and `create()` were removed -> use `ClientLinkEndpointCollection@create()` instead + +**Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection** +- `paymentCaptures->listFor()` into `paymentCaptures->pageFor()` +- `paymentCaptures->listForId()` into `paymentCaptures->pageForId()` + +**Mollie\Api\EndpointCollection\PaymentChargebackEndpointCollection** +- `listFor()` into `pageFor()` +- `listForId()` into `pageForId()` + +**Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection** +- `pageFor(Payment $payment, array $parameters = [])` changed to `pageFor(Payment $payment, ?string $from = null, ?int $limit = null, array $filters = [])` +- `pageForId(string $paymentId, array $parameters = [])` changed to `pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = [])` + +**Mollie\Api\EndpointCollection\SubscriptionEndpointCollection** +- `listFor` changed to `pageFor` +- `listForId` changed to `pageForId` +- `page` which previously returned all subscriptions, was renamed into `allFor` +- `allForId` and `iteratorForAll` were added to return all subscriptions + +### Renamed methods +**Mollie\Api\EndpointCollection\PermissionEndpointCollection** +- `all()` was renamed to `list()` to maintain consistency with other non-paginated endpoints + +### Removed non-valid method params +**Mollie\Api\EndpointCollection\PermissionEndpointCollection** +- `get()` second argument changed from `array $parameters` to `array|bool $testmode` to match API documentation + # Changelog ### Type cast embeded Resources In previous versions resources requested via `embed` param on requests like [get-payment](https://docs.mollie.com/reference/get-payment) were not casted into their respective collection or resource classes. Starting with this version all embeded resources are typecasted. @@ -167,3 +238,35 @@ With this you get a `Response` and can also inspect its status, body or any othe ## Some Context... ..on how the new request cycle works Screenshot 2024-09-09 at 11 03 17 + +### Added contractId parameter for Method Issuers +The `enable()` method on the `MethodIssuerEndpointCollection` now supports an optional `contractId` parameter when enabling voucher issuers. This parameter can be used when an intermediary party (contractor) is involved([1](https://docs.mollie.com/reference/enable-method-issuer)). + +```php +// Enable a method issuer with a contract ID +$issuer = $mollie->methodIssuers->enable( + profileId: 'pfl_...', + methodId: 'voucher', + issuerId: 'issuer_id', + contractId: 'contract_123' // Optional parameter +); +``` + +The contract ID can be updated as long as it hasn't been approved yet by repeating the API call with a different contract ID. + +### Added optional testmode parameter +The following methods now accept an optional `testmode` parameter: + +**Mollie\Api\EndpointCollection\PaymentLinkEndpointCollection** +- `get(string $paymentLinkId, ?bool $testmode = null)` +- `update(string $paymentLinkId, $payload = [], ?bool $testmode = null)` +- `delete(string $paymentLinkId, ?bool $testmode = null)` + +This parameter can be used when working with organization-level credentials such as OAuth access tokens to specify whether the operation should be performed in test mode. For API key credentials, this parameter can be omitted as the mode is determined by the key type. + +```php +// Example with testmode parameter +$paymentLink = $mollie->paymentLinks->get('pl_...', testmode: true); +$paymentLink = $mollie->paymentLinks->update('pl_...', ['description' => 'Updated'], testmode: true); +$mollie->paymentLinks->delete('pl_...', testmode: true); +``` diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index bb7332b9c..ba2643663 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -9,7 +9,7 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Capture parameters: @@ -19,14 +19,14 @@ */ $capture = $mollie ->paymentCaptures->createForId('tr_WDqYK6vllg', [ - "amount" => [ - "currency" => "EUR", - "value" => "5.00", + 'amount' => [ + 'currency' => 'EUR', + 'value' => '5.00', ], - "description" => "Order #12345", + 'description' => 'Order #12345', ]); - echo "

              New capture created " . htmlspecialchars($capture->id) . " (" . htmlspecialchars($capture->description) . ").

              "; + echo '

              New capture created '.htmlspecialchars($capture->id).' ('.htmlspecialchars($capture->description).').

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/captures/get-capture.php b/examples/captures/get-capture.php index 77b658d7c..8a1dc15a7 100644 --- a/examples/captures/get-capture.php +++ b/examples/captures/get-capture.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve a capture with ID 'cpt_4qqhO89gsT' for payment with @@ -19,9 +19,9 @@ $payment = $mollie->payments->get('tr_WDqYK6vllg'); $capture = $payment->getCapture('cpt_4qqhO89gsT'); - $amount = $capture->amount->currency . ' ' . $capture->amount->value; + $amount = $capture->amount->currency.' '.$capture->amount->value; - echo 'Captured ' . $amount; + echo 'Captured '.$amount; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/captures/list-captures.php b/examples/captures/list-captures.php index 8567db76d..c7caa73d7 100644 --- a/examples/captures/list-captures.php +++ b/examples/captures/list-captures.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * List captures for payment with ID 'tr_WDqYK6vllg'. @@ -19,9 +19,9 @@ $captures = $payment->captures(); foreach ($captures as $capture) { - $amount = $capture->amount->currency . ' ' . $capture->amount->value; - echo 'Captured ' . $amount . ' for payment ' . $payment->id; + $amount = $capture->amount->currency.' '.$capture->amount->value; + echo 'Captured '.$amount.' for payment '.$payment->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index 789a90fe5..cb9098f52 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -7,12 +7,12 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -22,21 +22,21 @@ * See: https://docs.mollie.com/reference/v2/client-links-api/create-client-link */ $clientLink = $mollie->clientLinks->create([ - "owner" => [ - "email" => "foo@test.com", - "givenName" => "foo", - "familyName" => "bar", - "locale" => "nl_NL", + 'owner' => [ + 'email' => 'foo@test.com', + 'givenName' => 'foo', + 'familyName' => 'bar', + 'locale' => 'nl_NL', ], - "name" => "Foo Company", - "address" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", + 'name' => 'Foo Company', + 'address' => [ + 'streetAndNumber' => 'Keizersgracht 313', + 'postalCode' => '1016 EE', + 'city' => 'Amsterdam', + 'country' => 'nl', ], - "registrationNumber" => "30204462", - "vatNumber" => "NL123456789B01", + 'registrationNumber' => '30204462', + 'vatNumber' => 'NL123456789B01', ]); /** @@ -46,7 +46,7 @@ * * For more info see: https://docs.mollie.com/reference/oauth2/authorize#parameters */ - $redirectUrl = $clientLink->getRedirectUrl("app_j9Pakf56Ajta6Y65AkdTtAv", "decafbad", "force", [ + $redirectUrl = $clientLink->getRedirectUrl('app_j9Pakf56Ajta6Y65AkdTtAv', 'decafbad', 'force', [ 'onboarding.read', 'onboarding.write', ]); @@ -55,7 +55,7 @@ * Send the customer off to finalize the organization creation. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $redirectUrl, true, 303); + header('Location: '.$redirectUrl, true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index 05d340415..1acf8178d 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the last created customer for this example. @@ -24,7 +24,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /** @@ -33,19 +33,19 @@ * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ $payment = $customer->createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "description" => "First payment - Order #{$orderId}", - "redirectUrl" => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "First payment - Order #{$orderId}", + 'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], // Flag this payment as a first payment to allow recurring payments later. - "sequenceType" => \Mollie\Api\Types\SequenceType::FIRST, + 'sequenceType' => \Mollie\Api\Types\SequenceType::FIRST, ]); /* @@ -60,7 +60,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-payment.php b/examples/customers/create-customer-payment.php index f02aab07f..27260603e 100644 --- a/examples/customers/create-customer-payment.php +++ b/examples/customers/create-customer-payment.php @@ -7,13 +7,13 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the last created customer for this example. * If no customers are created yet, run create-customer example. */ - $customer = $mollie->customers->collect(null, 1)[0]; + $customer = $mollie->customers->page(null, 1)[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute @@ -24,7 +24,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /** @@ -33,15 +33,15 @@ * @see https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ $payment = $customer->createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "description" => "Order #{$orderId}", - "redirectUrl" => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "Order #{$orderId}", + 'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], ]); @@ -54,7 +54,7 @@ * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-recurring-payment.php b/examples/customers/create-customer-recurring-payment.php index 812026b00..9276513de 100644 --- a/examples/customers/create-customer-recurring-payment.php +++ b/examples/customers/create-customer-recurring-payment.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the last created customer for this example. @@ -23,7 +23,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /** @@ -32,18 +32,18 @@ * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ $payment = $customer->createPayment([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "description" => "On-demand payment - Order #{$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}/payments/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "On-demand payment - Order #{$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], // Flag this payment as a recurring payment. - "sequenceType" => \Mollie\Api\Types\SequenceType::RECURRING, + 'sequenceType' => \Mollie\Api\Types\SequenceType::RECURRING, ]); /* @@ -55,8 +55,8 @@ * The payment will be either pending or paid immediately. The customer * does not have to perform any payment steps. */ - echo "

              Selected mandate is '" . htmlspecialchars($payment->mandateId) . "' (" . htmlspecialchars($payment->method) . ").

              \n"; - echo "

              The payment status is '" . htmlspecialchars($payment->status) . "'.

              \n"; + echo "

              Selected mandate is '".htmlspecialchars($payment->mandateId)."' (".htmlspecialchars($payment->method).").

              \n"; + echo "

              The payment status is '".htmlspecialchars($payment->status)."'.

              \n"; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer.php b/examples/customers/create-customer.php index 3608ab9cb..59382af12 100644 --- a/examples/customers/create-customer.php +++ b/examples/customers/create-customer.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /** * Customer creation parameters. @@ -15,13 +15,13 @@ * @See https://docs.mollie.com/reference/v2/customers-api/create-customer */ $customer = $mollie->customers->create([ - "name" => "Luke Skywalker", - "email" => "luke@example.org", - "metadata" => [ - "isJedi" => true, + 'name' => 'Luke Skywalker', + 'email' => 'luke@example.org', + 'metadata' => [ + 'isJedi' => true, ], ]); - echo "

              New customer created " . htmlspecialchars($customer->id) . " (" . htmlspecialchars($customer->name) . ").

              "; + echo '

              New customer created '.htmlspecialchars($customer->id).' ('.htmlspecialchars($customer->name).').

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/delete-customer.php b/examples/customers/delete-customer.php index 188e92640..2f267f000 100644 --- a/examples/customers/delete-customer.php +++ b/examples/customers/delete-customer.php @@ -7,10 +7,10 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; - $mollie->customers->delete("cst_fE3F6nvX"); - echo "

              Customer deleted!

              "; + $mollie->customers->delete('cst_fE3F6nvX'); + echo '

              Customer deleted!

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/list-customer-payments.php b/examples/customers/list-customer-payments.php index 9325f56e0..a4b69e22c 100644 --- a/examples/customers/list-customer-payments.php +++ b/examples/customers/list-customer-payments.php @@ -9,12 +9,12 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; /* @@ -28,30 +28,30 @@ */ $payments = $customer->payments(); - echo "
                "; + echo '
                  '; foreach ($payments as $payment) { - echo "
                • "; - echo "" . htmlspecialchars($payment->id) . "
                  "; - echo htmlspecialchars($payment->description) . "
                  "; - echo htmlspecialchars($payment->amount->currency) . " " . htmlspecialchars($payment->amount->value) . "
                  "; + echo '
                • '; + echo "".htmlspecialchars($payment->id).'
                  '; + echo htmlspecialchars($payment->description).'
                  '; + echo htmlspecialchars($payment->amount->currency).' '.htmlspecialchars($payment->amount->value).'
                  '; - echo "Status: " . htmlspecialchars($payment->status) . "
                  "; + echo 'Status: '.htmlspecialchars($payment->status).'
                  '; if ($payment->hasRefunds()) { - echo "Payment has been (partially) refunded.
                  "; + echo 'Payment has been (partially) refunded.
                  '; } if ($payment->hasChargebacks()) { - echo "Payment has been charged back.
                  "; + echo 'Payment has been charged back.
                  '; } if ($payment->canBeRefunded() && $payment->amountRemaining->currency === 'EUR' && $payment->amountRemaining->value >= '2.00') { - echo " (id) . "\">refund)"; + echo " (id).'">refund)'; } - echo "
                • "; + echo ''; } - echo "
                "; + echo '
              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/update-customer.php b/examples/customers/update-customer.php index 49984e362..1abef69cc 100644 --- a/examples/customers/update-customer.php +++ b/examples/customers/update-customer.php @@ -7,25 +7,25 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve an existing customer by his customerId */ - $customer = $mollie->customers->get("cst_cUe8HjeBuz"); + $customer = $mollie->customers->get('cst_cUe8HjeBuz'); /** * Customer fields that can be updated. * * @See https://docs.mollie.com/reference/v2/customers-api/update-customer */ - $customer->name = "Luke Sky"; - $customer->email = "luke@example.org"; - $customer->locale = "en_US"; + $customer->name = 'Luke Sky'; + $customer->email = 'luke@example.org'; + $customer->locale = 'en_US'; $customer->metadata->isJedi = true; $customer->update(); - echo "

              Customer updated: " . htmlspecialchars($customer->name) . "

              "; + echo '

              Customer updated: '.htmlspecialchars($customer->name).'

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/functions.php b/examples/functions.php index d97ef07e7..0d3104bb2 100644 --- a/examples/functions.php +++ b/examples/functions.php @@ -7,17 +7,17 @@ function database_read($orderId) { $orderId = intval($orderId); - $database = dirname(__FILE__) . "/database/order-{$orderId}.txt"; + $database = dirname(__FILE__)."/database/order-{$orderId}.txt"; $status = @file_get_contents($database); - return $status ? $status : "unknown order"; + return $status ? $status : 'unknown order'; } function database_write($orderId, $status) { $orderId = intval($orderId); - $database = dirname(__FILE__) . "/database/order-{$orderId}.txt"; + $database = dirname(__FILE__)."/database/order-{$orderId}.txt"; file_put_contents($database, $status); } diff --git a/examples/initialize.php b/examples/initialize.php index 8678f93f1..5af347b57 100644 --- a/examples/initialize.php +++ b/examples/initialize.php @@ -6,13 +6,13 @@ ini_set('display_startup_errors', '1'); error_reporting(E_ALL); -require_once __DIR__ . "/../vendor/autoload.php"; -require_once __DIR__ . "/functions.php"; +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/functions.php'; /* * Initialize the Mollie API library with your API key. * * See: https://www.mollie.com/dashboard/developers/api-keys */ -$mollie = new \Mollie\Api\MollieApiClient(); -$mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); +$mollie = new \Mollie\Api\MollieApiClient; +$mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); diff --git a/examples/initialize_with_oauth.php b/examples/initialize_with_oauth.php index a12ef401a..669175c46 100644 --- a/examples/initialize_with_oauth.php +++ b/examples/initialize_with_oauth.php @@ -7,13 +7,13 @@ ini_set('display_startup_errors', '1'); error_reporting(E_ALL); -require_once __DIR__ . "/../vendor/autoload.php"; -require_once __DIR__ . "/functions.php"; +require_once __DIR__.'/../vendor/autoload.php'; +require_once __DIR__.'/functions.php'; /* * Initialize the Mollie API library with OAuth. * * See: https://docs.mollie.com/oauth/overview */ -$mollie = new \Mollie\Api\MollieApiClient(); -$mollie->setAccessToken("access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ"); +$mollie = new \Mollie\Api\MollieApiClient; +$mollie->setAccessToken('access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ'); diff --git a/examples/invoices/list-invoices.php b/examples/invoices/list-invoices.php index 53b539ebb..58dbf09a3 100644 --- a/examples/invoices/list-invoices.php +++ b/examples/invoices/list-invoices.php @@ -7,30 +7,30 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /* * Get all the activated methods for this API key. */ $invoices = $mollie->invoices->all(); foreach ($invoices as $invoice) { - echo '
            • Invoice ' . htmlspecialchars($invoice->reference) . ': (' . htmlspecialchars($invoice->issuedAt) . ')'; - echo '
              Status: ' . $invoice->status; + echo '
            • Invoice '.htmlspecialchars($invoice->reference).': ('.htmlspecialchars($invoice->issuedAt).')'; + echo '
              Status: '.$invoice->status; echo ''; foreach ($invoice->lines as $line) { echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; } - echo ''; + echo ''; echo '
              PeriodDescriptionCountVAT PercentageAmount
              ' . htmlspecialchars($line->period) . '' . htmlspecialchars($line->description) . '' . htmlspecialchars($line->count) . '' . htmlspecialchars($line->vatPercentage) . '' . htmlspecialchars($line->amount->currency . " " . $line->amount->value) . ''.htmlspecialchars($line->period).''.htmlspecialchars($line->description).''.htmlspecialchars($line->count).''.htmlspecialchars($line->vatPercentage).''.htmlspecialchars($line->amount->currency.' '.$line->amount->value).'
              Gross Total' . htmlspecialchars($invoice->grossAmount->value . " " . $invoice->grossAmount->currency) . '
              Gross Total'.htmlspecialchars($invoice->grossAmount->value.' '.$invoice->grossAmount->currency).'
              '; - echo 'Click here to open PDF'; + echo 'Click here to open PDF'; echo '
            • '; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/mandates/create-mandate.php b/examples/mandates/create-mandate.php index 316ba47ac..ca04fbc33 100644 --- a/examples/mandates/create-mandate.php +++ b/examples/mandates/create-mandate.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the last created customer for this example. @@ -19,12 +19,12 @@ * Create a SEPA Direct Debit mandate for the customer */ $mandate = $customer->createMandate([ - "method" => \Mollie\Api\Types\MandateMethod::DIRECTDEBIT, - "consumerAccount" => 'NL34ABNA0243341423', - "consumerName" => 'B. A. Example', + 'method' => \Mollie\Api\Types\MandateMethod::DIRECTDEBIT, + 'consumerAccount' => 'NL34ABNA0243341423', + 'consumerName' => 'B. A. Example', ]); - echo "

              Mandate created with id " . $mandate->id . " for customer " . $customer->name . "

              "; + echo '

              Mandate created with id '.$mandate->id.' for customer '.$customer->name.'

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/mandates/list-mandates.php b/examples/mandates/list-mandates.php index 7d0161643..af252f496 100644 --- a/examples/mandates/list-mandates.php +++ b/examples/mandates/list-mandates.php @@ -7,21 +7,21 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve an existing customer by his customerId */ - $customer = $mollie->customers->get("cst_cUa8HjKBus"); + $customer = $mollie->customers->get('cst_cUa8HjKBus'); /* * List the mandates of this customer */ - echo "
                "; + echo '
                  '; foreach ($customer->mandates() as $mandate) { - echo "
                • " . htmlspecialchars($mandate->id) . " - " . htmlspecialchars($mandate->method) . ": " . htmlspecialchars($mandate->status) . "
                • "; + echo '
                • '.htmlspecialchars($mandate->id).' - '.htmlspecialchars($mandate->method).': '.htmlspecialchars($mandate->status).'
                • '; } - echo "
                "; + echo '
              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/mandates/revoke-mandate.php b/examples/mandates/revoke-mandate.php index ba7093352..6a1381f80 100644 --- a/examples/mandates/revoke-mandate.php +++ b/examples/mandates/revoke-mandate.php @@ -7,24 +7,24 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve an existing customer by his customerId */ - $customer = $mollie->customers->get("cst_cUa8HjKBus"); + $customer = $mollie->customers->get('cst_cUa8HjKBus'); /* * Retrieve an existing mandate by his mandateId */ - $mandate = $customer->getMandate("mdt_pa3s7rGnrC"); + $mandate = $customer->getMandate('mdt_pa3s7rGnrC'); /* * Revoke the mandate */ $mandate->revoke(); - echo "

              Mandate has been successfully revoked.

              "; + echo '

              Mandate has been successfully revoked.

              '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/orders/cancel-order-lines.php b/examples/orders/cancel-order-lines.php deleted file mode 100644 index f0f827f7c..000000000 --- a/examples/orders/cancel-order-lines.php +++ /dev/null @@ -1,44 +0,0 @@ -orders->get($orderId); - $line = $order->lines()->get($lineId); - if ($line && $line->isCancelable) { - $order->cancelLines([ - 'lines' => [ - [ - 'id' => $lineId, - 'quantity' => 1, // optional parameter - ], - ], - ]); - - $updatedOrder = $mollie->orders->get($orderId); - - echo 'Your order ' . $order->id . ' was updated:'; - foreach ($order->lines as $line) { - echo $line->description . '. Status: ' . $line->status . '.'; - } - } else { - echo "Unable to cancel line " . $lineId . " for your order " . $orderId . "."; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/cancel-order.php b/examples/orders/cancel-order.php deleted file mode 100644 index 4c4143594..000000000 --- a/examples/orders/cancel-order.php +++ /dev/null @@ -1,26 +0,0 @@ -orders->get("ord_pbjz8x"); - if ($order->isCancelable) { - $canceledOrder = $order->cancel(); - echo "Your order " . $order->id . " has been canceled."; - } else { - echo "Unable to cancel your order " . $order->id . "."; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/create-order.php b/examples/orders/create-order.php deleted file mode 100644 index 9dc431899..000000000 --- a/examples/orders/create-order.php +++ /dev/null @@ -1,118 +0,0 @@ -orders->create([ - "amount" => [ - "value" => "1027.99", - "currency" => "EUR", - ], - "billingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "shippingAddress" => [ - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", - ], - "metadata" => [ - "order_id" => $orderId, - ], - "consumerDateOfBirth" => "1958-01-31", - "locale" => "en_US", - "orderNumber" => strval($orderId), - "redirectUrl" => "{$protocol}://{$hostname}{$path}/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}{$path}/webhook.php", - "method" => "ideal", - "lines" => [ - [ - "sku" => "5702016116977", - "name" => "LEGO 42083 Bugatti Chiron", - "productUrl" => "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - "quantity" => 2, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "399.00", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "698.00", - ], - "discountAmount" => [ - "currency" => "EUR", - "value" => "100.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "121.14", - ], - ], - [ - "type" => "digital", - "sku" => "5702015594028", - "name" => "LEGO 42056 Porsche 911 GT3 RS", - "productUrl" => "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl" => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', - "quantity" => 1, - "vatRate" => "21.00", - "unitPrice" => [ - "currency" => "EUR", - "value" => "329.99", - ], - "totalAmount" => [ - "currency" => "EUR", - "value" => "329.99", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "57.27", - ], - ], - ], - ]); - - /* - * Send the customer off to complete the order payment. - * This request should always be a GET, thus we enforce 303 http response code - */ - header("Location: " . $order->getCheckoutUrl(), true, 303); -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/list-methods.php b/examples/orders/list-methods.php deleted file mode 100644 index 5289b160c..000000000 --- a/examples/orders/list-methods.php +++ /dev/null @@ -1,28 +0,0 @@ -methods->all(['resource' => 'orders']); - foreach ($methods as $method) { - echo '
              '; - echo ' '; - echo htmlspecialchars($method->description) . ' (' . htmlspecialchars($method->id) . ')'; - echo '
              '; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/list-orders.php b/examples/orders/list-orders.php deleted file mode 100644 index 01076935d..000000000 --- a/examples/orders/list-orders.php +++ /dev/null @@ -1,48 +0,0 @@ -'; - $latestOrders = $mollie->orders->collect(); - printOrders($latestOrders); - - $previousOrders = $latestOrders->next(); - printOrders($previousOrders); - echo '
            '; -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} - -function printOrders($orders) -{ - if (empty($orders)) { - return; - } - - foreach ($orders as $order) { - echo '
          • Order ' . htmlspecialchars($order->id) . ': (' . htmlspecialchars($order->createdAt) . ')'; - echo '
            Status: ' . htmlspecialchars($order->status); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
            Billed toShipped toTotal amount
            ' . htmlspecialchars($order->shippingAddress->givenName) . ' ' . htmlspecialchars($order->shippingAddress->familyName) . '' . htmlspecialchars($order->billingAddress->givenName) . ' ' . htmlspecialchars($order->billingAddress->familyName) . '' . htmlspecialchars($order->amount->currency) . str_replace('.', ',', htmlspecialchars($order->amount->value)) . '
            '; - echo 'Click here to pay'; - echo '
          • '; - } -} diff --git a/examples/orders/refund-order-completely.php b/examples/orders/refund-order-completely.php deleted file mode 100644 index 35e112f29..000000000 --- a/examples/orders/refund-order-completely.php +++ /dev/null @@ -1,25 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $refund = $order->refundAll(); - - echo 'Refund ' . $refund->id . ' was created for order ' . $order->id; - echo 'You will receive ' . $refund->amount->currency . $refund->amount->value; -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/refund-order-partially.php b/examples/orders/refund-order-partially.php deleted file mode 100644 index 5970de291..000000000 --- a/examples/orders/refund-order-partially.php +++ /dev/null @@ -1,33 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $refund = $order->refund([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - ], - "description" => "Required quantity not in stock, refunding one photo book.", - ]); - - echo 'Refund ' . $refund->id . ' was created for part of your order ' . $order->id; - echo 'You will receive ' . $refund->amount->currency . $refund->amount->value; -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/update-order-line.php b/examples/orders/update-order-line.php deleted file mode 100644 index 8456eb044..000000000 --- a/examples/orders/update-order-line.php +++ /dev/null @@ -1,44 +0,0 @@ -orders->get("ord_kEn1PlbGa"); - $line = $order->lines()->get('odl_1.uh5oen'); - - $line->name = "Update line name description"; - - $orderWithNewLineName = $line->update(); - - /* - * Send the customer off to complete the order payment. - * This request should always be a GET, thus we enforce 303 http response code - */ - header("Location: " . $orderWithNewLineName->getCheckoutUrl(), true, 303); -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/update-order-lines-multiple.php b/examples/orders/update-order-lines-multiple.php deleted file mode 100644 index cad794118..000000000 --- a/examples/orders/update-order-lines-multiple.php +++ /dev/null @@ -1,70 +0,0 @@ - \Mollie\Api\Types\OrderLineUpdateOperationType::ADD, - "data" => [ - "type" => \Mollie\Api\Types\OrderLineType::DIGITAL, - "name" => "Adding new orderline", - "quantity" => 2, - "sku" => "12345679", - "totalAmount" => [ - "currency" => "EUR", - "value" => "30.00", - ], - "unitPrice" => [ - "currency" => "EUR", - "value" => "15.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "0.00", - ], - "vatRate" => "0.00", - ], - ]; - $updateOrderLine = [ - "operation" => \Mollie\Api\Types\OrderLineUpdateOperationType::UPDATE, - "data" => [ - "id" => "odl_1.1l9vx0", - "name" => "New order line name", - ], - ]; - $cancelOrderLine = [ - "operation" => \Mollie\Api\Types\OrderLineUpdateOperationType::CANCEL, - "data" => [ - "id" => "odl_1.4hqjw6", - ], - ]; - - $operations = [ - $addOrderLine, - $updateOrderLine, - $cancelOrderLine, - ]; - - $order = $mollie->orderLines->updateMultiple('ord_pbjz8x', $operations); -} catch (\Mollie\Api\Exceptions\ApiException $e) { - /* - * When updating order lines for orders that used a pay after delivery method such as Klarna Pay Later, the - * supplier (Klarna) may decline the requested changes. This results in an error response from the Mollie API. - * The order initial remains intact without applying the requested changes. - */ - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/update-order.php b/examples/orders/update-order.php deleted file mode 100644 index f33e72658..000000000 --- a/examples/orders/update-order.php +++ /dev/null @@ -1,45 +0,0 @@ -orders->get("ord_kEn1PlbGa"); - $order->billingAddress->organizationName = "Mollie B.V."; - $order->billingAddress->streetAndNumber = "Keizersgracht 126"; - $order->billingAddress->city = "Amsterdam"; - $order->billingAddress->region = "Noord-Holland"; - $order->billingAddress->postalCode = "1234AB"; - $order->billingAddress->country = "NL"; - $order->billingAddress->title = "Dhr"; - $order->billingAddress->givenName = "Piet"; - $order->billingAddress->familyName = "Mondriaan"; - $order->billingAddress->email = "piet@mondriaan.com"; - $order->billingAddress->phone = "+31208202070"; - $order->update(); - - /* - * Send the customer off to complete the order payment. - * This request should always be a GET, thus we enforce 303 http response code - */ - header("Location: " . $order->getCheckoutUrl(), true, 303); -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/orders/webhook.php b/examples/orders/webhook.php deleted file mode 100644 index c2bd5ce07..000000000 --- a/examples/orders/webhook.php +++ /dev/null @@ -1,50 +0,0 @@ -orders->get($_POST["id"]); - $orderId = $order->metadata->order_id; - - /* - * Update the order in the database. - */ - database_write($orderId, $order->status); - - if ($order->isPaid() || $order->isAuthorized()) { - /* - * The order is paid or authorized - * At this point you'd probably want to start the process of delivering the product to the customer. - */ - } elseif ($order->isCanceled()) { - /* - * The order is canceled. - */ - } elseif ($order->isExpired()) { - /* - * The order is expired. - */ - } elseif ($order->isCompleted()) { - /* - * The order is completed. - */ - } elseif ($order->isPending()) { - /* - * The order is pending. - */ - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index 22ab89087..ab4160885 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -33,7 +33,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; $orderId = 'ord_8wmqcHMN4U'; @@ -42,7 +42,7 @@ while ($page->hasPrevious()) { foreach ($page as $order) { - echo($order->id); + echo $order->id; } $page = $page->previous(); @@ -51,8 +51,8 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) foreach ($mollie->orders->iterator(null, null, [], true) as $order) { - echo($order->id); + echo $order->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index e8066f1dd..2c859dc36 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -33,25 +33,23 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; - + require '../initialize.php'; // cursor paginating through all orders $page = $mollie->orders->collect(); while ($page->hasNext()) { foreach ($page as $order) { - echo($order->id); + echo $order->id; } $page = $page->next(); } - // using the iterator we can iterate over all orders directly foreach ($mollie->orders->iterator() as $order) { - echo($order->id); + echo $order->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payment-links/create-payment-link.php b/examples/payment-links/create-payment-link.php index a3f018929..672b47bb2 100644 --- a/examples/payment-links/create-payment-link.php +++ b/examples/payment-links/create-payment-link.php @@ -9,12 +9,12 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -24,19 +24,19 @@ * description Description of the payment. */ $paymentLink = $mollie->paymentLinks->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings ], - "description" => "Bicycle tires", - "webhookUrl" => "{$protocol}://{$hostname}{$path}/webhook.php", // optional + 'description' => 'Bicycle tires', + 'webhookUrl' => "{$protocol}://{$hostname}{$path}/webhook.php", // optional ]); /* * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $paymentLink->getCheckoutUrl(), true, 303); + header('Location: '.$paymentLink->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payment-links/list-payment-links.php b/examples/payment-links/list-payment-links.php index df7d3ce84..13e013ad2 100644 --- a/examples/payment-links/list-payment-links.php +++ b/examples/payment-links/list-payment-links.php @@ -9,12 +9,12 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -23,17 +23,17 @@ */ $paymentLinks = $mollie->paymentLinks->collect(); - echo "
              "; + echo '
                '; foreach ($paymentLinks as $paymentLink) { - echo "
              • "; - echo "" . htmlspecialchars($paymentLink->id) . "
                "; - echo htmlspecialchars($paymentLink->description) . "
                "; - echo htmlspecialchars($paymentLink->amount->currency) . " " . htmlspecialchars($paymentLink->amount->value) . "
                "; - echo "Link: " . htmlspecialchars($paymentLink->getCheckoutUrl()) . "
                "; + echo '
              • '; + echo "".htmlspecialchars($paymentLink->id).'
                '; + echo htmlspecialchars($paymentLink->description).'
                '; + echo htmlspecialchars($paymentLink->amount->currency).' '.htmlspecialchars($paymentLink->amount->value).'
                '; + echo 'Link: '.htmlspecialchars($paymentLink->getCheckoutUrl()).'
                '; - echo "
              • "; + echo ''; } - echo "
              "; + echo '
            '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payments/create-capturable-payment.php b/examples/payments/create-capturable-payment.php index 36c078c2b..558606bd4 100644 --- a/examples/payments/create-capturable-payment.php +++ b/examples/payments/create-capturable-payment.php @@ -9,7 +9,7 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Generate a unique order id for this example. It is important to include this unique attribute @@ -20,7 +20,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -35,18 +35,18 @@ * captureMode Capture mode "manual" to make sure the payment isn't captured automatically after creation */ $payment = $mollie->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings ], - "description" => "Order #{$orderId}", - "redirectUrl" => "{$protocol}://{$hostname}{$path}/return.php?order_id={$orderId}", - "webhookUrl" => "{$protocol}://{$hostname}{$path}/webhook.php", - "metadata" => [ - "order_id" => $orderId, + 'description' => "Order #{$orderId}", + 'redirectUrl' => "{$protocol}://{$hostname}{$path}/return.php?order_id={$orderId}", + 'webhookUrl' => "{$protocol}://{$hostname}{$path}/webhook.php", + 'metadata' => [ + 'order_id' => $orderId, ], - "captureMode" => 'manual', - "method" => "creditcard", + 'captureMode' => 'manual', + 'method' => 'creditcard', ]); /* @@ -58,7 +58,7 @@ * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payments/create-ideal-payment.php b/examples/payments/create-ideal-payment.php index 92328a7fe..372ac2e04 100644 --- a/examples/payments/create-ideal-payment.php +++ b/examples/payments/create-ideal-payment.php @@ -9,18 +9,18 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * First, let the customer pick the bank in a simple HTML form. This step is actually optional. */ - if ($_SERVER["REQUEST_METHOD"] != "POST") { - $method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]); + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + $method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ['include' => 'issuers']); echo '
            Select your bank:
            "; - echo "

            "; - echo 'Create a payment
            '; - echo 'Create an iDEAL payment
            '; - echo 'List payments
            '; - echo "

            "; + echo '

            '; + echo 'Create a payment
            '; + echo 'Create an iDEAL payment
            '; + echo 'List payments
            '; + echo '

            '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payments/return.php b/examples/payments/return.php index ec53f0bbc..1177f7ff4 100644 --- a/examples/payments/return.php +++ b/examples/payments/return.php @@ -10,17 +10,17 @@ * NOTE: The examples are using a text file as a database. * Please use a real database like MySQL in production code. */ -require_once "../functions.php"; +require_once '../functions.php'; -$status = database_read($_GET["order_id"]); +$status = database_read($_GET['order_id']); /* * The order status is normally updated by the webhook. * In case the webhook did not yet arrive, we can poll the API synchronously. */ -if ($status !== "paid") { - $payment = $mollie->payments->get($_GET["order_id"]); +if ($status !== 'paid') { + $payment = $mollie->payments->get($_GET['order_id']); $status = $payment->status; /* * Optionally, update the database here, or wait for the webhook to arrive. @@ -30,13 +30,13 @@ /* * Determine the url parts to these example files. */ -$protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; +$protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); -echo "

            Your payment status is '" . htmlspecialchars($status) . "'.

            "; -echo "

            "; -echo 'Create a payment
            '; -echo 'Create an iDEAL payment
            '; -echo 'List payments
            '; -echo "

            "; +echo "

            Your payment status is '".htmlspecialchars($status)."'.

            "; +echo '

            '; +echo 'Create a payment
            '; +echo 'Create an iDEAL payment
            '; +echo 'List payments
            '; +echo '

            '; diff --git a/examples/payments/update-payment.php b/examples/payments/update-payment.php index 8149d5a4c..c02344d09 100644 --- a/examples/payments/update-payment.php +++ b/examples/payments/update-payment.php @@ -9,7 +9,7 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Payment parameters: @@ -19,13 +19,12 @@ * metadata Custom metadata that is stored with the payment. */ - - $payment = $mollie->payments->get("tr_7UhSN1zuXS"); + $payment = $mollie->payments->get('tr_7UhSN1zuXS'); $newOrderId = 98765; - $payment->description = "Order #".$newOrderId; - $payment->redirectUrl = "https://example.org/webshop/order/98765/"; - $payment->webhookUrl = "https://example.org/webshop/payments/webhook/"; - $payment->metadata = ["order_id" => $newOrderId]; + $payment->description = 'Order #'.$newOrderId; + $payment->redirectUrl = 'https://example.org/webshop/order/98765/'; + $payment->webhookUrl = 'https://example.org/webshop/payments/webhook/'; + $payment->metadata = ['order_id' => $newOrderId]; $payment = $payment->update(); /* @@ -37,7 +36,7 @@ * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/payments/webhook.php b/examples/payments/webhook.php index ef907b763..56e8871a9 100644 --- a/examples/payments/webhook.php +++ b/examples/payments/webhook.php @@ -11,12 +11,12 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the payment's current state. */ - $payment = $mollie->payments->get($_POST["id"]); + $payment = $mollie->payments->get($_POST['id']); $orderId = $payment->metadata->order_id; /* @@ -61,5 +61,5 @@ */ } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/profiles/create-profile.php b/examples/profiles/create-profile.php index c06f87988..22f58b416 100644 --- a/examples/profiles/create-profile.php +++ b/examples/profiles/create-profile.php @@ -6,7 +6,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /** * Create the profile @@ -14,14 +14,14 @@ * @See https://docs.mollie.com/reference/v2/profiles-api/create-profile */ $profile = $mollie->profiles->create([ - "name" => "My website name", - "website" => "https://www.mywebsite.com", - "email" => "info@mywebsite.com", - "phone" => "+31208202070", - "businessCategory" => "MARKETPLACES", - "mode" => "live", + 'name' => 'My website name', + 'website' => 'https://www.mywebsite.com', + 'email' => 'info@mywebsite.com', + 'phone' => '+31208202070', + 'businessCategory' => 'MARKETPLACES', + 'mode' => 'live', ]); - echo "

            Profile created: " . htmlspecialchars($profile->name) . "

            "; + echo '

            Profile created: '.htmlspecialchars($profile->name).'

            '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "

            API call failed: " . htmlspecialchars($e->getMessage()) . "

            "; + echo '

            API call failed: '.htmlspecialchars($e->getMessage()).'

            '; } diff --git a/examples/profiles/delete-profile.php b/examples/profiles/delete-profile.php index 3ca675ea2..776ec1e25 100644 --- a/examples/profiles/delete-profile.php +++ b/examples/profiles/delete-profile.php @@ -6,15 +6,15 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /** * Delete a profile via the profileId * * @See https://docs.mollie.com/reference/v2/profiles-api/delete-profile */ - $profile = $mollie->profiles->delete("pfl_v9hTwCvYqw"); - echo "

            Profile deleted

            "; + $profile = $mollie->profiles->delete('pfl_v9hTwCvYqw'); + echo '

            Profile deleted

            '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "

            API call failed: " . htmlspecialchars($e->getMessage()) . "

            "; + echo '

            API call failed: '.htmlspecialchars($e->getMessage()).'

            '; } diff --git a/examples/profiles/list-profiles.php b/examples/profiles/list-profiles.php index 8323f0366..7534c6a9a 100644 --- a/examples/profiles/list-profiles.php +++ b/examples/profiles/list-profiles.php @@ -6,7 +6,7 @@ /* * Initialize the Mollie API library with your OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /* * Get the all the profiles for this account. @@ -14,11 +14,11 @@ $profiles = $mollie->profiles->collect(); foreach ($profiles as $profile) { echo '
            '; - echo htmlspecialchars($profile->name) . - ' - ' . htmlspecialchars($profile->website) . - ' (' . htmlspecialchars($profile->id) . ')'; + echo htmlspecialchars($profile->name). + ' - '.htmlspecialchars($profile->website). + ' ('.htmlspecialchars($profile->id).')'; echo '
            '; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/profiles/update-profile.php b/examples/profiles/update-profile.php index 69a384e17..afd8e840f 100644 --- a/examples/profiles/update-profile.php +++ b/examples/profiles/update-profile.php @@ -6,25 +6,25 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /* * Retrieve an existing profile by his profileId */ - $profile = $mollie->profiles->get("pfl_eA4MSz7Bvy"); + $profile = $mollie->profiles->get('pfl_eA4MSz7Bvy'); /** * Profile fields that can be updated. * * @See https://docs.mollie.com/reference/v2/profiles-api/update-profile */ - $profile->name = "Mollie B.V."; + $profile->name = 'Mollie B.V.'; $profile->website = 'www.mollie.com'; $profile->email = 'info@mollie.com'; $profile->phone = '0612345670'; - $profile->businessCategory = "MARKETPLACES"; + $profile->businessCategory = 'MARKETPLACES'; $profile->update(); - echo "

            Profile updated: " . htmlspecialchars($profile->name) . "

            "; + echo '

            Profile updated: '.htmlspecialchars($profile->name).'

            '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "

            API call failed: " . htmlspecialchars($e->getMessage()) . "

            "; + echo '

            API call failed: '.htmlspecialchars($e->getMessage()).'

            '; } diff --git a/examples/sessions/cancel-session.php b/examples/sessions/cancel-session.php index 2b679b546..bc1d152ca 100644 --- a/examples/sessions/cancel-session.php +++ b/examples/sessions/cancel-session.php @@ -7,16 +7,16 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Cancel the session with ID "sess_dfsklg13jO" * * See: https://docs.mollie.com/reference/v2/sessions-api/cancel-session */ - $session = $mollie->sessions->get("sess_dfsklg13jO"); + $session = $mollie->sessions->get('sess_dfsklg13jO'); $session->cancel(); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/sessions/create-session.php b/examples/sessions/create-session.php index 5f9f351ba..5618c17db 100644 --- a/examples/sessions/create-session.php +++ b/examples/sessions/create-session.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Generate a unique session id for this example. It is important to include this unique attribute @@ -18,7 +18,7 @@ /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -28,26 +28,26 @@ * See: https://docs.mollie.com/reference/v2/sessions-api/create-session */ $session = $mollie->sessions->create([ - "paymentData" => [ - "amount" => [ - "value" => "10.00", - "currency" => "EUR", + 'paymentData' => [ + 'amount' => [ + 'value' => '10.00', + 'currency' => 'EUR', ], - "description" => "Order #12345", + 'description' => 'Order #12345', ], - "method" => "paypal", - "methodDetails" => [ - "checkoutFlow" => "express", + 'method' => 'paypal', + 'methodDetails' => [ + 'checkoutFlow' => 'express', ], - "returnUrl" => "{$protocol}://{$hostname}{$path}/shippingSelection.php?order_id={$sessionId}", - "cancelUrl" => "{$protocol}://{$hostname}{$path}/cancel.php?order_id={$sessionId}", + 'returnUrl' => "{$protocol}://{$hostname}{$path}/shippingSelection.php?order_id={$sessionId}", + 'cancelUrl' => "{$protocol}://{$hostname}{$path}/cancel.php?order_id={$sessionId}", ]); /* * Send the customer off to complete the payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $session->getRedirectUrl(), true, 303); + header('Location: '.$session->getRedirectUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/sessions/list-sessions.php b/examples/sessions/list-sessions.php index 9a50b897c..9ba055898 100644 --- a/examples/sessions/list-sessions.php +++ b/examples/sessions/list-sessions.php @@ -3,12 +3,11 @@ * List sessions using the Mollie API. */ - try { /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * List the most recent sessions @@ -23,7 +22,7 @@ printSessions($previousSessions); echo '
          '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } function printSessions($sessions) @@ -33,16 +32,16 @@ function printSessions($sessions) } foreach ($sessions as $session) { - echo '
        • Session ' . htmlspecialchars($session->id) . ': (' . htmlspecialchars($session->failedAt) . ')'; - echo '
          Status: ' . htmlspecialchars($session->status); + echo '
        • Session '.htmlspecialchars($session->id).': ('.htmlspecialchars($session->failedAt).')'; + echo '
          Status: '.htmlspecialchars($session->status); echo ''; echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; echo ''; echo '
          Billed toShipped toTotal amount
          ' . htmlspecialchars($session->shippingAddress->givenName) . ' ' . htmlspecialchars($session->shippingAddress->familyName) . '' . htmlspecialchars($session->billingAddress->givenName) . ' ' . htmlspecialchars($session->billingAddress->familyName) . '' . htmlspecialchars($session->amount->currency) . str_replace('.', ',', htmlspecialchars($session->amount->value)) . ''.htmlspecialchars($session->shippingAddress->givenName).' '.htmlspecialchars($session->shippingAddress->familyName).''.htmlspecialchars($session->billingAddress->givenName).' '.htmlspecialchars($session->billingAddress->familyName).''.htmlspecialchars($session->amount->currency).str_replace('.', ',', htmlspecialchars($session->amount->value)).'
          '; - echo 'Click here to pay'; + echo 'Click here to pay'; echo '
        • '; } } diff --git a/examples/sessions/update-session.php b/examples/sessions/update-session.php index 7c489f454..3f0ea0f0e 100644 --- a/examples/sessions/update-session.php +++ b/examples/sessions/update-session.php @@ -9,27 +9,27 @@ * * See: https://www.mollie.com/dashboard/developers/api-keys */ - require "../initialize.php"; + require '../initialize.php'; - $session = $mollie->sessions->get("sess_dfsklg13jO"); - $session->billingAddress->organizationName = "Mollie B.V."; - $session->billingAddress->streetAndNumber = "Keizersgracht 126"; - $session->billingAddress->city = "Amsterdam"; - $session->billingAddress->region = "Noord-Holland"; - $session->billingAddress->postalCode = "1234AB"; - $session->billingAddress->country = "NL"; - $session->billingAddress->title = "Dhr"; - $session->billingAddress->givenName = "Piet"; - $session->billingAddress->familyName = "Mondriaan"; - $session->billingAddress->email = "piet@mondriaan.com"; - $session->billingAddress->phone = "+31208202070"; + $session = $mollie->sessions->get('sess_dfsklg13jO'); + $session->billingAddress->organizationName = 'Mollie B.V.'; + $session->billingAddress->streetAndNumber = 'Keizersgracht 126'; + $session->billingAddress->city = 'Amsterdam'; + $session->billingAddress->region = 'Noord-Holland'; + $session->billingAddress->postalCode = '1234AB'; + $session->billingAddress->country = 'NL'; + $session->billingAddress->title = 'Dhr'; + $session->billingAddress->givenName = 'Piet'; + $session->billingAddress->familyName = 'Mondriaan'; + $session->billingAddress->email = 'piet@mondriaan.com'; + $session->billingAddress->phone = '+31208202070'; $session->update(); /* * Send the customer off to complete the order payment. * This request should always be a GET, thus we enforce 303 http response code */ - header("Location: " . $session->getRedirectUrl(), true, 303); + header('Location: '.$session->getRedirectUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/settlements/list-settlements.php b/examples/settlements/list-settlements.php index 9938acd07..c5dd02e46 100644 --- a/examples/settlements/list-settlements.php +++ b/examples/settlements/list-settlements.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your OAuth access token. */ - require "../initialize_with_oauth.php"; + require '../initialize_with_oauth.php'; /* * Get the all the settlements for this account. @@ -15,7 +15,7 @@ $settlements = $mollie->settlements->collect(); echo '
            '; foreach ($settlements as $settlement) { - echo '
          • Settlement ' . htmlspecialchars($settlement->reference) . ': (' . htmlspecialchars($settlement->createdAt) . ')'; + echo '
          • Settlement '.htmlspecialchars($settlement->reference).': ('.htmlspecialchars($settlement->createdAt).')'; echo ''; // Convert from stdClass to array $settlement_periods = json_decode(json_encode($settlement->periods), true); @@ -23,31 +23,31 @@ foreach ($months as $month => $monthly_settlement) { foreach ($monthly_settlement['revenue'] as $revenue) { echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; } foreach ($monthly_settlement['costs'] as $revenue) { echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; } } } - echo ''; + echo ''; echo '
            MonthDescriptionCountNetVATGross
            ' . htmlspecialchars($year . '-' . $month) . '' . htmlspecialchars($revenue['description']) . '' . htmlspecialchars($revenue['count']) . ' x' . htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'] . " " . $revenue['amountNet']['currency'] : '-') . '' . htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'] . " " . $revenue['amountVat']['currency'] : '-') . '' . htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'] . " " . $revenue['amountGross']['currency'] : '-') . ''.htmlspecialchars($year.'-'.$month).''.htmlspecialchars($revenue['description']).''.htmlspecialchars($revenue['count']).' x'.htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'].' '.$revenue['amountNet']['currency'] : '-').''.htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'].' '.$revenue['amountVat']['currency'] : '-').''.htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'].' '.$revenue['amountGross']['currency'] : '-').'
            ' . htmlspecialchars($year . '-' . $month) . '' . htmlspecialchars($revenue['description']) . '' . htmlspecialchars($revenue['count']) . ' x' . htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'] . " " . $revenue['amountNet']['currency'] : '-') . '' . htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'] . " " . $revenue['amountVat']['currency'] : '-') . '' . htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'] . " " . $revenue['amountGross']['currency'] : '-') . ''.htmlspecialchars($year.'-'.$month).''.htmlspecialchars($revenue['description']).''.htmlspecialchars($revenue['count']).' x'.htmlspecialchars($revenue['amountNet']['value'] ? $revenue['amountNet']['value'].' '.$revenue['amountNet']['currency'] : '-').''.htmlspecialchars($revenue['amountVat']['value'] ? $revenue['amountVat']['value'].' '.$revenue['amountVat']['currency'] : '-').''.htmlspecialchars($revenue['amountGross']['value'] ? $revenue['amountGross']['value'].' '.$revenue['amountGross']['currency'] : '-').'
            TOTAL' . htmlspecialchars($settlement->amount->value . " " . $settlement->amount->currency) . '
            TOTAL'.htmlspecialchars($settlement->amount->value.' '.$settlement->amount->currency).'
            '; echo '
          • '; } echo '
          '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/shipments/create-shipment-all.php b/examples/shipments/create-shipment-all.php deleted file mode 100644 index a1f126b4a..000000000 --- a/examples/shipments/create-shipment-all.php +++ /dev/null @@ -1,27 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $shipment = $order->shipAll(); - - echo 'A shipment with ID ' . $shipment->id. ' has been created for your order with ID ' . $order->id . '.'; - foreach ($shipment->lines as $line) { - echo $line->name . ' - status: ' . $line->status . '.'; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/shipments/create-shipment-partial.php b/examples/shipments/create-shipment-partial.php deleted file mode 100644 index 8c15cf6e1..000000000 --- a/examples/shipments/create-shipment-partial.php +++ /dev/null @@ -1,42 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $lineId1 = $order->lines()[0]->id; - $lineId2 = $order->lines()[1]->id; - $shipment = $order->createShipment( - [ - 'lines' => [ - [ - 'id' => $lineId1, - // assume all is shipped if no quantity is specified - ], - [ - 'id' => $lineId2, - 'quantity' => 1, // you can set the quantity if not all is shipped at once - ], - ], - ] - ); - - echo 'A shipment with ID ' . $shipment->id. ' has been created for your order with ID ' . $order->id . '.'; - foreach ($shipment->lines as $line) { - echo $line->name . '- status: ' . $line->status . '.'; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/shipments/get-shipment.php b/examples/shipments/get-shipment.php deleted file mode 100644 index fbdd21d85..000000000 --- a/examples/shipments/get-shipment.php +++ /dev/null @@ -1,27 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $shipment = $order->getShipment("shp_3wmsgCJN4U"); - - echo 'Shipment with ID ' . $shipment->id. ' for order with ID ' . $order->id . '.'; - foreach ($shipment->lines as $line) { - echo $line->name . ' - status: ' . $line->status . '.'; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/shipments/list-shipments.php b/examples/shipments/list-shipments.php deleted file mode 100644 index 91cc0ff80..000000000 --- a/examples/shipments/list-shipments.php +++ /dev/null @@ -1,30 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $shipments = $order->shipments(); - - echo 'Shipments for order with ID ' . $order->id . ':'; - foreach ($shipments as $shipment) { - echo 'Shipment ' . $shipment->id . '. Items:'; - foreach ($shipment->lines as $line) { - echo $line->name . ' - status: ' . $line->status . '.'; - } - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/shipments/update-shipment.php b/examples/shipments/update-shipment.php deleted file mode 100644 index c77913889..000000000 --- a/examples/shipments/update-shipment.php +++ /dev/null @@ -1,40 +0,0 @@ -orders->get('ord_8wmqcHMN4U'); - $shipment = $order->getShipment("shp_3wmsgCJN4U"); - - $shipment->tracking = [ - 'carrier' => 'PostNL', - 'code' => '3SKABA000000000', - 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', - ]; - $shipment = $shipment->update(); - - echo 'Shipment with ID ' . $shipment->id. ' for order with ID ' . $order->id . '.'; - echo 'Tracking information updated:'; - echo 'Carrier: ' . $shipment->tracking->carrier; - echo 'Code: ' . $shipment->tracking->code; - echo 'Url: ' . $shipment->tracking->url; - - foreach ($shipment->lines as $line) { - echo $line->name . ' - status: ' . $line->status . '.'; - } -} catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); -} diff --git a/examples/subscriptions/cancel-subscription.php b/examples/subscriptions/cancel-subscription.php index c7cd11821..48dc974e6 100644 --- a/examples/subscriptions/cancel-subscription.php +++ b/examples/subscriptions/cancel-subscription.php @@ -7,7 +7,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve the last created customer for this example. @@ -30,7 +30,7 @@ /* * The subscription status should now be canceled */ - echo "

          The subscription status is now: '" . htmlspecialchars($canceledSubscription->status) . "'.

          \n"; + echo "

          The subscription status is now: '".htmlspecialchars($canceledSubscription->status)."'.

          \n"; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/subscriptions/create-subscription.php b/examples/subscriptions/create-subscription.php index 9df37f301..2c17b4bfe 100644 --- a/examples/subscriptions/create-subscription.php +++ b/examples/subscriptions/create-subscription.php @@ -7,12 +7,12 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Determine the url parts to these example files. */ - $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? "https" : "http"; + $protocol = isset($_SERVER['HTTPS']) && strcasecmp('off', $_SERVER['HTTPS']) !== 0 ? 'https' : 'http'; $hostname = $_SERVER['HTTP_HOST']; $path = dirname($_SERVER['REQUEST_URI'] ?? $_SERVER['PHP_SELF']); @@ -34,16 +34,16 @@ * @See: https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription */ $subscription = $customer->createSubscription([ - "amount" => [ - "value" => "10.00", // You must send the correct number of decimals, thus we enforce the use of strings - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings + 'currency' => 'EUR', ], - "times" => 12, - "interval" => "1 month", - "description" => "Subscription #{$subscriptionId}", - "webhookUrl" => "{$protocol}://{$hostname}{$path}/webhook.php", - "metadata" => [ - "subscription_id" => $subscriptionId, + 'times' => 12, + 'interval' => '1 month', + 'description' => "Subscription #{$subscriptionId}", + 'webhookUrl' => "{$protocol}://{$hostname}{$path}/webhook.php", + 'metadata' => [ + 'subscription_id' => $subscriptionId, ], ]); @@ -52,10 +52,10 @@ * a pending or valid mandate. If the customer has no mandates an error is returned. You * should then set up a "first payment" for the customer. */ - echo "

          The subscription status is '" . htmlspecialchars($subscription->status) . "'.

          \n"; - echo "

          "; - echo '18-cancel-subscription
          '; - echo "

          "; + echo "

          The subscription status is '".htmlspecialchars($subscription->status)."'.

          \n"; + echo '

          '; + echo '18-cancel-subscription
          '; + echo '

          '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/subscriptions/update-subscription.php b/examples/subscriptions/update-subscription.php index 6efd54b58..3a778f624 100644 --- a/examples/subscriptions/update-subscription.php +++ b/examples/subscriptions/update-subscription.php @@ -6,13 +6,13 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Retrieve an existing subscription */ - $customer = $mollie->customers->get("cst_cUe8HjeBuz"); - $subscription = $customer->getSubscription("sub_DRjwaT5qHx"); + $customer = $mollie->customers->get('cst_cUe8HjeBuz'); + $subscription = $customer->getSubscription('sub_DRjwaT5qHx'); /** * Subscription fields that can be updated are described by the link: @@ -20,12 +20,12 @@ */ $subscription->times = 10; $subscription->startDate = '2018-12-02'; // Year-month-day - $subscription->amount = (object)['value' => '12.12', 'currency' => 'EUR']; + $subscription->amount = (object) ['value' => '12.12', 'currency' => 'EUR']; $subscription->webhookUrl = 'https://some-webhook-url.com/with/path'; $subscription->description = 'Monthly subscription'; $subscription->update(); - echo "

          Subscription updated: " . $subscription->id . "

          "; + echo '

          Subscription updated: '.$subscription->id.'

          '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/src/Contracts/Connector.php b/src/Contracts/Connector.php index e70daf856..6a428f01e 100644 --- a/src/Contracts/Connector.php +++ b/src/Contracts/Connector.php @@ -5,7 +5,7 @@ use Mollie\Api\Helpers\MiddlewareHandlers; use Mollie\Api\Http\Request; -interface Connector extends Authenticatable, Hydratable, IdempotencyContract, SupportsDebuggingContract +interface Connector extends Authenticatable, Hydratable, IdempotencyContract, SupportsDebuggingContract, Testable { public function send(Request $request): ?object; diff --git a/src/Contracts/PayloadRepository.php b/src/Contracts/PayloadRepository.php index 6731cd9e1..5f6b25ade 100644 --- a/src/Contracts/PayloadRepository.php +++ b/src/Contracts/PayloadRepository.php @@ -19,6 +19,8 @@ public function all(); public function remove(string $key): self; + public function add(string $key, $value): self; + public function isEmpty(): bool; public function isNotEmpty(): bool; diff --git a/src/Contracts/Rule.php b/src/Contracts/Rule.php index d912e73e0..158fc2f2d 100644 --- a/src/Contracts/Rule.php +++ b/src/Contracts/Rule.php @@ -6,5 +6,5 @@ interface Rule { - public function validate($value, $context, Closure $fail): void; + public function validate($value, Closure $fail, $context): void; } diff --git a/src/Contracts/SupportsResourceHydration.php b/src/Contracts/SupportsResourceHydration.php new file mode 100644 index 000000000..357b72a44 --- /dev/null +++ b/src/Contracts/SupportsResourceHydration.php @@ -0,0 +1,8 @@ +send(new GetBalanceRequest($id, $testmode)); + return $this->send((new GetBalanceRequest($id))->test($testmode)); } /** @@ -48,13 +48,15 @@ public function primary(array $testmode = []): Balance */ public function page(?string $from = null, ?int $limit = null, array $filters = []): BalanceCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedBalanceQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, ])->create(); - return $this->send(new GetPaginatedBalanceRequest($query)); + return $this->send((new GetPaginatedBalanceRequest($query))->test($testmode)); } /** @@ -65,6 +67,8 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedBalanceQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -75,6 +79,7 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter (new GetPaginatedBalanceRequest($query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } } diff --git a/src/EndpointCollection/BalanceReportEndpointCollection.php b/src/EndpointCollection/BalanceReportEndpointCollection.php index 40aa9b4e6..ce974a023 100644 --- a/src/EndpointCollection/BalanceReportEndpointCollection.php +++ b/src/EndpointCollection/BalanceReportEndpointCollection.php @@ -3,6 +3,7 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Factories\GetBalanceReportQueryFactory; +use Mollie\Api\Helpers; use Mollie\Api\Http\Query\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; @@ -19,11 +20,13 @@ class BalanceReportEndpointCollection extends EndpointCollection */ public function getForId(string $balanceId, $query = []): ?BalanceReport { + $testmode = Helpers::extractBool($query, 'testmode', false); + $query = GetBalanceReportQueryFactory::new($query) ->create(); /** @var BalanceReport */ - return $this->send(new GetBalanceReportRequest($balanceId, $query)); + return $this->send((new GetBalanceReportRequest($balanceId, $query))->test($testmode)); } /** diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php index 30e319180..6fcf625a6 100644 --- a/src/EndpointCollection/BalanceTransactionEndpointCollection.php +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -20,9 +20,9 @@ class BalanceTransactionEndpointCollection extends EndpointCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageFor(Balance $balance, $query = []): BalanceTransactionCollection + public function pageFor(Balance $balance, $query = [], ?bool $testmode = null): BalanceTransactionCollection { - return $this->pageForId($balance->id, $query); + return $this->pageForId($balance->id, $query, $testmode); } /** @@ -30,9 +30,9 @@ public function pageFor(Balance $balance, $query = []): BalanceTransactionCollec * * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false): LazyCollection + public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection { - return $this->iteratorForId($balance->id, $parameters, $iterateBackwards); + return $this->iteratorForId($balance->id, $parameters, $iterateBackwards, $testmode); } /** @@ -42,10 +42,10 @@ public function iteratorFor(Balance $balance, array $parameters = [], bool $iter * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForPrimary($query = []): BalanceTransactionCollection + public function pageForPrimary($query = [], ?bool $testmode = null): BalanceTransactionCollection { /** @var BalanceTransactionCollection */ - return $this->pageForId('primary', $query); + return $this->pageForId('primary', $query, $testmode); } /** @@ -54,7 +54,7 @@ public function pageForPrimary($query = []): BalanceTransactionCollection * @param array|PaginatedQuery $query * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function iteratorForPrimary($query = [], bool $iterateBackwards = false): LazyCollection + public function iteratorForPrimary($query = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection { return $this->iteratorForId('primary', $query, $iterateBackwards); } @@ -63,10 +63,11 @@ public function iteratorForPrimary($query = [], bool $iterateBackwards = false): * List the transactions for a specific Balance ID. * * @param array|PaginatedQuery $query + * @param bool|null $testmode * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId(string $balanceId, $query = []): BalanceTransactionCollection + public function pageForId(string $balanceId, $query = [], bool $testmode = false): BalanceTransactionCollection { if (! $query instanceof PaginatedQuery) { $query = PaginatedQueryFactory::new($query) @@ -74,7 +75,7 @@ public function pageForId(string $balanceId, $query = []): BalanceTransactionCol } /** @var BalanceTransactionCollection */ - return $this->send(new GetPaginatedBalanceTransactionRequest($balanceId, $query)); + return $this->send((new GetPaginatedBalanceTransactionRequest($balanceId, $query))->test($testmode)); } /** @@ -83,7 +84,7 @@ public function pageForId(string $balanceId, $query = []): BalanceTransactionCol * @param array|PaginatedQuery $query * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function iteratorForId(string $balanceId, $query = [], bool $iterateBackwards = false): LazyCollection + public function iteratorForId(string $balanceId, $query = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection { if (! $query instanceof PaginatedQuery) { $query = PaginatedQueryFactory::new($query) @@ -94,6 +95,7 @@ public function iteratorForId(string $balanceId, $query = [], bool $iterateBackw (new GetPaginatedBalanceTransactionRequest($balanceId, $query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } } diff --git a/src/EndpointCollection/ChargebackEndpointCollection.php b/src/EndpointCollection/ChargebackEndpointCollection.php index 737b8213b..68200b13d 100644 --- a/src/EndpointCollection/ChargebackEndpointCollection.php +++ b/src/EndpointCollection/ChargebackEndpointCollection.php @@ -4,6 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedChargebackQueryFactory; +use Mollie\Api\Helpers; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; @@ -19,6 +20,8 @@ class ChargebackEndpointCollection extends EndpointCollection */ public function page(?string $from = null, ?int $limit = null, array $filters = []): ChargebackCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedChargebackQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -26,7 +29,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = ])->create(); /** @var ChargebackCollection */ - return $this->send(new GetPaginatedChargebacksRequest($query)); + return $this->send((new GetPaginatedChargebacksRequest($query))->test($testmode)); } /** @@ -38,6 +41,8 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, $filters = [], bool $iterateBackwards = false): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedChargebackQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -48,6 +53,7 @@ public function iterator(?string $from = null, ?int $limit = null, $filters = [] (new GetPaginatedChargebacksRequest($query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } } diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index fa2050fb5..d926b56cf 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -17,6 +17,7 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Resources\LazyCollection; +use Symfony\Component\Console\Helper\Helper; class CustomerEndpointCollection extends EndpointCollection { @@ -24,17 +25,19 @@ class CustomerEndpointCollection extends EndpointCollection * Creates a customer in Mollie. * * @param array|CreateCustomerPayload $data An array containing details on the customer. - * + * @param array|bool|null $testmode * @throws ApiException */ - public function create($data = []): Customer + public function create($data = [], $testmode = []): Customer { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + if (! $data instanceof CreateCustomerPayload) { $data = CreateCustomerPayloadFactory::new($data)->create(); } /** @var Customer */ - return $this->send(new CreateCustomerRequest($data)); + return $this->send((new CreateCustomerRequest($data))->test($testmode)); } /** @@ -49,7 +52,7 @@ public function get(string $id, $testmode = []): Customer $testmode = Helpers::extractBool($testmode, 'testmode', false); /** @var Customer */ - return $this->send(new GetCustomerRequest($id, $testmode)); + return $this->send((new GetCustomerRequest($id))->test($testmode)); } /** @@ -84,7 +87,7 @@ public function delete(string $id, $testmode = []): ?Customer $testmode = Helpers::extractBool($testmode, 'testmode', false); /** @var null|Customer */ - return $this->send(new DeleteCustomerRequest($id, $testmode)); + return $this->send((new DeleteCustomerRequest($id))->test($testmode)); } /** @@ -96,6 +99,8 @@ public function delete(string $id, $testmode = []): ?Customer */ public function page(?string $from = null, ?int $limit = null, array $filters = []): CustomerCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -103,7 +108,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = ])->create(); /** @var CustomerCollection */ - return $this->send(new GetPaginatedCustomerRequest($query)); + return $this->send((new GetPaginatedCustomerRequest($query))->test($testmode)); } /** @@ -114,6 +119,8 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -124,6 +131,7 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter (new GetPaginatedCustomerRequest($query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } } diff --git a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php new file mode 100644 index 000000000..3b8308dd2 --- /dev/null +++ b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php @@ -0,0 +1,120 @@ +createForId($customer->id, $payload, $testmode); + } + + /** + * Create a subscription for a Customer ID + * + * @param string $customerId + * @param array| $payload + * + * @throws ApiException + */ + public function createForId($customerId, array $payload = []): Payment + { + $testmode = Helpers::extractBool($payload, 'testmode', false); + $profileId = Arr::get($payload, 'profileId'); + + /** @var Payment */ + return $this->send((new CreateCustomerPaymentRequest($customerId, $profileId))->test($testmode)); + } + + /** + * @param string $from The first resource ID you want to include in your list. + * + * @throws ApiException + */ + public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection + { + return $this->pageForId($customer->id, $from, $limit, $parameters); + } + + /** + * @param string $from The first resource ID you want to include in your list. + * + * @throws ApiException + */ + public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedCustomerPaymentsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send(new GetPaginatedCustomerPaymentsRequest( + $customerId, + $query + ))->test($testmode); + } + + /** + * Create an iterator for iterating over payments for the given customer, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over payments for the given customer id, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedCustomerPaymentsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedCustomerPaymentsRequest($customerId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/InvoiceEndpointCollection.php b/src/EndpointCollection/InvoiceEndpointCollection.php new file mode 100644 index 000000000..b20cb61ae --- /dev/null +++ b/src/EndpointCollection/InvoiceEndpointCollection.php @@ -0,0 +1,68 @@ +send(new GetInvoiceRequest($invoiceId)); + } + + /** + * Retrieves a collection of Invoices from Mollie. + * + * @param string|null $from The first invoice ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): InvoiceCollection + { + $query = GetPaginatedInvoiceQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var InvoiceCollection */ + return $this->send(new GetPaginatedInvoiceRequest($query)); + } + + /** + * Create an iterator for iterating over invoices retrieved from Mollie. + * + * @param string|null $from The first invoice ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $parameters, + ])->create(); + + return $this->send( + (new GetPaginatedInvoiceRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php new file mode 100644 index 000000000..4d754b4e4 --- /dev/null +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -0,0 +1,179 @@ +createForId($customer->id, $payload); + } + + /** + * Creates a mandate for a specific customer ID. + * + * @param array $payload + * @param array $filters + * + * @throws ApiException + */ + public function createForId(string $customerId, $payload = [], bool $testmode = false): Mandate + { + if (! $payload instanceof CreateMandatePayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $payload = CreateMandatePayloadFactory::new($payload)->create(); + } + + /** @var Mandate */ + return $this->send((new CreateMandateRequest($customerId, $payload))->test($testmode)); + } + + /** + * Retrieve a specific mandate for a customer. + * + * + * @throws ApiException + */ + public function getFor(Customer $customer, string $mandateId, array $parameters = []): Mandate + { + return $this->getForId($customer->id, $mandateId, $parameters); + } + + /** + * Retrieve a specific mandate for a customer ID. + * + * @param array $testmode + * + * @throws ApiException + */ + public function getForId(string $customerId, string $mandateId, $testmode = []): Mandate + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + /** @var Mandate */ + return $this->send((new GetMandateRequest($customerId, $mandateId))->test($testmode)); + } + + /** + * Revoke a mandate for a specific customer. + * + * + * @throws ApiException + */ + public function revokeFor(Customer $customer, string $mandateId, array $data = []): void + { + $this->revokeForId($customer->id, $mandateId, $data); + } + + /** + * Revoke a mandate for a specific customer ID. + * + * @param array|bool $testmode + * + * @throws ApiException + */ + public function revokeForId(string $customerId, string $mandateId, array $testmode = []): void + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + $this->send((new RevokeMandateRequest($customerId, $mandateId))->test($testmode)); + } + + /** + * Retrieves a collection of mandates for the given customer. + * + * @param string $from The first mandate ID you want to include in your list. + * + * @throws ApiException + */ + public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection + { + return $this->pageForId($customer->id, $from, $limit, $parameters); + } + + /** + * Retrieves a collection of mandates for the given customer ID. + * + * @param string $from The first mandate ID you want to include in your list. + * + * @throws ApiException + */ + public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): MandateCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var MandateCollection */ + return $this->send((new GetPaginatedMandateRequest($customerId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over mandates for the given customer. + * + * @param string $from The first mandate ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over mandates for the given customer ID. + * + * @param string $from The first mandate ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedMandateRequest($customerId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/MethodEndpointCollection.php b/src/EndpointCollection/MethodEndpointCollection.php new file mode 100644 index 000000000..65d891964 --- /dev/null +++ b/src/EndpointCollection/MethodEndpointCollection.php @@ -0,0 +1,87 @@ +create(); + } + + /** @var MethodCollection */ + return $this->send(new GetAllPaymentMethodsRequest($query)); + } + + /** + * Retrieve all enabled methods for the organization. + * In test mode, this includes pending methods. + * The results are not paginated. + * + * @throws ApiException + */ + public function allEnabled($query = [], bool $testmode = false): MethodCollection + { + if (! $query instanceof GetEnabledPaymentMethodsQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetEnabledPaymentMethodsQueryFactory::new($query) + ->create(); + } + + /** @var MethodCollection */ + return $this->send((new GetEnabledPaymentMethodsRequest($query))->test($testmode)); + } + + /** + * @deprecated Use allEnabled() instead + * + * @throws ApiException + */ + public function allActive($query = [], ?bool $testmode = null): MethodCollection + { + return $this->allEnabled($query, $testmode); + } + + /** + * Retrieve a payment method from Mollie. + * + * Will throw an ApiException if the method id is invalid or the resource cannot be found. + * + * @throws ApiException + */ + public function get(string $methodId, $query = [], bool $testmode = false): Method + { + if (! $query instanceof GetPaymentMethodQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaymentMethodQueryFactory::new($query) + ->create(); + } + + /** @var Method */ + return $this->send((new GetPaymentMethodRequest($methodId, $query))->test($testmode)); + } +} diff --git a/src/EndpointCollection/MethodIssuerEndpointCollection.php b/src/EndpointCollection/MethodIssuerEndpointCollection.php new file mode 100644 index 000000000..5da33703a --- /dev/null +++ b/src/EndpointCollection/MethodIssuerEndpointCollection.php @@ -0,0 +1,31 @@ +send(new EnableMethodIssuerRequest($profileId, $methodId, $issuerId, $contractId)); + } + + /** + * Disable an issuer for a specific payment method. + * + * @throws ApiException + */ + public function disable(string $profileId, string $methodId, string $issuerId): void + { + return $this->send(new DisableMethodIssuerRequest($profileId, $methodId, $issuerId)); + } +} diff --git a/src/EndpointCollection/OnboardingEndpointCollection.php b/src/EndpointCollection/OnboardingEndpointCollection.php new file mode 100644 index 000000000..2e799522c --- /dev/null +++ b/src/EndpointCollection/OnboardingEndpointCollection.php @@ -0,0 +1,14 @@ +send(new GetOnboardingStatusRequest); + } +} diff --git a/src/EndpointCollection/OrganizationEndpointCollection.php b/src/EndpointCollection/OrganizationEndpointCollection.php index d7e1988a7..36f8a6ea7 100644 --- a/src/EndpointCollection/OrganizationEndpointCollection.php +++ b/src/EndpointCollection/OrganizationEndpointCollection.php @@ -4,8 +4,10 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Helpers; +use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; +use Mollie\Api\Resources\Partner; class OrganizationEndpointCollection extends EndpointCollection { @@ -23,7 +25,7 @@ public function get(string $id, $testmode = []): Organization $testmode = Helpers::extractBool($testmode, 'testmode', false); /** @var Organization */ - return $this->send(new GetOrganizationRequest($id, $testmode)); + return $this->send((new GetOrganizationRequest($id))->test($testmode)); } /** @@ -38,4 +40,14 @@ public function current($testmode = []): Organization /** @var Organization */ return $this->get('me', $testmode); } + + /** + * Retrieve the partner status of the current organization. + * + * @throws ApiException + */ + public function partnerStatus(): Partner + { + return $this->send(new GetOrganizationPartnerStatusRequest); + } } diff --git a/src/EndpointCollection/OrganizationPartnerEndpointCollection.php b/src/EndpointCollection/OrganizationPartnerEndpointCollection.php new file mode 100644 index 000000000..8d3ae173e --- /dev/null +++ b/src/EndpointCollection/OrganizationPartnerEndpointCollection.php @@ -0,0 +1,17 @@ +send(new GetOrganizationPartnerStatusRequest); + } +} diff --git a/src/EndpointCollection/PaymentCaptureEndpointCollection.php b/src/EndpointCollection/PaymentCaptureEndpointCollection.php new file mode 100644 index 000000000..7a6a46ed9 --- /dev/null +++ b/src/EndpointCollection/PaymentCaptureEndpointCollection.php @@ -0,0 +1,148 @@ +createForId($payment->id, $payload, $testmode); + } + + /** + * Creates a payment capture in Mollie. + * + * @param array|CreatePaymentCapturePayload $payload An array containing details on the capture. + * + * @throws ApiException + */ + public function createForId(string $paymentId, $payload = [], bool $testmode = false): Capture + { + if (! $payload instanceof CreatePaymentCapturePayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $payload = CreatePaymentCapturePayloadFactory::new($payload)->create(); + } + + /** @var Capture */ + return $this->send((new CreatePaymentCaptureRequest($paymentId, $payload))->test($testmode)); + } + + /** + * @param array|GetPaymentCaptureQuery $query + * + * @throws ApiException + */ + public function getFor(Payment $payment, string $captureId, $query = [], ?bool $testmode = null): Capture + { + return $this->getForId($payment->id, $captureId, $query, $testmode); + } + + /** + * @param array|GetPaymentCaptureQuery $query + * + * @throws ApiException + */ + public function getForId(string $paymentId, string $captureId, $query = [], bool $testmode = false): Capture + { + if (! $query instanceof GetPaymentCaptureQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaymentCaptureQueryFactory::new($query)->create(); + } + + /** @var Capture */ + return $this->send((new GetPaymentCaptureRequest($paymentId, $captureId, $query))->test($testmode)); + } + + /** + * @param array|GetPaginatedPaymentCapturesQuery $query + * + * @throws ApiException + */ + public function pageFor(Payment $payment, $query = [], ?bool $testmode = null): CaptureCollection + { + return $this->pageForId($payment->id, $query, $testmode); + } + + /** + * @param array|GetPaginatedPaymentCapturesQuery $query + * + * @throws ApiException + */ + public function pageForId(string $paymentId, $query = [], bool $testmode = false): CaptureCollection + { + if (! $query instanceof GetPaginatedPaymentCapturesQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaginatedPaymentCapturesQueryFactory::new($query)->create(); + } + + /** @var CaptureCollection */ + return $this->send((new GetPaginatedPaymentCapturesRequest($paymentId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over captures for the given payment, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Payment $payment, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over captures for the given payment id, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $paymentId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedPaymentCapturesQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedPaymentCapturesRequest($paymentId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/PaymentChargebackEndpointCollection.php b/src/EndpointCollection/PaymentChargebackEndpointCollection.php new file mode 100644 index 000000000..8cd1b7e10 --- /dev/null +++ b/src/EndpointCollection/PaymentChargebackEndpointCollection.php @@ -0,0 +1,115 @@ +getForId($payment->id, $chargebackId, $query, $testmode); + } + + /** + * @param array|GetPaymentChargebackQuery $query + * + * @throws ApiException + */ + public function getForId(string $paymentId, string $chargebackId, $query = [], bool $testmode = false): Chargeback + { + if (! $query instanceof GetPaymentChargebackQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaymentChargebackQueryFactory::new($query)->create(); + } + + /** @var Chargeback */ + return $this->send((new GetPaymentChargebackRequest($paymentId, $chargebackId, $query))->test($testmode)); + } + + /** + * @param array|GetPaginatedPaymentChargebacksQuery $query + * + * @throws ApiException + */ + public function pageFor(Payment $payment, $query = []): ChargebackCollection + { + return $this->pageForId($payment->id, $query); + } + + /** + * @param array|GetPaginatedPaymentChargebacksQuery $query + * + * @throws ApiException + */ + public function pageForId(string $paymentId, $query = [], bool $testmode = false): ChargebackCollection + { + if (! $query instanceof GetPaginatedPaymentChargebacksQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaginatedPaymentChargebacksQueryFactory::new($query)->create(); + } + + /** @var ChargebackCollection */ + return $this->send((new GetPaginatedPaymentChargebacksRequest($paymentId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over chargebacks for the given payment, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Payment $payment, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over chargebacks for the given payment id, retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $paymentId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedPaymentChargebacksQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedPaymentChargebacksRequest($paymentId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index ba43be7e8..8b64a2c08 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -16,8 +16,8 @@ use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Http\Query\GetPaymentQuery; use Mollie\Api\Http\Requests\CancelPaymentRequest; -use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; +use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest; use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; @@ -36,14 +36,15 @@ class PaymentEndpointCollection extends EndpointCollection * * @throws ApiException */ - public function get(string $paymentId, $query = []): Payment + public function get(string $id, $query = [], bool $testmode = false): Payment { if (! $query instanceof GetPaymentQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); $query = GetPaymentQueryFactory::new($query) ->create(); } - return $this->send(new GetPaymentRequest($paymentId, $query)); + return $this->send((new GetPaymentRequest($id, $query))->test($testmode)); } /** @@ -54,9 +55,10 @@ public function get(string $paymentId, $query = []): Payment * * @throws ApiException */ - public function create($data = [], $query = []): Payment + public function create($data = [], $query = [], bool $testmode = false): Payment { if (! $data instanceof CreatePaymentPayload) { + $testmode = Helpers::extractBool($data, 'testmode', $testmode); $data = CreatePaymentPayloadFactory::new($data) ->create(); } @@ -66,7 +68,7 @@ public function create($data = [], $query = []): Payment } /** @var Payment */ - return $this->send(new CreatePaymentRequest($data, $query)); + return $this->send((new CreatePaymentRequest($data, $query))->test($testmode)); } /** @@ -79,15 +81,16 @@ public function create($data = [], $query = []): Payment * * @throws ApiException */ - public function update($id, $data = []): ?Payment + public function update($id, $data = [], bool $testmode = false): ?Payment { if (! $data instanceof UpdatePaymentPayload) { + $testmode = Helpers::extractBool($data, 'testmode', $testmode); $data = UpdatePaymentPayloadFactory::new($data) ->create(); } /** @var null|Payment */ - return $this->send(new UpdatePaymentRequest($id, $data)); + return $this->send((new UpdatePaymentRequest($id, $data))->test($testmode)); } /** @@ -119,7 +122,7 @@ public function cancel(string $id, $data = []): ?Payment $testmode = Helpers::extractBool($data, 'testmode', false); /** @var null|Payment */ - return $this->send(new CancelPaymentRequest($id, $testmode)); + return $this->send((new CancelPaymentRequest($id))->test($testmode)); } /** @@ -132,17 +135,18 @@ public function cancel(string $id, $data = []): ?Payment * * @throws ApiException */ - public function refund(Payment $payment, $payload = []): Refund + public function refund(Payment $payment, $payload = [], bool $testmode = false): Refund { if (! $payload instanceof CreateRefundPaymentPayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); $payload = CreateRefundPaymentPayloadFactory::new($payload) ->create(); } - return $this->send(new CreatePaymentRefundRequest( + return $this->send((new CreatePaymentRefundRequest( $payment->id, $payload - )); + ))->test($testmode)); } /** @@ -150,13 +154,14 @@ public function refund(Payment $payment, $payload = []): Refund */ public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, ])->create(); - return $this->send(new GetPaginatedPaymentsRequest($query)); + return $this->send((new GetPaginatedPaymentsRequest($query))->test($testmode)); } /** @@ -167,6 +172,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -177,6 +183,7 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter (new GetPaginatedPaymentsRequest($query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } } diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php new file mode 100644 index 000000000..54ffe5843 --- /dev/null +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -0,0 +1,131 @@ +create(); + } + + /** @var PaymentLink */ + return $this->send(new CreatePaymentLinkRequest($payload)); + } + + /** + * Retrieve a payment link from Mollie. + * + * Will throw an ApiException if the payment link id is invalid or the resource cannot be found. + * + * @param array $testmode + * + * @throws ApiException + */ + public function get(string $paymentLinkId, $testmode = []): PaymentLink + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + /** @var PaymentLink */ + return $this->send((new GetPaymentLinkRequest($paymentLinkId))->test($testmode)); + } + + /** + * Update a Payment Link. + * + * @param array|UpdatePaymentLinkPayload $payload + * + * @throws ApiException + */ + public function update(string $paymentLinkId, $payload = [], ?bool $testmode = null): PaymentLink + { + if (! $payload instanceof UpdatePaymentLinkPayload) { + $payload = UpdatePaymentLinkPayloadFactory::new($payload)->create(); + } + + /** @var PaymentLink */ + return $this->send((new UpdatePaymentLinkRequest($paymentLinkId, $payload))->test($testmode)); + } + + /** + * Delete a Payment Link. + * + * + * @throws ApiException + */ + public function delete(string $paymentLinkId, ?bool $testmode = null): void + { + $this->send((new DeletePaymentLinkRequest($paymentLinkId))->test($testmode)); + } + + /** + * Retrieves a collection of Payment Links from Mollie. + * + * @param string|null $from The first payment link ID you want to include in your list. + * @param array|bool $testmode + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, $testmode = []): PaymentLinkCollection + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + /** @var PaymentLinkCollection */ + return $this->send((new GetPaginatedPaymentLinksRequest($query))->test($testmode)); + } + + /** + * Create an iterator for iterating over payment links retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + ?bool $testmode = null, + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedPaymentLinksRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php new file mode 100644 index 000000000..1714a3ea7 --- /dev/null +++ b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php @@ -0,0 +1,97 @@ +pageForId($paymentLink->id, $from, $limit, $filters); + } + + /** + * Retrieves a collection of Payments from Mollie for the given Payment Link ID. + * + * @param string|null $from The first payment ID you want to include in your list. + * + * @throws ApiException + */ + public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, ?array $filters = null): PaymentCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = SortablePaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var PaymentCollection */ + return $this->send((new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over payments associated with the provided Payment Link object, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + PaymentLink $paymentLink, + ?string $from = null, + ?int $limit = null, + ?array $filters = null, + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId( + $paymentLink->id, + $from, + $limit, + $filters, + $iterateBackwards + ); + } + + /** + * Create an iterator for iterating over payments associated with the provided Payment Link id, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $paymentLinkId, + ?string $from = null, + ?int $limit = null, + ?array $filters = null, + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = SortablePaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php index 13fae2ad2..13d03b156 100644 --- a/src/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -7,8 +7,8 @@ use Mollie\Api\Factories\GetPaymentRefundQueryFactory; use Mollie\Api\Helpers; use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; -use Mollie\Api\Http\Query\GetPaginatedPaymentRefundQuery; use Mollie\Api\Http\Query\GetPaymentRefundQuery; +use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Http\Requests\GetPaymentRefundRequest; @@ -22,45 +22,36 @@ class PaymentRefundEndpointCollection extends EndpointCollection /** * Creates a refund for a specific payment. * - * @param Payment $payment - * @param array $data - * @param array $filters + * @param array|bool $testmode * - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createFor(Payment $payment, array $data, array $filters = []): Refund + public function createFor(Payment $payment, array $data, $testmode = []): Refund { - return $this->createForId($payment->id, $data, $filters); + return $this->createForId($payment->id, $data, $testmode); } /** * Creates a refund for a specific payment. * - * @param string $paymentId - * @param array $payload - * @param array $filters + * @param array $payload * - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function createForId(string $paymentId, $payload = [], array $filters = []): Refund + public function createForId(string $paymentId, $payload = [], $testmode = []): Refund { + $testmode = Helpers::extractBool($testmode, 'testmode', false); if (! $payload instanceof CreateRefundPaymentPayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); $payload = CreateRefundPaymentPayloadFactory::new($payload) ->create(); } /** @var Refund */ - return $this->send(new CreatePaymentRefundRequest($paymentId, $payload, $filters)); + return $this->send((new CreatePaymentRefundRequest($paymentId, $payload))->test($testmode)); } /** - * @param Payment $payment - * @param string $refundId - * @param array $parameters - * - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ public function getFor(Payment $payment, string $refundId, array $parameters = []): Refund @@ -69,64 +60,74 @@ public function getFor(Payment $payment, string $refundId, array $parameters = [ } /** - * @param string $paymentId - * @param string $refundId - * @param array|GetPaymentRefundQuery $query + * @param array|GetPaymentRefundQuery $query * - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException */ - public function getForId(string $paymentId, string $refundId, $query = []): Refund + public function getForId(string $paymentId, string $refundId, $query = [], bool $testmode = false): Refund { if (! $query instanceof GetPaymentRefundQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); $query = GetPaymentRefundQueryFactory::new($query) ->create(); } /** @var Refund */ - return $this->send(new GetPaymentRefundRequest($paymentId, $refundId, $query)); + return $this->send((new GetPaymentRefundRequest($paymentId, $refundId, $query))->test($testmode)); } /** - * @param string $paymentId - * @param array|GetPaginatedPaymentRefundQuery $parameters + * @param array|bool $testmode + * @return null * - * @return RefundCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForId(string $paymentId, $parameters = []): RefundCollection + public function cancelForPayment(Payment $payment, string $refundId, $testmode = []) { - return $this->pageFor($paymentId, $parameters); + return $this->cancelForId($payment->id, $refundId, $testmode); } /** - * @param array|GetPaginatedPaymentRefundQuery $query + * @param array|bool $testmode + * @return null * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageFor(string $paymentId, $query = []): RefundCollection + public function cancelForId(string $paymentId, string $refundId, $testmode = []) { - if (! $query instanceof GetPaginatedPaymentRefundQuery) { - $query = GetPaginatedPaymentRefundQueryFactory::new($query) - ->create(); - } + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + return $this->send((new CancelPaymentRefundRequest($paymentId, $refundId))->test($testmode)); + } + + /** + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedPaymentRefundQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); - return $this->send(new GetPaginatedPaymentRefundsRequest( - $paymentId, - $query - )); + return $this->send((new GetPaginatedPaymentRefundsRequest($paymentId, $query))->test($testmode)); + } + + /** + * @throws \Mollie\Api\Exceptions\ApiException + */ + public function pageFor(Payment $payment, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection + { + return $this->pageForId($payment->id, $from, $limit, $filters); } /** * Create an iterator for iterating over refunds for the given payment, retrieved from Mollie. * - * @param Payment $payment - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorFor( Payment $payment, @@ -141,13 +142,8 @@ public function iteratorFor( /** * Create an iterator for iterating over refunds for the given payment id, retrieved from Mollie. * - * @param string $paymentId - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $filters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorForId( string $paymentId, @@ -156,6 +152,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); $query = GetPaginatedPaymentRefundQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -166,34 +163,7 @@ public function iteratorForId( (new GetPaginatedPaymentRefundsRequest($paymentId, $query)) ->useIterator() ->setIterationDirection($iterateBackwards) + ->test($testmode) ); } - - /** - * @param \Mollie\Api\Resources\Payment $payment - * @param string $refundId - * @param array $parameters - * @return null - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelForPayment(Payment $payment, string $refundId, $parameters = []) - { - return $this->cancelForId($payment->id, $refundId, $parameters); - } - - /** - * @param string $paymentId - * @param string $refundId - * @param array|bool $testmode - * @return null - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelForId(string $paymentId, string $refundId, $testmode = []) - { - $testmode = Helpers::extractBool($testmode, 'testmode', false); - - return $this->send(new CancelPaymentRefundRequest($paymentId, $refundId, $testmode)); - } } diff --git a/src/EndpointCollection/PaymentRouteEndpointCollection.php b/src/EndpointCollection/PaymentRouteEndpointCollection.php new file mode 100644 index 000000000..817a1c0cb --- /dev/null +++ b/src/EndpointCollection/PaymentRouteEndpointCollection.php @@ -0,0 +1,42 @@ +updateReleaseDateForId($payment->id, $routeId, $releaseDate, $testmode); + } + + /** + * Update the release date for a payment route using payment ID. + * + * @param DateTimeInterface $releaseDate UTC datetime when the funds will become available + * + * @throws ApiException + */ + public function updateReleaseDateForId(string $paymentId, string $routeId, string $releaseDate, ?bool $testmode = null): Route + { + $payload = UpdatePaymentRoutePayloadFactory::new([ + 'releaseDate' => $releaseDate, + ])->create(); + + /** @var Route */ + return $this->send((new UpdatePaymentRouteRequest($paymentId, $routeId, $payload))->test($testmode)); + } +} diff --git a/src/EndpointCollection/PermissionEndpointCollection.php b/src/EndpointCollection/PermissionEndpointCollection.php new file mode 100644 index 000000000..4509e7486 --- /dev/null +++ b/src/EndpointCollection/PermissionEndpointCollection.php @@ -0,0 +1,41 @@ +send((new GetPermissionRequest($permissionId))->test($testmode)); + } + + /** + * Retrieve all permissions from Mollie. + * + * @throws ApiException + */ + public function list(): PermissionCollection + { + /** @var PermissionCollection */ + return $this->send(new ListPermissionsRequest); + } +} diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php new file mode 100644 index 000000000..39db2c17f --- /dev/null +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -0,0 +1,149 @@ +create(); + } + + /** @var Profile */ + return $this->send(new CreateProfileRequest($payload)); + } + + /** + * Retrieve a Profile from Mollie. + * + * Will throw an ApiException if the profile id is invalid or the resource cannot be found. + * + * @param array|bool $testmode + * @return Profile|CurrentProfile + * + * @throws ApiException + */ + public function get(string $profileId, $testmode = []): Profile + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + + /** @var Profile */ + return $this->send((new GetProfileRequest($profileId))->test($testmode)); + } + + /** + * Retrieve the current Profile from Mollie. + * + * @param array|bool $testmode + * + * @throws ApiException + */ + public function getCurrent($testmode = []): CurrentProfile + { + GetProfileRequest::$targetResourceClass = CurrentProfile::class; + /** @var CurrentProfile */ + return $this->get('me', $testmode); + } + + /** + * Update a specific Profile resource. + * + * Will throw an ApiException if the profile id is invalid or the resource cannot be found. + * + * @param array|UpdateProfilePayload $data + * + * @throws ApiException + */ + public function update(string $profileId, $payload = []): ?Profile + { + if (! $payload instanceof UpdateProfilePayload) { + $payload = UpdateProfilePayloadFactory::new($payload) + ->create(); + } + + /** @var Profile|null */ + return $this->send(new UpdateProfileRequest($profileId, $payload)); + } + + /** + * Delete a Profile from Mollie. + * + * Will throw a ApiException if the profile id is invalid or the resource cannot be found. + * Returns with HTTP status No Content (204) if successful. + * + * + * @throws ApiException + */ + public function delete(string $profileId): ?Profile + { + /** @var Profile|null */ + return $this->send(new DeleteProfileRequest($profileId)); + } + + /** + * Retrieves a collection of Profiles from Mollie. + * + * @param string|null $from The first profile ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null): ProfileCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + /** @var ProfileCollection */ + return $this->send(new GetPaginatedProfilesRequest($query)); + } + + /** + * Create an iterator for iterating over profiles retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + bool $iterateBackwards = false + ): LazyCollection { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedProfilesRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/RefundEndpointCollection.php b/src/EndpointCollection/RefundEndpointCollection.php new file mode 100644 index 000000000..0b7afbb69 --- /dev/null +++ b/src/EndpointCollection/RefundEndpointCollection.php @@ -0,0 +1,60 @@ + $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var RefundCollection */ + return $this->send((new GetPaginatedRefundsRequest($query))->test($testmode)); + } + + /** + * Create an iterator for iterating over refunds retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedRefundsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedRefundsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SessionEndpointCollection.php b/src/EndpointCollection/SessionEndpointCollection.php new file mode 100644 index 000000000..dc20d3dfa --- /dev/null +++ b/src/EndpointCollection/SessionEndpointCollection.php @@ -0,0 +1,129 @@ +send(new GetSessionRequest($sessionId, $parameters)); + } + + /** + * Creates a session in Mollie. + * + * @param CreateSessionPayload|array $data An array containing details on the session. + * + * @throws ApiException + */ + public function create($data = [], array $filters = []): Session + { + if (! $data instanceof CreateSessionPayload) { + $data = CreateSessionPayloadFactory::new($data) + ->create(); + } + + /** @var Session */ + return $this->send(new CreateSessionRequest($data, $filters)); + } + + /** + * Update the given Session. + * + * Will throw a ApiException if the session id is invalid or the resource cannot be found. + * + * @param array|UpdateSessionPayload $data + * + * @throws ApiException + */ + public function update(string $id, $data = []): Session + { + if (! $data instanceof UpdateSessionPayload) { + $data = UpdateSessionPayloadFactory::new($data) + ->create(); + } + + /** @var Session */ + return $this->send(new UpdateSessionRequest($id, $data)); + } + + /** + * Cancel the given Session. + * + * Will throw a ApiException if the session id is invalid or the resource cannot be found. + * + * @throws ApiException + */ + public function cancel(string $id, array $parameters = []): ?Session + { + /** @var Session|null */ + return $this->send(new CancelSessionRequest($id, $parameters)); + } + + /** + * Get the sessions endpoint. + * + * @param string|null $from The first session ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): SessionCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var SessionCollection */ + return $this->send(new GetPaginatedSessionsRequest($query)); + } + + /** + * Create an iterator for iterating over sessions retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSessionsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/SettlementCaptureEndpointCollection.php b/src/EndpointCollection/SettlementCaptureEndpointCollection.php new file mode 100644 index 000000000..44552dbc2 --- /dev/null +++ b/src/EndpointCollection/SettlementCaptureEndpointCollection.php @@ -0,0 +1,89 @@ +pageForId($settlement->id, $query, $testmode); + } + + /** + * Retrieves a collection of Settlement Captures from Mollie. + * + * @param array|GetPaginatedSettlementCapturesQuery $query + * + * @throws ApiException + */ + public function pageForId(string $settlementId, $query = [], bool $testmode = false): CaptureCollection + { + if (! $query instanceof GetPaginatedSettlementCapturesQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaginatedSettlementCapturesQueryFactory::new($query)->create(); + } + + /** @var CaptureCollection */ + return $this->send((new GetPaginatedSettlementCapturesRequest($settlementId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over captures for the given settlement, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Settlement $settlement, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over captures for the given settlement id, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedSettlementCapturesQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementCapturesRequest($settlementId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SettlementChargebackEndpointCollection.php b/src/EndpointCollection/SettlementChargebackEndpointCollection.php new file mode 100644 index 000000000..b28ebd737 --- /dev/null +++ b/src/EndpointCollection/SettlementChargebackEndpointCollection.php @@ -0,0 +1,89 @@ +pageForId($settlement->id, $query, $testmode); + } + + /** + * Retrieves a collection of Settlement Chargebacks from Mollie. + * + * @param array|GetPaginatedSettlementChargebacksQuery $query + * + * @throws ApiException + */ + public function pageForId(string $settlementId, $query = [], bool $testmode = false): ChargebackCollection + { + if (! $query instanceof GetPaginatedSettlementChargebacksQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaginatedSettlementChargebacksQueryFactory::new($query)->create(); + } + + /** @var ChargebackCollection */ + return $this->send((new GetPaginatedSettlementChargebacksRequest($settlementId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over chargebacks for the given settlement, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorFor( + Settlement $settlement, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over chargebacks for the given settlement id, retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedSettlementChargebacksQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementChargebacksRequest($settlementId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SettlementPaymentEndpointCollection.php b/src/EndpointCollection/SettlementPaymentEndpointCollection.php new file mode 100644 index 000000000..2f921267b --- /dev/null +++ b/src/EndpointCollection/SettlementPaymentEndpointCollection.php @@ -0,0 +1,80 @@ +pageForId($settlement->id, $query, $testmode); + } + + /** + * Retrieves a collection of Settlement Payments from Mollie. + * + * @param array|GetPaginatedSettlementPaymentsQuery $query + * + * @throws ApiException + */ + public function pageForId(string $settlementId, $query = [], bool $testmode = false): PaymentCollection + { + if (! $query instanceof SortablePaginatedQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = SortablePaginatedQueryFactory::new($query)->create(); + } + + return $this->send((new GetPaginatedSettlementPaymentsRequest($settlementId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over payments for the given settlement, retrieved from Mollie. + */ + public function iteratorFor( + Settlement $settlement, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards); + } + + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($parameters, 'testmode', false); + $query = SortablePaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $parameters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementPaymentsRequest($settlementId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SettlementRefundEndpointCollection.php b/src/EndpointCollection/SettlementRefundEndpointCollection.php new file mode 100644 index 000000000..b06acd566 --- /dev/null +++ b/src/EndpointCollection/SettlementRefundEndpointCollection.php @@ -0,0 +1,82 @@ +pageForId($settlement->id, $query, $testmode); + } + + /** + * Retrieves a collection of Settlement Refunds from Mollie. + * + * @param array|GetPaginatedSettlementRefundsQuery $query + * + * @throws ApiException + */ + public function pageForId(string $settlementId, $query = [], bool $testmode = false): RefundCollection + { + if (! $query instanceof GetPaginatedSettlementRefundsQuery) { + $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $query = GetPaginatedSettlementRefundsQueryFactory::new($query)->create(); + } + + return $this->send((new GetPaginatedSettlementRefundsRequest($settlementId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over refunds for the given settlement, retrieved from Mollie. + */ + public function iteratorFor( + Settlement $settlement, + ?string $from = null, + ?int $limit = null, + array $parameters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over refunds for the given settlement id, retrieved from Mollie. + */ + public function iteratorForId( + string $settlementId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetPaginatedSettlementRefundsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementRefundsRequest($settlementId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SettlementsEndpointCollection.php b/src/EndpointCollection/SettlementsEndpointCollection.php new file mode 100644 index 000000000..ae02aba8c --- /dev/null +++ b/src/EndpointCollection/SettlementsEndpointCollection.php @@ -0,0 +1,80 @@ +send(new GetSettlementRequest($settlementId)); + } + + /** + * Retrieve the details of the current settlement that has not yet been paid out. + * + * @throws ApiException + */ + public function next(): Settlement + { + return $this->send(new GetSettlementRequest('next')); + } + + /** + * Retrieve the details of the open balance of the organization. + * + * @throws ApiException + */ + public function open(): Settlement + { + return $this->send(new GetSettlementRequest('open')); + } + + /** + * Retrieves a collection of Settlements from Mollie. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection + { + $query = GetPaginatedSettlementsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send(new GetPaginatedSettlementsRequest($query)); + } + + /** + * Create an iterator for iterating over settlements retrieved from Mollie. + */ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = GetPaginatedSettlementsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/EndpointCollection/SubscriptionEndpointCollection.php b/src/EndpointCollection/SubscriptionEndpointCollection.php new file mode 100644 index 000000000..46a08da3c --- /dev/null +++ b/src/EndpointCollection/SubscriptionEndpointCollection.php @@ -0,0 +1,219 @@ +getForId($customer->id, $subscriptionId, $testmode); + } + + /** + * Retrieve a single subscription from Mollie. + * + * @throws ApiException + */ + public function getForId(string $customerId, string $subscriptionId, $testmode = []): Subscription + { + $testmode = Helpers::extractBool($testmode, 'testmode'); + + return $this->send((new GetSubscriptionRequest($customerId, $subscriptionId))->test($testmode)); + } + + /** + * Creates a subscription for a Customer in Mollie. + * + * @param array|CreateSubscriptionPayload $data An array containing details on the subscription. + * + * @throws ApiException + */ + public function createFor(Customer $customer, $data = [], bool $testmode = false): Subscription + { + return $this->createForId($customer->id, $data, $testmode); + } + + /** + * Creates a subscription for a Customer in Mollie. + * + * @param array|CreateSubscriptionPayload $data An array containing details on the subscription. + * + * @throws ApiException + */ + public function createForId(string $customerId, $data = [], bool $testmode = false): Subscription + { + if (! $data instanceof CreateSubscriptionPayload) { + $testmode = Helpers::extractBool($data, 'testmode', $testmode); + $data = CreateSubscriptionPayloadFactory::new($data)->create(); + } + + return $this->send((new CreateSubscriptionRequest($customerId, $data))->test($testmode)); + } + + /** + * Update the given Subscription. + * + * @param array|UpdateSubscriptionPayload $data + * + * @throws ApiException + */ + public function update(string $customerId, string $subscriptionId, $data = [], ?bool $testmode = null): ?Subscription + { + if (! $data instanceof UpdateSubscriptionPayload) { + $testmode = Helpers::extractBool($data, 'testmode', $testmode); + $data = UpdateSubscriptionPayloadFactory::new($data)->create(); + } + + return $this->send((new UpdateSubscriptionRequest($customerId, $subscriptionId, $data))->test($testmode)); + } + + /** + * Cancel the given Subscription. + * + * @throws ApiException + */ + public function cancelFor(Customer $customer, string $subscriptionId, ?bool $testmode = null): ?Subscription + { + return $this->cancelForId($customer->id, $subscriptionId, $testmode); + } + + /** + * Cancel the given Subscription. + * + * @throws ApiException + */ + public function cancelForId(string $customerId, string $subscriptionId, ?bool $testmode = null): ?Subscription + { + return $this->send((new CancelSubscriptionRequest($customerId, $subscriptionId))->test($testmode)); + } + + /** + * Retrieve a page of subscriptions from Mollie. + * + * @throws ApiException + */ + public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection + { + return $this->pageForId($customer->id, $from, $limit, $filters); + } + + /** + * Retrieve a page of subscriptions from Mollie. + * + * @throws ApiException + */ + public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send((new GetPaginatedSubscriptionsRequest($customerId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over subscriptions for the given customer, retrieved from Mollie. + */ + public function iteratorFor( + Customer $customer, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForId($customer->id, $from, $limit, $filters, $iterateBackwards); + } + + /** + * Create an iterator for iterating over subscriptions for the given customer id, retrieved from Mollie. + */ + public function iteratorForId( + string $customerId, + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedSubscriptionsRequest($customerId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } + + public function allFor(?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection + { + return $this->allForId($from, $limit, $filters); + } + + public function allForId( + ?string $from = null, + ?int $limit = null, + array $filters = [] + ): SubscriptionCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetAllPaginatedSubscriptionsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send((new GetAllPaginatedSubscriptionsRequest($query))->test($testmode)); + } + + public function iteratorForAll( + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = true + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + $query = GetAllPaginatedSubscriptionsQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetAllPaginatedSubscriptionsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php new file mode 100644 index 000000000..a1055ed6a --- /dev/null +++ b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php @@ -0,0 +1,89 @@ +pageForIds($subscription->customerId, $subscription->id, $from, $limit, $testmode); + } + + /** + * Retrieves a paginated collection of Subscription Payments from Mollie. + * + * @param string|null $from The first payment ID you want to include in your list. + * @param int|null $limit The maximum amount of results you want to retrieve per page. + * @param bool|array $testmode + * @throws ApiException + */ + public function pageForIds( + string $customerId, + string $subscriptionId, + ?string $from = null, + ?int $limit = null, + $testmode = [] + ): PaymentCollection { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send((new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $query))->test($testmode)); + } + + /** + * Create an iterator for iterating over payments for the given subscription, retrieved from Mollie. + */ + public function iteratorFor( + Subscription $subscription, + ?string $from = null, + ?int $limit = null, + $testmode = [], + bool $iterateBackwards = false + ): LazyCollection { + return $this->iteratorForIds($subscription->customerId, $subscription->id, $from, $limit, $testmode, $iterateBackwards); + } + + /** + * Create an iterator for iterating over payments for the given subscription ID, retrieved from Mollie. + */ + public function iteratorForIds( + string $customerId, + string $subscriptionId, + ?string $from = null, + ?int $limit = null, + $testmode = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/TerminalEndpointCollection.php b/src/EndpointCollection/TerminalEndpointCollection.php new file mode 100644 index 000000000..d98ef49b5 --- /dev/null +++ b/src/EndpointCollection/TerminalEndpointCollection.php @@ -0,0 +1,77 @@ +send((new GetTerminalRequest($id))->test($testmode)); + } + + /** + * Retrieves a collection of Terminals from Mollie for the current organization / profile, ordered from newest to oldest. + * + * @param string|null $from The first terminal ID you want to include in your list. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, $testmode = []): TerminalCollection + { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + /** @var TerminalCollection */ + return $this->send((new GetPaginatedTerminalsRequest($query))->test($testmode)); + } + + /** + * Create an iterator for iterating over terminals retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + $testmode = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($testmode, 'testmode', false); + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedTerminalsRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/EndpointCollection/WalletEndpointCollection.php b/src/EndpointCollection/WalletEndpointCollection.php new file mode 100644 index 000000000..a3bf6967b --- /dev/null +++ b/src/EndpointCollection/WalletEndpointCollection.php @@ -0,0 +1,29 @@ + $domain, + 'validationUrl' => $validationUrl, + ], $parameters))->create(); + + /** @var string */ + return $this->send(new ApplePayPaymentSessionRequest($payload)); + } +} diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php deleted file mode 100644 index b4d851d05..000000000 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ /dev/null @@ -1,141 +0,0 @@ -createForId($customer->id, $options, $filters); - } - - /** - * Create a subscription for a Customer ID - * - * @param string $customerId - * @param array $options - * @param array $filters - * - * @return Payment - * @throws ApiException - */ - public function createForId($customerId, array $options = [], array $filters = []) - { - $this->parentId = $customerId; - - /** @var Payment */ - return $this->createResource($options, $filters); - } - - /** - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return PaymentCollection - * @throws ApiException - */ - public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection - { - return $this->listForId($customer->id, $from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over payments for the given customer, retrieved from Mollie. - * - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - Customer $customer, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return PaymentCollection - * @throws ApiException - */ - public function listForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection - { - $this->parentId = $customerId; - - /** @var PaymentCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over payments for the given customer id, retrieved from Mollie. - * - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $customerId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $customerId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php deleted file mode 100644 index 8ea206fe8..000000000 --- a/src/Endpoints/InvoiceEndpoint.php +++ /dev/null @@ -1,93 +0,0 @@ -readResource($invoiceId, $parameters); - } - - /** - * Retrieves a collection of Invoices from Mollie. - * - * @param string $from The first invoice ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return InvoiceCollection - * @throws ApiException - */ - public function page(string $from = null, int $limit = null, array $parameters = []): InvoiceCollection - { - /** @var InvoiceCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * This is a wrapper method for page - * - * @param array $parameters - * - * @return InvoiceCollection - * @throws ApiException - */ - public function all(array $parameters = []): InvoiceCollection - { - return $this->page(null, null, $parameters); - } - - /** - * Create an iterator for iterating over invoices retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php deleted file mode 100644 index e07857f18..000000000 --- a/src/Endpoints/MandateEndpoint.php +++ /dev/null @@ -1,194 +0,0 @@ -createForId($customer->id, $options, $filters); - } - - /** - * @param string $customerId - * @param array $options - * @param array $filters - * - * @return Mandate - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $customerId, array $options = [], array $filters = []): Mandate - { - $this->parentId = $customerId; - - /** @var Mandate */ - return $this->createResource($options, $filters); - } - - /** - * @param Customer $customer - * @param string $mandateId - * @param array $parameters - * - * @return Mandate - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getFor(Customer $customer, $mandateId, array $parameters = []): Mandate - { - return $this->getForId($customer->id, $mandateId, $parameters); - } - - /** - * @param string $customerId - * @param string $mandateId - * @param array $parameters - * - * @return Mandate - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForId(string $customerId, $mandateId, array $parameters = []) - { - $this->parentId = $customerId; - - /** @var Mandate */ - return $this->readResource($mandateId, $parameters); - } - - /** - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return MandateCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection - { - return $this->listForId($customer->id, $from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over mandates for the given customer, retrieved from Mollie. - * - * @param Customer $customer - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - Customer $customer, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $customerId - * @param ?string $from - * @param ?int $limit - * @param array $parameters - * - * @return MandateCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection - { - $this->parentId = $customerId; - - /** @var MandateCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over mandates for the given customer id, retrieved from Mollie. - * - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $customerId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $customerId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param Customer $customer - * @param string $mandateId - * @param array $data - * - * @return null|Mandate - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function revokeFor(Customer $customer, string $mandateId, array $data = []): ?Mandate - { - return $this->revokeForId($customer->id, $mandateId, $data); - } - - /** - * @param string $customerId - * @param string $mandateId - * @param array $data - * - * @return null|Mandate - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function revokeForId(string $customerId, string $mandateId, array $data = []): ?Mandate - { - $this->parentId = $customerId; - - /** @var null|Mandate */ - return $this->deleteResource($mandateId, $data); - } -} diff --git a/src/Endpoints/MethodEndpoint.php b/src/Endpoints/MethodEndpoint.php deleted file mode 100644 index d2aa1a531..000000000 --- a/src/Endpoints/MethodEndpoint.php +++ /dev/null @@ -1,84 +0,0 @@ -allActive($parameters); - } - - /** - * Retrieve all active methods for the organization. In test mode, this includes pending methods. - * The results are not paginated. - * - * - * @throws ApiException - */ - public function allActive(array $parameters = []): MethodCollection - { - /** @var MethodCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Retrieve all available methods for the organization, including activated and not yet activated methods. The - * results are not paginated. Make sure to include the profileId parameter if using an OAuth Access Token. - * - * @param array $parameters Query string parameters. - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function allAvailable(array $parameters = []): MethodCollection - { - $url = 'methods/all'.$this->buildQueryString($parameters); - - return $this - ->client - ->send(new DynamicGetRequest( - $url, - MethodCollection::class, - )); - } - - /** - * Retrieve a payment method from Mollie. - * - * Will throw a ApiException if the method id is invalid or the resource cannot be found. - * - * @throws ApiException - */ - public function get(string $methodId, array $parameters = []): Method - { - /** @var Method */ - return $this->readResource($methodId, $parameters); - } -} diff --git a/src/Endpoints/MethodIssuerEndpoint.php b/src/Endpoints/MethodIssuerEndpoint.php deleted file mode 100644 index ad90f4aa1..000000000 --- a/src/Endpoints/MethodIssuerEndpoint.php +++ /dev/null @@ -1,88 +0,0 @@ -profileId = $profileId; - $this->methodId = $methodId; - $this->issuerId = $issuerId; - - /** @var Issuer */ - $response = $this->createResource([], []); - - $this->resetResourceIds(); - - return $response; - } - - public function disable(string $profileId, string $methodId, string $issuerId) - { - $this->profileId = $profileId; - $this->methodId = $methodId; - - return $this->deleteResource($issuerId); - } - - protected function resetResourceIds() - { - $this->profileId = null; - $this->methodId = null; - $this->issuerId = null; - } - - /** - * @return string - * @throws ApiException - */ - public function getResourcePath(): string - { - if (!$this->profileId) { - throw new ApiException("No profileId provided."); - } - - if (!$this->methodId) { - throw new ApiException("No methodId provided."); - } - - $path = "profiles/{$this->profileId}/methods/{$this->methodId}/issuers"; - - if ($this->issuerId) { - $path .= "/$this->issuerId"; - } - - return $path; - } -} diff --git a/src/Endpoints/OnboardingEndpoint.php b/src/Endpoints/OnboardingEndpoint.php deleted file mode 100644 index 2a5f0bf6b..000000000 --- a/src/Endpoints/OnboardingEndpoint.php +++ /dev/null @@ -1,68 +0,0 @@ -readResource('', []); - } - - /** - * @deprecated 2023-05-01 For an alternative, see https://docs.mollie.com/reference/create-client-link . - * Submit data that will be prefilled in the merchant’s onboarding. - * Please note that the data you submit will only be processed when the onboarding status is needs-data. - * - * Information that the merchant has entered in their dashboard will not be overwritten. - * - * Will throw a ApiException if the resource cannot be found. - * - * @return void - * @throws ApiException - * @deprecated use ClientLinkEndpoint create() method - */ - public function submit(array $parameters = []): void - { - $this->create($parameters, []); - } - - /** - * @param array $body - * @param array $filters - * - * @return void - * @throws \Mollie\Api\Exceptions\ApiException - */ - private function create(array $body, array $filters): void - { - $this->createResource($body, $filters); - } -} diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php deleted file mode 100644 index 1d76ccf37..000000000 --- a/src/Endpoints/OrderEndpoint.php +++ /dev/null @@ -1,120 +0,0 @@ -createResource($data, $filters); - } - - /** - * Update a specific Order resource - * - * Will throw a ApiException if the order id is invalid or the resource cannot be found. - * - * - * @throws ApiException - */ - public function update(string $orderId, array $data = []): ?Order - { - $this->guardAgainstInvalidId($orderId); - - /** @var null|Order */ - return $this->updateResource($orderId, $data); - } - - /** - * Retrieve a single order from Mollie. - * - * Will throw a ApiException if the order id is invalid or the resource cannot - * be found. - * - * @throws ApiException - */ - public function get(string $orderId, array $parameters = []): Order - { - $this->guardAgainstInvalidId($orderId); - - /** @var Order */ - return $this->readResource($orderId, $parameters); - } - - /** - * Cancel the given Order. - * - * If the order was partially shipped, the status will be "completed" instead of - * "canceled". - * Will throw a ApiException if the order id is invalid or the resource cannot - * be found. - * Returns the canceled order with HTTP status 200. - * - * @param array $parameters - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancel(string $orderId, $parameters = []): ?Order - { - /** @var null|Order */ - return $this->deleteResource($orderId, $parameters); - } - - /** - * Retrieves a collection of Orders from Mollie. - * - * @param string $from The first order ID you want to include in your list. - * - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): OrderCollection - { - /** @var OrderCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over orders retrieved from Mollie. - * - * @param string $from The first order ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/OrderLineEndpoint.php b/src/Endpoints/OrderLineEndpoint.php deleted file mode 100644 index 5cdaa86da..000000000 --- a/src/Endpoints/OrderLineEndpoint.php +++ /dev/null @@ -1,114 +0,0 @@ -parentId = $orderId; - - $this->guardAgainstInvalidId($orderlineId); - - $response = $this->client->performHttpCall( - self::REST_UPDATE, - $this->getPathToSingleResource(urlencode($orderlineId)), - $this->parseRequestBody($data) - ); - - if ($response->isEmpty()) { - return null; - } - - /** @var Order */ - return ResourceFactory::createFromApiResult($this->client, $response, Order::class); - } - - /** - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function updateMultiple(string $orderId, array $operations, array $parameters = []): Order - { - if (empty($orderId)) { - throw new ApiException('Invalid resource id.'); - } - - $this->parentId = $orderId; - - $parameters['operations'] = $operations; - - $result = $this->client->performHttpCall( - self::REST_UPDATE, - "{$this->getResourcePath()}", - $this->parseRequestBody($parameters) - ); - - /** @var Order */ - return ResourceFactory::createFromApiResult($this->client, $result, Order::class); - } - - /** - * Cancel lines for the provided order. - * The data array must contain a lines array. - * You can pass an empty lines array if you want to cancel all eligible lines. - * - * - * @throws ApiException - */ - public function cancelFor(Order $order, array $data): void - { - $this->cancelForId($order->id, $data); - } - - /** - * Cancel lines for the provided order id. - * The data array must contain a lines array. - * You can pass an empty lines array if you want to cancel all eligible lines. - * - * - * @throws ApiException - */ - public function cancelForId(string $orderId, array $data): void - { - if (! isset($data['lines']) || ! is_array($data['lines'])) { - throw new ApiException('A lines array is required.'); - } - - $this->parentId = $orderId; - - $this->client->performHttpCall( - self::REST_DELETE, - "{$this->getResourcePath()}", - $this->parseRequestBody($data) - ); - } -} diff --git a/src/Endpoints/OrderPaymentEndpoint.php b/src/Endpoints/OrderPaymentEndpoint.php deleted file mode 100644 index 0eaa527c6..000000000 --- a/src/Endpoints/OrderPaymentEndpoint.php +++ /dev/null @@ -1,64 +0,0 @@ -createForId($order->id, $data, $filters); - } - - /** - * Creates a payment in Mollie for a specific order ID. - * - * @param string $orderId - * @param array $data An array containing details on the order payment. - * @param array $filters - * - * @return Payment - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $orderId, array $data, array $filters = []): Payment - { - $this->parentId = $orderId; - - /** @var Payment */ - return $this->createResource($data, $filters); - } -} diff --git a/src/Endpoints/OrderRefundEndpoint.php b/src/Endpoints/OrderRefundEndpoint.php deleted file mode 100644 index 7c3da894c..000000000 --- a/src/Endpoints/OrderRefundEndpoint.php +++ /dev/null @@ -1,91 +0,0 @@ -createForId($order->id, $data, $filters); - } - - /** - * Refund some order lines. You can provide an empty array for the - * "lines" data to refund all eligible lines for this order. - * - * @param string $orderId - * @param array $data - * @param array $filters - * - * @return Refund - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $orderId, array $data, array $filters = []): Refund - { - $this->parentId = $orderId; - - /** @var Refund */ - return $this->createResource($data, $filters); - } - - /** - * @param $orderId - * @param array $parameters - * @return RefundCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function pageForId($orderId, array $parameters = []): RefundCollection - { - $this->parentId = $orderId; - - /** @var RefundCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * @param Order $order - * @param array $parameters - * @return RefundCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function pageFor(Order $order, array $parameters = []): RefundCollection - { - return $this->pageForId($order->id, $parameters); - } -} diff --git a/src/Endpoints/OrderShipmentEndpoint.php b/src/Endpoints/OrderShipmentEndpoint.php deleted file mode 100644 index 872e82928..000000000 --- a/src/Endpoints/OrderShipmentEndpoint.php +++ /dev/null @@ -1,161 +0,0 @@ -createForId($order->id, $options, $filters); - } - - /** - * Create a shipment for some order lines. You can provide an empty array for the - * "lines" option to include all unshipped lines for this order. - * - * @param string $orderId - * @param array $options - * @param array $filters - * - * @return Shipment - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $orderId, array $options = [], array $filters = []): Shipment - { - $this->parentId = $orderId; - - /** @var Shipment */ - return $this->createResource($options, $filters); - } - - /** - * Retrieve a single shipment and the order lines shipped by a shipment’s ID. - * - * @param Order $order - * @param string $shipmentId - * @param array $parameters - * - * @return Shipment - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getFor(Order $order, string $shipmentId, array $parameters = []): Shipment - { - return $this->getForId($order->id, $shipmentId, $parameters); - } - - /** - * Retrieve a single shipment and the order lines shipped by a shipment’s ID. - * - * @param string $orderId - * @param string $shipmentId - * @param array $parameters - * - * @return Shipment - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForId(string $orderId, string $shipmentId, array $parameters = []): Shipment - { - $this->parentId = $orderId; - - /** @var Shipment */ - return $this->readResource($shipmentId, $parameters); - } - - /** - * Update a specific Order Shipment resource. - * - * Will throw an ApiException if the shipment id is invalid or the resource cannot be found. - * - * @param string $shipmentId - * @param string $orderId - * @param array $data - * - * @return null|Shipment - * @throws ApiException - */ - public function update(string $orderId, $shipmentId, array $data = []): ?Shipment - { - $this->guardAgainstInvalidId($shipmentId); - - $this->parentId = $orderId; - - /** @var null|Shipment */ - return $this->updateResource($shipmentId, $data); - } - - /** - * Return all shipments for the Order provided. - * - * @param Order $order - * @param array $parameters - * - * @return ShipmentCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listFor(Order $order, array $parameters = []): ShipmentCollection - { - return $this->listForId($order->id, $parameters); - } - - /** - * Return all shipments for the provided Order id. - * - * @param string $orderId - * @param array $parameters - * - * @return ShipmentCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $orderId, array $parameters = []): ShipmentCollection - { - $this->parentId = $orderId; - - /** @var ShipmentCollection */ - return $this->fetchCollection(null, null, $parameters); - } -} diff --git a/src/Endpoints/OrganizationPartnerEndpoint.php b/src/Endpoints/OrganizationPartnerEndpoint.php deleted file mode 100644 index b885ced54..000000000 --- a/src/Endpoints/OrganizationPartnerEndpoint.php +++ /dev/null @@ -1,38 +0,0 @@ -readResource('', []); - } -} diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php deleted file mode 100644 index 8f429fb3d..000000000 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ /dev/null @@ -1,165 +0,0 @@ -createForId($payment->id, $data, $filters); - } - - /** - * Creates a payment capture in Mollie. - * - * @param string $paymentId The payment's ID. - * @param array $data An array containing details on the capture. - * @param array $filters - * - * @return Capture - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $paymentId, array $data = [], array $filters = []): Capture - { - $this->parentId = $paymentId; - - /** @var Capture */ - return $this->createResource($data, $filters); - } - - /** - * @param Payment $payment - * @param string $captureId - * @param array $parameters - * - * @return Capture - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getFor(Payment $payment, string $captureId, array $parameters = []): Capture - { - return $this->getForId($payment->id, $captureId, $parameters); - } - - /** - * @param string $paymentId - * @param string $captureId - * @param array $parameters - * - * @return \Mollie\Api\Resources\Capture - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForId(string $paymentId, string $captureId, array $parameters = []): Capture - { - $this->parentId = $paymentId; - - /** @var Capture */ - return $this->readResource($captureId, $parameters); - } - - /** - * @param Payment $payment - * @param array $parameters - * - * @return CaptureCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listFor(Payment $payment, array $parameters = []): CaptureCollection - { - return $this->listForId($payment->id, $parameters); - } - - /** - * Create an iterator for iterating over captures for the given payment, retrieved from Mollie. - * - * @param Payment $payment - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - Payment $payment, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $paymentId - * @param array $parameters - * - * @return CaptureCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $paymentId, array $parameters = []): CaptureCollection - { - $this->parentId = $paymentId; - - /** @var CaptureCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Create an iterator for iterating over captures for the given payment id, retrieved from Mollie. - * - * @param string $paymentId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $paymentId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $paymentId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php deleted file mode 100644 index e7b9cc5d8..000000000 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ /dev/null @@ -1,133 +0,0 @@ -getForId($payment->id, $chargebackId, $parameters); - } - - /** - * @param string $paymentId - * @param string $chargebackId - * @param array $parameters - * - * @return Chargeback - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForId(string $paymentId, string $chargebackId, array $parameters = []): Chargeback - { - $this->parentId = $paymentId; - - /** @var Chargeback */ - return $this->readResource($chargebackId, $parameters); - } - - /** - * @param Payment $payment - * @param array $parameters - * - * @return ChargebackCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listFor(Payment $payment, array $parameters = []): ChargebackCollection - { - /** @var ChargebackCollection */ - return $this->listForId($payment->id, $parameters); - } - - /** - * Create an iterator for iterating over chargebacks for the given payment, retrieved from Mollie. - * - * @param Payment $payment - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - Payment $payment, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $paymentId - * @param array $parameters - * - * @return ChargebackCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $paymentId, array $parameters = []): ChargebackCollection - { - $this->parentId = $paymentId; - - /** @var ChargebackCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Create an iterator for iterating over chargebacks for the given payment id, retrieved from Mollie. - * - * @param string $paymentId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $paymentId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $paymentId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php deleted file mode 100644 index 067cbcb96..000000000 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ /dev/null @@ -1,135 +0,0 @@ -createResource($data, $filters); - } - - /** - * Retrieve payment link from Mollie. - * - * Will throw a ApiException if the payment link id is invalid or the resource cannot be found. - * - * @param string $paymentLinkId - * @param array $parameters - * @return PaymentLink - * @throws ApiException - */ - public function get(string $paymentLinkId, array $parameters = []): PaymentLink - { - $this->guardAgainstInvalidId($paymentLinkId); - - /** @var PaymentLink */ - return $this->readResource($paymentLinkId, $parameters); - } - - /** - * Update a Payment Link. - * - * @param string $paymentLinkId - * @param array $data - * @return null|PaymentLink - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function update(string $paymentLinkId, array $data): ?PaymentLink - { - $this->guardAgainstInvalidId($paymentLinkId); - - /** @var null|PaymentLink */ - return $this->updateResource($paymentLinkId, $data); - } - - /** - * Delete a Payment Link. - * - * @param string $paymentLinkId - * @param array $data - * @return void - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function delete(string $paymentLinkId, array $data = []): void - { - $this->guardAgainstInvalidId($paymentLinkId); - - $this->deleteResource($paymentLinkId, $data); - } - - /** - * Retrieves a collection of Payment Links from Mollie. - * - * @param string $from The first payment link ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return PaymentLinkCollection - * @throws ApiException - */ - public function page(string $from = null, int $limit = null, array $parameters = []): PaymentLinkCollection - { - /** @var PaymentLinkCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over payment links retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/PaymentLinkPaymentEndpoint.php b/src/Endpoints/PaymentLinkPaymentEndpoint.php deleted file mode 100644 index 99b9eee1d..000000000 --- a/src/Endpoints/PaymentLinkPaymentEndpoint.php +++ /dev/null @@ -1,96 +0,0 @@ -parentId = $paymentLinkId; - - return $this->fetchCollection($from, $limit, $filters); - } - - public function pageFor(PaymentLink $paymentLink, string $from = null, int $limit = null, array $filters = []) - { - return $this->pageForId($paymentLink->id, $from, $limit, $filters); - } - - /** - * Create an iterator for iterating over payments associated with the provided Payment Link id, retrieved from Mollie. - * - * @param string $paymentLinkId - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $paymentLinkId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $paymentLinkId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } - - /** - * Create an iterator for iterating over payments associated with the provided Payment Link object, retrieved from Mollie. - * - * @param PaymentLink $paymentLink - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - PaymentLink $paymentLink, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId( - $paymentLink->id, - $from, - $limit, - $parameters, - $iterateBackwards - ); - } -} diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php deleted file mode 100644 index fe9283870..000000000 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ /dev/null @@ -1,210 +0,0 @@ -getForId($payment->id, $refundId, $parameters); - } - - /** - * @param string $paymentId - * @param string $refundId - * @param array $parameters - * - * @return Refund - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function getForId(string $paymentId, $refundId, array $parameters = []): Refund - { - $this->parentId = $paymentId; - - /** @var Refund */ - return $this->readResource($refundId, $parameters); - } - - /** - * @param Payment $payment - * @param array $parameters - * - * @return RefundCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listFor(Payment $payment, array $parameters = []): RefundCollection - { - /** @var RefundCollection */ - return $this->listForId($payment->id, $parameters); - } - - /** - * Create an iterator for iterating over refunds for the given payment, retrieved from Mollie. - * - * @param Payment $payment - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorFor( - Payment $payment, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $paymentId - * @param array $parameters - * - * @return RefundCollection - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function listForId(string $paymentId, array $parameters = []): RefundCollection - { - $this->parentId = $paymentId; - - /** @var RefundCollection */ - return $this->fetchCollection(null, null, $parameters); - } - - /** - * Create an iterator for iterating over refunds for the given payment id, retrieved from Mollie. - * - * @param string $paymentId - * @param string|null $from The first resource ID you want to include in your list. - * @param int|null $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $paymentId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $paymentId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } - - - /** - * Creates a refund for a specific payment. - * - * @param Payment $payment - * @param array $data - * @param array $filters - * - * @return Refund - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createFor(Payment $payment, array $data, array $filters = []): Refund - { - return $this->createForId($payment->id, $data, $filters); - } - - /** - * Creates a refund for a specific payment. - * - * @param string $paymentId - * @param array $data - * @param array $filters - * - * @return Refund - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForId(string $paymentId, array $data, array $filters = []): Refund - { - $this->parentId = $paymentId; - - /** @var Refund */ - return $this->createResource($data, $filters); - } - - /** - * @param \Mollie\Api\Resources\Payment $payment - * @param string $refundId - * @param array $parameters - * @return null - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelForPayment(Payment $payment, string $refundId, array $parameters = []) - { - $this->parentId = $payment->id; - - return $this->cancelForId($payment->id, $refundId, $parameters); - } - - /** - * @param string $paymentId - * @param string $refundId - * @param array $parameters - * @return null - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelForId(string $paymentId, string $refundId, array $parameters = []) - { - $this->parentId = $paymentId; - - $body = null; - if (count($parameters) > 0) { - $body = json_encode($parameters); - } - - $this->client->performHttpCall( - EndpointAbstract::REST_DELETE, - $this->getResourcePath() . '/' . $refundId, - $body - ); - - $this->getResourcePath(); - - return null; - } -} diff --git a/src/Endpoints/PaymentRouteEndpoint.php b/src/Endpoints/PaymentRouteEndpoint.php deleted file mode 100644 index c1607682a..000000000 --- a/src/Endpoints/PaymentRouteEndpoint.php +++ /dev/null @@ -1,57 +0,0 @@ -updateReleaseDateForPaymentId($payment->id, $routeId, $releaseDate); - } - - /** - * @param string $paymentId - * @param string $routeId - * @param string $releaseDate - UTC datetime in ISO-8601 format when the funds for the following payment will become available on - * the balance of the connected account - * - * @return Route - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function updateReleaseDateForPaymentId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): ?Route - { - $this->parentId = $paymentId; - - /** @var Route */ - return $this->updateResource($routeId, [ - 'releaseDate' => $releaseDate, - 'testmode' => $testmode, - ]); - } -} diff --git a/src/Endpoints/PermissionEndpoint.php b/src/Endpoints/PermissionEndpoint.php deleted file mode 100644 index 3e8fe4139..000000000 --- a/src/Endpoints/PermissionEndpoint.php +++ /dev/null @@ -1,61 +0,0 @@ -readResource($permissionId, $parameters); - } - - /** - * Retrieve all permissions. - * - * @param array $parameters - * - * @return PermissionCollection - * @throws ApiException - */ - public function all(array $parameters = []): PermissionCollection - { - /** @var PermissionCollection */ - return $this->fetchCollection(null, null, $parameters); - } -} diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php deleted file mode 100644 index a83f48e31..000000000 --- a/src/Endpoints/ProfileEndpoint.php +++ /dev/null @@ -1,164 +0,0 @@ -createResource($data, $filters); - } - - /** - * Retrieve a Profile from Mollie. - * - * Will throw an ApiException if the profile id is invalid or the resource cannot be found. - * - * @param string $profileId - * @param array $parameters - * - * @return Profile - * @throws ApiException - */ - public function get($profileId, array $parameters = []): Profile - { - if ($profileId === 'me') { - return $this->getCurrent($parameters); - } - - /** @var Profile */ - return $this->readResource($profileId, $parameters); - } - - /** - * Update a specific Profile resource. - * - * Will throw an ApiException if the profile id is invalid or the resource cannot be found. - * - * @param string $profileId - * @param array $data - * @return null|Profile - * @throws ApiException - */ - public function update(string $profileId, array $data = []): ?Profile - { - $this->guardAgainstInvalidId($profileId); - - /** @var null|Profile */ - return $this->updateResource($profileId, $data); - } - - /** - * Retrieve the current Profile from Mollie. - * - * @param array $parameters - * - * @return CurrentProfile - * @throws ApiException - */ - public function getCurrent(array $parameters = []): CurrentProfile - { - static::$resource = CurrentProfile::class; - - /** @var CurrentProfile */ - return $this->readResource('me', $parameters); - } - - /** - * Delete a Profile from Mollie. - * - * Will throw a ApiException if the profile id is invalid or the resource cannot be found. - * Returns with HTTP status No Content (204) if successful. - * - * @param string $profileId - * - * @param array $data - * @return null|Profile - * @throws ApiException - */ - public function delete($profileId, array $data = []): ?Profile - { - /** @var null|Profile */ - return $this->deleteResource($profileId, $data); - } - - /** - * Retrieves a collection of Profiles from Mollie. - * - * @param string $from The first profile ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return ProfileCollection - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): ProfileCollection - { - /** @var ProfileCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over profiles retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator( - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php deleted file mode 100644 index b6f4623ac..000000000 --- a/src/Endpoints/RefundEndpoint.php +++ /dev/null @@ -1,67 +0,0 @@ -fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over refunds retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator( - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SessionEndpoint.php b/src/Endpoints/SessionEndpoint.php index 8f2d72ee8..0f30bf1d0 100644 --- a/src/Endpoints/SessionEndpoint.php +++ b/src/Endpoints/SessionEndpoint.php @@ -7,9 +7,9 @@ use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; -class SessionEndpoint extends CollectionEndpointAbstract +class SessionEndpoint extends EndpointCollection { - protected $resourcePath = "sessions"; + protected $resourcePath = 'sessions'; /** * @var string @@ -31,9 +31,8 @@ protected function getResourceObject() * Get the collection object that is used by this API endpoint. Every API * endpoint uses one type of collection object. * - * @param int $count - * @param \stdClass $_links - * + * @param int $count + * @param \stdClass $_links * @return SessionCollection */ protected function getResourceCollectionObject($count, $_links) @@ -44,15 +43,14 @@ protected function getResourceCollectionObject($count, $_links) /** * Creates a session in Mollie. * - * @param array $data An array containing details on the session. - * @param array $filters - * + * @param array $data An array containing details on the session. * @return Session + * * @throws ApiException */ public function create(array $data = [], array $filters = []) { - return $this->rest_create($data, $filters); + return $this->createResource($data, $filters); } /** @@ -60,19 +58,18 @@ public function create(array $data = [], array $filters = []) * * Will throw a ApiException if the resource id is invalid or the resource cannot be found. * - * @param string $resourceId - * - * @param array $data + * @param string $resourceId * @return Session + * * @throws ApiException */ public function update($resourceId, array $data = []) { if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '".self::RESOURCE_ID_PREFIX."'."); } - return parent::rest_update($resourceId, $data); + return $this->updateResource($resourceId, $data); } /** @@ -81,59 +78,54 @@ public function update($resourceId, array $data = []) * Will throw a ApiException if the resource id is invalid or the resource cannot * be found. * - * @param array $parameters * @return Session + * * @throws ApiException */ public function get($resourceId, array $parameters = []) { if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '".self::RESOURCE_ID_PREFIX."'."); } - return parent::rest_read($resourceId, $parameters); + return $this->readResource($resourceId, $parameters); } /** * Cancel the given Session. * - * @param string $resourceId - * @param array $parameters + * @param string $resourceId + * @param array $parameters * @return Session + * * @throws ApiException */ public function cancel($resourceId, $parameters = []) { - return $this->rest_delete($resourceId, $parameters); + return $this->deleteResource($resourceId, $parameters); } /** * Retrieves a collection of Sessions from Mollie. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * + * @param string $from The first resource ID you want to include in your list. * @return SessionCollection + * * @throws ApiException */ public function page(?string $from = null, ?int $limit = null, array $parameters = []) { - return $this->rest_list($from, $limit, $parameters); + return $this->fetchCollection($from, $limit, $parameters); } /** * Create an iterator for iterating over sessions retrieved from Mollie. * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse resource iteration (default is false). - * - * @return LazyCollection + * @param string $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse resource iteration (default is false). */ public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection { - return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + return $this->createIterator($from, $limit, $parameters, $iterateBackwards); } } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php deleted file mode 100644 index d9bc198ea..000000000 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ /dev/null @@ -1,75 +0,0 @@ -parentId = $settlementId; - - /** @var CaptureCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over captures for the given settlement id, retrieved from Mollie. - * - * @param string $settlementId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $settlementId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $settlementId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php deleted file mode 100644 index a3b3c82b0..000000000 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ /dev/null @@ -1,75 +0,0 @@ -parentId = $settlementId; - - /** @var ChargebackCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over chargeback for the given settlement id, retrieved from Mollie. - * - * @param string $settlementId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $settlementId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $settlementId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php deleted file mode 100644 index b600582da..000000000 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ /dev/null @@ -1,73 +0,0 @@ -parentId = $settlementId; - - /** @var PaymentCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over payments for the given settlement id, retrieved from Mollie. - * - * @param string $settlementId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $settlementId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $settlementId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php deleted file mode 100644 index a3f376088..000000000 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ /dev/null @@ -1,75 +0,0 @@ -parentId = $settlementId; - - /** @var RefundCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over refunds for the given settlement id, retrieved from Mollie. - * - * @param string $settlementId - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iteratorForId( - string $settlementId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $settlementId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php deleted file mode 100644 index 150fa39ad..000000000 --- a/src/Endpoints/SettlementsEndpoint.php +++ /dev/null @@ -1,104 +0,0 @@ -readResource($settlementId, $parameters); - } - - /** - * Retrieve the details of the current settlement that has not yet been paid out. - * - * @return Settlement - * @throws ApiException - */ - public function next(): Settlement - { - /** @var Settlement */ - return $this->readResource("next", []); - } - - /** - * Retrieve the details of the open balance of the organization. - * - * @return Settlement - * @throws ApiException - */ - public function open(): Settlement - { - /** @var Settlement */ - return $this->readResource("open", []); - } - - /** - * Retrieves a collection of Settlements from Mollie. - * - * @param string $from The first settlement ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return SettlementCollection - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): SettlementCollection - { - /** @var SettlementCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over settlements retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php deleted file mode 100644 index 19aeab70e..000000000 --- a/src/Endpoints/SubscriptionEndpoint.php +++ /dev/null @@ -1,208 +0,0 @@ -createForId($customer->id, $options, $filters); - } - - /** - * Create a subscription for a Customer - * - * - * @throws ApiException - */ - public function createForId(string $customerId, array $options = [], array $filters = []): Subscription - { - $this->parentId = $customerId; - - /** @var Subscription */ - return $this->createResource($options, $filters); - } - - /** - * Update a specific Subscription resource. - * - * Will throw an ApiException if the subscription id is invalid or the resource cannot be found. - * - * - * - * @throws ApiException - */ - public function update(string $customerId, string $subscriptionId, array $data = []): ?Subscription - { - $this->guardAgainstInvalidId($subscriptionId); - - $this->parentId = $customerId; - - /** @var null|Subscription */ - return $this->updateResource($subscriptionId, $data); - } - - /** - * @throws ApiException - */ - public function getFor(Customer $customer, string $subscriptionId, array $parameters = []): Subscription - { - return $this->getForId($customer->id, $subscriptionId, $parameters); - } - - /** - * @throws ApiException - */ - public function getForId(string $customerId, string $subscriptionId, array $parameters = []): Subscription - { - $this->parentId = $customerId; - - /** @var Subscription */ - return $this->readResource($subscriptionId, $parameters); - } - - /** - * @param string $from The first resource ID you want to include in your list. - * - * @throws ApiException - */ - public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection - { - return $this->listForId($customer->id, $from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over subscriptions for the given customer, retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - public function iteratorFor( - Customer $customer, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); - } - - /** - * @param string $customerId - * @param string $from The first resource ID you want to include in your list. - * - * @throws ApiException - */ - public function listForId($customerId, ?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection - { - $this->parentId = $customerId; - - /** @var SubscriptionCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over subscriptions for the given customer id, retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - public function iteratorForId( - string $customerId, - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - $this->parentId = $customerId; - - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } - - /** - * @throws ApiException - */ - public function cancelFor(Customer $customer, string $subscriptionId, array $data = []): ?Subscription - { - return $this->cancelForId($customer->id, $subscriptionId, $data); - } - - /** - * @throws ApiException - */ - public function cancelForId(string $customerId, string $subscriptionId, array $data = []): ?Subscription - { - $this->parentId = $customerId; - - /** @var null|Subscription */ - return $this->deleteResource($subscriptionId, $data); - } - - /** - * Retrieves a collection of Subscriptions from Mollie. - * - * @param string $from The first payment ID you want to include in your list. - * - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): SubscriptionCollection - { - $apiPath = 'subscriptions'.$this->buildQueryString( - $this->getMergedFilters($parameters, $from, $limit) - ); - - $result = $this->client->performHttpCall( - self::REST_LIST, - $apiPath - ); - - /** @var SubscriptionCollection */ - return $this->buildResultCollection($result->json()); - } - - /** - * Create an iterator for iterating over subscriptions retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - $page = $this->page($from, $limit, $parameters); - - return $page->getAutoIterator($iterateBackwards); - } -} diff --git a/src/Endpoints/SubscriptionPaymentEndpoint.php b/src/Endpoints/SubscriptionPaymentEndpoint.php deleted file mode 100644 index 92485a0ec..000000000 --- a/src/Endpoints/SubscriptionPaymentEndpoint.php +++ /dev/null @@ -1,76 +0,0 @@ -customerId = $customerId; - $this->subscriptionId = $subscriptionId; - - /** @var PaymentCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - public function getResourcePath(): string - { - if (is_null($this->customerId)) { - throw new ApiException('No customerId provided.'); - } - - if (is_null($this->subscriptionId)) { - throw new ApiException('No subscriptionId provided.'); - } - - return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments"; - } -} diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php deleted file mode 100644 index 5a55b67d2..000000000 --- a/src/Endpoints/TerminalEndpoint.php +++ /dev/null @@ -1,94 +0,0 @@ -guardAgainstInvalidId($terminalId); - - /** @var Terminal */ - return $this->readResource($terminalId, $parameters); - } - - /** - * Retrieves a collection of Terminals from Mollie for the current organization / profile, ordered from newest to oldest. - * - * @param string $from The first terminal ID you want to include in your list. - * @param int $limit - * @param array $parameters - * - * @return TerminalCollection - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []): TerminalCollection - { - /** @var TerminalCollection */ - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over terminals retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param int $limit - * @param array $parameters - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - * - * @return LazyCollection - */ - public function iterator( - ?string $from = null, - ?int $limit = null, - array $parameters = [], - bool $iterateBackwards = false - ): LazyCollection { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Endpoints/WalletEndpoint.php b/src/Endpoints/WalletEndpoint.php deleted file mode 100644 index 4af80c2ff..000000000 --- a/src/Endpoints/WalletEndpoint.php +++ /dev/null @@ -1,32 +0,0 @@ -parseRequestBody(array_merge([ - 'domain' => $domain, - 'validationUrl' => $validationUrl, - ], $parameters)); - - $response = $this->client->performHttpCall( - self::REST_CREATE, - 'wallets/applepay/sessions', - $body - ); - - return $response->body(); - } -} diff --git a/src/Exceptions/CurlConnectTimeoutException.php b/src/Exceptions/CurlConnectTimeoutException.php index ab40ca1bc..8b011d5c1 100644 --- a/src/Exceptions/CurlConnectTimeoutException.php +++ b/src/Exceptions/CurlConnectTimeoutException.php @@ -2,6 +2,4 @@ namespace Mollie\Api\Exceptions; -class CurlConnectTimeoutException extends ApiException -{ -} +class CurlConnectTimeoutException extends ApiException {} diff --git a/src/Exceptions/EmbeddedResourcesNotParseableException.php b/src/Exceptions/EmbeddedResourcesNotParseableException.php index 7042278fb..611d7fccf 100644 --- a/src/Exceptions/EmbeddedResourcesNotParseableException.php +++ b/src/Exceptions/EmbeddedResourcesNotParseableException.php @@ -2,6 +2,4 @@ namespace Mollie\Api\Exceptions; -class EmbeddedResourcesNotParseableException extends ApiException -{ -} +class EmbeddedResourcesNotParseableException extends ApiException {} diff --git a/src/Exceptions/HttpAdapterDoesNotSupportDebuggingException.php b/src/Exceptions/HttpAdapterDoesNotSupportDebuggingException.php index 3970a3b33..9becc22a5 100644 --- a/src/Exceptions/HttpAdapterDoesNotSupportDebuggingException.php +++ b/src/Exceptions/HttpAdapterDoesNotSupportDebuggingException.php @@ -2,6 +2,4 @@ namespace Mollie\Api\Exceptions; -class HttpAdapterDoesNotSupportDebuggingException extends ApiException -{ -} +class HttpAdapterDoesNotSupportDebuggingException extends ApiException {} diff --git a/src/Exceptions/IncompatiblePlatform.php b/src/Exceptions/IncompatiblePlatform.php index 72f494bfe..cd5534c66 100644 --- a/src/Exceptions/IncompatiblePlatform.php +++ b/src/Exceptions/IncompatiblePlatform.php @@ -5,8 +5,12 @@ class IncompatiblePlatform extends ApiException { public const INCOMPATIBLE_PHP_VERSION = 1000; + public const INCOMPATIBLE_CURL_EXTENSION = 2000; + public const INCOMPATIBLE_CURL_FUNCTION = 2500; + public const INCOMPATIBLE_JSON_EXTENSION = 3000; + public const INCOMPATIBLE_RANDOM_BYTES_FUNCTION = 4000; } diff --git a/src/Exceptions/RequestValidationException.php b/src/Exceptions/RequestValidationException.php deleted file mode 100644 index f9d4bc202..000000000 --- a/src/Exceptions/RequestValidationException.php +++ /dev/null @@ -1,5 +0,0 @@ -get('domain'), + $this->get('validationUrl'), + $this->get('profileId'), + ); + } +} diff --git a/src/Factories/CreateCustomerPayloadFactory.php b/src/Factories/CreateCustomerPayloadFactory.php index 0e042b2e9..ff8eea25f 100644 --- a/src/Factories/CreateCustomerPayloadFactory.php +++ b/src/Factories/CreateCustomerPayloadFactory.php @@ -14,7 +14,6 @@ public function create(): CreateCustomerPayload $this->get('email'), $this->get('locale'), $this->mapIfNotNull('metadata', Metadata::class), - $this->get('testmode') ); } } diff --git a/src/Factories/CreateMandatePayloadFactory.php b/src/Factories/CreateMandatePayloadFactory.php new file mode 100644 index 000000000..fe0eeb44a --- /dev/null +++ b/src/Factories/CreateMandatePayloadFactory.php @@ -0,0 +1,28 @@ +has(['method', 'consumerName'])) { + throw new \InvalidArgumentException('Method and consumerName are required for creating a mandate'); + } + + return new CreateMandatePayload( + $this->get('method'), + $this->get('consumerName'), + $this->get('consumerAccount'), + $this->get('consumerBic'), + $this->get('consumerEmail'), + $this->mapIfNotNull('signatureDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->get('mandateReference'), + $this->get('paypalBillingAgreementId'), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/CreatePaymentCapturePayloadFactory.php b/src/Factories/CreatePaymentCapturePayloadFactory.php new file mode 100644 index 000000000..b1795d2bb --- /dev/null +++ b/src/Factories/CreatePaymentCapturePayloadFactory.php @@ -0,0 +1,18 @@ +get('description'), + $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('metadata', Metadata::class) + ); + } +} diff --git a/src/Factories/CreatePaymentLinkPayloadFactory.php b/src/Factories/CreatePaymentLinkPayloadFactory.php new file mode 100644 index 000000000..269537597 --- /dev/null +++ b/src/Factories/CreatePaymentLinkPayloadFactory.php @@ -0,0 +1,21 @@ +get('description'), + $this->mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), + $this->get('redirectUrl'), + $this->get('webhookUrl'), + $this->get('profileId'), + $this->get('reusable'), + $this->get('expiresAt'), + ); + } +} diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index 8a2464905..96cfade12 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -44,7 +44,6 @@ public function create(): CreatePaymentPayload $this->get('customerId'), $this->get('profileId'), $this->get('additional') ?? Helpers::filterByProperties(CreatePaymentPayload::class, $this->data), - $this->get('testmode') ); } } diff --git a/src/Factories/CreateProfilePayloadFactory.php b/src/Factories/CreateProfilePayloadFactory.php new file mode 100644 index 000000000..1d018b55d --- /dev/null +++ b/src/Factories/CreateProfilePayloadFactory.php @@ -0,0 +1,21 @@ +get('name'), + website: $this->get('website'), + email: $this->get('email'), + phone: $this->get('phone'), + description: $this->get('description'), + countriesOfActivity: $this->get('countriesOfActivity'), + businessCategory: $this->get('businessCategory') + ); + } +} diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php index 9404a546c..ad8e03db2 100644 --- a/src/Factories/CreateRefundPaymentPayloadFactory.php +++ b/src/Factories/CreateRefundPaymentPayloadFactory.php @@ -19,7 +19,6 @@ public function create(): CreateRefundPaymentPayload 'routingReversals', fn (array $items) => RefundRouteCollectionFactory::new($items)->create() ), - $this->get('testmode') ); } } diff --git a/src/Factories/CreateSubscriptionPayloadFactory.php b/src/Factories/CreateSubscriptionPayloadFactory.php new file mode 100644 index 000000000..2e55fe61a --- /dev/null +++ b/src/Factories/CreateSubscriptionPayloadFactory.php @@ -0,0 +1,28 @@ +get('amount'))->create(), + $this->get('interval'), + $this->get('description'), + $this->get('status'), + $this->get('times'), + $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->get('method'), + $this->mapIfNotNull('applicationFee', fn (array $fee) => ApplicationFeeFactory::new($fee)->create()), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('webhookUrl'), + $this->get('mandateId'), + $this->get('profileId'), + ); + } +} diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index cc7f8d2f1..6143cf4e2 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -20,9 +20,27 @@ public static function new(array $data): self return new static($data); } - protected function get(string $key, $default = null): mixed + /** + * Get a value from the data array or the backup key. + * + * @param string|array $key + * @param mixed $default + */ + protected function get($key, $default = null, $backupKey = 'filters.'): mixed { - return Arr::get($this->data, $key, $default); + $keys = (array) $key; + + if ($backupKey !== null) { + $keys[] = $backupKey.$key; + } + + foreach ($keys as $key) { + if ($value = Arr::get($this->data, $key, $default)) { + return $value; + } + } + + return $default; } protected function has($keys): bool @@ -33,12 +51,13 @@ protected function has($keys): bool /** * Map a value to a new form if it is not null. * - * @param string $key The key to retrieve the value from the data array. + * @param string|array $key The key to retrieve the value from the data array. * @param callable|string $composable A callable function to transform the value, or the name of a class to instantiate. + * @param string $backupKey The key to retrieve the value from the data array if the first key is null. * @return mixed The transformed value, a new class instance, or null if the value is null. */ - protected function mapIfNotNull(string $key, $composable): mixed + protected function mapIfNotNull($key, $composable, $backupKey = 'filters.'): mixed { - return Helpers::compose($this->get($key), $composable); + return Helpers::compose($this->get($key, null, $backupKey), $composable); } } diff --git a/src/Factories/GetAllMethodsQueryFactory.php b/src/Factories/GetAllMethodsQueryFactory.php new file mode 100644 index 000000000..b7affa211 --- /dev/null +++ b/src/Factories/GetAllMethodsQueryFactory.php @@ -0,0 +1,17 @@ +get('locale'), + $this->get('include', []), + $this->mapIfNotNull('amount', MoneyFactory::class) + ); + } +} diff --git a/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php b/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php new file mode 100644 index 000000000..2264597a6 --- /dev/null +++ b/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php @@ -0,0 +1,19 @@ + $this->get('from'), + 'limit' => $this->get('limit'), + ])->create(), + $this->get('profileId') + ); + } +} diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php index 387114e14..54c805a1b 100644 --- a/src/Factories/GetBalanceReportQueryFactory.php +++ b/src/Factories/GetBalanceReportQueryFactory.php @@ -17,7 +17,6 @@ public function create(): GetBalanceReportQuery DateTimeImmutable::createFromFormat('Y-m-d', $this->get('from')), DateTimeImmutable::createFromFormat('Y-m-d', $this->get('until')), $this->get('grouping'), - $this->get('testmode') ); } } diff --git a/src/Factories/GetEnabledMethodsQueryFactory.php b/src/Factories/GetEnabledMethodsQueryFactory.php new file mode 100644 index 000000000..33d973e0a --- /dev/null +++ b/src/Factories/GetEnabledMethodsQueryFactory.php @@ -0,0 +1,25 @@ +get('sequenceType', MethodQuery::SEQUENCE_TYPE_ONEOFF), + $this->get('resource', MethodQuery::RESOURCE_PAYMENTS), + $this->get('locale'), + $this->mapIfNotNull('amount', MoneyFactory::class), + $this->get('billingCountry'), + $this->get('includeWallets'), + $this->get('orderLineCategories', []), + $this->get('profileId'), + $this->get('include', []), + $this->get('testmode') + ); + } +} diff --git a/src/Factories/GetPaginatedBalanceQueryFactory.php b/src/Factories/GetPaginatedBalanceQueryFactory.php index 30782dd84..cde0fb5ed 100644 --- a/src/Factories/GetPaginatedBalanceQueryFactory.php +++ b/src/Factories/GetPaginatedBalanceQueryFactory.php @@ -8,14 +8,9 @@ class GetPaginatedBalanceQueryFactory extends Factory { public function create(): GetPaginatedBalanceQuery { - $testmode = $this->get('filters.testmode'); - $currency = $this->get('filters.currency'); - return new GetPaginatedBalanceQuery( - $this->get('currency', $currency), - $this->get('from'), - $this->get('limit'), - $this->get('testmode', $testmode) + SortablePaginatedQueryFactory::new($this->data)->create(), + $this->get('currency') ); } } diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php index 0814cf1c3..6c47e1015 100644 --- a/src/Factories/GetPaginatedChargebackQueryFactory.php +++ b/src/Factories/GetPaginatedChargebackQueryFactory.php @@ -6,14 +6,20 @@ class GetPaginatedChargebackQueryFactory extends Factory { + private PaginatedQueryFactory $paginatedQueryFactory; + + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + $this->paginatedQueryFactory = new PaginatedQueryFactory($attributes); + } + public function create(): GetPaginatedChargebackQuery { return new GetPaginatedChargebackQuery( - $this->has('includePayment') || $this->get('filters.include') === 'payment', - $this->get('profileId', $this->get('filters.profileId')), - $this->get('from'), - $this->get('limit'), - $this->get('testmode', $this->get('filters.testmode')) + $this->paginatedQueryFactory->create(), + $this->get('includePayment', false), + $this->get('profileId') ); } } diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php index 5eb21c62d..0a5a0475c 100644 --- a/src/Factories/GetPaginatedClientQueryFactory.php +++ b/src/Factories/GetPaginatedClientQueryFactory.php @@ -6,12 +6,19 @@ class GetPaginatedClientQueryFactory extends Factory { + private PaginatedQueryFactory $paginatedQueryFactory; + + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + $this->paginatedQueryFactory = new PaginatedQueryFactory($attributes); + } + public function create(): GetPaginatedClientQuery { return new GetPaginatedClientQuery( - $this->get('embed', $this->get('filters.embed', [])), - $this->get('from'), - $this->get('limit'), + $this->paginatedQueryFactory->create(), + $this->get('embed', []) ); } } diff --git a/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php b/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php new file mode 100644 index 000000000..b0f7ca188 --- /dev/null +++ b/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php @@ -0,0 +1,16 @@ +data)->create(), + $this->get('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedInvoiceQueryFactory.php b/src/Factories/GetPaginatedInvoiceQueryFactory.php new file mode 100644 index 000000000..b33e04ed9 --- /dev/null +++ b/src/Factories/GetPaginatedInvoiceQueryFactory.php @@ -0,0 +1,29 @@ +paginatedQueryFactory = new PaginatedQueryFactory($attributes); + } + + public function create(): GetPaginatedInvoiceQuery + { + $reference = $this->get('filters.reference'); + $year = $this->get('filters.year'); + + return new GetPaginatedInvoiceQuery( + $this->paginatedQueryFactory->create(), + $this->get('reference', $reference), + $this->get('year', $year) + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php new file mode 100644 index 000000000..cbfb91bce --- /dev/null +++ b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php @@ -0,0 +1,18 @@ +get('filters.include', []); + + return new GetPaginatedPaymentCapturesQuery( + PaginatedQueryFactory::new($this->data)->create(), + $this->get('include', $include) + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php new file mode 100644 index 000000000..6146a1046 --- /dev/null +++ b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php @@ -0,0 +1,18 @@ +get('filters.include', []); + + return new GetPaginatedPaymentChargebacksQuery( + PaginatedQueryFactory::new($this->data)->create(), + $this->get('include', $include), + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php index b512f12b6..1af7b443d 100644 --- a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php @@ -9,10 +9,8 @@ class GetPaginatedPaymentRefundQueryFactory extends Factory public function create(): GetPaginatedPaymentRefundQuery { return new GetPaginatedPaymentRefundQuery( - $this->has('includePayment') || $this->get('filters.include') === 'payment', - $this->get('from'), - $this->get('limit'), - $this->get('testmode', $this->get('filters.testmode')) + PaginatedQueryFactory::new($this->data)->create(), + $this->get('includePayment', false) ); } } diff --git a/src/Factories/GetPaginatedRefundsQueryFactory.php b/src/Factories/GetPaginatedRefundsQueryFactory.php new file mode 100644 index 000000000..f35b89641 --- /dev/null +++ b/src/Factories/GetPaginatedRefundsQueryFactory.php @@ -0,0 +1,17 @@ +data)->create(), + $this->get('embed'), + $this->get('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php new file mode 100644 index 000000000..465d2fe62 --- /dev/null +++ b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php @@ -0,0 +1,16 @@ +data)->create(), + $this->get('include', []) + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php b/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php new file mode 100644 index 000000000..102f585cf --- /dev/null +++ b/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php @@ -0,0 +1,20 @@ +data)->create(), + $this->get('includePayment', false), + $this->get('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php new file mode 100644 index 000000000..009a82eb8 --- /dev/null +++ b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php @@ -0,0 +1,18 @@ +has(['filters.include', 'filters.includePayment']); + + return new GetPaginatedSettlementRefundsQuery( + PaginatedQueryFactory::new($this->data)->create(), + $this->get('includePayment', $includePayment) + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementsQueryFactory.php b/src/Factories/GetPaginatedSettlementsQueryFactory.php new file mode 100644 index 000000000..23f91401a --- /dev/null +++ b/src/Factories/GetPaginatedSettlementsQueryFactory.php @@ -0,0 +1,21 @@ +get('balanceId'); + + return new GetPaginatedSettlementsQuery( + PaginatedQueryFactory::new($this->data)->create(), + $this->get('filters.balanceId', $balanceId), + ); + } +} diff --git a/src/Factories/GetPaymentCaptureQueryFactory.php b/src/Factories/GetPaymentCaptureQueryFactory.php new file mode 100644 index 000000000..235f957b4 --- /dev/null +++ b/src/Factories/GetPaymentCaptureQueryFactory.php @@ -0,0 +1,15 @@ +get('include', []), + ); + } +} diff --git a/src/Factories/GetPaymentChargebackQueryFactory.php b/src/Factories/GetPaymentChargebackQueryFactory.php new file mode 100644 index 000000000..fcaef86d9 --- /dev/null +++ b/src/Factories/GetPaymentChargebackQueryFactory.php @@ -0,0 +1,16 @@ +get('include', []), + testmode: $this->get('testmode', null) + ); + } +} diff --git a/src/Factories/GetPaymentMethodQueryFactory.php b/src/Factories/GetPaymentMethodQueryFactory.php new file mode 100644 index 000000000..7b2c17f75 --- /dev/null +++ b/src/Factories/GetPaymentMethodQueryFactory.php @@ -0,0 +1,18 @@ +get('locale'), + $this->get('currency'), + $this->get('profileId'), + $this->get('include'), + ); + } +} diff --git a/src/Factories/GetPaymentRefundQueryFactory.php b/src/Factories/GetPaymentRefundQueryFactory.php index ce2023d7f..d509c30e1 100644 --- a/src/Factories/GetPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaymentRefundQueryFactory.php @@ -10,7 +10,6 @@ public function create(): GetPaymentRefundQuery { return new GetPaymentRefundQuery( $this->get('include', []), - $this->get('testmode') ); } } diff --git a/src/Factories/PaginatedQueryFactory.php b/src/Factories/PaginatedQueryFactory.php index 3afa55dca..d4c62fe6b 100644 --- a/src/Factories/PaginatedQueryFactory.php +++ b/src/Factories/PaginatedQueryFactory.php @@ -8,12 +8,9 @@ class PaginatedQueryFactory extends Factory { public function create(): PaginatedQuery { - $testmode = $this->get('filters.testmode'); - return new PaginatedQuery( $this->get('from'), $this->get('limit'), - $this->get('testmode', $testmode) ); } } diff --git a/src/Factories/SortablePaginatedQueryFactory.php b/src/Factories/SortablePaginatedQueryFactory.php index 53a16c2db..b964bf537 100644 --- a/src/Factories/SortablePaginatedQueryFactory.php +++ b/src/Factories/SortablePaginatedQueryFactory.php @@ -8,14 +8,10 @@ class SortablePaginatedQueryFactory extends Factory { public function create(): SortablePaginatedQuery { - $sort = $this->get('filters.sort'); - $testmode = $this->get('filters.testmode'); - return new SortablePaginatedQuery( $this->get('from'), $this->get('limit'), - $this->get('sort', $sort), - $this->get('testmode', $testmode) + $this->get('sort'), ); } } diff --git a/src/Factories/UpdatePaymentLinkPayloadFactory.php b/src/Factories/UpdatePaymentLinkPayloadFactory.php new file mode 100644 index 000000000..e1d12ebbc --- /dev/null +++ b/src/Factories/UpdatePaymentLinkPayloadFactory.php @@ -0,0 +1,16 @@ +get('description'), + $this->get('archived'), + ); + } +} diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php index f28d7f092..ba016f2dc 100644 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -20,7 +20,6 @@ public function create(): UpdatePaymentPayload $this->get('locale'), $this->get('restrictPaymentMethodsToCountry'), $this->get('additional') ?? Helpers::filterByProperties(UpdatePaymentPayload::class, $this->data), - $this->get('testmode') ); } } diff --git a/src/Factories/UpdatePaymentRoutePayloadFactory.php b/src/Factories/UpdatePaymentRoutePayloadFactory.php new file mode 100644 index 000000000..ea6c48417 --- /dev/null +++ b/src/Factories/UpdatePaymentRoutePayloadFactory.php @@ -0,0 +1,16 @@ +get('releaseDate')), + ); + } +} diff --git a/src/Factories/UpdateProfilePayloadFactory.php b/src/Factories/UpdateProfilePayloadFactory.php new file mode 100644 index 000000000..acda6c700 --- /dev/null +++ b/src/Factories/UpdateProfilePayloadFactory.php @@ -0,0 +1,22 @@ +get('name'), + website: $this->get('website'), + email: $this->get('email'), + phone: $this->get('phone'), + description: $this->get('description'), + countriesOfActivity: $this->get('countriesOfActivity'), + businessCategory: $this->get('businessCategory'), + mode: $this->get('mode') + ); + } +} diff --git a/src/Factories/UpdateSubscriptionPayloadFactory.php b/src/Factories/UpdateSubscriptionPayloadFactory.php new file mode 100644 index 000000000..ac08e6745 --- /dev/null +++ b/src/Factories/UpdateSubscriptionPayloadFactory.php @@ -0,0 +1,24 @@ +mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), + $this->get('description'), + $this->get('interval'), + $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->get('times'), + $this->mapIfNotNull('metadata', Metadata::class), + $this->get('webhookUrl'), + $this->get('mandateId') + ); + } +} diff --git a/src/Helpers/Validator.php b/src/Helpers/Validator.php deleted file mode 100644 index 33e852ea2..000000000 --- a/src/Helpers/Validator.php +++ /dev/null @@ -1,74 +0,0 @@ -rules(); - - [$validatableProperties, $propsWithRules] = $this->extractValidatableAndRules($provider, $rules); - - // Validate validatable properties - foreach ($validatableProperties as $property) { - $this->validate($property); - } - - // Merge additional rules with the rulesWithValues array - foreach ($additional as $key => $value) { - if (array_key_exists($key, $rules)) { - $propsWithRules[$key] = $value; - } - } - - // Validate properties with rules - foreach ($propsWithRules as $key => $value) { - $rules[$key]->validate($value, $provider, static function (string $message) { - throw new RequestValidationException($message); - }); - } - } - - private function extractValidatableAndRules($provider, array $rules): array - { - $validatableProperties = []; - $propsWithRules = []; - - /** @var ReflectionProperty $property */ - foreach (Helpers::getProperties($provider) as $property) { - if ($property->isStatic() || ! $property->isInitialized($provider)) { - continue; - } - - $value = $this->extractValue($provider, $property); - - if ($value === null) { - continue; - } - - if ($value instanceof ValidatableDataProvider) { - $validatableProperties[] = $value; - } elseif (array_key_exists($property->getName(), $rules)) { - $propsWithRules[$property->getName()] = $value; - } - } - - return [$validatableProperties, $propsWithRules]; - } - - private function extractValue($provider, ReflectionProperty $property) - { - $property->setAccessible(true); - - return $property->getValue($provider); - } -} diff --git a/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php b/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php index f705ad1da..2118dfec5 100644 --- a/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php +++ b/src/Http/Adapter/GuzzleRetryMiddlewareFactory.php @@ -21,9 +21,7 @@ class GuzzleRetryMiddlewareFactory public const DELAY_INCREASE_MS = 1000; /** - * @param bool $delay default to true, can be false to speed up tests - * - * @return callable + * @param bool $delay default to true, can be false to speed up tests */ public function retry(bool $delay = true): callable { @@ -36,8 +34,6 @@ public function retry(bool $delay = true): callable /** * Returns a method that takes the number of retries and returns the number of milliseconds * to wait - * - * @return callable */ private function getRetryDelay(): callable { @@ -48,8 +44,6 @@ private function getRetryDelay(): callable /** * Returns a method that returns zero milliseconds to wait - * - * @return callable */ private function getZeroRetryDelay(): callable { @@ -58,16 +52,13 @@ private function getZeroRetryDelay(): callable }; } - /** - * @return callable - */ private function newRetryDecider(): callable { return function ( $retries, Request $request, - Response $response = null, - TransferException $exception = null + ?Response $response = null, + ?TransferException $exception = null ) { if ($retries >= static::MAX_RETRIES) { return false; diff --git a/src/Http/Middleware/Hydrate.php b/src/Http/Middleware/Hydrate.php index aa8a33a06..152981a58 100644 --- a/src/Http/Middleware/Hydrate.php +++ b/src/Http/Middleware/Hydrate.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Http\Middleware; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\HandlesResourceCreation; @@ -11,7 +12,7 @@ class Hydrate public function __invoke(Response $response) { - if (! $response->getRequest()::$shouldAutoHydrate) { + if (! $response->getRequest()::$shouldAutoHydrate || !$response->getRequest() instanceof ResourceHydratableRequest) { return $response; } diff --git a/src/Http/Payload/Address.php b/src/Http/Payload/Address.php index 28ef08310..5b48cb3a1 100644 --- a/src/Http/Payload/Address.php +++ b/src/Http/Payload/Address.php @@ -63,7 +63,7 @@ public function __construct( public function data(): array { - return array_filter([ + return [ 'title' => $this->title, 'givenName' => $this->givenName, 'familyName' => $this->familyName, @@ -76,6 +76,6 @@ public function data(): array 'city' => $this->city, 'region' => $this->region, 'country' => $this->country, - ]); + ]; } } diff --git a/src/Http/Payload/CreateCustomerPayload.php b/src/Http/Payload/CreateCustomerPayload.php index 673be16b8..330149854 100644 --- a/src/Http/Payload/CreateCustomerPayload.php +++ b/src/Http/Payload/CreateCustomerPayload.php @@ -12,20 +12,16 @@ class CreateCustomerPayload extends DataBag public ?Metadata $metadata; - public ?bool $testmode; - public function __construct( ?string $name = null, ?string $email = null, ?string $locale = null, - ?Metadata $metadata = null, - ?bool $testmode = null + ?Metadata $metadata = null ) { $this->name = $name; $this->email = $email; $this->locale = $locale; $this->metadata = $metadata; - $this->testmode = $testmode; } public function data() @@ -35,7 +31,6 @@ public function data() 'email' => $this->email, 'locale' => $this->locale, 'metadata' => $this->metadata, - 'testmode' => $this->testmode, ]; } } diff --git a/src/Http/Payload/CreateMandatePayload.php b/src/Http/Payload/CreateMandatePayload.php new file mode 100644 index 000000000..a26230104 --- /dev/null +++ b/src/Http/Payload/CreateMandatePayload.php @@ -0,0 +1,58 @@ +method = $method; + $this->consumerName = $consumerName; + $this->consumerAccount = $consumerAccount; + $this->consumerBic = $consumerBic; + $this->consumerEmail = $consumerEmail; + $this->signatureDate = $signatureDate; + $this->mandateReference = $mandateReference; + $this->paypalBillingAgreementId = $paypalBillingAgreementId; + } + + public function data(): array + { + return [ + 'method' => $this->method, + 'consumerName' => $this->consumerName, + 'consumerAccount' => $this->consumerAccount, + 'consumerBic' => $this->consumerBic, + 'consumerEmail' => $this->consumerEmail, + 'signatureDate' => $this->signatureDate?->format('Y-m-d'), + 'mandateReference' => $this->mandateReference, + 'paypalBillingAgreementId' => $this->paypalBillingAgreementId, + ]; + } +} diff --git a/src/Http/Payload/CreatePaymentCapturePayload.php b/src/Http/Payload/CreatePaymentCapturePayload.php new file mode 100644 index 000000000..dfd5339cf --- /dev/null +++ b/src/Http/Payload/CreatePaymentCapturePayload.php @@ -0,0 +1,31 @@ +amount = $amount; + $this->description = $description; + $this->metadata = $metadata; + } + + public function data(): array + { + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'metadata' => $this->metadata, + ]; + } +} diff --git a/src/Http/Payload/CreatePaymentLinkPayload.php b/src/Http/Payload/CreatePaymentLinkPayload.php new file mode 100644 index 000000000..c131c3411 --- /dev/null +++ b/src/Http/Payload/CreatePaymentLinkPayload.php @@ -0,0 +1,53 @@ +description = $description; + $this->amount = $amount; + $this->redirectUrl = $redirectUrl; + $this->webhookUrl = $webhookUrl; + $this->profileId = $profileId; + $this->reusable = $reusable; + $this->expiresAt = $expiresAt; + } + + public function data(): array + { + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'redirectUrl' => $this->redirectUrl, + 'webhookUrl' => $this->webhookUrl, + 'profileId' => $this->profileId, + 'reusable' => $this->reusable, + 'expiresAt' => $this->expiresAt?->format('Y-m-d'), + ]; + } +} diff --git a/src/Http/Payload/CreatePaymentPayload.php b/src/Http/Payload/CreatePaymentPayload.php index 2aee4bf57..fbcd681a5 100644 --- a/src/Http/Payload/CreatePaymentPayload.php +++ b/src/Http/Payload/CreatePaymentPayload.php @@ -52,8 +52,6 @@ class CreatePaymentPayload extends DataBag public ?string $profileId; - public ?bool $testmode; - /** * Method specific data. * @@ -83,7 +81,6 @@ public function __construct( ?string $mandateId = null, ?string $customerId = null, ?string $profileId = null, - ?bool $testmode = null, array $additional = [] ) { $this->description = $description; @@ -108,7 +105,6 @@ public function __construct( $this->customerId = $customerId; $this->profileId = $profileId; $this->additional = $additional; - $this->testmode = $testmode; } public function data(): array diff --git a/src/Http/Payload/CreateProfilePayload.php b/src/Http/Payload/CreateProfilePayload.php new file mode 100644 index 000000000..2c865fe4a --- /dev/null +++ b/src/Http/Payload/CreateProfilePayload.php @@ -0,0 +1,51 @@ +name = $name; + $this->website = $website; + $this->email = $email; + $this->phone = $phone; + $this->description = $description; + $this->countriesOfActivity = $countriesOfActivity; + $this->businessCategory = $businessCategory; + } + + public function data(): array + { + return [ + 'name' => $this->name, + 'website' => $this->website, + 'email' => $this->email, + 'phone' => $this->phone, + 'description' => $this->description, + 'countriesOfActivity' => $this->countriesOfActivity, + 'businessCategory' => $this->businessCategory, + ]; + } +} diff --git a/src/Http/Payload/CreateRefundPaymentPayload.php b/src/Http/Payload/CreateRefundPaymentPayload.php index e16efd056..cb813bfaa 100644 --- a/src/Http/Payload/CreateRefundPaymentPayload.php +++ b/src/Http/Payload/CreateRefundPaymentPayload.php @@ -21,22 +21,18 @@ class CreateRefundPaymentPayload extends DataBag */ public ?DataCollection $routingReversals = null; - public ?bool $testmode = null; - public function __construct( string $description, Money $amount, ?Metadata $metadata = null, ?bool $reverseRouting = null, ?DataCollection $routingReversals = null, - ?bool $testmode = null ) { $this->description = $description; $this->amount = $amount; $this->metadata = $metadata; $this->reverseRouting = $reverseRouting; $this->routingReversals = $routingReversals; - $this->testmode = $testmode; } public function data(): array @@ -47,7 +43,6 @@ public function data(): array 'metadata' => $this->metadata, 'reverseRouting' => $this->reverseRouting, 'routingReversals' => $this->routingReversals, - 'testmode' => $this->testmode, ]; } } diff --git a/src/Http/Payload/CreateSubscriptionPayload.php b/src/Http/Payload/CreateSubscriptionPayload.php new file mode 100644 index 000000000..ad7faba6e --- /dev/null +++ b/src/Http/Payload/CreateSubscriptionPayload.php @@ -0,0 +1,78 @@ +amount = $amount; + $this->interval = $interval; + $this->description = $description; + $this->status = $status; + $this->times = $times; + $this->startDate = $startDate; + $this->method = $method; + $this->applicationFee = $applicationFee; + $this->metadata = $metadata; + $this->webhookUrl = $webhookUrl; + $this->mandateId = $mandateId; + $this->profileId = $profileId; + } + + public function data(): array + { + return [ + 'amount' => $this->amount, + 'interval' => $this->interval, + 'description' => $this->description, + 'status' => $this->status, + 'times' => $this->times, + 'startDate' => $this->startDate?->format('Y-m-d'), + 'method' => $this->method, + 'applicationFee' => $this->applicationFee, + 'metadata' => $this->metadata, + 'webhookUrl' => $this->webhookUrl, + 'mandateId' => $this->mandateId, + 'profileId' => $this->profileId, + ]; + } +} diff --git a/src/Http/Payload/DataBag.php b/src/Http/Payload/DataBag.php index 6e75bcf98..338261024 100644 --- a/src/Http/Payload/DataBag.php +++ b/src/Http/Payload/DataBag.php @@ -5,13 +5,10 @@ use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Contracts\DataProvider; use Mollie\Api\Contracts\DataResolver; -use Mollie\Api\Contracts\ValidatableDataProvider; -use Mollie\Api\Traits\HasRules; use Mollie\Api\Traits\ResolvesValues; -abstract class DataBag implements Arrayable, DataProvider, DataResolver, ValidatableDataProvider +abstract class DataBag implements Arrayable, DataProvider, DataResolver { - use HasRules; use ResolvesValues; public function toArray(): array diff --git a/src/Http/Payload/OrderLine.php b/src/Http/Payload/OrderLine.php index 1de25c7c0..113e6cffa 100644 --- a/src/Http/Payload/OrderLine.php +++ b/src/Http/Payload/OrderLine.php @@ -2,11 +2,6 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Rules\Included; -use Mollie\Api\Rules\Max; -use Mollie\Api\Rules\Min; -use Mollie\Api\Types\OrderLineType; - class OrderLine extends DataBag { public string $description; @@ -83,13 +78,4 @@ public function data(): array 'productUrl' => $this->productUrl, ]; } - - public function rules(): array - { - return [ - 'type' => Included::in(OrderLineType::class), - 'quantity' => Min::value(1), - 'sku' => Max::value(64), - ]; - } } diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php index 5b82812af..e468e6d5b 100644 --- a/src/Http/Payload/RecurringBillingCycle.php +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Payload; use DateTimeInterface; -use Mollie\Api\Rules\Matches; class RecurringBillingCycle extends DataBag { @@ -46,11 +45,4 @@ public function data(): array 'startDate' => $this->startDate->format('Y-m-d'), ]; } - - public function rules(): array - { - return [ - 'interval' => Matches::pattern('/^\d+ (months|weeks|days)$/'), - ]; - } } diff --git a/src/Http/Payload/RequestApplePayPaymentSessionPayload.php b/src/Http/Payload/RequestApplePayPaymentSessionPayload.php new file mode 100644 index 000000000..cdd550e50 --- /dev/null +++ b/src/Http/Payload/RequestApplePayPaymentSessionPayload.php @@ -0,0 +1,31 @@ +domain = $domain; + $this->validationUrl = $validationUrl; + $this->profileId = $profileId; + } + + public function data(): array + { + return [ + 'domain' => $this->domain, + 'validationUrl' => $this->validationUrl, + 'profileId' => $this->profileId, + ]; + } +} diff --git a/src/Http/Payload/UpdatePaymentLinkPayload.php b/src/Http/Payload/UpdatePaymentLinkPayload.php new file mode 100644 index 000000000..92c56b66d --- /dev/null +++ b/src/Http/Payload/UpdatePaymentLinkPayload.php @@ -0,0 +1,26 @@ +description = $description; + $this->archived = $archived; + } + + public function data(): array + { + return [ + 'description' => $this->description, + 'archived' => $this->archived, + ]; + } +} diff --git a/src/Http/Payload/UpdatePaymentPayload.php b/src/Http/Payload/UpdatePaymentPayload.php index f5774907a..1f390d3c4 100644 --- a/src/Http/Payload/UpdatePaymentPayload.php +++ b/src/Http/Payload/UpdatePaymentPayload.php @@ -27,8 +27,6 @@ class UpdatePaymentPayload extends DataBag */ public array $additional = []; - public ?bool $testmode; - public function __construct( ?string $description = null, ?string $redirectUrl = null, @@ -38,7 +36,6 @@ public function __construct( ?string $method = null, ?string $locale = null, ?string $restrictPaymentMethodsToCountry = null, - ?bool $testmode = null, array $additional = [] ) { $this->description = $description; @@ -50,7 +47,6 @@ public function __construct( $this->locale = $locale; $this->restrictPaymentMethodsToCountry = $restrictPaymentMethodsToCountry; $this->additional = $additional; - $this->testmode = $testmode; } public function data(): array @@ -64,7 +60,6 @@ public function data(): array 'method' => $this->method, 'locale' => $this->locale, 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, - 'testmode' => $this->testmode, ], $this->additional); } } diff --git a/src/Http/Payload/UpdatePaymentRoutePayload.php b/src/Http/Payload/UpdatePaymentRoutePayload.php new file mode 100644 index 000000000..967e14ada --- /dev/null +++ b/src/Http/Payload/UpdatePaymentRoutePayload.php @@ -0,0 +1,23 @@ +releaseDate = $releaseDate; + } + + public function data(): array + { + return [ + 'releaseDate' => $this->releaseDate->format('Y-m-d'), + ]; + } +} diff --git a/src/Http/Payload/UpdateProfilePayload.php b/src/Http/Payload/UpdateProfilePayload.php new file mode 100644 index 000000000..ebe735c25 --- /dev/null +++ b/src/Http/Payload/UpdateProfilePayload.php @@ -0,0 +1,56 @@ +name = $name; + $this->website = $website; + $this->email = $email; + $this->phone = $phone; + $this->description = $description; + $this->countriesOfActivity = $countriesOfActivity; + $this->businessCategory = $businessCategory; + $this->mode = $mode; + } + + public function data(): array + { + return [ + 'name' => $this->name, + 'website' => $this->website, + 'email' => $this->email, + 'phone' => $this->phone, + 'description' => $this->description, + 'countriesOfActivity' => $this->countriesOfActivity, + 'businessCategory' => $this->businessCategory, + 'mode' => $this->mode, + ]; + } +} diff --git a/src/Http/Payload/UpdateSubscriptionPayload.php b/src/Http/Payload/UpdateSubscriptionPayload.php new file mode 100644 index 000000000..76cb09ad8 --- /dev/null +++ b/src/Http/Payload/UpdateSubscriptionPayload.php @@ -0,0 +1,58 @@ +amount = $amount; + $this->description = $description; + $this->interval = $interval; + $this->startDate = $startDate; + $this->times = $times; + $this->metadata = $metadata; + $this->webhookUrl = $webhookUrl; + $this->mandateId = $mandateId; + } + + public function data(): array + { + return [ + 'amount' => $this->amount, + 'description' => $this->description, + 'interval' => $this->interval, + 'startDate' => $this->startDate?->format('Y-m-d'), + 'times' => $this->times, + 'metadata' => $this->metadata, + 'webhookUrl' => $this->webhookUrl, + 'mandateId' => $this->mandateId, + ]; + } +} diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index 63e986b91..6552476f8 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -5,6 +5,8 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Contracts\HasResponse; use Mollie\Api\Contracts\PayloadRepository; +use Mollie\Api\Contracts\SupportsTestmodeInPayload; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Helpers\MiddlewarePriority; use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; @@ -13,11 +15,12 @@ use Mollie\Api\Http\Middleware\Hydrate; use Mollie\Api\Http\Middleware\ResetIdempotencyKey; use Mollie\Api\Http\Middleware\ThrowExceptionIfRequestFailed; +use Mollie\Api\Http\PendingRequest\AddTestmodeIfEnabled; use Mollie\Api\Http\PendingRequest\AuthenticateRequest; use Mollie\Api\Http\PendingRequest\MergeRequestProperties; +use Mollie\Api\Http\PendingRequest\RemoveTestmodeFromApiAuthenticatedRequests; use Mollie\Api\Http\PendingRequest\SetBody; use Mollie\Api\Http\PendingRequest\SetUserAgent; -use Mollie\Api\Http\PendingRequest\ValidateProperties; use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\ManagesPsrRequests; @@ -55,15 +58,20 @@ public function __construct(Connector $connector, Request $request) $this ->tap(new MergeRequestProperties) - ->tap(new ValidateProperties) + ->tap(new AddTestmodeIfEnabled) ->tap(new SetBody) ->tap(new SetUserAgent) - ->tap(new AuthenticateRequest); + ->tap(new AuthenticateRequest) + ->tap(new RemoveTestmodeFromApiAuthenticatedRequests); $this ->middleware() + + /** On request */ ->onRequest(new EvaluateHydrationSetting, 'hydration') ->onRequest(new ApplyIdempotencyKey, 'idempotency') + + /** On response */ ->onResponse(new ResetIdempotencyKey, 'idempotency') ->onResponse(new GuardResponse, MiddlewarePriority::HIGH) ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH) @@ -71,6 +79,17 @@ public function __construct(Connector $connector, Request $request) } + public function setTestmode(bool $testmode): self + { + if ($this->request instanceof SupportsTestmodeInQuery) { + $this->query()->add('testmode', $testmode); + } elseif ($this->request instanceof SupportsTestmodeInPayload) { + $this->payload()->add('testmode', $testmode); + } + + return $this; + } + public function setPayload(PayloadRepository $bodyRepository): self { $this->payload = $bodyRepository; diff --git a/src/Http/PendingRequest/AddTestmodeIfEnabled.php b/src/Http/PendingRequest/AddTestmodeIfEnabled.php new file mode 100644 index 000000000..f19760fc6 --- /dev/null +++ b/src/Http/PendingRequest/AddTestmodeIfEnabled.php @@ -0,0 +1,19 @@ +getConnector(); + + if ($connector->getTestmode() || $pendingRequest->getRequest()->getTestmode()) { + $pendingRequest->setTestmode(true); + } + + return $pendingRequest; + } +} diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php index f361e4547..2fd310f5d 100644 --- a/src/Http/PendingRequest/AuthenticateRequest.php +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -17,26 +17,8 @@ public function __invoke(PendingRequest $pendingRequest): PendingRequest throw new ApiException('You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.'); } - /** - * Remove testmode parameter from the request if authenticated via ApiKey. - */ - if ($authenticator instanceof ApiKeyAuthenticator) { - $this->removeTestmode($pendingRequest); - } - $authenticator->authenticate($pendingRequest); return $pendingRequest; } - - private function removeTestmode(PendingRequest $pendingRequest): void - { - if ($pendingRequest->query()->has('testmode')) { - $pendingRequest->query()->remove('testmode'); - } - - if ($pendingRequest->getRequest() instanceof HasPayload) { - $pendingRequest->payload()->remove('testmode'); - } - } } diff --git a/src/Http/PendingRequest/RemoveTestmodeFromApiAuthenticatedRequests.php b/src/Http/PendingRequest/RemoveTestmodeFromApiAuthenticatedRequests.php new file mode 100644 index 000000000..726e33f18 --- /dev/null +++ b/src/Http/PendingRequest/RemoveTestmodeFromApiAuthenticatedRequests.php @@ -0,0 +1,33 @@ +getConnector()->getAuthenticator(); + + if ($authenticator instanceof ApiKeyAuthenticator) { + $this->removeTestmode($pendingRequest); + } + + return $pendingRequest; + } + + private function removeTestmode(PendingRequest $pendingRequest): void + { + if ($pendingRequest->getRequest() instanceof SupportsTestmodeInQuery) { + $pendingRequest->query()->remove('testmode'); + } + + if ($pendingRequest->getRequest() instanceof SupportsTestmodeInPayload) { + $pendingRequest->payload()->remove('testmode'); + } + } +} diff --git a/src/Http/PendingRequest/ValidateProperties.php b/src/Http/PendingRequest/ValidateProperties.php deleted file mode 100644 index 04010e9a3..000000000 --- a/src/Http/PendingRequest/ValidateProperties.php +++ /dev/null @@ -1,21 +0,0 @@ -getRequest(); - - Validator::make()->validate( - $request, - $pendingRequest->query()->all() - ); - - return $pendingRequest; - } -} diff --git a/src/Http/Query/CreatePaymentQuery.php b/src/Http/Query/CreatePaymentQuery.php index cd0835a73..fa691e119 100644 --- a/src/Http/Query/CreatePaymentQuery.php +++ b/src/Http/Query/CreatePaymentQuery.php @@ -2,9 +2,7 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Rules\Included; use Mollie\Api\Traits\ComposableFromArray; -use Mollie\Api\Types\PaymentQuery; class CreatePaymentQuery extends Query { @@ -24,11 +22,4 @@ public function toArray(): array 'include' => $this->include, ]; } - - public function rules(): array - { - return [ - 'include' => Included::in([PaymentQuery::INCLUDE_QR_CODE]), - ]; - } } diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php new file mode 100644 index 000000000..9137229b0 --- /dev/null +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -0,0 +1,34 @@ +locale = $locale; + $this->include = $include; + $this->amount = $amount; + } + + public function toArray(): array + { + return [ + 'include' => Arr::join($this->include), + 'locale' => $this->locale, + 'amount' => $this->amount?->data(), + ]; + } +} diff --git a/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php b/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php new file mode 100644 index 000000000..9576683a9 --- /dev/null +++ b/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php @@ -0,0 +1,23 @@ +paginatedQuery = $paginatedQuery; + $this->profileId = $profileId; + } + + public function toArray(): array + { + return array_merge($this->paginatedQuery->toArray(), [ + 'profileId' => $this->profileId, + ]); + } +} diff --git a/src/Http/Query/GetBalanceReportQuery.php b/src/Http/Query/GetBalanceReportQuery.php index 36f58928f..f469e9983 100644 --- a/src/Http/Query/GetBalanceReportQuery.php +++ b/src/Http/Query/GetBalanceReportQuery.php @@ -12,18 +12,14 @@ class GetBalanceReportQuery extends Query public ?string $grouping; - public ?bool $testmode; - public function __construct( DateTimeInterface $from, DateTimeInterface $until, ?string $grouping = null, - ?bool $testmode = null ) { $this->from = $from; $this->until = $until; $this->grouping = $grouping; - $this->testmode = $testmode; } public function toArray(): array @@ -32,7 +28,6 @@ public function toArray(): array 'from' => $this->from->format('Y-m-d'), 'until' => $this->until->format('Y-m-d'), 'grouping' => $this->grouping, - 'testmode' => $this->testmode, ]; } } diff --git a/src/Http/Query/GetEnabledMethodsQuery.php b/src/Http/Query/GetEnabledMethodsQuery.php new file mode 100644 index 000000000..fd36a45b2 --- /dev/null +++ b/src/Http/Query/GetEnabledMethodsQuery.php @@ -0,0 +1,37 @@ + $this->sequenceType, + 'locale' => $this->locale, + 'amount' => $this->amount?->data(), + 'resource' => $this->resource, + 'billingCountry' => $this->billingCountry, + 'includeWallets' => Arr::join($this->includeWallets), + 'orderLineCategories' => Arr::join($this->orderLineCategories), + 'profileId' => $this->profileId, + 'include' => Arr::join($this->include), + ]; + } +} diff --git a/src/Http/Query/GetPaginatedBalanceQuery.php b/src/Http/Query/GetPaginatedBalanceQuery.php index 14e5315d8..7e23d507f 100644 --- a/src/Http/Query/GetPaginatedBalanceQuery.php +++ b/src/Http/Query/GetPaginatedBalanceQuery.php @@ -2,25 +2,24 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedBalanceQuery extends PaginatedQuery +class GetPaginatedBalanceQuery extends Query { + private SortablePaginatedQuery $paginatedQuery; + public ?string $currency; public function __construct( - ?string $currency = null, - ?string $from = null, - ?int $limit = null, - ?bool $testmode = null + SortablePaginatedQuery $paginatedQuery, + ?string $currency = null ) { - parent::__construct($from, $limit, $testmode); - + $this->paginatedQuery = $paginatedQuery; $this->currency = $currency; } public function toArray(): array { return array_merge( - parent::toArray(), + $this->paginatedQuery->toArray(), [ 'currency' => $this->currency, ] diff --git a/src/Http/Query/GetPaginatedChargebackQuery.php b/src/Http/Query/GetPaginatedChargebackQuery.php index 4e96ef5ee..1eb7e916e 100644 --- a/src/Http/Query/GetPaginatedChargebackQuery.php +++ b/src/Http/Query/GetPaginatedChargebackQuery.php @@ -2,21 +2,20 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedChargebackQuery extends PaginatedQuery +class GetPaginatedChargebackQuery extends Query { + private PaginatedQuery $paginatedQuery; + public bool $includePayment = false; public ?string $profileId = null; public function __construct( + PaginatedQuery $paginatedQuery, bool $includePayment = false, - ?string $profileId = null, - ?string $from = null, - ?int $limit = null, - ?bool $testmode = null + ?string $profileId = null ) { - parent::__construct($from, $limit, $testmode); - + $this->paginatedQuery = $paginatedQuery; $this->includePayment = $includePayment; $this->profileId = $profileId; } @@ -24,7 +23,7 @@ public function __construct( public function toArray(): array { return array_merge( - parent::toArray(), + $this->paginatedQuery->toArray(), [ 'include' => $this->includePayment ? 'payment' : null, 'profileId' => $this->profileId, diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index 4d24f7404..682b9f73e 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -3,37 +3,28 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Rules\Included; -use Mollie\Api\Types\ClientQuery; -class GetPaginatedClientQuery extends PaginatedQuery +class GetPaginatedClientQuery extends Query { + private PaginatedQuery $paginatedQuery; + public array $embed = []; public function __construct( - array $embed = [], - ?string $from = null, - ?int $limit = null + PaginatedQuery $paginatedQuery, + array $embed = [] ) { - parent::__construct($from, $limit); - + $this->paginatedQuery = $paginatedQuery; $this->embed = $embed; } public function toArray(): array { return array_merge( - parent::toArray(), + $this->paginatedQuery->toArray(), [ 'embed' => Arr::join($this->embed), ] ); } - - public function rules(): array - { - return [ - 'embed' => Included::in(ClientQuery::class), - ]; - } } diff --git a/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php b/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php new file mode 100644 index 000000000..c19c1876e --- /dev/null +++ b/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php @@ -0,0 +1,28 @@ +paginatedQuery = $paginatedQuery; + $this->profileId = $profileId; + } + + public function toArray(): array + { + return array_merge( + $this->paginatedQuery->toArray(), + [ + 'profileId' => $this->profileId, + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedInvoiceQuery.php b/src/Http/Query/GetPaginatedInvoiceQuery.php new file mode 100644 index 000000000..9e7336592 --- /dev/null +++ b/src/Http/Query/GetPaginatedInvoiceQuery.php @@ -0,0 +1,33 @@ +paginatedQuery = $paginatedQuery; + $this->reference = $reference; + $this->year = $year; + } + + public function toArray(): array + { + return array_merge( + $this->paginatedQuery->toArray(), + [ + 'reference' => $this->reference, + 'year' => $this->year, + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php new file mode 100644 index 000000000..70f9a36b7 --- /dev/null +++ b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php @@ -0,0 +1,30 @@ +paginatedQuery = $paginatedQuery; + $this->include = $include; + } + + public function toArray(): array + { + return array_merge( + $this->paginatedQuery->toArray(), + [ + 'include' => Arr::join($this->include), + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php new file mode 100644 index 000000000..b46bda9bd --- /dev/null +++ b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php @@ -0,0 +1,30 @@ +paginatedQuery = $paginatedQuery; + $this->include = $include; + } + + public function toArray(): array + { + return array_merge( + $this->paginatedQuery->toArray(), + [ + 'include' => Arr::join($this->include), + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedPaymentRefundQuery.php b/src/Http/Query/GetPaginatedPaymentRefundQuery.php index a3d3cd74e..156c941f9 100644 --- a/src/Http/Query/GetPaginatedPaymentRefundQuery.php +++ b/src/Http/Query/GetPaginatedPaymentRefundQuery.php @@ -2,25 +2,24 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedPaymentRefundQuery extends PaginatedQuery +class GetPaginatedPaymentRefundQuery extends Query { + private PaginatedQuery $paginatedQuery; + public bool $includePayment = false; public function __construct( - bool $includePayment = false, - ?string $from = null, - ?int $limit = null, - ?bool $testmode = null + PaginatedQuery $paginatedQuery, + bool $includePayment = false ) { - parent::__construct($from, $limit, $testmode); - + $this->paginatedQuery = $paginatedQuery; $this->includePayment = $includePayment; } public function toArray(): array { return array_merge( - parent::toArray(), + $this->paginatedQuery->toArray(), [ 'include' => $this->includePayment ? 'payment' : null, ] diff --git a/src/Http/Query/GetPaginatedRefundsQuery.php b/src/Http/Query/GetPaginatedRefundsQuery.php new file mode 100644 index 000000000..b4faaaa60 --- /dev/null +++ b/src/Http/Query/GetPaginatedRefundsQuery.php @@ -0,0 +1,35 @@ +paginatedQuery = $paginatedQuery; + $this->embed = $embed; + $this->profileId = $profileId; + } + + public function toArray(): array + { + return array_merge( + $this->paginatedQuery->toArray(), + [ + 'embed' => Arr::join($this->embed), + 'profileId' => $this->profileId, + ] + ); + } +} diff --git a/src/Http/Query/GetPaginatedSettlementCapturesQuery.php b/src/Http/Query/GetPaginatedSettlementCapturesQuery.php new file mode 100644 index 000000000..82fce4128 --- /dev/null +++ b/src/Http/Query/GetPaginatedSettlementCapturesQuery.php @@ -0,0 +1,5 @@ +query = $query; + $this->balanceId = $balanceId; + } + + public function toArray(): array + { + return array_merge( + $this->query->toArray(), + $this->balanceId ? ['balanceId' => $this->balanceId] : [] + ); + } +} diff --git a/src/Http/Query/GetPaymentCaptureQuery.php b/src/Http/Query/GetPaymentCaptureQuery.php new file mode 100644 index 000000000..7ff491485 --- /dev/null +++ b/src/Http/Query/GetPaymentCaptureQuery.php @@ -0,0 +1,23 @@ +include = $include; + } + + public function toArray(): array + { + return [ + 'include' => Arr::join($this->include), + ]; + } +} diff --git a/src/Http/Query/GetPaymentChargebackQuery.php b/src/Http/Query/GetPaymentChargebackQuery.php new file mode 100644 index 000000000..e6ee01686 --- /dev/null +++ b/src/Http/Query/GetPaymentChargebackQuery.php @@ -0,0 +1,23 @@ +include = $include; + } + + public function toArray(): array + { + return [ + 'include' => Arr::join($this->include), + ]; + } +} diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php new file mode 100644 index 000000000..c2a8e3179 --- /dev/null +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -0,0 +1,25 @@ + $this->locale, + 'currency' => $this->currency, + 'profileId' => $this->profileId, + 'include' => $this->include ? Arr::join($this->include) : null, + ]; + } +} diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php index 47926356a..dcccaac2a 100644 --- a/src/Http/Query/GetPaymentQuery.php +++ b/src/Http/Query/GetPaymentQuery.php @@ -3,8 +3,6 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Rules\Included; -use Mollie\Api\Types\PaymentQuery; class GetPaymentQuery extends Query { @@ -12,16 +10,12 @@ class GetPaymentQuery extends Query public array $include = []; - public ?bool $testmode = null; - public function __construct( array $embed = [], array $include = [], - ?bool $testmode = null ) { $this->embed = $embed; $this->include = $include; - $this->testmode = $testmode; } public function toArray(): array @@ -29,15 +23,6 @@ public function toArray(): array return [ 'embed' => Arr::join($this->embed), 'include' => Arr::join($this->include), - 'testmode' => $this->testmode, - ]; - } - - public function rules(): array - { - return [ - 'embed' => Included::in(PaymentQuery::EMBEDS), - 'include' => Included::in(PaymentQuery::INCLUDES), ]; } } diff --git a/src/Http/Query/GetPaymentRefundQuery.php b/src/Http/Query/GetPaymentRefundQuery.php index 767e2fefc..ee81ae896 100644 --- a/src/Http/Query/GetPaymentRefundQuery.php +++ b/src/Http/Query/GetPaymentRefundQuery.php @@ -3,35 +3,21 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Rules\Included; -use Mollie\Api\Types\PaymentRefundQuery; class GetPaymentRefundQuery extends Query { public array $include = []; - public ?bool $testmode = null; - public function __construct( array $include = [], - ?bool $testmode = null ) { $this->include = $include; - $this->testmode = $testmode; } public function toArray(): array { return [ 'include' => Arr::join($this->include), - 'testmode' => $this->testmode, - ]; - } - - public function rules(): array - { - return [ - 'include' => Included::in(PaymentRefundQuery::INCLUDES), ]; } } diff --git a/src/Http/Query/PaginatedQuery.php b/src/Http/Query/PaginatedQuery.php index 3efc932e6..78820ec94 100644 --- a/src/Http/Query/PaginatedQuery.php +++ b/src/Http/Query/PaginatedQuery.php @@ -8,16 +8,12 @@ class PaginatedQuery extends Query public ?int $limit = null; - public ?bool $testmode = null; - public function __construct( ?string $from = null, ?int $limit = null, - ?bool $testmode = null ) { $this->from = $from; $this->limit = $limit; - $this->testmode = $testmode; } public function toArray(): array @@ -25,7 +21,6 @@ public function toArray(): array return [ 'from' => $this->from, 'limit' => $this->limit, - 'testmode' => $this->testmode, ]; } } diff --git a/src/Http/Query/Query.php b/src/Http/Query/Query.php index 420dbaea2..55b880486 100644 --- a/src/Http/Query/Query.php +++ b/src/Http/Query/Query.php @@ -3,10 +3,5 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Contracts\ValidatableDataProvider; -use Mollie\Api\Traits\HasRules; -abstract class Query implements Arrayable, ValidatableDataProvider -{ - use HasRules; -} +abstract class Query implements Arrayable {} diff --git a/src/Http/Query/SortablePaginatedQuery.php b/src/Http/Query/SortablePaginatedQuery.php index a495eb970..83e8b72d4 100644 --- a/src/Http/Query/SortablePaginatedQuery.php +++ b/src/Http/Query/SortablePaginatedQuery.php @@ -2,8 +2,6 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Rules\Included; - class SortablePaginatedQuery extends PaginatedQuery { public ?string $sort = null; @@ -12,9 +10,8 @@ public function __construct( ?string $from = null, ?int $limit = null, ?string $sort = null, - ?bool $testmode = null ) { - parent::__construct($from, $limit, $testmode); + parent::__construct($from, $limit); $this->sort = $sort; } @@ -28,11 +25,4 @@ public function toArray(): array ] ); } - - public function rules(): array - { - return [ - 'sort' => Included::in(['asc', 'desc']), - ]; - } } diff --git a/src/Http/Request.php b/src/Http/Request.php index 0ed2015a7..7549b13a5 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -3,27 +3,21 @@ namespace Mollie\Api\Http; use LogicException; -use Mollie\Api\Contracts\ValidatableDataProvider; +use Mollie\Api\Traits\HandlesTestmode; use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; -use Mollie\Api\Traits\HasRules; -abstract class Request implements ValidatableDataProvider +abstract class Request { use HasMiddleware; + use HandlesTestmode; use HasRequestProperties; - use HasRules; /** * Define the HTTP method. */ protected static string $method; - /** - * The resource class the request should be casted to. - */ - public static string $targetResourceClass; - public static bool $shouldAutoHydrate = false; public static function hydrate(bool $shouldAutoHydrate = true): void @@ -43,15 +37,6 @@ public function getMethod(): string return static::$method; } - public function getTargetResourceClass(): string - { - if (empty(static::$targetResourceClass)) { - throw new \RuntimeException('Resource class is not set.'); - } - - return static::$targetResourceClass; - } - /** * Resolve the resource path. */ diff --git a/src/Http/Requests/ApplePayPaymentSessionRequest.php b/src/Http/Requests/ApplePayPaymentSessionRequest.php new file mode 100644 index 000000000..461eeb615 --- /dev/null +++ b/src/Http/Requests/ApplePayPaymentSessionRequest.php @@ -0,0 +1,33 @@ +payload = $payload; + } + + public function resolveResourcePath(): string + { + return 'wallets/applepay/sessions'; + } + + public function defaultPayload(): array + { + return $this->payload->toArray(); + } +} diff --git a/src/Http/Requests/CancelPaymentRefundRequest.php b/src/Http/Requests/CancelPaymentRefundRequest.php index efba4ee3b..ec0873476 100644 --- a/src/Http/Requests/CancelPaymentRefundRequest.php +++ b/src/Http/Requests/CancelPaymentRefundRequest.php @@ -2,23 +2,26 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Resources\Payment; -use Mollie\Api\Rules\Id; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Http\Request; use Mollie\Api\Types\Method; -class CancelPaymentRefundRequest extends SimpleRequest +class CancelPaymentRefundRequest extends Request implements SupportsTestmodeInQuery { protected static string $method = Method::DELETE; - public function rules(): array + protected string $paymentId; + + protected string $id; + + public function __construct(string $paymentId, string $id) { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; + $this->paymentId = $paymentId; + $this->id = $id; } public function resolveResourcePath(): string { - return "payments/{$this->id}"; + return "payments/{$this->paymentId}/refunds/{$this->id}"; } } diff --git a/src/Http/Requests/CancelPaymentRequest.php b/src/Http/Requests/CancelPaymentRequest.php index 34a7daf16..8b87d51f9 100644 --- a/src/Http/Requests/CancelPaymentRequest.php +++ b/src/Http/Requests/CancelPaymentRequest.php @@ -3,20 +3,20 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Resources\Payment; -use Mollie\Api\Rules\Id; use Mollie\Api\Types\Method; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; -class CancelPaymentRequest extends SimpleRequest +class CancelPaymentRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { protected static string $method = Method::DELETE; public static string $targetResourceClass = Payment::class; - public function rules(): array + protected string $id; + + public function __construct(string $id) { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; + $this->id = $id; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CancelSubscriptionRequest.php b/src/Http/Requests/CancelSubscriptionRequest.php new file mode 100644 index 000000000..0f2fdc523 --- /dev/null +++ b/src/Http/Requests/CancelSubscriptionRequest.php @@ -0,0 +1,38 @@ +customerId = $customerId; + $this->subscriptionId = $subscriptionId; + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}"; + } +} diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index ccc4079d2..c7c97c283 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -2,13 +2,16 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Http\Payload\CreateClientLinkPayload; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\ClientLink; +use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class CreateClientLinkRequest extends Request +class CreateClientLinkRequest extends ResourceHydratableRequest implements HasPayload { + use HasJsonPayload; + /** * Define the HTTP method. */ @@ -33,7 +36,6 @@ protected function defaultPayload(): array public function resolveResourcePath(): string { - return 'client-links'; } } diff --git a/src/Http/Requests/CreateCustomerPaymentRequest.php b/src/Http/Requests/CreateCustomerPaymentRequest.php new file mode 100644 index 000000000..b742fa964 --- /dev/null +++ b/src/Http/Requests/CreateCustomerPaymentRequest.php @@ -0,0 +1,46 @@ +customerId = $customerId; + $this->profileId = $profileId; + } + + protected function defaultPayload(): array + { + return [ + 'profileId' => $this->profileId, + ]; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/payments"; + } +} diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php index 347c6ba2b..dfa6cd1ea 100644 --- a/src/Http/Requests/CreateCustomerRequest.php +++ b/src/Http/Requests/CreateCustomerRequest.php @@ -3,13 +3,13 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Contracts\SupportsTestmodeInPayload; use Mollie\Api\Http\Payload\CreateCustomerPayload; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Customer; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class CreateCustomerRequest extends Request implements HasPayload +class CreateCustomerRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInPayload { use HasJsonPayload; diff --git a/src/Http/Requests/CreateMandateRequest.php b/src/Http/Requests/CreateMandateRequest.php new file mode 100644 index 000000000..f01a02fac --- /dev/null +++ b/src/Http/Requests/CreateMandateRequest.php @@ -0,0 +1,45 @@ +customerId = $customerId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/mandates"; + } +} diff --git a/src/Http/Requests/CreatePaymentCaptureRequest.php b/src/Http/Requests/CreatePaymentCaptureRequest.php new file mode 100644 index 000000000..473a3bad6 --- /dev/null +++ b/src/Http/Requests/CreatePaymentCaptureRequest.php @@ -0,0 +1,45 @@ +paymentId = $paymentId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/captures"; + } +} diff --git a/src/Http/Requests/CreatePaymentLinkRequest.php b/src/Http/Requests/CreatePaymentLinkRequest.php new file mode 100644 index 000000000..677f2f7ab --- /dev/null +++ b/src/Http/Requests/CreatePaymentLinkRequest.php @@ -0,0 +1,44 @@ +payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return 'payment-links'; + } +} diff --git a/src/Http/Requests/CreatePaymentRefundRequest.php b/src/Http/Requests/CreatePaymentRefundRequest.php index fd08c00a5..9c7d451ea 100644 --- a/src/Http/Requests/CreatePaymentRefundRequest.php +++ b/src/Http/Requests/CreatePaymentRefundRequest.php @@ -3,15 +3,12 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Contracts\SupportsTestmode; +use Mollie\Api\Contracts\SupportsTestmodeInPayload; use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; -use Mollie\Api\Http\Request; -use Mollie\Api\Resources\Payment; -use Mollie\Api\Rules\Id; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class CreatePaymentRefundRequest extends Request implements HasPayload, SupportsTestmode +class CreatePaymentRefundRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInPayload { use HasJsonPayload; @@ -42,13 +39,6 @@ protected function defaultPayload(): array return $this->payload->toArray(); } - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; - } - public function resolveResourcePath(): string { return "payments/{$this->paymentId}/refunds"; diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index f61c5cc7a..8cb84a9e5 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -5,12 +5,12 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Query\CreatePaymentQuery; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; -class CreatePaymentRequest extends Request implements HasPayload +class CreatePaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInQuery { use HasJsonPayload; diff --git a/src/Http/Requests/CreateProfileRequest.php b/src/Http/Requests/CreateProfileRequest.php new file mode 100644 index 000000000..ed1e44e10 --- /dev/null +++ b/src/Http/Requests/CreateProfileRequest.php @@ -0,0 +1,45 @@ +payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return 'profiles'; + } +} diff --git a/src/Http/Requests/CreateSubscriptionRequest.php b/src/Http/Requests/CreateSubscriptionRequest.php new file mode 100644 index 000000000..91e461411 --- /dev/null +++ b/src/Http/Requests/CreateSubscriptionRequest.php @@ -0,0 +1,48 @@ +customerId = $customerId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions"; + } +} diff --git a/src/Http/Requests/DeleteCustomerRequest.php b/src/Http/Requests/DeleteCustomerRequest.php index 55179f797..b0c682350 100644 --- a/src/Http/Requests/DeleteCustomerRequest.php +++ b/src/Http/Requests/DeleteCustomerRequest.php @@ -2,23 +2,13 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Resources\Customer; -use Mollie\Api\Rules\Id; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Types\Method; -class DeleteCustomerRequest extends SimpleRequest +class DeleteCustomerRequest extends SimpleRequest implements SupportsTestmodeInQuery { protected static string $method = Method::DELETE; - public static string $targetResourceClass = Customer::class; - - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Customer::$resourceIdPrefix), - ]; - } - public function resolveResourcePath(): string { return "customers/{$this->id}"; diff --git a/src/Http/Requests/DeletePaymentLinkRequest.php b/src/Http/Requests/DeletePaymentLinkRequest.php new file mode 100644 index 000000000..5ae59494d --- /dev/null +++ b/src/Http/Requests/DeletePaymentLinkRequest.php @@ -0,0 +1,16 @@ +id}"; + } +} diff --git a/src/Http/Requests/DeleteProfileRequest.php b/src/Http/Requests/DeleteProfileRequest.php new file mode 100644 index 000000000..9156442cb --- /dev/null +++ b/src/Http/Requests/DeleteProfileRequest.php @@ -0,0 +1,26 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->id}"; + } +} diff --git a/src/Http/Requests/DisableMethodIssuerRequest.php b/src/Http/Requests/DisableMethodIssuerRequest.php new file mode 100644 index 000000000..953a9c22d --- /dev/null +++ b/src/Http/Requests/DisableMethodIssuerRequest.php @@ -0,0 +1,32 @@ +profileId = $profileId; + $this->methodId = $methodId; + $this->issuerId = $issuerId; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->profileId}/methods/{$this->methodId}/issuers/{$this->issuerId}"; + } +} diff --git a/src/Http/Requests/DynamicDeleteRequest.php b/src/Http/Requests/DynamicDeleteRequest.php deleted file mode 100644 index 4b8e85e0f..000000000 --- a/src/Http/Requests/DynamicDeleteRequest.php +++ /dev/null @@ -1,45 +0,0 @@ -testmode = $testmode; - $this->body = $body; - } - - protected function defaultQuery(): array - { - return [ - 'testmode' => $this->testmode, - ]; - } - - protected function defaultPayload(): array - { - return $this->body; - } -} diff --git a/src/Http/Requests/DynamicPatchRequest.php b/src/Http/Requests/DynamicPatchRequest.php deleted file mode 100644 index 2fbf178ff..000000000 --- a/src/Http/Requests/DynamicPatchRequest.php +++ /dev/null @@ -1,40 +0,0 @@ -payload = $payload; - $this->query = $query; - } - - protected function defaultQuery(): array - { - return $this->query; - } - - protected function defaultPayload(): array - { - return $this->payload; - } -} diff --git a/src/Http/Requests/DynamicPostRequest.php b/src/Http/Requests/DynamicPostRequest.php deleted file mode 100644 index 72d8bb250..000000000 --- a/src/Http/Requests/DynamicPostRequest.php +++ /dev/null @@ -1,43 +0,0 @@ -payload = $payload; - $this->query = $query; - } - - protected function defaultQuery(): array - { - return $this->query; - } - - protected function defaultPayload(): array - { - return $this->payload; - } -} diff --git a/src/Http/Requests/DynamicRequest.php b/src/Http/Requests/DynamicRequest.php index 82045cc47..214083dce 100644 --- a/src/Http/Requests/DynamicRequest.php +++ b/src/Http/Requests/DynamicRequest.php @@ -2,9 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; - -abstract class DynamicRequest extends Request +abstract class DynamicRequest extends ResourceHydratableRequest { private string $url; diff --git a/src/Http/Requests/EnableMethodIssuerRequest.php b/src/Http/Requests/EnableMethodIssuerRequest.php new file mode 100644 index 000000000..9a58eedb1 --- /dev/null +++ b/src/Http/Requests/EnableMethodIssuerRequest.php @@ -0,0 +1,55 @@ +profileId = $profileId; + $this->methodId = $methodId; + $this->issuerId = $issuerId; + $this->contractId = $contractId; + } + + protected function defaultPayload(): array + { + return [ + 'contractId' => $this->contractId, + ]; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->profileId}/methods/{$this->methodId}/issuers/{$this->issuerId}"; + } +} diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php new file mode 100644 index 000000000..4cb739c58 --- /dev/null +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -0,0 +1,37 @@ +query = $query; + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + public function resolveResourcePath(): string + { + return 'methods/all'; + } +} diff --git a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php new file mode 100644 index 000000000..6bc1b615b --- /dev/null +++ b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php @@ -0,0 +1,26 @@ +id = $id; + } + /** * Resolve the resource path. */ diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index ebd0a9f40..1fdcee8a6 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -3,13 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Client; -use Mollie\Api\Rules\Included; -use Mollie\Api\Types\ClientQuery; use Mollie\Api\Types\Method; -class GetClientRequest extends Request +class GetClientRequest extends ResourceHydratableRequest { /** * Define the HTTP method. @@ -38,13 +35,6 @@ protected function defaultQuery(): array ]; } - public function rules(): array - { - return [ - 'embed' => Included::in(ClientQuery::class), - ]; - } - public function resolveResourcePath(): string { return "clients/{$this->id}"; diff --git a/src/Http/Requests/GetCustomerRequest.php b/src/Http/Requests/GetCustomerRequest.php index 19d1c4682..df134090c 100644 --- a/src/Http/Requests/GetCustomerRequest.php +++ b/src/Http/Requests/GetCustomerRequest.php @@ -2,16 +2,23 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Customer; -use Mollie\Api\Rules\Id; use Mollie\Api\Types\Method; -class GetCustomerRequest extends SimpleRequest +class GetCustomerRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { protected static string $method = Method::GET; public static string $targetResourceClass = Customer::class; + private string $id; + + public function __construct(string $id) + { + $this->id = $id; + } + /** * Resolve the resource path. */ @@ -19,11 +26,4 @@ public function resolveResourcePath(): string { return "customers/{$this->id}"; } - - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Customer::$resourceIdPrefix), - ]; - } } diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php new file mode 100644 index 000000000..beee61729 --- /dev/null +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -0,0 +1,32 @@ +query = $query; + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + public function resolveResourcePath(): string + { + return 'methods'; + } +} diff --git a/src/Http/Requests/GetInvoiceRequest.php b/src/Http/Requests/GetInvoiceRequest.php new file mode 100644 index 000000000..cf3a582ab --- /dev/null +++ b/src/Http/Requests/GetInvoiceRequest.php @@ -0,0 +1,28 @@ +id = $id; + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "invoices/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetMandateRequest.php b/src/Http/Requests/GetMandateRequest.php new file mode 100644 index 000000000..49174bb90 --- /dev/null +++ b/src/Http/Requests/GetMandateRequest.php @@ -0,0 +1,35 @@ +customerId = $customerId; + $this->mandateId = $mandateId; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/mandates/{$this->mandateId}"; + } +} diff --git a/src/Http/Requests/GetOnboardingRequest.php b/src/Http/Requests/GetOnboardingRequest.php new file mode 100644 index 000000000..2247c4545 --- /dev/null +++ b/src/Http/Requests/GetOnboardingRequest.php @@ -0,0 +1,18 @@ +customerId = $customerId; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/payments"; + } +} diff --git a/src/Http/Requests/GetPaginatedCustomerRequest.php b/src/Http/Requests/GetPaginatedCustomerRequest.php index 843cabdd9..0b1f32bf1 100644 --- a/src/Http/Requests/GetPaginatedCustomerRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerRequest.php @@ -3,10 +3,11 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedCustomerRequest extends PaginatedRequest implements IsIteratable +class GetPaginatedCustomerRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedInvoiceRequest.php b/src/Http/Requests/GetPaginatedInvoiceRequest.php new file mode 100644 index 000000000..bedddc8c4 --- /dev/null +++ b/src/Http/Requests/GetPaginatedInvoiceRequest.php @@ -0,0 +1,22 @@ +customerId = $customerId; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/mandates"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php new file mode 100644 index 000000000..6ff9d314d --- /dev/null +++ b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php @@ -0,0 +1,48 @@ +paymentId = $paymentId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query ? $this->query->toArray() : []; + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/captures"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php new file mode 100644 index 000000000..68acb0bdb --- /dev/null +++ b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php @@ -0,0 +1,44 @@ +paymentId = $paymentId; + } + + protected function defaultQuery(): array + { + return $this->query ? $this->query->toArray() : []; + } + + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/chargebacks"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php new file mode 100644 index 000000000..4e9c104ab --- /dev/null +++ b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php @@ -0,0 +1,35 @@ +paymentLinkId = $paymentLinkId; + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "payment-links/{$this->paymentLinkId}/payments"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php new file mode 100644 index 000000000..fb97a1be2 --- /dev/null +++ b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php @@ -0,0 +1,29 @@ +paymentId = $paymentId; } - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; - } - public function resolveResourcePath(): string { return "payments/{$this->paymentId}/refunds"; diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php index eacdceeb7..67c916877 100644 --- a/src/Http/Requests/GetPaginatedPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -3,10 +3,11 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedPaymentsRequest extends SortablePaginatedRequest implements IsIteratable +class GetPaginatedPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedProfilesRequest.php b/src/Http/Requests/GetPaginatedProfilesRequest.php new file mode 100644 index 000000000..c8340d431 --- /dev/null +++ b/src/Http/Requests/GetPaginatedProfilesRequest.php @@ -0,0 +1,31 @@ +settlementId = $settlementId; + + parent::__construct($query); + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "settlements/{$this->settlementId}/captures"; + } +} diff --git a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php new file mode 100644 index 000000000..1bfa5b996 --- /dev/null +++ b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php @@ -0,0 +1,38 @@ +settlementId = $settlementId; + + parent::__construct($query); + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "settlements/{$this->settlementId}/chargebacks"; + } +} diff --git a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php new file mode 100644 index 000000000..caf029d9d --- /dev/null +++ b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php @@ -0,0 +1,36 @@ +settlementId = $settlementId; + + parent::__construct($query); + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "settlements/{$this->settlementId}/payments"; + } +} diff --git a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php new file mode 100644 index 000000000..c8a4a55a4 --- /dev/null +++ b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php @@ -0,0 +1,38 @@ +settlementId = $settlementId; + + parent::__construct($query); + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "settlements/{$this->settlementId}/refunds"; + } +} diff --git a/src/Http/Requests/GetPaginatedSettlementsRequest.php b/src/Http/Requests/GetPaginatedSettlementsRequest.php new file mode 100644 index 000000000..687155bad --- /dev/null +++ b/src/Http/Requests/GetPaginatedSettlementsRequest.php @@ -0,0 +1,25 @@ +customerId = $customerId; + $this->subscriptionId = $subscriptionId; + + parent::__construct($query); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments"; + } +} diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php new file mode 100644 index 000000000..02e9d3495 --- /dev/null +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -0,0 +1,36 @@ +customerId = $customerId; + + parent::__construct($query); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions"; + } +} diff --git a/src/Http/Requests/GetPaginatedTerminalsRequest.php b/src/Http/Requests/GetPaginatedTerminalsRequest.php new file mode 100644 index 000000000..a8c4730de --- /dev/null +++ b/src/Http/Requests/GetPaginatedTerminalsRequest.php @@ -0,0 +1,26 @@ +paymentId = $paymentId; + $this->captureId = $captureId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query?->toArray() ?? []; + } + + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/captures/{$this->captureId}"; + } +} diff --git a/src/Http/Requests/GetPaymentChargebackRequest.php b/src/Http/Requests/GetPaymentChargebackRequest.php new file mode 100644 index 000000000..d1c029d5d --- /dev/null +++ b/src/Http/Requests/GetPaymentChargebackRequest.php @@ -0,0 +1,44 @@ +paymentId = $paymentId; + $this->chargebackId = $chargebackId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query?->toArray() ?? []; + } + + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/chargebacks/{$this->chargebackId}"; + } +} diff --git a/src/Http/Requests/GetPaymentLinkRequest.php b/src/Http/Requests/GetPaymentLinkRequest.php new file mode 100644 index 000000000..aac61091c --- /dev/null +++ b/src/Http/Requests/GetPaymentLinkRequest.php @@ -0,0 +1,35 @@ +id = $id; + } + + /** + * Resolve the resource path. + */ + public function resolveResourcePath(): string + { + return "payment-links/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php new file mode 100644 index 000000000..968f0e663 --- /dev/null +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -0,0 +1,35 @@ +methodId = $methodId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + public function resolveResourcePath(): string + { + return "methods/{$this->methodId}"; + } +} diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index 3067972ae..51b6e2a95 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -2,14 +2,12 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Query\GetPaymentRefundQuery; -use Mollie\Api\Http\Request; -use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; -use Mollie\Api\Rules\Id; use Mollie\Api\Types\Method; -class GetPaymentRefundRequest extends Request +class GetPaymentRefundRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { /** * Define the HTTP method. @@ -39,14 +37,6 @@ protected function defaultQuery(): array return $this->query->toArray(); } - public function rules(): array - { - return [ - 'paymentId' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - 'refundId' => Id::startsWithPrefix(Refund::$resourceIdPrefix), - ]; - } - /** * Resolve the resource path. */ diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index da4dee8d1..4e723d00a 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -2,13 +2,12 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Query\GetPaymentQuery; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; -use Mollie\Api\Rules\Id; use Mollie\Api\Types\Method; -class GetPaymentRequest extends Request +class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { /** * Define the HTTP method. @@ -18,7 +17,7 @@ class GetPaymentRequest extends Request /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = \Mollie\Api\Resources\Payment::class; + public static string $targetResourceClass = Payment::class; private string $id; @@ -37,13 +36,6 @@ protected function defaultQuery(): array return $this->query->toArray(); } - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; - } - /** * Resolve the resource path. */ diff --git a/src/Http/Requests/GetPermissionRequest.php b/src/Http/Requests/GetPermissionRequest.php new file mode 100644 index 000000000..4749aab63 --- /dev/null +++ b/src/Http/Requests/GetPermissionRequest.php @@ -0,0 +1,26 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "permissions/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetProfileRequest.php b/src/Http/Requests/GetProfileRequest.php new file mode 100644 index 000000000..c8cb8ff43 --- /dev/null +++ b/src/Http/Requests/GetProfileRequest.php @@ -0,0 +1,29 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetSettlementRequest.php b/src/Http/Requests/GetSettlementRequest.php new file mode 100644 index 000000000..149a5a161 --- /dev/null +++ b/src/Http/Requests/GetSettlementRequest.php @@ -0,0 +1,26 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "settlements/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetSubscriptionRequest.php b/src/Http/Requests/GetSubscriptionRequest.php new file mode 100644 index 000000000..6a5fa6c00 --- /dev/null +++ b/src/Http/Requests/GetSubscriptionRequest.php @@ -0,0 +1,35 @@ +customerId = $customerId; + $this->id = $id; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetTerminalRequest.php b/src/Http/Requests/GetTerminalRequest.php new file mode 100644 index 000000000..a9595f454 --- /dev/null +++ b/src/Http/Requests/GetTerminalRequest.php @@ -0,0 +1,29 @@ +id = $id; + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "terminals/{$this->id}"; + } +} diff --git a/src/Http/Requests/ListPermissionsRequest.php b/src/Http/Requests/ListPermissionsRequest.php new file mode 100644 index 000000000..c1c7b0708 --- /dev/null +++ b/src/Http/Requests/ListPermissionsRequest.php @@ -0,0 +1,21 @@ +query = $query; } diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php new file mode 100644 index 000000000..41642e4a8 --- /dev/null +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -0,0 +1,23 @@ +customerId = $customerId; + $this->mandateId = $mandateId; + } + + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/mandates/{$this->mandateId}"; + } +} diff --git a/src/Http/Requests/SimpleRequest.php b/src/Http/Requests/SimpleRequest.php index 0888c2eee..7fbefa71c 100644 --- a/src/Http/Requests/SimpleRequest.php +++ b/src/Http/Requests/SimpleRequest.php @@ -8,18 +8,8 @@ abstract class SimpleRequest extends Request { protected string $id; - protected bool $testmode; - - public function __construct(string $id, bool $testmode = false) + public function __construct(string $id) { $this->id = $id; - $this->testmode = $testmode; - } - - protected function defaultQuery(): array - { - return [ - 'testmode' => $this->testmode, - ]; } } diff --git a/src/Http/Requests/SortablePaginatedRequest.php b/src/Http/Requests/SortablePaginatedRequest.php deleted file mode 100644 index a5a11e636..000000000 --- a/src/Http/Requests/SortablePaginatedRequest.php +++ /dev/null @@ -1,14 +0,0 @@ -payload->toArray(); } - protected function defaultQuery(): array - { - return [ - 'testmode' => false, - ]; - } - - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Customer::$resourceIdPrefix), - ]; - } - public function resolveResourcePath(): string { return "customers/{$this->id}"; diff --git a/src/Http/Requests/UpdatePaymentLinkRequest.php b/src/Http/Requests/UpdatePaymentLinkRequest.php new file mode 100644 index 000000000..c01d73495 --- /dev/null +++ b/src/Http/Requests/UpdatePaymentLinkRequest.php @@ -0,0 +1,42 @@ +id = $id; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "payment-links/{$this->id}"; + } +} diff --git a/src/Http/Requests/UpdatePaymentRequest.php b/src/Http/Requests/UpdatePaymentRequest.php index 259f165eb..8bd9d7f8d 100644 --- a/src/Http/Requests/UpdatePaymentRequest.php +++ b/src/Http/Requests/UpdatePaymentRequest.php @@ -3,14 +3,13 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Payload\UpdatePaymentPayload; -use Mollie\Api\Http\Request; use Mollie\Api\Resources\Payment; -use Mollie\Api\Rules\Id; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class UpdatePaymentRequest extends Request implements HasPayload +class UpdatePaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInQuery { use HasJsonPayload; @@ -36,13 +35,6 @@ protected function defaultPayload(): array return $this->payload->toArray(); } - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix(Payment::$resourceIdPrefix), - ]; - } - public function resolveResourcePath(): string { return "payments/{$this->id}"; diff --git a/src/Http/Requests/UpdatePaymentRouteRequest.php b/src/Http/Requests/UpdatePaymentRouteRequest.php new file mode 100644 index 000000000..180fe27ab --- /dev/null +++ b/src/Http/Requests/UpdatePaymentRouteRequest.php @@ -0,0 +1,48 @@ +paymentId = $paymentId; + $this->routeId = $routeId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "payments/{$this->paymentId}/routes/{$this->routeId}"; + } +} diff --git a/src/Http/Requests/UpdateProfileRequest.php b/src/Http/Requests/UpdateProfileRequest.php new file mode 100644 index 000000000..78a096501 --- /dev/null +++ b/src/Http/Requests/UpdateProfileRequest.php @@ -0,0 +1,41 @@ +id = $id; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->id}"; + } +} diff --git a/src/Http/Requests/UpdateSubscriptionRequest.php b/src/Http/Requests/UpdateSubscriptionRequest.php new file mode 100644 index 000000000..0cc526dd3 --- /dev/null +++ b/src/Http/Requests/UpdateSubscriptionRequest.php @@ -0,0 +1,54 @@ +customerId = $customerId; + $this->subscriptionId = $subscriptionId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + /** + * The resource path. + */ + public function resolveResourcePath(): string + { + return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}"; + } +} diff --git a/src/Http/Response.php b/src/Http/Response.php index 641224f91..b2fa3d259 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -3,7 +3,9 @@ namespace Mollie\Api\Http; use Mollie\Api\Contracts\Connector; +use Mollie\Api\Contracts\SupportsResourceHydration; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Traits\HandlesResourceCreation; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -45,6 +47,10 @@ public function __construct( */ public function toResource() { + if (! $this->getRequest() instanceof ResourceHydratableRequest) { + return $this; + } + return $this->createResource($this->getRequest(), $this); } diff --git a/src/Http/ResponseStatusCode.php b/src/Http/ResponseStatusCode.php index 27ca4caaa..6ccea9096 100644 --- a/src/Http/ResponseStatusCode.php +++ b/src/Http/ResponseStatusCode.php @@ -5,66 +5,128 @@ class ResponseStatusCode { public const HTTP_CONTINUE = 100; + public const HTTP_SWITCHING_PROTOCOLS = 101; + public const HTTP_PROCESSING = 102; + public const HTTP_EARLY_HINTS = 103; + public const HTTP_OK = 200; + public const HTTP_CREATED = 201; + public const HTTP_ACCEPTED = 202; + public const HTTP_NON_AUTHORITATIVE_INFORMATION = 203; + public const HTTP_NO_CONTENT = 204; + public const HTTP_RESET_CONTENT = 205; + public const HTTP_PARTIAL_CONTENT = 206; + public const HTTP_MULTI_STATUS = 207; + public const HTTP_ALREADY_REPORTED = 208; + public const HTTP_IM_USED = 226; + public const HTTP_MULTIPLE_CHOICES = 300; + public const HTTP_MOVED_PERMANENTLY = 301; + public const HTTP_FOUND = 302; + public const HTTP_SEE_OTHER = 303; + public const HTTP_NOT_MODIFIED = 304; + public const HTTP_USE_PROXY = 305; + public const HTTP_SWITCH_PROXY = 306; // No longer used + public const HTTP_TEMPORARY_REDIRECT = 307; + public const HTTP_PERMANENT_REDIRECT = 308; + public const HTTP_BAD_REQUEST = 400; + public const HTTP_UNAUTHORIZED = 401; + public const HTTP_PAYMENT_REQUIRED = 402; + public const HTTP_FORBIDDEN = 403; + public const HTTP_NOT_FOUND = 404; + public const HTTP_METHOD_NOT_ALLOWED = 405; + public const HTTP_NOT_ACCEPTABLE = 406; + public const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; + public const HTTP_REQUEST_TIMEOUT = 408; + public const HTTP_CONFLICT = 409; + public const HTTP_GONE = 410; + public const HTTP_LENGTH_REQUIRED = 411; + public const HTTP_PRECONDITION_FAILED = 412; + public const HTTP_PAYLOAD_TOO_LARGE = 413; + public const HTTP_URI_TOO_LONG = 414; + public const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + public const HTTP_RANGE_NOT_SATISFIABLE = 416; + public const HTTP_EXPECTATION_FAILED = 417; + public const HTTP_I_AM_A_TEAPOT = 418; + public const HTTP_MISDIRECTED_REQUEST = 421; + public const HTTP_UNPROCESSABLE_ENTITY = 422; + public const HTTP_LOCKED = 423; + public const HTTP_FAILED_DEPENDENCY = 424; + public const HTTP_TOO_EARLY = 425; + public const HTTP_UPGRADE_REQUIRED = 426; + public const HTTP_PRECONDITION_REQUIRED = 428; + public const HTTP_TOO_MANY_REQUESTS = 429; + public const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; + public const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; + public const HTTP_INTERNAL_SERVER_ERROR = 500; + public const HTTP_NOT_IMPLEMENTED = 501; + public const HTTP_BAD_GATEWAY = 502; + public const HTTP_SERVICE_UNAVAILABLE = 503; + public const HTTP_GATEWAY_TIMEOUT = 504; + public const HTTP_HTTP_VERSION_NOT_SUPPORTED = 505; + public const HTTP_VARIANT_ALSO_NEGOTIATES = 506; + public const HTTP_INSUFFICIENT_STORAGE = 507; + public const HTTP_LOOP_DETECTED = 508; + public const HTTP_NOT_EXTENDED = 510; + public const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; } diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 08c8be9c7..b470e7fde 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -12,11 +12,11 @@ use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; use Mollie\Api\EndpointCollection\CustomerEndpointCollection; +use Mollie\Api\EndpointCollection\CustomerPaymentsEndpoint; use Mollie\Api\EndpointCollection\OrderEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; use Mollie\Api\Endpoints\InvoiceEndpoint; use Mollie\Api\Endpoints\MandateEndpoint; use Mollie\Api\Endpoints\MethodEndpoint; @@ -36,7 +36,6 @@ use Mollie\Api\Endpoints\ProfileEndpoint; use Mollie\Api\Endpoints\ProfileMethodEndpoint; use Mollie\Api\Endpoints\RefundEndpoint; -use Mollie\Api\Endpoints\SessionEndpoint; use Mollie\Api\Endpoints\SettlementCaptureEndpoint; use Mollie\Api\Endpoints\SettlementChargebackEndpoint; use Mollie\Api\Endpoints\SettlementPaymentEndpoint; diff --git a/src/Repositories/JsonPayloadRepository.php b/src/Repositories/JsonPayloadRepository.php index 6bacedf52..7405811c1 100644 --- a/src/Repositories/JsonPayloadRepository.php +++ b/src/Repositories/JsonPayloadRepository.php @@ -30,6 +30,13 @@ public function all(): array return $this->store; } + public function add(string $key, $value): self + { + $this->store[$key] = $value; + + return $this; + } + public function remove(string $key): self { unset($this->store[$key]); diff --git a/src/Resources/BalanceCollection.php b/src/Resources/BalanceCollection.php index dcb44203e..de4da2460 100644 --- a/src/Resources/BalanceCollection.php +++ b/src/Resources/BalanceCollection.php @@ -6,15 +6,11 @@ class BalanceCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "balances"; + public static string $collectionName = 'balances'; /** * Resource class name. - * - * @var string */ public static string $resource = Balance::class; } diff --git a/src/Resources/BalanceReport.php b/src/Resources/BalanceReport.php index 96479f742..14c2ca3ad 100644 --- a/src/Resources/BalanceReport.php +++ b/src/Resources/BalanceReport.php @@ -17,6 +17,7 @@ class BalanceReport extends BaseResource * The ID of the balance this report was generated for. * * @example bal_gVMhHKqSSRYJyPsuoPNFH + * * @var string */ public $balanceId; @@ -27,6 +28,7 @@ class BalanceReport extends BaseResource * * * @example Europe/Amsterdam + * * @var string */ public $timeZone; @@ -38,6 +40,7 @@ class BalanceReport extends BaseResource * * * @example 2020-01-01 + * * @var string */ public $from; diff --git a/src/Resources/BalanceTransaction.php b/src/Resources/BalanceTransaction.php index 795d40062..18c26595f 100644 --- a/src/Resources/BalanceTransaction.php +++ b/src/Resources/BalanceTransaction.php @@ -25,6 +25,7 @@ class BalanceTransaction extends BaseResource * The identifier uniquely referring this balance transaction. Mollie assigns this identifier at creation. * * @example baltr_QM24QwzUWR4ev4Xfgyt29d + * * @var string */ public $id; @@ -40,6 +41,7 @@ class BalanceTransaction extends BaseResource * UTC datetime the balance transaction was created in ISO-8601 format. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -49,6 +51,7 @@ class BalanceTransaction extends BaseResource * for example when it concerns a refund, the amount will be negative. * * @example {"currency":"EUR", "value":"100.00"} + * * @var \stdClass */ public $resultAmount; diff --git a/src/Resources/BalanceTransactionCollection.php b/src/Resources/BalanceTransactionCollection.php index 5c3b8c1f5..ceb6739a3 100644 --- a/src/Resources/BalanceTransactionCollection.php +++ b/src/Resources/BalanceTransactionCollection.php @@ -8,15 +8,11 @@ class BalanceTransactionCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "balance_transactions"; + public static string $collectionName = 'balance_transactions'; /** * Resource class name. - * - * @var string */ public static string $resource = BalanceTransaction::class; } diff --git a/src/Resources/Capture.php b/src/Resources/Capture.php index 89cd86209..d1a59bd86 100644 --- a/src/Resources/Capture.php +++ b/src/Resources/Capture.php @@ -13,6 +13,7 @@ class Capture extends BaseResource /** * Id of the capture + * * @var string */ public $id; diff --git a/src/Resources/CaptureCollection.php b/src/Resources/CaptureCollection.php index 61e8e641a..c943747b5 100644 --- a/src/Resources/CaptureCollection.php +++ b/src/Resources/CaptureCollection.php @@ -6,15 +6,11 @@ class CaptureCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "captures"; + public static string $collectionName = 'captures'; /** * Resource class name. - * - * @var string */ public static string $resource = Capture::class; } diff --git a/src/Resources/Chargeback.php b/src/Resources/Chargeback.php index c54bf7ad2..672cebc26 100644 --- a/src/Resources/Chargeback.php +++ b/src/Resources/Chargeback.php @@ -29,6 +29,7 @@ class Chargeback extends BaseResource * UTC datetime the payment was created in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $createdAt; @@ -65,6 +66,7 @@ class Chargeback extends BaseResource * UTC datetime the date and time the chargeback was reversed in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $reversedAt; diff --git a/src/Resources/ChargebackCollection.php b/src/Resources/ChargebackCollection.php index 7a1c0410e..225fee3ac 100644 --- a/src/Resources/ChargebackCollection.php +++ b/src/Resources/ChargebackCollection.php @@ -6,15 +6,11 @@ class ChargebackCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "chargebacks"; + public static string $collectionName = 'chargebacks'; /** * Resource class name. - * - * @var string */ public static string $resource = Chargeback::class; } diff --git a/src/Resources/Client.php b/src/Resources/Client.php index 4b3e143d8..67a9b8d6a 100644 --- a/src/Resources/Client.php +++ b/src/Resources/Client.php @@ -17,6 +17,7 @@ class Client extends BaseResource implements EmbeddedResourcesContract * UTC datetime the order was created in ISO-8601 format. * * @example "2018-03-21T13:13:37+00:00" + * * @var string|null */ public $organizationCreatedAt; diff --git a/src/Resources/ClientCollection.php b/src/Resources/ClientCollection.php index b2eee4856..43827169e 100644 --- a/src/Resources/ClientCollection.php +++ b/src/Resources/ClientCollection.php @@ -6,15 +6,11 @@ class ClientCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "clients"; + public static string $collectionName = 'clients'; /** * Resource class name. - * - * @var string */ public static string $resource = Client::class; } diff --git a/src/Resources/ClientLink.php b/src/Resources/ClientLink.php index 36ac0b7a3..e2b0b79ff 100644 --- a/src/Resources/ClientLink.php +++ b/src/Resources/ClientLink.php @@ -15,6 +15,7 @@ class ClientLink extends BaseResource * Id of the client link. * * @example csr_vZCnNQsV2UtfXxYifWKWH + * * @var string */ public $id; diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 5a7b41e29..f56cc6556 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -4,11 +4,11 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Traits\InteractsWithResource as TraitsInteractsWithResource; +use Mollie\Api\Traits\InteractsWithResource; abstract class CursorCollection extends BaseCollection { - use TraitsInteractsWithResource; + use InteractsWithResource; /** * Return the next set of resources when available diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index d8ec43bd1..c67242b84 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -119,9 +119,9 @@ public function getSubscription($subscriptionId, array $parameters = []) } /** - * @param string $subscriptionId - * + * @param string $subscriptionId * @return \Mollie\Api\Resources\Subscription + * * @throws ApiException */ public function cancelSubscription($subscriptionId) diff --git a/src/Resources/CustomerCollection.php b/src/Resources/CustomerCollection.php index cc3513b89..31a204442 100644 --- a/src/Resources/CustomerCollection.php +++ b/src/Resources/CustomerCollection.php @@ -6,15 +6,11 @@ class CustomerCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "customers"; + public static string $collectionName = 'customers'; /** * Resource class name. - * - * @var string */ public static string $resource = Customer::class; } diff --git a/src/Resources/HasPresetOptions.php b/src/Resources/HasPresetOptions.php index 546b54b29..7ee972f67 100644 --- a/src/Resources/HasPresetOptions.php +++ b/src/Resources/HasPresetOptions.php @@ -9,15 +9,13 @@ trait HasPresetOptions { /** * When accessed by oAuth we want to pass the testmode by default - * - * @return array */ protected function getPresetOptions(): array { $options = []; if ($this->client->usesOAuth()) { - $options["testmode"] = $this->mode === "test" ? true : false; + $options['testmode'] = $this->mode === 'test' ? true : false; } return $options; @@ -25,9 +23,6 @@ protected function getPresetOptions(): array /** * Apply the preset options. - * - * @param array $options - * @return array */ protected function withPresetOptions(array $options): array { diff --git a/src/Resources/Invoice.php b/src/Resources/Invoice.php index 66049a846..98c2e3ee5 100644 --- a/src/Resources/Invoice.php +++ b/src/Resources/Invoice.php @@ -6,6 +6,8 @@ class Invoice extends BaseResource { + public static string $resourceIdPrefix = 'inv_'; + /** * @var string */ @@ -72,6 +74,7 @@ class Invoice extends BaseResource * Array containing the invoice lines. * * @see https://docs.mollie.com/reference/v2/invoices-api/get-invoice + * * @var array */ public $lines; @@ -83,25 +86,16 @@ class Invoice extends BaseResource */ public $_links; - /** - * @return bool - */ public function isPaid(): bool { return $this->status == InvoiceStatus::PAID; } - /** - * @return bool - */ public function isOpen(): bool { return $this->status == InvoiceStatus::OPEN; } - /** - * @return bool - */ public function isOverdue(): bool { return $this->status == InvoiceStatus::OVERDUE; diff --git a/src/Resources/InvoiceCollection.php b/src/Resources/InvoiceCollection.php index 89de8f59b..01dbbf29d 100644 --- a/src/Resources/InvoiceCollection.php +++ b/src/Resources/InvoiceCollection.php @@ -6,15 +6,11 @@ class InvoiceCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "invoices"; + public static string $collectionName = 'invoices'; /** * Resource class name. - * - * @var string */ public static string $resource = Invoice::class; } diff --git a/src/Resources/Issuer.php b/src/Resources/Issuer.php index 357238c81..e315a689e 100644 --- a/src/Resources/Issuer.php +++ b/src/Resources/Issuer.php @@ -22,6 +22,7 @@ class Issuer extends BaseResource * The payment method this issuer belongs to. * * @see Mollie_API_Object_Method + * * @var string */ public $method; diff --git a/src/Resources/IssuerCollection.php b/src/Resources/IssuerCollection.php index c7223b8a7..b04a66758 100644 --- a/src/Resources/IssuerCollection.php +++ b/src/Resources/IssuerCollection.php @@ -2,6 +2,4 @@ namespace Mollie\Api\Resources; -class IssuerCollection extends BaseCollection -{ -} +class IssuerCollection extends BaseCollection {} diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index 640ebc623..f3eeaaf68 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Http\Requests\DynamicDeleteRequest; +use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Types\MandateStatus; class Mandate extends BaseResource @@ -79,20 +79,17 @@ public function isInvalid(): bool */ public function revoke(): ?Mandate { - if (! isset($this->_links->self->href)) { + if (! isset($this->id, $this->customerId)) { return $this; } - $body = [ - 'testmode' => $this->mode === 'test' ? true : false, - ]; - return $this ->connector - ->send(new DynamicDeleteRequest( - $this->_links->self->href, - self::class, + ->send((new RevokeMandateRequest( + $this->customerId, + $this->id, $this->mode === 'test' - )); + ))->test($this->mode === 'test')) + ->toResource(); } } diff --git a/src/Resources/MandateCollection.php b/src/Resources/MandateCollection.php index 8bf5fc74b..5955bf1e7 100644 --- a/src/Resources/MandateCollection.php +++ b/src/Resources/MandateCollection.php @@ -6,21 +6,16 @@ class MandateCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "mandates"; + public static string $collectionName = 'mandates'; /** * Resource class name. - * - * @var string */ public static string $resource = Mandate::class; /** - * @param string $status - * @return MandateCollection + * @param string $status */ public function whereStatus($status): self { diff --git a/src/Resources/MethodCollection.php b/src/Resources/MethodCollection.php index 0194f862c..b5faabac2 100644 --- a/src/Resources/MethodCollection.php +++ b/src/Resources/MethodCollection.php @@ -6,8 +6,6 @@ class MethodCollection extends BaseCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "methods"; + public static string $collectionName = 'methods'; } diff --git a/src/Resources/MethodPrice.php b/src/Resources/MethodPrice.php index 366a2366d..80bc5fa56 100644 --- a/src/Resources/MethodPrice.php +++ b/src/Resources/MethodPrice.php @@ -8,6 +8,7 @@ class MethodPrice extends BaseResource * The area or product-type where the pricing is applied for, translated in the optional locale passed. * * @example "The Netherlands" + * * @var string */ public $description; diff --git a/src/Resources/MethodPriceCollection.php b/src/Resources/MethodPriceCollection.php index 68ea66c14..c34b17fb6 100644 --- a/src/Resources/MethodPriceCollection.php +++ b/src/Resources/MethodPriceCollection.php @@ -2,6 +2,4 @@ namespace Mollie\Api\Resources; -class MethodPriceCollection extends BaseCollection -{ -} +class MethodPriceCollection extends BaseCollection {} diff --git a/src/Resources/Onboarding.php b/src/Resources/Onboarding.php index 7f29f8629..a0dd94ca9 100644 --- a/src/Resources/Onboarding.php +++ b/src/Resources/Onboarding.php @@ -39,25 +39,16 @@ class Onboarding extends BaseResource */ public $_links; - /** - * @return bool - */ public function needsData(): bool { return $this->status === OnboardingStatus::NEEDS_DATA; } - /** - * @return bool - */ public function isInReview(): bool { return $this->status === OnboardingStatus::IN_REVIEW; } - /** - * @return bool - */ public function isCompleted(): bool { return $this->status === OnboardingStatus::COMPLETED; diff --git a/src/Resources/Order.php b/src/Resources/Order.php deleted file mode 100644 index f3838653b..000000000 --- a/src/Resources/Order.php +++ /dev/null @@ -1,513 +0,0 @@ - PaymentCollection::class, - 'refunds' => RefundCollection::class, - 'shipments' => ShipmentCollection::class, - ]; - } - - /** - * Is this order created? - */ - public function isCreated(): bool - { - return $this->status === OrderStatus::CREATED; - } - - /** - * Is this order paid for? - */ - public function isPaid(): bool - { - return $this->status === OrderStatus::PAID; - } - - /** - * Is this order authorized? - */ - public function isAuthorized(): bool - { - return $this->status === OrderStatus::AUTHORIZED; - } - - /** - * Is this order canceled? - */ - public function isCanceled(): bool - { - return $this->status === OrderStatus::CANCELED; - } - - /** - * Is this order shipping? - */ - public function isShipping(): bool - { - return $this->status === OrderStatus::SHIPPING; - } - - /** - * Is this order completed? - */ - public function isCompleted(): bool - { - return $this->status === OrderStatus::COMPLETED; - } - - /** - * Is this order expired? - */ - public function isExpired(): bool - { - return $this->status === OrderStatus::EXPIRED; - } - - /** - * Is this order completed? - */ - public function isPending(): bool - { - return $this->status === OrderStatus::PENDING; - } - - /** - * Cancels this order. - * If the order was partially shipped, the status will be "completed" instead of - * "canceled". - * Will throw a ApiException if the order id is invalid or the resource cannot - * be found. - * - * @return Order - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancel() - { - return $this->connector->orders->cancel($this->id, $this->getPresetOptions()); - } - - /** - * Cancel a line for this order. - * The data array must contain a lines array. - * You can pass an empty lines array if you want to cancel all eligible lines. - * Returns null if successful. - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelLines(array $data): void - { - $this->connector->orderLines->cancelFor($this, $data); - } - - /** - * Cancels all eligible lines for this order. - * Returns null if successful. - * - * @param array $data - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function cancelAllLines($data = []): void - { - $data['lines'] = []; - - $this->connector->orderLines->cancelFor($this, $data); - } - - /** - * Get the line value objects - */ - public function lines(): OrderLineCollection - { - /** @var OrderLineCollection */ - return ResourceFactory::createBaseResourceCollection( - $this->connector, - OrderLine::class, - $this->lines - ); - } - - /** - * Create a shipment for some order lines. You can provide an empty array for the - * "lines" option to include all unshipped lines for this order. - * - * - * @throws ApiException - */ - public function createShipment(array $options = []): Shipment - { - return $this->connector->shipments->createFor($this, $this->withPresetOptions($options)); - } - - /** - * Create a shipment for all unshipped order lines. - */ - public function shipAll(array $options = []): Shipment - { - $options['lines'] = []; - - return $this->createShipment($options); - } - - /** - * Retrieve a specific shipment for this order. - * - * @param string $shipmentId - * @return Shipment - * - * @throws ApiException - */ - public function getShipment($shipmentId, array $parameters = []) - { - return $this->connector->shipments->getFor($this, $shipmentId, $this->withPresetOptions($parameters)); - } - - /** - * Get all shipments for this order. - * - * - * @throws ApiException - */ - public function shipments(array $parameters = []): ShipmentCollection - { - return $this->connector->shipments->listFor($this, $this->withPresetOptions($parameters)); - } - - /** - * Get the checkout URL where the customer can complete the payment. - */ - public function getCheckoutUrl(): ?string - { - if (empty($this->_links->checkout)) { - return null; - } - - return $this->_links->checkout->href; - } - - /** - * Refund specific order lines. - * - * @throws ApiException - */ - public function refund(array $data): Refund - { - return $this->connector->orderRefunds->createFor($this, $this->withPresetOptions($data)); - } - - /** - * Refund all eligible order lines. - */ - public function refundAll(array $data = []): Refund - { - $data['lines'] = []; - - return $this->refund($data); - } - - /** - * Retrieves all refunds associated with this order - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function refunds(): RefundCollection - { - return $this->connector->orderRefunds->pageFor($this); - } - - /** - * Saves the order's updated billingAddress and/or shippingAddress. - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function update(): ?Order - { - $body = [ - 'billingAddress' => $this->billingAddress, - 'shippingAddress' => $this->shippingAddress, - 'orderNumber' => $this->orderNumber, - 'redirectUrl' => $this->redirectUrl, - 'cancelUrl' => $this->cancelUrl, - 'webhookUrl' => $this->webhookUrl, - ]; - - /** @var null|Order */ - return $this->connector->orders->update($this->id, $body); - } - - /** - * Create a new payment for this Order. - * - * @param array $data - * @param array $filters - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createPayment($data, $filters = []): Payment - { - return $this->connector->orderPayments->createFor($this, $data, $filters); - } - - /** - * Retrieve the payments for this order. - * Requires the order to be retrieved using the embed payments parameter. - */ - public function payments(): ?PaymentCollection - { - if (! isset($this->_embedded, $this->_embedded->payments)) { - return null; - } - - /** @var PaymentCollection */ - return ResourceFactory::createBaseResourceCollection( - $this->connector, - Payment::class, - $this->_embedded->payments, - ); - } -} diff --git a/src/Resources/OrderCollection.php b/src/Resources/OrderCollection.php deleted file mode 100644 index a5889220a..000000000 --- a/src/Resources/OrderCollection.php +++ /dev/null @@ -1,20 +0,0 @@ -_links->productUrl)) { - return null; - } - - return $this->_links->productUrl; - } - - /** - * Get the image URL of the product sold. - */ - public function getImageUrl(): ?string - { - if (empty($this->_links->imageUrl)) { - return null; - } - - return $this->_links->imageUrl; - } - - /** - * Is this order line created? - */ - public function isCreated(): bool - { - return $this->status === OrderLineStatus::CREATED; - } - - /** - * Is this order line paid for? - */ - public function isPaid(): bool - { - return $this->status === OrderLineStatus::PAID; - } - - /** - * Is this order line authorized? - */ - public function isAuthorized(): bool - { - return $this->status === OrderLineStatus::AUTHORIZED; - } - - /** - * Is this order line canceled? - */ - public function isCanceled(): bool - { - return $this->status === OrderLineStatus::CANCELED; - } - - /** - * Is this order line shipping? - */ - public function isShipping(): bool - { - return $this->status === OrderLineStatus::SHIPPING; - } - - /** - * Is this order line completed? - */ - public function isCompleted(): bool - { - return $this->status === OrderLineStatus::COMPLETED; - } - - /** - * Is this order line for a physical product? - */ - public function isPhysical(): bool - { - return $this->type === OrderLineType::PHYSICAL; - } - - /** - * Is this order line for applying a discount? - */ - public function isDiscount(): bool - { - return $this->type === OrderLineType::DISCOUNT; - } - - /** - * Is this order line for a digital product? - */ - public function isDigital(): bool - { - return $this->type === OrderLineType::DIGITAL; - } - - /** - * Is this order line for applying a shipping fee? - */ - public function isShippingFee(): bool - { - return $this->type === OrderLineType::SHIPPING_FEE; - } - - /** - * Is this order line for store credit? - */ - public function isStoreCredit(): bool - { - return $this->type === OrderLineType::STORE_CREDIT; - } - - /** - * Is this order line for a gift card? - */ - public function isGiftCard(): bool - { - return $this->type === OrderLineType::GIFT_CARD; - } - - /** - * Is this order line for a surcharge? - */ - public function isSurcharge(): bool - { - return $this->type === OrderLineType::SURCHARGE; - } - - /** - * Update an orderline by supplying one or more parameters in the data array - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function update(): ?Order - { - /** @var null|Order */ - return $this->connector->orderLines->update($this->orderId, $this->id, $this->getUpdateData()); - } - - /** - * Get sanitized array of order line data - */ - public function getUpdateData(): array - { - $data = [ - 'name' => $this->name, - 'imageUrl' => $this->imageUrl, - 'productUrl' => $this->productUrl, - 'metadata' => $this->metadata, - 'sku' => $this->sku, - 'quantity' => $this->quantity, - 'unitPrice' => $this->unitPrice, - 'discountAmount' => $this->discountAmount, - 'totalAmount' => $this->totalAmount, - 'vatAmount' => $this->vatAmount, - 'vatRate' => $this->vatRate, - ]; - - // Explicitly filter only NULL values to keep "vatRate => 0" intact - return array_filter($data, function ($value) { - return $value !== null; - }); - } -} diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php index aad7e387e..dfaecdefc 100644 --- a/src/Resources/OrderLineCollection.php +++ b/src/Resources/OrderLineCollection.php @@ -8,8 +8,7 @@ class OrderLineCollection extends BaseCollection * Get a specific order line. * Returns null if the order line cannot be found. * - * @param string $lineId - * @return OrderLine|null + * @param string $lineId */ public function get($lineId): ?OrderLine { diff --git a/src/Resources/PaymentCollection.php b/src/Resources/PaymentCollection.php index f31b78f8d..b1ebca308 100644 --- a/src/Resources/PaymentCollection.php +++ b/src/Resources/PaymentCollection.php @@ -6,15 +6,11 @@ class PaymentCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "payments"; + public static string $collectionName = 'payments'; /** * Resource class name. - * - * @var string */ public static string $resource = Payment::class; } diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index c35a6df6d..524643ab1 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -4,6 +4,8 @@ class PaymentLink extends BaseResource { + public static string $resourceIdPrefix = 'pl_'; + /** * Id of the payment link (on the Mollie platform). * diff --git a/src/Resources/PaymentLinkCollection.php b/src/Resources/PaymentLinkCollection.php index 1113b60dd..ea70210e6 100644 --- a/src/Resources/PaymentLinkCollection.php +++ b/src/Resources/PaymentLinkCollection.php @@ -6,15 +6,11 @@ class PaymentLinkCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "payment_links"; + public static string $collectionName = 'payment_links'; /** * Resource class name. - * - * @var string */ public static string $resource = PaymentLink::class; } diff --git a/src/Resources/Permission.php b/src/Resources/Permission.php index fe0761d0a..fb140b1a8 100644 --- a/src/Resources/Permission.php +++ b/src/Resources/Permission.php @@ -6,6 +6,7 @@ class Permission extends BaseResource { /** * @var string + * * @example payments.read */ public $id; diff --git a/src/Resources/PermissionCollection.php b/src/Resources/PermissionCollection.php index 08fa05dee..dfd3be0fb 100644 --- a/src/Resources/PermissionCollection.php +++ b/src/Resources/PermissionCollection.php @@ -6,8 +6,6 @@ class PermissionCollection extends BaseCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "permissions"; + public static string $collectionName = 'permissions'; } diff --git a/src/Resources/ProfileCollection.php b/src/Resources/ProfileCollection.php index fbe586e55..e8fe21133 100644 --- a/src/Resources/ProfileCollection.php +++ b/src/Resources/ProfileCollection.php @@ -6,15 +6,11 @@ class ProfileCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "profiles"; + public static string $collectionName = 'profiles'; /** * Resource class name. - * - * @var string */ public static string $resource = Profile::class; } diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index 7c0acaa04..1c74c24b8 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Http\Requests\DynamicDeleteRequest; +use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Types\RefundStatus; class Refund extends BaseResource @@ -164,8 +164,9 @@ public function cancel(): void { $this ->connector - ->send(new DynamicDeleteRequest( - $this->_links->self->href - )); + ->send((new CancelPaymentRefundRequest( + $this->paymentId, + $this->id + ))->test($this->mode === 'test')); } } diff --git a/src/Resources/RefundCollection.php b/src/Resources/RefundCollection.php index 0d1cd3c97..1ab9eecfd 100644 --- a/src/Resources/RefundCollection.php +++ b/src/Resources/RefundCollection.php @@ -6,15 +6,11 @@ class RefundCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "refunds"; + public static string $collectionName = 'refunds'; /** * Resource class name. - * - * @var string */ public static string $resource = Refund::class; } diff --git a/src/Resources/Route.php b/src/Resources/Route.php index 20b119d34..a2bfa8331 100644 --- a/src/Resources/Route.php +++ b/src/Resources/Route.php @@ -4,6 +4,8 @@ class Route extends BaseResource { + public static string $resourceIdPrefix = 'rt_'; + /** * Id of the payment method. * @@ -29,6 +31,7 @@ class Route extends BaseResource * A UTC date. The settlement of a routed payment can be delayed on payment level, by specifying a release Date * * @example "2013-12-25" + * * @var string */ public $releaseDate; diff --git a/src/Resources/Session.php b/src/Resources/Session.php index 842559b73..6913d5c9c 100644 --- a/src/Resources/Session.php +++ b/src/Resources/Session.php @@ -12,6 +12,7 @@ class Session extends BaseResource * The session's unique identifier, * * @example sess_dfsklg13jO + * * @var string */ public $id; @@ -27,6 +28,7 @@ class Session extends BaseResource * UTC datetime indicating the time at which the Session failed in ISO-8601 format. * * @example "2013-12-25T10:30:54+00:00" + * * @var string|null */ public $failedAt; @@ -96,6 +98,7 @@ class Session extends BaseResource * The person and the address the payment is shipped to. * * @deprecated + * * @var \stdClass */ public $shippingAddress; @@ -104,13 +107,14 @@ class Session extends BaseResource * The person and the address the payment is billed to. * * @deprecated - * @var \stdClass * + * @var \stdClass */ public $billingAddress; /** * An object with several URL objects relevant to the customer. Every URL object will contain an href and a type field. + * * @var \stdClass */ public $_links; @@ -139,6 +143,7 @@ public function hasFailed() * Saves the session's updatable properties. * * @return \Mollie\Api\Resources\Session + * * @throws \Mollie\Api\Exceptions\ApiException */ public function update() @@ -157,6 +162,7 @@ public function update() * Cancels this session. * * @return Session + * * @throws \Mollie\Api\Exceptions\ApiException */ public function cancel() diff --git a/src/Resources/SessionCollection.php b/src/Resources/SessionCollection.php index b1414c36b..4cdd8351b 100644 --- a/src/Resources/SessionCollection.php +++ b/src/Resources/SessionCollection.php @@ -9,7 +9,7 @@ class SessionCollection extends CursorCollection */ public function getCollectionResourceName() { - return "sessions"; + return 'sessions'; } /** diff --git a/src/Resources/Settlement.php b/src/Resources/Settlement.php index e514f777c..9dd9f0389 100644 --- a/src/Resources/Settlement.php +++ b/src/Resources/Settlement.php @@ -7,6 +7,8 @@ class Settlement extends BaseResource { + public static string $resourceIdPrefix = 'stl_'; + /** * Id of the settlement. * diff --git a/src/Resources/SettlementCollection.php b/src/Resources/SettlementCollection.php index dd759f684..186128237 100644 --- a/src/Resources/SettlementCollection.php +++ b/src/Resources/SettlementCollection.php @@ -6,15 +6,11 @@ class SettlementCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "settlements"; + public static string $collectionName = 'settlements'; /** * Resource class name. - * - * @var string */ public static string $resource = Settlement::class; } diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php deleted file mode 100644 index 602dd38c3..000000000 --- a/src/Resources/Shipment.php +++ /dev/null @@ -1,119 +0,0 @@ -tracking !== null; - } - - /** - * Does this shipment offer a track and trace code? - */ - public function hasTrackingUrl(): bool - { - return $this->hasTracking() && ! empty($this->tracking->url); - } - - /** - * Retrieve the track and trace url. Returns null if there is no url available. - */ - public function getTrackingUrl(): ?string - { - if (! $this->hasTrackingUrl()) { - return null; - } - - return $this->tracking->url; - } - - /** - * Get the line value objects - */ - public function lines(): OrderLineCollection - { - /** @var OrderLineCollection */ - return ResourceFactory::createBaseResourceCollection( - $this->connector, - OrderLine::class, - $this->lines - ); - } - - /** - * Get the Order object for this shipment - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function order(): Order - { - return $this->connector->orders->get($this->orderId); - } - - /** - * Save changes made to this shipment. - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function update(): ?Shipment - { - $body = [ - 'tracking' => $this->tracking, - ]; - - return $this->connector->shipments->update($this->orderId, $this->id, $body); - } -} diff --git a/src/Resources/ShipmentCollection.php b/src/Resources/ShipmentCollection.php index 5bf66633c..028c2ee6e 100644 --- a/src/Resources/ShipmentCollection.php +++ b/src/Resources/ShipmentCollection.php @@ -6,8 +6,6 @@ class ShipmentCollection extends BaseCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ public static string $collectionName = 'shipments'; } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 9410f98f9..2cd447e81 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -2,12 +2,14 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Http\Requests\DynamicDeleteRequest; +use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\SubscriptionStatus; class Subscription extends BaseResource { + public static string $resourceIdPrefix = 'sub_'; + /** * @var string */ @@ -182,11 +184,10 @@ public function cancel(): ?Subscription return $this ->connector - ->send(new DynamicDeleteRequest( - $this->_links->self->href, - self::class, - $this->mode === 'test' - )); + ->send((new CancelSubscriptionRequest( + $this->customerId, + $this->id + ))->test($this->mode === 'test')); } /** diff --git a/src/Resources/SubscriptionCollection.php b/src/Resources/SubscriptionCollection.php index f1799621a..eb0541ec0 100644 --- a/src/Resources/SubscriptionCollection.php +++ b/src/Resources/SubscriptionCollection.php @@ -6,15 +6,11 @@ class SubscriptionCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "subscriptions"; + public static string $collectionName = 'subscriptions'; /** * Resource class name. - * - * @var string */ public static string $resource = Subscription::class; } diff --git a/src/Resources/Terminal.php b/src/Resources/Terminal.php index a4ff90a83..e419a3ec7 100644 --- a/src/Resources/Terminal.php +++ b/src/Resources/Terminal.php @@ -6,6 +6,8 @@ class Terminal extends BaseResource { + public static string $resourceIdPrefix = 'term_'; + /** * @var string */ @@ -15,6 +17,7 @@ class Terminal extends BaseResource * Id of the terminal (on the Mollie platform). * * @example term_7MgL4wea46qkRcoTZjWEH + * * @var string */ public $id; @@ -23,6 +26,7 @@ class Terminal extends BaseResource * The profile ID this terminal belongs to. * * @example pfl_QkEhN94Ba + * * @var string */ public $profileId; @@ -33,6 +37,7 @@ class Terminal extends BaseResource * active means payments are accepted, and inactive means it is deactivated. * * @example active + * * @var string */ public $status; @@ -62,6 +67,7 @@ class Terminal extends BaseResource * The currency which is set for the terminal, in ISO 4217 format. * * @example EUR + * * @var string */ public $currency; @@ -78,6 +84,7 @@ class Terminal extends BaseResource * The timezone of the terminal. * * @example Europe/Brussels + * * @var string */ public $timezone; @@ -86,6 +93,7 @@ class Terminal extends BaseResource * This will be a full locale provided by the user. * * @example nl_NL + * * @var string */ public $locale; @@ -94,6 +102,7 @@ class Terminal extends BaseResource * UTC datetime the terminal was created, in ISO 8601 format. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $createdAt; @@ -102,6 +111,7 @@ class Terminal extends BaseResource * UTC datetime the terminal was last updated, in ISO 8601 format. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $updatedAt; @@ -111,6 +121,7 @@ class Terminal extends BaseResource * This parameter is omitted if the terminal is not disabled yet. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $disabledAt; @@ -120,6 +131,7 @@ class Terminal extends BaseResource * This parameter is omitted if the terminal is not active yet. * * @example "2021-12-25T10:30:54+00:00" + * * @var string */ public $activatedAt; @@ -131,25 +143,16 @@ class Terminal extends BaseResource */ public $_links; - /** - * @return bool - */ public function isPending(): bool { return $this->status === TerminalStatus::PENDING; } - /** - * @return bool - */ public function isActive(): bool { return $this->status === TerminalStatus::ACTIVE; } - /** - * @return bool - */ public function isInactive(): bool { return $this->status === TerminalStatus::INACTIVE; diff --git a/src/Resources/TerminalCollection.php b/src/Resources/TerminalCollection.php index 6aa47ce9a..fa78a655f 100644 --- a/src/Resources/TerminalCollection.php +++ b/src/Resources/TerminalCollection.php @@ -6,15 +6,11 @@ class TerminalCollection extends CursorCollection { /** * The name of the collection resource in Mollie's API. - * - * @var string */ - public static string $collectionName = "terminals"; + public static string $collectionName = 'terminals'; /** * Resource class name. - * - * @var string */ public static string $resource = Terminal::class; } diff --git a/src/Rules/Id.php b/src/Rules/Id.php deleted file mode 100644 index a66ca8024..000000000 --- a/src/Rules/Id.php +++ /dev/null @@ -1,43 +0,0 @@ -prefix = $prefix; - } - - public static function startsWithPrefix(string $prefix): self - { - return new self($prefix); - } - - public function validate($id, $context, Closure $fail): void - { - if (! $context instanceof Request) { - $fail('The Id rule can only be used on a Request instance.'); - } - - if (strpos($id, $this->prefix) !== 0) { - // @todo: message is wrong for child endpoints e.g. PaymentRefundsEndpointCollection - $resourceType = $this->getResourceType($context); - - $fail("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '".$this->prefix."'."); - } - } - - public function getResourceType(Request $request): string - { - $classBasename = basename(str_replace('\\', '/', $request->getTargetResourceClass())); - - return strtolower($classBasename); - } -} diff --git a/src/Rules/Included.php b/src/Rules/Included.php deleted file mode 100644 index f54403884..000000000 --- a/src/Rules/Included.php +++ /dev/null @@ -1,48 +0,0 @@ -allowed = $allowed; - } - - /** - * @param string|array $classOrArray - */ - public static function in($classOrArray): self - { - if (is_array($classOrArray)) { - return new self($classOrArray); - } - - $reflection = new ReflectionClass($classOrArray); - - return new self($reflection->getConstants()); - } - - public function validate($value, $context, Closure $fail): void - { - $values = explode(',', $value); - - foreach ($values as $value) { - if (! in_array($value, $this->allowed)) { - $fail("Invalid include: '{$value}'. Allowed are: ".implode(', ', $this->allowed).'.'); - } - } - } -} diff --git a/src/Rules/Matches.php b/src/Rules/Matches.php deleted file mode 100644 index be318cd27..000000000 --- a/src/Rules/Matches.php +++ /dev/null @@ -1,29 +0,0 @@ -pattern = $pattern; - } - - public static function pattern(string $pattern): self - { - return new self($pattern); - } - - public function validate($value, $context, Closure $fail): void - { - if (! preg_match($this->pattern, $value)) { - $fail("The value {$value} does not match the pattern: {$this->pattern}"); - } - } -} diff --git a/src/Rules/Max.php b/src/Rules/Max.php deleted file mode 100644 index 035451d6f..000000000 --- a/src/Rules/Max.php +++ /dev/null @@ -1,33 +0,0 @@ -max = $max; - } - - public static function value(int $max): self - { - return new self($max); - } - - public function validate($value, $context, Closure $fail): void - { - $length = is_numeric($value) ? $value : strlen($value); - - if ($length > $this->max) { - $fail("The value must not exceed {$this->max}."); - } - } -} diff --git a/src/Rules/Min.php b/src/Rules/Min.php deleted file mode 100644 index 1974453f5..000000000 --- a/src/Rules/Min.php +++ /dev/null @@ -1,33 +0,0 @@ -min = $min; - } - - public static function value(int $min): self - { - return new self($min); - } - - public function validate($value, $context, Closure $fail): void - { - $length = is_numeric($value) ? $value : strlen($value); - - if ($length < $this->min) { - $fail("The value must be at least {$this->min}."); - } - } -} diff --git a/src/Traits/GetAllConstants.php b/src/Traits/GetAllConstants.php new file mode 100644 index 000000000..01e9f57fa --- /dev/null +++ b/src/Traits/GetAllConstants.php @@ -0,0 +1,13 @@ +getConstants()); + } +} diff --git a/src/Traits/HandlesResourceCreation.php b/src/Traits/HandlesResourceCreation.php index cd38d9388..302049f3a 100644 --- a/src/Traits/HandlesResourceCreation.php +++ b/src/Traits/HandlesResourceCreation.php @@ -4,6 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Http\Request; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\BaseResource; @@ -16,7 +17,7 @@ trait HandlesResourceCreation /** * @return mixed */ - protected function createResource(Request $request, Response $response) + protected function createResource(ResourceHydratableRequest $request, Response $response) { $targetResourceClass = $request->getTargetResourceClass(); diff --git a/src/Traits/HandlesTestmode.php b/src/Traits/HandlesTestmode.php index 315905ff5..e7f547afb 100644 --- a/src/Traits/HandlesTestmode.php +++ b/src/Traits/HandlesTestmode.php @@ -4,19 +4,17 @@ trait HandlesTestmode { - protected bool $testmode = false; + protected ?bool $testmode = null; - public function enableTestmode(): self + public function test(bool $testmode = true): self { - $this->testmode = true; + $this->testmode = $testmode; return $this; } - public function disableTestmode(): self + public function getTestmode(): ?bool { - $this->testmode = false; - - return $this; + return $this->testmode; } } diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 749950423..73587f960 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -7,39 +7,33 @@ use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; use Mollie\Api\EndpointCollection\CustomerEndpointCollection; +use Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection; +use Mollie\Api\EndpointCollection\InvoiceEndpointCollection; +use Mollie\Api\EndpointCollection\MandateEndpointCollection; +use Mollie\Api\EndpointCollection\MethodEndpointCollection; +use Mollie\Api\EndpointCollection\MethodIssuerEndpointCollection; +use Mollie\Api\EndpointCollection\OnboardingEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; +use Mollie\Api\EndpointCollection\OrganizationPartnerEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentLinkEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentLinkPaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Endpoints\CustomerPaymentsEndpoint; -use Mollie\Api\Endpoints\InvoiceEndpoint; -use Mollie\Api\Endpoints\MandateEndpoint; -use Mollie\Api\Endpoints\MethodEndpoint; -use Mollie\Api\Endpoints\MethodIssuerEndpoint; -use Mollie\Api\Endpoints\OnboardingEndpoint; -use Mollie\Api\Endpoints\OrderEndpoint; -use Mollie\Api\Endpoints\OrderLineEndpoint; -use Mollie\Api\Endpoints\OrderPaymentEndpoint; -use Mollie\Api\Endpoints\OrderRefundEndpoint; -use Mollie\Api\Endpoints\OrderShipmentEndpoint; -use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; -use Mollie\Api\Endpoints\PaymentCaptureEndpoint; -use Mollie\Api\Endpoints\PaymentChargebackEndpoint; -use Mollie\Api\Endpoints\PaymentLinkEndpoint; -use Mollie\Api\Endpoints\PaymentLinkPaymentEndpoint; -use Mollie\Api\Endpoints\PaymentRouteEndpoint; -use Mollie\Api\Endpoints\PermissionEndpoint; -use Mollie\Api\Endpoints\ProfileEndpoint; +use Mollie\Api\EndpointCollection\PaymentRouteEndpointCollection; +use Mollie\Api\EndpointCollection\PermissionEndpointCollection; +use Mollie\Api\EndpointCollection\ProfileEndpointCollection; +use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementsEndpointCollection; +use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; +use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; +use Mollie\Api\EndpointCollection\TerminalEndpointCollection; +use Mollie\Api\EndpointCollection\WalletEndpointCollection; use Mollie\Api\Endpoints\ProfileMethodEndpoint; -use Mollie\Api\Endpoints\RefundEndpoint; -use Mollie\Api\Endpoints\SettlementCaptureEndpoint; -use Mollie\Api\Endpoints\SettlementChargebackEndpoint; -use Mollie\Api\Endpoints\SettlementPaymentEndpoint; -use Mollie\Api\Endpoints\SettlementRefundEndpoint; -use Mollie\Api\Endpoints\SettlementsEndpoint; -use Mollie\Api\Endpoints\SubscriptionEndpoint; -use Mollie\Api\Endpoints\SubscriptionPaymentEndpoint; -use Mollie\Api\Endpoints\TerminalEndpoint; -use Mollie\Api\Endpoints\WalletEndpoint; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\BalanceTransactionCollection; @@ -65,40 +59,35 @@ protected function initializeHasEndpoints(): void 'chargebacks' => ChargebackEndpointCollection::class, 'clients' => ClientEndpointCollection::class, 'clientLinks' => ClientLinkEndpointCollection::class, - 'customerPayments' => CustomerPaymentsEndpoint::class, + 'customerPayments' => CustomerPaymentsEndpointCollection::class, 'customers' => CustomerEndpointCollection::class, - 'invoices' => InvoiceEndpoint::class, - 'mandates' => MandateEndpoint::class, - 'methods' => MethodEndpoint::class, - 'methodIssuers' => MethodIssuerEndpoint::class, - 'onboarding' => OnboardingEndpoint::class, - 'orderLines' => OrderLineEndpoint::class, - 'orderPayments' => OrderPaymentEndpoint::class, - 'orderRefunds' => OrderRefundEndpoint::class, - 'orders' => OrderEndpoint::class, - 'organizationPartners' => OrganizationPartnerEndpoint::class, + 'invoices' => InvoiceEndpointCollection::class, + 'mandates' => MandateEndpointCollection::class, + 'methods' => MethodEndpointCollection::class, + 'methodIssuers' => MethodIssuerEndpointCollection::class, + 'onboarding' => OnboardingEndpointCollection::class, + 'organizationPartners' => OrganizationPartnerEndpointCollection::class, 'organizations' => OrganizationEndpointCollection::class, 'payments' => PaymentEndpointCollection::class, 'paymentRefunds' => PaymentRefundEndpointCollection::class, - 'paymentCaptures' => PaymentCaptureEndpoint::class, - 'paymentChargebacks' => PaymentChargebackEndpoint::class, - 'paymentLinks' => PaymentLinkEndpoint::class, - 'paymentLinkPayments' => PaymentLinkPaymentEndpoint::class, - 'paymentRoutes' => PaymentRouteEndpoint::class, - 'permissions' => PermissionEndpoint::class, - 'profiles' => ProfileEndpoint::class, + 'paymentCaptures' => PaymentCaptureEndpointCollection::class, + 'paymentChargebacks' => ChargebackEndpointCollection::class, + 'paymentLinks' => PaymentLinkEndpointCollection::class, + 'paymentLinkPayments' => PaymentLinkPaymentEndpointCollection::class, + 'paymentRoutes' => PaymentRouteEndpointCollection::class, + 'permissions' => PermissionEndpointCollection::class, + 'profiles' => ProfileEndpointCollection::class, 'profileMethods' => ProfileMethodEndpoint::class, - 'refunds' => RefundEndpoint::class, - 'settlementCaptures' => SettlementCaptureEndpoint::class, - 'settlementChargebacks' => SettlementChargebackEndpoint::class, - 'settlementPayments' => SettlementPaymentEndpoint::class, - 'settlementRefunds' => SettlementRefundEndpoint::class, - 'shipments' => OrderShipmentEndpoint::class, - 'settlements' => SettlementsEndpoint::class, - 'subscriptions' => SubscriptionEndpoint::class, - 'subscriptionPayments' => SubscriptionPaymentEndpoint::class, - 'terminals' => TerminalEndpoint::class, - 'wallets' => WalletEndpoint::class, + 'refunds' => RefundEndpointCollection::class, + 'settlementCaptures' => SettlementCaptureEndpointCollection::class, + 'settlementChargebacks' => SettlementChargebackEndpointCollection::class, + 'settlementPayments' => SettlementPaymentEndpointCollection::class, + 'settlementRefunds' => SettlementRefundEndpointCollection::class, + 'settlements' => SettlementsEndpointCollection::class, + 'subscriptions' => SubscriptionEndpointCollection::class, + 'subscriptionPayments' => SubscriptionPaymentEndpointCollection::class, + 'terminals' => TerminalEndpointCollection::class, + 'wallets' => WalletEndpointCollection::class, ]; foreach ($endpointClasses as $name => $class) { diff --git a/src/Traits/HasRules.php b/src/Traits/HasRules.php deleted file mode 100644 index c7bd02735..000000000 --- a/src/Traits/HasRules.php +++ /dev/null @@ -1,11 +0,0 @@ -getMock(); } - public function testCheckCompatibilityThrowsExceptionOnPhpVersion() + public function test_check_compatibility_throws_exception_on_php_version() { $this->expectException(\Mollie\Api\Exceptions\IncompatiblePlatform::class); $this->checker->expects($this->once()) @@ -36,7 +36,7 @@ public function testCheckCompatibilityThrowsExceptionOnPhpVersion() $this->checker->checkCompatibility(); } - public function testCheckCompatibilityThrowsExceptionOnJsonExtension() + public function test_check_compatibility_throws_exception_on_json_extension() { $this->expectException(\Mollie\Api\Exceptions\IncompatiblePlatform::class); $this->checker->expects($this->once()) diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 582336dca..8b70a5024 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -21,7 +21,7 @@ class BalanceEndpointCollectionTest extends TestCase use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testListBalances() + public function test_list_balances() { $client = new MockClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), @@ -86,7 +86,7 @@ public function testListBalances() ); } - public function testIterateBalances() + public function test_iterate_balances() { $client = new MockClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), @@ -98,7 +98,7 @@ public function testIterateBalances() } } - public function testGetBalance() + public function test_get_balance() { $client = new MockClient([ GetBalanceRequest::class => new MockResponse(200, 'balance'), @@ -122,7 +122,7 @@ public function testGetBalance() ); } - public function testGetPrimaryBalance() + public function test_get_primary_balance() { $client = new MockClient([ GetBalanceRequest::class => new MockResponse(200, 'balance'), diff --git a/tests/Helpers/UrlTest.php b/tests/Helpers/UrlTest.php index 5d5ab7af1..70d3d72b8 100644 --- a/tests/Helpers/UrlTest.php +++ b/tests/Helpers/UrlTest.php @@ -7,7 +7,7 @@ class UrlTest extends TestCase { - public function testJoin() + public function test_join() { $baseUrl = 'https://example.com'; $endpoint = '/api/v1/users'; @@ -18,7 +18,7 @@ public function testJoin() $this->assertEquals($expected, $result); } - public function testIsValid() + public function test_is_valid() { $validUrl = 'https://example.com'; $invalidUrl = 'example.com'; @@ -27,7 +27,7 @@ public function testIsValid() $this->assertFalse(Url::isValid($invalidUrl)); } - public function testParseQuery() + public function test_parse_query() { $query = 'param1=value1¶m2=value2'; diff --git a/tests/Helpers/ValidatorTest.php b/tests/Helpers/ValidatorTest.php deleted file mode 100644 index 9054b18b3..000000000 --- a/tests/Helpers/ValidatorTest.php +++ /dev/null @@ -1,124 +0,0 @@ -expectException(RequestValidationException::class); - $this->expectExceptionMessage("Invalid foo ID: 'bar_123'. A resource ID should start with 'foo'."); - - $foo = new HasProperties('bar_123'); - $validator = new Validator; - - $validator->validate($foo); - } - - /** @test */ - public function it_validates_all_validatable_properties_by_deferring_to_their_validate_methods() - { - $this->expectException(RequestValidationException::class); - $this->expectExceptionMessage("Invalid include: 'foo'. Allowed are: bar."); - - $foo = new HasValidatableProperties(new ValidatableData('foo')); - $validator = new Validator; - - $validator->validate($foo); - } - - /** @test */ - public function it_does_not_validate_null_validatable_properties() - { - $foo = new HasValidatableProperties(null); // ValidatableData is null - $validator = new Validator; - - // No exception should be thrown because the ValidatableData is null - $validator->validate($foo); - - $this->assertTrue(true); // If no exception is thrown, the test passes - } - - /** @test */ - public function it_validates_additional_properties_without_overriding_provider_data() - { - $this->expectException(RequestValidationException::class); - $this->expectExceptionMessage("Invalid foo ID: 'bar_123'. A resource ID should start with 'foo'."); - - $foo = new HasProperties('foo_123'); // Valid ID from provider - $validator = new Validator; - - $additional = ['extra_id' => 'bar_123']; // Invalid additional ID with a different key - - $validator->validate($foo, $additional); - } -} - -class HasProperties extends Request -{ - protected string $id; - - /** - * The resource class the request should be casted to. - */ - public static string $targetResourceClass = 'foo'; - - public function __construct(string $id) - { - $this->id = $id; - } - - public function resolveResourcePath(): string - { - return 'foo'; - } - - public function rules(): array - { - return [ - 'id' => Id::startsWithPrefix('foo'), - 'extra_id' => Id::startsWithPrefix('foo'), // New rule for extra_id - ]; - } -} - -class HasValidatableProperties implements ValidatableDataProvider -{ - protected ?ValidatableData $validatableData; - - public function __construct(?ValidatableData $validatableData) - { - $this->validatableData = $validatableData; - } - - public function rules(): array - { - return []; - } -} - -class ValidatableData implements ValidatableDataProvider -{ - protected string $included; - - public function __construct(string $included) - { - $this->included = $included; - } - - public function rules(): array - { - return [ - 'included' => Included::make(['bar']), - ]; - } -} diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index d98db72dd..831e524ee 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -17,7 +17,7 @@ class GuzzleMollieHttpAdapterTest extends TestCase { /** @test */ - public function testDebuggingIsSupported() + public function test_debugging_is_supported() { $adapter = GuzzleMollieHttpAdapter::createDefault(); $this->assertTrue($adapter instanceof SupportsDebuggingContract); @@ -31,7 +31,7 @@ public function testDebuggingIsSupported() } /** @test */ - public function whenDebuggingAnApiExceptionIncludesTheRequest() + public function when_debugging_an_api_exception_includes_the_request() { $guzzleClient = $this->createMock(Client::class); $guzzleClient @@ -59,7 +59,7 @@ public function whenDebuggingAnApiExceptionIncludesTheRequest() } /** @test */ - public function whenNotDebuggingAnApiExceptionIsExcludedFromTheRequest() + public function when_not_debugging_an_api_exception_is_excluded_from_the_request() { $guzzleClient = $this->createMock(Client::class); $guzzleClient diff --git a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php index 29ce12f7a..73ed55e79 100644 --- a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php +++ b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php @@ -11,7 +11,7 @@ class MollieHttpAdapterPickerTest extends TestCase { /** @test */ - public function createsAGuzzleAdapterIfNullIsPassedAndGuzzleIsDetected() + public function creates_a_guzzle_adapter_if_null_is_passed_and_guzzle_is_detected() { $picker = new MollieHttpAdapterPicker; @@ -21,7 +21,7 @@ public function createsAGuzzleAdapterIfNullIsPassedAndGuzzleIsDetected() } /** @test */ - public function returnsTheAdapterThatWasPassedIn() + public function returns_the_adapter_that_was_passed_in() { $picker = new MollieHttpAdapterPicker; $mockAdapter = new MockMollieHttpAdapter; @@ -33,7 +33,7 @@ public function returnsTheAdapterThatWasPassedIn() } /** @test */ - public function wrapsAGuzzleClientIntoAnAdapter() + public function wraps_a_guzzle_client_into_an_adapter() { $picker = new MollieHttpAdapterPicker; $guzzleClient = new GuzzleClient; @@ -44,7 +44,7 @@ public function wrapsAGuzzleClientIntoAnAdapter() } /** @test */ - public function throwsAnExceptionWhenReceivingAnUnrecognizedClient() + public function throws_an_exception_when_receiving_an_unrecognized_client() { $this->expectExceptionObject(new UnrecognizedClientException('The provided http client or adapter was not recognized')); $picker = new MollieHttpAdapterPicker; diff --git a/tests/Http/Adapter/RetryMiddlewareFactoryTest.php b/tests/Http/Adapter/RetryMiddlewareFactoryTest.php index 0b57a4543..084cf373f 100644 --- a/tests/Http/Adapter/RetryMiddlewareFactoryTest.php +++ b/tests/Http/Adapter/RetryMiddlewareFactoryTest.php @@ -13,7 +13,7 @@ class RetryMiddlewareFactoryTest extends TestCase { - public function testRetriesConnectException() + public function test_retries_connect_exception() { $middlewareFactory = new GuzzleRetryMiddlewareFactory; @@ -33,7 +33,7 @@ public function testRetriesConnectException() $this->assertEquals(200, $finalResponse->getStatusCode()); } - public function testRetryLimit() + public function test_retry_limit() { $middlewareFactory = new GuzzleRetryMiddlewareFactory; @@ -58,7 +58,7 @@ public function testRetryLimit() $client->request('GET', '/')->getStatusCode(); } - public function testRetryDelay() + public function test_retry_delay() { $middlewareFactory = new GuzzleRetryMiddlewareFactory; diff --git a/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php index a8b414065..e4eca6fe2 100644 --- a/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php @@ -16,7 +16,7 @@ class BalanceReportEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testCanGetReportThroughBalanceReportEndpoint() + public function test_can_get_report_through_balance_report_endpoint() { $this->mockApiCall( new Request( @@ -42,7 +42,7 @@ public function testCanGetReportThroughBalanceReportEndpoint() $this->assertBalanceReport($report); } - public function testCanGetPrimaryBalanceReportThroughBalanceReportEndpoint() + public function test_can_get_primary_balance_report_through_balance_report_endpoint() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php index c7ef795b4..bf2473fb4 100644 --- a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php @@ -18,7 +18,7 @@ class BalanceTransactionEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testGetBalanceTransactionsThroughEndpoint() + public function test_get_balance_transactions_through_endpoint() { $this->mockApiCall( new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), @@ -98,7 +98,7 @@ public function testGetBalanceTransactionsThroughEndpoint() $this->assertTransactions($transactions); } - public function testIteratorForBalanceTransactionsThroughEndpoint() + public function test_iterator_for_balance_transactions_through_endpoint() { $this->mockApiCall( new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), @@ -178,7 +178,7 @@ public function testIteratorForBalanceTransactionsThroughEndpoint() } } - public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() + public function test_get_primary_balance_transactions_through_balance_transaction_endpoint() { $this->mockApiCall( new Request('GET', '/v2/balances/primary/transactions'), @@ -255,7 +255,7 @@ public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoi $this->assertTransactions($transactions); } - public function testIteratorForPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() + public function test_iterator_for_primary_balance_transactions_through_balance_transaction_endpoint() { $this->mockApiCall( new Request('GET', '/v2/balances/primary/transactions'), diff --git a/tests/Mollie/API/Endpoints/BaseEndpointTest.php b/tests/Mollie/API/Endpoints/BaseEndpointTest.php index cb8a02e42..23b1e9d0e 100644 --- a/tests/Mollie/API/Endpoints/BaseEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BaseEndpointTest.php @@ -27,9 +27,9 @@ protected function mockApiCall(Request $expectedRequest, Response $response, $oA $this->apiClient = new MollieApiClient($this->guzzleClient); if (! $oAuthClient) { - $this->apiClient->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); + $this->apiClient->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); } else { - $this->apiClient->setAccessToken("access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ"); + $this->apiClient->setAccessToken('access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ'); } $this->guzzleClient @@ -37,12 +37,12 @@ protected function mockApiCall(Request $expectedRequest, Response $response, $oA ->method('send') ->with($this->isInstanceOf(Request::class)) ->willReturnCallback(function (Request $request) use ($expectedRequest, $response) { - $this->assertEquals($expectedRequest->getMethod(), $request->getMethod(), "HTTP method must be identical"); + $this->assertEquals($expectedRequest->getMethod(), $request->getMethod(), 'HTTP method must be identical'); $this->assertEquals( $expectedRequest->getUri()->getPath(), $request->getUri()->getPath(), - "URI path must be identical" + 'URI path must be identical' ); $this->assertEquals( @@ -58,7 +58,7 @@ protected function mockApiCall(Request $expectedRequest, Response $response, $oA $this->assertJsonStringEqualsJsonString( $expectedBody, $requestBody, - "HTTP body must be identical" + 'HTTP body must be identical' ); } diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index 6f769d520..1645b76d5 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -14,7 +14,7 @@ class ChargebackEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testListChargebacks() + public function test_list_chargebacks() { $this->mockApiCall( new Request( @@ -129,7 +129,7 @@ public function testListChargebacks() $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', '-0.37', null); } - public function testIterateChargebacks() + public function test_iterate_chargebacks() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php index 0fed72aec..3cd92eb25 100644 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientEndpointTest.php @@ -12,7 +12,7 @@ class ClientEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testGetClient() + public function test_get_client() { $this->mockApiCall( new Request('GET', '/v2/clients/org_1337'), @@ -57,7 +57,7 @@ public function testGetClient() $this->assertClient($client); } - public function testGetClientsPage() + public function test_get_clients_page() { $this->mockApiCall( new Request('GET', '/v2/clients', [], ''), diff --git a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php b/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php index 755526d47..14ca8c2fc 100644 --- a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php @@ -13,7 +13,7 @@ class ClientLinkEndpointTest extends BaseEndpointTest /** * @dataProvider clientCreateData */ - public function testCreateClientLink(string $client_link_id, string $app_id, string $state, array $scopes, string $approval_prompt, string $expected_url_query) + public function test_create_client_link(string $client_link_id, string $app_id, string $state, array $scopes, string $approval_prompt, string $expected_url_query) { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php index 20e939ba0..69d16cfbb 100644 --- a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php @@ -9,7 +9,7 @@ class CustomerEndpointTest extends BaseEndpointTest { - public function testCreateWorks() + public function test_create_works() { $this->mockApiCall( new Request('POST', '/v2/customers'), @@ -38,25 +38,25 @@ public function testCreateWorks() /** @var Customer $customer */ $customer = $this->apiClient->customers->create([ - "name" => "John Doe", - "email" => "johndoe@example.org", + 'name' => 'John Doe', + 'email' => 'johndoe@example.org', ]); $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals("customer", $customer->resource); - $this->assertEquals("cst_FhQJRw4s2n", $customer->id); - $this->assertEquals("John Doe", $customer->name); - $this->assertEquals("johndoe@example.org", $customer->email); + $this->assertEquals('customer', $customer->resource); + $this->assertEquals('cst_FhQJRw4s2n', $customer->id); + $this->assertEquals('John Doe', $customer->name); + $this->assertEquals('johndoe@example.org', $customer->email); $this->assertNull($customer->locale); $this->assertNull($customer->metadata); $this->assertEquals([], $customer->recentlyUsedMethods); - $this->assertEquals("2018-04-19T08:49:01+00:00", $customer->createdAt); + $this->assertEquals('2018-04-19T08:49:01+00:00', $customer->createdAt); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/create-customer", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/create-customer', 'type' => 'text/html']; $this->assertEquals($documentationLink, $customer->_links->documentation); } - public function testGetWorks() + public function test_get_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n'), @@ -84,23 +84,23 @@ public function testGetWorks() ); /** @var Customer $customer */ - $customer = $this->apiClient->customers->get("cst_FhQJRw4s2n"); + $customer = $this->apiClient->customers->get('cst_FhQJRw4s2n'); $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals("customer", $customer->resource); - $this->assertEquals("cst_FhQJRw4s2n", $customer->id); - $this->assertEquals("John Doe", $customer->name); - $this->assertEquals("johndoe@example.org", $customer->email); + $this->assertEquals('customer', $customer->resource); + $this->assertEquals('cst_FhQJRw4s2n', $customer->id); + $this->assertEquals('John Doe', $customer->name); + $this->assertEquals('johndoe@example.org', $customer->email); $this->assertNull($customer->locale); $this->assertNull($customer->metadata); $this->assertEquals([], $customer->recentlyUsedMethods); - $this->assertEquals("2018-04-19T08:49:01+00:00", $customer->createdAt); + $this->assertEquals('2018-04-19T08:49:01+00:00', $customer->createdAt); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/get-customer", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/get-customer', 'type' => 'text/html']; $this->assertEquals($documentationLink, $customer->_links->documentation); } - public function testListWorks() + public function test_list_works() { $this->mockApiCall( new Request('GET', '/v2/customers'), @@ -144,20 +144,20 @@ public function testListWorks() $this->assertInstanceOf(CustomerCollection::class, $customers); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/list-customers", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/list-customers', 'type' => 'text/html']; $this->assertEquals($documentationLink, $customers->_links->documentation); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers?limit=50", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $customers->_links->self); foreach ($customers as $customer) { $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals("customer", $customer->resource); + $this->assertEquals('customer', $customer->resource); $this->assertNotEmpty($customer->createdAt); } } - public function testIteratorWorks() + public function test_iterator_works() { $this->mockApiCall( new Request('GET', '/v2/customers'), @@ -199,12 +199,12 @@ public function testIteratorWorks() foreach ($this->apiClient->customers->iterator() as $customer) { $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals("customer", $customer->resource); + $this->assertEquals('customer', $customer->resource); $this->assertNotEmpty($customer->createdAt); } } - public function testUpdateWorks() + public function test_update_works() { $expectedName = 'Kaas Broodje'; $expectedEmail = 'kaas.broodje@gmail.com'; @@ -218,8 +218,8 @@ public function testUpdateWorks() "resource": "customer", "id": "cst_FhQJRw4s2n", "mode": "test", - "name": "' . $expectedName . '", - "email": "' . $expectedEmail . '", + "name": "'.$expectedName.'", + "email": "'.$expectedEmail.'", "locale": null, "metadata": null, "recentlyUsedMethods": [], diff --git a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php index 7dc563c07..23c8b57a5 100644 --- a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php @@ -13,12 +13,12 @@ class CustomerPaymentEndpointTest extends BaseEndpointTest { - public function testCreateCustomerPayment() + public function test_create_customer_payment() { $this->mockApiCall( new Request( - "POST", - "/v2/customers/cst_FhQJRw4s2n/payments", + 'POST', + '/v2/customers/cst_FhQJRw4s2n/payments', [], '{ "amount":{ @@ -84,59 +84,59 @@ public function testCreateCustomerPayment() $customer = $this->getCustomer(); $payment = $customer->createPayment([ - "amount" => [ - "currency" => "EUR", - "value" => "20.00", + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', ], - "description" => "My first API payment", - "redirectUrl" => "https://example.org/redirect", - "webhookUrl" => "https://example.org/webhook", - "metadata" => [ - "order_id" => "1234", + 'description' => 'My first API payment', + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + 'metadata' => [ + 'order_id' => '1234', ], ]); $this->assertInstanceOf(Payment::class, $payment); $this->assertEquals('tr_44aKxzEbr8', $payment->id); $this->assertEquals('test', $payment->mode); - $this->assertEquals("2018-03-13T14:02:29+00:00", $payment->createdAt); + $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $payment->amount); $this->assertEquals('My first API payment', $payment->description); $this->assertNull($payment->method); - $this->assertEquals((object)["order_id" => "1234"], $payment->metadata); + $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); $this->assertEquals(PaymentStatus::OPEN, $payment->status); $this->assertFalse($payment->isCancelable); - $this->assertEquals("2018-03-13T14:17:29+00:00", $payment->expiresAt); + $this->assertEquals('2018-03-13T14:17:29+00:00', $payment->expiresAt); $this->assertNull($payment->details); - $this->assertEquals("pfl_2A1gacu42V", $payment->profileId); + $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals("https://example.org/redirect", $payment->redirectUrl); - $this->assertEquals("https://example.org/webhook", $payment->webhookUrl); + $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); + $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $payment->_links->self); - $checkoutLink = (object)["href" => "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type" => "text/html"]; + $checkoutLink = (object) ['href' => 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', 'type' => 'text/html']; $this->assertEquals($checkoutLink, $payment->_links->checkout); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $payment->_links->customer); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/create-payment", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/create-payment', 'type' => 'text/html']; $this->assertEquals($documentationLink, $payment->_links->documentation); } - public function testListCustomerPayments() + public function test_list_customer_payments() { $this->mockApiCall( new Request( - "GET", - "/v2/customers/cst_FhQJRw4s2n/payments?testmode=true", + 'GET', + '/v2/customers/cst_FhQJRw4s2n/payments?testmode=true', [], '' ), @@ -280,10 +280,10 @@ public function testListCustomerPayments() $this->assertEquals(3, $payments->count()); $this->assertEquals(3, count($payments)); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/list-customer-payments', 'type' => 'text/html']; $this->assertEquals($documentationLink, $payments->_links->documentation); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $payments->_links->self); } diff --git a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php index 4b8b4c07c..85c7d4504 100644 --- a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php @@ -12,7 +12,7 @@ class CustomerSubscriptionPaymentEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testListWorks() + public function test_list_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments?testmode=true'), diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php index 12c338fff..2344738d1 100644 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php @@ -10,12 +10,12 @@ class InvoiceEndpointTest extends BaseEndpointTest { - public function testGetInvoice() + public function test_get_invoice() { $this->mockApiCall( new Request( - "GET", - "/v2/invoices/inv_bsa6PvAwaK", + 'GET', + '/v2/invoices/inv_bsa6PvAwaK', [], '' ), @@ -82,39 +82,39 @@ public function testGetInvoice() ) ); - $invoice = $this->apiClient->invoices->get("inv_bsa6PvAwaK"); + $invoice = $this->apiClient->invoices->get('inv_bsa6PvAwaK'); $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals("invoice", $invoice->resource); - $this->assertEquals("inv_bsa6PvAwaK", $invoice->id); - $this->assertEquals("2018.190241", $invoice->reference); - $this->assertEquals("123456789B01", $invoice->vatNumber); + $this->assertEquals('invoice', $invoice->resource); + $this->assertEquals('inv_bsa6PvAwaK', $invoice->id); + $this->assertEquals('2018.190241', $invoice->reference); + $this->assertEquals('123456789B01', $invoice->vatNumber); $this->assertEquals(InvoiceStatus::PAID, $invoice->status); - $this->assertEquals("2018-05-02", $invoice->issuedAt); - $this->assertEquals("2018-05-02", $invoice->paidAt); + $this->assertEquals('2018-05-02', $invoice->issuedAt); + $this->assertEquals('2018-05-02', $invoice->paidAt); - $this->assertEquals((object) ["value" => "100.00", "currency" => "EUR"], $invoice->netAmount); - $this->assertEquals((object) ["value" => "0.00", "currency" => "EUR"], $invoice->vatAmount); - $this->assertEquals((object) ["value" => "100.00", "currency" => "EUR"], $invoice->grossAmount); + $this->assertEquals((object) ['value' => '100.00', 'currency' => 'EUR'], $invoice->netAmount); + $this->assertEquals((object) ['value' => '0.00', 'currency' => 'EUR'], $invoice->vatAmount); + $this->assertEquals((object) ['value' => '100.00', 'currency' => 'EUR'], $invoice->grossAmount); $this->assertCount(2, $invoice->lines); - $selfLink = (object)['href' => 'https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $invoice->_links->self); - $pdfLink = (object)['href' => 'https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985', 'type' => 'application/pdf']; + $pdfLink = (object) ['href' => 'https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985', 'type' => 'application/pdf']; $this->assertEquals($pdfLink, $invoice->_links->pdf); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/get-invoice', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/invoices-api/get-invoice', 'type' => 'text/html']; $this->assertEquals($documentationLink, $invoice->_links->documentation); } - public function testListInvoices() + public function test_list_invoices() { $this->mockApiCall( new Request( - "GET", - "/v2/invoices", + 'GET', + '/v2/invoices', [], '' ), @@ -203,10 +203,10 @@ public function testListInvoices() $invoices = $this->apiClient->invoices->page(); $this->assertInstanceOf(InvoiceCollection::class, $invoices); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html']; $this->assertEquals($documentationLink, $invoices->_links->documentation); - $selfLink = (object)['href' => 'https://api.mollie.nl/v2/invoices?limit=50', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/invoices?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $invoices->_links->self); $this->assertEmpty($invoices->_links->previous); @@ -214,17 +214,17 @@ public function testListInvoices() foreach ($invoices as $invoice) { $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals("invoice", $invoice->resource); + $this->assertEquals('invoice', $invoice->resource); $this->assertNotEmpty($invoice->lines); } } - public function testIterateInvoices() + public function test_iterate_invoices() { $this->mockApiCall( new Request( - "GET", - "/v2/invoices", + 'GET', + '/v2/invoices', [], '' ), @@ -312,7 +312,7 @@ public function testIterateInvoices() foreach ($this->apiClient->invoices->iterator() as $invoice) { $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals("invoice", $invoice->resource); + $this->assertEquals('invoice', $invoice->resource); $this->assertNotEmpty($invoice->lines); } } diff --git a/tests/Mollie/API/Endpoints/MandateEndpointTest.php b/tests/Mollie/API/Endpoints/MandateEndpointTest.php index ebbc91d09..40b931f42 100644 --- a/tests/Mollie/API/Endpoints/MandateEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MandateEndpointTest.php @@ -12,7 +12,7 @@ class MandateEndpointTest extends BaseEndpointTest { - public function testCreateWorks() + public function test_create_works() { $this->mockApiCall( new Request('POST', '/v2/customers/cst_FhQJRw4s2n/mandates'), @@ -54,32 +54,32 @@ public function testCreateWorks() /** @var Mandate $mandate */ $mandate = $customer->createMandate([ - "consumerName" => "John Doe", - "method" => "directdebit", - "consumerBic" => "INGBNL2A", - "consumerAccount" => "NL55INGB0000000000", + 'consumerName' => 'John Doe', + 'method' => 'directdebit', + 'consumerBic' => 'INGBNL2A', + 'consumerAccount' => 'NL55INGB0000000000', ]); $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals("mandate", $mandate->resource); + $this->assertEquals('mandate', $mandate->resource); $this->assertEquals(MandateStatus::VALID, $mandate->status); - $this->assertEquals("directdebit", $mandate->method); - $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details); + $this->assertEquals('directdebit', $mandate->method); + $this->assertEquals((object) ['consumerName' => 'John Doe', 'consumerAccount' => 'NL55INGB0000000000', 'consumerBic' => 'INGBNL2A'], $mandate->details); $this->assertNull($mandate->mandateReference); - $this->assertEquals("2018-05-07", $mandate->signatureDate); - $this->assertEquals("2018-05-07T10:49:08+00:00", $mandate->createdAt); + $this->assertEquals('2018-05-07', $mandate->signatureDate); + $this->assertEquals('2018-05-07T10:49:08+00:00', $mandate->createdAt); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $mandate->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $mandate->_links->customer); - $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/create-mandate", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/create-mandate', 'type' => 'text/html']; $this->assertEquals($documentationLink, $mandate->_links->documentation); } - public function testGetWorks() + public function test_get_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h'), @@ -120,28 +120,28 @@ public function testGetWorks() $customer = $this->getCustomer(); /** @var Mandate $mandate */ - $mandate = $customer->getMandate("mdt_AcQl5fdL4h"); + $mandate = $customer->getMandate('mdt_AcQl5fdL4h'); $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals("mandate", $mandate->resource); + $this->assertEquals('mandate', $mandate->resource); $this->assertEquals(MandateStatus::VALID, $mandate->status); $this->assertEquals(MandateMethod::DIRECTDEBIT, $mandate->method); - $this->assertEquals((object) ["consumerName" => "John Doe", "consumerAccount" => "NL55INGB0000000000", "consumerBic" => "INGBNL2A"], $mandate->details); + $this->assertEquals((object) ['consumerName' => 'John Doe', 'consumerAccount' => 'NL55INGB0000000000', 'consumerBic' => 'INGBNL2A'], $mandate->details); $this->assertNull($mandate->mandateReference); - $this->assertEquals("2018-05-07", $mandate->signatureDate); - $this->assertEquals("2018-05-07T10:49:08+00:00", $mandate->createdAt); + $this->assertEquals('2018-05-07', $mandate->signatureDate); + $this->assertEquals('2018-05-07T10:49:08+00:00', $mandate->createdAt); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $mandate->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $mandate->_links->customer); - $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/create-mandate", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/create-mandate', 'type' => 'text/html']; $this->assertEquals($documentationLink, $mandate->_links->documentation); } - public function testListWorks() + public function test_list_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), @@ -203,21 +203,21 @@ public function testListWorks() /** @var Mandate $mandate */ foreach ($mandates as $mandate) { $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals("mandate", $mandate->resource); + $this->assertEquals('mandate', $mandate->resource); $this->assertEquals(MandateStatus::VALID, $mandate->status); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $mandate->_links->customer); } - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $mandates->_links->self); - $documentationLink = (object)["href" => "https://mollie.com/en/docs/reference/customers/list-mandates", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/list-mandates', 'type' => 'text/html']; $this->assertEquals($documentationLink, $mandates->_links->documentation); } - public function testCustomerHasValidMandateWhenTrue() + public function test_customer_has_valid_mandate_when_true() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), @@ -275,7 +275,7 @@ public function testCustomerHasValidMandateWhenTrue() $this->assertTrue($customer->hasValidMandate()); } - public function testCustomerHasValidMandateWhenFalse() + public function test_customer_has_valid_mandate_when_false() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), @@ -308,7 +308,7 @@ public function testCustomerHasValidMandateWhenFalse() $this->assertFalse($customer->hasValidMandate()); } - public function testCustomerHasValidMandateForMethodWhenFalse() + public function test_customer_has_valid_mandate_for_method_when_false() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), @@ -341,7 +341,7 @@ public function testCustomerHasValidMandateForMethodWhenFalse() $this->assertFalse($customer->hasValidMandateForMethod('directdebit')); } - public function testCustomerHasValidMandateForMethodWhenTrue() + public function test_customer_has_valid_mandate_for_method_when_true() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), diff --git a/tests/Mollie/API/Endpoints/MethodEndpointTest.php b/tests/Mollie/API/Endpoints/MethodEndpointTest.php index b585fed05..d3fc91ed2 100644 --- a/tests/Mollie/API/Endpoints/MethodEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodEndpointTest.php @@ -19,7 +19,7 @@ class MethodEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testGetMethod() + public function test_get_method() { $this->mockApiCall( new Request('GET', '/v2/methods/ideal'), @@ -79,7 +79,7 @@ public function testGetMethod() ); } - public function testGetMethodWithIncludeIssuers() + public function test_get_method_with_include_issuers() { $this->mockApiCall( new Request('GET', '/v2/methods/ideal?include=issuers'), @@ -169,7 +169,7 @@ public function testGetMethodWithIncludeIssuers() ); } - public function testGetMethodWithIncludePricing() + public function test_get_method_with_include_pricing() { $this->mockApiCall( new Request('GET', '/v2/methods/ideal?include=pricing'), @@ -267,7 +267,7 @@ public function testGetMethodWithIncludePricing() $this->assertEquals('0', $method_price->variable); } - public function testGetTranslatedMethod() + public function test_get_translated_method() { $this->mockApiCall( new Request('GET', '/v2/methods/sofort?locale=de_DE'), @@ -330,7 +330,7 @@ public function testGetTranslatedMethod() $this->assertEquals($documentationLink, $method->_links->documentation); } - public function testListAllActiveMethods() + public function test_list_all_active_methods() { $this->mockApiCall( new Request('GET', '/v2/methods'), @@ -481,7 +481,7 @@ public function testListAllActiveMethods() $this->assertEquals($selfLink, $creditcardMethod->_links->self); } - public function testListAllAvailableMethods() + public function test_list_all_available_methods() { $this->mockApiCall( new Request('GET', '/v2/methods/all?include=pricing'), diff --git a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php index a251c2b1a..b9a28c5b7 100644 --- a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php @@ -11,7 +11,7 @@ class MethodIssuerEndpointTest extends BaseEndpointTest { /** @test */ - public function testEnableIssuer() + public function test_enable_issuer() { $this->mockApiCall( new Request( @@ -40,7 +40,7 @@ public function testEnableIssuer() } /** @test */ - public function testDisableIssuer() + public function test_disable_issuer() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php b/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php index af9d1afbf..7f5e4758e 100644 --- a/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php @@ -11,7 +11,7 @@ final class OnboardingEndpointTest extends BaseEndpointTest { - public function testGetWorks() + public function test_get_works() { $this->mockApiCall( new Request('GET', '/v2/onboarding/me'), @@ -50,27 +50,27 @@ public function testGetWorks() $onboarding = $this->apiClient->onboarding->get(); $this->assertInstanceOf(Onboarding::class, $onboarding); - $this->assertEquals("onboarding", $onboarding->resource); - $this->assertEquals("Mollie B.V.", $onboarding->name); + $this->assertEquals('onboarding', $onboarding->resource); + $this->assertEquals('Mollie B.V.', $onboarding->name); $this->assertEquals(OnboardingStatus::COMPLETED, $onboarding->status); - $this->assertEquals("2018-12-20T10:49:08+00:00", $onboarding->signedUpAt); + $this->assertEquals('2018-12-20T10:49:08+00:00', $onboarding->signedUpAt); $this->assertEquals(true, $onboarding->canReceivePayments); $this->assertEquals(true, $onboarding->canReceiveSettlements); - $selfLink = (object)['href' => 'https://api.mollie.com/v2/onboarding/me', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/onboarding/me', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $onboarding->_links->self); - $dashboardLink = (object)['href' => 'https://www.mollie.com/dashboard/onboarding', 'type' => 'text/html']; + $dashboardLink = (object) ['href' => 'https://www.mollie.com/dashboard/onboarding', 'type' => 'text/html']; $this->assertEquals($dashboardLink, $onboarding->_links->dashboard); - $organizationLink = (object)['href' => 'https://api.mollie.com/v2/organization/org_12345', 'type' => 'application/hal+json']; + $organizationLink = (object) ['href' => 'https://api.mollie.com/v2/organization/org_12345', 'type' => 'application/hal+json']; $this->assertEquals($organizationLink, $onboarding->_links->organization); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status', 'type' => 'text/html']; $this->assertEquals($documentationLink, $onboarding->_links->documentation); } - public function testSubmitWorks() + public function test_submit_works() { $this->mockApiCall( new Request('POST', '/v2/onboarding/me'), diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php deleted file mode 100644 index 79364fea0..000000000 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ /dev/null @@ -1,1191 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/orders', - [], - '{ - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "metadata": { - "order_id": "1337", - "description": "Lego cars" - }, - "consumerDateOfBirth": "1958-01-31", - "orderNumber": "1337", - "locale": "nl_NL", - "method" : "klarnapaylater", - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "lines": [ - { - "sku": "5702016116977", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "quantity": 2, - "unitPrice": { - "currency": "EUR", - "value": "399.00" - }, - "vatRate": "21.00", - "vatAmount": { - "currency": "EUR", - "value": "121.14" - }, - "discountAmount": { - "currency": "EUR", - "value": "100.00" - }, - "totalAmount": { - "currency": "EUR", - "value": "698.00" - } - }, - { - "type": "digital", - "sku": "5702015594028", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "quantity": 1, - "unitPrice": { - "currency": "EUR", - "value": "329.99" - }, - "vatRate": "21.00", - "vatAmount": { - "currency": "EUR", - "value": "57.27" - }, - "totalAmount": { - "currency": "EUR", - "value": "329.99" - } - } - ] - }' - ), - new Response( - 201, - [], - $this->getOrderResponseFixture('ord_pbjz8x') - ) - ); - - $order = $this->apiClient->orders->create([ - 'amount' => [ - 'value' => '1027.99', - 'currency' => 'EUR', - ], - 'billingAddress' => [ - 'organizationName' => 'Organization Name LTD.', - 'streetAndNumber' => 'Keizersgracht 313', - 'postalCode' => '1016 EE', - 'city' => 'Amsterdam', - 'country' => 'nl', - 'givenName' => 'Luke', - 'familyName' => 'Skywalker', - 'email' => 'luke@skywalker.com', - ], - 'shippingAddress' => [ - 'organizationName' => 'Organization Name LTD.', - 'streetAndNumber' => 'Keizersgracht 313', - 'postalCode' => '1016 EE', - 'city' => 'Amsterdam', - 'country' => 'nl', - 'givenName' => 'Luke', - 'familyName' => 'Skywalker', - 'email' => 'luke@skywalker.com', - ], - 'metadata' => [ - 'order_id' => '1337', - 'description' => 'Lego cars', - ], - 'consumerDateOfBirth' => '1958-01-31', - 'locale' => 'nl_NL', - 'orderNumber' => '1337', - 'redirectUrl' => 'https://example.org/redirect', - 'webhookUrl' => 'https://example.org/webhook', - 'method' => 'klarnapaylater', - 'lines' => [ - [ - 'sku' => '5702016116977', - 'name' => 'LEGO 42083 Bugatti Chiron', - 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', - 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - 'quantity' => 2, - 'vatRate' => '21.00', - 'unitPrice' => [ - 'currency' => 'EUR', - 'value' => '399.00', - ], - 'totalAmount' => [ - 'currency' => 'EUR', - 'value' => '698.00', - ], - 'discountAmount' => [ - 'currency' => 'EUR', - 'value' => '100.00', - ], - 'vatAmount' => [ - 'currency' => 'EUR', - 'value' => '121.14', - ], - ], - [ - 'type' => 'digital', - 'sku' => '5702015594028', - 'name' => 'LEGO 42056 Porsche 911 GT3 RS', - 'productUrl' => 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', - 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', - 'quantity' => 1, - 'vatRate' => '21.00', - 'unitPrice' => [ - 'currency' => 'EUR', - 'value' => '329.99', - ], - 'totalAmount' => [ - 'currency' => 'EUR', - 'value' => '329.99', - ], - 'vatAmount' => [ - 'currency' => 'EUR', - 'value' => '57.27', - ], - ], - ], - ]); - - $this->assertOrder($order, 'ord_pbjz8x'); - } - - public function testGetOrderDirectly() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x' - ), - new Response( - 200, - [], - $this->getOrderResponseFixture('ord_pbjz8x') - ) - ); - - $order = $this->apiClient->orders->get('ord_pbjz8x'); - - $this->assertOrder($order, 'ord_pbjz8x'); - } - - public function testGetOrderDirectlyIncludingPayments() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_kEn1PlbGa?embed=payments' - ), - new Response( - 200, - [], - '{ - "resource": "order", - "id": "ord_kEn1PlbGa", - "profileId": "pfl_URR55HPMGx", - "method": "klarnapaylater", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "status": "created", - "isCancelable": true, - "metadata": null, - "createdAt": "2018-08-02T09:29:56+00:00", - "expiresAt": "2018-08-30T09:29:56+00:00", - "mode": "live", - "locale": "nl_NL", - "billingAddress": { - "organizationName": "Mollie B.V.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": "18475", - "shippingAddress": { - "organizationName": "Mollie B.V.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "redirectUrl": "https://example.org/redirect", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "ord_pbjz8x", - "name": "LEGO 42083 Bugatti Chiron", - "sku": "5702016116977", - "type": "physical", - "status": "created", - "metadata": null, - "isCancelable": false, - "quantity": 2, - "quantityShipped": 0, - "amountShipped": { - "value": "0.00", - "currency": "EUR" - }, - "quantityRefunded": 0, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "quantityCanceled": 0, - "amountCanceled": { - "value": "0.00", - "currency": "EUR" - }, - "shippableQuantity": 0, - "refundableQuantity": 0, - "cancelableQuantity": 0, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "productUrl": { - "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "type": "text/html" - }, - "imageUrl": { - "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "type": "text/html" - } - } - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "ord_pbjz8x", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "sku": "5702015594028", - "type": "physical", - "status": "created", - "metadata": null, - "isCancelable": false, - "quantity": 1, - "quantityShipped": 0, - "amountShipped": { - "value": "0.00", - "currency": "EUR" - }, - "quantityRefunded": 0, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "quantityCanceled": 0, - "amountCanceled": { - "value": "0.00", - "currency": "EUR" - }, - "shippableQuantity": 0, - "refundableQuantity": 0, - "cancelableQuantity": 0, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "productUrl": { - "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "type": "text/html" - }, - "imageUrl": { - "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "type": "text/html" - } - } - } - ], - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_ncaPcAhuUV", - "mode": "live", - "createdAt": "2018-09-07T12:00:05+00:00", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "description": "Order #1337 (Lego cars)", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "locale": "nl_NL", - "profileId": "pfl_URR55HPMGx", - "orderId": "ord_kEn1PlbGa", - "sequenceType": "oneoff", - "redirectUrl": "https://example.org/redirect", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_ncaPcAhuUV", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/ncaPcAhuUV", - "type": "text/html" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/order/checkout/pbjz8x", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->apiClient->orders->get('ord_kEn1PlbGa', ['embed' => 'payments']); - - $this->assertInstanceOf(Order::class, $order); - $this->assertEquals('ord_kEn1PlbGa', $order->id); - - $payments = $order->payments(); - $this->assertInstanceOf(PaymentCollection::class, $payments); - - $payment = $payments[0]; - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('tr_ncaPcAhuUV', $payment->id); - $this->assertEquals('2018-09-07T12:00:05+00:00', $payment->createdAt); - $this->assertAmountObject('1027.99', 'EUR', $payment->amount); - $this->assertEquals('Order #1337 (Lego cars)', $payment->description); - $this->assertNull($payment->method); - $this->assertNull($payment->metadata); - $this->assertEquals('open', $payment->status); - $this->assertFalse($payment->isCancelable); - $this->assertEquals('nl_NL', $payment->locale); - $this->assertEquals('pfl_URR55HPMGx', $payment->profileId); - $this->assertEquals('ord_kEn1PlbGa', $payment->orderId); - $this->assertEquals('oneoff', $payment->sequenceType); - $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_ncaPcAhuUV', - 'application/hal+json', - $payment->_links->self - ); - $this->assertLinkObject( - 'https://www.mollie.com/payscreen/select-method/ncaPcAhuUV', - 'text/html', - $payment->_links->checkout - ); - $this->assertLinkObject( - 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa', - 'application/hal+json', - $payment->_links->order - ); - } - - public function testGetOrderOnShipmentResource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x' - ), - new Response( - 200, - [], - $this->getOrderResponseFixture('ord_pbjz8x') - ) - ); - - $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x'); - $order = $shipment->order(); - - $this->assertOrder($order, 'ord_pbjz8x'); - } - - public function testListOrders() - { - $this->mockApiCall( - new Request('GET', '/v2/orders'), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "orders": [ - '.$this->getOrderResponseFixture('ord_pbjz1x').', - '.$this->getOrderResponseFixture('ord_pbjz2y').', - '.$this->getOrderResponseFixture('ord_pbjz3z').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/list-orders", - "type": "text/html" - } - } - }' - ) - ); - - $orders = $this->apiClient->orders->page(); - - $this->assertInstanceOf(OrderCollection::class, $orders); - $this->assertEquals(3, $orders->count()); - $this->assertEquals(3, count($orders)); - - $this->assertNull($orders->_links->previous); - $selfLink = $this->createLinkObject( - 'https://api.mollie.com/v2/orders', - 'application/hal+json' - ); - $this->assertEquals($selfLink, $orders->_links->self); - - $nextLink = $this->createLinkObject( - 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', - 'application/hal+json' - ); - $this->assertEquals($nextLink, $orders->_links->next); - - $documentationLink = $this->createLinkObject( - 'https://docs.mollie.com/reference/v2/orders-api/list-orders', - 'text/html' - ); - $this->assertEquals($documentationLink, $orders->_links->documentation); - - $this->assertOrder($orders[0], 'ord_pbjz1x'); - $this->assertOrder($orders[1], 'ord_pbjz2y'); - $this->assertOrder($orders[2], 'ord_pbjz3z'); - } - - public function testIterateOrders() - { - $this->mockApiCall( - new Request('GET', '/v2/orders'), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "orders": [ - '.$this->getOrderResponseFixture('ord_pbjz1x').', - '.$this->getOrderResponseFixture('ord_pbjz2y').', - '.$this->getOrderResponseFixture('ord_pbjz3z').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders", - "type": "application/hal+json" - }, - "previous": null, - "next": null, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/list-orders", - "type": "text/html" - } - } - }' - ) - ); - - foreach ($this->apiClient->orders->iterator() as $order) { - $this->assertInstanceOf(Order::class, $order); - } - } - - public function testCancelOrderDirectly() - { - $this->mockApiCall( - new Request('DELETE', '/v2/orders/ord_pbjz1x'), - new Response( - 200, - [], - $this->getOrderResponseFixture( - 'ord_pbjz1x', - OrderStatus::CANCELED - ) - ) - ); - $order = $this->apiClient->orders->cancel('ord_pbjz1x'); - $this->assertOrder($order, 'ord_pbjz1x', OrderStatus::CANCELED); - } - - public function testCancelOrderOnResource() - { - $this->mockApiCall( - new Request('DELETE', '/v2/orders/ord_pbjz1x'), - new Response( - 200, - [], - $this->getOrderResponseFixture( - 'ord_pbjz1x', - OrderStatus::CANCELED - ) - ) - ); - $order = $this->getOrder('ord_pbjz1x'); - $canceledOrder = $order->cancel(); - $this->assertOrder($canceledOrder, 'ord_pbjz1x', OrderStatus::CANCELED); - } - - public function testCancelOrderLines() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/orders/ord_8wmqcHMN4U/lines', - [], - '{ - "lines": [ - { - "id": "odl_dgtxyl", - "quantity": 1 - } - ] - }' - ), - new Response(204) - ); - - $order = $this->getOrder('ord_8wmqcHMN4U'); - - $result = $order->cancelLines([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - ], - ]); - - $this->assertNull($result); - } - - public function testCancelAllOrderLines() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/orders/ord_8wmqcHMN4U/lines', - [], - '{ - "lines": [], - "foo": "bar" - }' - ), - new Response(204) - ); - - $order = $this->getOrder('ord_8wmqcHMN4U'); - - $result = $order->cancelAllLines([ - 'foo' => 'bar', - ]); - - $this->assertNull($result); - } - - /** @test */ - public function testUpdateOrder() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/orders/ord_pbjz8x', - [], - '{ - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1234AB", - "city": "Amsterdam", - "country": "NL", - "givenName": "Piet", - "familyName": "Mondriaan", - "email": "piet@mondriaan.com", - "region": "Noord-Holland", - "title": "Dhr", - "phone": "+31208202070" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": "16738", - "redirectUrl": "https://example.org/updated-redirect", - "cancelUrl": "https://example.org/updated-cancel-url", - "webhookUrl": "https://example.org/updated-webhook" - }' - ), - new Response( - 200, - [], - $this->getOrderResponseFixture( - 'ord_pbjz8x', - OrderStatus::CREATED, - '16738' - ) - ) - ); - - /** @var Order $order */ - $order = $this->getOrder('ord_pbjz8x'); - - $order->billingAddress->organizationName = 'Organization Name LTD.'; - $order->billingAddress->streetAndNumber = 'Keizersgracht 313'; - $order->billingAddress->city = 'Amsterdam'; - $order->billingAddress->region = 'Noord-Holland'; - $order->billingAddress->postalCode = '1234AB'; - $order->billingAddress->country = 'NL'; - $order->billingAddress->title = 'Dhr'; - $order->billingAddress->givenName = 'Piet'; - $order->billingAddress->familyName = 'Mondriaan'; - $order->billingAddress->email = 'piet@mondriaan.com'; - $order->billingAddress->phone = '+31208202070'; - $order->orderNumber = '16738'; - $order->redirectUrl = 'https://example.org/updated-redirect'; - $order->cancelUrl = 'https://example.org/updated-cancel-url'; - $order->webhookUrl = 'https://example.org/updated-webhook'; - $order = $order->update(); - - $this->assertOrder($order, 'ord_pbjz8x', OrderStatus::CREATED, '16738'); - } - - public function testUpdateOrderLine() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/orders/ord_pbjz8x/lines/odl_dgtxyl', - [], - '{ - "name": "LEGO 71043 Hogwartsâ„¢ Castle", - "productUrl": "https://shop.lego.com/en-GB/product/Hogwarts-Castle-71043", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/71043_alt1?$main$", - "quantity": 2, - "vatRate": "21.00", - "sku": "5702016116977", - "unitPrice": { - "currency": "EUR", - "value": "349.00" - }, - "totalAmount": { - "currency": "EUR", - "value": "598.00" - }, - "discountAmount": { - "currency": "EUR", - "value": "100.00" - }, - "vatAmount": { - "currency": "EUR", - "value": "103.79" - }, - "metadata": { - "foo": "bar" - } - }' - ), - new Response(200, [], $this->getOrderResponseFixture('ord_pbjz8x')) - ); - - $orderLine = new OrderLine($this->apiClient); - $orderLine->id = 'odl_dgtxyl'; - $orderLine->orderId = 'ord_pbjz8x'; - $orderLine->name = 'LEGO 71043 Hogwartsâ„¢ Castle'; - $orderLine->productUrl = 'https://shop.lego.com/en-GB/product/Hogwarts-Castle-71043'; - $orderLine->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/71043_alt1?$main$'; - $orderLine->sku = '5702016116977'; - $orderLine->quantity = 2; - $orderLine->vatRate = '21.00'; - $orderLine->unitPrice = (object) ['currency' => 'EUR', 'value' => '349.00']; - $orderLine->totalAmount = (object) ['currency' => 'EUR', 'value' => '598.00']; - $orderLine->discountAmount = (object) ['currency' => 'EUR', 'value' => '100.00']; - $orderLine->vatAmount = (object) ['currency' => 'EUR', 'value' => '103.79']; - $orderLine->metadata = (object) ['foo' => 'bar']; - - $result = $orderLine->update(); - - $this->assertOrder($result, 'ord_pbjz8x'); - } - - protected function assertOrder($order, $order_id, $order_status = OrderStatus::CREATED, $orderNumber = '1337') - { - $this->assertInstanceOf(Order::class, $order); - $this->assertEquals('order', $order->resource); - $this->assertEquals($order_id, $order->id); - $this->assertEquals('pfl_URR55HPMGx', $order->profileId); - $this->assertEquals('live', $order->mode); - $this->assertEquals('klarnapaylater', $order->method); - $this->assertEquals('2018-08-02T09:29:56+00:00', $order->createdAt); - $this->assertEquals('2018-09-02T09:29:56+00:00', $order->expiresAt); - - $this->assertAmountObject('1027.99', 'EUR', $order->amount); - $this->assertAmountObject('0.00', 'EUR', $order->amountCaptured); - $this->assertAmountObject('0.00', 'EUR', $order->amountRefunded); - - $this->assertEquals((object) [ - 'order_id' => '1337', - 'description' => 'Lego cars', - ], $order->metadata); - - $this->assertEquals($order_status, $order->status); - - $billingAddress = new stdClass; - $billingAddress->organizationName = 'Organization Name LTD.'; - $billingAddress->streetAndNumber = 'Keizersgracht 313'; - $billingAddress->postalCode = '1016 EE'; - $billingAddress->city = 'Amsterdam'; - $billingAddress->country = 'nl'; - $billingAddress->givenName = 'Luke'; - $billingAddress->familyName = 'Skywalker'; - $billingAddress->email = 'luke@skywalker.com'; - $this->assertEquals($billingAddress, $order->billingAddress); - - $shippingAddress = new stdClass; - $shippingAddress->organizationName = 'Organization Name LTD.'; - $shippingAddress->streetAndNumber = 'Keizersgracht 313'; - $shippingAddress->postalCode = '1016 EE'; - $shippingAddress->city = 'Amsterdam'; - $shippingAddress->country = 'nl'; - $shippingAddress->givenName = 'Luke'; - $shippingAddress->familyName = 'Skywalker'; - $shippingAddress->email = 'luke@skywalker.com'; - $this->assertEquals($shippingAddress, $order->shippingAddress); - - $this->assertEquals($orderNumber, $order->orderNumber); - $this->assertEquals('nl_NL', $order->locale); - - $this->assertEquals('https://example.org/redirect', $order->redirectUrl); - $this->assertEquals('https://example.org/webhook', $order->webhookUrl); - - $links = (object) [ - 'self' => $this->createLinkObject( - 'https://api.mollie.com/v2/orders/'.$order_id, - 'application/hal+json' - ), - 'checkout' => $this->createLinkObject( - 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', - 'text/html' - ), - 'documentation' => $this->createLinkObject( - 'https://docs.mollie.com/reference/v2/orders-api/get-order', - 'text/html' - ), - ]; - $this->assertEquals($links, $order->_links); - - $line1 = new stdClass; - $line1->resource = 'orderline'; - $line1->id = 'odl_dgtxyl'; - $line1->orderId = $order_id; - $line1->name = 'LEGO 42083 Bugatti Chiron'; - $line1->productUrl = 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083'; - $line1->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$'; - $line1->sku = '5702016116977'; - $line1->type = OrderLineType::PHYSICAL; - $line1->status = OrderLineStatus::CREATED; - $line1->isCancelable = true; - $line1->quantity = 2; - $line1->unitPrice = $this->createAmountObject('399.00', 'EUR'); - $line1->vatRate = '21.00'; - $line1->vatAmount = $this->createAmountObject('121.14', 'EUR'); - $line1->discountAmount = $this->createAmountObject('100.00', 'EUR'); - $line1->totalAmount = $this->createAmountObject('698.00', 'EUR'); - $line1->createdAt = '2018-08-02T09:29:56+00:00'; - $this->assertEquals($line1, $order->lines[0]); - - $line2 = new stdClass; - $line2->resource = 'orderline'; - $line2->id = 'odl_jp31jz'; - $line2->orderId = $order_id; - $line2->name = 'LEGO 42056 Porsche 911 GT3 RS'; - $line2->productUrl = 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056'; - $line2->imageUrl = 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$'; - $line2->sku = '5702015594028'; - $line2->type = OrderLineType::DIGITAL; - $line2->status = OrderLineStatus::CREATED; - $line2->isCancelable = true; - $line2->quantity = 1; - $line2->unitPrice = $this->createAmountObject('329.99', 'EUR'); - $line2->vatRate = '21.00'; - $line2->vatAmount = $this->createAmountObject('57.27', 'EUR'); - $line2->totalAmount = $this->createAmountObject('329.99', 'EUR'); - $line2->createdAt = '2018-08-02T09:29:56+00:00'; - $this->assertEquals($line2, $order->lines[1]); - - $this->assertNull($order->payments()); - } - - protected function getOrder($id) - { - $orderJson = $this->getOrderResponseFixture($id); - - return $this->copy(json_decode($orderJson), new Order($this->apiClient)); - } - - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED, $orderNumber = '1337') - { - return str_replace( - [ - '<>', - '<>', - ], - [ - $order_id, - $orderNumber, - ], - '{ - "resource": "order", - "id": "<>", - "profileId": "pfl_URR55HPMGx", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "amountCaptured": { - "value": "0.00", - "currency": "EUR" - }, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "status": "'.$order_status.'", - "metadata": { - "order_id": "1337", - "description": "Lego cars" - }, - "consumerDateOfBirth": "1958-01-31", - "createdAt": "2018-08-02T09:29:56+00:00", - "expiresAt": "2018-09-02T09:29:56+00:00", - "mode": "live", - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": <>, - "locale": "nl_NL", - "method" : "klarnapaylater", - "isCancelable": true, - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "created", - "isCancelable": true, - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "created", - "isCancelable": true, - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ); - } - - protected function getShipment($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::SHIPPING) - { - $shipmentJson = $this->getShipmentResponseFixture( - $shipmentId, - $orderId, - $orderlineStatus - ); - - return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient)); - } - - protected function getShipmentResponseFixture($shipmentId, $orderId, $orderlineStatus = OrderLineStatus::SHIPPING) - { - return str_replace( - [ - '<>', - '<>', - '<>', - ], - [ - $orderId, - $shipmentId, - $orderlineStatus, - ], - '{ - "resource": "shipment", - "id": "<>", - "orderId": "<>", - "createdAt": "2018-08-02T09:29:56+00:00", - "profileId": "pfl_URR55HPMGx", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "<>", - "quantity": 1, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "<>", - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>/shipments/<>", - "type": "application/hal+json" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment", - "type": "text/html" - } - } - }' - ); - } -} diff --git a/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php b/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php deleted file mode 100644 index 601ce439b..000000000 --- a/tests/Mollie/API/Endpoints/OrderLineEndpointTest.php +++ /dev/null @@ -1,306 +0,0 @@ -expectException(ApiException::class); - - $this->guzzleClient = $this->createMock(Client::class); - $this->apiClient = new MollieApiClient($this->guzzleClient); - - $order = new Order($this->apiClient); - $order->id = 'ord_pbjz8x'; - - $this->apiClient->orderLines->cancelFor($order, []); - } - - public function testUpdateMultipleOrderLines() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/orders/ord_pbjz8x/lines', - [], - '{ - "operations": [ - { - "operation": "update", - "data": { - "id": "odl_1.1l9vx0", - "name": "New order line name" - } - }, - { - "operation": "cancel", - "data": { - "id": "odl_1.4hqjw6" - } - }, - { - "operation": "add", - "data": { - "name": "Adding new orderline", - "quantity": 2, - "sku": "12345679", - "totalAmount": { - "currency": "EUR", - "value": "30.00" - }, - "type": "digital", - "unitPrice": { - "currency": "EUR", - "value": "15.00" - }, - "vatAmount": { - "currency": "EUR", - "value": "0.00" - }, - "vatRate": "0.00" - } - } - ] - }' - ), - new Response( - 200, - [], - '{ - "resource": "order", - "id": "ord_pbjz8x", - "profileId": "pfl_h7UgNeDGTA", - "method": "klarnapaylater", - "amount": { - "value": "50.00", - "currency": "EUR" - }, - "status": "created", - "isCancelable": true, - "metadata": null, - "createdAt": "2022-06-09T13:49:10+00:00", - "expiresAt": "2022-07-07T13:49:10+00:00", - "mode": "live", - "locale": "en_US", - "billingAddress": { - "streetAndNumber": "Herengracht 1", - "postalCode": "1052CB", - "city": "Amsterdam", - "country": "NL", - "givenName": "mollie", - "familyName": "test", - "email": "test@test.com" - }, - "shopperCountryMustMatchBillingCountry": false, - "orderNumber": "1", - "redirectUrl": "https://api.platform.mollielabs.net", - "webhookUrl": "https://api.platform.mollielabs.net", - "lines": [ - { - "resource": "orderline", - "id": "odl_1.1l9vx0", - "orderId": "ord_pbjz8x", - "name": "New orderline name", - "sku": "123456", - "type": "digital", - "status": "created", - "metadata": null, - "isCancelable": false, - "quantity": 2, - "quantityShipped": 0, - "amountShipped": { - "value": "0.00", - "currency": "EUR" - }, - "quantityRefunded": 0, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "quantityCanceled": 0, - "amountCanceled": { - "value": "0.00", - "currency": "EUR" - }, - "shippableQuantity": 0, - "refundableQuantity": 0, - "cancelableQuantity": 0, - "unitPrice": { - "value": "10.00", - "currency": "EUR" - }, - "vatRate": "0.00", - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "20.00", - "currency": "EUR" - }, - "createdAt": "2022-06-09T13:49:10+00:00" - }, - { - "resource": "orderline", - "id": "odl_1.4hqjw6", - "orderId": "ord_pbjz8x", - "name": "A cancelled orderline", - "sku": "1234444", - "type": "digital", - "status": "canceled", - "metadata": null, - "isCancelable": true, - "quantity": 1, - "quantityShipped": 0, - "amountShipped": { - "value": "0.00", - "currency": "EUR" - }, - "quantityRefunded": 0, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "quantityCanceled": 1, - "amountCanceled": { - "value": "5.00", - "currency": "EUR" - }, - "shippableQuantity": 0, - "refundableQuantity": 0, - "cancelableQuantity": 0, - "unitPrice": { - "value": "5.00", - "currency": "EUR" - }, - "vatRate": "0.00", - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "5.00", - "currency": "EUR" - }, - "createdAt": "2022-06-10T11:05:21+00:00" - }, - { - "resource": "orderline", - "id": "odl_1.3ccpk8", - "orderId": "ord_pbjz8x", - "name": "Adding new orderline", - "sku": "12345679", - "type": "digital", - "status": "created", - "metadata": null, - "isCancelable": true, - "quantity": 2, - "quantityShipped": 0, - "amountShipped": { - "value": "0.00", - "currency": "EUR" - }, - "quantityRefunded": 0, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "quantityCanceled": 0, - "amountCanceled": { - "value": "0.00", - "currency": "EUR" - }, - "shippableQuantity": 0, - "refundableQuantity": 0, - "cancelableQuantity": 0, - "unitPrice": { - "value": "15.00", - "currency": "EUR" - }, - "vatRate": "0.00", - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "30.00", - "currency": "EUR" - }, - "createdAt": "2022-06-10T11:16:49+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", - "type": "application/hal+json" - }, - "dashboard": { - "href": "https://www.mollie.com/dashboard/org_2816091/orders/ord_pbjz8x", - "type": "text/html" - }, - "checkout": { - "href": "https://www.mollie.com/checkout/order/xvb27g", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->apiClient->orderLines->updateMultiple( - 'ord_pbjz8x', - [ - [ - "operation" => "update", - "data" => [ - "id" => "odl_1.1l9vx0", - "name" => "New order line name", - ], - ], - [ - "operation" => "cancel", - "data" => [ - "id" => "odl_1.4hqjw6", - ], - ], - [ - "operation" => "add", - "data" => [ - "name" => "Adding new orderline", - "quantity" => 2, - "sku" => "12345679", - "totalAmount" => [ - "currency" => "EUR", - "value" => "30.00", - ], - "type" => "digital", - "unitPrice" => [ - "currency" => "EUR", - "value" => "15.00", - ], - "vatAmount" => [ - "currency" => "EUR", - "value" => "0.00", - ], - "vatRate" => "0.00", - ], - ], - ] - ); - - $this->assertInstanceOf(Order::class, $order); - $this->assertEquals('ord_pbjz8x', $order->id); - } -} diff --git a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php deleted file mode 100644 index 40fce6bc7..000000000 --- a/tests/Mollie/API/Endpoints/OrderPaymentEndpointTest.php +++ /dev/null @@ -1,285 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/orders/ord_stTC2WHAuS/payments', - [], - '{ - "method": "banktransfer", - "dueDate": "2018-12-21" - }' - ), - new Response( - 201, - [], - '{ - "resource": "payment", - "id": "tr_WDqYK6vllg", - "mode": "test", - "amount": { - "currency": "EUR", - "value": "698.00" - }, - "status": "open", - "description": "Order #1337 (Lego cars)", - "createdAt": "2018-12-01T17:09:02+00:00", - "method": "banktransfer", - "metadata": null, - "orderId": "ord_stTC2WHAuS", - "isCancelable": true, - "locale": "nl_NL", - "profileId": "pfl_URR55HPMGx", - "sequenceType": "oneoff", - "settlementAmount": { - "value": "698.00", - "currency": "EUR" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/ord_stTC2WHAuS", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/paymentscreen/testmode/?method=banktransfer&token=fgnwdh", - "type": "text/html" - }, - "status": { - "href": "https://www.mollie.com/paymentscreen/banktransfer/status/fgnwdh", - "type": "text/html" - }, - "payOnline": { - "href": "https://www.mollie.com/paymentscreen/banktransfer/pay-online/fgnwdh", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/create-order-payment", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->getOrder('ord_stTC2WHAuS'); - - $payment = $order->createPayment([ - 'method' => 'banktransfer', - 'dueDate' => '2018-12-21', - ]); - - $this->assertNotNull($payment); - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('payment', $payment->resource); - $this->assertEquals('tr_WDqYK6vllg', $payment->id); - $this->assertEquals('test', $payment->mode); - $this->assertAmountObject(698, 'EUR', $payment->amount); - $this->assertEquals('open', $payment->status); - $this->assertEquals(PaymentStatus::OPEN, $payment->status); - $this->assertEquals('Order #1337 (Lego cars)', $payment->description); - $this->assertEquals('2018-12-01T17:09:02+00:00', $payment->createdAt); - $this->assertEquals(PaymentMethod::BANKTRANSFER, $payment->method); - $this->assertNull($payment->metadata); - $this->assertEquals('ord_stTC2WHAuS', $payment->orderId); - $this->assertTrue($payment->isCancelable); - $this->assertEquals('nl_NL', $payment->locale); - $this->assertEquals('pfl_URR55HPMGx', $payment->profileId); - $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertAmountObject(698, 'EUR', $payment->settlementAmount); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg', - 'application/hal+json', - $payment->_links->self - ); - $this->assertLinkObject( - 'https://api.mollie.com/v2/orders/ord_stTC2WHAuS', - 'application/hal+json', - $payment->_links->order - ); - $this->assertLinkObject( - 'https://www.mollie.com/paymentscreen/testmode/?method=banktransfer&token=fgnwdh', - 'text/html', - $payment->_links->checkout - ); - $this->assertLinkObject( - 'https://www.mollie.com/paymentscreen/banktransfer/status/fgnwdh', - 'text/html', - $payment->_links->status - ); - $this->assertLinkObject( - 'https://www.mollie.com/paymentscreen/banktransfer/pay-online/fgnwdh', - 'text/html', - $payment->_links->payOnline - ); - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/orders-api/create-order-payment', - 'text/html', - $payment->_links->documentation - ); - } - - protected function getOrder($id) - { - $orderJson = $this->getOrderResponseFixture($id); - - return $this->copy(json_decode($orderJson), new Order($this->apiClient)); - } - - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) - { - return str_replace( - '<>', - $order_id, - '{ - "resource": "order", - "id": "<>", - "profileId": "pfl_URR55HPMGx", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "amountCaptured": { - "value": "0.00", - "currency": "EUR" - }, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "status": "'.$order_status.'", - "metadata": { - "order_id": "1337", - "description": "Lego cars" - }, - "consumerDateOfBirth": "1958-01-31", - "createdAt": "2018-08-02T09:29:56+00:00", - "mode": "live", - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": "1337", - "locale": "nl_NL", - "method" : "klarnapaylater", - "isCancelable": true, - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "created", - "isCancelable": true, - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "created", - "isCancelable": true, - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ); - } -} diff --git a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php b/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php deleted file mode 100644 index 59c97498e..000000000 --- a/tests/Mollie/API/Endpoints/OrderRefundEndpointTest.php +++ /dev/null @@ -1,427 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/orders/ord_stTC2WHAuS/refunds', - [], - '{ - "lines": [ - { - "id": "odl_dgtxyl", - "quantity": 1 - } - ] - }' - ), - new Response( - 201, - [], - $this->getOrderRefundResponseFixture('re_4qqhO89gsT', 'ord_stTC2WHAuS') - ) - ); - - $order = $this->getOrder('ord_stTC2WHAuS'); - - $refund = $order->refund([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - ], - ]); - - $this->assertOrderRefund($refund, 're_4qqhO89gsT'); - } - - public function testCreateCompleteOrderRefund() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/orders/ord_stTC2WHAuS/refunds', - [], - '{ - "lines": [] - }' - ), - new Response( - 201, - [], - $this->getOrderRefundResponseFixture('re_4qqhO89gsT', 'ord_stTC2WHAuS') - ) - ); - - $order = $this->getOrder('ord_stTC2WHAuS'); - - $refund = $order->refundAll(); - - $this->assertOrderRefund($refund, 're_4qqhO89gsT'); - } - - public function testListOrderRefunds() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_stTC2WHAuS/refunds' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_4qqhO89gsT", - "amount": { - "currency": "EUR", - "value": "698.00" - }, - "status": "pending", - "createdAt": "2018-03-19T12:33:37+00:00", - "description": "Item not in stock, refunding", - "paymentId": "tr_WDqYK6vllg", - "orderId": "ord_pbjz8x", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "ord_pbjz8x", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "refunded", - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/ord_pbjz8x", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?from=re_APBiGPH2vV&limit=5", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/list-order-refunds", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->getOrder('ord_stTC2WHAuS'); - - $refunds = $order->refunds(); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count()); - $this->assertCount(1, $refunds); - - $this->assertOrderRefund($refunds[0], 're_4qqhO89gsT'); - } - - protected function assertOrderRefund($refund, $refund_id, $refund_status = RefundStatus::PENDING) - { - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals($refund_id, $refund->id); - $this->assertAmountObject('698.00', 'EUR', $refund->amount); - - $this->assertEquals($refund_status, $refund->status); - $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); - $this->assertEquals('Item not in stock, refunding', $refund->description); - $this->assertEquals('tr_WDqYK6vllg', $refund->paymentId); - - $this->assertLinkObject( - "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/{$refund_id}", - 'application/hal+json', - $refund->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/refunds-api/get-refund', - 'text/html', - $refund->_links->documentation - ); - } - - protected function getOrderRefundResponseFixture($refund_id, $order_id) - { - return str_replace( - ['<>', '<>'], - [$refund_id, $order_id], - '{ - "resource": "refund", - "id": "<>", - "amount": { - "currency": "EUR", - "value": "698.00" - }, - "status": "pending", - "createdAt": "2018-03-19T12:33:37+00:00", - "description": "Item not in stock, refunding", - "paymentId": "tr_WDqYK6vllg", - "orderId": "<>", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "refunded", - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/<>", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund", - "type": "text/html" - } - } - }' - ); - } - - protected function getOrder($id) - { - $orderJson = $this->getOrderResponseFixture($id); - - return $this->copy(json_decode($orderJson), new Order($this->apiClient)); - } - - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) - { - return str_replace( - '<>', - $order_id, - '{ - "resource": "order", - "id": "<>", - "profileId": "pfl_URR55HPMGx", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "amountCaptured": { - "value": "0.00", - "currency": "EUR" - }, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "status": "'.$order_status.'", - "metadata": { - "order_id": "1337", - "description": "Lego cars" - }, - "consumerDateOfBirth": "1958-01-31", - "createdAt": "2018-08-02T09:29:56+00:00", - "mode": "live", - "billingAddress": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "shippingAddress": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": "1337", - "locale": "nl_NL", - "method" : "klarnapaylater", - "isCancelable": true, - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "created", - "isCancelable": true, - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "created", - "isCancelable": true, - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "refunds": { - "href": "https://api.mollie.com/v2/orders/<>/refunds", - "type": "application/hal+json" - }, - "self": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ); - } -} diff --git a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php b/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php index abba0d5dd..c47d549fb 100644 --- a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php @@ -11,7 +11,7 @@ class OrganizationEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testGetOrganization() + public function test_get_organization() { $this->mockApiCall( new Request('GET', '/v2/organizations/org_12345678'), @@ -51,7 +51,7 @@ public function testGetOrganization() $this->assertOrganization($organization); } - public function testGetCurrentOrganization() + public function test_get_current_organization() { $this->mockApiCall( new Request('GET', '/v2/organizations/me'), diff --git a/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php b/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php index 6a9c9d5e1..3718fd825 100644 --- a/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php @@ -10,7 +10,7 @@ final class OrganizationPartnerEndpointTest extends BaseEndpointTest { - public function testGetWorks() + public function test_get_works() { $this->mockApiCall( new Request('GET', '/v2/organizations/me/partner'), @@ -42,17 +42,17 @@ public function testGetWorks() $partner = $this->apiClient->organizationPartners->get(); $this->assertInstanceOf(Partner::class, $partner); - $this->assertEquals("partner", $partner->resource); - $this->assertEquals("signuplink", $partner->partnerType); - $this->assertEquals("2018-03-20T13:13:37+00:00", $partner->partnerContractSignedAt); + $this->assertEquals('partner', $partner->resource); + $this->assertEquals('signuplink', $partner->partnerType); + $this->assertEquals('2018-03-20T13:13:37+00:00', $partner->partnerContractSignedAt); - $selfLink = (object)['href' => 'https://api.mollie.com/v2/organizations/me/partner', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/organizations/me/partner', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $partner->_links->self); - $signUpLink = (object)['href' => 'https://www.mollie.com/dashboard/signup/myCode?lang=en', 'type' => 'text/html']; + $signUpLink = (object) ['href' => 'https://www.mollie.com/dashboard/signup/myCode?lang=en', 'type' => 'text/html']; $this->assertEquals($signUpLink, $partner->_links->signuplink); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/organizations-api/get-partner', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/organizations-api/get-partner', 'type' => 'text/html']; $this->assertEquals($documentationLink, $partner->_links->documentation); } } diff --git a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php index 5b5e1d457..77f7799b6 100644 --- a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php @@ -14,7 +14,7 @@ class PaymentCaptureEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testCreateCaptureForPaymentResource() + public function test_create_capture_for_payment_resource() { $this->mockApiCall( new Request( @@ -41,7 +41,7 @@ public function testCreateCaptureForPaymentResource() $this->assertCapture($capture); } - public function testGetCaptureForPaymentResource() + public function test_get_capture_for_payment_resource() { $this->mockApiCall( new Request( @@ -63,7 +63,7 @@ public function testGetCaptureForPaymentResource() $this->assertCapture($capture); } - public function testGetCaptureOnPaymentResource() + public function test_get_capture_on_payment_resource() { $this->mockApiCall( new Request( @@ -82,7 +82,7 @@ public function testGetCaptureOnPaymentResource() $this->assertCapture($capture); } - public function testListCapturesOnPaymentResource() + public function test_list_captures_on_payment_resource() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php index d1e0f0ac2..4082f1b3d 100644 --- a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php @@ -15,7 +15,7 @@ class PaymentChargebackEndpointTest extends BaseEndpointTest use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function testListChargebacksOnPaymentResource() + public function test_list_chargebacks_on_payment_resource() { $this->mockApiCall( new Request( @@ -123,7 +123,7 @@ public function testListChargebacksOnPaymentResource() $this->assertChargeback($chargebacks[1], 'tr_44aKxzEbr8', 'chb_6cqlwf', '-0.37'); } - public function testGetChargebackOnPaymentResource() + public function test_get_chargeback_on_payment_resource() { $this->mockApiCall( new Request( @@ -169,7 +169,7 @@ public function testGetChargebackOnPaymentResource() $this->assertChargeback($chargeback, 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00'); } - public function testPaymentChargebacksListForIdPaymentChargebackEndpoint() + public function test_payment_chargebacks_list_for_id_payment_chargeback_endpoint() { $this->mockApiCall( new Request( @@ -238,7 +238,7 @@ public function testPaymentChargebacksListForIdPaymentChargebackEndpoint() $this->assertEquals($chargebacks[0]->paymentId, 'tr_44aKxzEbr8'); } - public function testPaymentChargebacksListForPaymentChargebackEndpoint() + public function test_payment_chargebacks_list_for_payment_chargeback_endpoint() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index 08a8b3f3f..1a55a7365 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -15,7 +15,7 @@ class PaymentEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testCreatePayment() + public function test_create_payment() { $this->mockApiCall( new Request( @@ -96,7 +96,7 @@ public function testCreatePayment() $this->assertEquals('test', $payment->mode); $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; $amount->currency = 'EUR'; $this->assertEquals($amount, $payment->amount); @@ -123,7 +123,7 @@ public function testCreatePayment() $this->assertEquals($documentationLink, $payment->_links->documentation); } - public function testUpdatePayment() + public function test_update_payment() { $this->mockApiCall( new Request( @@ -234,7 +234,7 @@ public function testUpdatePayment() ); } - public function testGetPayment() + public function test_get_payment() { $this->mockApiCall( new Request( @@ -306,7 +306,7 @@ public function testGetPayment() $this->assertEquals('test', $payment->mode); $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; $amount->currency = 'EUR'; $this->assertEquals($amount, $payment->amount); @@ -316,12 +316,12 @@ public function testGetPayment() $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); $this->assertEquals(PaymentStatus::PAID, $payment->status); - $amountRefunded = new Stdclass(); + $amountRefunded = new Stdclass; $amountRefunded->value = '0.00'; $amountRefunded->currency = 'EUR'; $this->assertEquals($amountRefunded, $payment->amountRefunded); - $amountRemaining = new Stdclass(); + $amountRemaining = new Stdclass; $amountRemaining->value = '20.00'; $amountRemaining->currency = 'EUR'; $this->assertEquals($amountRemaining, $payment->amountRemaining); @@ -345,7 +345,7 @@ public function testGetPayment() $this->assertEquals($documentationLink, $payment->_links->documentation); } - public function testListPayment() + public function test_list_payment() { $this->mockApiCall( new Request( @@ -493,7 +493,7 @@ public function testListPayment() $this->assertEquals($nextLink, $payments->_links->next); } - public function testIteratePayment() + public function test_iterate_payment() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php index 1db7f9ec6..1c4d6fdf4 100644 --- a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php @@ -11,12 +11,12 @@ class PaymentLinkEndpointTest extends BaseEndpointTest { /** @test */ - public function testListPaymentLinks() + public function test_list_payment_links() { $this->mockApiCall( new Request( - "GET", - "/v2/payment-links", + 'GET', + '/v2/payment-links', [], '' ), @@ -81,12 +81,12 @@ public function testListPaymentLinks() } /** @test */ - public function testIteratePaymentLinks() + public function test_iterate_payment_links() { $this->mockApiCall( new Request( - "GET", - "/v2/payment-links", + 'GET', + '/v2/payment-links', [], '' ), @@ -142,18 +142,18 @@ public function testIteratePaymentLinks() ); foreach ($this->apiClient->paymentLinks->iterator() as $paymentLink) { $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals("payment-link", $paymentLink->resource); + $this->assertEquals('payment-link', $paymentLink->resource); // No need to test all attributes as these are mapped dynamically. } } /** @test */ - public function testGetPaymentLink() + public function test_get_payment_link() { $this->mockApiCall( new Request( - "GET", - "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", + 'GET', + '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true', [], '' ), @@ -193,20 +193,20 @@ public function testGetPaymentLink() ) ); - $paymentLink = $this->apiClient->paymentLinks->get("pl_4Y0eZitmBnQ6IDoMqZQKh", ["testmode" => true]); + $paymentLink = $this->apiClient->paymentLinks->get('pl_4Y0eZitmBnQ6IDoMqZQKh', ['testmode' => true]); $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals("payment-link", $paymentLink->resource); - $this->assertEquals("pl_4Y0eZitmBnQ6IDoMqZQKh", $paymentLink->id); + $this->assertEquals('payment-link', $paymentLink->resource); + $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLink->id); // No need to test all attributes as these are mapped dynamically. } /** @test */ - public function testCreatePaymentLink() + public function test_create_payment_link() { $this->mockApiCall( new Request( - "POST", - "/v2/payment-links", + 'POST', + '/v2/payment-links', [], '{ "description": "Bicycle tires", @@ -256,14 +256,14 @@ public function testCreatePaymentLink() ); $paymentLink = $this->apiClient->paymentLinks->create([ - "description" => "Bicycle tires", - "amount" => [ - "currency" => "EUR", - "value" => "24.95", + 'description' => 'Bicycle tires', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '24.95', ], - "webhookUrl" => "https://webshop.example.org/payment-links/webhook/", - "redirectUrl" => "https://webshop.example.org/thanks", - "expiresAt" => "2023-06-06T11:00:00+00:00", + 'webhookUrl' => 'https://webshop.example.org/payment-links/webhook/', + 'redirectUrl' => 'https://webshop.example.org/thanks', + 'expiresAt' => '2023-06-06T11:00:00+00:00', ]); $this->assertInstanceOf(PaymentLink::class, $paymentLink); @@ -273,12 +273,12 @@ public function testCreatePaymentLink() } /** @test */ - public function testUpdatePaymentLink() + public function test_update_payment_link() { $this->mockApiCall( new Request( - "PATCH", - "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh", + 'PATCH', + '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh', [], '{ "description":"Bicycle tires", @@ -334,12 +334,12 @@ public function testUpdatePaymentLink() } /** @test */ - public function testDeletePaymentLink() + public function test_delete_payment_link() { $this->mockApiCall( new Request( - "DELETE", - "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh" + 'DELETE', + '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh' ), new Response( 204, diff --git a/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php index 722f642c6..d2555d9a7 100644 --- a/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php @@ -12,12 +12,12 @@ class PaymentLinkPaymentEndpointTest extends BaseEndpointTest { /** @test */ - public function testGetPaymentsPageForPaymentLink() + public function test_get_payments_page_for_payment_link() { $this->mockApiCall( new Request( - "GET", - "/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments" + 'GET', + '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments' ), new Response( 200, @@ -80,11 +80,11 @@ public function testGetPaymentsPageForPaymentLink() ) ); - $response = $this->apiClient->paymentLinkPayments->pageForId("pl_4Y0eZitmBnQ6IDoMqZQKh"); + $response = $this->apiClient->paymentLinkPayments->pageForId('pl_4Y0eZitmBnQ6IDoMqZQKh'); $this->assertInstanceOf(PaymentCollection::class, $response); $this->assertInstanceOf(Payment::class, $response[0]); - $this->assertEquals($response[0]->id, "tr_7UhSN1zuXS"); + $this->assertEquals($response[0]->id, 'tr_7UhSN1zuXS'); // Not necessary to test all fields... } } diff --git a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php index f579b18e5..24da25e00 100644 --- a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php @@ -11,12 +11,12 @@ class PaymentRefundEndpointTest extends BaseEndpointTest { - public function testGetRefundForPaymentResource() + public function test_get_refund_for_payment_resource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm" + 'GET', + '/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm' ), new Response( 200, @@ -54,42 +54,42 @@ public function testGetRefundForPaymentResource() ) ); - $refund = $this->apiClient->paymentRefunds->getFor($this->getPayment(), "re_PsAvxvLsnm"); + $refund = $this->apiClient->paymentRefunds->getFor($this->getPayment(), 're_PsAvxvLsnm'); $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_PsAvxvLsnm", $refund->id); + $this->assertEquals('re_PsAvxvLsnm', $refund->id); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->amount); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt); - $this->assertEquals("My first API payment", $refund->description); - $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); + $this->assertEquals('My first API payment', $refund->description); + $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '-20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->settlementAmount); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/get-refund", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/get-refund', 'type' => 'text/html']; $this->assertEquals($documentationLink, $refund->_links->documentation); } - public function testCreateRefundForPaymentResource() + public function test_create_refund_for_payment_resource() { $this->mockApiCall( new Request( - "POST", - "/v2/payments/tr_44aKxzEbr8/refunds" + 'POST', + '/v2/payments/tr_44aKxzEbr8/refunds' ), new Response( 201, @@ -127,43 +127,42 @@ public function testCreateRefundForPaymentResource() ); $payment = $this->getPayment(); $refundData = [ - "amount" => [ - "currency" => "EUR", - "value" => "20.00", + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', ], ]; $refund = $this->apiClient->paymentRefunds->createFor($payment, $refundData); $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_4qqhO89gsT", $refund->id); + $this->assertEquals('re_4qqhO89gsT', $refund->id); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->amount); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-14T17:09:02.0Z", $refund->createdAt); - $this->assertEquals("Order #33", $refund->description); - $this->assertEquals("tr_WDqYK6vllg", $refund->paymentId); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-14T17:09:02.0Z', $refund->createdAt); + $this->assertEquals('Order #33', $refund->description); + $this->assertEquals('tr_WDqYK6vllg', $refund->paymentId); - - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund', 'type' => 'text/html']; $this->assertEquals($documentationLink, $refund->_links->documentation); } - public function testGetRefundOnPaymentResource() + public function test_get_refund_on_payment_resource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm" + 'GET', + '/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm' ), new Response( 201, @@ -201,42 +200,42 @@ public function testGetRefundOnPaymentResource() ) ); - $refund = $this->getPayment()->getRefund("re_PsAvxvLsnm"); + $refund = $this->getPayment()->getRefund('re_PsAvxvLsnm'); $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_PsAvxvLsnm", $refund->id); + $this->assertEquals('re_PsAvxvLsnm', $refund->id); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->amount); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt); - $this->assertEquals("My first API payment", $refund->description); - $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); + $this->assertEquals('My first API payment', $refund->description); + $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '-20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->settlementAmount); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-refund', 'type' => 'text/html']; $this->assertEquals($documentationLink, $refund->_links->documentation); } - public function testCreateRefund() + public function test_create_refund() { $this->mockApiCall( new Request( - "POST", - "/v2/payments/tr_44aKxzEbr8/refunds", + 'POST', + '/v2/payments/tr_44aKxzEbr8/refunds', [], '{"amount":{"currency":"EUR","value":"20.00"}}' ), @@ -277,46 +276,46 @@ public function testCreateRefund() ); $refund = $this->getPayment()->refund([ - "amount" => [ - "currency" => "EUR", - "value" => "20.00", + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', ], ]); $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_PsAvxvLsnm", $refund->id); + $this->assertEquals('re_PsAvxvLsnm', $refund->id); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->amount); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-19T12:33:37+00:00", $refund->createdAt); - $this->assertEquals("My first API payment", $refund->description); - $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); + $this->assertEquals('My first API payment', $refund->description); + $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - $amount = new Stdclass(); + $amount = new Stdclass; $amount->value = '-20.00'; - $amount->currency = "EUR"; + $amount->currency = 'EUR'; $this->assertEquals($amount, $refund->settlementAmount); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/refunds-api/create-refund", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-refund', 'type' => 'text/html']; $this->assertEquals($documentationLink, $refund->_links->documentation); } - public function testGetRefundsOnPaymentResource() + public function test_get_refunds_on_payment_resource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/refunds", + 'GET', + '/v2/payments/tr_44aKxzEbr8/refunds', [], '' ), @@ -380,29 +379,29 @@ public function testGetRefundsOnPaymentResource() $refund = $refunds[0]; $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_haCsig5aru", $refund->id); - $this->assertEquals("2.00", $refund->amount->value); - $this->assertEquals("EUR", $refund->amount->currency); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-28T10:56:10+00:00", $refund->createdAt); - $this->assertEquals("My first API payment", $refund->description); - $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId); - $this->assertEquals("-2.00", $refund->settlementAmount->value); - $this->assertEquals("EUR", $refund->settlementAmount->currency); - - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", "type" => "application/hal+json"]; + $this->assertEquals('re_haCsig5aru', $refund->id); + $this->assertEquals('2.00', $refund->amount->value); + $this->assertEquals('EUR', $refund->amount->currency); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-28T10:56:10+00:00', $refund->createdAt); + $this->assertEquals('My first API payment', $refund->description); + $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); + $this->assertEquals('-2.00', $refund->settlementAmount->value); + $this->assertEquals('EUR', $refund->settlementAmount->currency); + + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); } - public function testListRefundsOnPaymentResource() + public function test_list_refunds_on_payment_resource() { $this->mockApiCall( new Request( - "GET", - "/v2/payments/tr_44aKxzEbr8/refunds", + 'GET', + '/v2/payments/tr_44aKxzEbr8/refunds', [], '' ), @@ -499,29 +498,29 @@ public function testListRefundsOnPaymentResource() $refund = $refunds[0]; $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_b63hJyxbap", $refund->id); - $this->assertEquals("1.00", $refund->amount->value); - $this->assertEquals("EUR", $refund->amount->currency); - $this->assertEquals("refunded", $refund->status); - $this->assertEquals("2021-01-17T20:57:40+00:00", $refund->createdAt); - $this->assertEquals("Order #1610620820", $refund->description); - $this->assertEquals("tr_4NydwvhQDd", $refund->paymentId); - $this->assertEquals("-1.00", $refund->settlementAmount->value); - $this->assertEquals("EUR", $refund->settlementAmount->currency); - - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds/re_b63hJyxbap", "type" => "application/hal+json"]; + $this->assertEquals('re_b63hJyxbap', $refund->id); + $this->assertEquals('1.00', $refund->amount->value); + $this->assertEquals('EUR', $refund->amount->currency); + $this->assertEquals('refunded', $refund->status); + $this->assertEquals('2021-01-17T20:57:40+00:00', $refund->createdAt); + $this->assertEquals('Order #1610620820', $refund->description); + $this->assertEquals('tr_4NydwvhQDd', $refund->paymentId); + $this->assertEquals('-1.00', $refund->settlementAmount->value); + $this->assertEquals('EUR', $refund->settlementAmount->currency); + + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds/re_b63hJyxbap', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_4NydwvhQDd", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_4NydwvhQDd', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); } - public function testCancelRefundForPayment() + public function test_cancel_refund_for_payment() { $this->mockApiCall( new Request( - "DELETE", - "/v2/payments/tr_44aKxzEbr8/refunds/re_4qqhO89gsT", + 'DELETE', + '/v2/payments/tr_44aKxzEbr8/refunds/re_4qqhO89gsT', [], '{"testmode":true}' ), @@ -530,8 +529,8 @@ public function testCancelRefundForPayment() $response = $this->apiClient->paymentRefunds->cancelForPayment( $this->getPayment(), - "re_4qqhO89gsT", - [ 'testmode' => true ] + 're_4qqhO89gsT', + ['testmode' => true] ); $this->assertNull($response); diff --git a/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php index 7f0e21e94..523799347 100644 --- a/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php @@ -8,12 +8,12 @@ class PaymentRouteEndpointTest extends BaseEndpointTest { - public function testUpdateReleaseDateForPaymentId() + public function test_update_release_date_for_payment_id() { $this->mockApiCall( new Request( - "PATCH", - "/v2/payments/tr_2qkhcMzypH/routes/rt_9dk4al1n", + 'PATCH', + '/v2/payments/tr_2qkhcMzypH/routes/rt_9dk4al1n', [], '{ "releaseDate": "2021-09-14", @@ -44,6 +44,6 @@ public function testUpdateReleaseDateForPaymentId() $this->assertInstanceOf(Route::class, $route); $this->assertEquals('rt_9dk4al1n', $route->id); - $this->assertEquals("2021-09-14", $route->releaseDate); + $this->assertEquals('2021-09-14', $route->releaseDate); } } diff --git a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php b/tests/Mollie/API/Endpoints/PermissionEndpointTest.php index 3aa2b8e39..1ac8296d2 100644 --- a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PermissionEndpointTest.php @@ -17,7 +17,7 @@ class PermissionEndpointTest extends BaseEndpointTest * * @dataProvider dpTestGetPermissionIds */ - public function testGetPermissionIds($permissionId) + public function test_get_permission_ids($permissionId) { $this->mockApiCall( new Request('GET', '/v2/permissions/'.$permissionId), @@ -98,7 +98,7 @@ protected function assertPermission($permission, $permissionId) ); } - public function testListPermissions() + public function test_list_permissions() { $this->mockApiCall( new Request('GET', '/v2/permissions'), diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php index e70694dd6..5a65f4120 100644 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php @@ -11,12 +11,12 @@ class ProfileEndpointTest extends BaseEndpointTest { - public function testGetProfile() + public function test_get_profile() { $this->mockApiCall( new Request( - "GET", - "/v2/profiles/pfl_ahe8z8OPut", + 'GET', + '/v2/profiles/pfl_ahe8z8OPut', [], '' ), @@ -70,41 +70,41 @@ public function testGetProfile() $profile = $this->apiClient->profiles->get('pfl_ahe8z8OPut'); $this->assertInstanceOf(Profile::class, $profile); - $this->assertEquals("pfl_ahe8z8OPut", $profile->id); - $this->assertEquals("live", $profile->mode); - $this->assertEquals("My website name", $profile->name); - $this->assertEquals("http://www.mywebsite.com", $profile->website); - $this->assertEquals("info@mywebsite.com", $profile->email); - $this->assertEquals("31123456789", $profile->phone); + $this->assertEquals('pfl_ahe8z8OPut', $profile->id); + $this->assertEquals('live', $profile->mode); + $this->assertEquals('My website name', $profile->name); + $this->assertEquals('http://www.mywebsite.com', $profile->website); + $this->assertEquals('info@mywebsite.com', $profile->email); + $this->assertEquals('31123456789', $profile->phone); $this->assertEquals(5399, $profile->categoryCode); $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); - $this->assertEquals((object) ["status" => "pending"], $profile->review); + $this->assertEquals((object) ['status' => 'pending'], $profile->review); - $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $profile->_links->self); - $chargebacksLink = (object)["href" => "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $chargebacksLink = (object) ['href' => 'https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($chargebacksLink, $profile->_links->chargebacks); - $methodsLink = (object)["href" => "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $methodsLink = (object) ['href' => 'https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($methodsLink, $profile->_links->methods); - $paymentsLink = (object)["href" => "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $paymentsLink = (object) ['href' => 'https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($paymentsLink, $profile->_links->payments); - $refundsLink = (object)["href" => "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $refundsLink = (object) ['href' => 'https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($refundsLink, $profile->_links->refunds); - $checkoutPreviewLink = (object)["href" => "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", "type" => "text/html"]; + $checkoutPreviewLink = (object) ['href' => 'https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut', 'type' => 'text/html']; $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl); } - public function testGetProfileUsingMe() + public function test_get_profile_using_me() { $this->mockApiCall( new Request( - "GET", - "/v2/profiles/me", + 'GET', + '/v2/profiles/me', [], '' ), @@ -158,17 +158,17 @@ public function testGetProfileUsingMe() $profile = $this->apiClient->profiles->get('me'); $this->assertInstanceOf(CurrentProfile::class, $profile); - $this->assertEquals("pfl_ahe8z8OPut", $profile->id); + $this->assertEquals('pfl_ahe8z8OPut', $profile->id); // No need to test it all again... } - public function testGetCurrentProfile() + public function test_get_current_profile() { $this->mockApiCall( new Request( - "GET", - "/v2/profiles/me", + 'GET', + '/v2/profiles/me', [], '' ), @@ -222,41 +222,41 @@ public function testGetCurrentProfile() $profile = $this->apiClient->profiles->getCurrent(); $this->assertInstanceOf(CurrentProfile::class, $profile); - $this->assertEquals("pfl_ahe8z8OPut", $profile->id); - $this->assertEquals("live", $profile->mode); - $this->assertEquals("My website name", $profile->name); - $this->assertEquals("http://www.mywebsite.com", $profile->website); - $this->assertEquals("info@mywebsite.com", $profile->email); - $this->assertEquals("31123456789", $profile->phone); + $this->assertEquals('pfl_ahe8z8OPut', $profile->id); + $this->assertEquals('live', $profile->mode); + $this->assertEquals('My website name', $profile->name); + $this->assertEquals('http://www.mywebsite.com', $profile->website); + $this->assertEquals('info@mywebsite.com', $profile->email); + $this->assertEquals('31123456789', $profile->phone); $this->assertEquals(5399, $profile->categoryCode); $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); - $this->assertEquals((object) ["status" => "pending"], $profile->review); + $this->assertEquals((object) ['status' => 'pending'], $profile->review); - $selfLink = (object)["href" => "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $profile->_links->self); - $chargebacksLink = (object)["href" => "https://api.mollie.com/v2/chargebacks", "type" => "application/hal+json"]; + $chargebacksLink = (object) ['href' => 'https://api.mollie.com/v2/chargebacks', 'type' => 'application/hal+json']; $this->assertEquals($chargebacksLink, $profile->_links->chargebacks); - $methodsLink = (object)["href" => "https://api.mollie.com/v2/methods", "type" => "application/hal+json"]; + $methodsLink = (object) ['href' => 'https://api.mollie.com/v2/methods', 'type' => 'application/hal+json']; $this->assertEquals($methodsLink, $profile->_links->methods); - $paymentsLink = (object)["href" => "https://api.mollie.com/v2/payments", "type" => "application/hal+json"]; + $paymentsLink = (object) ['href' => 'https://api.mollie.com/v2/payments', 'type' => 'application/hal+json']; $this->assertEquals($paymentsLink, $profile->_links->payments); - $refundsLink = (object)["href" => "https://api.mollie.com/v2/refunds", "type" => "application/hal+json"]; + $refundsLink = (object) ['href' => 'https://api.mollie.com/v2/refunds', 'type' => 'application/hal+json']; $this->assertEquals($refundsLink, $profile->_links->refunds); - $checkoutPreviewLink = (object)["href" => "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", "type" => "text/html"]; + $checkoutPreviewLink = (object) ['href' => 'https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut', 'type' => 'text/html']; $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl); } - public function testListProfiles() + public function test_list_profiles() { $this->mockApiCall( new Request( - "GET", - "/v2/profiles", + 'GET', + '/v2/profiles', [], '' ), @@ -374,14 +374,14 @@ public function testListProfiles() $this->assertInstanceOf(Profile::class, $profile); } - $selfLink = (object)["href" => "https://api.mollie.nl/v2/profiles?limit=50", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/profiles?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $profiles->_links->self); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/profiles-api/list-profiles", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/profiles-api/list-profiles', 'type' => 'text/html']; $this->assertEquals($documentationLink, $profiles->_links->documentation); } - public function testUpdateProfile() + public function test_update_profile() { $expectedWebsiteName = 'Mollie'; $expectedEmail = 'mollie@mollie.com'; @@ -396,10 +396,10 @@ public function testUpdateProfile() "resource": "profile", "id": "pfl_ahe8z8OPut", "mode": "live", - "name": "' . $expectedWebsiteName . '", + "name": "'.$expectedWebsiteName.'", "website": "http://www.mywebsite.com", - "email": "' . $expectedEmail . '", - "phone": "' . $expectedPhone . '", + "email": "'.$expectedEmail.'", + "phone": "'.$expectedPhone.'", "categoryCode": 5399, "status": "verified", "review": { diff --git a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php index 0be48de8a..b35c96432 100644 --- a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php @@ -13,7 +13,7 @@ class ProfileMethodEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testEnableProfileMethod() + public function test_enable_profile_method() { $this->mockApiCall( new Request( @@ -69,7 +69,7 @@ public function testEnableProfileMethod() ); } - public function testDisableProfileMethod() + public function test_disable_profile_method() { $this->mockApiCall( new Request( @@ -85,7 +85,7 @@ public function testDisableProfileMethod() $this->assertNull($result); } - public function testEnableCurrentProfileMethod() + public function test_enable_current_profile_method() { $this->mockApiCall( new Request( @@ -141,7 +141,7 @@ public function testEnableCurrentProfileMethod() ); } - public function testDisableCurrentProfileMethod() + public function test_disable_current_profile_method() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php index bcd483341..4ff055ba0 100644 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/RefundEndpointTest.php @@ -9,12 +9,12 @@ class RefundEndpointTest extends BaseEndpointTest { - public function testListRefunds() + public function test_list_refunds() { $this->mockApiCall( new Request( - "GET", - "/v2/refunds", + 'GET', + '/v2/refunds', [], '' ), @@ -78,29 +78,29 @@ public function testListRefunds() $refund = $refunds[0]; $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_haCsig5aru", $refund->id); - $this->assertEquals("2.00", $refund->amount->value); - $this->assertEquals("EUR", $refund->amount->currency); - $this->assertEquals("pending", $refund->status); - $this->assertEquals("2018-03-28T10:56:10+00:00", $refund->createdAt); - $this->assertEquals("My first API payment", $refund->description); - $this->assertEquals("tr_44aKxzEbr8", $refund->paymentId); - $this->assertEquals("-2.00", $refund->settlementAmount->value); - $this->assertEquals("EUR", $refund->settlementAmount->currency); + $this->assertEquals('re_haCsig5aru', $refund->id); + $this->assertEquals('2.00', $refund->amount->value); + $this->assertEquals('EUR', $refund->amount->currency); + $this->assertEquals('pending', $refund->status); + $this->assertEquals('2018-03-28T10:56:10+00:00', $refund->createdAt); + $this->assertEquals('My first API payment', $refund->description); + $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); + $this->assertEquals('-2.00', $refund->settlementAmount->value); + $this->assertEquals('EUR', $refund->settlementAmount->currency); - $selfLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $refund->_links->self); - $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $refund->_links->payment); } - public function testIterateRefunds() + public function test_iterate_refunds() { $this->mockApiCall( new Request( - "GET", - "/v2/refunds", + 'GET', + '/v2/refunds', [], '' ), @@ -157,7 +157,7 @@ public function testIterateRefunds() foreach ($this->apiClient->refunds->iterator() as $refund) { $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("refund", $refund->resource); + $this->assertEquals('refund', $refund->resource); } } } diff --git a/tests/Mollie/API/Endpoints/SessionEndpointTest.php b/tests/Mollie/API/Endpoints/SessionEndpointTest.php index 648e72f24..7724475d2 100644 --- a/tests/Mollie/API/Endpoints/SessionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SessionEndpointTest.php @@ -12,15 +12,15 @@ class SessionEndpointTest extends BaseEndpointTest { - use LinkObjectTestHelpers; use AmountObjectTestHelpers; + use LinkObjectTestHelpers; - public function testCreateSession() + public function test_create_session() { $this->mockApiCall( new Request( - "POST", - "/v2/sessions", + 'POST', + '/v2/sessions', [], '{ "paymentData": { @@ -41,40 +41,40 @@ public function testCreateSession() new Response( 201, [], - $this->getSessionResponseFixture("sess_pbjz8x") + $this->getSessionResponseFixture('sess_pbjz8x') ) ); $session = $this->apiClient->sessions->create([ - "paymentData" => [ - "amount" => [ - "value" => "10.00", - "currency" => "EUR", + 'paymentData' => [ + 'amount' => [ + 'value' => '10.00', + 'currency' => 'EUR', ], - "description" => "Order #12345", + 'description' => 'Order #12345', ], - "method" => "paypal", - "methodDetails" => [ - "checkoutFlow" => "express", + 'method' => 'paypal', + 'methodDetails' => [ + 'checkoutFlow' => 'express', ], - "returnUrl" => "https://example.org/redirect", - "cancelUrl" => "https://example.org/cancel", + 'returnUrl' => 'https://example.org/redirect', + 'cancelUrl' => 'https://example.org/cancel', ]); $this->assertSession($session, 'sess_pbjz8x'); } - public function testGetSession() + public function test_get_session() { $this->mockApiCall( new Request( - "GET", - "/v2/sessions/sess_pbjz8x" + 'GET', + '/v2/sessions/sess_pbjz8x' ), new Response( 200, [], - $this->getSessionResponseFixture("sess_pbjz8x") + $this->getSessionResponseFixture('sess_pbjz8x') ) ); @@ -83,10 +83,10 @@ public function testGetSession() $this->assertSession($session, 'sess_pbjz8x'); } - public function testListSessions() + public function test_list_sessions() { $this->mockApiCall( - new Request("GET", "/v2/sessions"), + new Request('GET', '/v2/sessions'), new Response( 200, [], @@ -94,9 +94,9 @@ public function testListSessions() "count": 3, "_embedded": { "sessions": [ - ' . $this->getSessionResponseFixture("sess_pbjz1x") . ', - ' . $this->getSessionResponseFixture("sess_pbjz2y") . ', - ' . $this->getSessionResponseFixture("sess_pbjz3z") . ' + '.$this->getSessionResponseFixture('sess_pbjz1x').', + '.$this->getSessionResponseFixture('sess_pbjz2y').', + '.$this->getSessionResponseFixture('sess_pbjz3z').' ] }, "_links": { @@ -126,20 +126,20 @@ public function testListSessions() $this->assertNull($sessions->_links->previous); $selfLink = $this->createLinkObject( - "https://api.mollie.com/v2/sessions", - "application/hal+json" + 'https://api.mollie.com/v2/sessions', + 'application/hal+json' ); $this->assertEquals($selfLink, $sessions->_links->self); $nextLink = $this->createLinkObject( - "https://api.mollie.com/v2/sessions?from=sess_stTC2WHAuS", - "application/hal+json" + 'https://api.mollie.com/v2/sessions?from=sess_stTC2WHAuS', + 'application/hal+json' ); $this->assertEquals($nextLink, $sessions->_links->next); $documentationLink = $this->createLinkObject( - "https://docs.mollie.com/reference/v2/sessions-api/list-sessions", - "text/html" + 'https://docs.mollie.com/reference/v2/sessions-api/list-sessions', + 'text/html' ); $this->assertEquals($documentationLink, $sessions->_links->documentation); @@ -148,10 +148,10 @@ public function testListSessions() $this->assertSession($sessions[2], 'sess_pbjz3z'); } - public function testIterateSessions() + public function test_iterate_sessions() { $this->mockApiCall( - new Request("GET", "/v2/sessions"), + new Request('GET', '/v2/sessions'), new Response( 200, [], @@ -159,9 +159,9 @@ public function testIterateSessions() "count": 3, "_embedded": { "sessions": [ - ' . $this->getSessionResponseFixture("sess_pbjz1x") . ', - ' . $this->getSessionResponseFixture("sess_pbjz2y") . ', - ' . $this->getSessionResponseFixture("sess_pbjz3z") . ' + '.$this->getSessionResponseFixture('sess_pbjz1x').', + '.$this->getSessionResponseFixture('sess_pbjz2y').', + '.$this->getSessionResponseFixture('sess_pbjz3z').' ] }, "_links": { @@ -185,10 +185,10 @@ public function testIterateSessions() } } - public function testCancelSession() + public function test_cancel_session() { $this->mockApiCall( - new Request("DELETE", "/v2/sessions/sess_pbjz1x"), + new Request('DELETE', '/v2/sessions/sess_pbjz1x'), new Response( 200, [], @@ -203,12 +203,12 @@ public function testCancelSession() } /** @test */ - public function testUpdateSession() + public function test_update_session() { $this->mockApiCall( new Request( - "PATCH", - "/v2/sessions/sess_pbjz8x", + 'PATCH', + '/v2/sessions/sess_pbjz8x', [], '{ "billingAddress": { @@ -240,7 +240,7 @@ public function testUpdateSession() 200, [], $this->getSessionResponseFixture( - "sess_pbjz8x", + 'sess_pbjz8x', SessionStatus::STATUS_CREATED ) ) @@ -251,20 +251,20 @@ public function testUpdateSession() /** @var Session $session */ $session = $this->copy(json_decode($sessionJSON), new Session($this->apiClient)); - $session->billingAddress->organizationName = "Organization Name LTD."; - $session->billingAddress->streetAndNumber = "Keizersgracht 313"; - $session->billingAddress->city = "Amsterdam"; - $session->billingAddress->region = "Noord-Holland"; - $session->billingAddress->postalCode = "1234AB"; - $session->billingAddress->country = "NL"; - $session->billingAddress->title = "Dhr"; - $session->billingAddress->givenName = "Piet"; - $session->billingAddress->familyName = "Mondriaan"; - $session->billingAddress->email = "piet@mondriaan.com"; - $session->billingAddress->phone = "+31208202070"; + $session->billingAddress->organizationName = 'Organization Name LTD.'; + $session->billingAddress->streetAndNumber = 'Keizersgracht 313'; + $session->billingAddress->city = 'Amsterdam'; + $session->billingAddress->region = 'Noord-Holland'; + $session->billingAddress->postalCode = '1234AB'; + $session->billingAddress->country = 'NL'; + $session->billingAddress->title = 'Dhr'; + $session->billingAddress->givenName = 'Piet'; + $session->billingAddress->familyName = 'Mondriaan'; + $session->billingAddress->email = 'piet@mondriaan.com'; + $session->billingAddress->phone = '+31208202070'; $session = $session->update(); - $this->assertSession($session, "sess_pbjz8x", SessionStatus::STATUS_CREATED); + $this->assertSession($session, 'sess_pbjz8x', SessionStatus::STATUS_CREATED); } protected function assertSession($session, $session_id, $sessionStatus = SessionStatus::STATUS_CREATED) @@ -278,15 +278,15 @@ protected function assertSession($session, $session_id, $sessionStatus = Session $this->assertEquals($sessionStatus, $session->status); - $this->assertEquals("https://example.org/redirect", $session->getRedirectUrl()); + $this->assertEquals('https://example.org/redirect', $session->getRedirectUrl()); /** * @todo check how the links will be returned */ // $this->assertEquals("https://example.org/cancel", $session->cancelUrl); - $links = (object)[ + $links = (object) [ 'self' => $this->createLinkObject( - 'https://api.mollie.com/v2/sessions/' . $session_id, + 'https://api.mollie.com/v2/sessions/'.$session_id, 'application/hal+json' ), 'redirect' => $this->createLinkObject( @@ -301,8 +301,8 @@ protected function getSessionResponseFixture($session_id, $sessionStatus = Sessi { return str_replace( [ - "<>", - "<>", + '<>', + '<>', ], [ $session_id, diff --git a/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php index 366a66a33..2467867ea 100644 --- a/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php @@ -1,4 +1,5 @@ mockApiCall( new Request( @@ -93,6 +94,6 @@ public function testListSettlementCaptures() $capture = $captures[0]; $this->assertInstanceOf(Capture::class, $capture); - $this->assertEquals("cpt_4qqhO89gsT", $capture->id); + $this->assertEquals('cpt_4qqhO89gsT', $capture->id); } } diff --git a/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php index f76808490..d3bf612cd 100644 --- a/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php @@ -1,4 +1,5 @@ mockApiCall( new Request( @@ -83,6 +84,6 @@ public function testListSettlementChargebacks() $chargeback = $chargebacks[0]; $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals("chb_n9z0tp", $chargeback->id); + $this->assertEquals('chb_n9z0tp', $chargeback->id); } } diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php index a8eab4902..c08b26f30 100644 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php @@ -10,12 +10,12 @@ class SettlementEndpointTest extends BaseEndpointTest { - public function testGetSettlement() + public function test_get_settlement() { $this->mockApiCall( new Request( - "GET", - "/v2/settlements/stl_xcaSGAHuRt", + 'GET', + '/v2/settlements/stl_xcaSGAHuRt', [], '' ), @@ -195,41 +195,41 @@ public function testGetSettlement() ); /** @var Settlement $settlement */ - $settlement = $this->apiClient->settlements->get("stl_xcaSGAHuRt"); + $settlement = $this->apiClient->settlements->get('stl_xcaSGAHuRt'); $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals("settlement", $settlement->resource); - $this->assertEquals("stl_xcaSGAHuRt", $settlement->id); - $this->assertEquals("1234567.1234.12", $settlement->reference); - $this->assertEquals("2018-04-30T04:00:02+00:00", $settlement->createdAt); - $this->assertEquals("2018-05-01T04:00:02+00:00", $settlement->settledAt); + $this->assertEquals('settlement', $settlement->resource); + $this->assertEquals('stl_xcaSGAHuRt', $settlement->id); + $this->assertEquals('1234567.1234.12', $settlement->reference); + $this->assertEquals('2018-04-30T04:00:02+00:00', $settlement->createdAt); + $this->assertEquals('2018-05-01T04:00:02+00:00', $settlement->settledAt); $this->assertEquals(SettlementStatus::PENDING, $settlement->status); - $this->assertEquals((object) ["value" => "1980.98", "currency" => "EUR"], $settlement->amount); + $this->assertEquals((object) ['value' => '1980.98', 'currency' => 'EUR'], $settlement->amount); $this->assertNotEmpty($settlement->periods); - $this->assertEquals("inv_VseyTUhJSy", $settlement->invoiceId); + $this->assertEquals('inv_VseyTUhJSy', $settlement->invoiceId); - $selfLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $settlement->_links->self); - $paymentLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments', 'type' => 'application/hal+json']; + $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments', 'type' => 'application/hal+json']; $this->assertEquals($paymentLink, $settlement->_links->payments); - $refundLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds', 'type' => 'application/hal+json']; + $refundLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds', 'type' => 'application/hal+json']; $this->assertEquals($refundLink, $settlement->_links->refunds); - $chargebackLink = (object)['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks', 'type' => 'application/hal+json']; + $chargebackLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks', 'type' => 'application/hal+json']; $this->assertEquals($chargebackLink, $settlement->_links->chargebacks); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/get-settlement', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/settlements-api/get-settlement', 'type' => 'text/html']; $this->assertEquals($documentationLink, $settlement->_links->documentation); } - public function testListSettlement() + public function test_list_settlement() { $this->mockApiCall( new Request( - "GET", - "/v2/settlements", + 'GET', + '/v2/settlements', [], '' ), @@ -429,30 +429,30 @@ public function testListSettlement() $settlements = $this->apiClient->settlements->page(); $this->assertInstanceOf(SettlementCollection::class, $settlements); - $documentationLink = (object)['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html']; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html']; $this->assertEquals($documentationLink, $settlements->_links->documentation); - $selfLink = (object)['href' => 'https://api.mollie.nl/v2/settlements', 'type' => 'application/hal+json']; + $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/settlements', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $settlements->_links->self); $this->assertEmpty($settlements->_links->previous); - $nextLink = (object)['href' => 'https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs', 'type' => 'application/hal+json']; + $nextLink = (object) ['href' => 'https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs', 'type' => 'application/hal+json']; $this->assertEquals($nextLink, $settlements->_links->next); foreach ($settlements as $settlement) { $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals("settlement", $settlement->resource); + $this->assertEquals('settlement', $settlement->resource); $this->assertNotEmpty($settlement->periods); } } - public function testIterateSettlement() + public function test_iterate_settlement() { $this->mockApiCall( new Request( - "GET", - "/v2/settlements", + 'GET', + '/v2/settlements', [], '' ), @@ -647,7 +647,7 @@ public function testIterateSettlement() foreach ($this->apiClient->settlements->iterator() as $settlement) { $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals("settlement", $settlement->resource); + $this->assertEquals('settlement', $settlement->resource); $this->assertNotEmpty($settlement->periods); } } diff --git a/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php index 0a9f8d71e..5add3e5ec 100644 --- a/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php @@ -10,7 +10,7 @@ class SettlementPaymentsEndpointTest extends BaseEndpointTest { - public function testListSettlementPayments() + public function test_list_settlement_payments() { $this->mockApiCall( new Request( @@ -85,6 +85,6 @@ public function testListSettlementPayments() $payment = $payments[0]; $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals("tr_7UhSN1zuXS", $payment->id); + $this->assertEquals('tr_7UhSN1zuXS', $payment->id); } } diff --git a/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php index 261432c54..482829b0a 100644 --- a/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php @@ -13,7 +13,7 @@ class SettlementRefundEndpointTest extends BaseEndpointTest { /** @test */ - public function testListSettlementRefunds() + public function test_list_settlement_refunds() { $this->mockApiCall( new Request( @@ -87,6 +87,6 @@ public function testListSettlementRefunds() $refund = $refunds[0]; $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_3aKhkUNigy", $refund->id); + $this->assertEquals('re_3aKhkUNigy', $refund->id); } } diff --git a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php b/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php deleted file mode 100644 index 006c89bb8..000000000 --- a/tests/Mollie/API/Endpoints/ShipmentEndpointTest.php +++ /dev/null @@ -1,564 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/orders/ord_pbjz8x/shipments', - [], - '{ - "lines": [ - { - "id": "odl_dgtxyl", - "quantity": 1 - }, - { - "id": "odl_jp31jz" - } - ] - }' - ), - new Response( - 201, - [], - $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - $shipment = $order->createShipment([ - 'lines' => [ - [ - 'id' => 'odl_dgtxyl', - 'quantity' => 1, - ], - [ - 'id' => 'odl_jp31jz', - ], - ], - ]); - - $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - } - - public function testCreateShipmentUsingShorthand() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/orders/ord_pbjz8x/shipments', - [], - '{ - "lines": [] - }' - ), - new Response( - 201, - [], - $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - $shipment = $order->shipAll(); - - $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - } - - public function testGetShipment() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U' - ), - new Response( - 200, - [], - $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - $shipment = $this->apiClient->shipments->getFor($order, 'shp_3wmsgCJN4U'); - - $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - } - - public function testGetShipmentOnOrderResource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U' - ), - new Response( - 200, - [], - $this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x') - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - $shipment = $order->getShipment('shp_3wmsgCJN4U'); - - $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - } - - public function testListShipmentsViaShipmentEndpoint() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x/shipments' - ), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "shipments": [ - '.$this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x').', - '.$this->getShipmentResponseFixture('shp_kjh234CASX', 'ord_pbjz8x').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/order/ord_pbjz8x/shipments", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - $shipments = $this->apiClient->shipments->listFor($order); - - $this->assertInstanceOf(ShipmentCollection::class, $shipments); - $this->assertShipment($shipments[0], 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - $this->assertShipment($shipments[1], 'shp_kjh234CASX', 'ord_pbjz8x'); - } - - public function testListShipmentsOnOrderResource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/orders/ord_pbjz8x/shipments' - ), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "shipments": [ - '.$this->getShipmentResponseFixture('shp_3wmsgCJN4U', 'ord_pbjz8x').', - '.$this->getShipmentResponseFixture('shp_kjh234CASX', 'ord_pbjz8x').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/order/ord_pbjz8x/shipments", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments", - "type": "text/html" - } - } - }' - ) - ); - - $order = $this->getOrder('ord_pbjz8x'); - - $shipments = $order->shipments(); - - $this->assertInstanceOf(ShipmentCollection::class, $shipments); - $this->assertShipment($shipments[0], 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - $this->assertShipment($shipments[1], 'shp_kjh234CASX', 'ord_pbjz8x'); - } - - public function testUpdateShipmentTrackingInfo() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/orders/ord_pbjz8x/shipments/shp_3wmsgCJN4U', - [], - '{ - "tracking": { - "carrier": "PostNL", - "code": "3SKABA000000000", - "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" - } - }' - ), - new Response( - 200, - [], - $this->getShipmentResponseFixture( - 'shp_3wmsgCJN4U', - 'ord_pbjz8x', - OrderLineStatus::SHIPPING, - '"tracking": { - "carrier": "PostNL", - "code": "3SKABA000000000", - "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" - },' - ) - ) - ); - - $shipment = $this->getShipment('shp_3wmsgCJN4U', 'ord_pbjz8x', OrderLineStatus::SHIPPING); - - $shipment->tracking = [ - 'carrier' => 'PostNL', - 'code' => '3SKABA000000000', - 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', - ]; - $shipment = $shipment->update(); - - $this->assertShipment($shipment, 'shp_3wmsgCJN4U', 'ord_pbjz8x'); - - $this->assertEquals((object) [ - 'carrier' => 'PostNL', - 'code' => '3SKABA000000000', - 'url' => 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', - ], $shipment->tracking); - } - - protected function assertShipment($shipment, $shipment_id, $order_id) - { - $this->assertInstanceOf(Shipment::class, $shipment); - $this->assertEquals('shipment', $shipment->resource); - $this->assertEquals($shipment_id, $shipment->id); - $this->assertEquals($order_id, $shipment->orderId); - $this->assertEquals('2018-08-02T09:29:56+00:00', $shipment->createdAt); - $this->assertLinkObject( - "https://api.mollie.com/v2/orders/ord_pbjz8x/shipments/{$shipment_id}", - 'application/hal+json', - $shipment->_links->self - ); - $this->assertLinkObject( - 'https://api.mollie.com/v2/orders/ord_pbjz8x', - 'application/hal+json', - $shipment->_links->order - ); - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/shipments-api/get-shipment', - 'text/html', - $shipment->_links->documentation - ); - - $line1 = $shipment->lines()[0]; - $this->assertEquals('orderline', $line1->resource); - $this->assertEquals('odl_dgtxyl', $line1->id); - $this->assertEquals('ord_pbjz8x', $line1->orderId); - $this->assertEquals('LEGO 42083 Bugatti Chiron', $line1->name); - $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line1->productUrl); - $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line1->imageUrl); - $this->assertEquals('5702016116977', $line1->sku); - $this->assertEquals('physical', $line1->type); - $this->assertEquals(OrderLineStatus::SHIPPING, $line1->status); - $this->assertEquals(2, $line1->quantity); - $this->assertEquals('2018-08-02T09:29:56+00:00', $line1->createdAt); - $this->assertEquals('21.00', $line1->vatRate); - $this->assertAmountObject('121.14', 'EUR', $line1->vatAmount); - $this->assertAmountObject('399.00', 'EUR', $line1->unitPrice); - $this->assertAmountObject('100.00', 'EUR', $line1->discountAmount); - $this->assertAmountObject('698.00', 'EUR', $line1->totalAmount); - - $line2 = $shipment->lines()[1]; - $this->assertEquals('orderline', $line2->resource); - $this->assertEquals('odl_jp31jz', $line2->id); - $this->assertEquals('ord_pbjz8x', $line2->orderId); - $this->assertEquals('LEGO 42056 Porsche 911 GT3 RS', $line2->name); - $this->assertEquals('https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', $line2->productUrl); - $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', $line2->imageUrl); - $this->assertEquals('5702015594028', $line2->sku); - $this->assertEquals('digital', $line2->type); - $this->assertEquals(OrderLineStatus::SHIPPING, $line2->status); - $this->assertEquals(1, $line2->quantity); - $this->assertEquals('2018-08-02T09:29:56+00:00', $line2->createdAt); - $this->assertEquals('21.00', $line2->vatRate); - $this->assertAmountObject('57.27', 'EUR', $line2->vatAmount); - $this->assertAmountObject('329.99', 'EUR', $line2->unitPrice); - $this->assertAmountObject('329.99', 'EUR', $line2->totalAmount); - } - - protected function getOrder($id) - { - $orderJson = $this->getOrderResponseFixture($id); - - return $this->copy(json_decode($orderJson), new Order($this->apiClient)); - } - - protected function getShipment($shipment_id, $order_id, $orderLineStatus = OrderLineStatus::SHIPPING) - { - $shipmentJson = $this->getShipmentResponseFixture($shipment_id, $order_id, $orderLineStatus); - - return $this->copy(json_decode($shipmentJson), new Shipment($this->apiClient)); - } - - protected function getOrderResponseFixture($order_id, $order_status = OrderStatus::CREATED) - { - return str_replace( - '<>', - $order_id, - '{ - "resource": "order", - "id": "<>", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "amountCaptured": { - "value": "0.00", - "currency": "EUR" - }, - "amountRefunded": { - "value": "0.00", - "currency": "EUR" - }, - "status": "'.$order_status.'", - "metadata": { - "order_id": "1337", - "description": "Lego cars" - }, - "consumerDateOfBirth": "1958-01-31", - "createdAt": "2018-08-02T09:29:56+00:00", - "mode": "live", - "billingAddress": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "shippingAddress": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "orderNumber": "1337", - "locale": "nl_NL", - "method" : "klarnapaylater", - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "created", - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>/orderlines/odl_dgtxyl", - "type": "application/hal+json" - } - } - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "created", - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>/orderlines/odl_jp31jz", - "type": "application/hal+json" - } - } - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/orders-api/get-order", - "type": "text/html" - } - } - }' - ); - } - - protected function getShipmentResponseFixture($shipment_id, $order_id, $orderline_status = OrderLineStatus::SHIPPING, $tracking_info = '') - { - return str_replace( - [ - '<>', - '<>', - '<>', - '<>', - ], - [ - $order_id, - $shipment_id, - $orderline_status, - $tracking_info, - ], - '{ - "resource": "shipment", - "id": "<>", - "orderId": "<>", - "createdAt": "2018-08-02T09:29:56+00:00", - <> - "lines": [ - { - "resource": "orderline", - "id": "odl_dgtxyl", - "orderId": "<>", - "name": "LEGO 42083 Bugatti Chiron", - "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", - "sku": "5702016116977", - "type": "physical", - "status": "<>", - "quantity": 2, - "unitPrice": { - "value": "399.00", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "121.14", - "currency": "EUR" - }, - "discountAmount": { - "value": "100.00", - "currency": "EUR" - }, - "totalAmount": { - "value": "698.00", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - }, - { - "resource": "orderline", - "id": "odl_jp31jz", - "orderId": "<>", - "name": "LEGO 42056 Porsche 911 GT3 RS", - "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", - "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", - "sku": "5702015594028", - "type": "digital", - "status": "<>", - "quantity": 1, - "unitPrice": { - "value": "329.99", - "currency": "EUR" - }, - "vatRate": "21.00", - "vatAmount": { - "value": "57.27", - "currency": "EUR" - }, - "totalAmount": { - "value": "329.99", - "currency": "EUR" - }, - "createdAt": "2018-08-02T09:29:56+00:00" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/orders/<>/shipments/<>", - "type": "application/hal+json" - }, - "order": { - "href": "https://api.mollie.com/v2/orders/<>", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment", - "type": "text/html" - } - } - }' - ); - } -} diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php index 5890d7927..64c121c90 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php @@ -11,7 +11,7 @@ class SubscriptionEndpointTest extends BaseEndpointTest { - public function testCreateWorks() + public function test_create_works() { $this->mockApiCall( new Request('POST', '/v2/customers/cst_FhQJRw4s2n/subscriptions'), @@ -56,38 +56,38 @@ public function testCreateWorks() /** @var Subscription $subscription */ $subscription = $customer->createSubscription([ - "amount" => [ - "value" => "10.00", - "currency" => "EUR", + 'amount' => [ + 'value' => '10.00', + 'currency' => 'EUR', ], - "interval" => "1 month", - "description" => "Order 1234", + 'interval' => '1 month', + 'description' => 'Order 1234', ]); $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals("subscription", $subscription->resource); - $this->assertEquals("sub_wByQa6efm6", $subscription->id); - $this->assertEquals("test", $subscription->mode); - $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); + $this->assertEquals('subscription', $subscription->resource); + $this->assertEquals('sub_wByQa6efm6', $subscription->id); + $this->assertEquals('test', $subscription->mode); + $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); - $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount); - $this->assertEquals("Order 1234", $subscription->description); + $this->assertEquals((object) ['value' => '10.00', 'currency' => 'EUR'], $subscription->amount); + $this->assertEquals('Order 1234', $subscription->description); $this->assertNull($subscription->method); $this->assertNull($subscription->times); - $this->assertEquals("1 month", $subscription->interval); - $this->assertEquals("2018-04-24", $subscription->startDate); + $this->assertEquals('1 month', $subscription->interval); + $this->assertEquals('2018-04-24', $subscription->startDate); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $subscription->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $subscription->_links->customer); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription', 'type' => 'text/html']; $this->assertEquals($documentationLink, $subscription->_links->documentation); } - public function testGetWorks() + public function test_get_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'), @@ -131,32 +131,32 @@ public function testGetWorks() $customer = $this->getCustomer(); /** @var Subscription $subscription */ - $subscription = $customer->getSubscription("sub_wByQa6efm6"); + $subscription = $customer->getSubscription('sub_wByQa6efm6'); $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals("subscription", $subscription->resource); - $this->assertEquals("sub_wByQa6efm6", $subscription->id); - $this->assertEquals("test", $subscription->mode); - $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); + $this->assertEquals('subscription', $subscription->resource); + $this->assertEquals('sub_wByQa6efm6', $subscription->id); + $this->assertEquals('test', $subscription->mode); + $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); - $this->assertEquals((object)["value" => "10.00", "currency" => "EUR"], $subscription->amount); - $this->assertEquals("Order 1234", $subscription->description); + $this->assertEquals((object) ['value' => '10.00', 'currency' => 'EUR'], $subscription->amount); + $this->assertEquals('Order 1234', $subscription->description); $this->assertNull($subscription->method); $this->assertNull($subscription->times); - $this->assertEquals("1 month", $subscription->interval); - $this->assertEquals("2018-04-24", $subscription->startDate); + $this->assertEquals('1 month', $subscription->interval); + $this->assertEquals('2018-04-24', $subscription->startDate); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $subscription->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $subscription->_links->customer); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription', 'type' => 'text/html']; $this->assertEquals($documentationLink, $subscription->_links->documentation); } - public function testListWorks() + public function test_list_works() { $this->mockApiCall( new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions'), @@ -218,20 +218,20 @@ public function testListWorks() $this->assertEquals(count($subscriptions), $subscriptions->count()); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions', 'type' => 'text/html']; $this->assertEquals($documentationLink, $subscriptions->_links->documentation); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $subscriptions->_links->self); foreach ($subscriptions as $subscription) { $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals("subscription", $subscription->resource); + $this->assertEquals('subscription', $subscription->resource); $this->assertNotEmpty($subscription->createdAt); } } - public function testCancelViaCustomerResourceWorks() + public function test_cancel_via_customer_resource_works() { $this->mockApiCall( new Request('DELETE', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'), @@ -276,28 +276,27 @@ public function testCancelViaCustomerResourceWorks() $customer = $this->getCustomer(); /** @var Subscription $subscription */ - $subscription = $customer->cancelSubscription("sub_wByQa6efm6"); + $subscription = $customer->cancelSubscription('sub_wByQa6efm6'); $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals("subscription", $subscription->resource); - $this->assertEquals("sub_wByQa6efm6", $subscription->id); - $this->assertEquals("test", $subscription->mode); + $this->assertEquals('subscription', $subscription->resource); + $this->assertEquals('sub_wByQa6efm6', $subscription->id); + $this->assertEquals('test', $subscription->mode); $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); - $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); - $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt); - + $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); + $this->assertEquals('2018-04-24T12:31:32+00:00', $subscription->canceledAt); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $subscription->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $subscription->_links->customer); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription', 'type' => 'text/html']; $this->assertEquals($documentationLink, $subscription->_links->documentation); } - public function testCancelOnSubscriptionResourceWorks($value = '') + public function test_cancel_on_subscription_resource_works($value = '') { $this->mockApiCall( new Request('DELETE', '/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx'), @@ -344,25 +343,24 @@ public function testCancelOnSubscriptionResourceWorks($value = '') $subscription = $subscription->cancel(); $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals("subscription", $subscription->resource); - $this->assertEquals("sub_DRjwaT5qHx", $subscription->id); - $this->assertEquals("test", $subscription->mode); + $this->assertEquals('subscription', $subscription->resource); + $this->assertEquals('sub_DRjwaT5qHx', $subscription->id); + $this->assertEquals('test', $subscription->mode); $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); - $this->assertEquals("2018-04-24T11:41:55+00:00", $subscription->createdAt); - $this->assertEquals("2018-04-24T12:31:32+00:00", $subscription->canceledAt); - + $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); + $this->assertEquals('2018-04-24T12:31:32+00:00', $subscription->canceledAt); - $selfLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx", "type" => "application/hal+json"]; + $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx', 'type' => 'application/hal+json']; $this->assertEquals($selfLink, $subscription->_links->self); - $customerLink = (object)["href" => "https://api.mollie.com/v2/customers/cst_VhjQebNW5j", "type" => "application/hal+json"]; + $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_VhjQebNW5j', 'type' => 'application/hal+json']; $this->assertEquals($customerLink, $subscription->_links->customer); - $documentationLink = (object)["href" => "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", "type" => "text/html"]; + $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription', 'type' => 'text/html']; $this->assertEquals($documentationLink, $subscription->_links->documentation); } - public function testThatUpdateSubscriptionWorks() + public function test_that_update_subscription_works() { $expectedAmountValue = '12.00'; $expectedAmountCurrency = 'EUR'; @@ -381,14 +379,14 @@ public function testThatUpdateSubscriptionWorks() "createdAt": "2018-07-17T07:45:52+00:00", "status": "active", "amount": { - "value": "' . $expectedAmountValue . '", - "currency": "' . $expectedAmountCurrency . '" + "value": "'.$expectedAmountValue.'", + "currency": "'.$expectedAmountCurrency.'" }, "description": "Mollie Recurring subscription #1", "method": null, "times": 42, "interval": "15 days", - "startDate": "' . $expectedStartDate . '", + "startDate": "'.$expectedStartDate.'", "webhookUrl": "https://example.org/webhook", "_links": { "self": { @@ -409,7 +407,7 @@ public function testThatUpdateSubscriptionWorks() ); $subscription = $this->getSubscription(); - $expectedAmountObject = (object)[ + $expectedAmountObject = (object) [ 'value' => $expectedAmountValue, 'currency' => $expectedAmountCurrency, ]; @@ -422,7 +420,7 @@ public function testThatUpdateSubscriptionWorks() $this->assertEquals($expectedAmountObject, $updatedSubscription->amount); } - public function testListPageOfRootSubscriptionsWorks() + public function test_list_page_of_root_subscriptions_works() { $this->mockApiCall( new Request('GET', '/v2/subscriptions'), diff --git a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php index 72991f1ae..d3a39c06b 100644 --- a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php @@ -12,7 +12,7 @@ class SubscriptionPaymentEndpointTest extends BaseEndpointTest { /** @test */ - public function testListSubscriptionPayments(): void + public function test_list_subscription_payments(): void { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index 37480592b..0823cf23e 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -13,7 +13,7 @@ class TerminalEndpointTest extends BaseEndpointTest { use LinkObjectTestHelpers; - public function testGetTerminal() + public function test_get_terminal() { $this->mockApiCall( new Request( @@ -74,7 +74,7 @@ public function testGetTerminal() $this->assertLinkObject('https://docs.mollie.com/reference/v2/terminals-api/get-terminal', 'text/html', $terminal->_links->documentation); } - public function testListTerminal() + public function test_list_terminal() { $this->mockApiCall( new Request( @@ -190,7 +190,7 @@ public function testListTerminal() $this->assertNull($terminals->_links->previous); } - public function testIterateTerminal() + public function test_iterate_terminal() { $this->mockApiCall( new Request( diff --git a/tests/Mollie/API/Endpoints/WalletEndpointTest.php b/tests/Mollie/API/Endpoints/WalletEndpointTest.php index ee52bab33..ad14f3b47 100644 --- a/tests/Mollie/API/Endpoints/WalletEndpointTest.php +++ b/tests/Mollie/API/Endpoints/WalletEndpointTest.php @@ -7,7 +7,7 @@ class WalletEndpointTest extends BaseEndpointTest { - public function testRequestApplePayPaymentSession() + public function test_request_apple_pay_payment_session() { $responseBody = '{ "epochTimestamp": 1555507053169, @@ -22,8 +22,8 @@ public function testRequestApplePayPaymentSession() $this->mockApiCall( new Request( - "POST", - "/v2/wallets/applepay/sessions", + 'POST', + '/v2/wallets/applepay/sessions', [], '{ "domain": "pay.mywebshop.com", diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index 6217893d7..a3ac8955c 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -24,7 +24,7 @@ class MollieApiClientTest extends TestCase { - public function testSendReturnsBodyAsObject() + public function test_send_returns_body_as_object() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), @@ -38,7 +38,7 @@ public function testSendReturnsBodyAsObject() ); } - public function testSendCreatesApiExceptionCorrectly() + public function test_send_creates_api_exception_correctly() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); @@ -60,7 +60,7 @@ public function testSendCreatesApiExceptionCorrectly() } } - public function testSendCreatesApiExceptionWithoutFieldAndDocumentationUrl() + public function test_send_creates_api_exception_without_field_and_documentation_url() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); @@ -81,7 +81,7 @@ public function testSendCreatesApiExceptionWithoutFieldAndDocumentationUrl() } } - public function testCanBeSerializedAndUnserialized() + public function test_can_be_serialized_and_unserialized() { $client = new MollieApiClient($this->createMock(Client::class)); @@ -104,7 +104,7 @@ public function testCanBeSerializedAndUnserialized() // no need to assert them all. } - public function testEnablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSupportIt() + public function test_enabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() { $this->expectException(HttpAdapterDoesNotSupportDebuggingException::class); $client = new MollieApiClient(new CurlMollieHttpAdapter); @@ -112,7 +112,7 @@ public function testEnablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSuppor $client->enableDebugging(); } - public function testDisablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSupportIt() + public function test_disabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() { $this->expectException(HttpAdapterDoesNotSupportDebuggingException::class); $client = new MollieApiClient(new CurlMollieHttpAdapter); @@ -126,7 +126,7 @@ public function testDisablingDebuggingThrowsAnExceptionIfHttpAdapterDoesNotSuppo * * @throws ApiException */ - public function testCorrectRequestHeaders() + public function test_correct_request_headers() { $client = new MockClient([ CreatePaymentRequest::class => new MockResponse(200, '{"resource": "payment"}'), @@ -160,7 +160,7 @@ public function testCorrectRequestHeaders() * @throws \Mollie\Api\Exceptions\IncompatiblePlatform * @throws \Mollie\Api\Exceptions\UnrecognizedClientException */ - public function testNoContentTypeWithoutProvidedBody() + public function test_no_content_type_without_provided_body() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(204, ''), @@ -229,7 +229,7 @@ public static function providesMutatingRequests(): array ]; } - public function testIdempotencyKeyIsNotUsedOnGetRequests() + public function test_idempotency_key_is_not_used_on_get_requests() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(204), @@ -242,7 +242,7 @@ public function testIdempotencyKeyIsNotUsedOnGetRequests() $this->assertFalse($response->getPendingRequest()->headers()->has(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); } - public function testIdempotencyKeyResetsAfterEachRequest() + public function test_idempotency_key_resets_after_each_request() { $client = new MockClient([ DynamicDeleteRequest::class => new MockResponse(204), @@ -257,7 +257,7 @@ public function testIdempotencyKeyResetsAfterEachRequest() $this->assertNull($client->getIdempotencyKey()); } - public function testItUsesTheIdempotencyKeyGenerator() + public function test_it_uses_the_idempotency_key_generator() { $client = new MockClient([ DynamicDeleteRequest::class => new MockResponse(204), diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 2aad2f64c..d29993a96 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -4,7 +4,7 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\LazyCollection; -use Mollie\Api\Resources\OrderCollection; +use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; use stdClass; use Tests\Fixtures\MockClient; @@ -17,15 +17,15 @@ class CursorCollectionTest extends TestCase public function can_get_next_collection_result_when_next_link_is_available() { $client = new MockClient([ - DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuS'), + DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'tr_stTC2WHAuS'), ]); - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], $this->arrayToObject([ 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + 'href' => 'https://api.mollie.com/v2/payments?from=tr_stTC2WHAuS', ], ]) ); @@ -34,16 +34,16 @@ public function can_get_next_collection_result_when_next_link_is_available() $nextPage = $collection->next(); - $this->assertEquals('ord_stTC2WHAuS', $nextPage[0]->id); + $this->assertEquals('tr_stTC2WHAuS', $nextPage[0]->id); $this->assertFalse($nextPage->hasNext()); } - public function testWillReturnNullIfNoNextResultIsAvailable() + public function test_will_return_null_if_no_next_result_is_available() { $client = new MockClient; - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], (object) [] @@ -53,18 +53,18 @@ public function testWillReturnNullIfNoNextResultIsAvailable() $this->assertNull($collection->next()); } - public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() + public function test_can_get_previous_collection_result_when_previous_link_is_available() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuS'), ]); - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], $this->arrayToObject([ 'previous' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + 'href' => 'https://api.mollie.com/v2/payments?from=tr_stTC2WHAuS', ], ]) ); @@ -73,16 +73,16 @@ public function testCanGetPreviousCollectionResultWhenPreviousLinkIsAvailable() $previousPage = $collection->previous(); - $this->assertEquals('ord_stTC2WHAuS', $previousPage[0]->id); + $this->assertEquals('tr_stTC2WHAuS', $previousPage[0]->id); $this->assertFalse($previousPage->hasPrevious()); } - public function testWillReturnNullIfNoPreviousResultIsAvailable() + public function test_will_return_null_if_no_previous_result_is_available() { $client = new MockClient; - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], (object) [] @@ -92,11 +92,11 @@ public function testWillReturnNullIfNoPreviousResultIsAvailable() $this->assertNull($collection->previous()); } - public function testAutoPaginatorReturnsLazyCollection() + public function test_auto_paginator_returns_lazy_collection() { $client = new MockClient; - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], (object) [] @@ -105,22 +105,22 @@ public function testAutoPaginatorReturnsLazyCollection() $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); } - public function testAutoPaginatorCanHandleConsecutiveCalls() + public function test_auto_paginator_can_handle_consecutive_calls() { $client = new MockClient([ DynamicGetRequest::class => new SequenceMockResponse( - new MockResponse(200, 'cursor-collection-next', 'ord_stTC2WHAuF'), - new MockResponse(200, 'cursor-collection-next', 'ord_stTC2WHAuS'), - new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuB') + new MockResponse(200, 'cursor-collection-next', 'tr_stTC2WHAuF'), + new MockResponse(200, 'cursor-collection-next', 'tr_stTC2WHAuS'), + new MockResponse(200, 'cursor-collection', 'tr_stTC2WHAuB') ), ]); - $collection = new OrderCollection( + $collection = new PaymentCollection( $client, [], $this->arrayToObject([ 'next' => [ - 'href' => 'https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS', + 'href' => 'https://api.mollie.com/v2/payments?from=tr_stTC2WHAuS', ], ]) ); @@ -130,7 +130,7 @@ public function testAutoPaginatorCanHandleConsecutiveCalls() $orderIds[] = $order->id; } - $this->assertEquals(['ord_stTC2WHAuF', 'ord_stTC2WHAuS', 'ord_stTC2WHAuB'], $orderIds); + $this->assertEquals(['tr_stTC2WHAuF', 'tr_stTC2WHAuS', 'tr_stTC2WHAuB'], $orderIds); } /** diff --git a/tests/Resources/InvoiceTest.php b/tests/Resources/InvoiceTest.php index 711b0f580..63f9f0225 100644 --- a/tests/Resources/InvoiceTest.php +++ b/tests/Resources/InvoiceTest.php @@ -16,7 +16,7 @@ class InvoiceTest extends TestCase * * @dataProvider dpTestInvoiceStatuses */ - public function testInvoiceStatuses($status, $function, $expected_boolean) + public function test_invoice_statuses($status, $function, $expected_boolean) { $invoice = new Invoice($this->createMock(MollieApiClient::class)); $invoice->status = $status; diff --git a/tests/Resources/LazyCollectionTest.php b/tests/Resources/LazyCollectionTest.php index 74164fbcd..c4960049d 100644 --- a/tests/Resources/LazyCollectionTest.php +++ b/tests/Resources/LazyCollectionTest.php @@ -12,7 +12,7 @@ class LazyCollectionTest extends TestCase */ private $collection; - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -23,7 +23,7 @@ public function setUp(): void }); } - public function testCanCreateACollectionFromGeneratorFunction() + public function test_can_create_a_collection_from_generator_function() { $this->assertEquals(3, $this->collection->count()); $this->assertEquals(1, $this->collection->get(0)); @@ -31,7 +31,7 @@ public function testCanCreateACollectionFromGeneratorFunction() $this->assertEquals(3, $this->collection->get(2)); } - public function testFilter() + public function test_filter() { $filtered = $this->collection->filter(function ($value) { return $value > 1; @@ -40,12 +40,12 @@ public function testFilter() $this->assertEquals(2, $filtered->count()); } - public function testAll() + public function test_all() { $this->assertEquals([1, 2, 3], $this->collection->all()); } - public function testFirst() + public function test_first() { $this->assertEquals(1, $this->collection->first()); $this->assertEquals(3, $this->collection->first(function ($value) { @@ -53,7 +53,7 @@ public function testFirst() })); } - public function testMap() + public function test_map() { $mapped = $this->collection->map(function ($value) { return $value * 2; @@ -66,14 +66,14 @@ public function testMap() }); } - public function testTake() + public function test_take() { $taken = $this->collection->take(2); $this->assertEquals(2, $taken->count()); } - public function testEvery() + public function test_every() { $this->assertTrue($this->collection->every(function ($value) { return $value > 0; @@ -84,7 +84,7 @@ public function testEvery() })); } - public function testChainedUsage() + public function test_chained_usage() { $result = $this->collection ->filter(function ($value) { diff --git a/tests/Resources/MandateCollectionTest.php b/tests/Resources/MandateCollectionTest.php index 834d6c9c4..a45a1c2ba 100644 --- a/tests/Resources/MandateCollectionTest.php +++ b/tests/Resources/MandateCollectionTest.php @@ -22,7 +22,7 @@ protected function setUp(): void $this->client = $this->createMock(MollieApiClient::class); } - public function testWhereStatus() + public function test_where_status() { $collection = new MandateCollection($this->client, [ $this->getMandateWithStatus(MandateStatus::VALID), diff --git a/tests/Resources/MethodTest.php b/tests/Resources/MethodTest.php index 337c5c48b..dc277d77c 100644 --- a/tests/Resources/MethodTest.php +++ b/tests/Resources/MethodTest.php @@ -9,7 +9,7 @@ class MethodTest extends TestCase { - public function testIssuersNullWorks() + public function test_issuers_null_works() { $method = new Method($this->createMock(MollieApiClient::class)); $this->assertNull($method->issuers); diff --git a/tests/Resources/OnboardingTest.php b/tests/Resources/OnboardingTest.php index afaaf8210..1de306b81 100644 --- a/tests/Resources/OnboardingTest.php +++ b/tests/Resources/OnboardingTest.php @@ -15,7 +15,7 @@ class OnboardingTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestOnboardingStatuses */ - public function testOnboardingStatuses($status, $function, $expected_boolean) + public function test_onboarding_statuses($status, $function, $expected_boolean) { $orderLine = new Onboarding($this->createMock(MollieApiClient::class)); $orderLine->status = $status; diff --git a/tests/Resources/OrderLineCollectionTest.php b/tests/Resources/OrderLineCollectionTest.php index d52ab3385..c8bd22b90 100644 --- a/tests/Resources/OrderLineCollectionTest.php +++ b/tests/Resources/OrderLineCollectionTest.php @@ -8,7 +8,7 @@ class OrderLineCollectionTest extends \PHPUnit\Framework\TestCase { - public function testCanGetOrderLine() + public function test_can_get_order_line() { $mockApi = $this->createMock(MollieApiClient::class); diff --git a/tests/Resources/OrderLineTest.php b/tests/Resources/OrderLineTest.php deleted file mode 100644 index 75068a984..000000000 --- a/tests/Resources/OrderLineTest.php +++ /dev/null @@ -1,172 +0,0 @@ -createMock(MollieApiClient::class)); - $orderLine->status = $status; - - $this->assertEquals($expected_boolean, $orderLine->{$function}()); - } - - /** - * @param string $type - * @param string $function - * @param bool $expected_boolean - * - * @dataProvider dpTestOrderLineTypes - */ - public function testOrderLineTypes($type, $function, $expected_boolean) - { - $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); - $orderLine->type = $type; - - $this->assertEquals($expected_boolean, $orderLine->{$function}()); - } - - /** - * @param string $vatRate - * @param bool $expected_boolean - * - * @dataProvider dpTestUpdateVatRate - */ - public function testUpdateVatRate($vatRate, $expected_boolean) - { - $orderLine = new OrderLine($this->createMock(MollieApiClient::class)); - $orderLine->vatRate = $vatRate; - - $this->assertEquals(isset($orderLine->getUpdateData()['vatRate']), $expected_boolean); - } - - public function dpTestUpdateVatRate() - { - return [ - [0, true], - ['0', true], - [null, false], - ]; - } - - public function dpTestOrderLineTypes() - { - return [ - [OrderLineType::PHYSICAL, 'isPhysical', true], - [OrderLineType::PHYSICAL, 'isDiscount', false], - [OrderLineType::PHYSICAL, 'isDigital', false], - [OrderLineType::PHYSICAL, 'isShippingFee', false], - [OrderLineType::PHYSICAL, 'isStoreCredit', false], - [OrderLineType::PHYSICAL, 'isGiftCard', false], - [OrderLineType::PHYSICAL, 'isSurcharge', false], - - [OrderLineType::DISCOUNT, 'isPhysical', false], - [OrderLineType::DISCOUNT, 'isDiscount', true], - [OrderLineType::DISCOUNT, 'isDigital', false], - [OrderLineType::DISCOUNT, 'isShippingFee', false], - [OrderLineType::DISCOUNT, 'isStoreCredit', false], - [OrderLineType::DISCOUNT, 'isGiftCard', false], - [OrderLineType::DISCOUNT, 'isSurcharge', false], - - [OrderLineType::DIGITAL, 'isPhysical', false], - [OrderLineType::DIGITAL, 'isDiscount', false], - [OrderLineType::DIGITAL, 'isDigital', true], - [OrderLineType::DIGITAL, 'isShippingFee', false], - [OrderLineType::DIGITAL, 'isStoreCredit', false], - [OrderLineType::DIGITAL, 'isGiftCard', false], - [OrderLineType::DIGITAL, 'isSurcharge', false], - - [OrderLineType::SHIPPING_FEE, 'isPhysical', false], - [OrderLineType::SHIPPING_FEE, 'isDiscount', false], - [OrderLineType::SHIPPING_FEE, 'isDigital', false], - [OrderLineType::SHIPPING_FEE, 'isShippingFee', true], - [OrderLineType::SHIPPING_FEE, 'isStoreCredit', false], - [OrderLineType::SHIPPING_FEE, 'isGiftCard', false], - [OrderLineType::SHIPPING_FEE, 'isSurcharge', false], - - [OrderLineType::STORE_CREDIT, 'isPhysical', false], - [OrderLineType::STORE_CREDIT, 'isDiscount', false], - [OrderLineType::STORE_CREDIT, 'isDigital', false], - [OrderLineType::STORE_CREDIT, 'isShippingFee', false], - [OrderLineType::STORE_CREDIT, 'isStoreCredit', true], - [OrderLineType::STORE_CREDIT, 'isGiftCard', false], - [OrderLineType::STORE_CREDIT, 'isSurcharge', false], - - [OrderLineType::GIFT_CARD, 'isPhysical', false], - [OrderLineType::GIFT_CARD, 'isDiscount', false], - [OrderLineType::GIFT_CARD, 'isDigital', false], - [OrderLineType::GIFT_CARD, 'isShippingFee', false], - [OrderLineType::GIFT_CARD, 'isStoreCredit', false], - [OrderLineType::GIFT_CARD, 'isGiftCard', true], - [OrderLineType::GIFT_CARD, 'isSurcharge', false], - - [OrderLineType::SURCHARGE, 'isPhysical', false], - [OrderLineType::SURCHARGE, 'isDiscount', false], - [OrderLineType::SURCHARGE, 'isDigital', false], - [OrderLineType::SURCHARGE, 'isShippingFee', false], - [OrderLineType::SURCHARGE, 'isStoreCredit', false], - [OrderLineType::SURCHARGE, 'isGiftCard', false], - [OrderLineType::SURCHARGE, 'isSurcharge', true], - ]; - } - - public function dpTestOrderLineStatuses() - { - return [ - [OrderLineStatus::CREATED, 'isCreated', true], - [OrderLineStatus::CREATED, 'isPaid', false], - [OrderLineStatus::CREATED, 'isAuthorized', false], - [OrderLineStatus::CREATED, 'isCanceled', false], - [OrderLineStatus::CREATED, 'isShipping', false], - [OrderLineStatus::CREATED, 'isCompleted', false], - - [OrderLineStatus::PAID, 'isCreated', false], - [OrderLineStatus::PAID, 'isPaid', true], - [OrderLineStatus::PAID, 'isAuthorized', false], - [OrderLineStatus::PAID, 'isCanceled', false], - [OrderLineStatus::PAID, 'isShipping', false], - [OrderLineStatus::PAID, 'isCompleted', false], - - [OrderLineStatus::AUTHORIZED, 'isCreated', false], - [OrderLineStatus::AUTHORIZED, 'isPaid', false], - [OrderLineStatus::AUTHORIZED, 'isAuthorized', true], - [OrderLineStatus::AUTHORIZED, 'isCanceled', false], - [OrderLineStatus::AUTHORIZED, 'isShipping', false], - [OrderLineStatus::AUTHORIZED, 'isCompleted', false], - - [OrderLineStatus::CANCELED, 'isCreated', false], - [OrderLineStatus::CANCELED, 'isPaid', false], - [OrderLineStatus::CANCELED, 'isAuthorized', false], - [OrderLineStatus::CANCELED, 'isCanceled', true], - [OrderLineStatus::CANCELED, 'isShipping', false], - [OrderLineStatus::CANCELED, 'isCompleted', false], - - [OrderLineStatus::SHIPPING, 'isCreated', false], - [OrderLineStatus::SHIPPING, 'isPaid', false], - [OrderLineStatus::SHIPPING, 'isAuthorized', false], - [OrderLineStatus::SHIPPING, 'isCanceled', false], - [OrderLineStatus::SHIPPING, 'isShipping', true], - [OrderLineStatus::SHIPPING, 'isCompleted', false], - - [OrderLineStatus::COMPLETED, 'isCreated', false], - [OrderLineStatus::COMPLETED, 'isPaid', false], - [OrderLineStatus::COMPLETED, 'isAuthorized', false], - [OrderLineStatus::COMPLETED, 'isCanceled', false], - [OrderLineStatus::COMPLETED, 'isShipping', false], - [OrderLineStatus::COMPLETED, 'isCompleted', true], - ]; - } -} diff --git a/tests/Resources/OrderTest.php b/tests/Resources/OrderTest.php deleted file mode 100644 index f4cb81748..000000000 --- a/tests/Resources/OrderTest.php +++ /dev/null @@ -1,293 +0,0 @@ -createMock(MollieApiClient::class)); - $order->status = $status; - - $this->assertEquals($expected_boolean, $order->{$function}()); - } - - public function dpTestOrderStatuses() - { - return [ - [OrderStatus::CREATED, 'isCreated', true], - [OrderStatus::CREATED, 'isPaid', false], - [OrderStatus::CREATED, 'isAuthorized', false], - [OrderStatus::CREATED, 'isCanceled', false], - [OrderStatus::CREATED, 'isShipping', false], - [OrderStatus::CREATED, 'isCompleted', false], - [OrderStatus::CREATED, 'isExpired', false], - [OrderStatus::CREATED, 'isPending', false], - - [OrderStatus::PAID, 'isCreated', false], - [OrderStatus::PAID, 'isPaid', true], - [OrderStatus::PAID, 'isAuthorized', false], - [OrderStatus::PAID, 'isCanceled', false], - [OrderStatus::PAID, 'isShipping', false], - [OrderStatus::PAID, 'isCompleted', false], - [OrderStatus::PAID, 'isExpired', false], - [OrderStatus::PAID, 'isPending', false], - - [OrderStatus::AUTHORIZED, 'isCreated', false], - [OrderStatus::AUTHORIZED, 'isPaid', false], - [OrderStatus::AUTHORIZED, 'isAuthorized', true], - [OrderStatus::AUTHORIZED, 'isCanceled', false], - [OrderStatus::AUTHORIZED, 'isShipping', false], - [OrderStatus::AUTHORIZED, 'isCompleted', false], - [OrderStatus::AUTHORIZED, 'isExpired', false], - [OrderStatus::AUTHORIZED, 'isPending', false], - - [OrderStatus::CANCELED, 'isCreated', false], - [OrderStatus::CANCELED, 'isPaid', false], - [OrderStatus::CANCELED, 'isAuthorized', false], - [OrderStatus::CANCELED, 'isCanceled', true], - [OrderStatus::CANCELED, 'isShipping', false], - [OrderStatus::CANCELED, 'isCompleted', false], - [OrderStatus::CANCELED, 'isExpired', false], - [OrderStatus::CANCELED, 'isPending', false], - - [OrderStatus::SHIPPING, 'isCreated', false], - [OrderStatus::SHIPPING, 'isPaid', false], - [OrderStatus::SHIPPING, 'isAuthorized', false], - [OrderStatus::SHIPPING, 'isCanceled', false], - [OrderStatus::SHIPPING, 'isShipping', true], - [OrderStatus::SHIPPING, 'isCompleted', false], - [OrderStatus::SHIPPING, 'isExpired', false], - [OrderStatus::SHIPPING, 'isPending', false], - - [OrderStatus::COMPLETED, 'isCreated', false], - [OrderStatus::COMPLETED, 'isPaid', false], - [OrderStatus::COMPLETED, 'isAuthorized', false], - [OrderStatus::COMPLETED, 'isCanceled', false], - [OrderStatus::COMPLETED, 'isShipping', false], - [OrderStatus::COMPLETED, 'isCompleted', true], - [OrderStatus::COMPLETED, 'isExpired', false], - [OrderStatus::COMPLETED, 'isPending', false], - - [OrderStatus::EXPIRED, 'isCreated', false], - [OrderStatus::EXPIRED, 'isPaid', false], - [OrderStatus::EXPIRED, 'isAuthorized', false], - [OrderStatus::EXPIRED, 'isCanceled', false], - [OrderStatus::EXPIRED, 'isShipping', false], - [OrderStatus::EXPIRED, 'isCompleted', false], - [OrderStatus::EXPIRED, 'isExpired', true], - [OrderStatus::EXPIRED, 'isPending', false], - - [OrderStatus::PENDING, 'isCreated', false], - [OrderStatus::PENDING, 'isPaid', false], - [OrderStatus::PENDING, 'isAuthorized', false], - [OrderStatus::PENDING, 'isCanceled', false], - [OrderStatus::PENDING, 'isShipping', false], - [OrderStatus::PENDING, 'isCompleted', false], - [OrderStatus::PENDING, 'isExpired', false], - [OrderStatus::PENDING, 'isPending', true], - ]; - } - - public function testCanGetLinesAsResourcesOnOrderResource() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $orderLine = new stdClass; - $lineArray = [ - 'resource' => 'orderline', - 'id' => 'odl_dgtxyl', - 'orderId' => 'ord_pbjz8x', - 'type' => 'physical', - 'name' => 'LEGO 42083 Bugatti Chiron', - 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', - 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - 'sku' => '5702016116977', - 'status' => 'created', - 'quantity' => 2, - 'unitPrice' => (object) [ - 'value' => '399.00', - 'currency' => 'EUR', - ], - 'vatRate' => '21.00', - 'vatAmount' => (object) [ - 'value' => '121.14', - 'currency' => 'EUR', - ], - 'discountAmount' => (object) [ - 'value' => '100.00', - 'currency' => 'EUR', - ], - 'totalAmount' => (object) [ - 'value' => '698.00', - 'currency' => 'EUR', - ], - 'createdAt' => '2018-08-02T09:29:56+00:00', - ]; - - foreach ($lineArray as $key => $value) { - $orderLine->{$key} = $value; - } - - $order->lines = [$orderLine]; - - $lines = $order->lines(); - - $this->assertInstanceOf(OrderLineCollection::class, $lines); - $this->assertCount(1, $lines); - - $line = $lines[0]; - - $this->assertInstanceOf(OrderLine::class, $line); - - $this->assertEquals('orderline', $line->resource); - $this->assertEquals('odl_dgtxyl', $line->id); - $this->assertEquals('ord_pbjz8x', $line->orderId); - $this->assertEquals('LEGO 42083 Bugatti Chiron', $line->name); - $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line->productUrl); - $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); - $this->assertEquals('5702016116977', $line->sku); - $this->assertEquals(OrderLineType::PHYSICAL, $line->type); - $this->assertEquals(OrderLineStatus::CREATED, $line->status); - $this->assertEquals(2, $line->quantity); - $this->assertAmountObject('399.00', 'EUR', $line->unitPrice); - $this->assertEquals('21.00', $line->vatRate); - $this->assertAmountObject('121.14', 'EUR', $line->vatAmount); - $this->assertAmountObject('100.00', 'EUR', $line->discountAmount); - $this->assertAmountObject('698.00', 'EUR', $line->totalAmount); - $this->assertEquals('2018-08-02T09:29:56+00:00', $line->createdAt); - } - - public function testCanGetPaymentsAsResourcesOnOrderResource() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $orderLine = new stdClass; - $lineArray = [ - 'resource' => 'orderline', - 'id' => 'odl_dgtxyl', - 'orderId' => 'ord_pbjz8x', - 'type' => 'physical', - 'name' => 'LEGO 42083 Bugatti Chiron', - 'productUrl' => 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', - 'imageUrl' => 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', - 'sku' => '5702016116977', - 'status' => 'created', - 'quantity' => 2, - 'unitPrice' => (object) [ - 'value' => '399.00', - 'currency' => 'EUR', - ], - 'vatRate' => '21.00', - 'vatAmount' => (object) [ - 'value' => '121.14', - 'currency' => 'EUR', - ], - 'discountAmount' => (object) [ - 'value' => '100.00', - 'currency' => 'EUR', - ], - 'totalAmount' => (object) [ - 'value' => '698.00', - 'currency' => 'EUR', - ], - 'createdAt' => '2018-08-02T09:29:56+00:00', - ]; - - foreach ($lineArray as $key => $value) { - $orderLine->{$key} = $value; - } - - $order->lines = [$orderLine]; - - $lines = $order->lines(); - - $this->assertInstanceOf(OrderLineCollection::class, $lines); - $this->assertCount(1, $lines); - - $line = $lines[0]; - - $this->assertInstanceOf(OrderLine::class, $line); - - $this->assertEquals('orderline', $line->resource); - $this->assertEquals('odl_dgtxyl', $line->id); - $this->assertEquals('ord_pbjz8x', $line->orderId); - $this->assertEquals('LEGO 42083 Bugatti Chiron', $line->name); - $this->assertEquals('https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', $line->productUrl); - $this->assertEquals('https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', $line->imageUrl); - $this->assertEquals('5702016116977', $line->sku); - $this->assertEquals(OrderLineType::PHYSICAL, $line->type); - $this->assertEquals(OrderLineStatus::CREATED, $line->status); - $this->assertEquals(2, $line->quantity); - $this->assertAmountObject('399.00', 'EUR', $line->unitPrice); - $this->assertEquals('21.00', $line->vatRate); - $this->assertAmountObject('121.14', 'EUR', $line->vatAmount); - $this->assertAmountObject('100.00', 'EUR', $line->discountAmount); - $this->assertAmountObject('698.00', 'EUR', $line->totalAmount); - $this->assertEquals('2018-08-02T09:29:56+00:00', $line->createdAt); - } - - public function testGetCheckoutUrlWorks() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $order->_links = $this->getOrderLinksDummy([ - 'checkout' => (object) [ - 'href' => 'https://www.some-mollie-checkout-url.com/123', - 'type' => 'text/html', - ], - ]); - - $this->assertEquals( - 'https://www.some-mollie-checkout-url.com/123', - $order->getCheckoutUrl() - ); - } - - public function testGetCheckoutUrlReturnsNullIfNoCheckoutUrlAvailable() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $order->_links = $this->getOrderLinksDummy(['checkout' => null]); - - $this->assertNull($order->getCheckoutUrl()); - } - - public function testPaymentsHelperReturnsIfNoEmbedAvailable() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $this->assertNull($order->payments()); - } - - public function testPaymentsHelperReturnsIfNoPaymentsEmbedded() - { - $order = new Order($this->createMock(MollieApiClient::class)); - $order->_embedded = null; - $this->assertNull($order->payments()); - } - - protected function getOrderLinksDummy($overrides = []) - { - return (object) array_merge( - [], - $overrides - ); - } -} diff --git a/tests/Resources/PaymentTest.php b/tests/Resources/PaymentTest.php index 2b1fbc33f..b3a339556 100644 --- a/tests/Resources/PaymentTest.php +++ b/tests/Resources/PaymentTest.php @@ -17,7 +17,7 @@ class PaymentTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestPaymentStatuses */ - public function testPaymentStatuses($status, $function, $expected_boolean) + public function test_payment_statuses($status, $function, $expected_boolean) { $payment = new Payment($this->createMock(MollieApiClient::class)); $payment->status = $status; @@ -78,7 +78,7 @@ public function dpTestPaymentStatuses() ]; } - public function testIsPaidReturnsTrueWhenPaidDatetimeIsSet() + public function test_is_paid_returns_true_when_paid_datetime_is_set() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -86,7 +86,7 @@ public function testIsPaidReturnsTrueWhenPaidDatetimeIsSet() $this->assertTrue($payment->isPaid()); } - public function testHasRefundsReturnsTrueWhenPaymentHasRefunds() + public function test_has_refunds_returns_true_when_payment_has_refunds() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -96,7 +96,7 @@ public function testHasRefundsReturnsTrueWhenPaymentHasRefunds() $this->assertTrue($payment->hasRefunds()); } - public function testHasRefundsReturnsFalseWhenPaymentHasNoRefunds() + public function test_has_refunds_returns_false_when_payment_has_no_refunds() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -104,7 +104,7 @@ public function testHasRefundsReturnsFalseWhenPaymentHasNoRefunds() $this->assertFalse($payment->hasRefunds()); } - public function testHasChargebacksReturnsTrueWhenPaymentHasChargebacks() + public function test_has_chargebacks_returns_true_when_payment_has_chargebacks() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -114,7 +114,7 @@ public function testHasChargebacksReturnsTrueWhenPaymentHasChargebacks() $this->assertTrue($payment->hasChargebacks()); } - public function testHasChargebacksReturnsFalseWhenPaymentHasNoChargebacks() + public function test_has_chargebacks_returns_false_when_payment_has_no_chargebacks() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -122,7 +122,7 @@ public function testHasChargebacksReturnsFalseWhenPaymentHasNoChargebacks() $this->assertFalse($payment->hasChargebacks()); } - public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsFirst() + public function test_has_recurring_type_returns_true_when_recurring_type_is_first() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -131,7 +131,7 @@ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsFirst() $this->assertTrue($payment->hasSequenceTypeFirst()); } - public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsRecurring() + public function test_has_recurring_type_returns_true_when_recurring_type_is_recurring() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -140,7 +140,7 @@ public function testHasRecurringTypeReturnsTrueWhenRecurringTypeIsRecurring() $this->assertFalse($payment->hasSequenceTypeFirst()); } - public function testHasRecurringTypeReturnsFalseWhenRecurringTypeIsNone() + public function test_has_recurring_type_returns_false_when_recurring_type_is_none() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -149,7 +149,7 @@ public function testHasRecurringTypeReturnsFalseWhenRecurringTypeIsNone() $this->assertFalse($payment->hasSequenceTypeRecurring()); } - public function testGetCheckoutUrlReturnsPaymentUrlFromLinksObject() + public function test_get_checkout_url_returns_payment_url_from_links_object() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -160,7 +160,7 @@ public function testGetCheckoutUrlReturnsPaymentUrlFromLinksObject() $this->assertSame($payment->getCheckoutUrl(), 'https://example.com'); } - public function testGetMobileAppCheckoutUrlReturnsPaymentUrlFromLinksObject() + public function test_get_mobile_app_checkout_url_returns_payment_url_from_links_object() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -171,7 +171,7 @@ public function testGetMobileAppCheckoutUrlReturnsPaymentUrlFromLinksObject() $this->assertSame($payment->getMobileAppCheckoutUrl(), 'https://example-mobile-checkout.com'); } - public function testCanBeRefundedReturnsTrueWhenAmountRemainingIsSet() + public function test_can_be_refunded_returns_true_when_amount_remaining_is_set() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -184,7 +184,7 @@ public function testCanBeRefundedReturnsTrueWhenAmountRemainingIsSet() $this->assertTrue($payment->canBePartiallyRefunded()); } - public function testCanBeRefundedReturnsFalseWhenAmountRemainingIsNull() + public function test_can_be_refunded_returns_false_when_amount_remaining_is_null() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -193,7 +193,7 @@ public function testCanBeRefundedReturnsFalseWhenAmountRemainingIsNull() $this->assertFalse($payment->canBePartiallyRefunded()); } - public function testGetAmountRefundedReturnsAmountRefundedAsFloat() + public function test_get_amount_refunded_returns_amount_refunded_as_float() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -201,7 +201,7 @@ public function testGetAmountRefundedReturnsAmountRefundedAsFloat() self::assertSame(22.0, $payment->getAmountRefunded()); } - public function testGetAmountRefundedReturns0WhenAmountRefundedIsSetToNull() + public function test_get_amount_refunded_returns0_when_amount_refunded_is_set_to_null() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -209,7 +209,7 @@ public function testGetAmountRefundedReturns0WhenAmountRefundedIsSetToNull() self::assertSame(0.0, $payment->getAmountRefunded()); } - public function testGetAmountRemainingReturnsAmountRemainingAsFloat() + public function test_get_amount_remaining_returns_amount_remaining_as_float() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -217,7 +217,7 @@ public function testGetAmountRemainingReturnsAmountRemainingAsFloat() self::assertSame(22.0, $payment->getAmountRemaining()); } - public function testGetAmountRemainingReturns0WhenAmountRemainingIsSetToNull() + public function test_get_amount_remaining_returns0_when_amount_remaining_is_set_to_null() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -225,7 +225,7 @@ public function testGetAmountRemainingReturns0WhenAmountRemainingIsSetToNull() self::assertSame(0.0, $payment->getAmountRemaining()); } - public function testGetAmountChargedBackReturnsAmountChargedBackAsFloat() + public function test_get_amount_charged_back_returns_amount_charged_back_as_float() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -233,7 +233,7 @@ public function testGetAmountChargedBackReturnsAmountChargedBackAsFloat() self::assertSame(22.0, $payment->getAmountChargedBack()); } - public function testGetAmountChargedBackReturns0WhenAmountChargedBackIsSetToNull() + public function test_get_amount_charged_back_returns0_when_amount_charged_back_is_set_to_null() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -241,7 +241,7 @@ public function testGetAmountChargedBackReturns0WhenAmountChargedBackIsSetToNull self::assertSame(0.0, $payment->getAmountChargedBack()); } - public function testGetSettlementAmountReturns0WhenSettlementAmountIsSetToNull() + public function test_get_settlement_amount_returns0_when_settlement_amount_is_set_to_null() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -249,7 +249,7 @@ public function testGetSettlementAmountReturns0WhenSettlementAmountIsSetToNull() self::assertSame(0.0, $payment->getSettlementAmount()); } - public function testGetSettlementAmountReturnsSettlementAmountAsFloat() + public function test_get_settlement_amount_returns_settlement_amount_as_float() { $payment = new Payment($this->createMock(MollieApiClient::class)); @@ -257,7 +257,7 @@ public function testGetSettlementAmountReturnsSettlementAmountAsFloat() self::assertSame(22.0, $payment->getSettlementAmount()); } - public function testHasSplitPaymentsReturnsFalseWhenPaymentHasNoSplit() + public function test_has_split_payments_returns_false_when_payment_has_no_split() { $payment = new Payment($this->createMock(MollieApiClient::class)); diff --git a/tests/Resources/ProfileTest.php b/tests/Resources/ProfileTest.php index eef7a3d9b..9bbe48af3 100644 --- a/tests/Resources/ProfileTest.php +++ b/tests/Resources/ProfileTest.php @@ -15,7 +15,7 @@ class ProfileTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestProfileStatusses */ - public function testProfileStatusses($status, $function, $expected_boolean) + public function test_profile_statusses($status, $function, $expected_boolean) { $profile = new Profile($this->createMock(MollieApiClient::class)); $profile->status = $status; diff --git a/tests/Resources/RefundTest.php b/tests/Resources/RefundTest.php index d8ecfc828..2b9f31e85 100644 --- a/tests/Resources/RefundTest.php +++ b/tests/Resources/RefundTest.php @@ -15,7 +15,7 @@ class RefundTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestRefundStatuses */ - public function testRefundStatuses($status, $function, $expected_boolean) + public function test_refund_statuses($status, $function, $expected_boolean) { $refund = new Refund($this->createMock(MollieApiClient::class)); $refund->status = $status; @@ -29,7 +29,7 @@ public function testRefundStatuses($status, $function, $expected_boolean) * * @dataProvider dpTestRefundCanBeCanceled */ - public function testRefundCanBeCanceled($status, $expected_boolean) + public function test_refund_can_be_canceled($status, $expected_boolean) { $refund = new Refund($this->createMock(MollieApiClient::class)); $refund->status = $status; diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index bb1e84eaf..4506f97dc 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -12,7 +12,7 @@ class ResourceFactoryTest extends TestCase { - public function testCreateFromApiResponseWorks() + public function test_create_from_api_response_works() { $apiResult = json_decode('{ "resource":"payment", @@ -35,7 +35,7 @@ public function testCreateFromApiResponseWorks() $this->assertEquals((object) ['value' => '20.00', 'currency' => 'EUR'], $payment->amount); } - public function testEmbeddedCollectionsAreTypeCasted() + public function test_embedded_collections_are_type_casted() { $apiResult = json_decode('{ "resource":"payment", @@ -73,7 +73,7 @@ public function testEmbeddedCollectionsAreTypeCasted() } /** @test */ - public function testEmbeddedResourcesAreTypeCasted() + public function test_embedded_resources_are_type_casted() { $apiResult = json_decode('{ "resource": "client", diff --git a/tests/Resources/SettlementTest.php b/tests/Resources/SettlementTest.php index c8b626896..b99197ac9 100644 --- a/tests/Resources/SettlementTest.php +++ b/tests/Resources/SettlementTest.php @@ -15,7 +15,7 @@ class SettlementTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestSettlementStatuses */ - public function testSettlementStatuses($status, $function, $expected_boolean) + public function test_settlement_statuses($status, $function, $expected_boolean) { $settlement = new Settlement($this->createMock(MollieApiClient::class)); $settlement->status = $status; diff --git a/tests/Resources/ShipmentTest.php b/tests/Resources/ShipmentTest.php index 4c8b98841..7a3a9f9dd 100644 --- a/tests/Resources/ShipmentTest.php +++ b/tests/Resources/ShipmentTest.php @@ -8,28 +8,28 @@ class ShipmentTest extends TestCase { - public function testHasTrackingReturnsTrueIfObjectNotNull() + public function test_has_tracking_returns_true_if_object_not_null() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = $this->getTrackingDummy(); $this->assertTrue($shipment->hasTracking()); } - public function testHasTrackingReturnsFalseIfObjectIsNull() + public function test_has_tracking_returns_false_if_object_is_null() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = null; $this->assertFalse($shipment->hasTracking()); } - public function testHasTrackingUrlReturnsFalseIfTrackingIsNotSet() + public function test_has_tracking_url_returns_false_if_tracking_is_not_set() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = null; $this->assertFalse($shipment->hasTrackingUrl()); } - public function testHasTrackingUrlReturnsTrueIfUrlIsSet() + public function test_has_tracking_url_returns_true_if_url_is_set() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = $this->getTrackingDummy([ @@ -38,7 +38,7 @@ public function testHasTrackingUrlReturnsTrueIfUrlIsSet() $this->assertTrue($shipment->hasTrackingUrl()); } - public function testHasTrackingUrlReturnsFalseIfUrlIsNotSet() + public function test_has_tracking_url_returns_false_if_url_is_not_set() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = $this->getTrackingDummy([ @@ -47,7 +47,7 @@ public function testHasTrackingUrlReturnsFalseIfUrlIsNotSet() $this->assertFalse($shipment->hasTrackingUrl()); } - public function testGetTrackingUrlReturnsNullIfNotAvailable() + public function test_get_tracking_url_returns_null_if_not_available() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); @@ -60,7 +60,7 @@ public function testGetTrackingUrlReturnsNullIfNotAvailable() $this->assertNull($shipment->getTrackingUrl()); } - public function testGetTrackingUrlReturnsUrlIfAvailable() + public function test_get_tracking_url_returns_url_if_available() { $shipment = new Shipment($this->createMock(MollieApiClient::class)); $shipment->tracking = $this->getTrackingDummy([ diff --git a/tests/Resources/SubscriptionTest.php b/tests/Resources/SubscriptionTest.php index ef068251a..afa1b0c6b 100644 --- a/tests/Resources/SubscriptionTest.php +++ b/tests/Resources/SubscriptionTest.php @@ -15,7 +15,7 @@ class SubscriptionTest extends \PHPUnit\Framework\TestCase * * @dataProvider dpTestSubscriptionStatuses */ - public function testSubscriptionStatuses($status, $function, $expected_boolean) + public function test_subscription_statuses($status, $function, $expected_boolean) { $subscription = new Subscription($this->createMock(MollieApiClient::class)); $subscription->status = $status; diff --git a/tests/Rules/IdTest.php b/tests/Rules/IdTest.php deleted file mode 100644 index d2a917f14..000000000 --- a/tests/Rules/IdTest.php +++ /dev/null @@ -1,76 +0,0 @@ -assertInstanceOf(Id::class, $rule); - } - - /** @test */ - public function validate_throws_exception_if_not_instance_of_request() - { - $rule = new Id('ord_'); - - $nonRequestContext = new \stdClass; // Generic object to simulate incorrect context - - $rule->validate('ord_12345', $nonRequestContext, function ($message) { - $this->assertEquals('The Id rule can only be used on a Request instance.', $message); - }); - } - - /** @test */ - public function validate_throws_exception_if_id_does_not_start_with_prefix() - { - $rule = new Id('ord_'); - $request = new TestRequest; - - $rule->validate('inv_12345', $request, function ($message) { - $this->assertEquals("Invalid order ID: 'inv_12345'. A resource ID should start with 'ord_'.", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_if_id_starts_with_prefix() - { - $rule = new Id('ord_'); - $request = new TestRequest; - - $rule->validate('ord_12345', $request, function () { - $this->fail('Callback should not be invoked for a valid ID.'); - }); - - $this->assertTrue(true); // If no exception is thrown, the test passes - } - - /** @test */ - public function get_resource_type_returns_lowercase_class_basename() - { - $rule = new Id('ord_'); - $request = new TestRequest; - - $resourceType = $rule->getResourceType($request); - - $this->assertEquals('order', $resourceType); - } -} - -class TestRequest extends Request -{ - public static string $targetResourceClass = 'Order'; - - public function resolveResourcePath(): string - { - return 'test'; - } -} diff --git a/tests/Rules/IncludedTest.php b/tests/Rules/IncludedTest.php deleted file mode 100644 index fe3091580..000000000 --- a/tests/Rules/IncludedTest.php +++ /dev/null @@ -1,63 +0,0 @@ - 'value1', - 'VALUE2' => 'value2', - ]; - - $this->assertInstanceOf(Included::class, $rule); - $this->assertEquals($expectedAllowedValues, (new ReflectionClass(SampleClass::class))->getConstants()); - } - - /** @test */ - public function validate_invokes_callback_when_value_not_included() - { - $allowed = ['value1', 'value2']; - $rule = new Included($allowed); - - $rule->validate('invalid_value', null, function ($message) use ($allowed) { - $this->assertEquals("Invalid include: 'invalid_value'. Allowed are: ".implode(', ', $allowed).'.', $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_when_value_is_included() - { - $allowed = ['value1', 'value2']; - $rule = new Included($allowed); - - $rule->validate('value1', null, function () { - $this->fail('Callback should not be invoked for a valid value.'); - }); - - $rule->validate('value2', null, function () { - $this->fail('Callback should not be invoked for a valid value.'); - }); - - $rule->validate('value1,value2', null, function () { - $this->fail('Callback should not be invoked for a valid value.'); - }); - - $this->assertTrue(true); - } -} - -class SampleClass -{ - const VALUE1 = 'value1'; - - const VALUE2 = 'value2'; -} diff --git a/tests/Rules/MatchesTest.php b/tests/Rules/MatchesTest.php deleted file mode 100644 index 8c7915fd5..000000000 --- a/tests/Rules/MatchesTest.php +++ /dev/null @@ -1,42 +0,0 @@ -assertInstanceOf(Matches::class, $rule); - } - - /** @test */ - public function validate_invokes_callback_on_non_matching_value() - { - $pattern = '/^test$/'; - $rule = new Matches($pattern); - - $rule->validate('nonmatching', null, function ($message) use ($pattern) { - $this->assertEquals("The value nonmatching does not match the pattern: {$pattern}", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_on_matching_value() - { - $pattern = '/^test$/'; - $rule = new Matches($pattern); - - $rule->validate('test', null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $this->assertTrue(true); - } -} diff --git a/tests/Rules/MaxTest.php b/tests/Rules/MaxTest.php deleted file mode 100644 index 140fbd7f4..000000000 --- a/tests/Rules/MaxTest.php +++ /dev/null @@ -1,86 +0,0 @@ -assertInstanceOf(Max::class, $rule); - } - - /** @test */ - public function validate_invokes_callback_when_numeric_value_exceeds_max() - { - $max = 100; - $rule = new Max($max); - - $rule->validate(150, null, function ($message) use ($max) { - $this->assertEquals("The value must not exceed {$max}.", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_when_numeric_value_is_equal_to_or_less_than_max() - { - $max = 100; - $rule = new Max($max); - - // If no exception or callback is triggered, the test passes - $rule->validate(100, null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $rule->validate(50, null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $this->assertTrue(true); - } - - /** @test */ - public function validate_invokes_callback_when_string_length_exceeds_max() - { - $max = 5; - $rule = new Max($max); - - $rule->validate('exceeds', null, function ($message) use ($max) { - $this->assertEquals("The value must not exceed {$max}.", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_when_string_length_is_equal_to_or_less_than_max() - { - $max = 5; - $rule = new Max($max); - - $rule->validate('valid', null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $rule->validate('tiny', null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $this->assertTrue(true); - } - - /** @test */ - public function validate_invokes_callback_when_string_value_exceeds_max() - { - $max = 7; - $rule = new Max($max); - - $rule->validate('DE123124', null, function ($message) use ($max) { - $this->assertEquals("The value must not exceed {$max}.", $message); - }); - } -} diff --git a/tests/Rules/MinTest.php b/tests/Rules/MinTest.php deleted file mode 100644 index 42a4f1968..000000000 --- a/tests/Rules/MinTest.php +++ /dev/null @@ -1,74 +0,0 @@ -assertInstanceOf(Min::class, $rule); - } - - /** @test */ - public function validate_invokes_callback_when_numeric_value_is_less_than_min() - { - $min = 10; - $rule = new Min($min); - - $rule->validate(5, null, function ($message) use ($min) { - $this->assertEquals("The value must be at least {$min}.", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_when_numeric_value_is_equal_to_or_greater_than_min() - { - $min = 10; - $rule = new Min($min); - - $rule->validate(10, null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $rule->validate(15, null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $this->assertTrue(true); - } - - /** @test */ - public function validate_invokes_callback_when_string_length_is_less_than_min() - { - $min = 5; - $rule = new Min($min); - - $rule->validate('tiny', null, function ($message) use ($min) { - $this->assertEquals("The value must be at least {$min}.", $message); - }); - } - - /** @test */ - public function validate_does_not_invoke_callback_when_string_length_is_equal_to_or_greater_than_min() - { - $min = 5; - $rule = new Min($min); - - $rule->validate('valid', null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $rule->validate('longer', null, function () { - $this->fail('Callback should not be invoked.'); - }); - - $this->assertTrue(true); - } -} diff --git a/tests/Types/MandateMethodTest.php b/tests/Types/MandateMethodTest.php index fe09c26c0..16dd53f46 100644 --- a/tests/Types/MandateMethodTest.php +++ b/tests/Types/MandateMethodTest.php @@ -14,7 +14,7 @@ class MandateMethodTest extends TestCase * * @dataProvider dpTestGetForFirstPaymentMethod */ - public function testGetForFirstPaymentMethod($firstPaymentMethod, $expectedMethod) + public function test_get_for_first_payment_method($firstPaymentMethod, $expectedMethod) { $actualMethod = MandateMethod::getForFirstPaymentMethod($firstPaymentMethod); $this->assertEquals($expectedMethod, $actualMethod); From f2f9fcfd1bdac1fcf389b574eff63ad9638f5f3c Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 26 Nov 2024 20:41:47 +0100 Subject: [PATCH 066/131] wip --- examples/captures/create-capture.php | 1 + examples/captures/get-capture.php | 1 + examples/captures/list-captures.php | 1 + examples/client-links/create-client-link.php | 1 + .../create-customer-first-payment.php | 1 + .../customers/create-customer-payment.php | 1 + .../create-customer-recurring-payment.php | 1 + examples/customers/create-customer.php | 1 + examples/customers/delete-customer.php | 1 + examples/customers/list-customer-payments.php | 1 + examples/customers/update-customer.php | 1 + examples/functions.php | 1 + examples/initialize.php | 1 + examples/invoices/list-invoices.php | 1 + examples/mandates/create-mandate.php | 1 + examples/mandates/list-mandates.php | 1 + examples/mandates/revoke-mandate.php | 1 + examples/pagination/backwards.php | 1 + examples/pagination/basic_usage.php | 1 + .../payment-links/create-payment-link.php | 1 + examples/payment-links/list-payment-links.php | 1 + .../payments/create-capturable-payment.php | 1 + examples/payments/create-ideal-payment.php | 1 + examples/payments/create-payment-oauth.php | 1 + examples/payments/create-payment.php | 1 + ...outed-payment-with-future-release-date.php | 1 + examples/payments/create-routed-payment.php | 1 + examples/payments/list-methods.php | 1 + examples/payments/list-payments.php | 1 + examples/payments/refund-payment.php | 1 + examples/payments/return.php | 1 + examples/payments/update-payment.php | 1 + examples/payments/webhook.php | 1 + examples/profiles/create-profile.php | 1 + examples/profiles/delete-profile.php | 1 + examples/profiles/list-profiles.php | 1 + examples/profiles/update-profile.php | 1 + examples/sessions/cancel-session.php | 1 + examples/sessions/create-session.php | 1 + examples/sessions/list-sessions.php | 1 + examples/sessions/update-session.php | 1 + examples/settlements/list-settlements.php | 1 + .../subscriptions/cancel-subscription.php | 1 + .../subscriptions/create-subscription.php | 1 + .../subscriptions/update-subscription.php | 1 + .../SingleResourceEndpointContract.php | 5 - .../CustomerEndpointCollection.php | 2 +- .../CustomerPaymentsEndpointCollection.php | 30 +++-- .../MandateEndpointCollection.php | 12 +- .../PaymentChargebackEndpointCollection.php | 2 +- .../PaymentRefundEndpointCollection.php | 4 +- .../ProfileEndpointCollection.php | 1 + .../SubscriptionPaymentEndpointCollection.php | 2 + src/Endpoints/RestEndpoint.php | 126 ------------------ src/Helpers.php | 1 - src/Http/Adapter/GuzzleMollieHttpAdapter.php | 4 +- src/Http/Adapter/PSR18MollieHttpAdapter.php | 4 +- src/Http/Middleware/Hydrate.php | 2 +- .../PendingRequest/AuthenticateRequest.php | 2 - src/Http/Request.php | 2 +- src/Http/Requests/CancelPaymentRequest.php | 2 +- .../Requests/CancelSubscriptionRequest.php | 2 +- .../Requests/CreateCustomerPaymentRequest.php | 36 ++--- src/Http/Requests/CreatePaymentRequest.php | 2 +- .../Requests/DeletePaymentLinkRequest.php | 2 +- .../GetAllPaginatedSubscriptionsRequest.php | 2 +- ...GetPaginatedPaymentLinkPaymentsRequest.php | 2 +- .../GetPaginatedPaymentLinksRequest.php | 2 +- .../GetPaginatedPaymentRefundsRequest.php | 4 +- ...etPaginatedSubscriptionPaymentsRequest.php | 2 +- .../GetPaginatedSubscriptionsRequest.php | 2 +- .../Requests/GetPaginatedTerminalsRequest.php | 2 +- src/Http/Requests/GetPaymentLinkRequest.php | 2 +- src/Http/Requests/GetSubscriptionRequest.php | 2 +- src/Http/Requests/GetTerminalRequest.php | 2 +- .../Requests/ResourceHydratableRequest.php | 2 +- .../Requests/UpdatePaymentLinkRequest.php | 2 +- src/Http/Response.php | 1 - src/MollieApiClient.php | 108 +++++++-------- src/Resources/Balance.php | 4 + src/Resources/BalanceTransaction.php | 4 + src/Resources/BaseResource.php | 2 + src/Resources/Capture.php | 4 + src/Resources/CursorCollection.php | 3 - src/Resources/Customer.php | 32 +++-- src/Resources/HasPresetOptions.php | 31 ----- src/Resources/Payment.php | 53 +++++--- src/Resources/Refund.php | 5 +- src/Resources/Session.php | 9 +- src/Traits/HasMode.php | 19 +++ src/Traits/InteractsWithResource.php | 20 --- ...Debuggable.php => IsDebuggableAdapter.php} | 2 +- src/Traits/ResolvesUri.php | 44 ------ 93 files changed, 253 insertions(+), 402 deletions(-) delete mode 100644 src/Contracts/SingleResourceEndpointContract.php delete mode 100644 src/Endpoints/RestEndpoint.php delete mode 100644 src/Resources/HasPresetOptions.php create mode 100644 src/Traits/HasMode.php delete mode 100644 src/Traits/InteractsWithResource.php rename src/Traits/{IsDebuggable.php => IsDebuggableAdapter.php} (97%) delete mode 100644 src/Traits/ResolvesUri.php diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index ba2643663..2ccc3a5af 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -1,4 +1,5 @@ createForId($customer->id, $payload, $testmode); + return $this->createForId($customer->id, $payload, $query, $testmode); } /** * Create a subscription for a Customer ID * * @param string $customerId - * @param array| $payload + * @param array|CreatePaymentPayload $payload + * @param array|CreatePaymentQuery $query * * @throws ApiException */ - public function createForId($customerId, array $payload = []): Payment + public function createForId($customerId, $payload = [], $query = [], bool $testmode = false): Payment { - $testmode = Helpers::extractBool($payload, 'testmode', false); - $profileId = Arr::get($payload, 'profileId'); + if (! $payload instanceof CreatePaymentPayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $payload = CreatePaymentPayloadFactory::new($payload) + ->create(); + } + + if (! $query instanceof CreatePaymentQuery) { + $query = CreatePaymentQuery::fromArray(Arr::wrap($query)); + } /** @var Payment */ - return $this->send((new CreateCustomerPaymentRequest($customerId, $profileId))->test($testmode)); + return $this->send((new CreateCustomerPaymentRequest($customerId, $payload, $query))->test($testmode)); } /** @@ -49,9 +59,9 @@ public function createForId($customerId, array $payload = []): Payment * * @throws ApiException */ - public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): PaymentCollection + public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { - return $this->pageForId($customer->id, $from, $limit, $parameters); + return $this->pageForId($customer->id, $from, $limit, $filters); } /** diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php index 4d754b4e4..1314c54b1 100644 --- a/src/EndpointCollection/MandateEndpointCollection.php +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -8,9 +8,9 @@ use Mollie\Api\Helpers; use Mollie\Api\Http\Payload\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; -use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; +use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Mandate; @@ -22,20 +22,18 @@ class MandateEndpointCollection extends EndpointCollection * Creates a mandate for a specific customer. * * @param array $payload - * @param array $filters * * @throws ApiException */ - public function createFor(Customer $customer, $payload = []): Mandate + public function createFor(Customer $customer, $payload = [], bool $testmode = false): Mandate { - return $this->createForId($customer->id, $payload); + return $this->createForId($customer->id, $payload, $testmode); } /** * Creates a mandate for a specific customer ID. * * @param array $payload - * @param array $filters * * @throws ApiException */ @@ -82,7 +80,7 @@ public function getForId(string $customerId, string $mandateId, $testmode = []): * * @throws ApiException */ - public function revokeFor(Customer $customer, string $mandateId, array $data = []): void + public function revokeFor(Customer $customer, string $mandateId, $data = []): void { $this->revokeForId($customer->id, $mandateId, $data); } @@ -94,7 +92,7 @@ public function revokeFor(Customer $customer, string $mandateId, array $data = [ * * @throws ApiException */ - public function revokeForId(string $customerId, string $mandateId, array $testmode = []): void + public function revokeForId(string $customerId, string $mandateId, $testmode = []): void { $testmode = Helpers::extractBool($testmode, 'testmode', false); diff --git a/src/EndpointCollection/PaymentChargebackEndpointCollection.php b/src/EndpointCollection/PaymentChargebackEndpointCollection.php index 8cd1b7e10..c2dd68706 100644 --- a/src/EndpointCollection/PaymentChargebackEndpointCollection.php +++ b/src/EndpointCollection/PaymentChargebackEndpointCollection.php @@ -107,7 +107,7 @@ public function iteratorForId( return $this->send( (new GetPaginatedPaymentChargebacksRequest($paymentId, $query)) - ->useIterator() + ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) ); diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php index 13d03b156..9c509a23e 100644 --- a/src/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -54,9 +54,9 @@ public function createForId(string $paymentId, $payload = [], $testmode = []): R /** * @throws \Mollie\Api\Exceptions\ApiException */ - public function getFor(Payment $payment, string $refundId, array $parameters = []): Refund + public function getFor(Payment $payment, string $refundId, array $parameters = [], bool $testmode = false): Refund { - return $this->getForId($payment->id, $refundId, $parameters); + return $this->getForId($payment->id, $refundId, $parameters, $testmode); } /** diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index 39db2c17f..cd4ba0e00 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -67,6 +67,7 @@ public function get(string $profileId, $testmode = []): Profile public function getCurrent($testmode = []): CurrentProfile { GetProfileRequest::$targetResourceClass = CurrentProfile::class; + /** @var CurrentProfile */ return $this->get('me', $testmode); } diff --git a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php index a1055ed6a..0c4a30fcf 100644 --- a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php @@ -18,6 +18,7 @@ class SubscriptionPaymentEndpointCollection extends EndpointCollection * @param string|null $from The first payment ID you want to include in your list. * @param int|null $limit The maximum amount of results you want to retrieve per page. * @param bool|array $testmode + * * @throws ApiException */ public function pageFor(Subscription $subscription, ?string $from = null, ?int $limit = null, $testmode = []): PaymentCollection @@ -31,6 +32,7 @@ public function pageFor(Subscription $subscription, ?string $from = null, ?int $ * @param string|null $from The first payment ID you want to include in your list. * @param int|null $limit The maximum amount of results you want to retrieve per page. * @param bool|array $testmode + * * @throws ApiException */ public function pageForIds( diff --git a/src/Endpoints/RestEndpoint.php b/src/Endpoints/RestEndpoint.php deleted file mode 100644 index 7acf192bd..000000000 --- a/src/Endpoints/RestEndpoint.php +++ /dev/null @@ -1,126 +0,0 @@ -client - ->send(new DynamicPostRequest( - $this->getResourcePath(), - static::getResourceClass(), - $body, - $filters - )) - ->toResource(); - } - - /** - * Sends a PATCH request to a single Mollie API object. - * - * - * @throws ApiException - */ - protected function updateResource(string $id, array $body = []): ?BaseResource - { - $id = urlencode($id); - - return $this - ->client - ->send(new DynamicPatchRequest( - $this->getPathToSingleResource($id), - static::getResourceClass(), - $body - )) - ->toResource(); - } - - /** - * Retrieves a single object from the REST API. - * - * @param string $id Id of the object to retrieve. - * - * @throws ApiException - */ - protected function readResource(string $id, array $filters): BaseResource - { - if (! $this instanceof SingleResourceEndpointContract && empty($id)) { - throw new ApiException('Invalid resource id.'); - } - - return $this - ->client - ->send(new DynamicGetRequest( - $this->getPathToSingleResource($id), - static::getResourceClass(), - $filters - )) - ->toResource(); - } - - /** - * Sends a DELETE request to a single Mollie API object. - * - * - * @throws ApiException - */ - protected function deleteResource(string $id, array $body = []): ?BaseResource - { - if (empty($id)) { - throw new ApiException('Invalid resource id.'); - } - - return $this - ->client - ->send(new DynamicDeleteRequest( - $this->getPathToSingleResource($id), - static::getResourceClass(), - null, - $body - )) - ->toResource(); - } - - protected function guardAgainstInvalidId(string $id): void - { - if (empty(static::$resourceIdPrefix)) { - throw new RuntimeException('Resource ID prefix is not set.'); - } - - if (empty($id) || strpos($id, static::$resourceIdPrefix) !== 0) { - $resourceType = $this->getResourceType(); - - throw new ApiException("Invalid {$resourceType} ID: '{$id}'. A resource ID should start with '".static::$resourceIdPrefix."'."); - } - } - - public function getResourceType(): string - { - $classBasename = basename(str_replace('\\', '/', static::getResourceClass())); - - return strtolower($classBasename); - } -} diff --git a/src/Helpers.php b/src/Helpers.php index e2524a190..d2379a804 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -73,7 +73,6 @@ public static function filterByProperties($class, array $array): array static::getProperties($class) ); - // Filter out the properties that are not part of the CreatePaymentData object return array_filter( $array, fn ($key) => ! in_array($key, $properties, true), diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 3c58bb6a5..c9eba6692 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -17,14 +17,14 @@ use Mollie\Api\Helpers\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Traits\IsDebuggable; +use Mollie\Api\Traits\IsDebuggableAdapter; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Throwable; final class GuzzleMollieHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { - use IsDebuggable; + use IsDebuggableAdapter; /** * Default response timeout (in seconds). diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 377abf546..09dc23228 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -8,7 +8,7 @@ use Mollie\Api\Helpers\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Traits\IsDebuggable; +use Mollie\Api\Traits\IsDebuggableAdapter; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; @@ -18,7 +18,7 @@ final class PSR18MollieHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { - use IsDebuggable; + use IsDebuggableAdapter; private ClientInterface $httpClient; diff --git a/src/Http/Middleware/Hydrate.php b/src/Http/Middleware/Hydrate.php index 152981a58..348b382a3 100644 --- a/src/Http/Middleware/Hydrate.php +++ b/src/Http/Middleware/Hydrate.php @@ -12,7 +12,7 @@ class Hydrate public function __invoke(Response $response) { - if (! $response->getRequest()::$shouldAutoHydrate || !$response->getRequest() instanceof ResourceHydratableRequest) { + if (! $response->getRequest()::$shouldAutoHydrate || ! $response->getRequest() instanceof ResourceHydratableRequest) { return $response; } diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php index 2fd310f5d..bc2be737f 100644 --- a/src/Http/PendingRequest/AuthenticateRequest.php +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -2,9 +2,7 @@ namespace Mollie\Api\Http\PendingRequest; -use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\Auth\ApiKeyAuthenticator; use Mollie\Api\Http\PendingRequest; class AuthenticateRequest diff --git a/src/Http/Request.php b/src/Http/Request.php index 7549b13a5..15bfda7b0 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -9,8 +9,8 @@ abstract class Request { - use HasMiddleware; use HandlesTestmode; + use HasMiddleware; use HasRequestProperties; /** diff --git a/src/Http/Requests/CancelPaymentRequest.php b/src/Http/Requests/CancelPaymentRequest.php index 8b87d51f9..6ee73d4d7 100644 --- a/src/Http/Requests/CancelPaymentRequest.php +++ b/src/Http/Requests/CancelPaymentRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class CancelPaymentRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/CancelSubscriptionRequest.php b/src/Http/Requests/CancelSubscriptionRequest.php index 0f2fdc523..0d76f7ad6 100644 --- a/src/Http/Requests/CancelSubscriptionRequest.php +++ b/src/Http/Requests/CancelSubscriptionRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Subscription; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class CancelSubscriptionRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/CreateCustomerPaymentRequest.php b/src/Http/Requests/CreateCustomerPaymentRequest.php index b742fa964..a6f16fbdb 100644 --- a/src/Http/Requests/CreateCustomerPaymentRequest.php +++ b/src/Http/Requests/CreateCustomerPaymentRequest.php @@ -4,39 +4,21 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Resources\Payment; -use Mollie\Api\Traits\HasJsonPayload; -use Mollie\Api\Types\Method; +use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Query\CreatePaymentQuery; -class CreateCustomerPaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInPayload +class CreateCustomerPaymentRequest extends CreatePaymentRequest implements HasPayload, SupportsTestmodeInPayload { - use HasJsonPayload; - - /** - * Define the HTTP method. - */ - protected static string $method = Method::POST; - - /** - * The resource class the request should be casted to. - */ - public static string $targetResourceClass = Payment::class; - protected string $customerId; - protected string $profileId; + public function __construct( + string $customerId, + CreatePaymentPayload $payload, + ?CreatePaymentQuery $query = null, + ) { + parent::__construct($payload, $query); - public function __construct(string $customerId, ?string $profileId = null) - { $this->customerId = $customerId; - $this->profileId = $profileId; - } - - protected function defaultPayload(): array - { - return [ - 'profileId' => $this->profileId, - ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index 8cb84a9e5..6f434ccd0 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -3,12 +3,12 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class CreatePaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/DeletePaymentLinkRequest.php b/src/Http/Requests/DeletePaymentLinkRequest.php index 5ae59494d..4ddcc0572 100644 --- a/src/Http/Requests/DeletePaymentLinkRequest.php +++ b/src/Http/Requests/DeletePaymentLinkRequest.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Types\Method; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Types\Method; class DeletePaymentLinkRequest extends SimpleRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php index 6bc1b615b..0457a1b78 100644 --- a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\SubscriptionCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetAllPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php index 4e9c104ab..6f2f05a4e 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Query\SortablePaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaginatedPaymentLinkPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php index fb97a1be2..3f1120932 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\PaymentLinkCollection; use Mollie\Api\Traits\IsIteratableRequest; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaginatedPaymentLinksRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php index acc63e6c7..06291d7f7 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\Http\Query\GetPaginatedPaymentRefundQuery; -use Mollie\Api\Traits\IsIteratableRequest; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Http\Query\GetPaginatedPaymentRefundQuery; use Mollie\Api\Resources\RefundCollection; +use Mollie\Api\Traits\IsIteratableRequest; class GetPaginatedPaymentRefundsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index dde3e24c5..e90b3e577 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index 02e9d3495..62f027d32 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Resources\SubscriptionCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaginatedTerminalsRequest.php b/src/Http/Requests/GetPaginatedTerminalsRequest.php index a8c4730de..321d592ad 100644 --- a/src/Http/Requests/GetPaginatedTerminalsRequest.php +++ b/src/Http/Requests/GetPaginatedTerminalsRequest.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\TerminalCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaginatedTerminalsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetPaymentLinkRequest.php b/src/Http/Requests/GetPaymentLinkRequest.php index aac61091c..37a3b5587 100644 --- a/src/Http/Requests/GetPaymentLinkRequest.php +++ b/src/Http/Requests/GetPaymentLinkRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetPaymentLinkRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetSubscriptionRequest.php b/src/Http/Requests/GetSubscriptionRequest.php index 6a5fa6c00..c75449de1 100644 --- a/src/Http/Requests/GetSubscriptionRequest.php +++ b/src/Http/Requests/GetSubscriptionRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Subscription; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class GetSubscriptionRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/GetTerminalRequest.php b/src/Http/Requests/GetTerminalRequest.php index a9595f454..b710a3009 100644 --- a/src/Http/Requests/GetTerminalRequest.php +++ b/src/Http/Requests/GetTerminalRequest.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Resources\Terminal; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Resources\Terminal; class GetTerminalRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index 41642e4a8..91c91f8fc 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Request; use Mollie\Api\Contracts\SupportsResourceHydration; +use Mollie\Api\Http\Request; abstract class ResourceHydratableRequest extends Request implements SupportsResourceHydration { diff --git a/src/Http/Requests/UpdatePaymentLinkRequest.php b/src/Http/Requests/UpdatePaymentLinkRequest.php index c01d73495..2c5ee98df 100644 --- a/src/Http/Requests/UpdatePaymentLinkRequest.php +++ b/src/Http/Requests/UpdatePaymentLinkRequest.php @@ -3,11 +3,11 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; +use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; class UpdatePaymentLinkRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInQuery { diff --git a/src/Http/Response.php b/src/Http/Response.php index b2fa3d259..0a2763d18 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http; use Mollie\Api\Contracts\Connector; -use Mollie\Api\Contracts\SupportsResourceHydration; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Traits\HandlesResourceCreation; diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index b470e7fde..5c939298b 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -12,39 +12,36 @@ use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; use Mollie\Api\EndpointCollection\CustomerEndpointCollection; -use Mollie\Api\EndpointCollection\CustomerPaymentsEndpoint; +use Mollie\Api\EndpointCollection\CustomerPaymentsEndpointCollection; +use Mollie\Api\EndpointCollection\InvoiceEndpointCollection; +use Mollie\Api\EndpointCollection\MandateEndpointCollection; +use Mollie\Api\EndpointCollection\MethodEndpointCollection; +use Mollie\Api\EndpointCollection\MethodIssuerEndpointCollection; +use Mollie\Api\EndpointCollection\OnboardingEndpointCollection; use Mollie\Api\EndpointCollection\OrderEndpointCollection; +use Mollie\Api\EndpointCollection\OrderShipmentEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; +use Mollie\Api\EndpointCollection\OrganizationPartnerEndpoint; +use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentChargebackEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentLinkEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentLinkPaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentRefundEndpointCollection; -use Mollie\Api\Endpoints\InvoiceEndpoint; -use Mollie\Api\Endpoints\MandateEndpoint; -use Mollie\Api\Endpoints\MethodEndpoint; -use Mollie\Api\Endpoints\MethodIssuerEndpoint; -use Mollie\Api\Endpoints\OnboardingEndpoint; -use Mollie\Api\Endpoints\OrderLineEndpoint; -use Mollie\Api\Endpoints\OrderPaymentEndpoint; -use Mollie\Api\Endpoints\OrderRefundEndpoint; -use Mollie\Api\Endpoints\OrderShipmentEndpoint; -use Mollie\Api\Endpoints\OrganizationPartnerEndpoint; -use Mollie\Api\Endpoints\PaymentCaptureEndpoint; -use Mollie\Api\Endpoints\PaymentChargebackEndpoint; -use Mollie\Api\Endpoints\PaymentLinkEndpoint; -use Mollie\Api\Endpoints\PaymentLinkPaymentEndpoint; -use Mollie\Api\Endpoints\PaymentRouteEndpoint; -use Mollie\Api\Endpoints\PermissionEndpoint; -use Mollie\Api\Endpoints\ProfileEndpoint; -use Mollie\Api\Endpoints\ProfileMethodEndpoint; -use Mollie\Api\Endpoints\RefundEndpoint; -use Mollie\Api\Endpoints\SettlementCaptureEndpoint; -use Mollie\Api\Endpoints\SettlementChargebackEndpoint; -use Mollie\Api\Endpoints\SettlementPaymentEndpoint; -use Mollie\Api\Endpoints\SettlementRefundEndpoint; -use Mollie\Api\Endpoints\SettlementsEndpoint; -use Mollie\Api\Endpoints\SubscriptionEndpoint; -use Mollie\Api\Endpoints\SubscriptionPaymentEndpoint; -use Mollie\Api\Endpoints\TerminalEndpoint; -use Mollie\Api\Endpoints\WalletEndpoint; +use Mollie\Api\EndpointCollection\PaymentRouteEndpointCollection; +use Mollie\Api\EndpointCollection\PermissionEndpointCollection; +use Mollie\Api\EndpointCollection\ProfileEndpointCollection; +use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; +use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementsEndpointCollection; +use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; +use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; +use Mollie\Api\EndpointCollection\TerminalEndpointCollection; +use Mollie\Api\EndpointCollection\WalletEndpointCollection; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Resources\BalanceTransactionCollection; @@ -67,40 +64,37 @@ * @property ChargebackEndpointCollection $chargebacks * @property ClientEndpointCollection $clients * @property ClientLinkEndpointCollection $clientLinks - * @property CustomerPaymentsEndpoint $customerPayments + * @property CustomerPaymentsEndpointCollection $customerPayments * @property CustomerEndpointCollection $customers - * @property InvoiceEndpoint $invoices - * @property MandateEndpoint $mandates - * @property MethodEndpoint $methods - * @property MethodIssuerEndpoint $methodIssuers - * @property OnboardingEndpoint $onboarding + * @property InvoiceEndpointCollection $invoices + * @property MandateEndpointCollection $mandates + * @property MethodEndpointCollection $methods + * @property MethodIssuerEndpointCollection $methodIssuers + * @property OnboardingEndpointCollection $onboarding * @property OrderEndpointCollection $orders - * @property OrderLineEndpoint $orderLines - * @property OrderPaymentEndpoint $orderPayments - * @property OrderRefundEndpoint $orderRefunds * @property OrganizationEndpointCollection $organizations * @property OrganizationPartnerEndpoint $organizationPartners * @property PaymentEndpointCollection $payments - * @property PaymentCaptureEndpoint $paymentCaptures - * @property PaymentChargebackEndpoint $paymentChargebacks - * @property PaymentLinkEndpoint $paymentLinks - * @property PaymentLinkPaymentEndpoint $paymentLinkPayments + * @property PaymentCaptureEndpointCollection $paymentCaptures + * @property PaymentChargebackEndpointCollection $paymentChargebacks + * @property PaymentLinkEndpointCollection $paymentLinks + * @property PaymentLinkPaymentEndpointCollection $paymentLinkPayments * @property PaymentRefundEndpointCollection $paymentRefunds - * @property PaymentRouteEndpoint $paymentRoutes - * @property PermissionEndpoint $permissions - * @property ProfileEndpoint $profiles - * @property ProfileMethodEndpoint $profileMethods - * @property RefundEndpoint $refunds - * @property SettlementsEndpoint $settlements - * @property SettlementCaptureEndpoint $settlementCaptures - * @property SettlementChargebackEndpoint $settlementChargebacks - * @property SettlementPaymentEndpoint $settlementPayments - * @property SettlementRefundEndpoint $settlementRefunds - * @property OrderShipmentEndpoint $shipments - * @property SubscriptionEndpoint $subscriptions - * @property SubscriptionPaymentEndpoint $subscriptionPayments - * @property TerminalEndpoint $terminals - * @property WalletEndpoint $wallets + * @property PaymentRouteEndpointCollection $paymentRoutes + * @property PermissionEndpointCollection $permissions + * @property ProfileEndpointCollection $profiles + * @property ProfileMethodEndpointCollection $profileMethods + * @property RefundEndpointCollection $refunds + * @property SettlementsEndpointCollection $settlements + * @property SettlementCaptureEndpointCollection $settlementCaptures + * @property SettlementChargebackEndpointCollection $settlementChargebacks + * @property SettlementPaymentEndpointCollection $settlementPayments + * @property SettlementRefundEndpointCollection $settlementRefunds + * @property OrderShipmentEndpointCollection $shipments + * @property SubscriptionEndpointCollection $subscriptions + * @property SubscriptionPaymentEndpointCollection $subscriptionPayments + * @property TerminalEndpointCollection $terminals + * @property WalletEndpointCollection $wallets * @property HttpAdapterContract $httpClient */ class MollieApiClient implements Connector diff --git a/src/Resources/Balance.php b/src/Resources/Balance.php index f09dd5da6..89b62b807 100644 --- a/src/Resources/Balance.php +++ b/src/Resources/Balance.php @@ -2,8 +2,12 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Traits\HasMode; + class Balance extends BaseResource { + use HasMode; + /** * Resource id prefix. Used to validate resource id's. */ diff --git a/src/Resources/BalanceTransaction.php b/src/Resources/BalanceTransaction.php index 18c26595f..42443ed26 100644 --- a/src/Resources/BalanceTransaction.php +++ b/src/Resources/BalanceTransaction.php @@ -4,8 +4,12 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Traits\HasMode; + class BalanceTransaction extends BaseResource { + use HasMode; + /** * Indicates this is a balance transaction resource. The value will always be "balance_transaction" here. * diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 6108cebc4..8795427e8 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -6,10 +6,12 @@ use Mollie\Api\Contracts\HasResponse; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; +use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] abstract class BaseResource implements HasResponse { + /** @var MollieApiClient */ protected Connector $connector; protected ?Response $response; diff --git a/src/Resources/Capture.php b/src/Resources/Capture.php index d1a59bd86..cd0992936 100644 --- a/src/Resources/Capture.php +++ b/src/Resources/Capture.php @@ -2,8 +2,12 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Traits\HasMode; + class Capture extends BaseResource { + use HasMode; + /** * Always 'capture' for this object * diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index f56cc6556..59d7f8c6c 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -4,12 +4,9 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Traits\InteractsWithResource; abstract class CursorCollection extends BaseCollection { - use InteractsWithResource; - /** * Return the next set of resources when available * diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index c67242b84..f06adfacd 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -3,10 +3,11 @@ namespace Mollie\Api\Resources; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Traits\HasMode; class Customer extends BaseResource { - use HasPresetOptions; + use HasMode; public static string $resourceIdPrefix = 'cst_'; @@ -82,7 +83,12 @@ public function update(): ?Customer */ public function createPayment(array $options = [], array $filters = []) { - return $this->connector->customerPayments->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->customerPayments->createFor( + $this, + $options, + $filters, + $this->isInTestmode() + ); } /** @@ -94,7 +100,7 @@ public function createPayment(array $options = [], array $filters = []) */ public function payments() { - return $this->connector->customerPayments->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->customerPayments->pageFor($this, null, null, $this->withMode()); } /** @@ -104,7 +110,7 @@ public function payments() */ public function createSubscription(array $options = [], array $filters = []) { - return $this->connector->subscriptions->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->subscriptions->createFor($this, $options, $this->isInTestmode()); } /** @@ -113,9 +119,9 @@ public function createSubscription(array $options = [], array $filters = []) * * @throws ApiException */ - public function getSubscription($subscriptionId, array $parameters = []) + public function getSubscription($subscriptionId) { - return $this->connector->subscriptions->getFor($this, $subscriptionId, $this->withPresetOptions($parameters)); + return $this->connector->subscriptions->getFor($this, $subscriptionId, $this->isInTestmode()); } /** @@ -126,7 +132,7 @@ public function getSubscription($subscriptionId, array $parameters = []) */ public function cancelSubscription($subscriptionId) { - return $this->connector->subscriptions->cancelFor($this, $subscriptionId, $this->getPresetOptions()); + return $this->connector->subscriptions->cancelFor($this, $subscriptionId, $this->isInTestmode()); } /** @@ -138,7 +144,7 @@ public function cancelSubscription($subscriptionId) */ public function subscriptions() { - return $this->connector->subscriptions->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->subscriptions->pageFor($this, null, null, $this->withMode()); } /** @@ -146,9 +152,9 @@ public function subscriptions() * * @throws ApiException */ - public function createMandate(array $options = [], array $filters = []) + public function createMandate(array $options = []) { - return $this->connector->mandates->createFor($this, $this->withPresetOptions($options), $filters); + return $this->connector->mandates->createFor($this, $options, $this->isInTestmode()); } /** @@ -159,7 +165,7 @@ public function createMandate(array $options = [], array $filters = []) */ public function getMandate($mandateId, array $parameters = []) { - return $this->connector->mandates->getFor($this, $mandateId, $parameters); + return $this->connector->mandates->getFor($this, $mandateId, $this->withMode($parameters)); } /** @@ -170,7 +176,7 @@ public function getMandate($mandateId, array $parameters = []) */ public function revokeMandate($mandateId) { - return $this->connector->mandates->revokeFor($this, $mandateId, $this->getPresetOptions()); + return $this->connector->mandates->revokeFor($this, $mandateId, $this->withMode()); } /** @@ -182,7 +188,7 @@ public function revokeMandate($mandateId) */ public function mandates() { - return $this->connector->mandates->listFor($this, null, null, $this->getPresetOptions()); + return $this->connector->mandates->pageFor($this, null, null, $this->withMode()); } /** diff --git a/src/Resources/HasPresetOptions.php b/src/Resources/HasPresetOptions.php deleted file mode 100644 index 7ee972f67..000000000 --- a/src/Resources/HasPresetOptions.php +++ /dev/null @@ -1,31 +0,0 @@ -client->usesOAuth()) { - $options['testmode'] = $this->mode === 'test' ? true : false; - } - - return $options; - } - - /** - * Apply the preset options. - */ - protected function withPresetOptions(array $options): array - { - return array_merge($this->getPresetOptions(), $options); - } -} diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index d4b6b23ea..434871230 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -4,13 +4,18 @@ use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\UpdatePaymentRequest; +use Mollie\Api\Traits\HasMode; +use Mollie\Api\Types\PaymentMethod; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; class Payment extends BaseResource implements EmbeddedResourcesContract { - use HasPresetOptions; + use HasMode; /** * Resource id prefix. Used to validate resource id's. @@ -610,7 +615,7 @@ public function refunds(): RefundCollection */ public function getRefund($refundId, array $parameters = []): Refund { - return $this->connector->paymentRefunds->getFor($this, $refundId, $this->withPresetOptions($parameters)); + return $this->connector->paymentRefunds->getFor($this, $refundId, $parameters, $this->isInTestmode()); } /** @@ -621,9 +626,11 @@ public function listRefunds(array $parameters = []): RefundCollection return $this ->connector ->paymentRefunds - ->listFor( + ->pageFor( $this, - $this->withPresetOptions($parameters) + null, + null, + $this->withMode($parameters), ); } @@ -656,7 +663,8 @@ public function getCapture($captureId, array $parameters = []): Capture return $this->connector->paymentCaptures->getFor( $this, $captureId, - $this->withPresetOptions($parameters) + $parameters, + $this->isInTestmode() ); } @@ -691,7 +699,8 @@ public function getChargeback($chargebackId, array $parameters = []): Chargeback return $this->connector->paymentChargebacks->getFor( $this, $chargebackId, - $this->withPresetOptions($parameters) + $parameters, + $this->isInTestmode() ); } @@ -712,22 +721,26 @@ public function refund($data): Refund */ public function update(): ?Payment { - $body = [ - 'description' => $this->description, - 'cancelUrl' => $this->cancelUrl, - 'redirectUrl' => $this->redirectUrl, - 'webhookUrl' => $this->webhookUrl, - 'metadata' => $this->metadata, - 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, - 'locale' => $this->locale, - 'dueDate' => $this->dueDate, - ]; + $additional = []; + if ($this->method === PaymentMethod::BANKTRANSFER) { + $additional['dueDate'] = $this->dueDate; + } - /** @var null|Payment */ - return $this->connector->payments->update( - $this->id, - $this->withPresetOptions($body) + $payload = new UpdatePaymentPayload( + $this->description, + $this->redirectUrl, + $this->cancelUrl, + $this->webhookUrl, + new Metadata($this->metadata), + $this->method, + $this->locale, + $this->restrictPaymentMethodsToCountry, + $additional ); + + return $this + ->connector + ->send((new UpdatePaymentRequest($this->id, $payload))->test($this->isInTestmode())); } /** diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index 1c74c24b8..f4d2acb08 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -3,11 +3,12 @@ namespace Mollie\Api\Resources; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; +use Mollie\Api\Traits\HasMode; use Mollie\Api\Types\RefundStatus; class Refund extends BaseResource { - use HasPresetOptions; + use HasMode; public static string $resourceIdPrefix = 're_'; @@ -167,6 +168,6 @@ public function cancel(): void ->send((new CancelPaymentRefundRequest( $this->paymentId, $this->id - ))->test($this->mode === 'test')); + ))->test($this->isInTestmode())); } } diff --git a/src/Resources/Session.php b/src/Resources/Session.php index 6913d5c9c..01d71483c 100644 --- a/src/Resources/Session.php +++ b/src/Resources/Session.php @@ -2,11 +2,12 @@ namespace Mollie\Api\Resources; +use Mollie\Api\Traits\HasMode; use Mollie\Api\Types\SessionStatus; class Session extends BaseResource { - use HasPresetOptions; + use HasMode; /** * The session's unique identifier, @@ -153,9 +154,7 @@ public function update() 'shippingAddress' => $this->shippingAddress, ]; - $result = $this->client->sessions->update($this->id, $this->withPresetOptions($body)); - - return ResourceFactory::createFromApiResult($result, new Session($this->client)); + return $this->connector->sessions->update($this->id, $this->withMode($body)); } /** @@ -167,7 +166,7 @@ public function update() */ public function cancel() { - return $this->client->sessions->cancel($this->id, $this->getPresetOptions()); + return $this->connector->sessions->cancel($this->id, $this->withMode()); } /** diff --git a/src/Traits/HasMode.php b/src/Traits/HasMode.php new file mode 100644 index 000000000..85b44257e --- /dev/null +++ b/src/Traits/HasMode.php @@ -0,0 +1,19 @@ +mode === 'test'; + } + + public function withMode(array $options = []): array + { + return array_merge($options, ['testmode' => $this->isInTestmode()]); + } +} diff --git a/src/Traits/InteractsWithResource.php b/src/Traits/InteractsWithResource.php deleted file mode 100644 index a763d2d52..000000000 --- a/src/Traits/InteractsWithResource.php +++ /dev/null @@ -1,20 +0,0 @@ -resolveResourcePath(); - - $query = $this->buildQuery($request->query()); - - return $path.$query; - } - - private function buildQuery(ArrayRepository $query): string - { - if ($query->isEmpty()) { - return ''; - } - - $query = $this->transformQuery($query->all()); - - return '?'.http_build_query($query, '', '&'); - } - - private function transformQuery(array $query): array - { - return array_map(function ($value) { - if ($value === true) { - return 'true'; - } - - if ($value === false) { - return 'false'; - } - - return $value; - }, $query); - } -} From f842f91846c1132269cae757f7ab4a85d165f49b Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 26 Nov 2024 20:44:25 +0100 Subject: [PATCH 067/131] wip --- src/MollieApiClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 5c939298b..50ec8bf09 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -42,6 +42,7 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; +use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Resources\BalanceTransactionCollection; @@ -166,7 +167,7 @@ public function getHttpClient(): HttpAdapterContract public function resolveBaseUrl(): string { - return rtrim($this->apiEndpoint, '/').'/'.self::API_VERSION; + return Url::join($this->apiEndpoint, self::API_VERSION); } public function __serialize(): array From be6161e7eaa98f5dd059d7651ff4b75e4d7363c3 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 28 Nov 2024 14:00:15 +0100 Subject: [PATCH 068/131] wip --- src/Contracts/Testable.php | 2 +- .../BalanceTransactionEndpointCollection.php | 6 +- .../ClientEndpointCollection.php | 12 +- .../MethodEndpointCollection.php | 6 +- .../SettlementEndpointCollection.php | 101 +++++++++ src/Factories/Factory.php | 9 + src/Factories/GetAllMethodsQueryFactory.php | 17 -- .../GetAllPaymentMethodsQueryFactory.php | 23 ++ .../GetBalanceReportQueryFactory.php | 2 +- src/Factories/GetClientQueryFactory.php | 20 ++ ... GetEnabledPaymentMethodsQueryFactory.php} | 14 +- .../GetPaginatedClientQueryFactory.php | 18 +- ...etPaginatedPaymentCapturesQueryFactory.php | 5 +- ...aginatedPaymentChargebacksQueryFactory.php | 5 +- .../GetPaginatedRefundsQueryFactory.php | 6 +- ...aginatedSettlementCapturesQueryFactory.php | 6 +- ...PaginatedSettlementRefundsQueryFactory.php | 3 +- .../GetPaymentCaptureQueryFactory.php | 5 +- .../GetPaymentChargebackQueryFactory.php | 6 +- .../GetPaymentMethodQueryFactory.php | 7 +- src/Factories/GetPaymentQueryFactory.php | 15 +- .../GetPaymentRefundQueryFactory.php | 6 +- src/Helpers/Arr.php | 23 ++ src/Http/Query/CreatePaymentQuery.php | 9 +- src/Http/Query/GetAllMethodsQuery.php | 17 +- src/Http/Query/GetClientQuery.php | 30 +++ ....php => GetEnabledPaymentMethodsQuery.php} | 10 +- .../Query/GetPaginatedChargebackQuery.php | 4 +- src/Http/Query/GetPaginatedClientQuery.php | 16 +- .../GetPaginatedPaymentCapturesQuery.php | 9 +- .../GetPaginatedPaymentChargebacksQuery.php | 10 +- .../Query/GetPaginatedPaymentRefundQuery.php | 4 +- src/Http/Query/GetPaginatedRefundsQuery.php | 12 +- src/Http/Query/GetPaymentCaptureQuery.php | 10 +- src/Http/Query/GetPaymentChargebackQuery.php | 10 +- src/Http/Query/GetPaymentMethodQuery.php | 29 ++- src/Http/Query/GetPaymentQuery.php | 36 ++- src/Http/Query/GetPaymentRefundQuery.php | 10 +- src/Http/Requests/GetClientRequest.php | 12 +- .../Requests/GetEnabledMethodsRequest.php | 6 +- src/MollieApiClient.php | 3 +- src/Resources/CursorCollection.php | 14 ++ src/Traits/HasEndpoints.php | 7 +- src/Types/PaymentIncludesQuery.php | 4 +- .../BalanceEndpointCollectionTest.php | 152 +++++-------- .../BalanceReportEndpointCollectionTest.php | 90 ++++++++ ...lanceTransactionEndpointCollectionTest.php | 64 ++++++ .../ChargebackEndpointCollectionTest.php | 54 +++++ .../ClientEndpointCollectionTest.php | 66 ++++++ .../ClientLinkEndpointCollectionTest.php | 31 +++ .../CustomerEndpointCollectionTest.php | 117 ++++++++++ ...CustomerPaymentsEndpointCollectionTest.php | 90 ++++++++ .../InvoiceEndpointCollectionTest.php | 73 +++++++ .../MandateEndpointCollectionTest.php | 105 +++++++++ .../MethodEndpointCollectionTest.php | 77 +++++++ .../MethodIssuerEndpointCollectionTest.php | 58 +++++ .../OnboardingEndpointCollectionTest.php | 30 +++ .../OrganizationEndpointCollectionTest.php | 70 ++++++ ...anizationPartnerEndpointCollectionTest.php | 29 +++ .../PaymentCaptureEndpointCollectionTest.php | 104 +++++++++ ...aymentChargebackEndpointCollectionTest.php | 81 +++++++ .../PaymentEndpointCollectionTest.php | 156 +++++++++++++ .../PaymentLinkEndpointCollectionTest.php | 123 +++++++++++ ...ymentLinkPaymentEndpointCollectionTest.php | 66 ++++++ .../PaymentRefundEndpointCollectionTest.php | 121 ++++++++++ .../PaymentRouteEndpointCollectionTest.php | 35 +++ .../PermissionEndpointCollectionTest.php | 56 +++++ .../ProfileEndpointCollectionTest.php | 139 ++++++++++++ .../RefundEndpointCollectionTest.php | 55 +++++ ...ettlementCaptureEndpointCollectionTest.php | 64 ++++++ ...lementChargebackEndpointCollectionTest.php | 62 ++++++ ...ettlementPaymentEndpointCollectionTest.php | 63 ++++++ ...SettlementRefundEndpointCollectionTest.php | 62 ++++++ .../SettlementsEndpointCollectionTest.php | 123 +++++++++++ .../SubscriptionEndpointCollectionTest.php | 151 +++++++++++++ ...scriptionPaymentEndpointCollectionTest.php | 66 ++++++ .../TerminalEndpointCollectionTest.php | 73 +++++++ .../WalletEndpointCollectionTest.php | 30 +++ .../Fixtures/Responses/apple-pay-session.json | 10 + tests/Fixtures/Responses/balance-list.json | 8 +- tests/Fixtures/Responses/balance-report.json | 149 +++++++++++++ .../Responses/balance-transactions.json | 63 ++++++ tests/Fixtures/Responses/balance.json | 4 +- tests/Fixtures/Responses/capture-list.json | 45 ++++ tests/Fixtures/Responses/capture.json | 27 +++ tests/Fixtures/Responses/chargeback-list.json | 206 ++++++++++++++++++ tests/Fixtures/Responses/chargeback.json | 33 +++ tests/Fixtures/Responses/client-link.json | 14 ++ tests/Fixtures/Responses/client-list.json | 33 +++ tests/Fixtures/Responses/client.json | 52 +++++ tests/Fixtures/Responses/current-profile.json | 47 ++++ .../Responses/cursor-collection-next.json | 6 +- .../Fixtures/Responses/cursor-collection.json | 4 +- tests/Fixtures/Responses/customer-list.json | 36 +++ tests/Fixtures/Responses/customer.json | 27 +++ ...mpty-balance-list.json => empty-list.json} | 8 +- tests/Fixtures/Responses/invoice-list.json | 61 ++++++ tests/Fixtures/Responses/invoice.json | 47 ++++ tests/Fixtures/Responses/issuer.json | 16 ++ tests/Fixtures/Responses/mandate-list.json | 44 ++++ tests/Fixtures/Responses/mandate.json | 30 +++ tests/Fixtures/Responses/method-list.json | 55 +++++ tests/Fixtures/Responses/method.json | 29 +++ tests/Fixtures/Responses/onboarding.json | 26 +++ tests/Fixtures/Responses/organization.json | 28 +++ tests/Fixtures/Responses/partner-status.json | 19 ++ .../Fixtures/Responses/payment-link-list.json | 49 +++++ tests/Fixtures/Responses/payment-link.json | 31 +++ tests/Fixtures/Responses/payment-list.json | 55 +++++ tests/Fixtures/Responses/payment-route.json | 13 ++ tests/Fixtures/Responses/payment.json | 6 +- tests/Fixtures/Responses/permission-list.json | 41 ++++ tests/Fixtures/Responses/permission.json | 16 ++ tests/Fixtures/Responses/profile-list.json | 43 ++++ tests/Fixtures/Responses/profile.json | 29 +++ tests/Fixtures/Responses/refund-list.json | 48 ++++ tests/Fixtures/Responses/refund.json | 28 +++ tests/Fixtures/Responses/session.json | 24 ++ tests/Fixtures/Responses/settlement-list.json | 41 ++++ tests/Fixtures/Responses/settlement.json | 125 +++++++++++ .../Fixtures/Responses/subscription-list.json | 53 +++++ tests/Fixtures/Responses/subscription.json | 35 +++ tests/Fixtures/Responses/terminal-list.json | 38 ++++ tests/Fixtures/Responses/terminal.json | 23 ++ .../unprocessable-entity-with-field.json | 2 +- tests/Helpers/ArrTest.php | 9 + tests/Helpers/HandlersTest.php | 64 ++++++ 127 files changed, 4955 insertions(+), 260 deletions(-) create mode 100644 src/EndpointCollection/SettlementEndpointCollection.php delete mode 100644 src/Factories/GetAllMethodsQueryFactory.php create mode 100644 src/Factories/GetAllPaymentMethodsQueryFactory.php create mode 100644 src/Factories/GetClientQueryFactory.php rename src/Factories/{GetEnabledMethodsQueryFactory.php => GetEnabledPaymentMethodsQueryFactory.php} (51%) create mode 100644 src/Http/Query/GetClientQuery.php rename src/Http/Query/{GetEnabledMethodsQuery.php => GetEnabledPaymentMethodsQuery.php} (75%) create mode 100644 tests/EndpointCollection/BalanceReportEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/ChargebackEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/ClientEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/ClientLinkEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/CustomerEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/InvoiceEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/MandateEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/MethodEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/OnboardingEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/OrganizationEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/PermissionEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/ProfileEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/RefundEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SettlementsEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SubscriptionEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/TerminalEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/WalletEndpointCollectionTest.php create mode 100644 tests/Fixtures/Responses/apple-pay-session.json create mode 100644 tests/Fixtures/Responses/balance-report.json create mode 100644 tests/Fixtures/Responses/balance-transactions.json create mode 100644 tests/Fixtures/Responses/capture-list.json create mode 100644 tests/Fixtures/Responses/capture.json create mode 100644 tests/Fixtures/Responses/chargeback-list.json create mode 100644 tests/Fixtures/Responses/chargeback.json create mode 100644 tests/Fixtures/Responses/client-link.json create mode 100644 tests/Fixtures/Responses/client-list.json create mode 100644 tests/Fixtures/Responses/client.json create mode 100644 tests/Fixtures/Responses/current-profile.json create mode 100644 tests/Fixtures/Responses/customer-list.json create mode 100644 tests/Fixtures/Responses/customer.json rename tests/Fixtures/Responses/{empty-balance-list.json => empty-list.json} (53%) create mode 100644 tests/Fixtures/Responses/invoice-list.json create mode 100644 tests/Fixtures/Responses/invoice.json create mode 100644 tests/Fixtures/Responses/issuer.json create mode 100644 tests/Fixtures/Responses/mandate-list.json create mode 100644 tests/Fixtures/Responses/mandate.json create mode 100644 tests/Fixtures/Responses/method-list.json create mode 100644 tests/Fixtures/Responses/method.json create mode 100644 tests/Fixtures/Responses/onboarding.json create mode 100644 tests/Fixtures/Responses/organization.json create mode 100644 tests/Fixtures/Responses/partner-status.json create mode 100644 tests/Fixtures/Responses/payment-link-list.json create mode 100644 tests/Fixtures/Responses/payment-link.json create mode 100644 tests/Fixtures/Responses/payment-list.json create mode 100644 tests/Fixtures/Responses/payment-route.json create mode 100644 tests/Fixtures/Responses/permission-list.json create mode 100644 tests/Fixtures/Responses/permission.json create mode 100644 tests/Fixtures/Responses/profile-list.json create mode 100644 tests/Fixtures/Responses/profile.json create mode 100644 tests/Fixtures/Responses/refund-list.json create mode 100644 tests/Fixtures/Responses/refund.json create mode 100644 tests/Fixtures/Responses/session.json create mode 100644 tests/Fixtures/Responses/settlement-list.json create mode 100644 tests/Fixtures/Responses/settlement.json create mode 100644 tests/Fixtures/Responses/subscription-list.json create mode 100644 tests/Fixtures/Responses/subscription.json create mode 100644 tests/Fixtures/Responses/terminal-list.json create mode 100644 tests/Fixtures/Responses/terminal.json create mode 100644 tests/Helpers/HandlersTest.php diff --git a/src/Contracts/Testable.php b/src/Contracts/Testable.php index 6653f7c2c..a88d45870 100644 --- a/src/Contracts/Testable.php +++ b/src/Contracts/Testable.php @@ -4,5 +4,5 @@ interface Testable { - public function getTestmode(): bool; + public function getTestmode(): ?bool; } diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php index 6fcf625a6..1036c78f9 100644 --- a/src/EndpointCollection/BalanceTransactionEndpointCollection.php +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -20,7 +20,7 @@ class BalanceTransactionEndpointCollection extends EndpointCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageFor(Balance $balance, $query = [], ?bool $testmode = null): BalanceTransactionCollection + public function pageFor(Balance $balance, $query = [], bool $testmode = false): BalanceTransactionCollection { return $this->pageForId($balance->id, $query, $testmode); } @@ -30,7 +30,7 @@ public function pageFor(Balance $balance, $query = [], ?bool $testmode = null): * * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection + public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection { return $this->iteratorForId($balance->id, $parameters, $iterateBackwards, $testmode); } @@ -42,7 +42,7 @@ public function iteratorFor(Balance $balance, array $parameters = [], bool $iter * * @throws \Mollie\Api\Exceptions\ApiException */ - public function pageForPrimary($query = [], ?bool $testmode = null): BalanceTransactionCollection + public function pageForPrimary($query = [], bool $testmode = false): BalanceTransactionCollection { /** @var BalanceTransactionCollection */ return $this->pageForId('primary', $query, $testmode); diff --git a/src/EndpointCollection/ClientEndpointCollection.php b/src/EndpointCollection/ClientEndpointCollection.php index fe14921c3..25309fc73 100644 --- a/src/EndpointCollection/ClientEndpointCollection.php +++ b/src/EndpointCollection/ClientEndpointCollection.php @@ -3,7 +3,9 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Factories\GetClientQueryFactory; use Mollie\Api\Factories\GetPaginatedClientQueryFactory; +use Mollie\Api\Http\Query\GetClientQuery; use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\Client; @@ -18,13 +20,19 @@ class ClientEndpointCollection extends EndpointCollection * Will throw an ApiException if the client id is invalid or the resource cannot be found. * The client id corresponds to the organization id, for example "org_1337". * + * @param string $id The client ID. + * @param GetClientQuery|array $query The query parameters. * * @throws ApiException */ - public function get(string $id, array $embed = []): Client + public function get(string $id, $query = []): Client { + if (!$query instanceof GetClientQuery) { + $query = GetClientQueryFactory::new($query)->create(); + } + /** @var Client */ - return $this->send(new GetClientRequest($id, $embed)); + return $this->send(new GetClientRequest($id, $query)); } /** diff --git a/src/EndpointCollection/MethodEndpointCollection.php b/src/EndpointCollection/MethodEndpointCollection.php index 65d891964..3820cff2a 100644 --- a/src/EndpointCollection/MethodEndpointCollection.php +++ b/src/EndpointCollection/MethodEndpointCollection.php @@ -3,12 +3,12 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetAllMethodsQueryFactory as GetAllPaymentMethodsQueryFactory; -use Mollie\Api\Factories\GetEnabledMethodsQueryFactory as GetEnabledPaymentMethodsQueryFactory; +use Mollie\Api\Factories\GetAllPaymentMethodsQueryFactory; +use Mollie\Api\Factories\GetEnabledPaymentMethodsQueryFactory; use Mollie\Api\Factories\GetPaymentMethodQueryFactory; use Mollie\Api\Helpers; use Mollie\Api\Http\Query\GetAllMethodsQuery as GetAllPaymentMethodsQuery; -use Mollie\Api\Http\Query\GetEnabledMethodsQuery as GetEnabledPaymentMethodsQuery; +use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; use Mollie\Api\Http\Query\GetPaymentMethodQuery; use Mollie\Api\Http\Requests\GetAllMethodsRequest as GetAllPaymentMethodsRequest; use Mollie\Api\Http\Requests\GetEnabledMethodsRequest as GetEnabledPaymentMethodsRequest; diff --git a/src/EndpointCollection/SettlementEndpointCollection.php b/src/EndpointCollection/SettlementEndpointCollection.php new file mode 100644 index 000000000..dc0f2a8fa --- /dev/null +++ b/src/EndpointCollection/SettlementEndpointCollection.php @@ -0,0 +1,101 @@ +send((new GetSettlementRequest($settlementId))->test($testmode)); + } + + /** + * Retrieve the next settlement from Mollie. + * + * @param array|bool $testmode + * @throws ApiException + */ + public function next($testmode = []): ?Settlement + { + return $this->get('next', $testmode); + } + + /** + * Retrieve the open balance from Mollie. + * + * @param array|bool $testmode + * @throws ApiException + */ + public function open($testmode = []): ?Settlement + { + return $this->get('open', $testmode); + } + + /** + * Retrieve a collection of settlements from Mollie. + * + * @param string|null $from The first settlement ID you want to include in your list. + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection + { + $testmode = Helpers::extractBool($filters, 'testmode', false); + + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + /** @var SettlementCollection */ + return $this->send((new GetPaginatedSettlementRequest($query))->test($testmode)); + } + + /** + * Create an iterator for iterating over settlements retrieved from Mollie. + * + * @param string|null $from The first settlement ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + array $filters = [], + bool $iterateBackwards = false + ): LazyCollection { + $testmode = Helpers::extractBool($filters, 'testmode', false); + + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ])->create(); + + return $this->send( + (new GetPaginatedSettlementRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ->test($testmode) + ); + } +} diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 6143cf4e2..13b8ab907 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -48,6 +48,15 @@ protected function has($keys): bool return Arr::has($this->data, $keys); } + /** + * @param string|array $key + * @param mixed $value + */ + protected function includes($key, $value, $backupKey = 'filters.'): bool + { + return Arr::includes($this->data, [$backupKey.$key, $key], $value); + } + /** * Map a value to a new form if it is not null. * diff --git a/src/Factories/GetAllMethodsQueryFactory.php b/src/Factories/GetAllMethodsQueryFactory.php deleted file mode 100644 index b7affa211..000000000 --- a/src/Factories/GetAllMethodsQueryFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get('locale'), - $this->get('include', []), - $this->mapIfNotNull('amount', MoneyFactory::class) - ); - } -} diff --git a/src/Factories/GetAllPaymentMethodsQueryFactory.php b/src/Factories/GetAllPaymentMethodsQueryFactory.php new file mode 100644 index 000000000..4fb790cf0 --- /dev/null +++ b/src/Factories/GetAllPaymentMethodsQueryFactory.php @@ -0,0 +1,23 @@ +includes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); + + return new GetAllMethodsQuery( + $this->get('locale'), + $this->get('includeIssuers', $includeIssuers), + $this->get('includePricing', $includePricing), + $this->mapIfNotNull('amount', MoneyFactory::class) + ); + } +} diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php index 54c805a1b..10e519808 100644 --- a/src/Factories/GetBalanceReportQueryFactory.php +++ b/src/Factories/GetBalanceReportQueryFactory.php @@ -9,7 +9,7 @@ class GetBalanceReportQueryFactory extends Factory { public function create(): GetBalanceReportQuery { - if (! $this->has(['from', 'unitl'])) { + if (! $this->has(['from', 'until'])) { throw new \InvalidArgumentException('The "from" and "until" fields are required.'); } diff --git a/src/Factories/GetClientQueryFactory.php b/src/Factories/GetClientQueryFactory.php new file mode 100644 index 000000000..5809702d6 --- /dev/null +++ b/src/Factories/GetClientQueryFactory.php @@ -0,0 +1,20 @@ +includes('embed', ClientQuery::EMBED_ORGANIZATION); + $embedOnboarding = $this->includes('embed', ClientQuery::EMBED_ONBOARDING); + + return new GetClientQuery( + $this->get('embedOrganization', $embedOrganization), + $this->get('embedOnboarding', $embedOnboarding), + ); + } +} diff --git a/src/Factories/GetEnabledMethodsQueryFactory.php b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php similarity index 51% rename from src/Factories/GetEnabledMethodsQueryFactory.php rename to src/Factories/GetEnabledPaymentMethodsQueryFactory.php index 33d973e0a..2bbed79ca 100644 --- a/src/Factories/GetEnabledMethodsQueryFactory.php +++ b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php @@ -2,14 +2,17 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetEnabledMethodsQuery; +use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; use Mollie\Api\Types\MethodQuery; -class GetEnabledMethodsQueryFactory extends Factory +class GetEnabledPaymentMethodsQueryFactory extends Factory { - public function create(): GetEnabledMethodsQuery + public function create(): GetEnabledPaymentMethodsQuery { - return new GetEnabledMethodsQuery( + $includeIssuers = $this->includes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); + + return new GetEnabledPaymentMethodsQuery( $this->get('sequenceType', MethodQuery::SEQUENCE_TYPE_ONEOFF), $this->get('resource', MethodQuery::RESOURCE_PAYMENTS), $this->get('locale'), @@ -18,7 +21,8 @@ public function create(): GetEnabledMethodsQuery $this->get('includeWallets'), $this->get('orderLineCategories', []), $this->get('profileId'), - $this->get('include', []), + $this->get('includeIssuers', $includeIssuers), + $this->get('includePricing', $includePricing), $this->get('testmode') ); } diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php index 0a5a0475c..6f42f9f2f 100644 --- a/src/Factories/GetPaginatedClientQueryFactory.php +++ b/src/Factories/GetPaginatedClientQueryFactory.php @@ -3,22 +3,18 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedClientQuery; - +use Mollie\Api\Types\ClientQuery; class GetPaginatedClientQueryFactory extends Factory { - private PaginatedQueryFactory $paginatedQueryFactory; - - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - $this->paginatedQueryFactory = new PaginatedQueryFactory($attributes); - } - public function create(): GetPaginatedClientQuery { + $embedOrganization = $this->includes('embed', ClientQuery::EMBED_ORGANIZATION); + $embedOnboarding = $this->includes('embed', ClientQuery::EMBED_ONBOARDING); + return new GetPaginatedClientQuery( - $this->paginatedQueryFactory->create(), - $this->get('embed', []) + PaginatedQueryFactory::new($this->data)->create(), + $this->get('embedOrganization', $embedOrganization), + $this->get('embedOnboarding', $embedOnboarding), ); } } diff --git a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php index cbfb91bce..7ff046330 100644 --- a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php @@ -3,16 +3,17 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedPaymentCapturesQuery; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentCapturesQueryFactory extends Factory { public function create(): GetPaginatedPaymentCapturesQuery { - $include = $this->get('filters.include', []); + $includePayments = $this->includes('include', PaymentIncludesQuery::PAYMENT); return new GetPaginatedPaymentCapturesQuery( PaginatedQueryFactory::new($this->data)->create(), - $this->get('include', $include) + $this->get('includePayments', $includePayments) ); } } diff --git a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php index 6146a1046..407720bb0 100644 --- a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php @@ -3,16 +3,17 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedPaymentChargebacksQuery; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentChargebacksQueryFactory extends Factory { public function create(): GetPaginatedPaymentChargebacksQuery { - $include = $this->get('filters.include', []); + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); return new GetPaginatedPaymentChargebacksQuery( PaginatedQueryFactory::new($this->data)->create(), - $this->get('include', $include), + $this->get('includePayment', $includePayment), ); } } diff --git a/src/Factories/GetPaginatedRefundsQueryFactory.php b/src/Factories/GetPaginatedRefundsQueryFactory.php index f35b89641..188ba8bba 100644 --- a/src/Factories/GetPaginatedRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedRefundsQueryFactory.php @@ -3,14 +3,16 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedRefundsQuery; - +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedRefundsQueryFactory extends Factory { public function create(): GetPaginatedRefundsQuery { + $embedPayment = $this->includes('embed', PaymentIncludesQuery::PAYMENT); + return new GetPaginatedRefundsQuery( PaginatedQueryFactory::new($this->data)->create(), - $this->get('embed'), + $this->get('embedPayment', $embedPayment), $this->get('profileId') ); } diff --git a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php index 465d2fe62..cbf53e8a6 100644 --- a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php @@ -3,14 +3,16 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedSettlementCapturesQuery; - +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedSettlementCapturesQueryFactory extends Factory { public function create(): GetPaginatedSettlementCapturesQuery { + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); + return new GetPaginatedSettlementCapturesQuery( PaginatedQueryFactory::new($this->data)->create(), - $this->get('include', []) + $this->get('includePayment', $includePayment) ); } } diff --git a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php index 009a82eb8..7f688d3b1 100644 --- a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php @@ -3,12 +3,13 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaginatedSettlementRefundsQuery; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedSettlementRefundsQueryFactory extends Factory { public function create(): GetPaginatedSettlementRefundsQuery { - $includePayment = $this->has(['filters.include', 'filters.includePayment']); + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); return new GetPaginatedSettlementRefundsQuery( PaginatedQueryFactory::new($this->data)->create(), diff --git a/src/Factories/GetPaymentCaptureQueryFactory.php b/src/Factories/GetPaymentCaptureQueryFactory.php index 235f957b4..7e06edd8a 100644 --- a/src/Factories/GetPaymentCaptureQueryFactory.php +++ b/src/Factories/GetPaymentCaptureQueryFactory.php @@ -3,13 +3,16 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaymentCaptureQuery; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentCaptureQueryFactory extends Factory { public function create(): GetPaymentCaptureQuery { + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); + return new GetPaymentCaptureQuery( - $this->get('include', []), + $this->get('includePayment', $includePayment), ); } } diff --git a/src/Factories/GetPaymentChargebackQueryFactory.php b/src/Factories/GetPaymentChargebackQueryFactory.php index fcaef86d9..53f9bb119 100644 --- a/src/Factories/GetPaymentChargebackQueryFactory.php +++ b/src/Factories/GetPaymentChargebackQueryFactory.php @@ -3,14 +3,16 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaymentChargebackQuery; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentChargebackQueryFactory extends Factory { public function create(): GetPaymentChargebackQuery { + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); + return new GetPaymentChargebackQuery( - include: $this->get('include', []), - testmode: $this->get('testmode', null) + $this->get('includePayment', $includePayment), ); } } diff --git a/src/Factories/GetPaymentMethodQueryFactory.php b/src/Factories/GetPaymentMethodQueryFactory.php index 7b2c17f75..809ecacb1 100644 --- a/src/Factories/GetPaymentMethodQueryFactory.php +++ b/src/Factories/GetPaymentMethodQueryFactory.php @@ -3,16 +3,21 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaymentMethodQuery; +use Mollie\Api\Types\MethodQuery; class GetPaymentMethodQueryFactory extends Factory { public function create(): GetPaymentMethodQuery { + $includeIssuers = $this->includes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); + return new GetPaymentMethodQuery( $this->get('locale'), $this->get('currency'), $this->get('profileId'), - $this->get('include'), + $this->get('includeIssuers', $includeIssuers), + $this->get('includePricing', $includePricing), ); } } diff --git a/src/Factories/GetPaymentQueryFactory.php b/src/Factories/GetPaymentQueryFactory.php index 6245ffb0e..1af71fc43 100644 --- a/src/Factories/GetPaymentQueryFactory.php +++ b/src/Factories/GetPaymentQueryFactory.php @@ -3,15 +3,24 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaymentQuery; +use Mollie\Api\Types\PaymentQuery; class GetPaymentQueryFactory extends Factory { public function create(): GetPaymentQuery { + $embedCaptures = $this->includes('embed', PaymentQuery::EMBED_CAPTURES); + $embedRefunds = $this->includes('embed', PaymentQuery::EMBED_REFUNDS); + $embedChargebacks = $this->includes('embed', PaymentQuery::EMBED_CHARGEBACKS); + $includeQrCode = $this->includes('include', PaymentQuery::INCLUDE_QR_CODE); + $includeRemainderDetails = $this->includes('include', PaymentQuery::INCLUDE_REMAINDER_DETAILS); + return new GetPaymentQuery( - $this->get('embed', []), - $this->get('include', []), - $this->get('testmode') + $this->get('embedCaptures', $embedCaptures), + $this->get('embedRefunds', $embedRefunds), + $this->get('embedChargebacks', $embedChargebacks), + $this->get('includeQrCode', $includeQrCode), + $this->get('includeRemainderDetails', $includeRemainderDetails), ); } } diff --git a/src/Factories/GetPaymentRefundQueryFactory.php b/src/Factories/GetPaymentRefundQueryFactory.php index d509c30e1..879990e34 100644 --- a/src/Factories/GetPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaymentRefundQueryFactory.php @@ -3,13 +3,15 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Query\GetPaymentRefundQuery; - +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentRefundQueryFactory extends Factory { public function create(): GetPaymentRefundQuery { + $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); + return new GetPaymentRefundQuery( - $this->get('include', []), + $this->get('includePayment', $includePayment), ); } } diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index 17b665c0f..bc17dadeb 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -85,4 +85,27 @@ public static function wrap($array): array { return is_array($array) ? $array : [$array]; } + + /** + * Check if a value exists in an array of includes. + * @param array $array + * @param string|array $key + * @param mixed $value + * + * @example includes(['includes' => ['payment']], 'includes', 'payment') => true + * @example includes(['includes' => ['refund']], 'includes', 'payment') => false + * @example includes(['includes' => ['payment' => 'foo']], 'includes.payment', 'foo') => true + */ + public static function includes(array $array, $key, $value): bool + { + $keys = (array) $key; + + foreach ($keys as $k) { + if (Arr::has($array, $k) && in_array($value, Arr::wrap(Arr::get($array, $k, [])))) { + return true; + } + } + + return false; + } } diff --git a/src/Http/Query/CreatePaymentQuery.php b/src/Http/Query/CreatePaymentQuery.php index fa691e119..ebe90b01e 100644 --- a/src/Http/Query/CreatePaymentQuery.php +++ b/src/Http/Query/CreatePaymentQuery.php @@ -3,23 +3,24 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Traits\ComposableFromArray; +use Mollie\Api\Types\PaymentQuery; class CreatePaymentQuery extends Query { use ComposableFromArray; - public ?string $include = null; + private bool $includeQrCode; public function __construct( - ?string $include = null + bool $includeQrCode = false, ) { - $this->include = $include; + $this->includeQrCode = $includeQrCode; } public function toArray(): array { return [ - 'include' => $this->include, + 'include' => $this->includeQrCode ? PaymentQuery::INCLUDE_QR_CODE : null, ]; } } diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php index 9137229b0..967d24767 100644 --- a/src/Http/Query/GetAllMethodsQuery.php +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -2,31 +2,38 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Helpers\Arr; use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Types\MethodQuery; class GetAllMethodsQuery extends Query { private string $locale; - private array $include; + private bool $includeIssuers; + + private bool $includePricing; private ?Money $amount; public function __construct( string $locale, - array $include = [], + bool $includeIssuers = false, + bool $includePricing = false, ?Money $amount = null, ) { $this->locale = $locale; - $this->include = $include; + $this->includeIssuers = $includeIssuers; + $this->includePricing = $includePricing; $this->amount = $amount; } public function toArray(): array { return [ - 'include' => Arr::join($this->include), + 'include' => array_filter([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), 'locale' => $this->locale, 'amount' => $this->amount?->data(), ]; diff --git a/src/Http/Query/GetClientQuery.php b/src/Http/Query/GetClientQuery.php new file mode 100644 index 000000000..98608b449 --- /dev/null +++ b/src/Http/Query/GetClientQuery.php @@ -0,0 +1,30 @@ +embedOrganization = $embedOrganization; + $this->embedOnboarding = $embedOnboarding; + } + + public function toArray(): array + { + return [ + 'embed' => Arr::join([ + $this->embedOrganization ? ClientQuery::EMBED_ORGANIZATION : null, + $this->embedOnboarding ? ClientQuery::EMBED_ONBOARDING : null, + ]), + ]; + } +} diff --git a/src/Http/Query/GetEnabledMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php similarity index 75% rename from src/Http/Query/GetEnabledMethodsQuery.php rename to src/Http/Query/GetEnabledPaymentMethodsQuery.php index fd36a45b2..e2dfde18e 100644 --- a/src/Http/Query/GetEnabledMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -6,7 +6,7 @@ use Mollie\Api\Http\Payload\Money; use Mollie\Api\Types\MethodQuery; -class GetEnabledMethodsQuery extends Query +class GetEnabledPaymentMethodsQuery extends Query { public function __construct( private string $sequenceType = MethodQuery::SEQUENCE_TYPE_ONEOFF, @@ -17,7 +17,8 @@ public function __construct( private ?array $includeWallets = null, private ?array $orderLineCategories = null, private ?string $profileId = null, - private ?array $include = null, + private ?bool $includeIssuers = null, + private ?bool $includePricing = null, ) {} public function toArray(): array @@ -31,7 +32,10 @@ public function toArray(): array 'includeWallets' => Arr::join($this->includeWallets), 'orderLineCategories' => Arr::join($this->orderLineCategories), 'profileId' => $this->profileId, - 'include' => Arr::join($this->include), + 'include' => array_filter([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), ]; } } diff --git a/src/Http/Query/GetPaginatedChargebackQuery.php b/src/Http/Query/GetPaginatedChargebackQuery.php index 1eb7e916e..edb4afb77 100644 --- a/src/Http/Query/GetPaginatedChargebackQuery.php +++ b/src/Http/Query/GetPaginatedChargebackQuery.php @@ -2,6 +2,8 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaginatedChargebackQuery extends Query { private PaginatedQuery $paginatedQuery; @@ -25,7 +27,7 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'include' => $this->includePayment ? 'payment' : null, + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, 'profileId' => $this->profileId, ] ); diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index 682b9f73e..4435822c8 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -3,19 +3,22 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; - +use Mollie\Api\Types\ClientQuery; class GetPaginatedClientQuery extends Query { private PaginatedQuery $paginatedQuery; - public array $embed = []; + private bool $embedOrganization; + private bool $embedOnboarding; public function __construct( PaginatedQuery $paginatedQuery, - array $embed = [] + bool $embedOrganization = false, + bool $embedOnboarding = false, ) { $this->paginatedQuery = $paginatedQuery; - $this->embed = $embed; + $this->embedOrganization = $embedOrganization; + $this->embedOnboarding = $embedOnboarding; } public function toArray(): array @@ -23,7 +26,10 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'embed' => Arr::join($this->embed), + 'embed' => Arr::join([ + $this->embedOrganization ? ClientQuery::EMBED_ORGANIZATION : null, + $this->embedOnboarding ? ClientQuery::EMBED_ONBOARDING : null, + ]), ] ); } diff --git a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php index 70f9a36b7..4bfbaff4c 100644 --- a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php @@ -3,19 +3,20 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentCapturesQuery extends Query { private PaginatedQuery $paginatedQuery; - public array $include = []; + public bool $includePayment = false; public function __construct( PaginatedQuery $paginatedQuery, - array $include = [] + bool $includePayment = false ) { $this->paginatedQuery = $paginatedQuery; - $this->include = $include; + $this->includePayment = $includePayment; } public function toArray(): array @@ -23,7 +24,7 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'include' => Arr::join($this->include), + 'include' => Arr::join($this->includePayment ? [PaymentIncludesQuery::PAYMENT] : []), ] ); } diff --git a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php index b46bda9bd..c0b2f54c9 100644 --- a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php +++ b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php @@ -2,20 +2,20 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentChargebacksQuery extends Query { private PaginatedQuery $paginatedQuery; - public array $include = []; + public bool $includePayment = false; public function __construct( PaginatedQuery $paginatedQuery, - array $include = [] + bool $includePayment = false ) { $this->paginatedQuery = $paginatedQuery; - $this->include = $include; + $this->includePayment = $includePayment; } public function toArray(): array @@ -23,7 +23,7 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'include' => Arr::join($this->include), + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : [], ] ); } diff --git a/src/Http/Query/GetPaginatedPaymentRefundQuery.php b/src/Http/Query/GetPaginatedPaymentRefundQuery.php index 156c941f9..57eb50c49 100644 --- a/src/Http/Query/GetPaginatedPaymentRefundQuery.php +++ b/src/Http/Query/GetPaginatedPaymentRefundQuery.php @@ -2,6 +2,8 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaginatedPaymentRefundQuery extends Query { private PaginatedQuery $paginatedQuery; @@ -21,7 +23,7 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'include' => $this->includePayment ? 'payment' : null, + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, ] ); } diff --git a/src/Http/Query/GetPaginatedRefundsQuery.php b/src/Http/Query/GetPaginatedRefundsQuery.php index b4faaaa60..b26c870ea 100644 --- a/src/Http/Query/GetPaginatedRefundsQuery.php +++ b/src/Http/Query/GetPaginatedRefundsQuery.php @@ -2,23 +2,23 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedRefundsQuery extends Query { private PaginatedQuery $paginatedQuery; - public array $embed = []; + private bool $embedPayment; - public ?string $profileId = null; + private ?string $profileId; public function __construct( PaginatedQuery $paginatedQuery, - array $embed = [], + bool $embedPayment = false, ?string $profileId = null ) { $this->paginatedQuery = $paginatedQuery; - $this->embed = $embed; + $this->embedPayment = $embedPayment; $this->profileId = $profileId; } @@ -27,7 +27,7 @@ public function toArray(): array return array_merge( $this->paginatedQuery->toArray(), [ - 'embed' => Arr::join($this->embed), + 'embed' => $this->embedPayment ? PaymentIncludesQuery::PAYMENT : null, 'profileId' => $this->profileId, ] ); diff --git a/src/Http/Query/GetPaymentCaptureQuery.php b/src/Http/Query/GetPaymentCaptureQuery.php index 7ff491485..0501c22d7 100644 --- a/src/Http/Query/GetPaymentCaptureQuery.php +++ b/src/Http/Query/GetPaymentCaptureQuery.php @@ -3,21 +3,21 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; - +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentCaptureQuery extends Query { - public array $include = []; + public bool $includePayment = false; public function __construct( - array $include = [] + bool $includePayment = false ) { - $this->include = $include; + $this->includePayment = $includePayment; } public function toArray(): array { return [ - 'include' => Arr::join($this->include), + 'include' => Arr::join($this->includePayment ? [PaymentIncludesQuery::PAYMENT] : []), ]; } } diff --git a/src/Http/Query/GetPaymentChargebackQuery.php b/src/Http/Query/GetPaymentChargebackQuery.php index e6ee01686..fc00c064a 100644 --- a/src/Http/Query/GetPaymentChargebackQuery.php +++ b/src/Http/Query/GetPaymentChargebackQuery.php @@ -2,22 +2,22 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentChargebackQuery extends Query { - public array $include = []; + private bool $includePayment; public function __construct( - array $include = [] + bool $includePayment = false ) { - $this->include = $include; + $this->includePayment = $includePayment; } public function toArray(): array { return [ - 'include' => Arr::join($this->include), + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, ]; } } diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php index c2a8e3179..86e9e7a50 100644 --- a/src/Http/Query/GetPaymentMethodQuery.php +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -3,15 +3,29 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\MethodQuery; class GetPaymentMethodQuery extends Query { + private ?string $locale; + private ?string $currency; + private ?string $profileId; + private bool $includeIssuers; + private bool $includePricing; + public function __construct( - private ?string $locale = null, - private ?string $currency = null, - private ?string $profileId = null, - private ?array $include = null, - ) {} + ?string $locale = null, + ?string $currency = null, + ?string $profileId = null, + bool $includeIssuers = false, + bool $includePricing = false, + ) { + $this->locale = $locale; + $this->currency = $currency; + $this->profileId = $profileId; + $this->includeIssuers = $includeIssuers; + $this->includePricing = $includePricing; + } public function toArray(): array { @@ -19,7 +33,10 @@ public function toArray(): array 'locale' => $this->locale, 'currency' => $this->currency, 'profileId' => $this->profileId, - 'include' => $this->include ? Arr::join($this->include) : null, + 'include' => Arr::join([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), ]; } } diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php index dcccaac2a..f5778188a 100644 --- a/src/Http/Query/GetPaymentQuery.php +++ b/src/Http/Query/GetPaymentQuery.php @@ -3,26 +3,46 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentQuery; class GetPaymentQuery extends Query { - public array $embed = []; + public bool $embedCaptures = false; - public array $include = []; + public bool $embedRefunds = false; + + public bool $embedChargebacks = false; + + public bool $includeQrCode = false; + + public bool $includeRemainderDetails = false; public function __construct( - array $embed = [], - array $include = [], + bool $embedCaptures = false, + bool $embedRefunds = false, + bool $embedChargebacks = false, + bool $includeQrCode = false, + bool $includeRemainderDetails = false, ) { - $this->embed = $embed; - $this->include = $include; + $this->embedCaptures = $embedCaptures; + $this->embedRefunds = $embedRefunds; + $this->embedChargebacks = $embedChargebacks; + $this->includeQrCode = $includeQrCode; + $this->includeRemainderDetails = $includeRemainderDetails; } public function toArray(): array { return [ - 'embed' => Arr::join($this->embed), - 'include' => Arr::join($this->include), + 'embed' => Arr::join([ + $this->embedCaptures ? PaymentQuery::EMBED_CAPTURES : null, + $this->embedRefunds ? PaymentQuery::EMBED_REFUNDS : null, + $this->embedChargebacks ? PaymentQuery::EMBED_CHARGEBACKS : null, + ]), + 'include' => Arr::join([ + $this->includeQrCode ? PaymentQuery::INCLUDE_QR_CODE : null, + $this->includeRemainderDetails ? PaymentQuery::INCLUDE_REMAINDER_DETAILS : null, + ]), ]; } } diff --git a/src/Http/Query/GetPaymentRefundQuery.php b/src/Http/Query/GetPaymentRefundQuery.php index ee81ae896..54b7b0e4a 100644 --- a/src/Http/Query/GetPaymentRefundQuery.php +++ b/src/Http/Query/GetPaymentRefundQuery.php @@ -2,22 +2,22 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentRefundQuery extends Query { - public array $include = []; + private bool $includePayment; public function __construct( - array $include = [], + bool $includePayment = false, ) { - $this->include = $include; + $this->includePayment = $includePayment; } public function toArray(): array { return [ - 'include' => Arr::join($this->include), + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, ]; } } diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 1fdcee8a6..2073dda97 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Http\Query\GetClientQuery; use Mollie\Api\Resources\Client; use Mollie\Api\Types\Method; @@ -20,19 +20,17 @@ class GetClientRequest extends ResourceHydratableRequest private string $id; - private array $embed; + private GetClientQuery $query; - public function __construct(string $id, array $embed = []) + public function __construct(string $id, GetClientQuery $query) { $this->id = $id; - $this->embed = $embed; + $this->query = $query; } protected function defaultQuery(): array { - return [ - 'embed' => Arr::join($this->embed), - ]; + return $this->query->toArray(); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php index beee61729..8888b4d5b 100644 --- a/src/Http/Requests/GetEnabledMethodsRequest.php +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetEnabledMethodsQuery; +use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Types\Method as HttpMethod; @@ -13,9 +13,9 @@ class GetEnabledMethodsRequest extends ResourceHydratableRequest implements Supp public static string $targetResourceClass = MethodCollection::class; - private GetEnabledMethodsQuery $query; + private GetEnabledPaymentMethodsQuery $query; - public function __construct(GetEnabledMethodsQuery $query) + public function __construct(GetEnabledPaymentMethodsQuery $query) { $this->query = $query; } diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 50ec8bf09..d301df184 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -45,7 +45,6 @@ use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; -use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Traits\HandlesAuthentication; use Mollie\Api\Traits\HandlesAutoHydration; use Mollie\Api\Traits\HandlesDebugging; @@ -61,7 +60,7 @@ /** * @property BalanceEndpointCollection $balances * @property BalanceReportEndpointCollection $balanceReports - * @property BalanceTransactionCollection $balanceTransactions + * @property BalanceTransactionEndpointCollection $balanceTransactions * @property ChargebackEndpointCollection $chargebacks * @property ClientEndpointCollection $clients * @property ClientLinkEndpointCollection $clientLinks diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 59d7f8c6c..b7e54918d 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -7,6 +7,11 @@ abstract class CursorCollection extends BaseCollection { + /** + * Resource class name. + */ + public static string $resource = ''; + /** * Return the next set of resources when available * @@ -81,4 +86,13 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection } }); } + + public static function getResourceClass(): string + { + if (empty(static::$resource)) { + throw new \RuntimeException('Collection name not set'); + } + + return static::$resource; + } } diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 73587f960..f9fc7a863 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -3,6 +3,8 @@ namespace Mollie\Api\Traits; use Mollie\Api\EndpointCollection\BalanceEndpointCollection; +use Mollie\Api\EndpointCollection\BalanceReportEndpointCollection; +use Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection; use Mollie\Api\EndpointCollection\ChargebackEndpointCollection; use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; @@ -35,7 +37,6 @@ use Mollie\Api\EndpointCollection\WalletEndpointCollection; use Mollie\Api\Endpoints\ProfileMethodEndpoint; use Mollie\Api\MollieApiClient; -use Mollie\Api\Resources\BalanceTransactionCollection; /** * @mixin MollieApiClient @@ -54,8 +55,8 @@ protected function initializeHasEndpoints(): void $endpointClasses = [ 'balances' => BalanceEndpointCollection::class, - 'balanceReports' => BalanceEndpointCollection::class, - 'balanceTransactions' => BalanceTransactionCollection::class, + 'balanceReports' => BalanceReportEndpointCollection::class, + 'balanceTransactions' => BalanceTransactionEndpointCollection::class, 'chargebacks' => ChargebackEndpointCollection::class, 'clients' => ClientEndpointCollection::class, 'clientLinks' => ClientLinkEndpointCollection::class, diff --git a/src/Types/PaymentIncludesQuery.php b/src/Types/PaymentIncludesQuery.php index 11cb127b6..7b6da35ed 100644 --- a/src/Types/PaymentIncludesQuery.php +++ b/src/Types/PaymentIncludesQuery.php @@ -4,9 +4,9 @@ class PaymentIncludesQuery { - const INCLUDE_PAYMENT = 'payment'; + const PAYMENT = 'payment'; const INCLUDES = [ - self::INCLUDE_PAYMENT, + self::PAYMENT, ]; } diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 8b70a5024..4f152b429 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -9,7 +9,6 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; -use Mollie\Api\Types\BalanceTransferFrequency; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -21,7 +20,40 @@ class BalanceEndpointCollectionTest extends TestCase use AmountObjectTestHelpers; use LinkObjectTestHelpers; - public function test_list_balances() + /** @test */ + public function get() + { + $client = new MockClient([ + GetBalanceRequest::class => new MockResponse(200, 'balance'), + ]); + + /** @var Balance $balance */ + $balance = $client->balances->get('bal_gVMhHKqSSRYJyPsuoPNFH'); + + $this->assertBalance( + $balance, + 'bal_gVMhHKqSSRYJyPsuoPNFH', + ); + } + + /** @test */ + public function primary() + { + $client = new MockClient([ + GetBalanceRequest::class => new MockResponse(200, 'balance'), + ]); + + /** @var Balance $balance */ + $balance = $client->balances->primary(); + + $this->assertBalance( + $balance, + 'bal_gVMhHKqSSRYJyPsuoPNFH', + ); + } + + /** @test */ + public function page() { $client = new MockClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), @@ -35,7 +67,7 @@ public function test_list_balances() $this->assertCount(2, $balances); $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/balances-api/list-balances', + '...', 'text/html', $balances->_links->documentation ); @@ -47,50 +79,27 @@ public function test_list_balances() ); $this->assertLinkObject( - 'https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5', + '...', 'application/hal+json', $balances->_links->next ); - /** @var Balance $balanceA */ - $balanceA = $balances[0]; - - /** @var Balance $balanceB */ - $balanceB = $balances[1]; - $this->assertBalance( - $balanceA, + $balances[0], 'bal_gVMhHKqSSRYJyPsuoPNFH', - '2019-01-10T12:06:28+00:00', - BalanceTransferFrequency::DAILY, - '40.00', - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL53INGB0654422370', - 'bankAccountId' => 'bnk_jrty3f', - ] ); $this->assertBalance( - $balanceB, + $balances[1], 'bal_gVMhHKqSSRYJyPsuoPABC', - '2019-01-10T10:23:41+00:00', - BalanceTransferFrequency::TWICE_A_MONTH, - '5.00', - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL97MOLL6351480700', - 'bankAccountId' => 'bnk_jrty3e', - ] ); } - public function test_iterate_balances() + /** @test */ + public function iterate() { $client = new MockClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-balance-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'balances'), ]); foreach ($client->balances->iterator() as $balance) { @@ -98,84 +107,27 @@ public function test_iterate_balances() } } - public function test_get_balance() - { - $client = new MockClient([ - GetBalanceRequest::class => new MockResponse(200, 'balance'), - ]); - - /** @var Balance $balance */ - $balance = $client->balances->get('bal_gVMhHKqSSRYJyPsuoPNFH'); - - $this->assertBalance( - $balance, - 'bal_gVMhHKqSSRYJyPsuoPNFH', - '2019-01-10T10:23:41+00:00', - BalanceTransferFrequency::TWICE_A_MONTH, - '5.00', - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL53INGB0654422370', - 'bankAccountId' => 'bnk_jrty3f', - ] - ); - } - - public function test_get_primary_balance() - { - $client = new MockClient([ - GetBalanceRequest::class => new MockResponse(200, 'balance'), - ]); - - /** @var Balance $balance */ - $balance = $client->balances->primary(); - - $this->assertBalance( - $balance, - 'bal_gVMhHKqSSRYJyPsuoPNFH', - '2019-01-10T10:23:41+00:00', - BalanceTransferFrequency::TWICE_A_MONTH, - '5.00', - (object) [ - 'type' => 'bank-account', - 'beneficiaryName' => 'Jack Bauer', - 'bankAccount' => 'NL53INGB0654422370', - 'bankAccountId' => 'bnk_jrty3f', - ] - ); - } - /** * @return void */ protected function assertBalance( Balance $balance, string $balanceId, - string $createdAt, - string $transferFrequency, - string $thresholdValue, - \stdClass $destination ) { $this->assertInstanceOf(Balance::class, $balance); $this->assertEquals('balance', $balance->resource); $this->assertEquals($balanceId, $balance->id); - $this->assertEquals('live', $balance->mode); - $this->assertEquals($createdAt, $balance->createdAt); - $this->assertEquals('EUR', $balance->currency); - $this->assertAmountObject('0.00', 'EUR', $balance->availableAmount); - $this->assertAmountObject('0.00', 'EUR', $balance->incomingAmount); - $this->assertAmountObject('0.00', 'EUR', $balance->outgoingAmount); - $this->assertEquals($transferFrequency, $balance->transferFrequency); - $this->assertAmountObject($thresholdValue, 'EUR', $balance->transferThreshold); - $this->assertEquals('Mollie payout', $balance->transferReference); - $this->assertEquals($destination, $balance->transferDestination); - - $this->assertLinkObject( - "https://api.mollie.com/v2/balances/{$balanceId}", - 'application/hal+json', - $balance->_links->self - ); + $this->assertNotEmpty($balance->mode); + $this->assertNotEmpty($balance->createdAt); + $this->assertNotEmpty($balance->currency); + $this->assertNotNull($balance->availableAmount); + $this->assertNotNull($balance->incomingAmount); + $this->assertNotNull($balance->outgoingAmount); + $this->assertNotEmpty($balance->transferFrequency); + $this->assertNotNull($balance->transferThreshold); + $this->assertNotEmpty($balance->transferReference); + $this->assertNotNull($balance->transferDestination); + $this->assertNotNull($balance->_links->self); } } diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php new file mode 100644 index 000000000..057dc6757 --- /dev/null +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -0,0 +1,90 @@ + new MockResponse(200, 'balance-report', 'bal_gVMhHKqSSRYJyPsuoPNFH'), + ]); + + /** @var BalanceReport $report */ + $report = $client->balanceReports->getForId('bal_gVMhHKqSSRYJyPsuoPNFH', [ + 'from' => '2021-01-01', + 'until' => '2021-02-01', + 'grouping' => 'transaction-categories' + ]); + + $this->assertBalanceReport($report, 'bal_gVMhHKqSSRYJyPsuoPNFH'); + } + + /** @test */ + public function get_for_balance() + { + $client = new MockClient([ + GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_gVMhHKqSSRYJyPsuoPNFH'), + ]); + + $balance = new Balance($client); + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + + /** @var BalanceReport $report */ + $report = $client->balanceReports->getFor($balance, [ + 'from' => '2021-01-01', + 'until' => '2021-02-01', + 'grouping' => 'transaction-categories' + ]); + + $this->assertBalanceReport($report, 'bal_gVMhHKqSSRYJyPsuoPNFH'); + } + + /** @test */ + public function get_for_primary() + { + $client = new MockClient([ + GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_primary'), + ]); + + /** @var BalanceReport $report */ + $report = $client->balanceReports->getForPrimary([ + 'from' => '2024-01-01', + 'until' => '2024-01-31', + 'grouping' => 'transaction-categories' + ]); + + $this->assertBalanceReport($report, 'bal_primary'); + } + + protected function assertBalanceReport(BalanceReport $report, string $balanceId) + { + $this->assertInstanceOf(BalanceReport::class, $report); + $this->assertEquals('balance-report', $report->resource); + $this->assertEquals($balanceId, $report->balanceId); + $this->assertNotEmpty($report->timeZone); + $this->assertNotEmpty($report->from); + $this->assertNotEmpty($report->until); + $this->assertNotEmpty($report->grouping); + + $this->assertNotNull($report->totals->open->available->amount); + $this->assertNotNull($report->totals->open->pending->amount); + $this->assertNotNull($report->totals->payments->immediatelyAvailable->amount); + $this->assertNotNull($report->totals->payments->pending->amount); + } +} diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php new file mode 100644 index 000000000..8487940cd --- /dev/null +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -0,0 +1,64 @@ + new MockResponse(200, 'balance-transactions'), + ]); + + $balance = new Balance($client); + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + + /** @var BalanceTransactionCollection $transactions */ + $transactions = $client->balanceTransactions->pageFor($balance); + + $this->assertInstanceOf(BalanceTransactionCollection::class, $transactions); + $this->assertGreaterThan(0, $transactions->count()); + + foreach ($transactions as $transaction) { + $this->assertBalanceTransaction($transaction); + } + } + + /** @test */ + public function iterator_for() + { + $client = new MockClient([ + GetPaginatedBalanceTransactionRequest::class => new MockResponse(200, 'balance-transactions'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'balance_transactions'), + ]); + + $balance = new Balance($client); + $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + + foreach ($client->balanceTransactions->iteratorFor($balance) as $transaction) { + $this->assertBalanceTransaction($transaction); + } + } + + protected function assertBalanceTransaction(BalanceTransaction $transaction) + { + $this->assertInstanceOf(BalanceTransaction::class, $transaction); + $this->assertEquals('balance_transaction', $transaction->resource); + $this->assertNotEmpty($transaction->id); + $this->assertNotEmpty($transaction->type); + $this->assertNotEmpty($transaction->resultAmount); + $this->assertNotEmpty($transaction->initialAmount); + $this->assertNotEmpty($transaction->deductions); + $this->assertNotEmpty($transaction->context); + } +} diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php new file mode 100644 index 000000000..f9d96a817 --- /dev/null +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -0,0 +1,54 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + /** @var ChargebackCollection $chargebacks */ + $chargebacks = $client->chargebacks->page(); + + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertChargeback($chargeback); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + ]); + + foreach ($client->chargebacks->iterator() as $chargeback) { + $this->assertChargeback($chargeback); + } + } + + protected function assertChargeback(Chargeback $chargeback) + { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + $this->assertNotEmpty($chargeback->id); + $this->assertNotEmpty($chargeback->amount); + $this->assertNotEmpty($chargeback->settlementAmount); + $this->assertNotEmpty($chargeback->createdAt); + $this->assertNotEmpty($chargeback->paymentId); + } +} diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php new file mode 100644 index 000000000..3bf9ab65d --- /dev/null +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -0,0 +1,66 @@ + new MockResponse(200, 'client'), + ]); + + /** @var Client $clientResource */ + $clientResource = $client->clients->get('org_12345678'); + + $this->assertClient($clientResource); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), + ]); + + /** @var ClientCollection $clients */ + $clients = $client->clients->page(); + + $this->assertInstanceOf(ClientCollection::class, $clients); + $this->assertGreaterThan(0, $clients->count()); + + foreach ($clients as $clientResource) { + $this->assertClient($clientResource); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), + ]); + + foreach ($client->clients->iterator() as $clientResource) { + $this->assertClient($clientResource); + } + } + + protected function assertClient(Client $client) + { + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals('client', $client->resource); + $this->assertNotEmpty($client->id); + $this->assertNotEmpty($client->organizationCreatedAt); + $this->assertNotEmpty($client->_links); + } +} diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php new file mode 100644 index 000000000..dcd3617e5 --- /dev/null +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -0,0 +1,31 @@ + new MockResponse(201, 'client-link'), + ]); + + /** @var ClientLink $clientLink */ + $clientLink = $client->clientLinks->create([ + 'ownerId' => 'org_12345678', + 'name' => 'Test Client Link', + ]); + + $this->assertInstanceOf(ClientLink::class, $clientLink); + $this->assertEquals('client-link', $clientLink->resource); + $this->assertNotEmpty($clientLink->id); + $this->assertNotEmpty($clientLink->_links); + } +} diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php new file mode 100644 index 000000000..dec099d12 --- /dev/null +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -0,0 +1,117 @@ + new MockResponse(201, 'customer'), + ]); + + /** @var Customer $customer */ + $customer = $client->customers->create([ + 'name' => 'John Doe', + 'email' => 'john@example.org', + ]); + + $this->assertCustomer($customer); + } + + /** @test */ + public function get() + { + $client = new MockClient([ + GetCustomerRequest::class => new MockResponse(200, 'customer'), + ]); + + /** @var Customer $customer */ + $customer = $client->customers->get('cst_kEn1PlbGa'); + + $this->assertCustomer($customer); + } + + /** @test */ + public function update() + { + $client = new MockClient([ + UpdateCustomerRequest::class => new MockResponse(200, 'customer'), + ]); + + /** @var Customer $customer */ + $customer = $client->customers->update('cst_kEn1PlbGa', [ + 'name' => 'Updated Name', + 'email' => 'updated@example.org', + ]); + + $this->assertCustomer($customer); + } + + /** @test */ + public function delete() + { + $client = new MockClient([ + DeleteCustomerRequest::class => new MockResponse(204), + ]); + + $client->customers->delete('cst_kEn1PlbGa'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page() + { + $client = new MockClient([ + GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), + ]); + + /** @var CustomerCollection $customers */ + $customers = $client->customers->page(); + + $this->assertInstanceOf(CustomerCollection::class, $customers); + $this->assertGreaterThan(0, $customers->count()); + + foreach ($customers as $customer) { + $this->assertCustomer($customer); + } + } + + /** @test */ + public function iterator() + { + $client = new MockClient([ + GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), + ]); + + foreach ($client->customers->iterator() as $customer) { + $this->assertCustomer($customer); + } + } + + protected function assertCustomer(Customer $customer) + { + $this->assertInstanceOf(Customer::class, $customer); + $this->assertEquals('customer', $customer->resource); + $this->assertNotEmpty($customer->id); + $this->assertNotEmpty($customer->mode); + $this->assertNotEmpty($customer->name); + $this->assertNotEmpty($customer->email); + $this->assertNotEmpty($customer->createdAt); + $this->assertNotEmpty($customer->_links); + } +} diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php new file mode 100644 index 000000000..93c214d20 --- /dev/null +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -0,0 +1,90 @@ + new MockResponse(201, 'payment'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var Payment $payment */ + $payment = $client->customerPayments->createFor($customer, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'description' => 'Test payment', + 'redirectUrl' => 'https://example.org/redirect', + ]); + + $this->assertPayment($payment); + } + + /** @test */ + public function page_for() + { + $client = new MockClient([ + GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var PaymentCollection $payments */ + $payments = $client->customerPayments->pageFor($customer); + + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertPayment($payment); + } + } + + /** @test */ + public function iterator_for() + { + $client = new MockClient([ + GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + foreach ($client->customerPayments->iteratorFor($customer) as $payment) { + $this->assertPayment($payment); + } + } + + protected function assertPayment(Payment $payment) + { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + $this->assertNotEmpty($payment->id); + $this->assertNotEmpty($payment->mode); + $this->assertNotEmpty($payment->createdAt); + $this->assertNotEmpty($payment->status); + $this->assertNotEmpty($payment->amount); + $this->assertNotEmpty($payment->description); + $this->assertNotEmpty($payment->method); + $this->assertNotEmpty($payment->metadata); + $this->assertNotEmpty($payment->profileId); + $this->assertNotEmpty($payment->_links); + } +} diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php new file mode 100644 index 000000000..d7a9d8cab --- /dev/null +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -0,0 +1,73 @@ + new MockResponse(200, 'invoice'), + ]); + + /** @var Invoice $invoice */ + $invoice = $client->invoices->get('inv_xBEbP9rvAq'); + + $this->assertInvoice($invoice); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), + ]); + + /** @var InvoiceCollection $invoices */ + $invoices = $client->invoices->page(); + + $this->assertInstanceOf(InvoiceCollection::class, $invoices); + $this->assertEquals(1, $invoices->count()); + $this->assertCount(1, $invoices); + + $this->assertInvoice($invoices[0]); + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), + ]); + + foreach ($client->invoices->iterator() as $invoice) { + $this->assertInstanceOf(Invoice::class, $invoice); + $this->assertInvoice($invoice); + } + } + + protected function assertInvoice(Invoice $invoice) + { + $this->assertInstanceOf(Invoice::class, $invoice); + $this->assertEquals('invoice', $invoice->resource); + $this->assertEquals('2023.10000', $invoice->reference); + $this->assertEquals('NL001234567B01', $invoice->vatNumber); + $this->assertEquals('open', $invoice->status); + $this->assertEquals('45.00', $invoice->netAmount->value); + $this->assertEquals('EUR', $invoice->netAmount->currency); + $this->assertEquals('9.45', $invoice->vatAmount->value); + $this->assertEquals('54.45', $invoice->grossAmount->value); + $this->assertNotEmpty($invoice->lines); + $this->assertEquals('2023-09-01', $invoice->issuedAt); + $this->assertEquals('2023-09-14', $invoice->dueAt); + } +} diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php new file mode 100644 index 000000000..b7f6fbcd8 --- /dev/null +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -0,0 +1,105 @@ + new MockResponse(201, 'mandate'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_4qqhO89gsT'; + + /** @var Mandate $mandate */ + $mandate = $client->mandates->createFor($customer, [ + 'method' => 'directdebit', + 'consumerName' => 'John Doe', + 'consumerAccount' => 'NL55INGB0000000000', + 'consumerBic' => 'INGBNL2A', + 'signatureDate' => '2023-05-07', + 'mandateReference' => 'EXAMPLE-CORP-MD13804', + ]); + + $this->assertMandate($mandate); + } + + /** @test */ + public function get_for_test() + { + $client = new MockClient([ + GetMandateRequest::class => new MockResponse(200, 'mandate'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_4qqhO89gsT'; + + /** @var Mandate $mandate */ + $mandate = $client->mandates->getFor($customer, 'mdt_h3gAaD5zP'); + + $this->assertMandate($mandate); + } + + /** @test */ + public function revoke_for_test() + { + $client = new MockClient([ + RevokeMandateRequest::class => new MockResponse(204), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_4qqhO89gsT'; + + $client->mandates->revokeFor($customer, 'mdt_h3gAaD5zP'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page_for_test() + { + $client = new MockClient([ + GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_4qqhO89gsT'; + + /** @var MandateCollection $mandates */ + $mandates = $client->mandates->pageFor($customer); + + $this->assertInstanceOf(MandateCollection::class, $mandates); + $this->assertEquals(1, $mandates->count()); + $this->assertCount(1, $mandates); + + $this->assertMandate($mandates[0]); + } + + protected function assertMandate(Mandate $mandate) + { + $this->assertInstanceOf(Mandate::class, $mandate); + $this->assertEquals('mandate', $mandate->resource); + $this->assertEquals('live', $mandate->mode); + $this->assertEquals('valid', $mandate->status); + $this->assertEquals('directdebit', $mandate->method); + $this->assertEquals('EXAMPLE-CORP-MD13804', $mandate->mandateReference); + $this->assertEquals('2023-05-07', $mandate->signatureDate); + $this->assertEquals('cst_4qqhO89gsT', $mandate->customerId); + $this->assertNotEmpty($mandate->createdAt); + } +} diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php new file mode 100644 index 000000000..f18af466b --- /dev/null +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -0,0 +1,77 @@ + new MockResponse(200, 'method'), + ]); + + /** @var Method $method */ + $method = $client->methods->get('ideal'); + + $this->assertMethod($method); + } + + /** @test */ + public function all_test() + { + $client = new MockClient([ + GetAllMethodsRequest::class => new MockResponse(200, 'method-list'), + ]); + + /** @var MethodCollection $methods */ + $methods = $client->methods->all(); + + $this->assertInstanceOf(MethodCollection::class, $methods); + $this->assertEquals(2, $methods->count()); + $this->assertCount(2, $methods); + + foreach ($methods as $method) { + $this->assertInstanceOf(Method::class, $method); + $this->assertNotEmpty($method->id); + $this->assertNotEmpty($method->description); + $this->assertNotEmpty($method->status); + } + } + + /** @test */ + public function all_enabled_test() + { + $client = new MockClient([ + GetEnabledMethodsRequest::class => new MockResponse(200, 'method-list'), + ]); + + /** @var MethodCollection $methods */ + $methods = $client->methods->allEnabled(); + + $this->assertInstanceOf(MethodCollection::class, $methods); + $this->assertEquals(2, $methods->count()); + $this->assertCount(2, $methods); + } + + protected function assertMethod(Method $method) + { + $this->assertInstanceOf(Method::class, $method); + $this->assertEquals('method', $method->resource); + $this->assertEquals('iDEAL', $method->description); + $this->assertEquals('0.01', $method->minimumAmount->value); + $this->assertEquals('EUR', $method->minimumAmount->currency); + $this->assertEquals('50000.00', $method->maximumAmount->value); + $this->assertEquals('activated', $method->status); + $this->assertNotEmpty($method->image); + } +} diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php new file mode 100644 index 000000000..fa2489508 --- /dev/null +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -0,0 +1,58 @@ + new MockResponse(200, 'issuer'), + ]); + + /** @var Issuer $issuer */ + $issuer = $client->methodIssuers->enable( + 'pfl_v9hTwCvYqw', + 'ideal', + 'ideal_INGBNL2A', + 'ctr_123xyz' + ); + + $this->assertIssuer($issuer); + } + + /** @test */ + public function disable() + { + $client = new MockClient([ + DisableMethodIssuerRequest::class => new MockResponse(204), + ]); + + $client->methodIssuers->disable( + 'pfl_v9hTwCvYqw', + 'ideal', + 'ideal_INGBNL2A' + ); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + protected function assertIssuer(Issuer $issuer) + { + $this->assertInstanceOf(Issuer::class, $issuer); + $this->assertEquals('issuer', $issuer->resource); + $this->assertNotEmpty($issuer->id); + $this->assertNotEmpty($issuer->description); + $this->assertNotEmpty($issuer->status); + $this->assertNotEmpty($issuer->_links); + } +} diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php new file mode 100644 index 000000000..8ae875946 --- /dev/null +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -0,0 +1,30 @@ + new MockResponse(200, 'onboarding'), + ]); + + /** @var Onboarding $onboarding */ + $onboarding = $client->onboarding->status(); + + $this->assertInstanceOf(Onboarding::class, $onboarding); + $this->assertEquals('onboarding', $onboarding->resource); + $this->assertNotEmpty($onboarding->name); + $this->assertNotEmpty($onboarding->status); + $this->assertNotEmpty($onboarding->canReceivePayments); + $this->assertNotEmpty($onboarding->canReceiveSettlements); + } +} diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php new file mode 100644 index 000000000..c11ca487d --- /dev/null +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -0,0 +1,70 @@ + new MockResponse(200, 'organization'), + ]); + + /** @var Organization $organization */ + $organization = $client->organizations->get('org_12345678'); + + $this->assertOrganization($organization); + } + + /** @test */ + public function current_test() + { + $client = new MockClient([ + GetOrganizationRequest::class => new MockResponse(200, 'organization'), + ]); + + /** @var Organization $organization */ + $organization = $client->organizations->current(); + + $this->assertOrganization($organization); + } + + /** @test */ + public function partner_status_test() + { + $client = new MockClient([ + GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner'), + ]); + + /** @var Partner $partner */ + $partner = $client->organizations->partnerStatus(); + + $this->assertInstanceOf(Partner::class, $partner); + $this->assertEquals('partner', $partner->resource); + $this->assertNotEmpty($partner->partnerType); + $this->assertNotEmpty($partner->partnerContractSignedAt); + $this->assertNotEmpty($partner->_links); + } + + protected function assertOrganization(Organization $organization) + { + $this->assertInstanceOf(Organization::class, $organization); + $this->assertEquals('organization', $organization->resource); + $this->assertNotEmpty($organization->id); + $this->assertNotEmpty($organization->name); + $this->assertNotEmpty($organization->email); + $this->assertNotEmpty($organization->locale); + $this->assertNotEmpty($organization->address); + $this->assertNotEmpty($organization->registrationNumber); + $this->assertNotEmpty($organization->vatRegulation); + } +} diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php new file mode 100644 index 000000000..fce305d7e --- /dev/null +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -0,0 +1,29 @@ + new MockResponse(200, 'partner'), + ]); + + /** @var Partner $partner */ + $partner = $client->organizationPartner->status(); + + $this->assertInstanceOf(Partner::class, $partner); + $this->assertEquals('partner', $partner->resource); + $this->assertNotEmpty($partner->partnerType); + $this->assertNotEmpty($partner->partnerContractSignedAt); + $this->assertNotEmpty($partner->_links); + } +} diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php new file mode 100644 index 000000000..8fba8002e --- /dev/null +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -0,0 +1,104 @@ + new MockResponse(201, 'capture'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Capture $capture */ + $capture = $client->paymentCaptures->createFor($payment, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '35.95' + ], + 'description' => 'Capture for cart #12345', + ]); + + $this->assertCapture($capture); + } + + /** @test */ + public function get_for_test() + { + $client = new MockClient([ + GetPaymentCaptureRequest::class => new MockResponse(200, 'capture'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Capture $capture */ + $capture = $client->paymentCaptures->getFor($payment, 'cpt_mNepDkEtco6ah3QNPUGYH'); + + $this->assertCapture($capture); + } + + /** @test */ + public function page_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var CaptureCollection $captures */ + $captures = $client->paymentCaptures->pageFor($payment); + + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertEquals(1, $captures->count()); + $this->assertCount(1, $captures); + + $this->assertCapture($captures[0]); + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + foreach ($client->paymentCaptures->iteratorFor($payment) as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertCapture($capture); + } + } + + protected function assertCapture(Capture $capture) + { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + $this->assertNotEmpty($capture->id); + $this->assertEquals('live', $capture->mode); + $this->assertEquals('Capture for cart #12345', $capture->description); + $this->assertEquals('35.95', $capture->amount->value); + $this->assertEquals('EUR', $capture->amount->currency); + $this->assertEquals('tr_7UhSN1zuXS', $capture->paymentId); + $this->assertNotEmpty($capture->createdAt); + $this->assertNotEmpty($capture->_links); + } +} diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php new file mode 100644 index 000000000..01a056131 --- /dev/null +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -0,0 +1,81 @@ + new MockResponse(200, 'chargeback'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Chargeback $chargeback */ + $chargeback = $client->paymentChargebacks->getFor($payment, 'chb_n9z0tp'); + + $this->assertChargeback($chargeback); + } + + /** @test */ + public function page_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var ChargebackCollection $chargebacks */ + $chargebacks = $client->paymentChargebacks->pageFor($payment); + + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + $this->assertGreaterThan(0, count($chargebacks)); + + foreach ($chargebacks as $chargeback) { + $this->assertChargeback($chargeback); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + foreach ($client->paymentChargebacks->iteratorFor($payment) as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertChargeback($chargeback); + } + } + + protected function assertChargeback(Chargeback $chargeback) + { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + $this->assertNotEmpty($chargeback->id); + $this->assertNotEmpty($chargeback->amount); + $this->assertNotEmpty($chargeback->settlementAmount); + $this->assertNotEmpty($chargeback->createdAt); + $this->assertEquals('tr_7UhSN1zuXS', $chargeback->paymentId); + $this->assertNotEmpty($chargeback->_links); + } +} diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php new file mode 100644 index 000000000..ae5ba9cce --- /dev/null +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -0,0 +1,156 @@ + new MockResponse(201, 'payment'), + ]); + + /** @var Payment $payment */ + $payment = $client->payments->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'description' => 'Test payment', + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + ]); + + $this->assertPayment($payment); + } + + /** @test */ + public function get_test() + { + $client = new MockClient([ + GetPaymentRequest::class => new MockResponse(200, 'payment'), + ]); + + /** @var Payment $payment */ + $payment = $client->payments->get('tr_WDqYK6vllg'); + + $this->assertPayment($payment); + } + + /** @test */ + public function update_test() + { + $client = new MockClient([ + UpdatePaymentRequest::class => new MockResponse(200, 'payment'), + ]); + + /** @var Payment $payment */ + $payment = $client->payments->update('tr_WDqYK6vllg', [ + 'description' => 'Updated description', + 'redirectUrl' => 'https://example.org/updated-redirect', + ]); + + $this->assertPayment($payment); + } + + /** @test */ + public function cancel_test() + { + $client = new MockClient([ + CancelPaymentRequest::class => new MockResponse(204), + ]); + + $payment = $client->payments->cancel('tr_WDqYK6vllg'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function refund_test() + { + $client = new MockClient([ + CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_WDqYK6vllg'; + + /** @var Refund $refund */ + $refund = $client->payments->refund($payment, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '5.95', + ], + 'description' => 'Test refund', + ]); + + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + $this->assertNotEmpty($refund->id); + $this->assertEquals('5.95', $refund->amount->value); + $this->assertEquals('EUR', $refund->amount->currency); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + /** @var PaymentCollection $payments */ + $payments = $client->payments->page(); + + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + $this->assertGreaterThan(0, count($payments)); + + foreach ($payments as $payment) { + $this->assertPayment($payment); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + foreach ($client->payments->iterator() as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertPayment($payment); + } + } + + protected function assertPayment(Payment $payment) + { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + $this->assertNotEmpty($payment->id); + $this->assertNotEmpty($payment->mode); + $this->assertNotEmpty($payment->createdAt); + $this->assertNotEmpty($payment->status); + $this->assertNotEmpty($payment->amount); + $this->assertNotEmpty($payment->description); + $this->assertNotEmpty($payment->method); + $this->assertNotEmpty($payment->metadata); + $this->assertNotEmpty($payment->profileId); + $this->assertNotEmpty($payment->settlementAmount); + } +} diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php new file mode 100644 index 000000000..1bcc4c435 --- /dev/null +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -0,0 +1,123 @@ + new MockResponse(201, 'payment-link'), + ]); + + /** @var PaymentLink $paymentLink */ + $paymentLink = $client->paymentLinks->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'description' => 'Test payment link', + 'expiresAt' => '2023-12-31', + 'webhookUrl' => 'https://example.org/webhook', + ]); + + $this->assertPaymentLink($paymentLink); + } + + /** @test */ + public function get_test() + { + $client = new MockClient([ + GetPaymentLinkRequest::class => new MockResponse(200, 'payment-link'), + ]); + + /** @var PaymentLink $paymentLink */ + $paymentLink = $client->paymentLinks->get('pl_4Y0eZitmBnQ6IDoMqZQKh'); + + $this->assertPaymentLink($paymentLink); + } + + /** @test */ + public function update_test() + { + $client = new MockClient([ + UpdatePaymentLinkRequest::class => new MockResponse(200, 'payment-link'), + ]); + + /** @var PaymentLink $paymentLink */ + $paymentLink = $client->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', [ + 'description' => 'Updated description', + 'expiresAt' => '2024-01-01', + ]); + + $this->assertPaymentLink($paymentLink); + } + + /** @test */ + public function delete_test() + { + $client = new MockClient([ + DeletePaymentLinkRequest::class => new MockResponse(204), + ]); + + $client->paymentLinks->delete('pl_4Y0eZitmBnQ6IDoMqZQKh'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), + ]); + + /** @var PaymentLinkCollection $paymentLinks */ + $paymentLinks = $client->paymentLinks->page(); + + $this->assertInstanceOf(PaymentLinkCollection::class, $paymentLinks); + $this->assertGreaterThan(0, $paymentLinks->count()); + $this->assertGreaterThan(0, count($paymentLinks)); + + foreach ($paymentLinks as $paymentLink) { + $this->assertPaymentLink($paymentLink); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), + ]); + + foreach ($client->paymentLinks->iterator() as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertPaymentLink($paymentLink); + } + } + + protected function assertPaymentLink(PaymentLink $paymentLink) + { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + $this->assertNotEmpty($paymentLink->id); + $this->assertNotEmpty($paymentLink->description); + $this->assertNotEmpty($paymentLink->amount); + $this->assertNotEmpty($paymentLink->expiresAt); + $this->assertNotEmpty($paymentLink->_links); + } +} diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php new file mode 100644 index 000000000..222f38f32 --- /dev/null +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -0,0 +1,66 @@ + new MockResponse(200, 'payment-list'), + ]); + + $paymentLink = new PaymentLink($client); + $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; + + /** @var PaymentCollection $payments */ + $payments = $client->paymentLinkPayments->pageFor($paymentLink); + + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertPayment($payment); + } + } + + /** @test */ + public function iterator_for() + { + $client = new MockClient([ + GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + $paymentLink = new PaymentLink($client); + $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; + + foreach ($client->paymentLinkPayments->iteratorFor($paymentLink) as $payment) { + $this->assertPayment($payment); + } + } + + protected function assertPayment(Payment $payment) + { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + $this->assertNotEmpty($payment->id); + $this->assertNotEmpty($payment->mode); + $this->assertNotEmpty($payment->createdAt); + $this->assertNotEmpty($payment->status); + $this->assertNotEmpty($payment->amount); + $this->assertNotEmpty($payment->description); + $this->assertNotEmpty($payment->method); + $this->assertNotEmpty($payment->metadata); + $this->assertNotEmpty($payment->profileId); + $this->assertNotEmpty($payment->_links); + } +} diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php new file mode 100644 index 000000000..22c2b6c12 --- /dev/null +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -0,0 +1,121 @@ + new MockResponse(201, 'refund'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Refund $refund */ + $refund = $client->paymentRefunds->createFor($payment, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '5.95', + ], + 'description' => 'Test refund', + ]); + + $this->assertRefund($refund); + } + + /** @test */ + public function get_for_test() + { + $client = new MockClient([ + GetPaymentRefundRequest::class => new MockResponse(200, 'refund'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Refund $refund */ + $refund = $client->paymentRefunds->getFor($payment, 're_4qqhO89gsT'); + + $this->assertRefund($refund); + } + + /** @test */ + public function cancel_for_test() + { + $client = new MockClient([ + CancelPaymentRefundRequest::class => new MockResponse(204), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + $client->paymentRefunds->cancelForPayment($payment, 're_4qqhO89gsT'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var RefundCollection $refunds */ + $refunds = $client->paymentRefunds->pageFor($payment); + + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + $this->assertGreaterThan(0, count($refunds)); + + foreach ($refunds as $refund) { + $this->assertRefund($refund); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + foreach ($client->paymentRefunds->iteratorFor($payment) as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertRefund($refund); + } + } + + protected function assertRefund(Refund $refund) + { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + $this->assertNotEmpty($refund->id); + $this->assertNotEmpty($refund->amount); + $this->assertNotEmpty($refund->status); + $this->assertEquals('tr_7UhSN1zuXS', $refund->paymentId); + $this->assertNotEmpty($refund->createdAt); + $this->assertNotEmpty($refund->_links); + } +} diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php new file mode 100644 index 000000000..a3177a832 --- /dev/null +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -0,0 +1,35 @@ + new MockResponse(200, 'route'), + ]); + + $payment = new Payment($client); + $payment->id = 'tr_7UhSN1zuXS'; + + /** @var Route $route */ + $route = $client->paymentRoutes->updateReleaseDateFor($payment, 'rt_abc123', '2024-01-01'); + + $this->assertInstanceOf(Route::class, $route); + $this->assertEquals('route', $route->resource); + $this->assertNotEmpty($route->id); + $this->assertNotEmpty($route->amount); + $this->assertNotEmpty($route->destination); + $this->assertNotEmpty($route->releaseDate); + $this->assertNotEmpty($route->_links); + } +} diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php new file mode 100644 index 000000000..c7df7de8a --- /dev/null +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -0,0 +1,56 @@ + new MockResponse(200, 'permission'), + ]); + + /** @var Permission $permission */ + $permission = $client->permissions->get('payments.read'); + + $this->assertPermission($permission); + } + + /** @test */ + public function list_test() + { + $client = new MockClient([ + ListPermissionsRequest::class => new MockResponse(200, 'permission-list'), + ]); + + /** @var PermissionCollection $permissions */ + $permissions = $client->permissions->list(); + + $this->assertInstanceOf(PermissionCollection::class, $permissions); + $this->assertGreaterThan(0, $permissions->count()); + $this->assertGreaterThan(0, count($permissions)); + + foreach ($permissions as $permission) { + $this->assertPermission($permission); + } + } + + protected function assertPermission(Permission $permission) + { + $this->assertInstanceOf(Permission::class, $permission); + $this->assertEquals('permission', $permission->resource); + $this->assertNotEmpty($permission->id); + $this->assertNotEmpty($permission->description); + $this->assertNotEmpty($permission->granted); + $this->assertNotEmpty($permission->_links); + } +} diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php new file mode 100644 index 000000000..8ca67eb6e --- /dev/null +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -0,0 +1,139 @@ + new MockResponse(201, 'profile'), + ]); + + /** @var Profile $profile */ + $profile = $client->profiles->create([ + 'name' => 'My Test Profile', + 'website' => 'https://example.org', + 'email' => 'info@example.org', + 'phone' => '+31612345678', + 'categoryCode' => 5399, + ]); + + $this->assertProfile($profile); + } + + /** @test */ + public function get_test() + { + $client = new MockClient([ + GetProfileRequest::class => new MockResponse(200, 'profile'), + ]); + + /** @var Profile $profile */ + $profile = $client->profiles->get('pfl_v9hTwCvYqw'); + + $this->assertProfile($profile); + } + + /** @test */ + public function get_current_test() + { + $client = new MockClient([ + GetProfileRequest::class => new MockResponse(200, 'current-profile'), + ]); + + /** @var Profile $profile */ + $profile = $client->profiles->getCurrent(); + + $this->assertProfile($profile); + } + + /** @test */ + public function update_test() + { + $client = new MockClient([ + UpdateProfileRequest::class => new MockResponse(200, 'profile'), + ]); + + /** @var Profile $profile */ + $profile = $client->profiles->update('pfl_v9hTwCvYqw', [ + 'name' => 'Updated Profile Name', + 'website' => 'https://updated-example.org', + ]); + + $this->assertProfile($profile); + } + + /** @test */ + public function delete_test() + { + $client = new MockClient([ + DeleteProfileRequest::class => new MockResponse(204), + ]); + + $client->profiles->delete('pfl_v9hTwCvYqw'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), + ]); + + /** @var ProfileCollection $profiles */ + $profiles = $client->profiles->page(); + + $this->assertInstanceOf(ProfileCollection::class, $profiles); + $this->assertGreaterThan(0, $profiles->count()); + $this->assertGreaterThan(0, count($profiles)); + + foreach ($profiles as $profile) { + $this->assertProfile($profile); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), + ]); + + foreach ($client->profiles->iterator() as $profile) { + $this->assertInstanceOf(Profile::class, $profile); + $this->assertProfile($profile); + } + } + + protected function assertProfile(Profile $profile) + { + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + $this->assertNotEmpty($profile->id); + $this->assertNotEmpty($profile->mode); + $this->assertNotEmpty($profile->name); + $this->assertNotEmpty($profile->website); + $this->assertNotEmpty($profile->email); + $this->assertNotEmpty($profile->phone); + $this->assertNotEmpty($profile->businessCategory); + $this->assertNotEmpty($profile->status); + $this->assertNotEmpty($profile->createdAt); + $this->assertNotEmpty($profile->_links); + } +} diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php new file mode 100644 index 000000000..6d7f355dd --- /dev/null +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -0,0 +1,55 @@ + new MockResponse(200, 'refund-list'), + ]); + + /** @var RefundCollection $refunds */ + $refunds = $client->refunds->page(); + + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertRefund($refund); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), + ]); + + foreach ($client->refunds->iterator() as $refund) { + $this->assertRefund($refund); + } + } + + protected function assertRefund(Refund $refund) + { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + $this->assertNotEmpty($refund->id); + $this->assertNotEmpty($refund->amount); + $this->assertNotEmpty($refund->status); + $this->assertNotEmpty($refund->createdAt); + $this->assertNotEmpty($refund->paymentId); + $this->assertNotEmpty($refund->_links); + } +} diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php new file mode 100644 index 000000000..23007de63 --- /dev/null +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -0,0 +1,64 @@ + new MockResponse(200, 'capture-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + /** @var CaptureCollection $captures */ + $captures = $client->settlementCaptures->pageFor($settlement); + + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertGreaterThan(0, $captures->count()); + + foreach ($captures as $capture) { + $this->assertCapture($capture); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + foreach ($client->settlementCaptures->iteratorFor($settlement) as $capture) { + $this->assertCapture($capture); + } + } + + protected function assertCapture(Capture $capture) + { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + $this->assertNotEmpty($capture->id); + $this->assertNotEmpty($capture->mode); + $this->assertNotEmpty($capture->amount); + $this->assertNotEmpty($capture->settlementId); + $this->assertNotEmpty($capture->paymentId); + $this->assertNotEmpty($capture->shipmentId); + $this->assertNotEmpty($capture->createdAt); + $this->assertNotEmpty($capture->_links); + } +} diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php new file mode 100644 index 000000000..b867ba683 --- /dev/null +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -0,0 +1,62 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + /** @var ChargebackCollection $chargebacks */ + $chargebacks = $client->settlementChargebacks->pageFor($settlement); + + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertChargeback($chargeback); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + foreach ($client->settlementChargebacks->iteratorFor($settlement) as $chargeback) { + $this->assertChargeback($chargeback); + } + } + + protected function assertChargeback(Chargeback $chargeback) + { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + $this->assertNotEmpty($chargeback->id); + $this->assertNotEmpty($chargeback->amount); + $this->assertNotEmpty($chargeback->settlementAmount); + $this->assertNotEmpty($chargeback->createdAt); + $this->assertNotEmpty($chargeback->paymentId); + $this->assertNotEmpty($chargeback->_links); + } +} diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php new file mode 100644 index 000000000..9dadd8dcd --- /dev/null +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -0,0 +1,63 @@ + new MockResponse(200, 'payment-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + /** @var PaymentCollection $payments */ + $payments = $client->settlementPayments->pageFor($settlement); + + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertPayment($payment); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + foreach ($client->settlementPayments->iteratorFor($settlement) as $payment) { + $this->assertPayment($payment); + } + } + + protected function assertPayment(Payment $payment) + { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + $this->assertNotEmpty($payment->id); + $this->assertNotEmpty($payment->amount); + $this->assertNotEmpty($payment->description); + $this->assertNotEmpty($payment->createdAt); + $this->assertNotEmpty($payment->status); + $this->assertNotEmpty($payment->profileId); + $this->assertNotEmpty($payment->_links); + } +} diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php new file mode 100644 index 000000000..ebf10c89a --- /dev/null +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -0,0 +1,62 @@ + new MockResponse(200, 'refund-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + /** @var RefundCollection $refunds */ + $refunds = $client->settlementRefunds->pageFor($settlement); + + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertRefund($refund); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), + ]); + + $settlement = new Settlement($client); + $settlement->id = 'stl_jDk30akdN'; + + foreach ($client->settlementRefunds->iteratorFor($settlement) as $refund) { + $this->assertRefund($refund); + } + } + + protected function assertRefund(Refund $refund) + { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + $this->assertNotEmpty($refund->id); + $this->assertNotEmpty($refund->amount); + $this->assertNotEmpty($refund->status); + $this->assertNotEmpty($refund->createdAt); + $this->assertNotEmpty($refund->paymentId); + $this->assertNotEmpty($refund->_links); + } +} diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php new file mode 100644 index 000000000..4144ee352 --- /dev/null +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -0,0 +1,123 @@ +collection = $this->getMockBuilder(SettlementsEndpointCollection::class) + ->disableOriginalConstructor() + ->onlyMethods(['send']) + ->getMock(); + } + + public function testGet(): void + { + $settlement = $this->createMock(Settlement::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->isInstanceOf(GetSettlementRequest::class)) + ->willReturn($settlement); + + $result = $this->collection->get('stl_123'); + + $this->assertSame($settlement, $result); + } + + public function testNext(): void + { + $settlement = $this->createMock(Settlement::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->callback(function (GetSettlementRequest $request) { + return $request->getId() === 'next'; + })) + ->willReturn($settlement); + + $result = $this->collection->next(); + + $this->assertSame($settlement, $result); + } + + public function testOpen(): void + { + $settlement = $this->createMock(Settlement::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->callback(function (GetSettlementRequest $request) { + return $request->getId() === 'open'; + })) + ->willReturn($settlement); + + $result = $this->collection->open(); + + $this->assertSame($settlement, $result); + } + + public function testPage(): void + { + $collection = $this->createMock(SettlementCollection::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->isInstanceOf(GetPaginatedSettlementsRequest::class)) + ->willReturn($collection); + + $result = $this->collection->page('stl_123', 50, ['reference' => 'test']); + + $this->assertSame($collection, $result); + } + + public function testIterator(): void + { + $lazyCollection = $this->createMock(LazyCollection::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->callback(function (GetPaginatedSettlementsRequest $request) { + return $request->isIterator() && !$request->isIteratingBackwards(); + })) + ->willReturn($lazyCollection); + + $result = $this->collection->iterator('stl_123', 50, ['reference' => 'test']); + + $this->assertSame($lazyCollection, $result); + } + + public function testIteratorWithBackwardsIteration(): void + { + $lazyCollection = $this->createMock(LazyCollection::class); + + $this->collection + ->expects($this->once()) + ->method('send') + ->with($this->callback(function (GetPaginatedSettlementsRequest $request) { + return $request->isIterator() && $request->isIteratingBackwards(); + })) + ->willReturn($lazyCollection); + + $result = $this->collection->iterator('stl_123', 50, ['reference' => 'test'], true); + + $this->assertSame($lazyCollection, $result); + } +} diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php new file mode 100644 index 000000000..868eca0bf --- /dev/null +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -0,0 +1,151 @@ + new MockResponse(201, 'subscription'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var Subscription $subscription */ + $subscription = $client->subscriptions->createFor($customer, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '25.00', + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription', + 'webhookUrl' => 'https://example.org/webhook', + ]); + + $this->assertSubscription($subscription); + } + + /** @test */ + public function get_for_test() + { + $client = new MockClient([ + GetSubscriptionRequest::class => new MockResponse(200, 'subscription'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var Subscription $subscription */ + $subscription = $client->subscriptions->getFor($customer, 'sub_rVKGtNd6s3'); + + $this->assertSubscription($subscription); + } + + /** @test */ + public function update_for_test() + { + $client = new MockClient([ + UpdateSubscriptionRequest::class => new MockResponse(200, 'subscription'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var Subscription $subscription */ + $subscription = $client->subscriptions->update($customer->id, 'sub_rVKGtNd6s3', [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '30.00', + ], + 'description' => 'Updated subscription', + ]); + + $this->assertSubscription($subscription); + } + + /** @test */ + public function cancel_for_test() + { + $client = new MockClient([ + CancelSubscriptionRequest::class => new MockResponse(204), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + $client->subscriptions->cancelFor($customer, 'sub_rVKGtNd6s3'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page_for_test() + { + $client = new MockClient([ + GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + /** @var SubscriptionCollection $subscriptions */ + $subscriptions = $client->subscriptions->pageFor($customer); + + $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); + $this->assertGreaterThan(0, $subscriptions->count()); + $this->assertGreaterThan(0, count($subscriptions)); + + foreach ($subscriptions as $subscription) { + $this->assertSubscription($subscription); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + ]); + + $customer = new Customer($client); + $customer->id = 'cst_kEn1PlbGa'; + + foreach ($client->subscriptions->iteratorFor($customer) as $subscription) { + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertSubscription($subscription); + } + } + + protected function assertSubscription(Subscription $subscription) + { + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertEquals('subscription', $subscription->resource); + $this->assertNotEmpty($subscription->id); + $this->assertNotEmpty($subscription->mode); + $this->assertNotEmpty($subscription->createdAt); + $this->assertNotEmpty($subscription->status); + $this->assertNotEmpty($subscription->amount); + $this->assertNotEmpty($subscription->times); + $this->assertNotEmpty($subscription->interval); + $this->assertNotEmpty($subscription->description); + $this->assertNotEmpty($subscription->method); + $this->assertNotEmpty($subscription->webhookUrl); + $this->assertNotEmpty($subscription->_links); + } +} diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php new file mode 100644 index 000000000..ffb930f67 --- /dev/null +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -0,0 +1,66 @@ + new MockResponse(200, 'payment-list'), + ]); + + $subscription = new Subscription($client); + $subscription->id = 'sub_rVKGtNd6s3'; + $subscription->customerId = 'cust_kEn1PlbGa'; + + /** @var PaymentCollection $payments */ + $payments = $client->subscriptionPayments->pageFor($subscription); + + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertPayment($payment); + } + } + + /** @test */ + public function iterator_for_test() + { + $client = new MockClient([ + GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), + ]); + + $subscription = new Subscription($client); + $subscription->id = 'sub_rVKGtNd6s3'; + $subscription->customerId = 'cust_kEn1PlbGa'; + + foreach ($client->subscriptionPayments->iteratorFor($subscription) as $payment) { + $this->assertPayment($payment); + } + } + + protected function assertPayment(Payment $payment) + { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + $this->assertNotEmpty($payment->id); + $this->assertNotEmpty($payment->amount); + $this->assertNotEmpty($payment->description); + $this->assertNotEmpty($payment->createdAt); + $this->assertNotEmpty($payment->status); + $this->assertNotEmpty($payment->profileId); + $this->assertNotEmpty($payment->subscriptionId); + $this->assertNotEmpty($payment->_links); + } +} diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php new file mode 100644 index 000000000..7b98028f5 --- /dev/null +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -0,0 +1,73 @@ + new MockResponse(200, 'terminal'), + ]); + + /** @var Terminal $terminal */ + $terminal = $client->terminals->get('term_7jKQR2wmKx'); + + $this->assertTerminal($terminal); + } + + /** @test */ + public function page_test() + { + $client = new MockClient([ + GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + ]); + + /** @var TerminalCollection $terminals */ + $terminals = $client->terminals->page(); + + $this->assertInstanceOf(TerminalCollection::class, $terminals); + $this->assertGreaterThan(0, $terminals->count()); + + foreach ($terminals as $terminal) { + $this->assertTerminal($terminal); + } + } + + /** @test */ + public function iterator_test() + { + $client = new MockClient([ + GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + ]); + + foreach ($client->terminals->iterator() as $terminal) { + $this->assertTerminal($terminal); + } + } + + protected function assertTerminal(Terminal $terminal) + { + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals('terminal', $terminal->resource); + $this->assertNotEmpty($terminal->id); + $this->assertNotEmpty($terminal->profileId); + $this->assertNotEmpty($terminal->status); + $this->assertNotEmpty($terminal->brand); + $this->assertNotEmpty($terminal->model); + $this->assertNotEmpty($terminal->serialNumber); + $this->assertNotEmpty($terminal->currency); + $this->assertNotEmpty($terminal->createdAt); + $this->assertNotEmpty($terminal->updatedAt); + $this->assertNotEmpty($terminal->_links); + } +} diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php new file mode 100644 index 000000000..08f94fe11 --- /dev/null +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -0,0 +1,30 @@ + new MockResponse(200, 'apple-pay-session'), + ]); + + $session = $client->wallets->requestApplePayPaymentSession( + 'pay.example.org', + 'https://apple-pay-gateway.example.com/paymentservices/paymentSession', + [ + 'displayName' => "Chuck Norris's Store", + ] + ); + + $this->assertIsString($session); + $this->assertNotEmpty($session); + } +} diff --git a/tests/Fixtures/Responses/apple-pay-session.json b/tests/Fixtures/Responses/apple-pay-session.json new file mode 100644 index 000000000..372904730 --- /dev/null +++ b/tests/Fixtures/Responses/apple-pay-session.json @@ -0,0 +1,10 @@ +{ + "epochTimestamp": 1555507053169, + "expiresAt": 1555510653169, + "merchantSessionIdentifier": "SSH2EAF8AFAEAA94DEEA898162A5DAFD36E_916523AAED1343F5BC5815E12BEE9250AFFDC1A17C46B0DE5A9", + "nonce": "0206b8db", + "merchantIdentifier": "BD62FEB196874511C22DB28A9E14A89E3534C93194F73EA417EC566368D391EB", + "domainName": "pay.example.org", + "displayName": "Chuck Norris's Store", + "signature": "308006092a864886f7...8cc030ad3000000000000" +} diff --git a/tests/Fixtures/Responses/balance-list.json b/tests/Fixtures/Responses/balance-list.json index a636e2f9e..29904614e 100644 --- a/tests/Fixtures/Responses/balance-list.json +++ b/tests/Fixtures/Responses/balance-list.json @@ -35,7 +35,7 @@ }, "_links": { "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", + "href": "...", "type": "application/hal+json" } } @@ -73,7 +73,7 @@ }, "_links": { "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPABC", + "href": "...", "type": "application/hal+json" } } @@ -82,7 +82,7 @@ }, "_links": { "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", + "href": "...", "type": "text/html" }, "self": { @@ -91,7 +91,7 @@ }, "previous": null, "next": { - "href": "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5", + "href": "...", "type": "application/hal+json" } } diff --git a/tests/Fixtures/Responses/balance-report.json b/tests/Fixtures/Responses/balance-report.json new file mode 100644 index 000000000..cd217ffec --- /dev/null +++ b/tests/Fixtures/Responses/balance-report.json @@ -0,0 +1,149 @@ +{ + "resource": "balance-report", + "balanceId": "{{ RESOURCE_ID }}", + "timeZone": "Europe/Amsterdam", + "from": "2024-01-01", + "until": "2024-01-31", + "grouping": "transaction-categories", + "totals": { + "open": { + "available": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + }, + "pending": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + } + }, + "payments": { + "immediatelyAvailable": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + }, + "pending": { + "amount": { + "currency": "EUR", + "value": "4.98" + }, + "subtotals": [ + { + "transactionType": "payment", + "count": 1, + "amount": { + "currency": "EUR", + "value": "4.98" + }, + "subtotals": [ + { + "method": "ideal", + "count": 1, + "amount": { + "currency": "EUR", + "value": "4.98" + } + } + ] + } + ] + }, + "movedToAvailable": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + } + }, + "refunds": {}, + "capital": {}, + "chargebacks": {}, + "transfers": {}, + "fee-prepayments": { + "immediatelyAvailable": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + }, + "movedToAvailable": { + "amount": { + "currency": "EUR", + "value": "-0.36" + }, + "subtotals": [ + { + "prepaymentPartType": "fee", + "count": 1, + "amount": { + "currency": "EUR", + "value": "-0.29" + }, + "subtotals": [ + { + "feeType": "payment-fee", + "method": "ideal", + "count": 1, + "amount": { + "currency": "EUR", + "value": "-0.29" + } + } + ] + }, + { + "prepaymentPartType": "fee-vat", + "amount": { + "currency": "EUR", + "value": "-0.0609" + } + }, + { + "prepaymentPartType": "fee-rounding-compensation", + "amount": { + "currency": "EUR", + "value": "-0.0091" + } + } + ] + }, + "pending": { + "amount": { + "currency": "EUR", + "value": "-0.36" + }, + "subtotals": [] + } + }, + "corrections": {}, + "close": { + "available": { + "amount": { + "currency": "EUR", + "value": "0.00" + } + }, + "pending": { + "amount": { + "currency": "EUR", + "value": "4.32" + } + } + } + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/balance-transactions.json b/tests/Fixtures/Responses/balance-transactions.json new file mode 100644 index 000000000..a7966c9d7 --- /dev/null +++ b/tests/Fixtures/Responses/balance-transactions.json @@ -0,0 +1,63 @@ +{ + "count": 5, + "_embedded": { + "balance_transactions": [ + { + "resource": "balance_transaction", + "id": "baltr_*", + "type": "refund", + "resultAmount": { + "currency": "EUR", + "value": "-10.25" + }, + "initialAmount": { + "currency": "EUR", + "value": "-10.00" + }, + "deductions": { + "currency": "EUR", + "value": "-0.25" + }, + "context": { + "paymentId": "tr_7UhSN1zuXS", + "refundId": "re_4qqhO89gsT" + } + }, + { + "resource": "balance_transaction", + "id": "baltr_WhmDwNYR87FPDbiwBhUXCh", + "type": "payment", + "resultAmount": { + "currency": "EUR", + "value": "9.71" + }, + "initialAmount": { + "currency": "EUR", + "value": "10.00" + }, + "deductions": { + "currency": "EUR", + "value": "-0.29" + }, + "context": { + "paymentId": "tr_7UhSN1zuXS" + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?from=baltr_*&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/balance.json b/tests/Fixtures/Responses/balance.json index 81d26f94b..cb9c0df7f 100644 --- a/tests/Fixtures/Responses/balance.json +++ b/tests/Fixtures/Responses/balance.json @@ -31,11 +31,11 @@ }, "_links": { "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", + "href": "...", "type": "application/hal+json" }, "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/get-balance", + "href": "...", "type": "text/html" } } diff --git a/tests/Fixtures/Responses/capture-list.json b/tests/Fixtures/Responses/capture-list.json new file mode 100644 index 000000000..aa9a865ab --- /dev/null +++ b/tests/Fixtures/Responses/capture-list.json @@ -0,0 +1,45 @@ +{ + "count": 1, + "_embedded": { + "captures": [ + { + "resource": "capture", + "id": "cpt_mNepDkEtco6ah3QNPUGYH", + "mode": "live", + "description": "Capture for cart #12345", + "amount": { + "currency": "EUR", + "value": "35.95" + }, + "metadata": "{\"bookkeeping_id\":12345}", + "paymentId": "tr_7UhSN1zuXS", + "createdAt": "2023-08-02T09:29:56.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/captures?from=cpt_Sy3NzD2TYuQtUaxNyu8aH&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/capture.json b/tests/Fixtures/Responses/capture.json new file mode 100644 index 000000000..569077542 --- /dev/null +++ b/tests/Fixtures/Responses/capture.json @@ -0,0 +1,27 @@ +{ + "resource": "capture", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "description": "Capture for cart #12345", + "amount": { + "currency": "EUR", + "value": "35.95" + }, + "metadata": "{\"bookkeeping_id\":12345}", + "paymentId": "tr_7UhSN1zuXS", + "createdAt": "2023-08-02T09:29:56.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/chargeback-list.json b/tests/Fixtures/Responses/chargeback-list.json new file mode 100644 index 000000000..545f0643c --- /dev/null +++ b/tests/Fixtures/Responses/chargeback-list.json @@ -0,0 +1,206 @@ +{ + "_embedded": null, + "chargebacks": [ + { + "resource": "chargeback", + "id": "chb_xg7414", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "createdAt": "2022-01-03T13:28:13+00:00", + "paymentId": "tr_HdQrGb6N3r", + "settlementAmount": { + "value": "-10.00", + "currency": "EUR" + }, + "_embedded": { + "payment": { + "resource": "payment", + "id": "tr_HdQrGb6N3r", + "mode": "test", + "createdAt": "2022-01-03T13:27:35+00:00", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "description": "This is the description of the payment", + "method": "creditcard", + "metadata": { + "someProperty": "someValue", + "anotherProperty": "anotherValue" + }, + "status": "paid", + "paidAt": "2022-01-03T13:28:10+00:00", + "amountRefunded": { + "value": "0.00", + "currency": "EUR" + }, + "amountRemaining": { + "value": "10.00", + "currency": "EUR" + }, + "amountChargedBack": { + "value": "10.00", + "currency": "EUR" + }, + "locale": "en_US", + "restrictPaymentMethodsToCountry": "NL", + "countryCode": "NL", + "profileId": "pfl_85dxyKqNHa", + "sequenceType": "oneoff", + "redirectUrl": "https://example.com/landing_page", + "webhookUrl": "https://example.com/redirect", + "settlementAmount": { + "value": "10.00", + "currency": "EUR" + }, + "details": { + "cardNumber": "6787", + "cardHolder": "T. TEST", + "cardAudience": "consumer", + "cardLabel": "Mastercard", + "cardCountryCode": "NL", + "cardSecurity": "normal", + "feeRegion": "other" + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_13514547/payments/tr_HdQrGb6N3r", + "type": "text/html" + }, + "changePaymentState": { + "href": "https://www.mollie.com/checkout/test-mode?method=creditcard&token=3.lxnsca", + "type": "text/html" + }, + "chargebacks": { + "href": "https://api.mollie.com/v2/payments/tr_HdQrGb6N3r/chargebacks", + "type": "application/hal+json" + } + } + } + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_HdQrGb6N3r", + "type": "application/hal+json" + } + } + }, + { + "resource": "chargeback", + "id": "chb_ls7ahg", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "createdAt": "2022-01-03T13:20:37+00:00", + "paymentId": "tr_8bVBhk2qs4", + "settlementAmount": { + "value": "-10.00", + "currency": "EUR" + }, + "_embedded": { + "payment": { + "resource": "payment", + "id": "tr_8bVBhk2qs4", + "mode": "test", + "createdAt": "2022-01-03T13:11:20+00:00", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "description": "This is the description of the payment", + "method": "creditcard", + "metadata": { + "someProperty": "someValue", + "anotherProperty": "anotherValue" + }, + "status": "paid", + "paidAt": "2022-01-03T13:18:39+00:00", + "amountRefunded": { + "value": "0.00", + "currency": "EUR" + }, + "amountRemaining": { + "value": "10.00", + "currency": "EUR" + }, + "amountChargedBack": { + "value": "10.00", + "currency": "EUR" + }, + "locale": "en_US", + "restrictPaymentMethodsToCountry": "NL", + "countryCode": "NL", + "profileId": "pfl_85dxyKqNHa", + "sequenceType": "oneoff", + "redirectUrl": "https://example.com/landing_page", + "webhookUrl": "https://example.com/redirect", + "settlementAmount": { + "value": "10.00", + "currency": "EUR" + }, + "details": { + "cardNumber": "6787", + "cardHolder": "T. TEST", + "cardAudience": "consumer", + "cardLabel": "Mastercard", + "cardCountryCode": "NL", + "cardSecurity": "normal", + "feeRegion": "other" + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_13514547/payments/tr_8bVBhk2qs4", + "type": "text/html" + }, + "changePaymentState": { + "href": "https://www.mollie.com/checkout/test-mode?method=creditcard&token=3.11roh2", + "type": "text/html" + }, + "chargebacks": { + "href": "https://api.mollie.com/v2/payments/tr_8bVBhk2qs4/chargebacks", + "type": "application/hal+json" + } + } + } + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_8bVBhk2qs4", + "type": "application/hal+json" + } + } + } + ], + "count": 2, + "_links": { + "documentation": { + "href": "...", + "type": "text/html" + }, + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } +} diff --git a/tests/Fixtures/Responses/chargeback.json b/tests/Fixtures/Responses/chargeback.json new file mode 100644 index 000000000..2792646a2 --- /dev/null +++ b/tests/Fixtures/Responses/chargeback.json @@ -0,0 +1,33 @@ +{ + "resource": "chargeback", + "id": "{{ RESOURCE_ID }}", + "amount": { + "currency": "USD", + "value": "43.38" + }, + "settlementAmount": { + "currency": "EUR", + "value": "-35.07" + }, + "reason": { + "code": "AC01", + "description": "Account identifier incorrect (i.e. invalid IBAN)" + }, + "paymentId": "tr_7UhSN1zuXS", + "createdAt": "2023-03-14T17:09:02.0Z", + "reversedAt": null, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/client-link.json b/tests/Fixtures/Responses/client-link.json new file mode 100644 index 000000000..5e2314c9d --- /dev/null +++ b/tests/Fixtures/Responses/client-link.json @@ -0,0 +1,14 @@ +{ + "id": "csr_ayCz46QLwCbxpTaSYQQZH", + "resource": "client-link", + "_links": { + "clientLink": { + "href": "https://my.mollie.com/dashboard/client-link/csr_ayCz46QLwCbxpTaSYQQZH", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/client-list.json b/tests/Fixtures/Responses/client-list.json new file mode 100644 index 000000000..45bd85a7d --- /dev/null +++ b/tests/Fixtures/Responses/client-list.json @@ -0,0 +1,33 @@ +{ + "count": 5, + "_embedded": { + "clients": [ + { + "resource": "client", + "id": "org_12345678", + "organizationCreatedAt": "2023-04-06 13:10:19+00:00", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/clients?from=org_63916732&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/client.json b/tests/Fixtures/Responses/client.json new file mode 100644 index 000000000..525e9a5a6 --- /dev/null +++ b/tests/Fixtures/Responses/client.json @@ -0,0 +1,52 @@ +{ + "resource": "client", + "id": "org_7049691", + "organizationCreatedAt": "2019-12-06T10:09:32+00:00", + "_embedded": { + "organization": { + "resource": "organization", + "id": "org_7049691", + "name": "Hugo's eenzame zaak", + "email": "[[redacted]]", + "locale": "en_US", + "address": { + "streetAndNumber": "[[redacted]]", + "postalCode": "[[redacted]]", + "city": "[[redacted]]", + "country": "[[redacted]]" + }, + "registrationNumber": "[[redacted]]", + "vatNumber": "", + "vatRegulation": "dutch", + "verifiedAt": "2020-10-19T11:45:36+00:00", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/organization/org_7049691", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_7049691/", + "type": "text/html" + } + } + } + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/clients/org_7049691", + "type": "application/hal+json" + }, + "onboarding": { + "href": "https://api.mollie.com/v2/onboarding/org_7049691", + "type": "application/hal+json" + }, + "organization": { + "href": "https://api.mollie.com/v2/organization/org_7049691", + "type": "application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/partners-api/get-client", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/current-profile.json b/tests/Fixtures/Responses/current-profile.json new file mode 100644 index 000000000..bf5047cc4 --- /dev/null +++ b/tests/Fixtures/Responses/current-profile.json @@ -0,0 +1,47 @@ +{ + "resource": "profile", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "name": "Jonas Test BV", + "website": "https://example.com", + "email": "test@mollie.com", + "phone": "+31612345678", + "categoryCode": 6012, + "businessCategory": "MONEY_SERVICES", + "status": "verified", + "createdAt": "2021-12-08T15:42:58+00:00", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_13514547/settings/profiles/pfl_85dxyKqNHa", + "type": "text/html" + }, + "chargebacks": { + "href": "https://api.mollie.com/v2/chargebacks", + "type": "application/hal+json" + }, + "methods": { + "href": "https://api.mollie.com/v2/methods", + "type": "application/hal+json" + }, + "payments": { + "href": "https://api.mollie.com/v2/payments", + "type": "application/hal+json" + }, + "refunds": { + "href": "https://api.mollie.com/v2/refunds", + "type": "application/hal+json" + }, + "checkoutPreviewUrl": { + "href": "https://www.mollie.com/checkout/preview/{{ RESOURCE_ID }}", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/cursor-collection-next.json b/tests/Fixtures/Responses/cursor-collection-next.json index b376e4777..30d922dae 100644 --- a/tests/Fixtures/Responses/cursor-collection-next.json +++ b/tests/Fixtures/Responses/cursor-collection-next.json @@ -2,14 +2,14 @@ "count": 1, "_links": { "self": { - "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + "href": "https:\/\/api.mollie.com\/v2\/payments?from={{ RESOURCE_ID }}" }, "next": { - "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + "href": "https:\/\/api.mollie.com\/v2\/payments?from={{ RESOURCE_ID }}" } }, "_embedded": { - "orders": [ + "payments": [ { "id": "{{ RESOURCE_ID }}" } diff --git a/tests/Fixtures/Responses/cursor-collection.json b/tests/Fixtures/Responses/cursor-collection.json index f272c7ea2..36a035a94 100644 --- a/tests/Fixtures/Responses/cursor-collection.json +++ b/tests/Fixtures/Responses/cursor-collection.json @@ -2,11 +2,11 @@ "count": 1, "_links": { "self": { - "href": "https:\/\/api.mollie.com\/v2\/orders?from={{ RESOURCE_ID }}" + "href": "https:\/\/api.mollie.com\/v2\/payments?from={{ RESOURCE_ID }}" } }, "_embedded": { - "orders": [ + "payments": [ { "id": "{{ RESOURCE_ID }}" } diff --git a/tests/Fixtures/Responses/customer-list.json b/tests/Fixtures/Responses/customer-list.json new file mode 100644 index 000000000..1b73d9557 --- /dev/null +++ b/tests/Fixtures/Responses/customer-list.json @@ -0,0 +1,36 @@ +{ + "count": 5, + "_embedded": { + "customers": [ + { + "resource": "customer", + "id": "cst_8wmqcHMN4U", + "mode": "live", + "name": "John Doe", + "email": "customer@example.org", + "createdAt": "2023-04-06T13:10:19.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/customers?from=cst_stTC2WHAuS&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/customer.json b/tests/Fixtures/Responses/customer.json new file mode 100644 index 000000000..e1e9171d6 --- /dev/null +++ b/tests/Fixtures/Responses/customer.json @@ -0,0 +1,27 @@ +{ + "resource": "customer", + "id": "{{ RESOURCE_ID }}", + "mode": "test", + "name": "Jane Doe", + "email": "test@mollie.com", + "locale": "en_US", + "metadata": { + "someProperty": "someValue", + "anotherProperty": "anotherValue" + }, + "createdAt": "2022-01-03T13:42:04+00:00", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_13514547/customers/cst_tKt44u85MM", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/empty-balance-list.json b/tests/Fixtures/Responses/empty-list.json similarity index 53% rename from tests/Fixtures/Responses/empty-balance-list.json rename to tests/Fixtures/Responses/empty-list.json index ae9dd93fc..e928366cd 100644 --- a/tests/Fixtures/Responses/empty-balance-list.json +++ b/tests/Fixtures/Responses/empty-list.json @@ -1,15 +1,15 @@ { - "count": 2, + "count": 0, "_embedded": { - "balances": [] + "{{ RESOURCE_ID }}": [] }, "_links": { "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", + "href": "...", "type": "text/html" }, "self": { - "href": "https://api.mollie.com/v2/balances?limit=5", + "href": "...", "type": "application/hal+json" }, "previous": null, diff --git a/tests/Fixtures/Responses/invoice-list.json b/tests/Fixtures/Responses/invoice-list.json new file mode 100644 index 000000000..b4a60461b --- /dev/null +++ b/tests/Fixtures/Responses/invoice-list.json @@ -0,0 +1,61 @@ +{ + "count": 1, + "_embedded": { + "invoices": [ + { + "resource": "invoice", + "id": "inv_xBEbP9rvAq", + "reference": "2023.10000", + "vatNumber": "NL001234567B01", + "status": "open", + "netAmount": { + "currency": "EUR", + "value": "45.00" + }, + "vatAmount": { + "currency": "EUR", + "value": "9.45" + }, + "grossAmount": { + "currency": "EUR", + "value": "54.45" + }, + "lines": [ + { + "period": "2023-09", + "description": "iDEAL payment fees", + "count": 100, + "vatPercentage": 21, + "amount": { + "currency": "EUR", + "value": "45.00" + } + } + ], + "issuedAt": "2023-09-01", + "dueAt": "2023-09-14", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/invoices?from=inv_TUhzbAFMrt&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/invoice.json b/tests/Fixtures/Responses/invoice.json new file mode 100644 index 000000000..1b5157f25 --- /dev/null +++ b/tests/Fixtures/Responses/invoice.json @@ -0,0 +1,47 @@ +{ + "resource": "invoice", + "id": "{{ RESOURCE_ID }}", + "reference": "2023.10000", + "vatNumber": "NL001234567B01", + "status": "open", + "netAmount": { + "currency": "EUR", + "value": "45.00" + }, + "vatAmount": { + "currency": "EUR", + "value": "9.45" + }, + "grossAmount": { + "currency": "EUR", + "value": "54.45" + }, + "lines": [ + { + "period": "2023-09", + "description": "iDEAL payment fees", + "count": 100, + "vatPercentage": 21, + "amount": { + "currency": "EUR", + "value": "45.00" + } + } + ], + "issuedAt": "2023-09-01", + "dueAt": "2023-09-14", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "pdf": { + "href": "https://www.mollie.com/merchant/download/invoice/xBEbP9rvAq/2ab44d60b35b1d06090bba955fa2c602", + "type": "application/pdf" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/issuer.json b/tests/Fixtures/Responses/issuer.json new file mode 100644 index 000000000..fbfca9f91 --- /dev/null +++ b/tests/Fixtures/Responses/issuer.json @@ -0,0 +1,16 @@ +{ + "resource": "issuer", + "id": "festivalcadeau", + "description": "FestivalCadeau Giftcard", + "status": "pending-issuer", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/mandate-list.json b/tests/Fixtures/Responses/mandate-list.json new file mode 100644 index 000000000..9fb048740 --- /dev/null +++ b/tests/Fixtures/Responses/mandate-list.json @@ -0,0 +1,44 @@ +{ + "count": 1, + "_embedded": { + "mandates": [ + { + "resource": "mandate", + "id": "mdt_h3gAaD5zP", + "mode": "live", + "status": "valid", + "method": "directdebit", + "details": {}, + "mandateReference": "EXAMPLE-CORP-MD13804", + "signatureDate": "2023-05-07", + "customerId": "cst_4qqhO89gsT", + "createdAt": "2023-05-07T10:49:08.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "customer": { + "href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/mandates?from=mdt_pWUnw6pkBN&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/mandate.json b/tests/Fixtures/Responses/mandate.json new file mode 100644 index 000000000..c961c0de8 --- /dev/null +++ b/tests/Fixtures/Responses/mandate.json @@ -0,0 +1,30 @@ +{ + "resource": "mandate", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "status": "valid", + "method": "directdebit", + "details": { + "consumerName": "John Doe", + "consumerAccount": "NL55INGB0000000000", + "consumerBic": "INGBNL2A" + }, + "mandateReference": "EXAMPLE-CORP-MD13804", + "signatureDate": "2023-05-07", + "customerId": "cst_4qqhO89gsT", + "createdAt": "2023-05-07T10:49:08.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "customer": { + "href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/method-list.json b/tests/Fixtures/Responses/method-list.json new file mode 100644 index 000000000..b45f37967 --- /dev/null +++ b/tests/Fixtures/Responses/method-list.json @@ -0,0 +1,55 @@ +{ + "count": 2, + "_embedded": { + "methods": [ + { + "resource": "method", + "id": "ideal", + "description": "iDEAL", + "minimumAmount": { + "value": "0.01", + "currency": "EUR" + }, + "maximumAmount": { + "value": "50000.00", + "currency": "EUR" + }, + "image": { + "size1x": "https://mollie.com/external/icons/payment-methods/ideal.png", + "size2x": "https://mollie.com/external/icons/payment-methods/ideal%402x.png", + "svg": "https://mollie.com/external/icons/payment-methods/ideal.svg" + }, + "status": "activated" + }, + { + "resource": "method", + "id": "creditcard", + "description": "Credit card", + "minimumAmount": { + "value": "0.01", + "currency": "EUR" + }, + "maximumAmount": { + "value": "2000.00", + "currency": "EUR" + }, + "image": { + "size1x": "https://mollie.com/external/icons/payment-methods/creditcard.png", + "size2x": "https://mollie.com/external/icons/payment-methods/creditcard%402x.png", + "svg": "https://mollie.com/external/icons/payment-methods/creditcard.svg" + }, + "status": "activated" + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/method.json b/tests/Fixtures/Responses/method.json new file mode 100644 index 000000000..a40be508b --- /dev/null +++ b/tests/Fixtures/Responses/method.json @@ -0,0 +1,29 @@ +{ + "resource": "method", + "id": "{{ RESOURCE_ID }}", + "description": "iDEAL", + "minimumAmount": { + "value": "0.01", + "currency": "EUR" + }, + "maximumAmount": { + "value": "50000.00", + "currency": "EUR" + }, + "image": { + "size1x": "https://mollie.com/external/icons/payment-methods/ideal.png", + "size2x": "https://mollie.com/external/icons/payment-methods/ideal%402x.png", + "svg": "https://mollie.com/external/icons/payment-methods/ideal.svg" + }, + "status": "activated", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/onboarding.json b/tests/Fixtures/Responses/onboarding.json new file mode 100644 index 000000000..174aef972 --- /dev/null +++ b/tests/Fixtures/Responses/onboarding.json @@ -0,0 +1,26 @@ +{ + "resource": "onboarding", + "name": "Mollie B.V.", + "status": "completed", + "canReceivePayments": true, + "canReceiveSettlements": true, + "signedUpAt": "2023-12-20T10:49:08.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/onboarding", + "type": "text/html" + }, + "organization": { + "href": "https://api.mollie.com/v2/organizations/org_12345678", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/organization.json b/tests/Fixtures/Responses/organization.json new file mode 100644 index 000000000..fe9aeded0 --- /dev/null +++ b/tests/Fixtures/Responses/organization.json @@ -0,0 +1,28 @@ +{ + "resource": "organization", + "id": "{{ RESOURCE_ID }}", + "name": "Mollie B.V.", + "email": "info@mollie.com", + "address": { + "streetAndNumber": "Keizersgracht 126", + "postalCode": "1015 CW", + "city": "Amsterdam", + "country": "NL" + }, + "registrationNumber": "30204462", + "vatNumber": "NL815839091B01", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://mollie.com/dashboard/{{ RESOURCE_ID }}", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/partner-status.json b/tests/Fixtures/Responses/partner-status.json new file mode 100644 index 000000000..e847dfa68 --- /dev/null +++ b/tests/Fixtures/Responses/partner-status.json @@ -0,0 +1,19 @@ +{ + "resource": "partner", + "partnerType": "signuplink", + "partnerContractSignedAt": "2023-03-20T13:59:02.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "signuplink": { + "href": "https://www.mollie.com/dashboard/signup/exampleCode", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/payment-link-list.json b/tests/Fixtures/Responses/payment-link-list.json new file mode 100644 index 000000000..334e7fef9 --- /dev/null +++ b/tests/Fixtures/Responses/payment-link-list.json @@ -0,0 +1,49 @@ +{ + "count": 5, + "_embedded": { + "payment_links": [ + { + "resource": "payment-link", + "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56.0Z", + "expiresAt": "2023-06-06T11:00:00.0Z", + "reusable": false, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://payment-links.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payment-links?from=pl_ayGNzD4TYuQtUaxNyu8aH&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/payment-link.json b/tests/Fixtures/Responses/payment-link.json new file mode 100644 index 000000000..d87231dac --- /dev/null +++ b/tests/Fixtures/Responses/payment-link.json @@ -0,0 +1,31 @@ +{ + "resource": "payment-link", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "description": "Bicycle tires", + "amount": { + "currency": "EUR", + "value": "24.95" + }, + "archived": false, + "redirectUrl": "https://webshop.example.org/thanks", + "webhookUrl": "https://webshop.example.org/payment-links/webhook", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2021-03-20T09:29:56.0Z", + "expiresAt": "2023-06-06T11:00:00.0Z", + "reusable": false, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "paymentLink": { + "href": "https://payment-links.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/payment-list.json b/tests/Fixtures/Responses/payment-list.json new file mode 100644 index 000000000..11a64a60a --- /dev/null +++ b/tests/Fixtures/Responses/payment-list.json @@ -0,0 +1,55 @@ +{ + "count": 5, + "_embedded": { + "payments": [ + { + "resource": "payment", + "id": "tr_7UhSN1zuXS", + "mode": "live", + "status": "open", + "isCancelable": false, + "amount": { + "value": "75.00", + "currency": "GBP" + }, + "description": "Order #12345", + "method": "ideal", + "metadata": null, + "details": null, + "profileId": "pfl_QkEhN94Ba", + "redirectUrl": "https://webshop.example.org/order/12345/", + "createdAt": "2024-02-12T11:58:35.0Z", + "expiresAt": "2024-02-12T12:13:35.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/checkout/issuer/select/ideal/7UhSN1zuXS", + "type": "text/html" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_12345678/payments/tr_7UhSN1zuXS", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payments?from=tr_SDkzMggpvx&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/payment-route.json b/tests/Fixtures/Responses/payment-route.json new file mode 100644 index 000000000..db073f52b --- /dev/null +++ b/tests/Fixtures/Responses/payment-route.json @@ -0,0 +1,13 @@ +{ + "resource": "route", + "id": "rt_9dk4al1n", + "amount": { + "value": "7.50", + "currency": "EUR" + }, + "destination": { + "type": "organization", + "organizationId": "org_23456" + }, + "releaseDate": "2026-01-01" +} diff --git a/tests/Fixtures/Responses/payment.json b/tests/Fixtures/Responses/payment.json index c2f70d2b7..19c680257 100644 --- a/tests/Fixtures/Responses/payment.json +++ b/tests/Fixtures/Responses/payment.json @@ -22,15 +22,15 @@ "webhookUrl": "https://example.org/webhook", "_links": { "self": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", + "href": "...", "type": "application/hal+json" }, "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/44aKxzEbr8", + "href": "...", "type": "text/html" }, "documentation": { - "href": "https://docs.mollie.com/reference/v2/payments-api/create-payment", + "href": "...", "type": "text/html" } } diff --git a/tests/Fixtures/Responses/permission-list.json b/tests/Fixtures/Responses/permission-list.json new file mode 100644 index 000000000..a06245400 --- /dev/null +++ b/tests/Fixtures/Responses/permission-list.json @@ -0,0 +1,41 @@ +{ + "count": 2, + "_embedded": { + "permissions": [ + { + "resource": "permission", + "id": "payments.read", + "description": "View your payments", + "granted": true, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + }, + { + "resource": "permission", + "id": "payments.write", + "description": "Create new payments", + "granted": false, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/permission.json b/tests/Fixtures/Responses/permission.json new file mode 100644 index 000000000..efa881d71 --- /dev/null +++ b/tests/Fixtures/Responses/permission.json @@ -0,0 +1,16 @@ +{ + "resource": "permission", + "id": "{{ RESOURCE_ID }}", + "description": "View your payments", + "granted": true, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/profile-list.json b/tests/Fixtures/Responses/profile-list.json new file mode 100644 index 000000000..a5d609bac --- /dev/null +++ b/tests/Fixtures/Responses/profile-list.json @@ -0,0 +1,43 @@ +{ + "count": 1, + "_embedded": { + "profiles": [ + { + "resource": "profile", + "id": "pfl_QkEhN94Ba", + "mode": "live", + "name": "My website name", + "website": "https://shop.example.org", + "email": "info@example.org", + "phone": "+31208202070", + "businessCategory": "OTHER_MERCHANDISE", + "status": "verified", + "review": { + "status": "pending" + }, + "createdAt": "2023-03-20T09:28:37.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/profiles?from=pfl_v9hTwCvYqw&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/profile.json b/tests/Fixtures/Responses/profile.json new file mode 100644 index 000000000..1ab701945 --- /dev/null +++ b/tests/Fixtures/Responses/profile.json @@ -0,0 +1,29 @@ +{ + "resource": "profile", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "name": "My website name", + "website": "https://shop.example.org", + "email": "info@example.org", + "phone": "+31208202070", + "businessCategory": "OTHER_MERCHANDISE", + "status": "verified", + "review": { + "status": "pending" + }, + "createdAt": "2023-03-20T09:28:37.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "dashboard": { + "href": "https://www.mollie.com/dashboard/org_123456789/settings/profiles/pfl_QkEhN94Ba", + "type": "text/html" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/refund-list.json b/tests/Fixtures/Responses/refund-list.json new file mode 100644 index 000000000..3ee516be5 --- /dev/null +++ b/tests/Fixtures/Responses/refund-list.json @@ -0,0 +1,48 @@ +{ + "count": 1, + "_embedded": { + "refunds": [ + { + "resource": "refund", + "id": "re_4qqhO89gsT", + "mode": "live", + "description": "Order", + "amount": { + "currency": "EUR", + "value": "5.95" + }, + "status": "pending", + "metadata": { + "bookkeeping_id": 12345 + }, + "paymentId": "tr_7UhSN1zuXS", + "createdAt": "2023-03-14T17:09:02.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?from=re_APBiGPH2vV&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/refund.json b/tests/Fixtures/Responses/refund.json new file mode 100644 index 000000000..c7c5dfce2 --- /dev/null +++ b/tests/Fixtures/Responses/refund.json @@ -0,0 +1,28 @@ +{ + "resource": "refund", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "description": "Order", + "amount": { + "currency": "EUR", + "value": "5.95" + }, + "status": "pending", + "metadata": "{\"bookkeeping_id\":12345}", + "paymentId": "tr_7UhSN1zuXS", + "createdAt": "2023-03-14T17:09:02.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/session.json b/tests/Fixtures/Responses/session.json new file mode 100644 index 000000000..c6b3dfe29 --- /dev/null +++ b/tests/Fixtures/Responses/session.json @@ -0,0 +1,24 @@ +{ + "id": "{{ RESOURCE_ID }}", + "status": "created", + "amount": { + "value": 10.00, + "currency": "EUR" + }, + "description": "Order #12345", + "method": "paypal", + "methodDetails": { + "checkoutFlow": "express" + }, + "nextAction": "redirect", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/sessions/{{ RESOURCE_ID }}", + "type": "application/hal+json" + }, + "redirect": { + "href": "https://paypalc.com/order/dghjfidf;gj", + "type": "application/hal+json" + } + } +} diff --git a/tests/Fixtures/Responses/settlement-list.json b/tests/Fixtures/Responses/settlement-list.json new file mode 100644 index 000000000..e971f995f --- /dev/null +++ b/tests/Fixtures/Responses/settlement-list.json @@ -0,0 +1,41 @@ +{ + "count": 1, + "_embedded": { + "settlements": [ + { + "resource": "settlement", + "id": "stl_jDk30akdN", + "reference": "1234567.2404.03", + "status": "paidout", + "amount": { + "currency": "EUR", + "value": "39.75" + }, + "balanceId": "bal_3kUf4yU2nT", + "periods": {}, + "settledAt": "2024-04-06T09:41:44.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/settlements?from=cst_stTC2WHAuS&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/settlement.json b/tests/Fixtures/Responses/settlement.json new file mode 100644 index 000000000..523b4d026 --- /dev/null +++ b/tests/Fixtures/Responses/settlement.json @@ -0,0 +1,125 @@ +{ + "resource": "settlement", + "id": "{{ RESOURCE_ID }}", + "reference": "1234567.2404.03", + "status": "paidout", + "amount": { + "currency": "EUR", + "value": "39.75" + }, + "balanceId": "bal_3kUf4yU2nT", + "periods": { + "2024": { + "04": { + "revenue": [ + { + "description": "iDEAL", + "method": "ideal", + "count": 6, + "amountNet": { + "currency": "EUR", + "value": "86.1000" + }, + "amountVat": null, + "amountGross": { + "currency": "EUR", + "value": "86.1000" + } + }, + { + "description": "Refunds iDEAL", + "method": "refund", + "count": 2, + "amountNet": { + "currency": "EUR", + "value": "-43.2000" + }, + "amountVat": null, + "amountGross": { + "currency": "EUR", + "value": "-43.2000" + } + } + ], + "costs": [ + { + "description": "iDEAL", + "method": "ideal", + "count": 6, + "rate": { + "fixed": { + "currency": "EUR", + "value": "0.3500" + }, + "percentage": null + }, + "amountNet": { + "currency": "EUR", + "value": "2.1000" + }, + "amountVat": { + "currency": "EUR", + "value": "0.4410" + }, + "amountGross": { + "currency": "EUR", + "value": "2.5410" + } + }, + { + "description": "Refunds iDEAL", + "method": "refund", + "count": 2, + "rate": { + "fixed": { + "currency": "EUR", + "value": "0.2500" + }, + "percentage": null + }, + "amountNet": { + "currency": "EUR", + "value": "0.5000" + }, + "amountVat": { + "currency": "EUR", + "value": "0.1050" + }, + "amountGross": { + "currency": "EUR", + "value": "0.6050" + } + } + ], + "invoiceId": "inv_FrvewDA3Pr" + } + } + }, + "settledAt": "2024-04-06T09:41:44.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "payments": { + "href": "https://api.mollie.com/v2/settlements/{{ RESOURCE_ID }}/payments", + "type": "application/hal+json" + }, + "refunds": { + "href": "https://api.mollie.com/v2/settlements/{{ RESOURCE_ID }}/refunds", + "type": "application/hal+json" + }, + "chargebacks": { + "href": "https://api.mollie.com/v2/settlements/{{ RESOURCE_ID }}/chargebacks", + "type": "application/hal+json" + }, + "captures": { + "href": "https://api.mollie.com/v2/settlements/{{ RESOURCE_ID }}/captures", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/subscription-list.json b/tests/Fixtures/Responses/subscription-list.json new file mode 100644 index 000000000..c0a47b7d2 --- /dev/null +++ b/tests/Fixtures/Responses/subscription-list.json @@ -0,0 +1,53 @@ +{ + "count": 1, + "_embedded": { + "subscriptions": [ + { + "resource": "subscription", + "id": "sub_rVKGtNd6s3", + "mode": "live", + "amount": { + "currency": "EUR", + "value": "25.00" + }, + "times": 4, + "timesRemaining": 4, + "interval": "3 months", + "startDate": "2023-06-01", + "nextPaymentDate": "2023-09-01", + "description": "Quarterly payment", + "method": null, + "status": "active", + "webhookUrl": "https://webshop.example.org/payments/webhook", + "customerId": "cst_stTC2WHAuS", + "mandateId": "mdt_38HS4fsS", + "createdAt": "2023-04-06T13:10:19.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "customer": { + "href": "https://api.mollie.com/v2/customers/cst_stTC2WHAuS", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/subscriptions?from=sub_mnXbwhMfvo&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/subscription.json b/tests/Fixtures/Responses/subscription.json new file mode 100644 index 000000000..7ff63ff86 --- /dev/null +++ b/tests/Fixtures/Responses/subscription.json @@ -0,0 +1,35 @@ +{ + "resource": "subscription", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "amount": { + "currency": "EUR", + "value": "25.00" + }, + "times": 4, + "timesRemaining": 4, + "interval": "3 months", + "startDate": "2023-06-01", + "nextPaymentDate": "2023-09-01", + "description": "Quarterly payment", + "method": null, + "status": "active", + "webhookUrl": "https://webshop.example.org/payments/webhook", + "customerId": "cst_stTC2WHAuS", + "mandateId": "mdt_38HS4fsS", + "createdAt": "2023-04-06T13:10:19.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "customer": { + "href": "https://api.mollie.com/v2/customers/cst_stTC2WHAuS", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/terminal-list.json b/tests/Fixtures/Responses/terminal-list.json new file mode 100644 index 000000000..2a4f48102 --- /dev/null +++ b/tests/Fixtures/Responses/terminal-list.json @@ -0,0 +1,38 @@ +{ + "count": 1, + "_embedded": { + "terminals": [ + { + "resource": "terminal", + "id": "term_7MgL4wea46qkRcoTZjWEH", + "mode": "live", + "status": "active", + "brand": "PAX", + "model": "A920", + "serialNumber": "1234567890", + "currency": "EUR", + "description": "Terminal #12345", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2022-02-12T11:58:35.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": null, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/terminal.json b/tests/Fixtures/Responses/terminal.json new file mode 100644 index 000000000..42f91bcff --- /dev/null +++ b/tests/Fixtures/Responses/terminal.json @@ -0,0 +1,23 @@ +{ + "resource": "terminal", + "id": "{{ RESOURCE_ID }}", + "mode": "live", + "status": "active", + "brand": "PAX", + "model": "A920", + "serialNumber": "1234567890", + "currency": "EUR", + "description": "Terminal #12345", + "profileId": "pfl_QkEhN94Ba", + "createdAt": "2022-02-12T11:58:35.0Z", + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/unprocessable-entity-with-field.json b/tests/Fixtures/Responses/unprocessable-entity-with-field.json index 5c0668cf4..e0d977c08 100644 --- a/tests/Fixtures/Responses/unprocessable-entity-with-field.json +++ b/tests/Fixtures/Responses/unprocessable-entity-with-field.json @@ -5,7 +5,7 @@ "field": "recurringType", "_links": { "documentation": { - "href": "https://docs.mollie.com/guides/handling-errors", + "href": "...", "type": "text/html" } } diff --git a/tests/Helpers/ArrTest.php b/tests/Helpers/ArrTest.php index bf6bc50df..86fd0a006 100644 --- a/tests/Helpers/ArrTest.php +++ b/tests/Helpers/ArrTest.php @@ -57,4 +57,13 @@ public function wrap(): void $this->assertEquals($array, Arr::wrap($array)); } + + /** @test */ + public function includes(): void + { + $array = ['includes' => ['payment']]; + + $this->assertTrue(Arr::includes($array, 'includes', 'payment')); + $this->assertFalse(Arr::includes($array, 'includes', 'refund')); + } } diff --git a/tests/Helpers/HandlersTest.php b/tests/Helpers/HandlersTest.php new file mode 100644 index 000000000..787638298 --- /dev/null +++ b/tests/Helpers/HandlersTest.php @@ -0,0 +1,64 @@ +add(fn () => null); + + $this->assertCount(1, $handlers->getHandlers()); + } + + /** @test */ + public function handlers_are_executed_in_the_correct_order(): void + { + $output = []; + + $handlers = new Handlers(); + $handlers->add(function ($value) use (&$output) { + $output[] = 1; + + return new TestViableResponse($output); + }, 'a', MiddlewarePriority::LOW); + + $handlers->add(function () use (&$output) { + $output[] = 2; + }, 'b', MiddlewarePriority::MEDIUM); + + $handlers->add(function () use (&$output) { + $output[] = 3; + }, 'c', MiddlewarePriority::HIGH); + + $this->assertCount(3, $handlers->getHandlers()); + + $response = $handlers->execute($output); + + $this->assertInstanceOf(TestViableResponse::class, $response); + $this->assertEquals([3, 2, 1], $response->toArray()); + } +} + +class TestViableResponse implements ViableResponse, Arrayable +{ + public array $output = []; + + public function __construct(array $output) + { + $this->output = $output; + } + + public function toArray(): array + { + return $this->output; + } +} From 5e4c7262241841ccfade1d2743a4a45b7d43c1d3 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:23:16 +0100 Subject: [PATCH 069/131] wip --- src/Contracts/SupportsResourceHydration.php | 4 + .../CustomerEndpointCollection.php | 5 +- .../CustomerPaymentsEndpointCollection.php | 8 +- .../MandateEndpointCollection.php | 2 +- .../MethodIssuerEndpointCollection.php | 2 +- .../PaymentLinkEndpointCollection.php | 7 +- .../PaymentLinkPaymentEndpointCollection.php | 8 +- .../PaymentRouteEndpointCollection.php | 4 +- .../ProfileEndpointCollection.php | 6 +- .../ProfileMethodEndpointCollection.php | 159 +++++ .../SessionEndpointCollection.php | 54 +- .../SubscriptionEndpointCollection.php | 6 +- .../WalletEndpointCollection.php | 6 +- src/Endpoints/ProfileMethodEndpoint.php | 109 --- src/Endpoints/SessionEndpoint.php | 131 ---- .../GetAllPaymentMethodsQueryFactory.php | 2 +- src/Http/Middleware/Hydrate.php | 10 +- src/Http/Payload/AnyPayload.php | 22 + src/Http/Query/AnyQuery.php | 22 + src/Http/Query/GetAllMethodsQuery.php | 4 +- .../Query/GetEnabledPaymentMethodsQuery.php | 4 +- src/Http/Request.php | 7 - .../ApplePayPaymentSessionRequest.php | 6 +- src/Http/Requests/CancelSessionRequest.php | 25 + src/Http/Requests/CreateCustomerRequest.php | 2 +- src/Http/Requests/CreateProfileRequest.php | 1 - src/Http/Requests/CreateSessionRequest.php | 43 ++ src/Http/Requests/DeleteCustomerRequest.php | 10 +- .../Requests/DeletePaymentLinkRequest.php | 10 +- .../Requests/DisableProfileMethodRequest.php | 29 + .../Requests/EnableProfileMethodRequest.php | 34 + .../GetPaginatedPaymentChargebacksRequest.php | 5 - .../Requests/GetPaginatedSessionsRequest.php | 19 + src/Http/Requests/GetPermissionRequest.php | 3 + src/Http/Requests/GetSessionRequest.php | 33 + src/Http/Requests/GetTerminalRequest.php | 4 +- src/Http/Requests/ListPermissionsRequest.php | 2 +- .../Requests/ResourceHydratableRequest.php | 15 + src/Http/Requests/SimpleRequest.php | 15 - src/Http/Requests/UpdateSessionRequest.php | 37 + src/Http/Response.php | 8 +- src/MollieApiClient.php | 2 + src/Resources/AnyResource.php | 21 + src/Resources/CursorCollection.php | 16 +- src/Resources/MethodCollection.php | 4 +- src/Resources/OrderLineCollection.php | 23 - src/Resources/PermissionCollection.php | 4 +- src/Resources/ResourceCollection.php | 20 + src/Resources/ResourceFactory.php | 8 +- src/Resources/SessionCollection.php | 14 +- src/Traits/ComposableFromArray.php | 2 +- src/Traits/HandlesAutoHydration.php | 4 +- ...ation.php => HandlesResourceHydration.php} | 4 +- src/Traits/HasEndpoints.php | 9 +- .../BalanceEndpointCollectionTest.php | 2 +- .../BalanceReportEndpointCollectionTest.php | 2 +- ...lanceTransactionEndpointCollectionTest.php | 2 +- .../ChargebackEndpointCollectionTest.php | 6 +- .../ClientEndpointCollectionTest.php | 10 +- .../ClientLinkEndpointCollectionTest.php | 14 +- .../CustomerEndpointCollectionTest.php | 4 +- ...CustomerPaymentsEndpointCollectionTest.php | 20 +- .../InvoiceEndpointCollectionTest.php | 10 +- .../MandateEndpointCollectionTest.php | 29 +- .../MethodEndpointCollectionTest.php | 10 +- .../MethodIssuerEndpointCollectionTest.php | 2 +- .../OnboardingEndpointCollectionTest.php | 4 +- .../OrganizationEndpointCollectionTest.php | 13 +- ...anizationPartnerEndpointCollectionTest.php | 6 +- .../PaymentCaptureEndpointCollectionTest.php | 44 +- ...aymentChargebackEndpointCollectionTest.php | 26 +- .../PaymentEndpointCollectionTest.php | 60 +- .../PaymentLinkEndpointCollectionTest.php | 45 +- ...ymentLinkPaymentEndpointCollectionTest.php | 15 +- .../PaymentRefundEndpointCollectionTest.php | 14 +- .../PaymentRouteEndpointCollectionTest.php | 11 +- .../PermissionEndpointCollectionTest.php | 8 +- .../ProfileEndpointCollectionTest.php | 42 +- .../ProfileMethodEndpointCollectionTest.php | 75 ++ .../RefundEndpointCollectionTest.php | 8 +- .../SessionEndpointCollectionTest.php | 121 ++++ ...ettlementCaptureEndpointCollectionTest.php | 10 +- ...lementChargebackEndpointCollectionTest.php | 6 +- ...ettlementPaymentEndpointCollectionTest.php | 8 +- ...SettlementRefundEndpointCollectionTest.php | 8 +- .../SettlementsEndpointCollectionTest.php | 144 ++-- .../SubscriptionEndpointCollectionTest.php | 59 +- ...scriptionPaymentEndpointCollectionTest.php | 9 +- .../TerminalEndpointCollectionTest.php | 11 +- .../WalletEndpointCollectionTest.php | 14 +- tests/Fixtures/MockClient.php | 2 +- .../Requests/DynamicDeleteRequest.php | 36 + tests/Fixtures/Requests/DynamicGetRequest.php | 10 + tests/Fixtures/Responses/chargeback-list.json | 353 +++++----- tests/Fixtures/Responses/client-list.json | 2 +- tests/Fixtures/Responses/organization.json | 1 + tests/Fixtures/Responses/payment-list.json | 4 +- tests/Fixtures/Responses/payment.json | 2 +- tests/Fixtures/Responses/route.json | 13 + tests/Fixtures/Responses/session-list.json | 53 ++ tests/Fixtures/Responses/session.json | 9 +- tests/Helpers/ArrTest.php | 2 +- tests/Helpers/HandlersTest.php | 2 +- tests/Helpers/MiddlewareHandlersTest.php | 2 +- tests/Helpers/UrlTest.php | 2 +- .../Adapter/GuzzleMollieHttpAdapterTest.php | 2 +- .../Adapter/MollieHttpAdapterPickerTest.php | 2 +- .../Adapter/RetryMiddlewareFactoryTest.php | 2 +- .../Auth/BearetTokenAuthenticatorTest.php | 2 +- tests/Http/Middleware/GuardResponseTest.php | 2 +- .../Endpoints/BalanceReportEndpointTest.php | 398 ----------- .../BalanceTransactionEndpointTest.php | 380 ---------- .../Mollie/API/Endpoints/BaseEndpointTest.php | 77 --- .../API/Endpoints/ChargebackEndpointTest.php | 283 -------- .../API/Endpoints/ClientEndpointTest.php | 166 ----- .../API/Endpoints/ClientLinkEndpointTest.php | 126 ---- .../API/Endpoints/CustomerEndpointTest.php | 276 -------- .../Endpoints/CustomerPaymentEndpointTest.php | 315 --------- ...ustomerSubscriptionPaymentEndpointTest.php | 112 --- .../API/Endpoints/InvoiceEndpointTest.php | 319 --------- .../API/Endpoints/MandateEndpointTest.php | 427 ------------ .../API/Endpoints/MethodEndpointTest.php | 644 ----------------- .../Endpoints/MethodIssuerEndpointTest.php | 57 -- .../API/Endpoints/OnboardingEndpointTest.php | 82 --- .../Endpoints/OrganizationEndpointTest.php | 125 ---- .../OrganizationPartnerEndpointTest.php | 58 -- .../Endpoints/PaymentCaptureEndpointTest.php | 310 --------- .../PaymentChargebackEndpointTest.php | 403 ----------- .../API/Endpoints/PaymentEndpointTest.php | 628 ----------------- .../API/Endpoints/PaymentLinkEndpointTest.php | 353 ---------- .../PaymentLinkPaymentEndpointTest.php | 90 --- .../Endpoints/PaymentRefundEndpointTest.php | 601 ---------------- .../Endpoints/PaymentRouteEndpointTest.php | 49 -- .../API/Endpoints/PermissionEndpointTest.php | 169 ----- .../API/Endpoints/ProfileEndpointTest.php | 500 ------------- .../Endpoints/ProfileMethodEndpointTest.php | 230 ------ .../API/Endpoints/RefundEndpointTest.php | 163 ----- .../API/Endpoints/SessionEndpointTest.php | 361 ---------- .../SettlementCaptureEndpointTest.php | 99 --- .../SettlementChargebackEndpointTest.php | 89 --- .../API/Endpoints/SettlementEndpointTest.php | 654 ------------------ .../SettlementPaymentsEndpointTest.php | 90 --- .../SettlementRefundEndpointTest.php | 92 --- .../Endpoints/SubscriptionEndpointTest.php | 554 --------------- .../SubscriptionPaymentEndpointTest.php | 86 --- .../API/Endpoints/TerminalEndpointTest.php | 298 -------- .../API/Endpoints/WalletEndpointTest.php | 55 -- tests/MollieApiClientTest.php | 92 ++- tests/Resources/CursorCollectionTest.php | 21 +- tests/Resources/InvoiceTest.php | 2 +- tests/Resources/LazyCollectionTest.php | 2 +- tests/Resources/MandateCollectionTest.php | 2 +- tests/Resources/MethodTest.php | 2 +- tests/Resources/OrderLineCollectionTest.php | 37 - tests/Resources/ResourceFactoryTest.php | 2 +- tests/Resources/ShipmentTest.php | 84 --- tests/TestCase.php | 16 + tests/Traits/ResolvesValuesTest.php | 2 +- tests/Types/MandateMethodTest.php | 2 +- 159 files changed, 1582 insertions(+), 10790 deletions(-) create mode 100644 src/EndpointCollection/ProfileMethodEndpointCollection.php delete mode 100644 src/Endpoints/ProfileMethodEndpoint.php delete mode 100644 src/Endpoints/SessionEndpoint.php create mode 100644 src/Http/Payload/AnyPayload.php create mode 100644 src/Http/Query/AnyQuery.php create mode 100644 src/Http/Requests/CancelSessionRequest.php create mode 100644 src/Http/Requests/CreateSessionRequest.php create mode 100644 src/Http/Requests/DisableProfileMethodRequest.php create mode 100644 src/Http/Requests/EnableProfileMethodRequest.php create mode 100644 src/Http/Requests/GetPaginatedSessionsRequest.php create mode 100644 src/Http/Requests/GetSessionRequest.php delete mode 100644 src/Http/Requests/SimpleRequest.php create mode 100644 src/Http/Requests/UpdateSessionRequest.php create mode 100644 src/Resources/AnyResource.php delete mode 100644 src/Resources/OrderLineCollection.php create mode 100644 src/Resources/ResourceCollection.php rename src/Traits/{HandlesResourceCreation.php => HandlesResourceHydration.php} (94%) create mode 100644 tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php create mode 100644 tests/EndpointCollection/SessionEndpointCollectionTest.php create mode 100644 tests/Fixtures/Requests/DynamicDeleteRequest.php create mode 100644 tests/Fixtures/Requests/DynamicGetRequest.php create mode 100644 tests/Fixtures/Responses/route.json create mode 100644 tests/Fixtures/Responses/session-list.json delete mode 100644 tests/Mollie/API/Endpoints/BalanceReportEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/BaseEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ChargebackEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ClientEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/CustomerEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/InvoiceEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/MandateEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/MethodEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OnboardingEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrganizationEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/PermissionEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ProfileEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/RefundEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SessionEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SettlementEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/TerminalEndpointTest.php delete mode 100644 tests/Mollie/API/Endpoints/WalletEndpointTest.php delete mode 100644 tests/Resources/OrderLineCollectionTest.php delete mode 100644 tests/Resources/ShipmentTest.php create mode 100644 tests/TestCase.php diff --git a/src/Contracts/SupportsResourceHydration.php b/src/Contracts/SupportsResourceHydration.php index 357b72a44..15dd30e06 100644 --- a/src/Contracts/SupportsResourceHydration.php +++ b/src/Contracts/SupportsResourceHydration.php @@ -4,5 +4,9 @@ interface SupportsResourceHydration { + public static function hydrate(bool $shouldAutoHydrate = true): void; + + public function shouldAutoHydrate(): bool; + public function getTargetResourceClass(): string; } diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index 7590a615a..b5ca5fa99 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -82,12 +82,11 @@ public function update(string $id, $data = []): ?Customer * * @throws ApiException */ - public function delete(string $id, $testmode = []): ?Customer + public function delete(string $id, $testmode = []): void { $testmode = Helpers::extractBool($testmode, 'testmode', false); - /** @var null|Customer */ - return $this->send((new DeleteCustomerRequest($id))->test($testmode)); + $this->send((new DeleteCustomerRequest($id))->test($testmode)); } /** diff --git a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php index 1ba9ee4fc..8a2b8662a 100644 --- a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php +++ b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php @@ -21,10 +21,12 @@ class CustomerPaymentsEndpointCollection extends EndpointCollection /** * Create a subscription for a Customer * + * @param array|CreatePaymentPayload $payload + * @param array|CreatePaymentQuery $query * * @throws ApiException */ - public function createFor(Customer $customer, array $payload = [], array $query = [], bool $testmode = false): Payment + public function createFor(Customer $customer, $payload = [], $query = [], bool $testmode = false): Payment { return $this->createForId($customer->id, $payload, $query, $testmode); } @@ -78,10 +80,10 @@ public function pageForId(string $customerId, ?string $from = null, ?int $limit 'filters' => $filters, ])->create(); - return $this->send(new GetPaginatedCustomerPaymentsRequest( + return $this->send((new GetPaginatedCustomerPaymentsRequest( $customerId, $query - ))->test($testmode); + ))->test($testmode)); } /** diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php index 1314c54b1..9a46792f5 100644 --- a/src/EndpointCollection/MandateEndpointCollection.php +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -21,7 +21,7 @@ class MandateEndpointCollection extends EndpointCollection /** * Creates a mandate for a specific customer. * - * @param array $payload + * @param array|CreateMandatePayload $payload * * @throws ApiException */ diff --git a/src/EndpointCollection/MethodIssuerEndpointCollection.php b/src/EndpointCollection/MethodIssuerEndpointCollection.php index 5da33703a..ee28f3bde 100644 --- a/src/EndpointCollection/MethodIssuerEndpointCollection.php +++ b/src/EndpointCollection/MethodIssuerEndpointCollection.php @@ -26,6 +26,6 @@ public function enable(string $profileId, string $methodId, string $issuerId, ?s */ public function disable(string $profileId, string $methodId, string $issuerId): void { - return $this->send(new DisableMethodIssuerRequest($profileId, $methodId, $issuerId)); + $this->send(new DisableMethodIssuerRequest($profileId, $methodId, $issuerId)); } } diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index 54ffe5843..f3dd1cbb6 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -61,7 +61,7 @@ public function get(string $paymentLinkId, $testmode = []): PaymentLink * * @throws ApiException */ - public function update(string $paymentLinkId, $payload = [], ?bool $testmode = null): PaymentLink + public function update(string $paymentLinkId, $payload = [], bool $testmode = false): PaymentLink { if (! $payload instanceof UpdatePaymentLinkPayload) { $payload = UpdatePaymentLinkPayloadFactory::new($payload)->create(); @@ -77,7 +77,7 @@ public function update(string $paymentLinkId, $payload = [], ?bool $testmode = n * * @throws ApiException */ - public function delete(string $paymentLinkId, ?bool $testmode = null): void + public function delete(string $paymentLinkId, bool $testmode = false): void { $this->send((new DeletePaymentLinkRequest($paymentLinkId))->test($testmode)); } @@ -107,12 +107,13 @@ public function page(?string $from = null, ?int $limit = null, $testmode = []): * Create an iterator for iterating over payment links retrieved from Mollie. * * @param string|null $from The first resource ID you want to include in your list. + * @param bool $testmode * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iterator( ?string $from = null, ?int $limit = null, - ?bool $testmode = null, + $testmode = [], bool $iterateBackwards = false ): LazyCollection { $testmode = Helpers::extractBool($testmode, 'testmode', false); diff --git a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php index 1714a3ea7..7c975392a 100644 --- a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php @@ -20,7 +20,7 @@ class PaymentLinkPaymentEndpointCollection extends EndpointCollection * * @throws ApiException */ - public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, ?array $filters = null): PaymentCollection + public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { return $this->pageForId($paymentLink->id, $from, $limit, $filters); } @@ -32,7 +32,7 @@ public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $li * * @throws ApiException */ - public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, ?array $filters = null): PaymentCollection + public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { $testmode = Helpers::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ @@ -55,7 +55,7 @@ public function iteratorFor( PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, - ?array $filters = null, + array $filters = [], bool $iterateBackwards = false ): LazyCollection { return $this->iteratorForId( @@ -77,7 +77,7 @@ public function iteratorForId( string $paymentLinkId, ?string $from = null, ?int $limit = null, - ?array $filters = null, + array $filters = [], bool $iterateBackwards = false ): LazyCollection { $testmode = Helpers::extractBool($filters, 'testmode', false); diff --git a/src/EndpointCollection/PaymentRouteEndpointCollection.php b/src/EndpointCollection/PaymentRouteEndpointCollection.php index 817a1c0cb..2798da10e 100644 --- a/src/EndpointCollection/PaymentRouteEndpointCollection.php +++ b/src/EndpointCollection/PaymentRouteEndpointCollection.php @@ -18,7 +18,7 @@ class PaymentRouteEndpointCollection extends EndpointCollection * * @throws ApiException */ - public function updateReleaseDateFor(Payment $payment, string $routeId, string $releaseDate, ?bool $testmode = null): Route + public function updateReleaseDateFor(Payment $payment, string $routeId, string $releaseDate, bool $testmode = false): Route { return $this->updateReleaseDateForId($payment->id, $routeId, $releaseDate, $testmode); } @@ -30,7 +30,7 @@ public function updateReleaseDateFor(Payment $payment, string $routeId, string $ * * @throws ApiException */ - public function updateReleaseDateForId(string $paymentId, string $routeId, string $releaseDate, ?bool $testmode = null): Route + public function updateReleaseDateForId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): Route { $payload = UpdatePaymentRoutePayloadFactory::new([ 'releaseDate' => $releaseDate, diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index cd4ba0e00..8962f4c01 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -98,13 +98,11 @@ public function update(string $profileId, $payload = []): ?Profile * Will throw a ApiException if the profile id is invalid or the resource cannot be found. * Returns with HTTP status No Content (204) if successful. * - * * @throws ApiException */ - public function delete(string $profileId): ?Profile + public function delete(string $profileId): void { - /** @var Profile|null */ - return $this->send(new DeleteProfileRequest($profileId)); + $this->send(new DeleteProfileRequest($profileId)); } /** diff --git a/src/EndpointCollection/ProfileMethodEndpointCollection.php b/src/EndpointCollection/ProfileMethodEndpointCollection.php new file mode 100644 index 000000000..ca8415a75 --- /dev/null +++ b/src/EndpointCollection/ProfileMethodEndpointCollection.php @@ -0,0 +1,159 @@ +enableForId($profileId, $id); + } + + /** + * Enable a method for the provided Profile object. + * Alias of enableFor for backwards compatibility. + * + * @param Profile $profile + * @param string $id + * @throws ApiException + */ + public function createFor(Profile $profile, string $id): Method + { + return $this->enableFor($profile, $id); + } + + /** + * Enable a method for the current profile. + * Alias of enable for backwards compatibility. + * + * @param string $id + * @throws ApiException + */ + public function createForCurrentProfile(string $id): Method + { + return $this->enable($id); + } + + /** + * Enable a payment method for a specific profile. + * + * @param string $profileId The profile's ID or 'me' for the current profile + * @param string $id The payment method ID + * @throws ApiException + */ + public function enableForId(string $profileId, string $id): Method + { + /** @var Method */ + return $this->send(new EnableProfileMethodRequest($profileId, $id)); + } + + /** + * Enable a payment method for the provided Profile object. + * + * @param Profile $profile + * @param string $id The payment method ID + * @throws ApiException + */ + public function enableFor(Profile $profile, string $id): Method + { + return $this->enableForId($profile->id, $id); + } + + /** + * Enable a payment method for the current profile. + * + * @param string $id The payment method ID + * @throws ApiException + */ + public function enable(string $id): Method + { + return $this->enableForId('me', $id); + } + + /** + * Disable a method for the provided Profile ID. + * Alias of disableForId for backwards compatibility. + * + * @param string $profileId + * @param string $id + * @throws ApiException + */ + public function deleteForId(string $profileId, string $id): void + { + $this->disableForId($profileId, $id); + } + + /** + * Disable a method for the provided Profile object. + * Alias of disableFor for backwards compatibility. + * + * @param Profile $profile + * @param string $id + * @throws ApiException + */ + public function deleteFor(Profile $profile, string $id): void + { + $this->disableFor($profile, $id); + } + + /** + * Disable a method for the current profile. + * Alias of disable for backwards compatibility. + * + * @param string $id + * @throws ApiException + */ + public function deleteForCurrentProfile(string $id): void + { + $this->disable($id); + } + + /** + * Disable a payment method for a specific profile. + * + * @param string $profileId The profile's ID or 'me' for the current profile + * @param string $id The payment method ID + * @throws ApiException + */ + public function disableForId(string $profileId, string $id): void + { + $this->send(new DisableProfileMethodRequest($profileId, $id)); + } + + /** + * Disable a payment method for the provided Profile object. + * + * @param Profile $profile + * @param string $id The payment method ID + * @throws ApiException + */ + public function disableFor(Profile $profile, string $id): void + { + $this->disableForId($profile->id, $id); + } + + /** + * Disable a payment method for the current profile. + * + * @param string $id The payment method ID + * @throws ApiException + */ + public function disable(string $id): void + { + $this->disableForId('me', $id); + } +} diff --git a/src/EndpointCollection/SessionEndpointCollection.php b/src/EndpointCollection/SessionEndpointCollection.php index dc20d3dfa..ac0e06cc1 100644 --- a/src/EndpointCollection/SessionEndpointCollection.php +++ b/src/EndpointCollection/SessionEndpointCollection.php @@ -3,11 +3,8 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateSessionPayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdateSessionPayloadFactory; -use Mollie\Api\Http\Payload\CreateSessionPayload; -use Mollie\Api\Http\Payload\UpdateSessionPayload; +use Mollie\Api\Factories\SortablePaginatedQueryFactory; +use Mollie\Api\Http\Payload\AnyPayload; use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; @@ -16,6 +13,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; +use Mollie\Api\Http\Query\AnyQuery; class SessionEndpointCollection extends EndpointCollection { @@ -24,30 +22,39 @@ class SessionEndpointCollection extends EndpointCollection * * Will throw a ApiException if the session id is invalid or the resource cannot be found. * + * @param string $sessionId + * @param array|AnyQuery $query * @throws ApiException */ - public function get(string $sessionId, array $parameters = []): Session + public function get(string $sessionId, $query = []): Session { + if (! $query instanceof AnyQuery) { + $query = AnyQuery::fromArray($query); + } + /** @var Session */ - return $this->send(new GetSessionRequest($sessionId, $parameters)); + return $this->send(new GetSessionRequest($sessionId, $query)); } /** * Creates a session in Mollie. * - * @param CreateSessionPayload|array $data An array containing details on the session. - * + * @param array|AnyPayload $payload + * @param array|AnyQuery $query * @throws ApiException */ - public function create($data = [], array $filters = []): Session + public function create($payload = [], $query = []): Session { - if (! $data instanceof CreateSessionPayload) { - $data = CreateSessionPayloadFactory::new($data) - ->create(); + if (! $payload instanceof AnyPayload) { + $payload = AnyPayload::fromArray($payload); + } + + if (! $query instanceof AnyQuery) { + $query = AnyQuery::fromArray($query); } /** @var Session */ - return $this->send(new CreateSessionRequest($data, $filters)); + return $this->send(new CreateSessionRequest($payload, $query)); } /** @@ -55,19 +62,18 @@ public function create($data = [], array $filters = []): Session * * Will throw a ApiException if the session id is invalid or the resource cannot be found. * - * @param array|UpdateSessionPayload $data + * @param array|AnyPayload $payload * * @throws ApiException */ - public function update(string $id, $data = []): Session + public function update(string $id, $payload = []): Session { - if (! $data instanceof UpdateSessionPayload) { - $data = UpdateSessionPayloadFactory::new($data) - ->create(); + if (! $payload instanceof AnyPayload) { + $payload = AnyPayload::fromArray($payload); } /** @var Session */ - return $this->send(new UpdateSessionRequest($id, $data)); + return $this->send(new UpdateSessionRequest($id, $payload)); } /** @@ -77,10 +83,10 @@ public function update(string $id, $data = []): Session * * @throws ApiException */ - public function cancel(string $id, array $parameters = []): ?Session + public function cancel(string $id): ?Session { /** @var Session|null */ - return $this->send(new CancelSessionRequest($id, $parameters)); + return $this->send(new CancelSessionRequest($id)); } /** @@ -92,7 +98,7 @@ public function cancel(string $id, array $parameters = []): ?Session */ public function page(?string $from = null, ?int $limit = null, array $filters = []): SessionCollection { - $query = PaginatedQueryFactory::new([ + $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, @@ -114,7 +120,7 @@ public function iterator( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $query = PaginatedQueryFactory::new([ + $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, diff --git a/src/EndpointCollection/SubscriptionEndpointCollection.php b/src/EndpointCollection/SubscriptionEndpointCollection.php index 46a08da3c..5d7ecee9f 100644 --- a/src/EndpointCollection/SubscriptionEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionEndpointCollection.php @@ -83,7 +83,7 @@ public function createForId(string $customerId, $data = [], bool $testmode = fal * * @throws ApiException */ - public function update(string $customerId, string $subscriptionId, $data = [], ?bool $testmode = null): ?Subscription + public function update(string $customerId, string $subscriptionId, $data = [], bool $testmode = false): ?Subscription { if (! $data instanceof UpdateSubscriptionPayload) { $testmode = Helpers::extractBool($data, 'testmode', $testmode); @@ -98,7 +98,7 @@ public function update(string $customerId, string $subscriptionId, $data = [], ? * * @throws ApiException */ - public function cancelFor(Customer $customer, string $subscriptionId, ?bool $testmode = null): ?Subscription + public function cancelFor(Customer $customer, string $subscriptionId, bool $testmode = false): ?Subscription { return $this->cancelForId($customer->id, $subscriptionId, $testmode); } @@ -108,7 +108,7 @@ public function cancelFor(Customer $customer, string $subscriptionId, ?bool $tes * * @throws ApiException */ - public function cancelForId(string $customerId, string $subscriptionId, ?bool $testmode = null): ?Subscription + public function cancelForId(string $customerId, string $subscriptionId, bool $testmode = false): ?Subscription { return $this->send((new CancelSubscriptionRequest($customerId, $subscriptionId))->test($testmode)); } diff --git a/src/EndpointCollection/WalletEndpointCollection.php b/src/EndpointCollection/WalletEndpointCollection.php index a3bf6967b..32f064dd4 100644 --- a/src/EndpointCollection/WalletEndpointCollection.php +++ b/src/EndpointCollection/WalletEndpointCollection.php @@ -5,6 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\ApplePayPaymentSessionPayloadFactory; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; +use Mollie\Api\Resources\AnyResource; class WalletEndpointCollection extends EndpointCollection { @@ -12,18 +13,17 @@ class WalletEndpointCollection extends EndpointCollection * Obtain a new ApplePay payment session. * * @param array $parameters Additional parameters - * @return string The payment session data + * @return AnyResource The payment session data * * @throws ApiException */ - public function requestApplePayPaymentSession(string $domain, string $validationUrl, array $parameters = []): string + public function requestApplePayPaymentSession(string $domain, string $validationUrl, array $parameters = []): AnyResource { $payload = ApplePayPaymentSessionPayloadFactory::new(array_merge([ 'domain' => $domain, 'validationUrl' => $validationUrl, ], $parameters))->create(); - /** @var string */ return $this->send(new ApplePayPaymentSessionRequest($payload)); } } diff --git a/src/Endpoints/ProfileMethodEndpoint.php b/src/Endpoints/ProfileMethodEndpoint.php deleted file mode 100644 index d2b867d26..000000000 --- a/src/Endpoints/ProfileMethodEndpoint.php +++ /dev/null @@ -1,109 +0,0 @@ -parentId = $profileId; - - $result = $this->client->performHttpCall( - self::REST_CREATE, - $this->getResourcePath().'/'.urlencode($methodId), - $this->parseRequestBody($data) - ); - - /** @var Method */ - return ResourceFactory::createFromApiResult($this->client, $result, static::getResourceClass()); - } - - /** - * Enable a method for the provided Profile object. - * - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createFor(Profile $profile, string $methodId, array $data = []): Method - { - return $this->createForId($profile->id, $methodId, $data); - } - - /** - * Enable a method for the current profile. - * - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function createForCurrentProfile(string $methodId, array $data = []): Method - { - return $this->createForId('me', $methodId, $data); - } - - /** - * Disable a method for the provided Profile ID. - * - * @param string $profileId - * @param string $methodId - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function deleteForId($profileId, $methodId, array $data = []): ?Method - { - $this->parentId = $profileId; - - /** @var null|Method */ - return $this->deleteResource($methodId, $data); - } - - /** - * Disable a method for the provided Profile object. - * - * @param Profile $profile - * @param string $methodId - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function deleteFor($profile, $methodId, array $data = []): ?Method - { - return $this->deleteForId($profile->id, $methodId, $data); - } - - /** - * Disable a method for the current profile. - * - * @param string $methodId - * - * @throws \Mollie\Api\Exceptions\ApiException - */ - public function deleteForCurrentProfile($methodId, array $data): ?Method - { - return $this->deleteForId('me', $methodId, $data); - } -} diff --git a/src/Endpoints/SessionEndpoint.php b/src/Endpoints/SessionEndpoint.php deleted file mode 100644 index 0f30bf1d0..000000000 --- a/src/Endpoints/SessionEndpoint.php +++ /dev/null @@ -1,131 +0,0 @@ -client); - } - - /** - * Get the collection object that is used by this API endpoint. Every API - * endpoint uses one type of collection object. - * - * @param int $count - * @param \stdClass $_links - * @return SessionCollection - */ - protected function getResourceCollectionObject($count, $_links) - { - return new SessionCollection($this->client, $count, $_links); - } - - /** - * Creates a session in Mollie. - * - * @param array $data An array containing details on the session. - * @return Session - * - * @throws ApiException - */ - public function create(array $data = [], array $filters = []) - { - return $this->createResource($data, $filters); - } - - /** - * Update a specific Session resource - * - * Will throw a ApiException if the resource id is invalid or the resource cannot be found. - * - * @param string $resourceId - * @return Session - * - * @throws ApiException - */ - public function update($resourceId, array $data = []) - { - if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '".self::RESOURCE_ID_PREFIX."'."); - } - - return $this->updateResource($resourceId, $data); - } - - /** - * Retrieve a single session from Mollie. - * - * Will throw a ApiException if the resource id is invalid or the resource cannot - * be found. - * - * @return Session - * - * @throws ApiException - */ - public function get($resourceId, array $parameters = []) - { - if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '".self::RESOURCE_ID_PREFIX."'."); - } - - return $this->readResource($resourceId, $parameters); - } - - /** - * Cancel the given Session. - * - * @param string $resourceId - * @param array $parameters - * @return Session - * - * @throws ApiException - */ - public function cancel($resourceId, $parameters = []) - { - return $this->deleteResource($resourceId, $parameters); - } - - /** - * Retrieves a collection of Sessions from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @return SessionCollection - * - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $parameters = []) - { - return $this->fetchCollection($from, $limit, $parameters); - } - - /** - * Create an iterator for iterating over sessions retrieved from Mollie. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse resource iteration (default is false). - */ - public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection - { - return $this->createIterator($from, $limit, $parameters, $iterateBackwards); - } -} diff --git a/src/Factories/GetAllPaymentMethodsQueryFactory.php b/src/Factories/GetAllPaymentMethodsQueryFactory.php index 4fb790cf0..58c0e2722 100644 --- a/src/Factories/GetAllPaymentMethodsQueryFactory.php +++ b/src/Factories/GetAllPaymentMethodsQueryFactory.php @@ -14,9 +14,9 @@ public function create(): GetAllMethodsQuery $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); return new GetAllMethodsQuery( - $this->get('locale'), $this->get('includeIssuers', $includeIssuers), $this->get('includePricing', $includePricing), + $this->get('locale'), $this->mapIfNotNull('amount', MoneyFactory::class) ); } diff --git a/src/Http/Middleware/Hydrate.php b/src/Http/Middleware/Hydrate.php index 348b382a3..0a0a51d92 100644 --- a/src/Http/Middleware/Hydrate.php +++ b/src/Http/Middleware/Hydrate.php @@ -4,18 +4,20 @@ use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Traits\HandlesResourceCreation; +use Mollie\Api\Traits\HandlesResourceHydration; class Hydrate { - use HandlesResourceCreation; + use HandlesResourceHydration; public function __invoke(Response $response) { - if (! $response->getRequest()::$shouldAutoHydrate || ! $response->getRequest() instanceof ResourceHydratableRequest) { + $request = $response->getRequest(); + + if (! $request instanceof ResourceHydratableRequest || ! $request->shouldAutoHydrate()) { return $response; } - return $this->createResource($response->getRequest(), $response); + return $this->hydrate($request, $response); } } diff --git a/src/Http/Payload/AnyPayload.php b/src/Http/Payload/AnyPayload.php new file mode 100644 index 000000000..7fc8cb5fb --- /dev/null +++ b/src/Http/Payload/AnyPayload.php @@ -0,0 +1,22 @@ +data = $data; + } + + public function data(): array + { + return $this->data ?? []; + } +} diff --git a/src/Http/Query/AnyQuery.php b/src/Http/Query/AnyQuery.php new file mode 100644 index 000000000..a704cbfe0 --- /dev/null +++ b/src/Http/Query/AnyQuery.php @@ -0,0 +1,22 @@ +data = $data; + } + + public function toArray(): array + { + return $this->data ?? []; + } +} diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php index 967d24767..55b82d93f 100644 --- a/src/Http/Query/GetAllMethodsQuery.php +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -7,7 +7,7 @@ class GetAllMethodsQuery extends Query { - private string $locale; + private ?string $locale; private bool $includeIssuers; @@ -16,9 +16,9 @@ class GetAllMethodsQuery extends Query private ?Money $amount; public function __construct( - string $locale, bool $includeIssuers = false, bool $includePricing = false, + ?string $locale = null, ?Money $amount = null, ) { $this->locale = $locale; diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index e2dfde18e..e877e37b1 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -29,8 +29,8 @@ public function toArray(): array 'amount' => $this->amount?->data(), 'resource' => $this->resource, 'billingCountry' => $this->billingCountry, - 'includeWallets' => Arr::join($this->includeWallets), - 'orderLineCategories' => Arr::join($this->orderLineCategories), + 'includeWallets' => Arr::join($this->includeWallets ?? []), + 'orderLineCategories' => Arr::join($this->orderLineCategories ?? []), 'profileId' => $this->profileId, 'include' => array_filter([ $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, diff --git a/src/Http/Request.php b/src/Http/Request.php index 15bfda7b0..9ba7e92fa 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -18,13 +18,6 @@ abstract class Request */ protected static string $method; - public static bool $shouldAutoHydrate = false; - - public static function hydrate(bool $shouldAutoHydrate = true): void - { - self::$shouldAutoHydrate = $shouldAutoHydrate; - } - /** * Get the method of the request. */ diff --git a/src/Http/Requests/ApplePayPaymentSessionRequest.php b/src/Http/Requests/ApplePayPaymentSessionRequest.php index 461eeb615..a445cb4c6 100644 --- a/src/Http/Requests/ApplePayPaymentSessionRequest.php +++ b/src/Http/Requests/ApplePayPaymentSessionRequest.php @@ -4,16 +4,18 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Http\Payload\RequestApplePayPaymentSessionPayload; -use Mollie\Api\Http\Request; +use Mollie\Api\Resources\AnyResource; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; -class ApplePayPaymentSessionRequest extends Request implements HasPayload, ResourceHydratable +class ApplePayPaymentSessionRequest extends ResourceHydratableRequest implements HasPayload { use HasJsonPayload; protected static string $method = Method::POST; + public static string $targetResourceClass = AnyResource::class; + private RequestApplePayPaymentSessionPayload $payload; public function __construct(RequestApplePayPaymentSessionPayload $payload) diff --git a/src/Http/Requests/CancelSessionRequest.php b/src/Http/Requests/CancelSessionRequest.php new file mode 100644 index 000000000..f28c62a17 --- /dev/null +++ b/src/Http/Requests/CancelSessionRequest.php @@ -0,0 +1,25 @@ +sessionId = $sessionId; + } + + public function resolveResourcePath(): string + { + return "sessions/{$this->sessionId}"; + } +} diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php index dfa6cd1ea..756ae998a 100644 --- a/src/Http/Requests/CreateCustomerRequest.php +++ b/src/Http/Requests/CreateCustomerRequest.php @@ -15,7 +15,7 @@ class CreateCustomerRequest extends ResourceHydratableRequest implements HasPayl protected static string $method = Method::POST; - protected static string $targetResourceClass = Customer::class; + public static string $targetResourceClass = Customer::class; private CreateCustomerPayload $payload; diff --git a/src/Http/Requests/CreateProfileRequest.php b/src/Http/Requests/CreateProfileRequest.php index ed1e44e10..a16262501 100644 --- a/src/Http/Requests/CreateProfileRequest.php +++ b/src/Http/Requests/CreateProfileRequest.php @@ -26,7 +26,6 @@ class CreateProfileRequest extends ResourceHydratableRequest implements HasPaylo public function __construct(CreateProfilePayload $payload) { - parent::__construct(); $this->payload = $payload; } diff --git a/src/Http/Requests/CreateSessionRequest.php b/src/Http/Requests/CreateSessionRequest.php new file mode 100644 index 000000000..87568e767 --- /dev/null +++ b/src/Http/Requests/CreateSessionRequest.php @@ -0,0 +1,43 @@ +payload = $payload; + $this->query = $query; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + public function resolveResourcePath(): string + { + return 'sessions'; + } +} diff --git a/src/Http/Requests/DeleteCustomerRequest.php b/src/Http/Requests/DeleteCustomerRequest.php index b0c682350..6eb2c009a 100644 --- a/src/Http/Requests/DeleteCustomerRequest.php +++ b/src/Http/Requests/DeleteCustomerRequest.php @@ -3,12 +3,20 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Http\Request; use Mollie\Api\Types\Method; -class DeleteCustomerRequest extends SimpleRequest implements SupportsTestmodeInQuery +class DeleteCustomerRequest extends Request implements SupportsTestmodeInQuery { protected static string $method = Method::DELETE; + protected string $id; + + public function __construct(string $id) + { + $this->id = $id; + } + public function resolveResourcePath(): string { return "customers/{$this->id}"; diff --git a/src/Http/Requests/DeletePaymentLinkRequest.php b/src/Http/Requests/DeletePaymentLinkRequest.php index 4ddcc0572..7fb89041e 100644 --- a/src/Http/Requests/DeletePaymentLinkRequest.php +++ b/src/Http/Requests/DeletePaymentLinkRequest.php @@ -3,12 +3,20 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Http\Request; use Mollie\Api\Types\Method; -class DeletePaymentLinkRequest extends SimpleRequest implements SupportsTestmodeInQuery +class DeletePaymentLinkRequest extends Request implements SupportsTestmodeInQuery { protected static string $method = Method::DELETE; + protected string $id; + + public function __construct(string $id) + { + $this->id = $id; + } + public function resolveResourcePath(): string { return "payment-links/{$this->id}"; diff --git a/src/Http/Requests/DisableProfileMethodRequest.php b/src/Http/Requests/DisableProfileMethodRequest.php new file mode 100644 index 000000000..b687243f7 --- /dev/null +++ b/src/Http/Requests/DisableProfileMethodRequest.php @@ -0,0 +1,29 @@ +profileId = $profileId; + $this->methodId = $methodId; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->profileId}/methods/{$this->methodId}"; + } +} diff --git a/src/Http/Requests/EnableProfileMethodRequest.php b/src/Http/Requests/EnableProfileMethodRequest.php new file mode 100644 index 000000000..4356e82e9 --- /dev/null +++ b/src/Http/Requests/EnableProfileMethodRequest.php @@ -0,0 +1,34 @@ +profileId = $profileId; + $this->methodId = $methodId; + } + + public function resolveResourcePath(): string + { + return "profiles/{$this->profileId}/methods/{$this->methodId}"; + } +} diff --git a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php index 68acb0bdb..ec95c5b78 100644 --- a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php @@ -32,11 +32,6 @@ public function __construct(string $paymentId, ?GetPaginatedPaymentChargebacksQu $this->paymentId = $paymentId; } - protected function defaultQuery(): array - { - return $this->query ? $this->query->toArray() : []; - } - public function resolveResourcePath(): string { return "payments/{$this->paymentId}/chargebacks"; diff --git a/src/Http/Requests/GetPaginatedSessionsRequest.php b/src/Http/Requests/GetPaginatedSessionsRequest.php new file mode 100644 index 000000000..aa4f36fb4 --- /dev/null +++ b/src/Http/Requests/GetPaginatedSessionsRequest.php @@ -0,0 +1,19 @@ +sessionId = $sessionId; + $this->query = $query; + } + + protected function defaultQuery(): array + { + return $this->query->toArray(); + } + + public function resolveResourcePath(): string + { + return "sessions/{$this->sessionId}"; + } +} diff --git a/src/Http/Requests/GetTerminalRequest.php b/src/Http/Requests/GetTerminalRequest.php index b710a3009..e777435db 100644 --- a/src/Http/Requests/GetTerminalRequest.php +++ b/src/Http/Requests/GetTerminalRequest.php @@ -4,9 +4,11 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Terminal; - +use Mollie\Api\Types\Method; class GetTerminalRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { + protected static string $method = Method::GET; + /** * The resource class the request should be casted to. */ diff --git a/src/Http/Requests/ListPermissionsRequest.php b/src/Http/Requests/ListPermissionsRequest.php index c1c7b0708..1380435a2 100644 --- a/src/Http/Requests/ListPermissionsRequest.php +++ b/src/Http/Requests/ListPermissionsRequest.php @@ -5,7 +5,7 @@ use Mollie\Api\Resources\PermissionCollection; use Mollie\Api\Types\Method; -class ListPermissionsRequest extends Request +class ListPermissionsRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index 91c91f8fc..a01b7ea0a 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -7,11 +7,26 @@ abstract class ResourceHydratableRequest extends Request implements SupportsResourceHydration { + /** + * Whether the request should be automatically hydrated. + */ + protected static bool $shouldAutoHydrate = false; + /** * The resource class the request should be casted to. */ public static string $targetResourceClass; + public static function hydrate(bool $shouldAutoHydrate = true): void + { + self::$shouldAutoHydrate = $shouldAutoHydrate; + } + + public function shouldAutoHydrate(): bool + { + return self::$shouldAutoHydrate; + } + public function getTargetResourceClass(): string { if (empty(static::$targetResourceClass)) { diff --git a/src/Http/Requests/SimpleRequest.php b/src/Http/Requests/SimpleRequest.php deleted file mode 100644 index 7fbefa71c..000000000 --- a/src/Http/Requests/SimpleRequest.php +++ /dev/null @@ -1,15 +0,0 @@ -id = $id; - } -} diff --git a/src/Http/Requests/UpdateSessionRequest.php b/src/Http/Requests/UpdateSessionRequest.php new file mode 100644 index 000000000..7ac512cff --- /dev/null +++ b/src/Http/Requests/UpdateSessionRequest.php @@ -0,0 +1,37 @@ +sessionId = $sessionId; + $this->payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload->toArray(); + } + + public function resolveResourcePath(): string + { + return "sessions/{$this->sessionId}"; + } +} diff --git a/src/Http/Response.php b/src/Http/Response.php index 0a2763d18..32be2f4e9 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -5,7 +5,7 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Requests\ResourceHydratableRequest; -use Mollie\Api\Traits\HandlesResourceCreation; +use Mollie\Api\Traits\HandlesResourceHydration; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -14,7 +14,7 @@ class Response { - use HandlesResourceCreation; + use HandlesResourceHydration; protected ResponseInterface $psrResponse; @@ -50,7 +50,7 @@ public function toResource() return $this; } - return $this->createResource($this->getRequest(), $this); + return $this->hydrate($this->getRequest(), $this); } /** @@ -59,7 +59,7 @@ public function toResource() public function json(): stdClass { if (! $this->decoded) { - $this->decoded = @json_decode($body = $this->body() ?: '[]'); + $this->decoded = @json_decode($body = $this->body() ?: '{}'); if (json_last_error() !== JSON_ERROR_NONE) { throw new ApiException("Unable to decode Mollie response: '{$body}'."); diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index d301df184..65a8ca79d 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -55,6 +55,7 @@ use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; +use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\Traits\SendsRequests; /** @@ -94,6 +95,7 @@ * @property SubscriptionEndpointCollection $subscriptions * @property SubscriptionPaymentEndpointCollection $subscriptionPayments * @property TerminalEndpointCollection $terminals + * @property SessionEndpointCollection $sessions * @property WalletEndpointCollection $wallets * @property HttpAdapterContract $httpClient */ diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php new file mode 100644 index 000000000..32fc79dab --- /dev/null +++ b/src/Resources/AnyResource.php @@ -0,0 +1,21 @@ +attributes, $name); + } + + public function fill(array|stdClass $attributes): void + { + $this->attributes = $attributes instanceof stdClass ? (array) $attributes : $attributes; + } +} diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index b7e54918d..68280ee00 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -5,13 +5,8 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; -abstract class CursorCollection extends BaseCollection +abstract class CursorCollection extends ResourceCollection { - /** - * Resource class name. - */ - public static string $resource = ''; - /** * Return the next set of resources when available * @@ -86,13 +81,4 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection } }); } - - public static function getResourceClass(): string - { - if (empty(static::$resource)) { - throw new \RuntimeException('Collection name not set'); - } - - return static::$resource; - } } diff --git a/src/Resources/MethodCollection.php b/src/Resources/MethodCollection.php index b5faabac2..32e5dd082 100644 --- a/src/Resources/MethodCollection.php +++ b/src/Resources/MethodCollection.php @@ -2,10 +2,12 @@ namespace Mollie\Api\Resources; -class MethodCollection extends BaseCollection +class MethodCollection extends ResourceCollection { /** * The name of the collection resource in Mollie's API. */ public static string $collectionName = 'methods'; + + public static string $resource = Method::class; } diff --git a/src/Resources/OrderLineCollection.php b/src/Resources/OrderLineCollection.php deleted file mode 100644 index dfaecdefc..000000000 --- a/src/Resources/OrderLineCollection.php +++ /dev/null @@ -1,23 +0,0 @@ -id === $lineId) { - return $line; - } - } - - return null; - } -} diff --git a/src/Resources/PermissionCollection.php b/src/Resources/PermissionCollection.php index dfd3be0fb..709a44c5e 100644 --- a/src/Resources/PermissionCollection.php +++ b/src/Resources/PermissionCollection.php @@ -2,10 +2,12 @@ namespace Mollie\Api\Resources; -class PermissionCollection extends BaseCollection +class PermissionCollection extends ResourceCollection { /** * The name of the collection resource in Mollie's API. */ public static string $collectionName = 'permissions'; + + public static string $resource = Permission::class; } diff --git a/src/Resources/ResourceCollection.php b/src/Resources/ResourceCollection.php new file mode 100644 index 000000000..1f1c48140 --- /dev/null +++ b/src/Resources/ResourceCollection.php @@ -0,0 +1,20 @@ + $value) { - $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) + if ($resource instanceof AnyResource) { + $resource->fill($data); + } else { + foreach ($data as $property => $value) { + $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) ? self::parseEmbeddedResources($connector, $resource, $value) : $value; + } } return $resource; diff --git a/src/Resources/SessionCollection.php b/src/Resources/SessionCollection.php index 4cdd8351b..be1eeb9cd 100644 --- a/src/Resources/SessionCollection.php +++ b/src/Resources/SessionCollection.php @@ -5,18 +5,12 @@ class SessionCollection extends CursorCollection { /** - * @return string + * The name of the collection resource in Mollie's API. */ - public function getCollectionResourceName() - { - return 'sessions'; - } + public static string $collectionName = 'sessions'; /** - * @return BaseResource + * Resource class name. */ - protected function createResourceObject() - { - return new Session($this->client); - } + public static string $resource = Session::class; } diff --git a/src/Traits/ComposableFromArray.php b/src/Traits/ComposableFromArray.php index 72954e3fd..4f9fe50a4 100644 --- a/src/Traits/ComposableFromArray.php +++ b/src/Traits/ComposableFromArray.php @@ -4,7 +4,7 @@ trait ComposableFromArray { - public static function fromArray(array $data): self + public static function fromArray(array $data = []): self { return new static(...$data); } diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php index 861b3d1f5..26736eee7 100644 --- a/src/Traits/HandlesAutoHydration.php +++ b/src/Traits/HandlesAutoHydration.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Http\Request; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; trait HandlesAutoHydration { @@ -11,7 +11,7 @@ trait HandlesAutoHydration public static function shouldAutoHydrate(bool $shouldAutoHydrate = true): void { static::$hydrationSettingResolver = static function () use ($shouldAutoHydrate) { - Request::hydrate($shouldAutoHydrate); + ResourceHydratableRequest::hydrate($shouldAutoHydrate); }; } diff --git a/src/Traits/HandlesResourceCreation.php b/src/Traits/HandlesResourceHydration.php similarity index 94% rename from src/Traits/HandlesResourceCreation.php rename to src/Traits/HandlesResourceHydration.php index 302049f3a..1b4fc9b9b 100644 --- a/src/Traits/HandlesResourceCreation.php +++ b/src/Traits/HandlesResourceHydration.php @@ -12,12 +12,12 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceFactory; -trait HandlesResourceCreation +trait HandlesResourceHydration { /** * @return mixed */ - protected function createResource(ResourceHydratableRequest $request, Response $response) + protected function hydrate(ResourceHydratableRequest $request, Response $response) { $targetResourceClass = $request->getTargetResourceClass(); diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index f9fc7a863..6fce32bab 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -18,6 +18,7 @@ use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationPartnerEndpointCollection; use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; +use Mollie\Api\EndpointCollection\PaymentChargebackEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; use Mollie\Api\EndpointCollection\PaymentLinkEndpointCollection; use Mollie\Api\EndpointCollection\PaymentLinkPaymentEndpointCollection; @@ -25,6 +26,7 @@ use Mollie\Api\EndpointCollection\PaymentRouteEndpointCollection; use Mollie\Api\EndpointCollection\PermissionEndpointCollection; use Mollie\Api\EndpointCollection\ProfileEndpointCollection; +use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; use Mollie\Api\EndpointCollection\RefundEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; @@ -35,7 +37,7 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\Endpoints\ProfileMethodEndpoint; +use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\MollieApiClient; /** @@ -72,14 +74,15 @@ protected function initializeHasEndpoints(): void 'payments' => PaymentEndpointCollection::class, 'paymentRefunds' => PaymentRefundEndpointCollection::class, 'paymentCaptures' => PaymentCaptureEndpointCollection::class, - 'paymentChargebacks' => ChargebackEndpointCollection::class, + 'paymentChargebacks' => PaymentChargebackEndpointCollection::class, 'paymentLinks' => PaymentLinkEndpointCollection::class, 'paymentLinkPayments' => PaymentLinkPaymentEndpointCollection::class, 'paymentRoutes' => PaymentRouteEndpointCollection::class, 'permissions' => PermissionEndpointCollection::class, 'profiles' => ProfileEndpointCollection::class, - 'profileMethods' => ProfileMethodEndpoint::class, + 'profileMethods' => ProfileMethodEndpointCollection::class, 'refunds' => RefundEndpointCollection::class, + 'sessions' => SessionEndpointCollection::class, 'settlementCaptures' => SettlementCaptureEndpointCollection::class, 'settlementChargebacks' => SettlementChargebackEndpointCollection::class, 'settlementPayments' => SettlementPaymentEndpointCollection::class, diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 4f152b429..5589e524c 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -9,7 +9,7 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index 057dc6757..36f0af811 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -7,7 +7,7 @@ use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 8487940cd..2a13224a5 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index f9d96a817..257fe90f1 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -5,14 +5,14 @@ use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class ChargebackEndpointCollectionTest extends TestCase { /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), @@ -30,7 +30,7 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php index 3bf9ab65d..c8ac9434b 100644 --- a/tests/EndpointCollection/ClientEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -2,18 +2,19 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class ClientEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetClientRequest::class => new MockResponse(200, 'client'), @@ -26,7 +27,7 @@ public function get_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), @@ -44,10 +45,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'clients'), ]); foreach ($client->clients->iterator() as $clientResource) { diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index dcd3617e5..2ccb50e6d 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -2,9 +2,12 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Payload\CreateClientLinkPayload; +use Mollie\Api\Http\Payload\Owner; +use Mollie\Api\Http\Payload\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -18,10 +21,11 @@ public function create() ]); /** @var ClientLink $clientLink */ - $clientLink = $client->clientLinks->create([ - 'ownerId' => 'org_12345678', - 'name' => 'Test Client Link', - ]); + $clientLink = $client->clientLinks->create(new CreateClientLinkPayload( + new Owner('test@example.com', 'John', 'Doe'), + 'Test Client Link', + new OwnerAddress('NL'), + )); $this->assertInstanceOf(ClientLink::class, $clientLink); $this->assertEquals('client-link', $clientLink->resource); diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php index dec099d12..720968933 100644 --- a/tests/EndpointCollection/CustomerEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -7,9 +7,10 @@ use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Http\Requests\DeleteCustomerRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -96,6 +97,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'customers'), ]); foreach ($client->customers->iterator() as $customer) { diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 93c214d20..75e68ea8f 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -2,12 +2,16 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -24,14 +28,11 @@ public function create_for() $customer->id = 'cst_kEn1PlbGa'; /** @var Payment $payment */ - $payment = $client->customerPayments->createFor($customer, [ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '10.00', - ], - 'description' => 'Test payment', - 'redirectUrl' => 'https://example.org/redirect', - ]); + $payment = $client->customerPayments->createFor($customer, new CreatePaymentPayload( + 'Test payment', + new Money('10.00', 'EUR'), + 'https://example.org/redirect', + )); $this->assertPayment($payment); } @@ -62,6 +63,7 @@ public function iterator_for() { $client = new MockClient([ GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); $customer = new Customer($client); diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php index d7a9d8cab..94f6e8bcd 100644 --- a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -2,18 +2,19 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetInvoiceRequest; use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class InvoiceEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetInvoiceRequest::class => new MockResponse(200, 'invoice'), @@ -26,7 +27,7 @@ public function get_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), @@ -43,10 +44,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'invoices'), ]); foreach ($client->invoices->iterator() as $invoice) { diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index b7f6fbcd8..13251c849 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use DateTimeImmutable; +use Mollie\Api\Http\Payload\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; @@ -9,14 +11,14 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class MandateEndpointCollectionTest extends TestCase { /** @test */ - public function create_for_test() + public function create_for() { $client = new MockClient([ CreateMandateRequest::class => new MockResponse(201, 'mandate'), @@ -26,20 +28,21 @@ public function create_for_test() $customer->id = 'cst_4qqhO89gsT'; /** @var Mandate $mandate */ - $mandate = $client->mandates->createFor($customer, [ - 'method' => 'directdebit', - 'consumerName' => 'John Doe', - 'consumerAccount' => 'NL55INGB0000000000', - 'consumerBic' => 'INGBNL2A', - 'signatureDate' => '2023-05-07', - 'mandateReference' => 'EXAMPLE-CORP-MD13804', - ]); + $mandate = $client->mandates->createFor($customer, new CreateMandatePayload( + 'directdebit', + 'John Doe', + 'NL55INGB0000000000', + 'INGBNL2A', + 'john.doe@example.com', + new DateTimeImmutable('2023-05-07'), + 'EXAMPLE-CORP-MD13804', + )); $this->assertMandate($mandate); } /** @test */ - public function get_for_test() + public function get_for() { $client = new MockClient([ GetMandateRequest::class => new MockResponse(200, 'mandate'), @@ -55,7 +58,7 @@ public function get_for_test() } /** @test */ - public function revoke_for_test() + public function revoke_for() { $client = new MockClient([ RevokeMandateRequest::class => new MockResponse(204), @@ -71,7 +74,7 @@ public function revoke_for_test() } /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php index f18af466b..eab70af85 100644 --- a/tests/EndpointCollection/MethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -7,17 +7,17 @@ use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class MethodEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ - GetPaymentMethodRequest::class => new MockResponse(200, 'method'), + GetPaymentMethodRequest::class => new MockResponse(200, 'method', 'ideal'), ]); /** @var Method $method */ @@ -27,7 +27,7 @@ public function get_test() } /** @test */ - public function all_test() + public function all() { $client = new MockClient([ GetAllMethodsRequest::class => new MockResponse(200, 'method-list'), @@ -49,7 +49,7 @@ public function all_test() } /** @test */ - public function all_enabled_test() + public function all_enabled() { $client = new MockClient([ GetEnabledMethodsRequest::class => new MockResponse(200, 'method-list'), diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php index fa2489508..85dccdf54 100644 --- a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -5,7 +5,7 @@ use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php index 8ae875946..8057494a7 100644 --- a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -4,14 +4,14 @@ use Mollie\Api\Http\Requests\GetOnboardingRequest; use Mollie\Api\Resources\Onboarding; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class OnboardingEndpointCollectionTest extends TestCase { /** @test */ - public function status_test() + public function status() { $client = new MockClient([ GetOnboardingRequest::class => new MockResponse(200, 'onboarding'), diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php index c11ca487d..f7cb1a510 100644 --- a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -6,17 +6,17 @@ use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class OrganizationEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ - GetOrganizationRequest::class => new MockResponse(200, 'organization'), + GetOrganizationRequest::class => new MockResponse(200, 'organization', 'org_12345678'), ]); /** @var Organization $organization */ @@ -26,7 +26,7 @@ public function get_test() } /** @test */ - public function current_test() + public function current() { $client = new MockClient([ GetOrganizationRequest::class => new MockResponse(200, 'organization'), @@ -39,10 +39,10 @@ public function current_test() } /** @test */ - public function partner_status_test() + public function partner_status() { $client = new MockClient([ - GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner'), + GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); /** @var Partner $partner */ @@ -65,6 +65,5 @@ protected function assertOrganization(Organization $organization) $this->assertNotEmpty($organization->locale); $this->assertNotEmpty($organization->address); $this->assertNotEmpty($organization->registrationNumber); - $this->assertNotEmpty($organization->vatRegulation); } } diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php index fce305d7e..15e45764a 100644 --- a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -4,7 +4,7 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -14,11 +14,11 @@ class OrganizationPartnerEndpointCollectionTest extends TestCase public function status() { $client = new MockClient([ - GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner'), + GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); /** @var Partner $partner */ - $partner = $client->organizationPartner->status(); + $partner = $client->organizationPartners->status(); $this->assertInstanceOf(Partner::class, $partner); $this->assertEquals('partner', $partner->resource); diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index 8fba8002e..2faa59fda 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -2,68 +2,58 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; +use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; -use Mollie\Api\Resources\Payment; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentCaptureEndpointCollectionTest extends TestCase { /** @test */ - public function create_for_test() + public function create_for_id() { $client = new MockClient([ CreatePaymentCaptureRequest::class => new MockResponse(201, 'capture'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var Capture $capture */ - $capture = $client->paymentCaptures->createFor($payment, [ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '35.95' - ], - 'description' => 'Capture for cart #12345', - ]); + $capture = $client->paymentCaptures->createForId('tr_7UhSN1zuXS', new CreatePaymentCapturePayload( + 'Capture for cart #12345', + new Money('EUR', '35.95') + )); $this->assertCapture($capture); } /** @test */ - public function get_for_test() + public function get_for_id() { $client = new MockClient([ GetPaymentCaptureRequest::class => new MockResponse(200, 'capture'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var Capture $capture */ - $capture = $client->paymentCaptures->getFor($payment, 'cpt_mNepDkEtco6ah3QNPUGYH'); + $capture = $client->paymentCaptures->getForId('tr_7UhSN1zuXS', 'cpt_mNepDkEtco6ah3QNPUGYH'); $this->assertCapture($capture); } /** @test */ - public function page_for_test() + public function page_for_id() { $client = new MockClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var CaptureCollection $captures */ - $captures = $client->paymentCaptures->pageFor($payment); + $captures = $client->paymentCaptures->pageForId('tr_7UhSN1zuXS'); $this->assertInstanceOf(CaptureCollection::class, $captures); $this->assertEquals(1, $captures->count()); @@ -73,16 +63,14 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','captures'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - - foreach ($client->paymentCaptures->iteratorFor($payment) as $capture) { + foreach ($client->paymentCaptures->iteratorForId('tr_7UhSN1zuXS') as $capture) { $this->assertInstanceOf(Capture::class, $capture); $this->assertCapture($capture); } diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index 01a056131..ad261d38b 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -6,41 +6,34 @@ use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use Mollie\Api\Resources\Payment; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentChargebackEndpointCollectionTest extends TestCase { /** @test */ - public function get_for_test() + public function get_for_id() { $client = new MockClient([ GetPaymentChargebackRequest::class => new MockResponse(200, 'chargeback'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var Chargeback $chargeback */ - $chargeback = $client->paymentChargebacks->getFor($payment, 'chb_n9z0tp'); + $chargeback = $client->paymentChargebacks->getForId('tr_7UhSN1zuXS', 'chb_n9z0tp'); $this->assertChargeback($chargeback); } /** @test */ - public function page_for_test() + public function page_for_id() { $client = new MockClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var ChargebackCollection $chargebacks */ - $chargebacks = $client->paymentChargebacks->pageFor($payment); + $chargebacks = $client->paymentChargebacks->pageForId('tr_7UhSN1zuXS'); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); $this->assertGreaterThan(0, $chargebacks->count()); @@ -52,16 +45,13 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - - foreach ($client->paymentChargebacks->iteratorFor($payment) as $chargeback) { + foreach ($client->paymentChargebacks->iteratorForId('tr_7UhSN1zuXS') as $chargeback) { $this->assertInstanceOf(Chargeback::class, $chargeback); $this->assertChargeback($chargeback); } @@ -75,7 +65,7 @@ protected function assertChargeback(Chargeback $chargeback) $this->assertNotEmpty($chargeback->amount); $this->assertNotEmpty($chargeback->settlementAmount); $this->assertNotEmpty($chargeback->createdAt); - $this->assertEquals('tr_7UhSN1zuXS', $chargeback->paymentId); + $this->assertStringStartsWith('tr_', $chargeback->paymentId); $this->assertNotEmpty($chargeback->_links); } } diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index ae5ba9cce..f78c94732 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -2,44 +2,46 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest; use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentEndpointCollectionTest extends TestCase { /** @test */ - public function create_test() + public function create() { $client = new MockClient([ CreatePaymentRequest::class => new MockResponse(201, 'payment'), ]); /** @var Payment $payment */ - $payment = $client->payments->create([ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '10.00', - ], - 'description' => 'Test payment', - 'redirectUrl' => 'https://example.org/redirect', - 'webhookUrl' => 'https://example.org/webhook', - ]); + $payment = $client->payments->create(new CreatePaymentPayload( + 'Test payment', + new Money('10.00', 'EUR'), + 'https://example.org/redirect', + 'https://example.org/webhook', + )); $this->assertPayment($payment); } /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetPaymentRequest::class => new MockResponse(200, 'payment'), @@ -52,23 +54,23 @@ public function get_test() } /** @test */ - public function update_test() + public function update() { $client = new MockClient([ UpdatePaymentRequest::class => new MockResponse(200, 'payment'), ]); /** @var Payment $payment */ - $payment = $client->payments->update('tr_WDqYK6vllg', [ - 'description' => 'Updated description', - 'redirectUrl' => 'https://example.org/updated-redirect', - ]); + $payment = $client->payments->update('tr_WDqYK6vllg', new UpdatePaymentPayload( + 'Updated description', + 'https://example.org/updated-redirect', + )); $this->assertPayment($payment); } /** @test */ - public function cancel_test() + public function cancel() { $client = new MockClient([ CancelPaymentRequest::class => new MockResponse(204), @@ -76,12 +78,11 @@ public function cancel_test() $payment = $client->payments->cancel('tr_WDqYK6vllg'); - // Test passes if no exception is thrown - $this->assertTrue(true); + $this->assertTrue($payment->getResponse()->successful()); } /** @test */ - public function refund_test() + public function refund() { $client = new MockClient([ CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), @@ -91,13 +92,10 @@ public function refund_test() $payment->id = 'tr_WDqYK6vllg'; /** @var Refund $refund */ - $refund = $client->payments->refund($payment, [ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '5.95', - ], - 'description' => 'Test refund', - ]); + $refund = $client->payments->refund($payment, new CreateRefundPaymentPayload( + 'Test refund', + new Money('5.95', 'EUR'), + )); $this->assertInstanceOf(Refund::class, $refund); $this->assertEquals('refund', $refund->resource); @@ -107,7 +105,7 @@ public function refund_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), @@ -126,10 +124,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); foreach ($client->payments->iterator() as $payment) { @@ -151,6 +150,5 @@ protected function assertPayment(Payment $payment) $this->assertNotEmpty($payment->method); $this->assertNotEmpty($payment->metadata); $this->assertNotEmpty($payment->profileId); - $this->assertNotEmpty($payment->settlementAmount); } } diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index 1bcc4c435..6b64c32ed 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -2,42 +2,47 @@ namespace Tests\EndpointCollection; +use DateTimeImmutable; +use Mollie\Api\Http\Payload\CreatePaymentLinkPayload; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaymentLinkRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentLinkEndpointCollectionTest extends TestCase { /** @test */ - public function create_test() + public function create() { $client = new MockClient([ CreatePaymentLinkRequest::class => new MockResponse(201, 'payment-link'), ]); /** @var PaymentLink $paymentLink */ - $paymentLink = $client->paymentLinks->create([ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '10.00', - ], - 'description' => 'Test payment link', - 'expiresAt' => '2023-12-31', - 'webhookUrl' => 'https://example.org/webhook', - ]); + $paymentLink = $client->paymentLinks->create(new CreatePaymentLinkPayload( + 'Test payment link', + new Money('10.00', 'EUR'), + 'https://example.org/redirect', + 'https://example.org/webhook', + null, + null, + new DateTimeImmutable('2023-12-31'), + )); $this->assertPaymentLink($paymentLink); } /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetPaymentLinkRequest::class => new MockResponse(200, 'payment-link'), @@ -50,23 +55,22 @@ public function get_test() } /** @test */ - public function update_test() + public function update() { $client = new MockClient([ UpdatePaymentLinkRequest::class => new MockResponse(200, 'payment-link'), ]); /** @var PaymentLink $paymentLink */ - $paymentLink = $client->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', [ - 'description' => 'Updated description', - 'expiresAt' => '2024-01-01', - ]); + $paymentLink = $client->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', new UpdatePaymentLinkPayload( + 'Updated description', + )); $this->assertPaymentLink($paymentLink); } /** @test */ - public function delete_test() + public function delete() { $client = new MockClient([ DeletePaymentLinkRequest::class => new MockResponse(204), @@ -79,7 +83,7 @@ public function delete_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), @@ -98,10 +102,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payment_links'), ]); foreach ($client->paymentLinks->iterator() as $paymentLink) { diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php index 222f38f32..62889bb36 100644 --- a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -2,11 +2,11 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; -use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -19,11 +19,8 @@ public function page_for() GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); - $paymentLink = new PaymentLink($client); - $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; - /** @var PaymentCollection $payments */ - $payments = $client->paymentLinkPayments->pageFor($paymentLink); + $payments = $client->paymentLinkPayments->pageForId('pl_4Y0eZitmBnQ6IDoMqZQKh'); $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertGreaterThan(0, $payments->count()); @@ -38,12 +35,10 @@ public function iterator_for() { $client = new MockClient([ GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); - $paymentLink = new PaymentLink($client); - $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; - - foreach ($client->paymentLinkPayments->iteratorFor($paymentLink) as $payment) { + foreach ($client->paymentLinkPayments->iteratorForId('pl_4Y0eZitmBnQ6IDoMqZQKh') as $payment) { $this->assertPayment($payment); } } diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index 22c2b6c12..70e4a7fea 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -6,17 +6,18 @@ use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentRefundEndpointCollectionTest extends TestCase { /** @test */ - public function create_for_test() + public function create_for() { $client = new MockClient([ CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), @@ -38,7 +39,7 @@ public function create_for_test() } /** @test */ - public function get_for_test() + public function get_for() { $client = new MockClient([ GetPaymentRefundRequest::class => new MockResponse(200, 'refund'), @@ -54,7 +55,7 @@ public function get_for_test() } /** @test */ - public function cancel_for_test() + public function cancel_for() { $client = new MockClient([ CancelPaymentRefundRequest::class => new MockResponse(204), @@ -70,7 +71,7 @@ public function cancel_for_test() } /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), @@ -92,10 +93,11 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); $payment = new Payment($client); diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php index a3177a832..e8d9f8355 100644 --- a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -3,26 +3,22 @@ namespace Tests\EndpointCollection; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; -use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Route; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PaymentRouteEndpointCollectionTest extends TestCase { /** @test */ - public function update_release_date_for_test() + public function update_release_date_for() { $client = new MockClient([ UpdatePaymentRouteRequest::class => new MockResponse(200, 'route'), ]); - $payment = new Payment($client); - $payment->id = 'tr_7UhSN1zuXS'; - /** @var Route $route */ - $route = $client->paymentRoutes->updateReleaseDateFor($payment, 'rt_abc123', '2024-01-01'); + $route = $client->paymentRoutes->updateReleaseDateForId('tr_7UhSN1zuXS', 'rt_abc123', '2024-01-01'); $this->assertInstanceOf(Route::class, $route); $this->assertEquals('route', $route->resource); @@ -30,6 +26,5 @@ public function update_release_date_for_test() $this->assertNotEmpty($route->amount); $this->assertNotEmpty($route->destination); $this->assertNotEmpty($route->releaseDate); - $this->assertNotEmpty($route->_links); } } diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php index c7df7de8a..ae2f1d675 100644 --- a/tests/EndpointCollection/PermissionEndpointCollectionTest.php +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -6,14 +6,14 @@ use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class PermissionEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetPermissionRequest::class => new MockResponse(200, 'permission'), @@ -26,7 +26,7 @@ public function get_test() } /** @test */ - public function list_test() + public function list() { $client = new MockClient([ ListPermissionsRequest::class => new MockResponse(200, 'permission-list'), @@ -50,7 +50,7 @@ protected function assertPermission(Permission $permission) $this->assertEquals('permission', $permission->resource); $this->assertNotEmpty($permission->id); $this->assertNotEmpty($permission->description); - $this->assertNotEmpty($permission->granted); + $this->assertIsBool($permission->granted); $this->assertNotEmpty($permission->_links); } } diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index 8ca67eb6e..ecadaa460 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -2,40 +2,43 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Payload\CreateProfilePayload; +use Mollie\Api\Http\Payload\UpdateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Http\Requests\DeleteProfileRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class ProfileEndpointCollectionTest extends TestCase { /** @test */ - public function create_test() + public function create() { $client = new MockClient([ CreateProfileRequest::class => new MockResponse(201, 'profile'), ]); /** @var Profile $profile */ - $profile = $client->profiles->create([ - 'name' => 'My Test Profile', - 'website' => 'https://example.org', - 'email' => 'info@example.org', - 'phone' => '+31612345678', - 'categoryCode' => 5399, - ]); + $profile = $client->profiles->create(new CreateProfilePayload( + 'My Test Profile', + 'https://example.org', + 'info@example.org', + '+31612345678', + 'test', + )); $this->assertProfile($profile); } /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetProfileRequest::class => new MockResponse(200, 'profile'), @@ -48,7 +51,7 @@ public function get_test() } /** @test */ - public function get_current_test() + public function get_current() { $client = new MockClient([ GetProfileRequest::class => new MockResponse(200, 'current-profile'), @@ -61,23 +64,23 @@ public function get_current_test() } /** @test */ - public function update_test() + public function update() { $client = new MockClient([ UpdateProfileRequest::class => new MockResponse(200, 'profile'), ]); /** @var Profile $profile */ - $profile = $client->profiles->update('pfl_v9hTwCvYqw', [ - 'name' => 'Updated Profile Name', - 'website' => 'https://updated-example.org', - ]); + $profile = $client->profiles->update('pfl_v9hTwCvYqw', new UpdateProfilePayload( + 'Updated Profile Name', + 'https://updated-example.org', + )); $this->assertProfile($profile); } /** @test */ - public function delete_test() + public function delete() { $client = new MockClient([ DeleteProfileRequest::class => new MockResponse(204), @@ -90,7 +93,7 @@ public function delete_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), @@ -109,10 +112,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'profiles'), ]); foreach ($client->profiles->iterator() as $profile) { diff --git a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php new file mode 100644 index 000000000..cbf87e2be --- /dev/null +++ b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php @@ -0,0 +1,75 @@ + new MockResponse(200, 'method', 'ideal'), + ]); + + /** @var Method $method */ + $method = $client->profileMethods->enableForId('pfl_v9hTwCvYqw', 'ideal'); + + $this->assertMethod($method); + } + + /** @test */ + public function enable() + { + $client = new MockClient([ + EnableProfileMethodRequest::class => new MockResponse(200, 'method', 'ideal'), + ]); + + /** @var Method $method */ + $method = $client->profileMethods->enable('ideal'); + + $this->assertMethod($method); + } + + /** @test */ + public function disable_for_id() + { + $client = new MockClient([ + DisableProfileMethodRequest::class => new MockResponse(204), + ]); + + $client->profileMethods->disableForId('pfl_v9hTwCvYqw', 'ideal'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function disable() + { + $client = new MockClient([ + DisableProfileMethodRequest::class => new MockResponse(204), + ]); + + $client->profileMethods->disable('ideal'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + protected function assertMethod(Method $method) + { + $this->assertInstanceOf(Method::class, $method); + $this->assertEquals('method', $method->resource); + $this->assertNotEmpty($method->id); + $this->assertNotEmpty($method->description); + $this->assertNotEmpty($method->status); + $this->assertNotEmpty($method->_links); + } +} diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php index 6d7f355dd..2a50a47c4 100644 --- a/tests/EndpointCollection/RefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -2,17 +2,18 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class RefundEndpointCollectionTest extends TestCase { /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), @@ -30,10 +31,11 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); foreach ($client->refunds->iterator() as $refund) { diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php new file mode 100644 index 000000000..ebf69071e --- /dev/null +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -0,0 +1,121 @@ + new MockResponse(200, 'session'), + ]); + + /** @var Session $session */ + $session = $client->sessions->get('ses_123', new AnyQuery(['include' => 'details'])); + + $this->assertSession($session); + } + + /** @test */ + public function create() + { + $client = new MockClient([ + CreateSessionRequest::class => new MockResponse(201, 'session'), + ]); + + /** @var Session $session */ + $session = $client->sessions->create(new AnyPayload([ + 'amount' => new Money('EUR', '10.00'), + 'description' => 'Test Session' + ])); + + $this->assertSession($session); + } + + /** @test */ + public function update() + { + $client = new MockClient([ + UpdateSessionRequest::class => new MockResponse(200, 'session'), + ]); + + /** @var Session $session */ + $session = $client->sessions->update('ses_123', new AnyPayload([ + 'description' => 'Updated Session' + ])); + + $this->assertSession($session); + } + + /** @test */ + public function cancel() + { + $client = new MockClient([ + CancelSessionRequest::class => new MockResponse(204), + ]); + + $client->sessions->cancel('ses_123'); + + // Test passes if no exception is thrown + $this->assertTrue(true); + } + + /** @test */ + public function page() + { + $client = new MockClient([ + GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), + ]); + + /** @var SessionCollection $sessions */ + $sessions = $client->sessions->page(); + + $this->assertInstanceOf(SessionCollection::class, $sessions); + $this->assertGreaterThan(0, $sessions->count()); + + foreach ($sessions as $session) { + $this->assertSession($session); + } + } + + /** @test */ + public function iterator() + { + $client = new MockClient([ + GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'sessions'), + ]); + + foreach ($client->sessions->iterator() as $session) { + $this->assertSession($session); + } + } + protected function assertSession(Session $session) + { + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + $this->assertNotEmpty($session->id); + $this->assertNotEmpty($session->mode); + $this->assertNotEmpty($session->createdAt); + $this->assertNotEmpty($session->status); + $this->assertNotEmpty($session->amount); + $this->assertNotEmpty($session->description); + $this->assertNotEmpty($session->_links); + } +} diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index 23007de63..4cd76fa3b 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -3,17 +3,18 @@ namespace Tests\EndpointCollection; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class SettlementCaptureEndpointCollectionTest extends TestCase { /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), @@ -34,10 +35,11 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'captures'), ]); $settlement = new Settlement($client); @@ -55,9 +57,7 @@ protected function assertCapture(Capture $capture) $this->assertNotEmpty($capture->id); $this->assertNotEmpty($capture->mode); $this->assertNotEmpty($capture->amount); - $this->assertNotEmpty($capture->settlementId); $this->assertNotEmpty($capture->paymentId); - $this->assertNotEmpty($capture->shipmentId); $this->assertNotEmpty($capture->createdAt); $this->assertNotEmpty($capture->_links); } diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index b867ba683..8ce917e90 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -6,14 +6,14 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class SettlementChargebackEndpointCollectionTest extends TestCase { /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), @@ -34,7 +34,7 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php index 9dadd8dcd..efc068b46 100644 --- a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -2,18 +2,19 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class SettlementPaymentEndpointCollectionTest extends TestCase { /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), @@ -34,10 +35,11 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); $settlement = new Settlement($client); diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index ebf10c89a..3c35b10e7 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -6,14 +6,15 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Mollie\Api\Http\Requests\DynamicGetRequest; class SettlementRefundEndpointCollectionTest extends TestCase { /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), @@ -34,10 +35,11 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); $settlement = new Settlement($client); diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php index 4144ee352..2ea3e8055 100644 --- a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -2,122 +2,96 @@ namespace Tests\EndpointCollection; -use Mollie\Api\EndpointCollection\SettlementsEndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; use Mollie\Api\Http\Requests\GetSettlementRequest; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; +use Tests\Fixtures\MockClient; +use Tests\Fixtures\MockResponse; class SettlementsEndpointCollectionTest extends TestCase { - private SettlementsEndpointCollection $collection; - - protected function setUp(): void - { - parent::setUp(); - $this->collection = $this->getMockBuilder(SettlementsEndpointCollection::class) - ->disableOriginalConstructor() - ->onlyMethods(['send']) - ->getMock(); - } - - public function testGet(): void + /** @test */ + public function get() { - $settlement = $this->createMock(Settlement::class); + $client = new MockClient([ + GetSettlementRequest::class => new MockResponse(200, 'settlement'), + ]); - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->isInstanceOf(GetSettlementRequest::class)) - ->willReturn($settlement); + /** @var Settlement $settlement */ + $settlement = $client->settlements->get('stl_123'); - $result = $this->collection->get('stl_123'); - - $this->assertSame($settlement, $result); + $this->assertSettlement($settlement); } - public function testNext(): void + /** @test */ + public function next() { - $settlement = $this->createMock(Settlement::class); - - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->callback(function (GetSettlementRequest $request) { - return $request->getId() === 'next'; - })) - ->willReturn($settlement); + $client = new MockClient([ + GetSettlementRequest::class => new MockResponse(200, 'settlement'), + ]); - $result = $this->collection->next(); + /** @var Settlement $settlement */ + $settlement = $client->settlements->next(); - $this->assertSame($settlement, $result); + $this->assertSettlement($settlement); } - public function testOpen(): void + /** @test */ + public function open() { - $settlement = $this->createMock(Settlement::class); - - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->callback(function (GetSettlementRequest $request) { - return $request->getId() === 'open'; - })) - ->willReturn($settlement); + $client = new MockClient([ + GetSettlementRequest::class => new MockResponse(200, 'settlement'), + ]); - $result = $this->collection->open(); + /** @var Settlement $settlement */ + $settlement = $client->settlements->open(); - $this->assertSame($settlement, $result); + $this->assertSettlement($settlement); } - public function testPage(): void + /** @test */ + public function page() { - $collection = $this->createMock(SettlementCollection::class); + $client = new MockClient([ + GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), + ]); - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->isInstanceOf(GetPaginatedSettlementsRequest::class)) - ->willReturn($collection); + /** @var SettlementCollection $settlements */ + $settlements = $client->settlements->page('stl_123', 50, ['reference' => 'test']); - $result = $this->collection->page('stl_123', 50, ['reference' => 'test']); + $this->assertInstanceOf(SettlementCollection::class, $settlements); + $this->assertGreaterThan(0, $settlements->count()); - $this->assertSame($collection, $result); + foreach ($settlements as $settlement) { + $this->assertSettlement($settlement); + } } - public function testIterator(): void + /** @test */ + public function iterator() { - $lazyCollection = $this->createMock(LazyCollection::class); - - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->callback(function (GetPaginatedSettlementsRequest $request) { - return $request->isIterator() && !$request->isIteratingBackwards(); - })) - ->willReturn($lazyCollection); - - $result = $this->collection->iterator('stl_123', 50, ['reference' => 'test']); - - $this->assertSame($lazyCollection, $result); + $client = new MockClient([ + GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'settlements'), + ]); + + foreach ($client->settlements->iterator('stl_123', 50, ['reference' => 'test']) as $settlement) { + $this->assertSettlement($settlement); + } } - public function testIteratorWithBackwardsIteration(): void + protected function assertSettlement(Settlement $settlement) { - $lazyCollection = $this->createMock(LazyCollection::class); - - $this->collection - ->expects($this->once()) - ->method('send') - ->with($this->callback(function (GetPaginatedSettlementsRequest $request) { - return $request->isIterator() && $request->isIteratingBackwards(); - })) - ->willReturn($lazyCollection); - - $result = $this->collection->iterator('stl_123', 50, ['reference' => 'test'], true); - - $this->assertSame($lazyCollection, $result); + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals('settlement', $settlement->resource); + $this->assertNotEmpty($settlement->id); + $this->assertNotEmpty($settlement->reference); + $this->assertNotEmpty($settlement->settledAt); + $this->assertNotEmpty($settlement->status); + $this->assertNotEmpty($settlement->amount); + $this->assertNotEmpty($settlement->_links); } } diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 868eca0bf..91c8039e3 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -10,14 +10,16 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; class SubscriptionEndpointCollectionTest extends TestCase { /** @test */ - public function create_for_test() + public function create_for() { $client = new MockClient([ CreateSubscriptionRequest::class => new MockResponse(201, 'subscription'), @@ -41,7 +43,7 @@ public function create_for_test() } /** @test */ - public function get_for_test() + public function get_for() { $client = new MockClient([ GetSubscriptionRequest::class => new MockResponse(200, 'subscription'), @@ -57,7 +59,7 @@ public function get_for_test() } /** @test */ - public function update_for_test() + public function update_for() { $client = new MockClient([ UpdateSubscriptionRequest::class => new MockResponse(200, 'subscription'), @@ -79,7 +81,7 @@ public function update_for_test() } /** @test */ - public function cancel_for_test() + public function cancel_for() { $client = new MockClient([ CancelSubscriptionRequest::class => new MockResponse(204), @@ -95,7 +97,7 @@ public function cancel_for_test() } /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), @@ -117,17 +119,57 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), ]); $customer = new Customer($client); $customer->id = 'cst_kEn1PlbGa'; foreach ($client->subscriptions->iteratorFor($customer) as $subscription) { - $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertSubscription($subscription); + } + } + + /** @test */ + public function all_for_id() + { + $client = new MockClient([ + GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + ]); + + /** @var SubscriptionCollection $subscriptions */ + $subscriptions = $client->subscriptions->allForId( + 'sub_123', + 50, + ['profile_id' => 'prf_123'] + ); + + $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); + $this->assertGreaterThan(0, $subscriptions->count()); + + foreach ($subscriptions as $subscription) { + $this->assertSubscription($subscription); + } + } + + /** @test */ + public function iterator_for_all() + { + $client = new MockClient([ + GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), + ]); + + foreach ($client->subscriptions->iteratorForAll( + 'sub_123', + 50, + ['profile_id' => 'prf_123'], + true + ) as $subscription) { $this->assertSubscription($subscription); } } @@ -144,7 +186,6 @@ protected function assertSubscription(Subscription $subscription) $this->assertNotEmpty($subscription->times); $this->assertNotEmpty($subscription->interval); $this->assertNotEmpty($subscription->description); - $this->assertNotEmpty($subscription->method); $this->assertNotEmpty($subscription->webhookUrl); $this->assertNotEmpty($subscription->_links); } diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php index ffb930f67..1d2c8dc47 100644 --- a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -2,18 +2,19 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class SubscriptionPaymentEndpointCollectionTest extends TestCase { /** @test */ - public function page_for_test() + public function page_for() { $client = new MockClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), @@ -35,10 +36,11 @@ public function page_for_test() } /** @test */ - public function iterator_for_test() + public function iterator_for() { $client = new MockClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); $subscription = new Subscription($client); @@ -60,7 +62,6 @@ protected function assertPayment(Payment $payment) $this->assertNotEmpty($payment->createdAt); $this->assertNotEmpty($payment->status); $this->assertNotEmpty($payment->profileId); - $this->assertNotEmpty($payment->subscriptionId); $this->assertNotEmpty($payment->_links); } } diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index 7b98028f5..291324c8c 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -4,16 +4,17 @@ use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class TerminalEndpointCollectionTest extends TestCase { /** @test */ - public function get_test() + public function get() { $client = new MockClient([ GetTerminalRequest::class => new MockResponse(200, 'terminal'), @@ -26,10 +27,11 @@ public function get_test() } /** @test */ - public function page_test() + public function page() { $client = new MockClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'terminals'), ]); /** @var TerminalCollection $terminals */ @@ -44,7 +46,7 @@ public function page_test() } /** @test */ - public function iterator_test() + public function iterator() { $client = new MockClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), @@ -67,7 +69,6 @@ protected function assertTerminal(Terminal $terminal) $this->assertNotEmpty($terminal->serialNumber); $this->assertNotEmpty($terminal->currency); $this->assertNotEmpty($terminal->createdAt); - $this->assertNotEmpty($terminal->updatedAt); $this->assertNotEmpty($terminal->_links); } } diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index 08f94fe11..8db783c09 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -3,7 +3,8 @@ namespace Tests\EndpointCollection; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; -use PHPUnit\Framework\TestCase; +use Mollie\Api\Resources\AnyResource; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -16,7 +17,7 @@ public function request_apple_pay_payment_session() ApplePayPaymentSessionRequest::class => new MockResponse(200, 'apple-pay-session'), ]); - $session = $client->wallets->requestApplePayPaymentSession( + $applePaySession = $client->wallets->requestApplePayPaymentSession( 'pay.example.org', 'https://apple-pay-gateway.example.com/paymentservices/paymentSession', [ @@ -24,7 +25,12 @@ public function request_apple_pay_payment_session() ] ); - $this->assertIsString($session); - $this->assertNotEmpty($session); + $this->assertInstanceOf(AnyResource::class, $applePaySession); + $this->assertNotEmpty($applePaySession->domainName); + $this->assertNotEmpty($applePaySession->displayName); + $this->assertNotEmpty($applePaySession->merchantIdentifier); + $this->assertNotEmpty($applePaySession->merchantSessionIdentifier); + $this->assertNotEmpty($applePaySession->nonce); + $this->assertNotEmpty($applePaySession->signature); } } diff --git a/tests/Fixtures/MockClient.php b/tests/Fixtures/MockClient.php index 9d6e00ce5..79983cb0f 100644 --- a/tests/Fixtures/MockClient.php +++ b/tests/Fixtures/MockClient.php @@ -13,6 +13,6 @@ public function __construct(array $expectedResponses = []) $this->httpClient = new MockMollieHttpAdapter($expectedResponses); - $this->setApiKey('test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + $this->setAccessToken('access_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); } } diff --git a/tests/Fixtures/Requests/DynamicDeleteRequest.php b/tests/Fixtures/Requests/DynamicDeleteRequest.php new file mode 100644 index 000000000..18395e4d5 --- /dev/null +++ b/tests/Fixtures/Requests/DynamicDeleteRequest.php @@ -0,0 +1,36 @@ +payload = $payload; + } + + protected function defaultPayload(): array + { + return $this->payload; + } +} diff --git a/tests/Fixtures/Requests/DynamicGetRequest.php b/tests/Fixtures/Requests/DynamicGetRequest.php new file mode 100644 index 000000000..710eee701 --- /dev/null +++ b/tests/Fixtures/Requests/DynamicGetRequest.php @@ -0,0 +1,10 @@ +mockApiCall( - new Request( - 'GET', - '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories' - ), - new Response( - 200, - [], - $this->getBalanceReportStub() - ) - ); - - $balance = new Balance($this->apiClient); - $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; - - $report = $this->apiClient->balanceReports->getFor($balance, [ - 'from' => '2021-01-01', - 'until' => '2021-02-01', - 'grouping' => 'transaction-categories', - ]); - - $this->assertBalanceReport($report); - } - - public function test_can_get_primary_balance_report_through_balance_report_endpoint() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/balances/primary/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories' - ), - new Response( - 200, - [], - $this->getBalanceReportStub() - ) - ); - - $report = $this->apiClient->balanceReports->getForPrimary([ - 'from' => '2021-01-01', - 'until' => '2021-02-01', - 'grouping' => 'transaction-categories', - ]); - - $this->assertBalanceReport($report); - } - - private function getBalanceReportStub() - { - return - '{ - "resource": "balance-report", - "balanceId": "bal_gVMhHKqSSRYJyPsuoPNFH", - "timeZone": "Europe/Amsterdam", - "from": "2021-01-01", - "until": "2021-01-31", - "grouping": "transaction-categories", - "totals": { - "open": { - "available": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - }, - "pending": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - } - }, - "payments": { - "immediatelyAvailable": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - }, - "pending": { - "amount": { - "currency": "EUR", - "value": "4.98" - }, - "subtotals": [ - { - "transactionType": "payment", - "count": 1, - "amount": { - "currency": "EUR", - "value": "4.98" - }, - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "4.98" - }, - "count": 1, - "method": "ideal" - } - ] - } - ] - }, - "movedToAvailable": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - } - }, - "refunds": {}, - "chargebacks": {}, - "capital": {}, - "transfers": {}, - "fee-prepayments": { - "immediatelyAvailable": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - }, - "movedToAvailable": { - "amount": { - "currency": "EUR", - "value": "-0.36" - }, - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "prepaymentPartType": "fee", - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "feeType": "payment-fee", - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "method": "ideal" - } - ] - } - ] - }, - { - "amount": { - "currency": "EUR", - "value": "-0.0609" - }, - "prepaymentPartType": "fee-vat" - }, - { - "amount": { - "currency": "EUR", - "value": "-0.0091" - }, - "prepaymentPartType": "fee-rounding-compensation" - } - ] - }, - "pending": { - "amount": { - "currency": "EUR", - "value": "-0.36" - }, - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "prepaymentPartType": "fee", - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "feeType": "payment-fee", - "subtotals": [ - { - "amount": { - "currency": "EUR", - "value": "-0.29" - }, - "count": 1, - "method": "ideal" - } - ] - } - ] - }, - { - "amount": { - "currency": "EUR", - "value": "-0.0609" - }, - "prepaymentPartType": "fee-vat" - }, - { - "amount": { - "currency": "EUR", - "value": "-0.0091" - }, - "prepaymentPartType": "fee-rounding-compensation" - } - ] - } - }, - "corrections": {}, - "close": { - "available": { - "amount": { - "currency": "EUR", - "value": "0.00" - } - }, - "pending": { - "amount": { - "currency": "EUR", - "value": "4.32" - } - } - } - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/get-balance-report", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories", - "type": "application/hal+json" - } - } - }'; - } - - private function assertBalanceReport($report) - { - $this->assertInstanceOf(BalanceReport::class, $report); - $this->assertEquals('balance-report', $report->resource); - $this->assertEquals('bal_gVMhHKqSSRYJyPsuoPNFH', $report->balanceId); - $this->assertEquals('Europe/Amsterdam', $report->timeZone); - $this->assertEquals($report->from, '2021-01-01'); - $this->assertEquals($report->until, '2021-01-31'); - $this->assertEquals($report->grouping, 'transaction-categories'); - $this->assertAmountObject('0.00', 'EUR', $report->totals->open->available->amount); - $this->assertAmountObject('0.00', 'EUR', $report->totals->open->pending->amount); - $this->assertAmountObject( - '0.00', - 'EUR', - $report->totals->payments->immediatelyAvailable->amount - ); - $this->assertAmountObject( - '4.98', - 'EUR', - $report->totals->payments->pending->amount - ); - $this->assertAmountObject( - '4.98', - 'EUR', - $report->totals->payments->pending->subtotals[0]->amount - ); - $this->assertEquals( - 'payment', - $report->totals->payments->pending->subtotals[0]->transactionType - ); - $this->assertEquals( - 1, - $report->totals->payments->pending->subtotals[0]->count - ); - $this->assertAmountObject( - '4.98', - 'EUR', - $report->totals->payments->pending->subtotals[0]->subtotals[0]->amount - ); - $this->assertEquals( - 1, - $report->totals->payments->pending->subtotals[0]->subtotals[0]->count - ); - $this->assertEquals( - 'ideal', - $report->totals->payments->pending->subtotals[0]->subtotals[0]->method - ); - $this->assertAmountObject( - '0.00', - 'EUR', - $report->totals->payments->movedToAvailable->amount - ); - $this->assertEquals(new \stdClass, $report->totals->refunds); - $this->assertEquals(new \stdClass, $report->totals->chargebacks); - $this->assertEquals(new \stdClass, $report->totals->capital); - $this->assertEquals(new \stdClass, $report->totals->transfers); - - $this->assertAmountObject( - '0.00', - 'EUR', - $report->totals->{'fee-prepayments'}->immediatelyAvailable->amount - ); - - $movedToAvailable = $report->totals->{'fee-prepayments'}->movedToAvailable; - - $this->assertAmountObject( - '-0.36', - 'EUR', - $movedToAvailable->amount - ); - - $this->assertAmountObject( - '-0.29', - 'EUR', - $movedToAvailable->subtotals[0]->amount - ); - - $this->assertEquals(1, $movedToAvailable->subtotals[0]->count); - $this->assertEquals('fee', $movedToAvailable->subtotals[0]->prepaymentPartType); - - $this->assertAmountObject( - '-0.29', - 'EUR', - $movedToAvailable->subtotals[0]->subtotals[0]->amount - ); - $this->assertEquals(1, $movedToAvailable->subtotals[0]->subtotals[0]->count); - $this->assertEquals('payment-fee', $movedToAvailable->subtotals[0]->subtotals[0]->feeType); - - $this->assertAmountObject( - '-0.29', - 'EUR', - $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->amount - ); - $this->assertEquals(1, $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->count); - $this->assertEquals('ideal', $movedToAvailable->subtotals[0]->subtotals[0]->subtotals[0]->method); - - $this->assertAmountObject( - '-0.0609', - 'EUR', - $movedToAvailable->subtotals[1]->amount - ); - $this->assertEquals('fee-vat', $movedToAvailable->subtotals[1]->prepaymentPartType); - - $this->assertAmountObject( - '-0.0091', - 'EUR', - $movedToAvailable->subtotals[2]->amount - ); - $this->assertEquals('fee-rounding-compensation', $movedToAvailable->subtotals[2]->prepaymentPartType); - - // etc. - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/balances-api/get-balance-report', - 'text/html', - $report->_links->documentation - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report?from=2021-01-01&until=2021-02-01&grouping=transaction-categories', - 'application/hal+json', - $report->_links->self - ); - } -} diff --git a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php deleted file mode 100644 index bf2473fb4..000000000 --- a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php +++ /dev/null @@ -1,380 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balance_transactions": [ - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", - "type": "refund", - "resultAmount": { - "value": "-10.25", - "currency": "EUR" - }, - "initialAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.25", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS", - "refundId": "re_4qqhO89gsT" - } - }, - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", - "type": "payment", - "resultAmount": { - "value": "9.71", - "currency": "EUR" - }, - "initialAmount": { - "value": "10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.29", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS" - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $balance = new Balance($this->apiClient); - $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; - - $transactions = $this->apiClient->balanceTransactions->listFor($balance); - - $this->assertTransactions($transactions); - } - - public function test_iterator_for_balance_transactions_through_endpoint() - { - $this->mockApiCall( - new Request('GET', '/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions'), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balance_transactions": [ - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", - "type": "refund", - "resultAmount": { - "value": "-10.25", - "currency": "EUR" - }, - "initialAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.25", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS", - "refundId": "re_4qqhO89gsT" - } - }, - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", - "type": "payment", - "resultAmount": { - "value": "9.71", - "currency": "EUR" - }, - "initialAmount": { - "value": "10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.29", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS" - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $balance = new Balance($this->apiClient); - $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; - - foreach ($this->apiClient->balanceTransactions->iteratorFor($balance) as $balanceTransactions) { - $this->assertInstanceOf(BalanceTransaction::class, $balanceTransactions); - } - } - - public function test_get_primary_balance_transactions_through_balance_transaction_endpoint() - { - $this->mockApiCall( - new Request('GET', '/v2/balances/primary/transactions'), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balance_transactions": [ - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", - "type": "refund", - "resultAmount": { - "value": "-10.25", - "currency": "EUR" - }, - "initialAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.25", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS", - "refundId": "re_4qqhO89gsT" - } - }, - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", - "type": "payment", - "resultAmount": { - "value": "9.71", - "currency": "EUR" - }, - "initialAmount": { - "value": "10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.29", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS" - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $transactions = $this->apiClient->balanceTransactions->listForPrimary(); - - $this->assertTransactions($transactions); - } - - public function test_iterator_for_primary_balance_transactions_through_balance_transaction_endpoint() - { - $this->mockApiCall( - new Request('GET', '/v2/balances/primary/transactions'), - new Response( - 200, - [], - '{ - "count": 2, - "_embedded": { - "balance_transactions": [ - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", - "type": "refund", - "resultAmount": { - "value": "-10.25", - "currency": "EUR" - }, - "initialAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.25", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS", - "refundId": "re_4qqhO89gsT" - } - }, - { - "resource": "balance_transaction", - "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", - "type": "payment", - "resultAmount": { - "value": "9.71", - "currency": "EUR" - }, - "initialAmount": { - "value": "10.00", - "currency": "EUR" - }, - "deductions": { - "value": "-0.29", - "currency": "EUR" - }, - "createdAt": "2021-01-10T12:06:28+00:00", - "context": { - "paymentId": "tr_7UhSN1zuXS" - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - foreach ($this->apiClient->balanceTransactions->iteratorForPrimary() as $balanceTransactions) { - $this->assertInstanceOf(BalanceTransaction::class, $balanceTransactions); - } - } - - private function assertTransactions(BaseCollection $transactions) - { - $this->assertInstanceOf(BalanceTransactionCollection::class, $transactions); - $this->assertCount(2, $transactions); - $this->assertEquals(2, $transactions->count()); - $this->assertLinkObject( - 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5', - 'application/hal+json', - $transactions->_links->self - ); - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions', - 'text/html', - $transactions->_links->documentation - ); - $this->assertNull($transactions->_links->next); - $this->assertNull($transactions->_links->previous); - - /** @var \Mollie\Api\Resources\BalanceTransaction $transactionA */ - $transactionA = $transactions[0]; - - /** @var \Mollie\Api\Resources\BalanceTransaction $transactionB */ - $transactionB = $transactions[1]; - - // Transaction A - $this->assertEquals('balance_transaction', $transactionA->resource); - $this->assertEquals('baltr_QM24QwzUWR4ev4Xfgyt29A', $transactionA->id); - $this->assertEquals('refund', $transactionA->type); - $this->assertAmountObject('-10.25', 'EUR', $transactionA->resultAmount); - $this->assertAmountObject('-10.00', 'EUR', $transactionA->initialAmount); - $this->assertAmountObject('-0.25', 'EUR', $transactionA->deductions); - $this->assertEquals('2021-01-10T12:06:28+00:00', $transactionA->createdAt); - $this->assertEquals('tr_7UhSN1zuXS', $transactionA->context->paymentId); - $this->assertEquals('re_4qqhO89gsT', $transactionA->context->refundId); - - // Transaction B - $this->assertEquals('balance_transaction', $transactionB->resource); - $this->assertEquals('baltr_QM24QwzUWR4ev4Xfgyt29B', $transactionB->id); - $this->assertEquals('payment', $transactionB->type); - $this->assertAmountObject('9.71', 'EUR', $transactionB->resultAmount); - $this->assertAmountObject('10.00', 'EUR', $transactionB->initialAmount); - $this->assertAmountObject('-0.29', 'EUR', $transactionB->deductions); - $this->assertEquals('2021-01-10T12:06:28+00:00', $transactionB->createdAt); - $this->assertEquals('tr_7UhSN1zuXS', $transactionB->context->paymentId); - } -} diff --git a/tests/Mollie/API/Endpoints/BaseEndpointTest.php b/tests/Mollie/API/Endpoints/BaseEndpointTest.php deleted file mode 100644 index 23b1e9d0e..000000000 --- a/tests/Mollie/API/Endpoints/BaseEndpointTest.php +++ /dev/null @@ -1,77 +0,0 @@ -guzzleClient = $this->createMock(Client::class); - - $this->apiClient = new MollieApiClient($this->guzzleClient); - - if (! $oAuthClient) { - $this->apiClient->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); - } else { - $this->apiClient->setAccessToken('access_Wwvu7egPcJLLJ9Kb7J632x8wJ2zMeJ'); - } - - $this->guzzleClient - ->expects($this->once()) - ->method('send') - ->with($this->isInstanceOf(Request::class)) - ->willReturnCallback(function (Request $request) use ($expectedRequest, $response) { - $this->assertEquals($expectedRequest->getMethod(), $request->getMethod(), 'HTTP method must be identical'); - - $this->assertEquals( - $expectedRequest->getUri()->getPath(), - $request->getUri()->getPath(), - 'URI path must be identical' - ); - - $this->assertEquals( - $expectedRequest->getUri()->getQuery(), - $request->getUri()->getQuery(), - 'Query string parameters must be identical' - ); - - $requestBody = $request->getBody()->getContents(); - $expectedBody = $expectedRequest->getBody()->getContents(); - - if (strlen($expectedBody) > 0 && strlen($requestBody) > 0) { - $this->assertJsonStringEqualsJsonString( - $expectedBody, - $requestBody, - 'HTTP body must be identical' - ); - } - - return $response; - }); - } - - protected function copy($array, $object) - { - foreach ($array as $property => $value) { - $object->$property = $value; - } - - return $object; - } -} diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php deleted file mode 100644 index 1645b76d5..000000000 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ /dev/null @@ -1,283 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/chargebacks' - ), - new Response( - 200, - [], - '{ - "_embedded":{ - "chargebacks":[ - { - "resource":"chargeback", - "id":"chb_n9z0tp", - "amount":{ - "value":"-13.00", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-13.00", - "currency":"EUR" - }, - "reversedAt": null, - "reason":{ - "code":"AC01", - "description":"" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - }, - { - "resource":"chargeback", - "id":"chb_6cqlwf", - "amount":{ - "value":"-0.37", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_nQKWJbDj7j", - "settlementAmount":{ - "value":"-0.37", - "currency":"EUR" - }, - "reversedAt": null, - "reason": null, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j/chargebacks/chb_6cqlwf", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - } - ] - }, - "_links":{ - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", - "type":"text/html" - }, - "self":{ - "href":"https://api.mollie.com/v2/chargebacks", - "type":"application/hal+json" - } - }, - "count": 2 - }' - ) - ); - - $chargebacks = $this->apiClient->chargebacks->page(); - - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals(2, $chargebacks->count()); - $this->assertCount(2, $chargebacks); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks', - 'text/html', - $chargebacks->_links->documentation - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/chargebacks', - 'application/hal+json', - $chargebacks->_links->self - ); - - $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00', 'AC01'); - $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', '-0.37', null); - } - - public function test_iterate_chargebacks() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/chargebacks' - ), - new Response( - 200, - [], - '{ - "_embedded":{ - "chargebacks":[ - { - "resource":"chargeback", - "id":"chb_n9z0tp", - "amount":{ - "value":"-13.00", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-13.00", - "currency":"EUR" - }, - "reversedAt": null, - "reason":{ - "code":"AC01", - "description":"" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - }, - { - "resource":"chargeback", - "id":"chb_6cqlwf", - "amount":{ - "value":"-0.37", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_nQKWJbDj7j", - "settlementAmount":{ - "value":"-0.37", - "currency":"EUR" - }, - "reversedAt": null, - "reason": null, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j/chargebacks/chb_6cqlwf", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - } - ] - }, - "_links":{ - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", - "type":"text/html" - }, - "self":{ - "href":"https://api.mollie.com/v2/chargebacks", - "type":"application/hal+json" - } - }, - "count": 2 - }' - ) - ); - - foreach ($this->apiClient->chargebacks->iterator() as $chargeback) { - $this->assertInstanceOf(Chargeback::class, $chargeback); - } - } - - protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount, $reasonCode) - { - $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals('chargeback', $chargeback->resource); - $this->assertEquals($chargebackId, $chargeback->id); - - $this->assertAmountObject($amount, 'EUR', $chargeback->amount); - $this->assertAmountObject($amount, 'EUR', $chargeback->settlementAmount); - - $this->assertEquals('2018-03-28T11:44:32+00:00', $chargeback->createdAt); - $this->assertEquals($paymentId, $chargeback->paymentId); - $this->assertNull($chargeback->reversedAt); - - if ($reasonCode === null) { - $this->assertNull($chargeback->reason); - } else { - $this->assertReasonObject($reasonCode, '', $chargeback->reason); - } - - $this->assertLinkObject( - "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}", - 'application/hal+json', - $chargeback->_links->self - ); - - $this->assertLinkObject( - "https://api.mollie.com/v2/payments/{$paymentId}", - 'application/hal+json', - $chargeback->_links->payment - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback', - 'text/html', - $chargeback->_links->documentation - ); - } - - protected function assertReasonObject($code, $description, $reasonObject) - { - $this->assertEquals( - $this->createReasonObject($code, $description), - $reasonObject - ); - } - - protected function createReasonObject($code, $description) - { - return (object) [ - 'code' => $code, - 'description' => $description, - ]; - } -} diff --git a/tests/Mollie/API/Endpoints/ClientEndpointTest.php b/tests/Mollie/API/Endpoints/ClientEndpointTest.php deleted file mode 100644 index 3cd92eb25..000000000 --- a/tests/Mollie/API/Endpoints/ClientEndpointTest.php +++ /dev/null @@ -1,166 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/clients/org_1337'), - new Response( - 200, - [], - '{ - "resource": "client", - "id": "org_1337", - "organizationCreatedAt": "2018-03-21T13:13:37+00:00", - "commission": { - "count": 200, - "totalAmount": { - "currency": "EUR", - "value": "10.00" - } - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/clients/org_1337", - "type": "application/hal+json" - }, - "organization": { - "href": "https://api.mollie.com/v2/organizations/org_1337", - "type": "application/hal+json" - }, - "onboarding": { - "href": "https://api.mollie.com/v2/onboarding/org_1337", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/clients-api/get-client", - "type": "text/html" - } - } - }' - ) - ); - - $client = $this->apiClient->clients->get('org_1337'); - - $this->assertClient($client); - } - - public function test_get_clients_page() - { - $this->mockApiCall( - new Request('GET', '/v2/clients', [], ''), - new Response( - 200, - [], - '{ - "count":1, - "_embedded":{ - "clients":[ - { - "resource":"client", - "id":"org_1337", - "organizationCreatedAt":"2018-03-21T13:13:37+00:00", - "commission":{ - "count":200, - "totalAmount":{ - "currency":"EUR", - "value":"10.00" - } - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/clients/org_1337", - "type":"application/hal+json" - }, - "organization":{ - "href":"https://api.mollie.com/v2/organizations/org_1337", - "type":"application/hal+json" - }, - "onboarding":{ - "href":"https://api.mollie.com/v2/onboarding/org_1337", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/clients-api/get-client", - "type":"text/html" - } - } - } - ] - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/clients?limit=3", - "type":"application/hal+json" - }, - "previous":null, - "next":{ - "href":"https://api.mollie.com/v2/clients?from=org_1379&limit=3", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/clients-api/list-clients", - "type":"text/html" - } - } - }' - ) - ); - - $clients = $this->apiClient->clients->page(); - - $this->assertInstanceOf(ClientCollection::class, $clients); - $this->assertEquals(1, $clients->count()); - $this->assertCount(1, $clients); - - $client = $clients[0]; - $this->assertClient($client); - } - - protected function assertClient($client) - { - $this->assertInstanceOf(Client::class, $client); - - $this->assertEquals('org_1337', $client->id); - $this->assertEquals('200', $client->commission->count); - $this->assertEquals('EUR', $client->commission->totalAmount->currency); - $this->assertEquals('10.00', $client->commission->totalAmount->value); - $this->assertEquals('2018-03-21T13:13:37+00:00', $client->organizationCreatedAt); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/clients/org_1337', - 'application/hal+json', - $client->_links->self - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/organizations/org_1337', - 'application/hal+json', - $client->_links->organization - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/onboarding/org_1337', - 'application/hal+json', - $client->_links->onboarding - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/clients-api/get-client', - 'text/html', - $client->_links->documentation - ); - } -} diff --git a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php b/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php deleted file mode 100644 index 14ca8c2fc..000000000 --- a/tests/Mollie/API/Endpoints/ClientLinkEndpointTest.php +++ /dev/null @@ -1,126 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/client-links', - [], - '{ - "owner": { - "email": "foo@test.com", - "givenName": "foo", - "familyName": "bar", - "locale": "nl_NL" - }, - "name": "Foo Company", - "address": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl" - }, - "registrationNumber": "30204462", - "vatNumber": "NL123456789B01" - }' - ), - new Response( - 201, - [], - $this->getClientLinkResponseFixture($client_link_id) - ) - ); - - $clientLink = $this->apiClient->clientLinks->create([ - 'owner' => [ - 'email' => 'foo@test.com', - 'givenName' => 'foo', - 'familyName' => 'bar', - 'locale' => 'nl_NL', - ], - 'name' => 'Foo Company', - 'address' => [ - 'streetAndNumber' => 'Keizersgracht 313', - 'postalCode' => '1016 EE', - 'city' => 'Amsterdam', - 'country' => 'nl', - ], - 'registrationNumber' => '30204462', - 'vatNumber' => 'NL123456789B01', - ]); - - $this->assertEquals($clientLink->id, $client_link_id); - $this->assertLinkObject("https://my.mollie.com/dashboard/client-link/finalize/{$client_link_id}", 'text/html', $clientLink->_links->clientLink); - $this->assertLinkObject('https://docs.mollie.com/reference/v2/clients-api/create-client-link', 'text/html', $clientLink->_links->documentation); - - $redirectLink = $clientLink->getRedirectUrl($app_id, $state, $scopes, $approval_prompt); - $this->assertEquals("https://my.mollie.com/dashboard/client-link/finalize/{$client_link_id}?{$expected_url_query}", $redirectLink); - } - - protected function getClientLinkResponseFixture(string $client_link_id) - { - return str_replace( - [ - '<>', - ], - [ - $client_link_id, - ], - '{ - "id": "<>", - "resource": "client-link", - "_links": { - "clientLink": { - "href": "https://my.mollie.com/dashboard/client-link/finalize/<>", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/clients-api/create-client-link", - "type": "text/html" - } - } - }' - ); - } - - public function clientCreateData(): array - { - return [ - [ - 'cl_vZCnNQsV2UtfXxYifWKWH', - 'app_j9Pakf56Ajta6Y65AkdTtAv', - 'decafbad', - [ - 'onboarding.read', - 'onboarding.write', - ], - 'force', - 'client_id=app_j9Pakf56Ajta6Y65AkdTtAv&state=decafbad&approval_prompt=force&scope=onboarding.read%20onboarding.write', - ], - [ - 'cl_vZCnNQsV2UtfXxYifWKWG', - 'app_j9Pakf56Ajta6Y65AkdTtAw', - 'decafbad', - [ - 'onboarding.read', - ], - 'auto', - 'client_id=app_j9Pakf56Ajta6Y65AkdTtAw&state=decafbad&approval_prompt=auto&scope=onboarding.read', - ], - ]; - } -} diff --git a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php deleted file mode 100644 index 69d16cfbb..000000000 --- a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +++ /dev/null @@ -1,276 +0,0 @@ -mockApiCall( - new Request('POST', '/v2/customers'), - new Response( - 200, - [], - '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/create-customer", - "type": "text/html" - } - } - }' - ) - ); - - /** @var Customer $customer */ - $customer = $this->apiClient->customers->create([ - 'name' => 'John Doe', - 'email' => 'johndoe@example.org', - ]); - - $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals('customer', $customer->resource); - $this->assertEquals('cst_FhQJRw4s2n', $customer->id); - $this->assertEquals('John Doe', $customer->name); - $this->assertEquals('johndoe@example.org', $customer->email); - $this->assertNull($customer->locale); - $this->assertNull($customer->metadata); - $this->assertEquals([], $customer->recentlyUsedMethods); - $this->assertEquals('2018-04-19T08:49:01+00:00', $customer->createdAt); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/create-customer', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $customer->_links->documentation); - } - - public function test_get_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n'), - new Response( - 200, - [], - '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }' - ) - ); - - /** @var Customer $customer */ - $customer = $this->apiClient->customers->get('cst_FhQJRw4s2n'); - - $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals('customer', $customer->resource); - $this->assertEquals('cst_FhQJRw4s2n', $customer->id); - $this->assertEquals('John Doe', $customer->name); - $this->assertEquals('johndoe@example.org', $customer->email); - $this->assertNull($customer->locale); - $this->assertNull($customer->metadata); - $this->assertEquals([], $customer->recentlyUsedMethods); - $this->assertEquals('2018-04-19T08:49:01+00:00', $customer->createdAt); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/get-customer', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $customer->_links->documentation); - } - - public function test_list_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers'), - new Response( - 200, - [], - '{ - "_embedded": { - "customers": [ - { - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00" - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/list-customers", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customers = $this->apiClient->customers->page(); - - $this->assertInstanceOf(CustomerCollection::class, $customers); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/list-customers', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $customers->_links->documentation); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $customers->_links->self); - - foreach ($customers as $customer) { - $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals('customer', $customer->resource); - $this->assertNotEmpty($customer->createdAt); - } - } - - public function test_iterator_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers'), - new Response( - 200, - [], - '{ - "_embedded": { - "customers": [ - { - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00" - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/list-customers", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - foreach ($this->apiClient->customers->iterator() as $customer) { - $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals('customer', $customer->resource); - $this->assertNotEmpty($customer->createdAt); - } - } - - public function test_update_works() - { - $expectedName = 'Kaas Broodje'; - $expectedEmail = 'kaas.broodje@gmail.com'; - - $this->mockApiCall( - new Request('PATCH', '/v2/customers/cst_FhQJRw4s2n'), - new Response( - 200, - [], - '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "'.$expectedName.'", - "email": "'.$expectedEmail.'", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - $customer->name = $expectedName; - $customer->email = $expectedEmail; - - $updatedCustomer = $customer->update(); - - $this->assertEquals($expectedName, $updatedCustomer->name); - $this->assertEquals($expectedEmail, $updatedCustomer->email); - } - - /** - * @return Customer - */ - private function getCustomer() - { - $customerJson = '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "self": { - "href": "http://api.mollie.test/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($customerJson), new Customer($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php deleted file mode 100644 index 23c8b57a5..000000000 --- a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php +++ /dev/null @@ -1,315 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/customers/cst_FhQJRw4s2n/payments', - [], - '{ - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description": "My first API payment", - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "metadata": { - "order_id": "1234" - } - }' - ), - new Response( - 201, - [], - '{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":null, - "metadata":{ - "order_id":"1234" - }, - "status":"open", - "isCancelable":false, - "expiresAt":"2018-03-13T14:17:29+00:00", - "details":null, - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "checkout":{ - "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8", - "type":"text/html" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/customers-api/create-payment", - "type":"text/html" - } - } - }' - ) - ); - - /** @var Customer $customer */ - $customer = $this->getCustomer(); - - $payment = $customer->createPayment([ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '20.00', - ], - 'description' => 'My first API payment', - 'redirectUrl' => 'https://example.org/redirect', - 'webhookUrl' => 'https://example.org/webhook', - 'metadata' => [ - 'order_id' => '1234', - ], - ]); - - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('tr_44aKxzEbr8', $payment->id); - $this->assertEquals('test', $payment->mode); - $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $payment->amount); - - $this->assertEquals('My first API payment', $payment->description); - $this->assertNull($payment->method); - $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); - $this->assertEquals(PaymentStatus::OPEN, $payment->status); - $this->assertFalse($payment->isCancelable); - $this->assertEquals('2018-03-13T14:17:29+00:00', $payment->expiresAt); - $this->assertNull($payment->details); - $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); - $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); - $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $payment->_links->self); - - $checkoutLink = (object) ['href' => 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', 'type' => 'text/html']; - $this->assertEquals($checkoutLink, $payment->_links->checkout); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $payment->_links->customer); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/create-payment', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $payment->_links->documentation); - } - - public function test_list_customer_payments() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/customers/cst_FhQJRw4s2n/payments?testmode=true', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_admNa2tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 1", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa", - "type": "text/html" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - }, - { - "resource": "payment", - "id": "tr_bcaLc7hFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 2", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa", - "type": "text/html" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - }, - { - "resource": "payment", - "id": "tr_pslHy1tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 3", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa", - "type": "text/html" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 3 - }' - ), - true - ); - - /** @var Customer $customer */ - $customer = $this->getCustomer(); - - $payments = $customer->payments(); - - $this->assertInstanceOf(PaymentCollection::class, $payments); - $this->assertEquals(3, $payments->count()); - $this->assertEquals(3, count($payments)); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/customers-api/list-customer-payments', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $payments->_links->documentation); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_TkNdP8yPrH/payments?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $payments->_links->self); - } - - /** - * @return CustomerPaymentEndpointTest - */ - private function getCustomer() - { - $customerJson = '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($customerJson), new Customer($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php deleted file mode 100644 index 85c7d4504..000000000 --- a/tests/Mollie/API/Endpoints/CustomerSubscriptionPaymentEndpointTest.php +++ /dev/null @@ -1,112 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments?testmode=true'), - new Response( - 200, - [], - '{ - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_DtKxVP2AgW", - "mode": "test", - "createdAt": "2018-09-19T12:49:52+00:00", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Some subscription 19 sep. 2018", - "method": "directdebit", - "metadata": null, - "status": "pending", - "isCancelable": true, - "expiresAt": "2019-09-19T12:49:52+00:00", - "locale": "nl_NL", - "profileId": "pfl_rH9rQtedgS", - "customerId": "cst_8wmqcHMN4U", - "mandateId": "mdt_aGQNkteF6w", - "subscriptionId": "sub_8JfGzs6v3K", - "sequenceType": "recurring", - "redirectUrl": null, - "webhookUrl": "https://example.org/webhook", - "settlementAmount": { - "value": "10.00", - "currency": "EUR" - }, - "details": { - "transferReference": "SD67-6850-2204-6029", - "creditorIdentifier": "NL08ZZZ502057730000", - "consumerName": "Customer A", - "consumerAccount": "NL50INGB0006588912", - "consumerBic": "INGBNL2A", - "dueDate": "2018-09-21", - "signatureDate": "2018-09-19" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_DtKxVP2AgW?testmode=true", - "type": "application/hal+json" - }, - "checkout": null, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U?testmode=true", - "type": "application/hal+json" - }, - "mandate": { - "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates/mdt_aGQNkteF6w?testmode=true", - "type": "application/hal+json" - }, - "subscription": { - "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K?testmode=true", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions-payments", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments?limit=50&testmode=true", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $subscription = new Subscription($this->apiClient); - $subscription->_links = $this->createNamedLinkObject( - 'payments', - '/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments?testmode=true', - 'application/hal+json' - ); - - $result = $subscription->payments(); - $this->assertInstanceOf(PaymentCollection::class, $result); - $this->assertEquals(1, $result->count()); - $this->assertEquals('Some subscription 19 sep. 2018', $result[0]->description); - } -} diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php deleted file mode 100644 index 2344738d1..000000000 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ /dev/null @@ -1,319 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/invoices/inv_bsa6PvAwaK', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "invoice", - "id": "inv_bsa6PvAwaK", - "reference": "2018.190241", - "vatNumber": "123456789B01", - "status": "paid", - "issuedAt": "2018-05-02", - "paidAt": "2018-05-02", - "netAmount": { - "value": "100.00", - "currency": "EUR" - }, - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "grossAmount": { - "value": "100.00", - "currency": "EUR" - }, - "lines": [ - { - "period": "2018-04", - "description": "iDEAL transaction costs: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - }, - { - "period": "2018-04", - "description": "Refunds iDEAL: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK", - "type": "application/hal+json" - }, - "pdf": { - "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985", - "type": "application/pdf" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice", - "type": "text/html" - } - } - }' - ) - ); - - $invoice = $this->apiClient->invoices->get('inv_bsa6PvAwaK'); - - $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals('invoice', $invoice->resource); - $this->assertEquals('inv_bsa6PvAwaK', $invoice->id); - $this->assertEquals('2018.190241', $invoice->reference); - $this->assertEquals('123456789B01', $invoice->vatNumber); - $this->assertEquals(InvoiceStatus::PAID, $invoice->status); - $this->assertEquals('2018-05-02', $invoice->issuedAt); - $this->assertEquals('2018-05-02', $invoice->paidAt); - - $this->assertEquals((object) ['value' => '100.00', 'currency' => 'EUR'], $invoice->netAmount); - $this->assertEquals((object) ['value' => '0.00', 'currency' => 'EUR'], $invoice->vatAmount); - $this->assertEquals((object) ['value' => '100.00', 'currency' => 'EUR'], $invoice->grossAmount); - - $this->assertCount(2, $invoice->lines); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $invoice->_links->self); - - $pdfLink = (object) ['href' => 'https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985', 'type' => 'application/pdf']; - $this->assertEquals($pdfLink, $invoice->_links->pdf); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/invoices-api/get-invoice', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $invoice->_links->documentation); - } - - public function test_list_invoices() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/invoices', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "invoices": [ - { - "resource": "invoice", - "id": "inv_bsa6PvAwaK", - "reference": "2018.190241", - "vatNumber": "123456789B01", - "status": "paid", - "issuedAt": "2018-05-02", - "paidAt": "2018-05-02", - "netAmount": { - "value": "100.00", - "currency": "EUR" - }, - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "grossAmount": { - "value": "100.00", - "currency": "EUR" - }, - "lines": [ - { - "period": "2018-04", - "description": "iDEAL transaction costs: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - }, - { - "period": "2018-04", - "description": "Refunds iDEAL: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK", - "type": "application/hal+json" - }, - "pdf": { - "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985", - "type": "application/pdf" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice", - "type": "text/html" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/invoices-api/list-invoices", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.nl/v2/invoices?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $invoices = $this->apiClient->invoices->page(); - $this->assertInstanceOf(InvoiceCollection::class, $invoices); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/invoices-api/list-invoices', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $invoices->_links->documentation); - - $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/invoices?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $invoices->_links->self); - - $this->assertEmpty($invoices->_links->previous); - $this->assertEmpty($invoices->_links->next); - - foreach ($invoices as $invoice) { - $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals('invoice', $invoice->resource); - $this->assertNotEmpty($invoice->lines); - } - } - - public function test_iterate_invoices() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/invoices', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "invoices": [ - { - "resource": "invoice", - "id": "inv_bsa6PvAwaK", - "reference": "2018.190241", - "vatNumber": "123456789B01", - "status": "paid", - "issuedAt": "2018-05-02", - "paidAt": "2018-05-02", - "netAmount": { - "value": "100.00", - "currency": "EUR" - }, - "vatAmount": { - "value": "0.00", - "currency": "EUR" - }, - "grossAmount": { - "value": "100.00", - "currency": "EUR" - }, - "lines": [ - { - "period": "2018-04", - "description": "iDEAL transaction costs: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - }, - { - "period": "2018-04", - "description": "Refunds iDEAL: april 2018", - "count": 1337, - "vatPercentage": 0, - "amount": { - "value": "50.00", - "currency": "EUR" - } - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK", - "type": "application/hal+json" - }, - "pdf": { - "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985", - "type": "application/pdf" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice", - "type": "text/html" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/invoices-api/list-invoices", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.nl/v2/invoices?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - foreach ($this->apiClient->invoices->iterator() as $invoice) { - $this->assertInstanceOf(Invoice::class, $invoice); - $this->assertEquals('invoice', $invoice->resource); - $this->assertNotEmpty($invoice->lines); - } - } -} diff --git a/tests/Mollie/API/Endpoints/MandateEndpointTest.php b/tests/Mollie/API/Endpoints/MandateEndpointTest.php deleted file mode 100644 index 40b931f42..000000000 --- a/tests/Mollie/API/Endpoints/MandateEndpointTest.php +++ /dev/null @@ -1,427 +0,0 @@ -mockApiCall( - new Request('POST', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "resource": "mandate", - "id": "mdt_AcQl5fdL4h", - "status": "valid", - "method": "directdebit", - "details": { - "consumerName": "John Doe", - "consumerAccount": "NL55INGB0000000000", - "consumerBic": "INGBNL2A" - }, - "mandateReference": null, - "signatureDate": "2018-05-07", - "createdAt": "2018-05-07T10:49:08+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/create-mandate", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var Mandate $mandate */ - $mandate = $customer->createMandate([ - 'consumerName' => 'John Doe', - 'method' => 'directdebit', - 'consumerBic' => 'INGBNL2A', - 'consumerAccount' => 'NL55INGB0000000000', - ]); - - $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals('mandate', $mandate->resource); - $this->assertEquals(MandateStatus::VALID, $mandate->status); - $this->assertEquals('directdebit', $mandate->method); - $this->assertEquals((object) ['consumerName' => 'John Doe', 'consumerAccount' => 'NL55INGB0000000000', 'consumerBic' => 'INGBNL2A'], $mandate->details); - $this->assertNull($mandate->mandateReference); - $this->assertEquals('2018-05-07', $mandate->signatureDate); - $this->assertEquals('2018-05-07T10:49:08+00:00', $mandate->createdAt); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $mandate->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $mandate->_links->customer); - - $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/create-mandate', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $mandate->_links->documentation); - } - - public function test_get_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h'), - new Response( - 200, - [], - '{ - "resource": "mandate", - "id": "mdt_AcQl5fdL4h", - "status": "valid", - "method": "directdebit", - "details": { - "consumerName": "John Doe", - "consumerAccount": "NL55INGB0000000000", - "consumerBic": "INGBNL2A" - }, - "mandateReference": null, - "signatureDate": "2018-05-07", - "createdAt": "2018-05-07T10:49:08+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/create-mandate", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var Mandate $mandate */ - $mandate = $customer->getMandate('mdt_AcQl5fdL4h'); - - $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals('mandate', $mandate->resource); - $this->assertEquals(MandateStatus::VALID, $mandate->status); - $this->assertEquals(MandateMethod::DIRECTDEBIT, $mandate->method); - $this->assertEquals((object) ['consumerName' => 'John Doe', 'consumerAccount' => 'NL55INGB0000000000', 'consumerBic' => 'INGBNL2A'], $mandate->details); - $this->assertNull($mandate->mandateReference); - $this->assertEquals('2018-05-07', $mandate->signatureDate); - $this->assertEquals('2018-05-07T10:49:08+00:00', $mandate->createdAt); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $mandate->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $mandate->_links->customer); - - $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/create-mandate', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $mandate->_links->documentation); - } - - public function test_list_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "_embedded": { - "mandates": [ - { - "resource": "mandate", - "id": "mdt_AcQl5fdL4h", - "status": "valid", - "method": "directdebit", - "details": { - "consumerName": "John Doe", - "consumerAccount": "NL55INGB0000000000", - "consumerBic": "INGBNL2A" - }, - "mandateReference": null, - "signatureDate": "2018-05-07", - "createdAt": "2018-05-07T10:49:08+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/list-mandates", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var MandateCollection $mandates */ - $mandates = $customer->mandates(); - $this->assertInstanceOf(MandateCollection::class, $mandates); - - /** @var Mandate $mandate */ - foreach ($mandates as $mandate) { - $this->assertInstanceOf(Mandate::class, $mandate); - $this->assertEquals('mandate', $mandate->resource); - $this->assertEquals(MandateStatus::VALID, $mandate->status); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $mandate->_links->customer); - } - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $mandates->_links->self); - - $documentationLink = (object) ['href' => 'https://mollie.com/en/docs/reference/customers/list-mandates', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $mandates->_links->documentation); - } - - public function test_customer_has_valid_mandate_when_true() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "_embedded": { - "mandates": [ - { - "resource": "mandate", - "id": "mdt_AcQl5fdL4h", - "status": "valid", - "method": "directdebit", - "details": { - "consumerName": "John Doe", - "consumerAccount": "NL55INGB0000000000", - "consumerBic": "INGBNL2A" - }, - "mandateReference": null, - "signatureDate": "2018-05-07", - "createdAt": "2018-05-07T10:49:08+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/list-mandates", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - $this->assertTrue($customer->hasValidMandate()); - } - - public function test_customer_has_valid_mandate_when_false() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "_embedded": { - "mandates": [] - }, - "count": 0, - "_links": { - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/list-mandates", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - $this->assertFalse($customer->hasValidMandate()); - } - - public function test_customer_has_valid_mandate_for_method_when_false() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "_embedded": { - "mandates": [] - }, - "count": 0, - "_links": { - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/list-mandates", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - $this->assertFalse($customer->hasValidMandateForMethod('directdebit')); - } - - public function test_customer_has_valid_mandate_for_method_when_true() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/mandates'), - new Response( - 200, - [], - '{ - "_embedded": { - "mandates": [ - { - "resource": "mandate", - "id": "mdt_AcQl5fdL4h", - "status": "valid", - "method": "directdebit", - "details": { - "consumerName": "John Doe", - "consumerAccount": "NL55INGB0000000000", - "consumerBic": "INGBNL2A" - }, - "mandateReference": null, - "signatureDate": "2018-05-07", - "createdAt": "2018-05-07T10:49:08+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/mandates/mdt_AcQl5fdL4h", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://mollie.com/en/docs/reference/customers/list-mandates", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_vzEExMcxj7/mandates?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - $this->assertTrue($customer->hasValidMandateForMethod('directdebit')); - } - - /** - * @return Customer - */ - private function getCustomer() - { - $customerJson = '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($customerJson), new Customer($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/MethodEndpointTest.php b/tests/Mollie/API/Endpoints/MethodEndpointTest.php deleted file mode 100644 index d3fc91ed2..000000000 --- a/tests/Mollie/API/Endpoints/MethodEndpointTest.php +++ /dev/null @@ -1,644 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/methods/ideal'), - new Response( - 200, - [], - '{ - "resource": "method", - "id": "ideal", - "description": "iDEAL", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/ideal", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", - "type": "text/html" - } - } - }' - ) - ); - - $idealMethod = $this->apiClient->methods->get('ideal'); - - $this->assertInstanceOf(Method::class, $idealMethod); - $this->assertEquals('ideal', $idealMethod->id); - $this->assertEquals('iDEAL', $idealMethod->description); - $this->assertAmountObject(0.01, 'EUR', $idealMethod->minimumAmount); - $this->assertAmountObject(50000, 'EUR', $idealMethod->maximumAmount); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal.png', $idealMethod->image->size1x); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal%402x.png', $idealMethod->image->size2x); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/ideal', - 'application/hal+json', - $idealMethod->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/methods-api/get-method', - 'text/html', - $idealMethod->_links->documentation - ); - } - - public function test_get_method_with_include_issuers() - { - $this->mockApiCall( - new Request('GET', '/v2/methods/ideal?include=issuers'), - new Response( - 200, - [], - '{ - "resource": "method", - "id": "ideal", - "description": "iDEAL", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" - }, - "issuers": [ - { - "resource": "issuer", - "id": "ideal_TESTNL99", - "name": "TBM Bank", - "method": "ideal", - "image": { - "size1x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png", - "size2x": "https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png" - } - } - ], - - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/ideal", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", - "type": "text/html" - } - } - }' - ) - ); - - $idealMethod = $this->apiClient->methods->get('ideal', ['include' => 'issuers']); - - $this->assertInstanceOf(Method::class, $idealMethod); - $this->assertEquals('ideal', $idealMethod->id); - $this->assertEquals('iDEAL', $idealMethod->description); - $this->assertAmountObject(0.01, 'EUR', $idealMethod->minimumAmount); - $this->assertAmountObject(50000, 'EUR', $idealMethod->maximumAmount); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal.png', $idealMethod->image->size1x); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/ideal%402x.png', $idealMethod->image->size2x); - - $issuers = $idealMethod->issuers(); - $this->assertInstanceOf(IssuerCollection::class, $issuers); - $this->assertCount(1, $issuers); - - $testIssuer = $issuers[0]; - - $this->assertInstanceOf(Issuer::class, $testIssuer); - $this->assertEquals('ideal_TESTNL99', $testIssuer->id); - $this->assertEquals('TBM Bank', $testIssuer->name); - $this->assertEquals('ideal', $testIssuer->method); - - $expectedSize1xImageLink = 'https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png'; - $this->assertEquals($expectedSize1xImageLink, $testIssuer->image->size1x); - - $expectedSize2xImageLink = 'https://www.mollie.com/images/checkout/v2/ideal-issuer-icons/TESTNL99.png'; - $this->assertEquals($expectedSize2xImageLink, $testIssuer->image->size2x); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/ideal', - 'application/hal+json', - $idealMethod->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/methods-api/get-method', - 'text/html', - $idealMethod->_links->documentation - ); - } - - public function test_get_method_with_include_pricing() - { - $this->mockApiCall( - new Request('GET', '/v2/methods/ideal?include=pricing'), - new Response( - 200, - [], - '{ - "resource": "method", - "id": "ideal", - "description": "iDEAL", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/external/icons/payment-methods/ideal.png", - "size2x": "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png", - "svg": "https://www.mollie.com/external/icons/payment-methods/ideal.svg" - }, - "pricing": [ - { - "description": "The Netherlands", - "fixed": { - "value": "0.29", - "currency": "EUR" - }, - "variable": "0" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/ideal", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", - "type": "text/html" - } - } - }' - ) - ); - - $method = $this->apiClient->methods->get('ideal', ['include' => 'pricing']); - - $this->assertInstanceOf(Method::class, $method); - $this->assertEquals('method', $method->resource); - $this->assertEquals('ideal', $method->id); - $this->assertEquals('iDEAL', $method->description); - $this->assertAmountObject(0.01, 'EUR', $method->minimumAmount); - $this->assertAmountObject(50000, 'EUR', $method->maximumAmount); - $this->assertEquals( - 'https://www.mollie.com/external/icons/payment-methods/ideal.png', - $method->image->size1x - ); - $this->assertEquals( - 'https://www.mollie.com/external/icons/payment-methods/ideal%402x.png', - $method->image->size2x - ); - - $this->assertEquals( - 'https://www.mollie.com/external/icons/payment-methods/ideal.svg', - $method->image->svg - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/ideal', - 'application/hal+json', - $method->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/methods-api/get-method', - 'text/html', - $method->_links->documentation - ); - - $price = $method->pricing[0]; - - $this->assertEquals('The Netherlands', $price->description); - $this->assertAmountObject(0.29, 'EUR', $price->fixed); - $this->assertEquals('0', $price->variable); - - $method_prices = $method->pricing(); - - $this->assertInstanceOf(MethodPriceCollection::class, $method_prices); - - $method_price = $method_prices[0]; - $this->assertInstanceOf(MethodPrice::class, $method_price); - $this->assertAmountObject(0.29, 'EUR', $method_price->fixed); - $this->assertEquals('0', $method_price->variable); - } - - public function test_get_translated_method() - { - $this->mockApiCall( - new Request('GET', '/v2/methods/sofort?locale=de_DE'), - new Response( - 200, - [], - '{ - "resource": "method", - "id": "sofort", - "description": "SOFORT \u00dcberweisung", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/sofort.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/sofort%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/sofort", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", - "type": "text/html" - } - } - }' - ) - ); - - $method = $this->apiClient->methods->get('sofort', ['locale' => 'de_DE']); - - $this->assertInstanceOf(Method::class, $method); - $this->assertEquals('sofort', $method->id); - $this->assertEquals('SOFORT Ãœberweisung', $method->description); - $this->assertAmountObject(0.01, 'EUR', $method->minimumAmount); - $this->assertAmountObject(50000, 'EUR', $method->maximumAmount); - - $amount = new Stdclass; - $amount->size1x = 'https://www.mollie.com/images/payscreen/methods/sofort.png'; - $amount->size2x = 'https://www.mollie.com/images/payscreen/methods/sofort%402x.png'; - - $selfLink = (object) [ - 'href' => 'https://api.mollie.com/v2/methods/sofort', - 'type' => 'application/hal+json', - ]; - $this->assertEquals($selfLink, $method->_links->self); - - $documentationLink = (object) [ - 'href' => 'https://docs.mollie.com/reference/v2/methods-api/get-method', - 'type' => 'text/html', - ]; - - $this->assertEquals($documentationLink, $method->_links->documentation); - } - - public function test_list_all_active_methods() - { - $this->mockApiCall( - new Request('GET', '/v2/methods'), - new Response( - 200, - [], - '{ - "_embedded": { - "methods": [ - { - "resource": "method", - "id": "ideal", - "description": "iDEAL", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/ideal", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "creditcard", - "description": "Credit card", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "2000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/creditcard", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "mistercash", - "description": "Bancontact", - "minimumAmount": { - "value": "0.02", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/mistercash", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "giftcard", - "description": "Gift cards", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": null, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/giftcard.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/giftcard%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/giftcard", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 4, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.com/v2/methods", - "type": "application/hal+json" - } - } - }' - ) - ); - - $methods = $this->apiClient->methods->allActive(); - - $this->assertInstanceOf(MethodCollection::class, $methods); - $this->assertEquals(4, $methods->count()); - $this->assertCount(4, $methods); - - $documentationLink = (object) [ - 'href' => 'https://docs.mollie.com/reference/v2/methods-api/list-methods', - 'type' => 'text/html', - ]; - $this->assertEquals($documentationLink, $methods->_links->documentation); - - $selfLink = (object) [ - 'href' => 'http://api.mollie.com/v2/methods', - 'type' => 'application/hal+json', - ]; - $this->assertEquals($selfLink, $methods->_links->self); - - $creditcardMethod = $methods[1]; - - $this->assertInstanceOf(Method::class, $creditcardMethod); - $this->assertEquals('creditcard', $creditcardMethod->id); - $this->assertEquals('Credit card', $creditcardMethod->description); - $this->assertAmountObject(0.01, 'EUR', $creditcardMethod->minimumAmount); - $this->assertAmountObject(2000, 'EUR', $creditcardMethod->maximumAmount); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard.png', $creditcardMethod->image->size1x); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard%402x.png', $creditcardMethod->image->size2x); - - $selfLink = (object) [ - 'href' => 'https://api.mollie.com/v2/methods/creditcard', - 'type' => 'application/hal+json', - ]; - $this->assertEquals($selfLink, $creditcardMethod->_links->self); - } - - public function test_list_all_available_methods() - { - $this->mockApiCall( - new Request('GET', '/v2/methods/all?include=pricing'), - new Response( - 200, - [], - '{ - "_embedded": { - "methods": [ - { - "resource": "method", - "id": "ideal", - "description": "iDEAL", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" - }, - "pricing": [ - { - "description": "Netherlands", - "fixed": { - "value": "0.29", - "currency": "EUR" - }, - "variable": "0" - } - ], - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/ideal", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "creditcard", - "description": "Credit card", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": { - "value": "2000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/creditcard.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/creditcard%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/creditcard", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "mistercash", - "description": "Bancontact", - "minimumAmount": { - "value": "0.02", - "currency": "EUR" - }, - "maximumAmount": { - "value": "50000.00", - "currency": "EUR" - }, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/mistercash.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/mistercash%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/mistercash", - "type": "application/hal+json" - } - } - }, - { - "resource": "method", - "id": "giftcard", - "description": "Gift cards", - "minimumAmount": { - "value": "0.01", - "currency": "EUR" - }, - "maximumAmount": null, - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/giftcard.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/giftcard%402x.png" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/giftcard", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 4, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/methods-api/list-methods", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.com/v2/methods", - "type": "application/hal+json" - } - } - }' - ) - ); - - $methods = $this->apiClient->methods->allAvailable(['include' => 'pricing']); - - $this->assertInstanceOf(MethodCollection::class, $methods); - $this->assertEquals(4, $methods->count()); - $this->assertCount(4, $methods); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/methods-api/list-methods', - 'text/html', - $methods->_links->documentation - ); - - $this->assertLinkObject( - 'http://api.mollie.com/v2/methods', - 'application/hal+json', - $methods->_links->self - ); - - $creditcardMethod = $methods[1]; - - $this->assertInstanceOf(Method::class, $creditcardMethod); - $this->assertEquals('creditcard', $creditcardMethod->id); - $this->assertEquals('Credit card', $creditcardMethod->description); - $this->assertAmountObject(0.01, 'EUR', $creditcardMethod->minimumAmount); - $this->assertAmountObject(2000, 'EUR', $creditcardMethod->maximumAmount); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard.png', $creditcardMethod->image->size1x); - $this->assertEquals('https://www.mollie.com/images/payscreen/methods/creditcard%402x.png', $creditcardMethod->image->size2x); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/creditcard', - 'application/hal+json', - $creditcardMethod->_links->self - ); - } -} diff --git a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php b/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php deleted file mode 100644 index b9a28c5b7..000000000 --- a/tests/Mollie/API/Endpoints/MethodIssuerEndpointTest.php +++ /dev/null @@ -1,57 +0,0 @@ -mockApiCall( - new Request( - 'POST', - 'https://api.mollie.com/v2/profiles/pfl_QkEhN94Ba/methods/ideal/issuers/festivalcadeau' - ), - new Response( - 201, - [], - '{ - "resource": "issuer", - "id": "festivalcadeau", - "name": "Festival Cadeau", - "method": "ideal", - "image": { - "size1x": "https://www.mollie.com/images/payscreen/methods/ideal.png", - "size2x": "https://www.mollie.com/images/payscreen/methods/ideal%402x.png" - } - }' - ) - ); - - $response = $this->apiClient->methodIssuers->enable('pfl_QkEhN94Ba', 'ideal', 'festivalcadeau'); - $this->assertInstanceOf(Issuer::class, $response); - $this->assertEquals('festivalcadeau', $response->id); - } - - /** @test */ - public function test_disable_issuer() - { - $this->mockApiCall( - new Request( - 'DELETE', - 'https://api.mollie.com/v2/profiles/pfl_QkEhN94Ba/methods/ideal/issuers/festivalcadeau' - ), - new Response(204) - ); - - $response = $this->apiClient->methodIssuers->disable('pfl_QkEhN94Ba', 'ideal', 'festivalcadeau'); - - $this->assertNull($response); - } -} diff --git a/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php b/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php deleted file mode 100644 index 7f5e4758e..000000000 --- a/tests/Mollie/API/Endpoints/OnboardingEndpointTest.php +++ /dev/null @@ -1,82 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/onboarding/me'), - new Response( - 200, - [], - '{ - "resource": "onboarding", - "name": "Mollie B.V.", - "signedUpAt": "2018-12-20T10:49:08+00:00", - "status": "completed", - "canReceivePayments": true, - "canReceiveSettlements": true, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/onboarding/me", - "type": "application/hal+json" - }, - "dashboard": { - "href": "https://www.mollie.com/dashboard/onboarding", - "type": "text/html" - }, - "organization": { - "href": "https://api.mollie.com/v2/organization/org_12345", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status", - "type": "text/html" - } - } - }' - ) - ); - - $onboarding = $this->apiClient->onboarding->get(); - - $this->assertInstanceOf(Onboarding::class, $onboarding); - $this->assertEquals('onboarding', $onboarding->resource); - $this->assertEquals('Mollie B.V.', $onboarding->name); - $this->assertEquals(OnboardingStatus::COMPLETED, $onboarding->status); - $this->assertEquals('2018-12-20T10:49:08+00:00', $onboarding->signedUpAt); - $this->assertEquals(true, $onboarding->canReceivePayments); - $this->assertEquals(true, $onboarding->canReceiveSettlements); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/onboarding/me', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $onboarding->_links->self); - - $dashboardLink = (object) ['href' => 'https://www.mollie.com/dashboard/onboarding', 'type' => 'text/html']; - $this->assertEquals($dashboardLink, $onboarding->_links->dashboard); - - $organizationLink = (object) ['href' => 'https://api.mollie.com/v2/organization/org_12345', 'type' => 'application/hal+json']; - $this->assertEquals($organizationLink, $onboarding->_links->organization); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $onboarding->_links->documentation); - } - - public function test_submit_works() - { - $this->mockApiCall( - new Request('POST', '/v2/onboarding/me'), - new Response(204) - ); - - $this->apiClient->onboarding->submit(); - } -} diff --git a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php b/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php deleted file mode 100644 index c47d549fb..000000000 --- a/tests/Mollie/API/Endpoints/OrganizationEndpointTest.php +++ /dev/null @@ -1,125 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/organizations/org_12345678'), - new Response( - 200, - [], - '{ - "resource": "organization", - "id": "org_12345678", - "name": "Mollie B.V.", - "email": "info@mollie.com", - "locale": "nl_NL", - "address": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "NL" - }, - "registrationNumber": "30204462", - "vatNumber": "NL815839091B01", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/organizations/org_12345678", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/organizations-api/get-organization", - "type": "text/html" - } - } - }' - ) - ); - - $organization = $this->apiClient->organizations->get('org_12345678'); - - $this->assertOrganization($organization); - } - - public function test_get_current_organization() - { - $this->mockApiCall( - new Request('GET', '/v2/organizations/me'), - new Response( - 200, - [], - '{ - "resource": "organization", - "id": "org_12345678", - "name": "Mollie B.V.", - "email": "info@mollie.com", - "locale": "nl_NL", - "address": { - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "NL" - }, - "registrationNumber": "30204462", - "vatNumber": "NL815839091B01", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/organizations/org_12345678", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/organizations-api/get-organization", - "type": "text/html" - } - } - }' - ) - ); - - $organization = $this->apiClient->organizations->current(); - - $this->assertOrganization($organization); - } - - protected function assertOrganization($organization) - { - $this->assertInstanceOf(Organization::class, $organization); - - $this->assertEquals('org_12345678', $organization->id); - $this->assertEquals('Mollie B.V.', $organization->name); - $this->assertEquals('info@mollie.com', $organization->email); - $this->assertEquals('nl_NL', $organization->locale); - - $this->assertEquals((object) [ - 'streetAndNumber' => 'Keizersgracht 313', - 'postalCode' => '1016 EE', - 'city' => 'Amsterdam', - 'country' => 'NL', - ], $organization->address); - - $this->assertEquals('30204462', $organization->registrationNumber); - $this->assertEquals('NL815839091B01', $organization->vatNumber); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/organizations/org_12345678', - 'application/hal+json', - $organization->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/organizations-api/get-organization', - 'text/html', - $organization->_links->documentation - ); - } -} diff --git a/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php b/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php deleted file mode 100644 index 3718fd825..000000000 --- a/tests/Mollie/API/Endpoints/OrganizationPartnerEndpointTest.php +++ /dev/null @@ -1,58 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/organizations/me/partner'), - new Response( - 200, - [], - '{ - "resource": "partner", - "partnerType": "signuplink", - "partnerContractSignedAt": "2018-03-20T13:13:37+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/organizations/me/partner", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/organizations-api/get-partner", - "type": "text/html" - }, - "signuplink": { - "href": "https://www.mollie.com/dashboard/signup/myCode?lang=en", - "type": "text/html" - } - } - }' - ) - ); - - $partner = $this->apiClient->organizationPartners->get(); - - $this->assertInstanceOf(Partner::class, $partner); - $this->assertEquals('partner', $partner->resource); - $this->assertEquals('signuplink', $partner->partnerType); - $this->assertEquals('2018-03-20T13:13:37+00:00', $partner->partnerContractSignedAt); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/organizations/me/partner', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $partner->_links->self); - - $signUpLink = (object) ['href' => 'https://www.mollie.com/dashboard/signup/myCode?lang=en', 'type' => 'text/html']; - $this->assertEquals($signUpLink, $partner->_links->signuplink); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/organizations-api/get-partner', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $partner->_links->documentation); - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php deleted file mode 100644 index 77f7799b6..000000000 --- a/tests/Mollie/API/Endpoints/PaymentCaptureEndpointTest.php +++ /dev/null @@ -1,310 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/payments/tr_WDqYK6vllg/captures' - ), - new Response( - 201, - [], - $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT') - ) - ); - - $capture = $this->apiClient->paymentCaptures->createFor( - $this->getPayment('tr_WDqYK6vllg'), - [ - 'amount' => [ - 'value' => '1027.99', - 'currency' => 'EUR', - ], - ] - ); - - $this->assertCapture($capture); - } - - public function test_get_capture_for_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT' - ), - new Response( - 200, - [], - $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT') - ) - ); - - $capture = $this->apiClient->paymentCaptures->getFor( - $this->getPayment('tr_WDqYK6vllg'), - 'cpt_4qqhO89gsT' - ); - - $this->assertCapture($capture); - } - - public function test_get_capture_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT' - ), - new Response( - 200, - [], - $this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT') - ) - ); - - $capture = $this->getPayment('tr_WDqYK6vllg')->getCapture('cpt_4qqhO89gsT'); - - $this->assertCapture($capture); - } - - public function test_list_captures_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_WDqYK6vllg/captures' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "captures": [ - '.$this->getCaptureFixture('tr_WDqYK6vllg', 'cpt_4qqhO89gsT').' - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/captures-api/list-captures", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $captures = $this->getPayment('tr_WDqYK6vllg')->captures(); - - $this->assertEquals(1, $captures->count()); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/captures-api/list-captures', - 'text/html', - $captures->_links->documentation - ); - - $this->assertLinkObject( - 'https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50', - 'application/hal+json', - $captures->_links->self - ); - - $this->assertNull($captures->_links->previous); - $this->assertNull($captures->_links->next); - - $this->assertCapture($captures[0]); - } - - protected function assertCapture($capture) - { - $this->assertInstanceOf(Capture::class, $capture); - - $this->assertEquals('capture', $capture->resource); - $this->assertEquals('cpt_4qqhO89gsT', $capture->id); - $this->assertEquals('live', $capture->mode); - $this->assertEquals('tr_WDqYK6vllg', $capture->paymentId); - $this->assertEquals('shp_3wmsgCJN4U', $capture->shipmentId); - $this->assertEquals('stl_jDk30akdN', $capture->settlementId); - - $this->assertAmountObject('1027.99', 'EUR', $capture->amount); - $this->assertAmountObject('399.00', 'EUR', $capture->settlementAmount); - - $this->assertEquals('2018-08-02T09:29:56+00:00', $capture->createdAt); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT', - 'application/hal+json', - $capture->_links->self - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg', - 'application/hal+json', - $capture->_links->payment - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U', - 'application/hal+json', - $capture->_links->shipment - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/settlements/stl_jDk30akdN', - 'application/hal+json', - $capture->_links->settlement - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/captures-api/get-capture', - 'text/html', - $capture->_links->documentation - ); - } - - protected function getCaptureFixture( - $payment_id = 'tr_WDqYK6vllg', - $capture_id = 'cpt_4qqhO89gsT' - ) { - return str_replace( - [ - '<>', - '<>', - ], - [ - $payment_id, - $capture_id, - ], - '{ - "resource": "capture", - "id": "<>", - "mode": "live", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "settlementAmount": { - "value": "399.00", - "currency": "EUR" - }, - "paymentId": "<>", - "shipmentId": "shp_3wmsgCJN4U", - "settlementId": "stl_jDk30akdN", - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/<>/captures/<>", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/<>", - "type": "application/hal+json" - }, - "shipment": { - "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture", - "type": "text/html" - } - } - }' - ); - } - - /** - * @return Payment - */ - protected function getPayment($payment_id = 'tr_44aKxzEbr8') - { - $paymentJson = '{ - "resource":"payment", - "id":"<>", - "mode":"test", - "createdAt":"2018-03-19T12:17:57+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":"ideal", - "metadata":{ - "order_id":1234 - }, - "status":"paid", - "paidAt":"2018-03-19T12:18:35+00:00", - "amountRefunded":{ - "value":"0.00", - "currency":"EUR" - }, - "amountRemaining":{ - "value":"20.00", - "currency":"EUR" - }, - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412", - "consumerBic":"TESTNL99" - }, - "locale":"nl_NL", - "countryCode":"NL", - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "settlementAmount":{ - "value":"20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/<>", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment", - "type":"text/html" - }, - "refunds":{ - "href":"https://api.mollie.com/v2/payments/<>/refunds", - "type":"application/hal+json" - }, - "captures":{ - "href":"https://api.mollie.com/v2/payments/<>/captures", - "type":"application/hal+json" - } - } - }'; - - $paymentJson = str_replace('<>', $payment_id, $paymentJson); - - return $this->copy(json_decode($paymentJson), new Payment($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php deleted file mode 100644 index 4082f1b3d..000000000 --- a/tests/Mollie/API/Endpoints/PaymentChargebackEndpointTest.php +++ /dev/null @@ -1,403 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/chargebacks' - ), - new Response( - 200, - [], - '{ - "_embedded":{ - "chargebacks":[ - { - "resource":"chargeback", - "id":"chb_n9z0tp", - "amount":{ - "value":"-13.00", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-13.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - }, - { - "resource":"chargeback", - "id":"chb_6cqlwf", - "amount":{ - "value":"-0.37", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-0.37", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_6cqlwf", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - } - ] - }, - "_links":{ - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", - "type":"text/html" - }, - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks", - "type":"application/hal+json" - } - }, - "count": 2 - }' - ) - ); - - $chargebacks = $this->getPayment()->chargebacks(); - - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals(2, $chargebacks->count()); - $this->assertCount(2, $chargebacks); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks', - 'text/html', - $chargebacks->_links->documentation - ); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks', - 'application/hal+json', - $chargebacks->_links->self - ); - - $this->assertChargeback($chargebacks[0], 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00'); - $this->assertChargeback($chargebacks[1], 'tr_44aKxzEbr8', 'chb_6cqlwf', '-0.37'); - } - - public function test_get_chargeback_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp' - ), - new Response( - 200, - [], - '{ - "resource":"chargeback", - "id":"chb_n9z0tp", - "amount":{ - "value":"-13.00", - "currency":"EUR" - }, - "createdAt":"2018-03-28T11:44:32+00:00", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-13.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", - "type": "text/html" - } - } - }' - ) - ); - - $chargeback = $this->getPayment()->getChargeback('chb_n9z0tp'); - - $this->assertChargeback($chargeback, 'tr_44aKxzEbr8', 'chb_n9z0tp', '-13.00'); - } - - public function test_payment_chargebacks_list_for_id_payment_chargeback_endpoint() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/chargebacks' - ), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "chargebacks": [ - { - "resource": "chargeback", - "id": "chb_n9z0tp", - "amount": { - "currency": "EUR", - "value": "43.38" - }, - "settlementAmount": { - "currency": "EUR", - "value": "-35.07" - }, - "createdAt": "2018-03-14T17:00:52.0Z", - "reversedAt": null, - "paymentId": "tr_44aKxzEbr8", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-payment-chargeback", - "type": "text/html" - } - } - }, - { }, - { } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/chargebacks", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/list-payment-chargebacks", - "type": "text/html" - } - } - }' - ) - ); - - $chargebacks = $this->apiClient->paymentChargebacks->listForId('tr_44aKxzEbr8'); - - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals($chargebacks[0]->id, 'chb_n9z0tp'); - $this->assertAmountObject('43.38', 'EUR', $chargebacks[0]->amount); - $this->assertEquals($chargebacks[0]->paymentId, 'tr_44aKxzEbr8'); - } - - public function test_payment_chargebacks_list_for_payment_chargeback_endpoint() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/chargebacks' - ), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "chargebacks": [ - { - "resource": "chargeback", - "id": "chb_n9z0tp", - "amount": { - "currency": "USD", - "value": "43.38" - }, - "settlementAmount": { - "currency": "EUR", - "value": "-35.07" - }, - "createdAt": "2018-03-14T17:00:52.0Z", - "reversedAt": null, - "paymentId": "tr_44aKxzEbr8", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-payment-chargeback", - "type": "text/html" - } - } - }, - { }, - { } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/chargebacks", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/chargebacks-api/list-payment-chargebacks", - "type": "text/html" - } - } - }' - ) - ); - $payment = $this->getPayment(); - - $chargebacks = $this->apiClient->paymentChargebacks->listFor($payment); - - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertEquals($chargebacks[0]->id, 'chb_n9z0tp'); - $this->assertEquals($chargebacks[0]->paymentId, 'tr_44aKxzEbr8'); - } - - protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount) - { - $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals('chargeback', $chargeback->resource); - $this->assertEquals($chargebackId, $chargeback->id); - - $this->assertAmountObject($amount, 'EUR', $chargeback->amount); - $this->assertAmountObject($amount, 'EUR', $chargeback->settlementAmount); - - $this->assertEquals('2018-03-28T11:44:32+00:00', $chargeback->createdAt); - $this->assertEquals($paymentId, $chargeback->paymentId); - - $this->assertLinkObject( - "https://api.mollie.com/v2/payments/{$paymentId}/chargebacks/{$chargebackId}", - 'application/hal+json', - $chargeback->_links->self - ); - - $this->assertLinkObject( - "https://api.mollie.com/v2/payments/{$paymentId}", - 'application/hal+json', - $chargeback->_links->payment - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback', - 'text/html', - $chargeback->_links->documentation - ); - } - - /** - * @return Payment - */ - protected function getPayment() - { - $paymentJson = '{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-19T12:17:57+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":"ideal", - "metadata":{ - "order_id":1234 - }, - "status":"paid", - "paidAt":"2018-03-19T12:18:35+00:00", - "amountRefunded":{ - "value":"0.00", - "currency":"EUR" - }, - "amountRemaining":{ - "value":"20.00", - "currency":"EUR" - }, - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412", - "consumerBic":"TESTNL99" - }, - "locale":"nl_NL", - "countryCode":"NL", - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "settlementAmount":{ - "value":"20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment", - "type":"text/html" - }, - "chargebacks":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks", - "type":"application/hal+json" - } - } - }'; - - return $this->copy(json_decode($paymentJson), new Payment($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php deleted file mode 100644 index 1a55a7365..000000000 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ /dev/null @@ -1,628 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/payments', - [], - '{ - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description": "My first API payment", - "redirectUrl": "https://example.org/redirect", - "webhookUrl": "https://example.org/webhook", - "metadata": { - "order_id": "1234" - } - }' - ), - new Response( - 201, - [], - '{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":null, - "metadata":{ - "order_id":"1234" - }, - "status":"open", - "isCancelable":false, - "expiresAt":"2018-03-13T14:17:29+00:00", - "details":null, - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "checkout":{ - "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8", - "type":"text/html" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/payments-api/create-payment", - "type":"text/html" - } - } - }' - ) - ); - - $payment = $this->apiClient->payments->create([ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '20.00', - ], - 'description' => 'My first API payment', - 'redirectUrl' => 'https://example.org/redirect', - 'webhookUrl' => 'https://example.org/webhook', - 'metadata' => [ - 'order_id' => '1234', - ], - ]); - - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('tr_44aKxzEbr8', $payment->id); - $this->assertEquals('test', $payment->mode); - $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $payment->amount); - - $this->assertEquals('My first API payment', $payment->description); - $this->assertNull($payment->method); - $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); - $this->assertEquals(PaymentStatus::OPEN, $payment->status); - $this->assertFalse($payment->isCancelable); - $this->assertEquals('2018-03-13T14:17:29+00:00', $payment->expiresAt); - $this->assertNull($payment->details); - $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); - $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); - $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $payment->_links->self); - - $checkoutLink = (object) ['href' => 'https://www.mollie.com/payscreen/select-method/44aKxzEbr8', 'type' => 'text/html']; - $this->assertEquals($checkoutLink, $payment->_links->checkout); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/create-payment', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $payment->_links->documentation); - } - - public function test_update_payment() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/payments/tr_7UhSN1zuXS', - [], - '{ - "description":"Order #98765", - "redirectUrl":"https://example.org/webshop/order/98765/", - "cancelUrl":"https://example.org/webshop/order/98765/canceled/", - "webhookUrl":"https://example.org/webshop/payments/webhook/", - "restrictPaymentMethodsToCountry": null, - "metadata":{ - "order_id":"98765" - }, - "dueDate":null, - "locale":null - }' - ), - new Response( - 200, - [], - '{ - "resource": "payment", - "id": "tr_7UhSN1zuXS", - "mode": "test", - "createdAt": "2018-03-20T09:13:37+00:00", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order #98765", - "method": null, - "metadata": { - "order_id": "98765" - }, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-20T09:28:37+00:00", - "details": null, - "profileId": "pfl_QkEhN94Ba", - "sequenceType": "oneoff", - "redirectUrl": "https://example.org/webshop/order/98765/", - "webhookUrl": "https://example.org/webshop/payments/webhook/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", - "type": "application/json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/payments-api/update-payment", - "type": "text/html" - } - } - }' - ) - ); - - // Get Payment stub - $payment = new Payment($this->apiClient); - $payment->id = 'tr_7UhSN1zuXS'; - $payment->_links = $this->createNamedLinkObject( - 'self', - 'https://api.mollie.com/v2/payments/tr_7UhSN1zuXS', - 'application/json' - ); - - // Modify fields - $payment->description = 'Order #98765'; - $payment->redirectUrl = 'https://example.org/webshop/order/98765/'; - $payment->webhookUrl = 'https://example.org/webshop/payments/webhook/'; - $payment->metadata = ['order_id' => '98765']; - $payment->cancelUrl = 'https://example.org/webshop/order/98765/canceled/'; - - $payment = $payment->update(); - - $this->assertEquals('payment', $payment->resource); - $this->assertEquals('tr_7UhSN1zuXS', $payment->id); - - $this->assertEquals('Order #98765', $payment->description); - $this->assertEquals('https://example.org/webshop/order/98765/', $payment->redirectUrl); - $this->assertEquals('https://example.org/webshop/payments/webhook/', $payment->webhookUrl); - $this->assertEquals((object) ['order_id' => '98765'], $payment->metadata); - $this->assertEquals('oneoff', $payment->sequenceType); - $this->assertEquals('pfl_QkEhN94Ba', $payment->profileId); - $this->assertNull($payment->details); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/payments/tr_7UhSN1zuXS', - 'application/json', - $payment->_links->self - ); - - $this->assertLinkObject( - 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', - 'text/html', - $payment->_links->checkout - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/payments-api/update-payment', - 'text/html', - $payment->_links->documentation - ); - } - - public function test_get_payment() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8?testmode=true', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":"ideal", - "metadata":{ - "order_id":"1234" - }, - "status":"paid", - "paidAt":"2018-03-19T12:18:35+00:00", - "amountRefunded":{ - "value":"0.00", - "currency":"EUR" - }, - "amountRemaining":{ - "value":"20.00", - "currency":"EUR" - }, - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412", - "consumerBic":"TESTNL99" - }, - "locale":"nl_NL", - "countryCode":"NL", - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "settlementAmount":{ - "value":"20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment", - "type":"text/html" - } - } - }' - ) - ); - - $payment = $this->apiClient->payments->get('tr_44aKxzEbr8', ['testmode' => true]); - - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('tr_44aKxzEbr8', $payment->id); - $this->assertEquals('test', $payment->mode); - $this->assertEquals('2018-03-13T14:02:29+00:00', $payment->createdAt); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $payment->amount); - - $this->assertEquals('My first API payment', $payment->description); - $this->assertEquals('ideal', $payment->method); - $this->assertEquals((object) ['order_id' => '1234'], $payment->metadata); - $this->assertEquals(PaymentStatus::PAID, $payment->status); - - $amountRefunded = new Stdclass; - $amountRefunded->value = '0.00'; - $amountRefunded->currency = 'EUR'; - $this->assertEquals($amountRefunded, $payment->amountRefunded); - - $amountRemaining = new Stdclass; - $amountRemaining->value = '20.00'; - $amountRemaining->currency = 'EUR'; - $this->assertEquals($amountRemaining, $payment->amountRemaining); - - $details = (object) [ - 'consumerName' => 'T. TEST', - 'consumerAccount' => 'NL17RABO0213698412', - 'consumerBic' => 'TESTNL99', - ]; - - $this->assertEquals($details, $payment->details); - $this->assertEquals('pfl_2A1gacu42V', $payment->profileId); - $this->assertEquals(SequenceType::ONEOFF, $payment->sequenceType); - $this->assertEquals('https://example.org/redirect', $payment->redirectUrl); - $this->assertEquals('https://example.org/webhook', $payment->webhookUrl); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $payment->_links->self); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/get-payment', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $payment->_links->documentation); - } - - public function test_list_payment() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments?limit=3', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_admNa2tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 1", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa", - "type": "text/html" - } - } - }, - { - "resource": "payment", - "id": "tr_bcaLc7hFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 2", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa", - "type": "text/html" - } - } - }, - { - "resource": "payment", - "id": "tr_pslHy1tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 3", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/payments-api/list-payments", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.com/v2/payments?limit=3", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3", - "type": "application/hal+json" - } - }, - "count": 3 - }' - ) - ); - - $payments = $this->apiClient->payments->page(null, 3); - - $this->assertInstanceOf(PaymentCollection::class, $payments); - $this->assertEquals(3, $payments->count()); - $this->assertEquals(3, count($payments)); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/payments-api/list-payments', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $payments->_links->documentation); - - $selfLink = (object) ['href' => 'http://api.mollie.com/v2/payments?limit=3', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $payments->_links->self); - - $this->assertNull($payments->_links->previous); - - $nextLink = (object) ['href' => 'http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3', 'type' => 'application/hal+json']; - $this->assertEquals($nextLink, $payments->_links->next); - } - - public function test_iterate_payment() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_admNa2tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 1", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa", - "type": "text/html" - } - } - }, - { - "resource": "payment", - "id": "tr_bcaLc7hFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 2", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa", - "type": "text/html" - } - } - }, - { - "resource": "payment", - "id": "tr_pslHy1tFfa", - "mode": "test", - "createdAt": "2018-03-19T15:00:50+00:00", - "amount": { - "value": "100.00", - "currency": "EUR" - }, - "description": "Payment no 3", - "method": null, - "metadata": null, - "status": "open", - "isCancelable": false, - "expiresAt": "2018-03-19T15:15:50+00:00", - "details": null, - "locale": "nl_NL", - "profileId": "pfl_7N5qjbu42V", - "sequenceType": "oneoff", - "redirectUrl": "https://www.example.org/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/payments-api/list-payments", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.com/v2/payments?limit=3", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 3 - }' - ) - ); - - foreach ($this->apiClient->payments->iterator() as $payment) { - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('payment', $payment->resource); - } - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php deleted file mode 100644 index 1c4d6fdf4..000000000 --- a/tests/Mollie/API/Endpoints/PaymentLinkEndpointTest.php +++ /dev/null @@ -1,353 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/payment-links', - [], - '' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "payment_links": [ - { - "resource": "payment-link", - "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", - "mode": "live", - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "archived": false, - "redirectUrl": "https://webshop.example.org/thanks", - "webhookUrl": "https://webshop.example.org/payment-links/webhook", - "profileId": "pfl_QkEhN94Ba", - "createdAt": "2021-03-20T09:29:56+00:00", - "expiresAt": "2023-06-06T11:00:00+00:00", - "_links": { - "self": { - "href": "...", - "type": "application/hal+json" - }, - "paymentLink": { - "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payment-links/", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/payment-links?from=pl_ayGNzD4TYuQtUaxNyu8aH&limit=5", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/list-payment-links", - "type": "text/html" - } - } - }' - ) - ); - - $paymentLinks = $this->apiClient->paymentLinks->page(); - $this->assertEquals(1, $paymentLinks->count()); - $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLinks[0]->id); - // No need to test all attributes as these are mapped dynamically. - } - - /** @test */ - public function test_iterate_payment_links() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payment-links', - [], - '' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "payment_links": [ - { - "resource": "payment-link", - "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", - "mode": "live", - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "archived": false, - "redirectUrl": "https://webshop.example.org/thanks", - "webhookUrl": "https://webshop.example.org/payment-links/webhook", - "profileId": "pfl_QkEhN94Ba", - "createdAt": "2021-03-20T09:29:56+00:00", - "expiresAt": "2023-06-06T11:00:00+00:00", - "_links": { - "self": { - "href": "...", - "type": "application/hal+json" - }, - "paymentLink": { - "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payment-links/", - "type": "application/hal+json" - }, - "previous": null, - "next": null, - "documentation": { - "href": "https://docs.mollie.com/reference/list-payment-links", - "type": "text/html" - } - } - }' - ) - ); - foreach ($this->apiClient->paymentLinks->iterator() as $paymentLink) { - $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals('payment-link', $paymentLink->resource); - // No need to test all attributes as these are mapped dynamically. - } - } - - /** @test */ - public function test_get_payment_link() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "payment-link", - "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", - "mode": "live", - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "archived": false, - "redirectUrl": "https://webshop.example.org/thanks", - "webhookUrl": "https://webshop.example.org/payment-links/webhook", - "profileId": "pfl_QkEhN94Ba", - "createdAt": "2021-03-20T09:29:56+00:00", - "expiresAt": "2023-06-06T11:00:00+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", - "type": "application/hal+json" - }, - "paymentLink": { - "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/get-payment-link", - "type": "text/html" - } - } - }' - ) - ); - - $paymentLink = $this->apiClient->paymentLinks->get('pl_4Y0eZitmBnQ6IDoMqZQKh', ['testmode' => true]); - $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals('payment-link', $paymentLink->resource); - $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLink->id); - // No need to test all attributes as these are mapped dynamically. - } - - /** @test */ - public function test_create_payment_link() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/payment-links', - [], - '{ - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "webhookUrl": "https://webshop.example.org/payment-links/webhook/", - "redirectUrl": "https://webshop.example.org/thanks", - "expiresAt": "2023-06-06T11:00:00+00:00" - }' - ), - new Response( - 201, - [], - '{ - "resource": "payment-link", - "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", - "mode": "live", - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "archived": false, - "redirectUrl": "https://webshop.example.org/thanks", - "webhookUrl": "https://webshop.example.org/payment-links/webhook", - "profileId": "pfl_QkEhN94Ba", - "createdAt": "2021-03-20T09:29:56+00:00", - "expiresAt": "2023-06-06T11:00:00+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", - "type": "application/hal+json" - }, - "paymentLink": { - "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/create-payment-link", - "type": "text/html" - } - } - }' - ) - ); - - $paymentLink = $this->apiClient->paymentLinks->create([ - 'description' => 'Bicycle tires', - 'amount' => [ - 'currency' => 'EUR', - 'value' => '24.95', - ], - 'webhookUrl' => 'https://webshop.example.org/payment-links/webhook/', - 'redirectUrl' => 'https://webshop.example.org/thanks', - 'expiresAt' => '2023-06-06T11:00:00+00:00', - ]); - - $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals('payment-link', $paymentLink->resource); - $this->assertEquals('pl_4Y0eZitmBnQ6IDoMqZQKh', $paymentLink->id); - // No need to test all attributes as these are mapped dynamically. - } - - /** @test */ - public function test_update_payment_link() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh', - [], - '{ - "description":"Bicycle tires", - "archived": true - }' - ), - new Response( - 200, - [], - '{ - "resource": "payment-link", - "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", - "mode": "live", - "description": "Bicycle tires", - "amount": { - "currency": "EUR", - "value": "24.95" - }, - "archived": true, - "redirectUrl": "https://webshop.example.org/thanks", - "webhookUrl": "https://webshop.example.org/payment-links/webhook", - "profileId": "pfl_QkEhN94Ba", - "createdAt": "2021-03-20T09:29:56+00:00", - "expiresAt": "2023-06-06T11:00:00+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh?testmode=true", - "type": "application/hal+json" - }, - "paymentLink": { - "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", - "type": "text/html" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/update-payment-link", - "type": "text/html" - } - } - }' - ) - ); - - $paymentLink = $this->apiClient->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', [ - 'description' => 'Bicycle tires', - 'archived' => true, - ]); - - $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $paymentLink->resource = 'payment-link'; - $paymentLink->id = 'pl_4Y0eZitmBnQ6IDoMqZQKh'; - $paymentLink->archived = true; - // No need to test all attributes as these are mapped dynamically. - } - - /** @test */ - public function test_delete_payment_link() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh' - ), - new Response( - 204, - [], - null - ) - ); - - $this->apiClient->paymentLinks->delete('pl_4Y0eZitmBnQ6IDoMqZQKh'); - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php deleted file mode 100644 index d2555d9a7..000000000 --- a/tests/Mollie/API/Endpoints/PaymentLinkPaymentEndpointTest.php +++ /dev/null @@ -1,90 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_7UhSN1zuXS", - "mode": "live", - "status": "open", - "isCancelable": false, - "amount": { - "value": "75.00", - "currency": "GBP" - }, - "description": "Order #12345", - "method": "ideal", - "metadata": null, - "details": null, - "profileId": "pfl_QkEhN94Ba", - "redirectUrl": "https://webshop.example.org/order/12345/", - "createdAt": "2024-02-12T11:58:35.0Z", - "expiresAt": "2024-02-12T12:13:35.0Z", - "_links": { - "self": { - "href": "...", - "type": "application/hal+json" - }, - "checkout": { - "href": "https://www.mollie.com/checkout/issuer/select/ideal/7UhSN1zuXS", - "type": "text/html" - }, - "dashboard": { - "href": "https://www.mollie.com/dashboard/org_12345678/payments/tr_7UhSN1zuXS", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "self": { - "href": "...", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments?from=tr_SDkzMggpvx&limit=5", - "type": "application/hal+json" - }, - "documentation": { - "href": "...", - "type": "text/html" - } - } - }' - ) - ); - - $response = $this->apiClient->paymentLinkPayments->pageForId('pl_4Y0eZitmBnQ6IDoMqZQKh'); - - $this->assertInstanceOf(PaymentCollection::class, $response); - $this->assertInstanceOf(Payment::class, $response[0]); - $this->assertEquals($response[0]->id, 'tr_7UhSN1zuXS'); - // Not necessary to test all fields... - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php deleted file mode 100644 index 24da25e00..000000000 --- a/tests/Mollie/API/Endpoints/PaymentRefundEndpointTest.php +++ /dev/null @@ -1,601 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm' - ), - new Response( - 200, - [], - '{ - "resource":"refund", - "id":"re_PsAvxvLsnm", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "status":"pending", - "createdAt":"2018-03-19T12:33:37+00:00", - "description":"My first API payment", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/refunds-api/get-refund", - "type":"text/html" - } - } - }' - ) - ); - - $refund = $this->apiClient->paymentRefunds->getFor($this->getPayment(), 're_PsAvxvLsnm'); - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_PsAvxvLsnm', $refund->id); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->amount); - - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); - $this->assertEquals('My first API payment', $refund->description); - $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - - $amount = new Stdclass; - $amount->value = '-20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->settlementAmount); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/get-refund', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $refund->_links->documentation); - } - - public function test_create_refund_for_payment_resource() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/payments/tr_44aKxzEbr8/refunds' - ), - new Response( - 201, - [], - '{ - "resource": "refund", - "id": "re_4qqhO89gsT", - "amount": { - "currency": "EUR", - "value": "20.00" - }, - "status": "pending", - "createdAt": "2018-03-14T17:09:02.0Z", - "description": "Order #33", - "metadata": { - "bookkeeping_id": 12345 - }, - "paymentId": "tr_WDqYK6vllg", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund", - "type": "text/html" - } - } - }' - ) - ); - $payment = $this->getPayment(); - $refundData = [ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '20.00', - ], - ]; - $refund = $this->apiClient->paymentRefunds->createFor($payment, $refundData); - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_4qqhO89gsT', $refund->id); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->amount); - - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-14T17:09:02.0Z', $refund->createdAt); - $this->assertEquals('Order #33', $refund->description); - $this->assertEquals('tr_WDqYK6vllg', $refund->paymentId); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $refund->_links->documentation); - } - - public function test_get_refund_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/refunds/re_PsAvxvLsnm' - ), - new Response( - 201, - [], - '{ - "resource":"refund", - "id":"re_PsAvxvLsnm", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "status":"pending", - "createdAt":"2018-03-19T12:33:37+00:00", - "description":"My first API payment", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/refunds-api/create-refund", - "type":"text/html" - } - } - }' - ) - ); - - $refund = $this->getPayment()->getRefund('re_PsAvxvLsnm'); - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_PsAvxvLsnm', $refund->id); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->amount); - - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); - $this->assertEquals('My first API payment', $refund->description); - $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - - $amount = new Stdclass; - $amount->value = '-20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->settlementAmount); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-refund', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $refund->_links->documentation); - } - - public function test_create_refund() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/payments/tr_44aKxzEbr8/refunds', - [], - '{"amount":{"currency":"EUR","value":"20.00"}}' - ), - new Response( - 201, - [], - '{ - "resource":"refund", - "id":"re_PsAvxvLsnm", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "status":"pending", - "createdAt":"2018-03-19T12:33:37+00:00", - "description":"My first API payment", - "paymentId":"tr_44aKxzEbr8", - "settlementAmount":{ - "value":"-20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm", - "type":"application/hal+json" - }, - "payment":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/refunds-api/create-refund", - "type":"text/html" - } - } - }' - ) - ); - - $refund = $this->getPayment()->refund([ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '20.00', - ], - ]); - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_PsAvxvLsnm', $refund->id); - - $amount = new Stdclass; - $amount->value = '20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->amount); - - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-19T12:33:37+00:00', $refund->createdAt); - $this->assertEquals('My first API payment', $refund->description); - $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - - $amount = new Stdclass; - $amount->value = '-20.00'; - $amount->currency = 'EUR'; - $this->assertEquals($amount, $refund->settlementAmount); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_Tgxm3amJBT/refunds/re_PmEtpvSsnm', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/refunds-api/create-refund', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $refund->_links->documentation); - } - - public function test_get_refunds_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/refunds', - [], - '' - ), - new Response( - 201, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_haCsig5aru", - "amount": { - "value": "2.00", - "currency": "EUR" - }, - "status": "pending", - "createdAt": "2018-03-28T10:56:10+00:00", - "description": "My first API payment", - "paymentId": "tr_44aKxzEbr8", - "settlementAmount": { - "value": "-2.00", - "currency": "EUR" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.nl/v2/payments/tr_44aKxzEbr8/refunds?limit=10", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 1 - }' - ) - ); - - $refunds = $this->getPayment()->refunds(); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count()); - $this->assertCount(1, $refunds); - - $refund = $refunds[0]; - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_haCsig5aru', $refund->id); - $this->assertEquals('2.00', $refund->amount->value); - $this->assertEquals('EUR', $refund->amount->currency); - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-28T10:56:10+00:00', $refund->createdAt); - $this->assertEquals('My first API payment', $refund->description); - $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - $this->assertEquals('-2.00', $refund->settlementAmount->value); - $this->assertEquals('EUR', $refund->settlementAmount->currency); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - } - - public function test_list_refunds_on_payment_resource() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/payments/tr_44aKxzEbr8/refunds', - [], - '' - ), - new Response( - 201, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_b63hJyxbap", - "amount": { - "value": "1.00", - "currency": "EUR" - }, - "createdAt": "2021-01-17T20:57:40+00:00", - "description": "Order #1610620820", - "paymentId": "tr_4NydwvhQDd", - "orderId": null, - "lines": null, - "settlementAmount": { - "value": "-1.00", - "currency": "EUR" - }, - "status": "refunded", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds/re_b63hJyxbap", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_4NydwvhQDd", - "type": "application/hal+json" - } - }, - "metadata": null - }, - { - "resource": "refund", - "id": "re_SpBqRM9rcn", - "amount": { - "value": "2.00", - "currency": "EUR" - }, - "createdAt": "2021-01-17T20:26:10+00:00", - "description": "test", - "paymentId": "tr_4NydwvhQDd", - "orderId": null, - "lines": null, - "settlementAmount": { - "value": "-2.00", - "currency": "EUR" - }, - "status": "refunded", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds/re_SpBqRM9rcn", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_4NydwvhQDd", - "type": "application/hal+json" - } - }, - "metadata": null - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 2 - }' - ) - ); - - $refunds = $this->getPayment()->listRefunds(); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - - /** @var RefundCollection $refunds */ - $this->assertEquals(2, $refunds->count()); - $this->assertCount(2, $refunds); - - $refund = $refunds[0]; - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_b63hJyxbap', $refund->id); - $this->assertEquals('1.00', $refund->amount->value); - $this->assertEquals('EUR', $refund->amount->currency); - $this->assertEquals('refunded', $refund->status); - $this->assertEquals('2021-01-17T20:57:40+00:00', $refund->createdAt); - $this->assertEquals('Order #1610620820', $refund->description); - $this->assertEquals('tr_4NydwvhQDd', $refund->paymentId); - $this->assertEquals('-1.00', $refund->settlementAmount->value); - $this->assertEquals('EUR', $refund->settlementAmount->currency); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_4NydwvhQDd/refunds/re_b63hJyxbap', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_4NydwvhQDd', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - } - - public function test_cancel_refund_for_payment() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/payments/tr_44aKxzEbr8/refunds/re_4qqhO89gsT', - [], - '{"testmode":true}' - ), - new Response(204) - ); - - $response = $this->apiClient->paymentRefunds->cancelForPayment( - $this->getPayment(), - 're_4qqhO89gsT', - ['testmode' => true] - ); - - $this->assertNull($response); - } - - /** - * @return Payment - */ - private function getPayment() - { - $paymentJson = '{ - "resource":"payment", - "id":"tr_44aKxzEbr8", - "mode":"test", - "createdAt":"2018-03-19T12:17:57+00:00", - "amount":{ - "value":"20.00", - "currency":"EUR" - }, - "description":"My first API payment", - "method":"ideal", - "metadata":{ - "order_id":1234 - }, - "status":"paid", - "paidAt":"2018-03-19T12:18:35+00:00", - "amountRefunded":{ - "value":"0.00", - "currency":"EUR" - }, - "amountRemaining":{ - "value":"20.00", - "currency":"EUR" - }, - "details":{ - "consumerName":"T. TEST", - "consumerAccount":"NL17RABO0213698412", - "consumerBic":"TESTNL99" - }, - "locale":"nl_NL", - "countryCode":"NL", - "profileId":"pfl_2A1gacu42V", - "sequenceType":"oneoff", - "redirectUrl":"https://example.org/redirect", - "webhookUrl":"https://example.org/webhook", - "settlementAmount":{ - "value":"20.00", - "currency":"EUR" - }, - "_links":{ - "self":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type":"application/hal+json" - }, - "documentation":{ - "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment", - "type":"text/html" - }, - "refunds":{ - "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds", - "type":"application/hal+json" - } - } - }'; - - return $this->copy(json_decode($paymentJson), new Payment($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php deleted file mode 100644 index 523799347..000000000 --- a/tests/Mollie/API/Endpoints/PaymentRouteEndpointTest.php +++ /dev/null @@ -1,49 +0,0 @@ -mockApiCall( - new Request( - 'PATCH', - '/v2/payments/tr_2qkhcMzypH/routes/rt_9dk4al1n', - [], - '{ - "releaseDate": "2021-09-14", - "testmode": false - }' - ), - new Response( - 201, - [], - '{ - "resource": "route", - "id": "rt_9dk4al1n", - "createdAt": "2021-08-28T14:02:29+00:00", - "amount": { - "value": "7.50", - "currency": "EUR" - }, - "destination": { - "type": "organization", - "organizationId": "org_23456" - }, - "releaseDate": "2021-09-14" - }' - ) - ); - - $route = $this->apiClient->paymentRoutes->updateReleaseDateForPaymentId('tr_2qkhcMzypH', 'rt_9dk4al1n', '2021-09-14'); - - $this->assertInstanceOf(Route::class, $route); - $this->assertEquals('rt_9dk4al1n', $route->id); - $this->assertEquals('2021-09-14', $route->releaseDate); - } -} diff --git a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php b/tests/Mollie/API/Endpoints/PermissionEndpointTest.php deleted file mode 100644 index 1ac8296d2..000000000 --- a/tests/Mollie/API/Endpoints/PermissionEndpointTest.php +++ /dev/null @@ -1,169 +0,0 @@ -mockApiCall( - new Request('GET', '/v2/permissions/'.$permissionId), - new Response( - 200, - [], - '{ - "resource": "permission", - "id": "'.$permissionId.'", - "description": "Some dummy permission description", - "granted": true, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/permissions/'.$permissionId.'", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission", - "type": "text/html" - } - } - }' - ) - ); - - $permission = $this->apiClient->permissions->get($permissionId); - - $this->assertPermission($permission, $permissionId); - } - - public function dpTestGetPermissionIds() - { - return [ - ['payments.read'], - ['payments.write'], - ['refunds.read'], - ['refunds.write'], - ['customers.read'], - ['customers.write'], - ['mandates.read'], - ['mandates.write'], - ['subscriptions.read'], - ['subscriptions.write'], - ['profiles.read'], - ['profiles.write'], - ['invoices.read'], - ['invoices.write'], - ['settlements.read'], - ['settlements.write'], - ['orders.read'], - ['orders.write'], - ['organizations.read'], - ['organizations.write'], - ]; - } - - protected function assertPermission($permission, $permissionId) - { - $this->assertInstanceOf(Permission::class, $permission); - $this->assertEquals('permission', $permission->resource); - $this->assertEquals($permissionId, $permission->id); - $this->assertEquals( - 'Some dummy permission description', - $permission->description - ); - $this->assertTrue($permission->granted); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/permissions/'.$permissionId, - 'application/hal+json', - $permission->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/permissions-api/get-permission', - 'text/html', - $permission->_links->documentation - ); - } - - public function test_list_permissions() - { - $this->mockApiCall( - new Request('GET', '/v2/permissions'), - new Response( - 200, - [], - '{ - "_embedded": { - "permissions": [ - { - "resource": "permission", - "id": "payments.write", - "description": "Some dummy permission description", - "granted": true, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/permissions/payments.write", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission", - "type": "text/html" - } - } - }, - { - "resource": "permission", - "id": "payments.read", - "description": "Some dummy permission description", - "granted": true, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/permissions/payments.read", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/permissions-api/get-permission", - "type": "text/html" - } - } - } - ] - }, - "count": 2, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/permissions-api/list-permissions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/permissions", - "type": "application/hal+json" - } - } - }' - ) - ); - - $permissions = $this->apiClient->permissions->all(); - - $this->assertInstanceOf(PermissionCollection::class, $permissions); - - $this->assertCount(2, $permissions); - - $this->assertPermission($permissions[0], 'payments.write'); - $this->assertPermission($permissions[1], 'payments.read'); - } -} diff --git a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileEndpointTest.php deleted file mode 100644 index 5a65f4120..000000000 --- a/tests/Mollie/API/Endpoints/ProfileEndpointTest.php +++ /dev/null @@ -1,500 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/profiles/pfl_ahe8z8OPut', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->apiClient->profiles->get('pfl_ahe8z8OPut'); - - $this->assertInstanceOf(Profile::class, $profile); - $this->assertEquals('pfl_ahe8z8OPut', $profile->id); - $this->assertEquals('live', $profile->mode); - $this->assertEquals('My website name', $profile->name); - $this->assertEquals('http://www.mywebsite.com', $profile->website); - $this->assertEquals('info@mywebsite.com', $profile->email); - $this->assertEquals('31123456789', $profile->phone); - $this->assertEquals(5399, $profile->categoryCode); - $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); - $this->assertEquals((object) ['status' => 'pending'], $profile->review); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $profile->_links->self); - - $chargebacksLink = (object) ['href' => 'https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($chargebacksLink, $profile->_links->chargebacks); - - $methodsLink = (object) ['href' => 'https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($methodsLink, $profile->_links->methods); - - $paymentsLink = (object) ['href' => 'https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($paymentsLink, $profile->_links->payments); - - $refundsLink = (object) ['href' => 'https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($refundsLink, $profile->_links->refunds); - - $checkoutPreviewLink = (object) ['href' => 'https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut', 'type' => 'text/html']; - $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl); - } - - public function test_get_profile_using_me() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/profiles/me', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->apiClient->profiles->get('me'); - - $this->assertInstanceOf(CurrentProfile::class, $profile); - $this->assertEquals('pfl_ahe8z8OPut', $profile->id); - - // No need to test it all again... - } - - public function test_get_current_profile() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/profiles/me', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->apiClient->profiles->getCurrent(); - - $this->assertInstanceOf(CurrentProfile::class, $profile); - $this->assertEquals('pfl_ahe8z8OPut', $profile->id); - $this->assertEquals('live', $profile->mode); - $this->assertEquals('My website name', $profile->name); - $this->assertEquals('http://www.mywebsite.com', $profile->website); - $this->assertEquals('info@mywebsite.com', $profile->email); - $this->assertEquals('31123456789', $profile->phone); - $this->assertEquals(5399, $profile->categoryCode); - $this->assertEquals(ProfileStatus::VERIFIED, $profile->status); - $this->assertEquals((object) ['status' => 'pending'], $profile->review); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $profile->_links->self); - - $chargebacksLink = (object) ['href' => 'https://api.mollie.com/v2/chargebacks', 'type' => 'application/hal+json']; - $this->assertEquals($chargebacksLink, $profile->_links->chargebacks); - - $methodsLink = (object) ['href' => 'https://api.mollie.com/v2/methods', 'type' => 'application/hal+json']; - $this->assertEquals($methodsLink, $profile->_links->methods); - - $paymentsLink = (object) ['href' => 'https://api.mollie.com/v2/payments', 'type' => 'application/hal+json']; - $this->assertEquals($paymentsLink, $profile->_links->payments); - - $refundsLink = (object) ['href' => 'https://api.mollie.com/v2/refunds', 'type' => 'application/hal+json']; - $this->assertEquals($refundsLink, $profile->_links->refunds); - - $checkoutPreviewLink = (object) ['href' => 'https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut', 'type' => 'text/html']; - $this->assertEquals($checkoutPreviewLink, $profile->_links->checkoutPreviewUrl); - } - - public function test_list_profiles() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/profiles', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "profiles": [{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }, - { - "resource": "profile", - "id": "pfl_znNaTRkJs5", - "mode": "live", - "name": "My website name 2", - "website": "http://www.mywebsite2.com", - "email": "info@mywebsite2.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_znNaTRkJs5", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_znNaTRkJs5", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_znNaTRkJs5", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_znNaTRkJs5", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_znNaTRkJs5", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_znNaTRkJs5", - "type": "text/html" - } - } - } - ] - }, - "count": 2, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/profiles-api/list-profiles", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.nl/v2/profiles?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $profiles = $this->apiClient->profiles->page(); - $this->assertInstanceOf(ProfileCollection::class, $profiles); - $this->assertEquals(2, $profiles->count()); - - foreach ($profiles as $profile) { - $this->assertInstanceOf(Profile::class, $profile); - } - - $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/profiles?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $profiles->_links->self); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/profiles-api/list-profiles', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $profiles->_links->documentation); - } - - public function test_update_profile() - { - $expectedWebsiteName = 'Mollie'; - $expectedEmail = 'mollie@mollie.com'; - $expectedPhone = '31123456766'; - - $this->mockApiCall( - new Request('PATCH', '/v2/profiles/pfl_ahe8z8OPut'), - new Response( - 200, - [], - '{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "'.$expectedWebsiteName.'", - "website": "http://www.mywebsite.com", - "email": "'.$expectedEmail.'", - "phone": "'.$expectedPhone.'", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->getProfile(); - $profile->name = $expectedWebsiteName; - $profile->email = $expectedEmail; - $profile->phone = $expectedPhone; - - $updatedProfile = $profile->update(); - - $this->assertEquals($expectedWebsiteName, $updatedProfile->name); - $this->assertEquals($expectedEmail, $updatedProfile->email); - $this->assertEquals($expectedPhone, $updatedProfile->phone); - } - - /** - * @return Profile - */ - private function getProfile() - { - $json = '{ - "resource": "profile", - "id": "pfl_ahe8z8OPut", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_ahe8z8OPut", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_ahe8z8OPut", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($json), new Profile($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php b/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php deleted file mode 100644 index b35c96432..000000000 --- a/tests/Mollie/API/Endpoints/ProfileMethodEndpointTest.php +++ /dev/null @@ -1,230 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact' - ), - new Response( - 201, - [], - '{ - "resource": "method", - "id": "bancontact", - "description": "Bancontact", - "image": { - "size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png", - "size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png", - "svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/bancontact", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/profiles-api/activate-method", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->getProfile(); - $method = $profile->enableMethod('bancontact'); - - $this->assertInstanceOf(Method::class, $method); - $this->assertEquals('bancontact', $method->id); - $this->assertEquals('Bancontact', $method->description); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.png', $method->image->size1x); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png', $method->image->size2x); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/bancontact', - 'application/hal+json', - $method->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/profiles-api/activate-method', - 'text/html', - $method->_links->documentation - ); - } - - public function test_disable_profile_method() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/profiles/pfl_v9hTwCvYqw/methods/bancontact' - ), - new Response(204) - ); - - $profile = $this->getProfile(); - $result = $profile->disableMethod('bancontact'); - - $this->assertNull($result); - } - - public function test_enable_current_profile_method() - { - $this->mockApiCall( - new Request( - 'POST', - '/v2/profiles/me/methods/bancontact' - ), - new Response( - 201, - [], - '{ - "resource": "method", - "id": "bancontact", - "description": "Bancontact", - "image": { - "size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png", - "size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png", - "svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/methods/bancontact", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/profiles-api/activate-method", - "type": "text/html" - } - } - }' - ) - ); - - $profile = $this->getCurrentProfile(); - $method = $profile->enableMethod('bancontact'); - - $this->assertInstanceOf(Method::class, $method); - $this->assertEquals('bancontact', $method->id); - $this->assertEquals('Bancontact', $method->description); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.png', $method->image->size1x); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png', $method->image->size2x); - $this->assertEquals('https://www.mollie.com/external/icons/payment-methods/bancontact.svg', $method->image->svg); - - $this->assertLinkObject( - 'https://api.mollie.com/v2/methods/bancontact', - 'application/hal+json', - $method->_links->self - ); - - $this->assertLinkObject( - 'https://docs.mollie.com/reference/v2/profiles-api/activate-method', - 'text/html', - $method->_links->documentation - ); - } - - public function test_disable_current_profile_method() - { - $this->mockApiCall( - new Request( - 'DELETE', - '/v2/profiles/me/methods/bancontact' - ), - new Response(204) - ); - - $profile = $this->getCurrentProfile(); - - $result = $profile->disableMethod('bancontact'); - - $this->assertNull($result); - } - - /** - * @return CurrentProfile - */ - private function getCurrentProfile() - { - return $this->copy( - json_decode($this->getProfileFixture()), - new CurrentProfile($this->apiClient) - ); - } - - /** - * @return Profile - */ - private function getProfile() - { - return $this->copy( - json_decode($this->getProfileFixture()), - new Profile($this->apiClient) - ); - } - - /** - * @return string - */ - private function getProfileFixture() - { - return '{ - "resource": "profile", - "id": "pfl_v9hTwCvYqw", - "mode": "live", - "name": "My website name", - "website": "http://www.mywebsite.com", - "email": "info@mywebsite.com", - "phone": "31123456789", - "categoryCode": 5399, - "status": "verified", - "review": { - "status": "pending" - }, - "createdAt": "2016-01-11T13:03:55+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/profiles/pfl_v9hTwCvYqw", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/chargebacks?profileId=pfl_v9hTwCvYqw", - "type": "application/hal+json" - }, - "methods": { - "href": "https://api.mollie.com/v2/methods?profileId=pfl_v9hTwCvYqw", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/payments?profileId=pfl_v9hTwCvYqw", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/refunds?profileId=pfl_v9hTwCvYqw", - "type": "application/hal+json" - }, - "checkoutPreviewUrl": { - "href": "https://www.mollie.com/payscreen/preview/pfl_v9hTwCvYqw", - "type": "text/html" - } - } - }'; - } -} diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php deleted file mode 100644 index 4ff055ba0..000000000 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ /dev/null @@ -1,163 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/refunds', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_haCsig5aru", - "amount": { - "value": "2.00", - "currency": "EUR" - }, - "status": "pending", - "createdAt": "2018-03-28T10:56:10+00:00", - "description": "My first API payment", - "paymentId": "tr_44aKxzEbr8", - "settlementAmount": { - "value": "-2.00", - "currency": "EUR" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.nl/v2/refunds?limit=10", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 1 - }' - ) - ); - - $refunds = $this->apiClient->refunds->page(); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertEquals(1, $refunds->count()); - $this->assertCount(1, $refunds); - - $refund = $refunds[0]; - - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_haCsig5aru', $refund->id); - $this->assertEquals('2.00', $refund->amount->value); - $this->assertEquals('EUR', $refund->amount->currency); - $this->assertEquals('pending', $refund->status); - $this->assertEquals('2018-03-28T10:56:10+00:00', $refund->createdAt); - $this->assertEquals('My first API payment', $refund->description); - $this->assertEquals('tr_44aKxzEbr8', $refund->paymentId); - $this->assertEquals('-2.00', $refund->settlementAmount->value); - $this->assertEquals('EUR', $refund->settlementAmount->currency); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $refund->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $refund->_links->payment); - } - - public function test_iterate_refunds() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/refunds', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_haCsig5aru", - "amount": { - "value": "2.00", - "currency": "EUR" - }, - "status": "pending", - "createdAt": "2018-03-28T10:56:10+00:00", - "description": "My first API payment", - "paymentId": "tr_44aKxzEbr8", - "settlementAmount": { - "value": "-2.00", - "currency": "EUR" - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds", - "type": "text/html" - }, - "self": { - "href": "http://api.mollie.nl/v2/refunds?limit=10", - "type": "application/hal+json" - }, - "previous": null, - "next": null - }, - "count": 1 - }' - ) - ); - - foreach ($this->apiClient->refunds->iterator() as $refund) { - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('refund', $refund->resource); - } - } -} diff --git a/tests/Mollie/API/Endpoints/SessionEndpointTest.php b/tests/Mollie/API/Endpoints/SessionEndpointTest.php deleted file mode 100644 index 7724475d2..000000000 --- a/tests/Mollie/API/Endpoints/SessionEndpointTest.php +++ /dev/null @@ -1,361 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/sessions', - [], - '{ - "paymentData": { - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order #12345" - }, - "method": "paypal", - "methodDetails": { - "checkoutFlow": "express" - }, - "returnUrl": "https://example.org/redirect", - "cancelUrl": "https://example.org/cancel" - }' - ), - new Response( - 201, - [], - $this->getSessionResponseFixture('sess_pbjz8x') - ) - ); - - $session = $this->apiClient->sessions->create([ - 'paymentData' => [ - 'amount' => [ - 'value' => '10.00', - 'currency' => 'EUR', - ], - 'description' => 'Order #12345', - ], - 'method' => 'paypal', - 'methodDetails' => [ - 'checkoutFlow' => 'express', - ], - 'returnUrl' => 'https://example.org/redirect', - 'cancelUrl' => 'https://example.org/cancel', - ]); - - $this->assertSession($session, 'sess_pbjz8x'); - } - - public function test_get_session() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/sessions/sess_pbjz8x' - ), - new Response( - 200, - [], - $this->getSessionResponseFixture('sess_pbjz8x') - ) - ); - - $session = $this->apiClient->sessions->get('sess_pbjz8x'); - - $this->assertSession($session, 'sess_pbjz8x'); - } - - public function test_list_sessions() - { - $this->mockApiCall( - new Request('GET', '/v2/sessions'), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "sessions": [ - '.$this->getSessionResponseFixture('sess_pbjz1x').', - '.$this->getSessionResponseFixture('sess_pbjz2y').', - '.$this->getSessionResponseFixture('sess_pbjz3z').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/sessions", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/sessions?from=sess_stTC2WHAuS", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/sessions-api/list-sessions", - "type": "text/html" - } - } - }' - ) - ); - - $sessions = $this->apiClient->sessions->page(); - - $this->assertInstanceOf(SessionCollection::class, $sessions); - $this->assertEquals(3, $sessions->count); - $this->assertEquals(3, count($sessions)); - - $this->assertNull($sessions->_links->previous); - $selfLink = $this->createLinkObject( - 'https://api.mollie.com/v2/sessions', - 'application/hal+json' - ); - $this->assertEquals($selfLink, $sessions->_links->self); - - $nextLink = $this->createLinkObject( - 'https://api.mollie.com/v2/sessions?from=sess_stTC2WHAuS', - 'application/hal+json' - ); - $this->assertEquals($nextLink, $sessions->_links->next); - - $documentationLink = $this->createLinkObject( - 'https://docs.mollie.com/reference/v2/sessions-api/list-sessions', - 'text/html' - ); - $this->assertEquals($documentationLink, $sessions->_links->documentation); - - $this->assertSession($sessions[0], 'sess_pbjz1x'); - $this->assertSession($sessions[1], 'sess_pbjz2y'); - $this->assertSession($sessions[2], 'sess_pbjz3z'); - } - - public function test_iterate_sessions() - { - $this->mockApiCall( - new Request('GET', '/v2/sessions'), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "sessions": [ - '.$this->getSessionResponseFixture('sess_pbjz1x').', - '.$this->getSessionResponseFixture('sess_pbjz2y').', - '.$this->getSessionResponseFixture('sess_pbjz3z').' - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/sessions", - "type": "application/hal+json" - }, - "previous": null, - "next": null, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/sessions-api/list-sessions", - "type": "text/html" - } - } - }' - ) - ); - - foreach ($this->apiClient->sessions->iterator() as $session) { - $this->assertInstanceOf(Session::class, $session); - } - } - - public function test_cancel_session() - { - $this->mockApiCall( - new Request('DELETE', '/v2/sessions/sess_pbjz1x'), - new Response( - 200, - [], - $this->getSessionResponseFixture( - 'sess_pbjz1x', - SessionStatus::STATUS_FAILED - ) - ) - ); - $session = $this->apiClient->sessions->cancel('sess_pbjz1x'); - $this->assertSession($session, 'sess_pbjz1x', SessionStatus::STATUS_FAILED); - } - - /** @test */ - public function test_update_session() - { - $this->mockApiCall( - new Request( - 'PATCH', - '/v2/sessions/sess_pbjz8x', - [], - '{ - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1234AB", - "city": "Amsterdam", - "country": "NL", - "givenName": "Piet", - "familyName": "Mondriaan", - "email": "piet@mondriaan.com", - "region": "Noord-Holland", - "title": "Dhr", - "phone": "+31208202070" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - } - }' - ), - new Response( - 200, - [], - $this->getSessionResponseFixture( - 'sess_pbjz8x', - SessionStatus::STATUS_CREATED - ) - ) - ); - - $sessionJSON = $this->getSessionResponseFixture('sess_pbjz8x'); - - /** @var Session $session */ - $session = $this->copy(json_decode($sessionJSON), new Session($this->apiClient)); - - $session->billingAddress->organizationName = 'Organization Name LTD.'; - $session->billingAddress->streetAndNumber = 'Keizersgracht 313'; - $session->billingAddress->city = 'Amsterdam'; - $session->billingAddress->region = 'Noord-Holland'; - $session->billingAddress->postalCode = '1234AB'; - $session->billingAddress->country = 'NL'; - $session->billingAddress->title = 'Dhr'; - $session->billingAddress->givenName = 'Piet'; - $session->billingAddress->familyName = 'Mondriaan'; - $session->billingAddress->email = 'piet@mondriaan.com'; - $session->billingAddress->phone = '+31208202070'; - $session = $session->update(); - - $this->assertSession($session, 'sess_pbjz8x', SessionStatus::STATUS_CREATED); - } - - protected function assertSession($session, $session_id, $sessionStatus = SessionStatus::STATUS_CREATED) - { - $this->assertInstanceOf(Session::class, $session); - $this->assertEquals('session', $session->resource); - $this->assertEquals($session_id, $session->id); - $this->assertEquals('paypal', $session->method); - - $this->assertAmountObject('10.00', 'EUR', $session->amount); - - $this->assertEquals($sessionStatus, $session->status); - - $this->assertEquals('https://example.org/redirect', $session->getRedirectUrl()); - /** - * @todo check how the links will be returned - */ - // $this->assertEquals("https://example.org/cancel", $session->cancelUrl); - - $links = (object) [ - 'self' => $this->createLinkObject( - 'https://api.mollie.com/v2/sessions/'.$session_id, - 'application/hal+json' - ), - 'redirect' => $this->createLinkObject( - 'https://example.org/redirect', - 'application/hal+json' - ), - ]; - $this->assertEquals($links, $session->_links); - } - - protected function getSessionResponseFixture($session_id, $sessionStatus = SessionStatus::STATUS_CREATED) - { - return str_replace( - [ - '<>', - '<>', - ], - [ - $session_id, - $sessionStatus, - ], - '{ - "resource": "session", - "id": "<>", - "status": "<>", - "amount": { - "value": 10.00, - "currency": "EUR" - }, - "description": "Order #12345", - "method": "paypal", - "methodDetails": { - "checkoutFlow":"express" - }, - "billingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1234AB", - "city": "Amsterdam", - "country": "NL", - "givenName": "Piet", - "familyName": "Mondriaan", - "email": "piet@mondriaan.com", - "region": "Noord-Holland", - "title": "Dhr", - "phone": "+31208202070" - }, - "shippingAddress": { - "organizationName": "Organization Name LTD.", - "streetAndNumber": "Keizersgracht 313", - "postalCode": "1016 EE", - "city": "Amsterdam", - "country": "nl", - "givenName": "Luke", - "familyName": "Skywalker", - "email": "luke@skywalker.com" - }, - "nextAction": "redirect", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/sessions/<>", - "type": "application/hal+json" - }, - "redirect": { - "href": "https://example.org/redirect", - "type": "application/hal+json" - } - } - }' - ); - } -} diff --git a/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php deleted file mode 100644 index 2467867ea..000000000 --- a/tests/Mollie/API/Endpoints/SettlementCaptureEndpointTest.php +++ /dev/null @@ -1,99 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_jDk30akdN/captures?limit=5&foo=bar' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "captures": [ - { - "resource": "capture", - "id": "cpt_4qqhO89gsT", - "mode": "live", - "amount": { - "value": "1027.99", - "currency": "EUR" - }, - "settlementAmount": { - "value": "399.00", - "currency": "EUR" - }, - "paymentId": "tr_WDqYK6vllg", - "shipmentId": "shp_3wmsgCJN4U", - "settlementId": "stl_jDk30akdN", - "createdAt": "2018-08-02T09:29:56+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "shipment": { - "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture", - "type": "text/html" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-captures", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/captures?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $settlement = new Settlement($this->apiClient); - $settlement->id = 'stl_jDk30akdN'; - - $captures = $settlement->captures(5, ['foo' => 'bar']); - - $this->assertInstanceOf(CaptureCollection::class, $captures); - $this->assertCount(1, $captures); - - $capture = $captures[0]; - $this->assertInstanceOf(Capture::class, $capture); - $this->assertEquals('cpt_4qqhO89gsT', $capture->id); - } -} diff --git a/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php deleted file mode 100644 index d3bf612cd..000000000 --- a/tests/Mollie/API/Endpoints/SettlementChargebackEndpointTest.php +++ /dev/null @@ -1,89 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_jDk30akdN/chargebacks?limit=5&foo=bar' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "chargebacks": [ - { - "resource": "chargeback", - "id": "chb_n9z0tp", - "amount": { - "value": "43.38", - "currency": "USD" - }, - "settlementAmount": { - "value": "-37.14", - "currency": "EUR" - }, - "createdAt": "2018-03-14T17:00:52.0Z", - "reversedAt": null, - "paymentId": "tr_WDqYK6vllg", - "settlementId": "stl_jDk30akdN", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-chargebacks", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/chargebacks", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $settlement = new Settlement($this->apiClient); - $settlement->id = 'stl_jDk30akdN'; - - $chargebacks = $settlement->chargebacks(5, ['foo' => 'bar']); - - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertCount(1, $chargebacks); - - $chargeback = $chargebacks[0]; - $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals('chb_n9z0tp', $chargeback->id); - } -} diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php deleted file mode 100644 index c08b26f30..000000000 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ /dev/null @@ -1,654 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_xcaSGAHuRt', - [], - '' - ), - new Response( - 200, - [], - '{ - "resource": "settlement", - "id": "stl_xcaSGAHuRt", - "reference": "1234567.1234.12", - "createdAt": "2018-04-30T04:00:02+00:00", - "settledAt": "2018-05-01T04:00:02+00:00", - "status": "pending", - "amount": { - "value": "1980.98", - "currency": "EUR" - }, - "periods": { - "2018": { - "04": { - "revenue": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - }, - { - "description": "iDEAL", - "method": "ideal", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - } - ], - "costs": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.00", - "currency": "EUR" - }, - "percentage": "1.80" - }, - "amountNet": { - "value": "14.22", - "currency": "EUR" - }, - "amountVat": { - "value": "2.9862", - "currency": "EUR" - }, - "amountGross": { - "value": "17.2062", - "currency": "EUR" - } - }, - { - "description": "Fixed creditcard costs", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Fixed iDEAL costs", - "method": "ideal", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Refunds iDEAL", - "method": "refund", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - } - ] - } - } - }, - "invoiceId": "inv_VseyTUhJSy", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/get-settlement", - "type": "text/html" - } - } - }' - ) - ); - - /** @var Settlement $settlement */ - $settlement = $this->apiClient->settlements->get('stl_xcaSGAHuRt'); - - $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals('settlement', $settlement->resource); - $this->assertEquals('stl_xcaSGAHuRt', $settlement->id); - $this->assertEquals('1234567.1234.12', $settlement->reference); - $this->assertEquals('2018-04-30T04:00:02+00:00', $settlement->createdAt); - $this->assertEquals('2018-05-01T04:00:02+00:00', $settlement->settledAt); - $this->assertEquals(SettlementStatus::PENDING, $settlement->status); - $this->assertEquals((object) ['value' => '1980.98', 'currency' => 'EUR'], $settlement->amount); - $this->assertNotEmpty($settlement->periods); - $this->assertEquals('inv_VseyTUhJSy', $settlement->invoiceId); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $settlement->_links->self); - - $paymentLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments', 'type' => 'application/hal+json']; - $this->assertEquals($paymentLink, $settlement->_links->payments); - - $refundLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds', 'type' => 'application/hal+json']; - $this->assertEquals($refundLink, $settlement->_links->refunds); - - $chargebackLink = (object) ['href' => 'https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks', 'type' => 'application/hal+json']; - $this->assertEquals($chargebackLink, $settlement->_links->chargebacks); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/settlements-api/get-settlement', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $settlement->_links->documentation); - } - - public function test_list_settlement() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/settlements', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "settlements": [ - { - "resource": "settlement", - "id": "stl_xcaSGAHuRt", - "reference": "1234567.1234.12", - "createdAt": "2018-04-30T04:00:02+00:00", - "settledAt": "2018-05-01T04:00:02+00:00", - "status": "pending", - "amount": { - "value": "1980.98", - "currency": "EUR" - }, - "periods": { - "2018": { - "04": { - "revenue": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - }, - { - "description": "iDEAL", - "method": "ideal", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - } - ], - "costs": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.00", - "currency": "EUR" - }, - "percentage": "1.80" - }, - "amountNet": { - "value": "14.22", - "currency": "EUR" - }, - "amountVat": { - "value": "2.9862", - "currency": "EUR" - }, - "amountGross": { - "value": "17.2062", - "currency": "EUR" - } - }, - { - "description": "Fixed creditcard costs", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Fixed iDEAL costs", - "method": "ideal", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Refunds iDEAL", - "method": "refund", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - } - ] - } - } - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlements", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.nl/v2/settlements", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs", - "type": "application/hal+json" - } - } - }' - ) - ); - - /** @var SettlementCollection $settlements */ - $settlements = $this->apiClient->settlements->page(); - $this->assertInstanceOf(SettlementCollection::class, $settlements); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/settlements-api/list-settlements', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $settlements->_links->documentation); - - $selfLink = (object) ['href' => 'https://api.mollie.nl/v2/settlements', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $settlements->_links->self); - - $this->assertEmpty($settlements->_links->previous); - - $nextLink = (object) ['href' => 'https://api.mollie.nl/v2/settlements?from=stl_xcaSGAHuRt&limit=1&previous=stl_xcaPACKpLs', 'type' => 'application/hal+json']; - $this->assertEquals($nextLink, $settlements->_links->next); - - foreach ($settlements as $settlement) { - $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals('settlement', $settlement->resource); - $this->assertNotEmpty($settlement->periods); - } - } - - public function test_iterate_settlement() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/settlements', - [], - '' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "settlements": [ - { - "resource": "settlement", - "id": "stl_xcaSGAHuRt", - "reference": "1234567.1234.12", - "createdAt": "2018-04-30T04:00:02+00:00", - "settledAt": "2018-05-01T04:00:02+00:00", - "status": "pending", - "amount": { - "value": "1980.98", - "currency": "EUR" - }, - "periods": { - "2018": { - "04": { - "revenue": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - }, - { - "description": "iDEAL", - "method": "ideal", - "count": 2, - "amountNet": { - "value": "790.00", - "currency": "EUR" - }, - "amountVat": null, - "amountGross": { - "value": "1000.00", - "currency": "EUR" - } - } - ], - "costs": [ - { - "description": "Creditcard", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.00", - "currency": "EUR" - }, - "percentage": "1.80" - }, - "amountNet": { - "value": "14.22", - "currency": "EUR" - }, - "amountVat": { - "value": "2.9862", - "currency": "EUR" - }, - "amountGross": { - "value": "17.2062", - "currency": "EUR" - } - }, - { - "description": "Fixed creditcard costs", - "method": "creditcard", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Fixed iDEAL costs", - "method": "ideal", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - }, - { - "description": "Refunds iDEAL", - "method": "refund", - "count": 2, - "rate": { - "fixed": { - "value": "0.25", - "currency": "EUR" - }, - "percentage": "0" - }, - "amountNet": { - "value": "0.50", - "currency": "EUR" - }, - "amountVat": { - "value": "0.105", - "currency": "EUR" - }, - "amountGross": { - "value": "0.605", - "currency": "EUR" - } - } - ] - } - } - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt", - "type": "application/hal+json" - }, - "payments": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments", - "type": "application/hal+json" - }, - "refunds": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds", - "type": "application/hal+json" - }, - "chargebacks": { - "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks", - "type": "application/hal+json" - } - } - } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlements", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.nl/v2/settlements", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - foreach ($this->apiClient->settlements->iterator() as $settlement) { - $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals('settlement', $settlement->resource); - $this->assertNotEmpty($settlement->periods); - } - } -} diff --git a/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php deleted file mode 100644 index 5add3e5ec..000000000 --- a/tests/Mollie/API/Endpoints/SettlementPaymentsEndpointTest.php +++ /dev/null @@ -1,90 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_jDk30akdN/payments?limit=5&foo=bar' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_7UhSN1zuXS", - "mode": "test", - "createdAt": "2018-02-12T11:58:35.0Z", - "expiresAt": "2018-02-12T12:13:35.0Z", - "status": "open", - "isCancelable": false, - "amount": { - "value": "75.00", - "currency": "GBP" - }, - "description": "Order #12345", - "method": "ideal", - "metadata": null, - "details": null, - "profileId": "pfl_QkEhN94Ba", - "settlementId": "stl_jDk30akdN", - "redirectUrl": "https://webshop.example.org/order/12345/", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/payments?limit=5", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/payments?from=tr_SDkzMggpvx&limit=5", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-payments", - "type": "text/html" - } - } - }' - ) - ); - - $settlement = new Settlement($this->apiClient); - $settlement->id = 'stl_jDk30akdN'; - - $payments = $settlement->payments(5, ['foo' => 'bar']); - - $this->assertInstanceOf(PaymentCollection::class, $payments); - $this->assertCount(1, $payments); - - $payment = $payments[0]; - $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('tr_7UhSN1zuXS', $payment->id); - } -} diff --git a/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php deleted file mode 100644 index 482829b0a..000000000 --- a/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php +++ /dev/null @@ -1,92 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_jDk30akdN/refunds?limit=5&foo=bar' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_3aKhkUNigy", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "status": "refunded", - "createdAt": "2018-08-30T07:59:02+00:00", - "description": "Order #33", - "paymentId": "tr_maJaG2j8OM", - "settlementAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "settlementId": "stl_jDk30akdN", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM/refunds/re_3aKhkUNigy", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - } - } - }, - { } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-refunds", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/refunds?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $settlement = new Settlement($this->apiClient); - $settlement->id = 'stl_jDk30akdN'; - - $refunds = $settlement->refunds(5, ['foo' => 'bar']); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertCount(2, $refunds); - - $refund = $refunds[0]; - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('re_3aKhkUNigy', $refund->id); - } -} diff --git a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php deleted file mode 100644 index 64c121c90..000000000 --- a/tests/Mollie/API/Endpoints/SubscriptionEndpointTest.php +++ /dev/null @@ -1,554 +0,0 @@ -mockApiCall( - new Request('POST', '/v2/customers/cst_FhQJRw4s2n/subscriptions'), - new Response( - 200, - [], - '{ - "resource": "subscription", - "id": "sub_wByQa6efm6", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "active", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var Subscription $subscription */ - $subscription = $customer->createSubscription([ - 'amount' => [ - 'value' => '10.00', - 'currency' => 'EUR', - ], - 'interval' => '1 month', - 'description' => 'Order 1234', - ]); - - $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); - $this->assertEquals('sub_wByQa6efm6', $subscription->id); - $this->assertEquals('test', $subscription->mode); - $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); - $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); - $this->assertEquals((object) ['value' => '10.00', 'currency' => 'EUR'], $subscription->amount); - $this->assertEquals('Order 1234', $subscription->description); - $this->assertNull($subscription->method); - $this->assertNull($subscription->times); - $this->assertEquals('1 month', $subscription->interval); - $this->assertEquals('2018-04-24', $subscription->startDate); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $subscription->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $subscription->_links->customer); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $subscription->_links->documentation); - } - - public function test_get_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'), - new Response( - 200, - [], - '{ - "resource": "subscription", - "id": "sub_wByQa6efm6", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "active", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var Subscription $subscription */ - $subscription = $customer->getSubscription('sub_wByQa6efm6'); - - $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); - $this->assertEquals('sub_wByQa6efm6', $subscription->id); - $this->assertEquals('test', $subscription->mode); - $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); - $this->assertEquals(SubscriptionStatus::ACTIVE, $subscription->status); - $this->assertEquals((object) ['value' => '10.00', 'currency' => 'EUR'], $subscription->amount); - $this->assertEquals('Order 1234', $subscription->description); - $this->assertNull($subscription->method); - $this->assertNull($subscription->times); - $this->assertEquals('1 month', $subscription->interval); - $this->assertEquals('2018-04-24', $subscription->startDate); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $subscription->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $subscription->_links->customer); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $subscription->_links->documentation); - } - - public function test_list_works() - { - $this->mockApiCall( - new Request('GET', '/v2/customers/cst_FhQJRw4s2n/subscriptions'), - new Response( - 200, - [], - '{ - "_embedded": { - "subscriptions": [{ - "resource": "subscription", - "id": "sub_wByQa6efm6", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "active", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - }] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $customer = $this->getCustomer(); - - $subscriptions = $customer->subscriptions(); - - $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); - - $this->assertEquals(count($subscriptions), $subscriptions->count()); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $subscriptions->_links->documentation); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions?limit=50', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $subscriptions->_links->self); - - foreach ($subscriptions as $subscription) { - $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); - $this->assertNotEmpty($subscription->createdAt); - } - } - - public function test_cancel_via_customer_resource_works() - { - $this->mockApiCall( - new Request('DELETE', '/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6'), - new Response( - 200, - [], - '{ - "resource": "subscription", - "id": "sub_wByQa6efm6", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "canceled", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "canceledAt": "2018-04-24T12:31:32+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", - "type": "text/html" - } - } - }' - ) - ); - - $customer = $this->getCustomer(); - - /** @var Subscription $subscription */ - $subscription = $customer->cancelSubscription('sub_wByQa6efm6'); - - $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); - $this->assertEquals('sub_wByQa6efm6', $subscription->id); - $this->assertEquals('test', $subscription->mode); - $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); - $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); - $this->assertEquals('2018-04-24T12:31:32+00:00', $subscription->canceledAt); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $subscription->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_FhQJRw4s2n', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $subscription->_links->customer); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $subscription->_links->documentation); - } - - public function test_cancel_on_subscription_resource_works($value = '') - { - $this->mockApiCall( - new Request('DELETE', '/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx'), - new Response( - 200, - [], - '{ - "resource": "subscription", - "id": "sub_DRjwaT5qHx", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "canceled", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "canceledAt": "2018-04-24T12:31:32+00:00", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_VhjQebNW5j", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription", - "type": "text/html" - } - } - }' - ) - ); - - $subscription = $this->getSubscription(); - - $subscription = $subscription->cancel(); - - $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); - $this->assertEquals('sub_DRjwaT5qHx', $subscription->id); - $this->assertEquals('test', $subscription->mode); - $this->assertEquals(SubscriptionStatus::CANCELED, $subscription->status); - $this->assertEquals('2018-04-24T11:41:55+00:00', $subscription->createdAt); - $this->assertEquals('2018-04-24T12:31:32+00:00', $subscription->canceledAt); - - $selfLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx', 'type' => 'application/hal+json']; - $this->assertEquals($selfLink, $subscription->_links->self); - - $customerLink = (object) ['href' => 'https://api.mollie.com/v2/customers/cst_VhjQebNW5j', 'type' => 'application/hal+json']; - $this->assertEquals($customerLink, $subscription->_links->customer); - - $documentationLink = (object) ['href' => 'https://docs.mollie.com/reference/v2/subscriptions-api/cancel-subscription', 'type' => 'text/html']; - $this->assertEquals($documentationLink, $subscription->_links->documentation); - } - - public function test_that_update_subscription_works() - { - $expectedAmountValue = '12.00'; - $expectedAmountCurrency = 'EUR'; - $expectedStartDate = '2018-12-12'; - - $this->mockApiCall( - new Request('PATCH', '/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx'), - new Response( - 200, - [], - '{ - "resource": "subscription", - "id": "sub_DRjwaT5qHx", - "customerId": "cst_VhjQebNW5j", - "mode": "live", - "createdAt": "2018-07-17T07:45:52+00:00", - "status": "active", - "amount": { - "value": "'.$expectedAmountValue.'", - "currency": "'.$expectedAmountCurrency.'" - }, - "description": "Mollie Recurring subscription #1", - "method": null, - "times": 42, - "interval": "15 days", - "startDate": "'.$expectedStartDate.'", - "webhookUrl": "https://example.org/webhook", - "_links": { - "self": { - "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx", - "type": "application/hal+json" - }, - "customer": { - "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/update-subscription", - "type": "text/html" - } - } - }' - ) - ); - - $subscription = $this->getSubscription(); - $expectedAmountObject = (object) [ - 'value' => $expectedAmountValue, - 'currency' => $expectedAmountCurrency, - ]; - $subscription->amount = $expectedAmountObject; - $subscription->startDate = $expectedStartDate; - - $updatedSubscription = $subscription->update(); - - $this->assertEquals($expectedStartDate, $updatedSubscription->startDate); - $this->assertEquals($expectedAmountObject, $updatedSubscription->amount); - } - - public function test_list_page_of_root_subscriptions_works() - { - $this->mockApiCall( - new Request('GET', '/v2/subscriptions'), - new Response( - 200, - [], - '{ - "_embedded": { - "subscriptions": [{ - "resource": "subscription", - "id": "sub_wByQa6efm6", - "mode": "test", - "createdAt": "2018-04-24T11:41:55+00:00", - "status": "active", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Order 1234", - "method": null, - "times": null, - "interval": "1 month", - "startDate": "2018-04-24", - "webhookUrl": null, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n/subscriptions/sub_wByQa6efm6", - "type": "application/hal+json" - }, - "customer": { - "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", - "type": "application/hal+json" - } - } - }] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/subscriptions?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $subscriptions = $this->apiClient->subscriptions->page(); - - $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); - $this->assertCount(1, $subscriptions); - $subscription = $subscriptions[0]; - - $this->assertEquals('subscription', $subscription->resource); - $this->assertEquals('sub_wByQa6efm6', $subscription->id); - // No need to test all attributes here ... - } - - /** - * @return Subscription - */ - private function getSubscription() - { - $subscriptionJson = '{ - "resource": "subscription", - "id": "sub_DRjwaT5qHx", - "customerId": "cst_VhjQebNW5j", - "mode": "live", - "createdAt": "2018-07-17T07:45:52+00:00", - "status": "active", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "description": "Mollie Recurring subscription #1", - "method": null, - "times": 42, - "interval": "15 days", - "startDate": "2018-12-12", - "webhookUrl": "https://example.org/webhook", - "_links": { - "self": { - "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j/subscriptions/sub_DRjwaT5qHx", - "type": "application/hal+json" - }, - "customer": { - "href": "http://api.mollie.test/v2/customers/cst_VhjQebNW5j", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/subscriptions-api/update-subscription", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($subscriptionJson), new Subscription($this->apiClient)); - } - - /** - * @return Customer - */ - private function getCustomer() - { - $customerJson = '{ - "resource": "customer", - "id": "cst_FhQJRw4s2n", - "mode": "test", - "name": "John Doe", - "email": "johndoe@example.org", - "locale": null, - "metadata": null, - "recentlyUsedMethods": [], - "createdAt": "2018-04-19T08:49:01+00:00", - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", - "type": "text/html" - } - } - }'; - - return $this->copy(json_decode($customerJson), new Customer($this->apiClient)); - } -} diff --git a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php deleted file mode 100644 index d3a39c06b..000000000 --- a/tests/Mollie/API/Endpoints/SubscriptionPaymentEndpointTest.php +++ /dev/null @@ -1,86 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/customers/cst_stTC2WHAuS/subscriptions/sub_8JfGzs6v3K/payments?limit=25' - ), - new Response( - 200, - [], - '{ - "count": 1, - "_embedded": { - "payments": [ - { - "resource": "payment", - "id": "tr_7UhSN1zuXS", - "mode": "live", - "amount": { - "currency": "EUR", - "value": "25.00" - }, - "description": "Quarterly payment", - "method": "creditcard", - "sequenceType": "recurring", - "status": "paid", - "isCancelable": false, - "webhookUrl": "https://webshop.example.org/payments/webhook", - "profileId": "pfl_QkEhN94Ba", - "customerId": "cst_stTC2WHAuS", - "mandateId": "mdt_38HS4fsS", - "createdAt": "2023-09-01T03:58:35.0Z", - "paidAt": "2023-09-01T04:02:01.0Z", - "_links": { - "self": { - "href": "...", - "type": "application/hal+json" - }, - "dashboard": { - "href": "https://www.mollie.com/dashboard/org_12345678/payments/tr_7UhSN1zuXS", - "type": "text/html" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/customers/cst_stTC2WHAuS/subscriptions/sub_8JfGzs6v3K/payments?limit=25", - "type": "application/hal+json" - }, - "previous": null, - "next": null, - "documentation": { - "href": "https://docs.mollie.com/reference/list-subscription-payments", - "type": "text/html" - } - } - }' - ) - ); - - $response = $this->apiClient->subscriptionPayments->pageForIds( - 'cst_stTC2WHAuS', - 'sub_8JfGzs6v3K', - null, - 25 - ); - - $this->assertInstanceOf(PaymentCollection::class, $response); - } -} diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php deleted file mode 100644 index 0823cf23e..000000000 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ /dev/null @@ -1,298 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/terminals/term_7MgL4wea46qkRcoTZjWEH?testmode=true', - [], - '' - ), - new Response( - 200, - [], - '{ - "id": "term_7MgL4wea46qkRcoTZjWEH", - "profileId": "pfl_QkEhN94Ba", - "status": "active", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567890", - "currency": "EUR", - "description": "Terminal #12345", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-12T11:58:35.0Z", - "updatedAt": "2022-11-15T13:32:11+00:00", - "activatedAt": "2022-02-12T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/terminals-api/get-terminal", - "type": "text/html" - } - } - }' - ) - ); - - $terminal = $this->apiClient->terminals->get('term_7MgL4wea46qkRcoTZjWEH', ['testmode' => true]); - - $this->assertInstanceOf(Terminal::class, $terminal); - $this->assertEquals('term_7MgL4wea46qkRcoTZjWEH', $terminal->id); - $this->assertEquals('pfl_QkEhN94Ba', $terminal->profileId); - $this->assertEquals(TerminalStatus::ACTIVE, $terminal->status); - $this->assertEquals('PAX', $terminal->brand); - $this->assertEquals('A920', $terminal->model); - $this->assertEquals('1234567890', $terminal->serialNumber); - $this->assertEquals('EUR', $terminal->currency); - $this->assertEquals('Terminal #12345', $terminal->description); - $this->assertEquals('GMT +08:00', $terminal->timezone); - $this->assertEquals('nl_NL', $terminal->locale); - $this->assertEquals('2022-02-12T11:58:35.0Z', $terminal->createdAt); - $this->assertEquals('2022-11-15T13:32:11+00:00', $terminal->updatedAt); - $this->assertEquals('2022-02-12T12:13:35.0Z', $terminal->activatedAt); - - $this->assertLinkObject('https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH', 'application/hal+json', $terminal->_links->self); - $this->assertLinkObject('https://docs.mollie.com/reference/v2/terminals-api/get-terminal', 'text/html', $terminal->_links->documentation); - } - - public function test_list_terminal() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/terminals?limit=3', - [], - '' - ), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "terminals": [ - { - "id": "term_7MgL4wea46qkRcoTZjWEH", - "resource": "terminal", - "profileId": "pfl_QkEhN94Ba", - "status": "active", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567890", - "currency": "EUR", - "description": "Terminal #12345", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-12T11:58:35.0Z", - "updatedAt": "2022-11-15T13:32:11+00:00", - "activatedAt": "2022-02-12T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", - "type": "application/hal+json" - } - } - }, - { - "id": "term_7MgL4wea46qkRcoTZjWEG", - "resource": "terminal", - "profileId": "pfl_QkEhN94Bb", - "status": "pending", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567891", - "currency": "EUR", - "description": "Terminal #12346", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-13T11:58:35.0Z", - "updatedAt": "2022-11-16T13:32:11+00:00", - "activatedAt": "2022-02-13T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEG", - "type": "application/hal+json" - } - } - }, - { - "id": "term_7MgL4wea46qkRcoTZjWEI", - "resource": "terminal", - "profileId": "pfl_QkEhN94Bc", - "status": "inactive", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567892", - "currency": "EUR", - "description": "Terminal #12347", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-14T11:58:35.0Z", - "updatedAt": "2022-11-17T13:32:11+00:00", - "activatedAt": "2022-02-14T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEI", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals?limit=3", - "type": "application/hal+json" - }, - "previous": null, - "next": { - "href": "https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH&limit=3", - "type": "application/hal+json" - }, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals", - "type": "text/html" - } - } - }' - ) - ); - - $terminals = $this->apiClient->terminals->page(null, 3); - - $this->assertInstanceOf(TerminalCollection::class, $terminals); - $this->assertEquals(3, $terminals->count()); - $this->assertEquals(3, count($terminals)); - - $this->assertLinkObject('https://docs.mollie.com/reference/v2/terminals-api/list-terminals', 'text/html', $terminals->_links->documentation); - $this->assertLinkObject('https://api.mollie.com/v2/terminals?limit=3', 'application/hal+json', $terminals->_links->self); - $this->assertLinkObject('https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH&limit=3', 'application/hal+json', $terminals->_links->next); - - $this->assertNull($terminals->_links->previous); - } - - public function test_iterate_terminal() - { - $this->mockApiCall( - new Request( - 'GET', - '/v2/terminals', - [], - '' - ), - new Response( - 200, - [], - '{ - "count": 3, - "_embedded": { - "terminals": [ - { - "id": "term_7MgL4wea46qkRcoTZjWEH", - "resource": "terminal", - "profileId": "pfl_QkEhN94Ba", - "status": "active", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567890", - "currency": "EUR", - "description": "Terminal #12345", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-12T11:58:35.0Z", - "updatedAt": "2022-11-15T13:32:11+00:00", - "activatedAt": "2022-02-12T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", - "type": "application/hal+json" - } - } - }, - { - "id": "term_7MgL4wea46qkRcoTZjWEG", - "resource": "terminal", - "profileId": "pfl_QkEhN94Bb", - "status": "pending", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567891", - "currency": "EUR", - "description": "Terminal #12346", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-13T11:58:35.0Z", - "updatedAt": "2022-11-16T13:32:11+00:00", - "activatedAt": "2022-02-13T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEG", - "type": "application/hal+json" - } - } - }, - { - "id": "term_7MgL4wea46qkRcoTZjWEI", - "resource": "terminal", - "profileId": "pfl_QkEhN94Bc", - "status": "inactive", - "brand": "PAX", - "model": "A920", - "serialNumber": "1234567892", - "currency": "EUR", - "description": "Terminal #12347", - "timezone": "GMT +08:00", - "locale": "nl_NL", - "createdAt": "2022-02-14T11:58:35.0Z", - "updatedAt": "2022-11-17T13:32:11+00:00", - "activatedAt": "2022-02-14T12:13:35.0Z", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEI", - "type": "application/hal+json" - } - } - } - ] - }, - "_links": { - "self": { - "href": "https://api.mollie.com/v2/terminals", - "type": "application/hal+json" - }, - "previous": null, - "next": null, - "documentation": { - "href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals", - "type": "text/html" - } - } - }' - ) - ); - - foreach ($this->apiClient->terminals->iterator() as $terminal) { - $this->assertInstanceOf(Terminal::class, $terminal); - $this->assertEquals('terminal', $terminal->resource); - } - } -} diff --git a/tests/Mollie/API/Endpoints/WalletEndpointTest.php b/tests/Mollie/API/Endpoints/WalletEndpointTest.php deleted file mode 100644 index ad14f3b47..000000000 --- a/tests/Mollie/API/Endpoints/WalletEndpointTest.php +++ /dev/null @@ -1,55 +0,0 @@ -mockApiCall( - new Request( - 'POST', - '/v2/wallets/applepay/sessions', - [], - '{ - "domain": "pay.mywebshop.com", - "validationUrl": "https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession", - "profileId": "pfl_xH2kP6Nc6X" - }' - ), - new Response( - 201, - [], - $responseBody - ) - ); - - $domain = 'pay.mywebshop.com'; - $validationUrl = 'https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession'; - - $response = $this->apiClient->wallets->requestApplePayPaymentSession( - $domain, - $validationUrl, - ['profileId' => 'pfl_xH2kP6Nc6X'] - ); - - $this->assertJsonStringEqualsJsonString( - $responseBody, - $response - ); - } -} diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index a3ac8955c..b9dc92782 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -12,19 +12,20 @@ use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; -use Mollie\Api\Http\Requests\DynamicDeleteRequest; -use Mollie\Api\Http\Requests\DynamicGetRequest; +use Tests\Fixtures\Requests\DynamicDeleteRequest; +use Tests\Fixtures\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response as HttpResponse; use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; class MollieApiClientTest extends TestCase { - public function test_send_returns_body_as_object() + /** @test */ + public function send_returns_body_as_object() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), @@ -38,7 +39,8 @@ public function test_send_returns_body_as_object() ); } - public function test_send_creates_api_exception_correctly() + /** @test */ + public function send_creates_api_exception_correctly() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); @@ -52,7 +54,7 @@ public function test_send_creates_api_exception_correctly() $client->send(new DynamicGetRequest('')); } catch (ApiException $e) { $this->assertEquals('recurringType', $e->getField()); - $this->assertEquals('https://docs.mollie.com/guides/handling-errors', $e->getDocumentationUrl()); + $this->assertNotEmpty($e->getDocumentationUrl()); $mockResponse->assertResponseBodyEquals($e->getResponse()); @@ -60,7 +62,8 @@ public function test_send_creates_api_exception_correctly() } } - public function test_send_creates_api_exception_without_field_and_documentation_url() + /** @test */ + public function send_creates_api_exception_without_field_and_documentation_url() { $this->expectException(ApiException::class); $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); @@ -81,7 +84,8 @@ public function test_send_creates_api_exception_without_field_and_documentation_ } } - public function test_can_be_serialized_and_unserialized() + /** @test */ + public function can_be_serialized_and_unserialized() { $client = new MollieApiClient($this->createMock(Client::class)); @@ -104,7 +108,8 @@ public function test_can_be_serialized_and_unserialized() // no need to assert them all. } - public function test_enabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() + /** @test */ + public function enabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() { $this->expectException(HttpAdapterDoesNotSupportDebuggingException::class); $client = new MollieApiClient(new CurlMollieHttpAdapter); @@ -112,7 +117,8 @@ public function test_enabling_debugging_throws_an_exception_if_http_adapter_does $client->enableDebugging(); } - public function test_disabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() + /** @test */ + public function disabling_debugging_throws_an_exception_if_http_adapter_does_not_support_it() { $this->expectException(HttpAdapterDoesNotSupportDebuggingException::class); $client = new MollieApiClient(new CurlMollieHttpAdapter); @@ -126,7 +132,8 @@ public function test_disabling_debugging_throws_an_exception_if_http_adapter_doe * * @throws ApiException */ - public function test_correct_request_headers() + /** @test */ + public function correct_request_headers() { $client = new MockClient([ CreatePaymentRequest::class => new MockResponse(200, '{"resource": "payment"}'), @@ -139,7 +146,7 @@ public function test_correct_request_headers() new Money('EUR', '100.00'), ))); - $usedHeaders = $response->getResponse()->getPendingRequest()->headers()->all(); + $usedHeaders = $response->getPendingRequest()->headers()->all(); // these change through environments // just make sure its existing @@ -160,7 +167,8 @@ public function test_correct_request_headers() * @throws \Mollie\Api\Exceptions\IncompatiblePlatform * @throws \Mollie\Api\Exceptions\UnrecognizedClientException */ - public function test_no_content_type_without_provided_body() + /** @test */ + public function no_content_type_without_provided_body() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(204, ''), @@ -173,7 +181,7 @@ public function test_no_content_type_without_provided_body() } /** @test */ - public function no_idempotency_is_set_on_if_no_key_nor_generator_are_set() + public function no_idempotency_is_set_if_no_key_nor_generator_are_set() { $client = new MockClient([ DynamicDeleteRequest::class => new MockResponse(204, ''), @@ -229,7 +237,8 @@ public static function providesMutatingRequests(): array ]; } - public function test_idempotency_key_is_not_used_on_get_requests() + /** @test */ + public function idempotency_key_is_not_used_on_get_requests() { $client = new MockClient([ DynamicGetRequest::class => new MockResponse(204), @@ -242,7 +251,8 @@ public function test_idempotency_key_is_not_used_on_get_requests() $this->assertFalse($response->getPendingRequest()->headers()->has(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); } - public function test_idempotency_key_resets_after_each_request() + /** @test */ + public function idempotency_key_resets_after_each_request() { $client = new MockClient([ DynamicDeleteRequest::class => new MockResponse(204), @@ -257,7 +267,8 @@ public function test_idempotency_key_resets_after_each_request() $this->assertNull($client->getIdempotencyKey()); } - public function test_it_uses_the_idempotency_key_generator() + /** @test */ + public function it_uses_the_idempotency_key_generator() { $client = new MockClient([ DynamicDeleteRequest::class => new MockResponse(204), @@ -275,4 +286,51 @@ public function test_it_uses_the_idempotency_key_generator() $this->assertEquals('fake-idempotency-key', $response->getPendingRequest()->headers()->get(ApplyIdempotencyKey::IDEMPOTENCY_KEY_HEADER)); $this->assertNull($client->getIdempotencyKey()); } + + /** @test */ + public function testmode_is_added_to_request_when_enabled() + { + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), + ]); + + $client->test(true); + + $response = $client->send(new DynamicGetRequest('')); + + $this->assertTrue($response->getPendingRequest()->query()->has('testmode')); + $this->assertTrue($response->getPendingRequest()->query()->get('testmode')); + } + + /** @test */ + public function testmode_is_removed_when_using_api_key_authentication() + { + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), + ]); + + $client->setApiKey('test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); + $client->test(true); + + $response = $client->send(new DynamicGetRequest('')); + + $this->assertFalse($response->getPendingRequest()->query()->has('testmode')); + } + + /** @test */ + public function testmode_is_not_removed_when_not_using_api_key_authentication() + { + $client = new MockClient([ + DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), + ]); + + // Not setting an API key, so using default authentication + // by default we use access token authentication in tests + $client->test(true); + + $response = $client->send(new DynamicGetRequest('')); + + $this->assertTrue($response->getPendingRequest()->query()->has('testmode')); + $this->assertTrue($response->getPendingRequest()->query()->get('testmode')); + } } diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index d29993a96..1c32eee50 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -5,7 +5,7 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; use stdClass; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -13,11 +13,18 @@ class CursorCollectionTest extends TestCase { + protected function setUp(): void + { + parent::setUp(); + + MockClient::shouldAutoHydrate(); + } + /** @test */ public function can_get_next_collection_result_when_next_link_is_available() { $client = new MockClient([ - DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'tr_stTC2WHAuS'), + DynamicGetRequest::class => new MockResponse(200, 'cursor-collection'), ]); $collection = new PaymentCollection( @@ -25,7 +32,7 @@ public function can_get_next_collection_result_when_next_link_is_available() [], $this->arrayToObject([ 'next' => [ - 'href' => 'https://api.mollie.com/v2/payments?from=tr_stTC2WHAuS', + 'href' => 'https://api.mollie.com/v2/payments?from=tr_*', ], ]) ); @@ -34,8 +41,6 @@ public function can_get_next_collection_result_when_next_link_is_available() $nextPage = $collection->next(); - $this->assertEquals('tr_stTC2WHAuS', $nextPage[0]->id); - $this->assertFalse($nextPage->hasNext()); } @@ -56,7 +61,7 @@ public function test_will_return_null_if_no_next_result_is_available() public function test_can_get_previous_collection_result_when_previous_link_is_available() { $client = new MockClient([ - DynamicGetRequest::class => new MockResponse(200, 'cursor-collection', 'ord_stTC2WHAuS'), + DynamicGetRequest::class => new MockResponse(200, 'cursor-collection'), ]); $collection = new PaymentCollection( @@ -64,7 +69,7 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av [], $this->arrayToObject([ 'previous' => [ - 'href' => 'https://api.mollie.com/v2/payments?from=tr_stTC2WHAuS', + 'href' => 'https://api.mollie.com/v2/payments?from=tr_*', ], ]) ); @@ -73,8 +78,6 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av $previousPage = $collection->previous(); - $this->assertEquals('tr_stTC2WHAuS', $previousPage[0]->id); - $this->assertFalse($previousPage->hasPrevious()); } diff --git a/tests/Resources/InvoiceTest.php b/tests/Resources/InvoiceTest.php index 63f9f0225..7c9126aeb 100644 --- a/tests/Resources/InvoiceTest.php +++ b/tests/Resources/InvoiceTest.php @@ -5,7 +5,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Invoice; use Mollie\Api\Types\InvoiceStatus; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; class InvoiceTest extends TestCase { diff --git a/tests/Resources/LazyCollectionTest.php b/tests/Resources/LazyCollectionTest.php index c4960049d..a3e9b170b 100644 --- a/tests/Resources/LazyCollectionTest.php +++ b/tests/Resources/LazyCollectionTest.php @@ -3,7 +3,7 @@ namespace Tests\Resources; use Mollie\Api\Resources\LazyCollection; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; class LazyCollectionTest extends TestCase { diff --git a/tests/Resources/MandateCollectionTest.php b/tests/Resources/MandateCollectionTest.php index a45a1c2ba..7838112f4 100644 --- a/tests/Resources/MandateCollectionTest.php +++ b/tests/Resources/MandateCollectionTest.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use Mollie\Api\Types\MandateStatus; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; class MandateCollectionTest extends TestCase { diff --git a/tests/Resources/MethodTest.php b/tests/Resources/MethodTest.php index dc277d77c..a443fb32c 100644 --- a/tests/Resources/MethodTest.php +++ b/tests/Resources/MethodTest.php @@ -5,7 +5,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\IssuerCollection; use Mollie\Api\Resources\Method; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; class MethodTest extends TestCase { diff --git a/tests/Resources/OrderLineCollectionTest.php b/tests/Resources/OrderLineCollectionTest.php deleted file mode 100644 index c8bd22b90..000000000 --- a/tests/Resources/OrderLineCollectionTest.php +++ /dev/null @@ -1,37 +0,0 @@ -createMock(MollieApiClient::class); - - $line1 = new OrderLine($mockApi); - $line1->id = 'odl_aaaaaaaaaaa1'; - - $line2 = new OrderLine($mockApi); - $line2->id = 'odl_aaaaaaaaaaa2'; - - $line3 = new OrderLine($mockApi); - $line3->id = 'odl_aaaaaaaaaaa3'; - - $lines = new OrderLineCollection($mockApi, [ - $line1, - $line2, - $line3, - ], null); - - $this->assertNull($lines->get('odl_not_existent')); - - $line = $lines->get('odl_aaaaaaaaaaa2'); - - $this->assertInstanceOf(OrderLine::class, $line); - $this->assertEquals($line2, $line); - } -} diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 4506f97dc..2b701ccb8 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -8,7 +8,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; -use PHPUnit\Framework\TestCase; +use Tests\TestCase; class ResourceFactoryTest extends TestCase { diff --git a/tests/Resources/ShipmentTest.php b/tests/Resources/ShipmentTest.php deleted file mode 100644 index 7a3a9f9dd..000000000 --- a/tests/Resources/ShipmentTest.php +++ /dev/null @@ -1,84 +0,0 @@ -createMock(MollieApiClient::class)); - $shipment->tracking = $this->getTrackingDummy(); - $this->assertTrue($shipment->hasTracking()); - } - - public function test_has_tracking_returns_false_if_object_is_null() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - $shipment->tracking = null; - $this->assertFalse($shipment->hasTracking()); - } - - public function test_has_tracking_url_returns_false_if_tracking_is_not_set() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - $shipment->tracking = null; - $this->assertFalse($shipment->hasTrackingUrl()); - } - - public function test_has_tracking_url_returns_true_if_url_is_set() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - $shipment->tracking = $this->getTrackingDummy([ - 'url' => 'https://www.some-tracking-url.com/123', - ]); - $this->assertTrue($shipment->hasTrackingUrl()); - } - - public function test_has_tracking_url_returns_false_if_url_is_not_set() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - $shipment->tracking = $this->getTrackingDummy([ - 'url' => null, - ]); - $this->assertFalse($shipment->hasTrackingUrl()); - } - - public function test_get_tracking_url_returns_null_if_not_available() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - - $shipment->tracking = null; - $this->assertNull($shipment->getTrackingUrl()); - - $shipment->tracking = $this->getTrackingDummy([ - 'url' => null, - ]); - $this->assertNull($shipment->getTrackingUrl()); - } - - public function test_get_tracking_url_returns_url_if_available() - { - $shipment = new Shipment($this->createMock(MollieApiClient::class)); - $shipment->tracking = $this->getTrackingDummy([ - 'url' => 'https://www.some-tracking-url.com/123', - ]); - - $this->assertEquals( - 'https://www.some-tracking-url.com/123', - $shipment->getTrackingUrl() - ); - } - - protected function getTrackingDummy($overrides = []) - { - return (object) array_merge([ - 'carrier' => 'DummyCarrier', - 'code' => '123456ABCD', - 'url' => 'https://www.example.org/tracktrace/1234', - ], $overrides); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 000000000..66d6a3860 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,16 @@ + Date: Tue, 3 Dec 2024 11:33:14 +0000 Subject: [PATCH 070/131] Fixes coding style --- .../ClientEndpointCollection.php | 2 +- .../ProfileMethodEndpointCollection.php | 36 ++++++++----------- .../SessionEndpointCollection.php | 11 +++--- .../SettlementEndpointCollection.php | 16 +++++---- .../GetAllPaymentMethodsQueryFactory.php | 1 - .../GetPaginatedClientQueryFactory.php | 1 + .../GetPaginatedRefundsQueryFactory.php | 1 + ...aginatedSettlementCapturesQueryFactory.php | 1 + .../GetPaymentRefundQueryFactory.php | 1 + src/Helpers/Arr.php | 2 +- src/Http/Query/GetClientQuery.php | 1 + src/Http/Query/GetPaginatedClientQuery.php | 2 ++ src/Http/Query/GetPaymentCaptureQuery.php | 1 + src/Http/Query/GetPaymentMethodQuery.php | 4 +++ src/Http/Requests/CreateSessionRequest.php | 1 + src/Http/Requests/GetSessionRequest.php | 1 + src/Http/Requests/GetTerminalRequest.php | 1 + src/Http/Requests/UpdateSessionRequest.php | 1 + src/MollieApiClient.php | 2 +- src/Traits/HasEndpoints.php | 2 +- .../BalanceEndpointCollectionTest.php | 2 +- .../BalanceReportEndpointCollectionTest.php | 8 ++--- ...lanceTransactionEndpointCollectionTest.php | 2 +- .../ChargebackEndpointCollectionTest.php | 2 +- .../ClientEndpointCollectionTest.php | 2 +- .../ClientLinkEndpointCollectionTest.php | 2 +- .../CustomerEndpointCollectionTest.php | 6 ++-- ...CustomerPaymentsEndpointCollectionTest.php | 3 +- .../InvoiceEndpointCollectionTest.php | 2 +- .../MandateEndpointCollectionTest.php | 2 +- .../MethodEndpointCollectionTest.php | 2 +- .../MethodIssuerEndpointCollectionTest.php | 4 +-- .../OnboardingEndpointCollectionTest.php | 2 +- .../OrganizationEndpointCollectionTest.php | 2 +- ...anizationPartnerEndpointCollectionTest.php | 2 +- .../PaymentCaptureEndpointCollectionTest.php | 6 ++-- ...aymentChargebackEndpointCollectionTest.php | 4 +-- .../PaymentEndpointCollectionTest.php | 2 +- .../PaymentLinkEndpointCollectionTest.php | 4 +-- ...ymentLinkPaymentEndpointCollectionTest.php | 2 +- .../PaymentRefundEndpointCollectionTest.php | 8 ++--- .../PaymentRouteEndpointCollectionTest.php | 2 +- .../PermissionEndpointCollectionTest.php | 2 +- .../ProfileEndpointCollectionTest.php | 4 +-- .../ProfileMethodEndpointCollectionTest.php | 4 +-- .../RefundEndpointCollectionTest.php | 2 +- .../SessionEndpointCollectionTest.php | 7 ++-- ...ettlementCaptureEndpointCollectionTest.php | 4 +-- ...lementChargebackEndpointCollectionTest.php | 2 +- ...ettlementPaymentEndpointCollectionTest.php | 2 +- ...SettlementRefundEndpointCollectionTest.php | 4 +-- .../SettlementsEndpointCollectionTest.php | 2 +- .../SubscriptionEndpointCollectionTest.php | 10 +++--- ...scriptionPaymentEndpointCollectionTest.php | 2 +- .../TerminalEndpointCollectionTest.php | 4 +-- .../WalletEndpointCollectionTest.php | 2 +- tests/Fixtures/Requests/DynamicGetRequest.php | 6 ++-- tests/Helpers/HandlersTest.php | 6 ++-- tests/Helpers/MiddlewareHandlersTest.php | 2 +- .../Adapter/GuzzleMollieHttpAdapterTest.php | 2 +- tests/MollieApiClientTest.php | 5 ++- tests/Resources/CursorCollectionTest.php | 2 +- 62 files changed, 122 insertions(+), 111 deletions(-) diff --git a/src/EndpointCollection/ClientEndpointCollection.php b/src/EndpointCollection/ClientEndpointCollection.php index 25309fc73..5ab558b2e 100644 --- a/src/EndpointCollection/ClientEndpointCollection.php +++ b/src/EndpointCollection/ClientEndpointCollection.php @@ -27,7 +27,7 @@ class ClientEndpointCollection extends EndpointCollection */ public function get(string $id, $query = []): Client { - if (!$query instanceof GetClientQuery) { + if (! $query instanceof GetClientQuery) { $query = GetClientQueryFactory::new($query)->create(); } diff --git a/src/EndpointCollection/ProfileMethodEndpointCollection.php b/src/EndpointCollection/ProfileMethodEndpointCollection.php index ca8415a75..bf27872d3 100644 --- a/src/EndpointCollection/ProfileMethodEndpointCollection.php +++ b/src/EndpointCollection/ProfileMethodEndpointCollection.php @@ -3,8 +3,8 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Http\Requests\DisableProfileMethodRequest; +use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\Profile; @@ -14,8 +14,6 @@ class ProfileMethodEndpointCollection extends EndpointCollection * Enable a method for the provided Profile ID. * Alias of enableForId for backwards compatibility. * - * @param string $profileId - * @param string $id * @throws ApiException */ public function createForId(string $profileId, string $id): Method @@ -27,8 +25,6 @@ public function createForId(string $profileId, string $id): Method * Enable a method for the provided Profile object. * Alias of enableFor for backwards compatibility. * - * @param Profile $profile - * @param string $id * @throws ApiException */ public function createFor(Profile $profile, string $id): Method @@ -40,7 +36,6 @@ public function createFor(Profile $profile, string $id): Method * Enable a method for the current profile. * Alias of enable for backwards compatibility. * - * @param string $id * @throws ApiException */ public function createForCurrentProfile(string $id): Method @@ -51,8 +46,9 @@ public function createForCurrentProfile(string $id): Method /** * Enable a payment method for a specific profile. * - * @param string $profileId The profile's ID or 'me' for the current profile - * @param string $id The payment method ID + * @param string $profileId The profile's ID or 'me' for the current profile + * @param string $id The payment method ID + * * @throws ApiException */ public function enableForId(string $profileId, string $id): Method @@ -64,8 +60,8 @@ public function enableForId(string $profileId, string $id): Method /** * Enable a payment method for the provided Profile object. * - * @param Profile $profile - * @param string $id The payment method ID + * @param string $id The payment method ID + * * @throws ApiException */ public function enableFor(Profile $profile, string $id): Method @@ -76,7 +72,8 @@ public function enableFor(Profile $profile, string $id): Method /** * Enable a payment method for the current profile. * - * @param string $id The payment method ID + * @param string $id The payment method ID + * * @throws ApiException */ public function enable(string $id): Method @@ -88,8 +85,6 @@ public function enable(string $id): Method * Disable a method for the provided Profile ID. * Alias of disableForId for backwards compatibility. * - * @param string $profileId - * @param string $id * @throws ApiException */ public function deleteForId(string $profileId, string $id): void @@ -101,8 +96,6 @@ public function deleteForId(string $profileId, string $id): void * Disable a method for the provided Profile object. * Alias of disableFor for backwards compatibility. * - * @param Profile $profile - * @param string $id * @throws ApiException */ public function deleteFor(Profile $profile, string $id): void @@ -114,7 +107,6 @@ public function deleteFor(Profile $profile, string $id): void * Disable a method for the current profile. * Alias of disable for backwards compatibility. * - * @param string $id * @throws ApiException */ public function deleteForCurrentProfile(string $id): void @@ -125,8 +117,9 @@ public function deleteForCurrentProfile(string $id): void /** * Disable a payment method for a specific profile. * - * @param string $profileId The profile's ID or 'me' for the current profile - * @param string $id The payment method ID + * @param string $profileId The profile's ID or 'me' for the current profile + * @param string $id The payment method ID + * * @throws ApiException */ public function disableForId(string $profileId, string $id): void @@ -137,8 +130,8 @@ public function disableForId(string $profileId, string $id): void /** * Disable a payment method for the provided Profile object. * - * @param Profile $profile - * @param string $id The payment method ID + * @param string $id The payment method ID + * * @throws ApiException */ public function disableFor(Profile $profile, string $id): void @@ -149,7 +142,8 @@ public function disableFor(Profile $profile, string $id): void /** * Disable a payment method for the current profile. * - * @param string $id The payment method ID + * @param string $id The payment method ID + * * @throws ApiException */ public function disable(string $id): void diff --git a/src/EndpointCollection/SessionEndpointCollection.php b/src/EndpointCollection/SessionEndpointCollection.php index ac0e06cc1..a99668056 100644 --- a/src/EndpointCollection/SessionEndpointCollection.php +++ b/src/EndpointCollection/SessionEndpointCollection.php @@ -5,6 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; use Mollie\Api\Http\Payload\AnyPayload; +use Mollie\Api\Http\Query\AnyQuery; use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; @@ -13,7 +14,6 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; -use Mollie\Api\Http\Query\AnyQuery; class SessionEndpointCollection extends EndpointCollection { @@ -22,8 +22,8 @@ class SessionEndpointCollection extends EndpointCollection * * Will throw a ApiException if the session id is invalid or the resource cannot be found. * - * @param string $sessionId - * @param array|AnyQuery $query + * @param array|AnyQuery $query + * * @throws ApiException */ public function get(string $sessionId, $query = []): Session @@ -39,8 +39,9 @@ public function get(string $sessionId, $query = []): Session /** * Creates a session in Mollie. * - * @param array|AnyPayload $payload - * @param array|AnyQuery $query + * @param array|AnyPayload $payload + * @param array|AnyQuery $query + * * @throws ApiException */ public function create($payload = [], $query = []): Session diff --git a/src/EndpointCollection/SettlementEndpointCollection.php b/src/EndpointCollection/SettlementEndpointCollection.php index dc0f2a8fa..0d6536a85 100644 --- a/src/EndpointCollection/SettlementEndpointCollection.php +++ b/src/EndpointCollection/SettlementEndpointCollection.php @@ -18,7 +18,8 @@ class SettlementEndpointCollection extends EndpointCollection * * Will throw an ApiException if the settlement id is invalid or the resource cannot be found. * - * @param array|bool $testmode + * @param array|bool $testmode + * * @throws ApiException */ public function get(string $settlementId, $testmode = []): Settlement @@ -32,7 +33,8 @@ public function get(string $settlementId, $testmode = []): Settlement /** * Retrieve the next settlement from Mollie. * - * @param array|bool $testmode + * @param array|bool $testmode + * * @throws ApiException */ public function next($testmode = []): ?Settlement @@ -43,7 +45,8 @@ public function next($testmode = []): ?Settlement /** * Retrieve the open balance from Mollie. * - * @param array|bool $testmode + * @param array|bool $testmode + * * @throws ApiException */ public function open($testmode = []): ?Settlement @@ -54,7 +57,8 @@ public function open($testmode = []): ?Settlement /** * Retrieve a collection of settlements from Mollie. * - * @param string|null $from The first settlement ID you want to include in your list. + * @param string|null $from The first settlement ID you want to include in your list. + * * @throws ApiException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection @@ -74,8 +78,8 @@ public function page(?string $from = null, ?int $limit = null, array $filters = /** * Create an iterator for iterating over settlements retrieved from Mollie. * - * @param string|null $from The first settlement ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * @param string|null $from The first settlement ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iterator( ?string $from = null, diff --git a/src/Factories/GetAllPaymentMethodsQueryFactory.php b/src/Factories/GetAllPaymentMethodsQueryFactory.php index 58c0e2722..2c82b718d 100644 --- a/src/Factories/GetAllPaymentMethodsQueryFactory.php +++ b/src/Factories/GetAllPaymentMethodsQueryFactory.php @@ -4,7 +4,6 @@ use Mollie\Api\Http\Query\GetAllMethodsQuery; use Mollie\Api\Types\MethodQuery; -use Mollie\Api\Types\PaymentMethod; class GetAllPaymentMethodsQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php index 6f42f9f2f..bb0389efe 100644 --- a/src/Factories/GetPaginatedClientQueryFactory.php +++ b/src/Factories/GetPaginatedClientQueryFactory.php @@ -4,6 +4,7 @@ use Mollie\Api\Http\Query\GetPaginatedClientQuery; use Mollie\Api\Types\ClientQuery; + class GetPaginatedClientQueryFactory extends Factory { public function create(): GetPaginatedClientQuery diff --git a/src/Factories/GetPaginatedRefundsQueryFactory.php b/src/Factories/GetPaginatedRefundsQueryFactory.php index 188ba8bba..22c441518 100644 --- a/src/Factories/GetPaginatedRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedRefundsQueryFactory.php @@ -4,6 +4,7 @@ use Mollie\Api\Http\Query\GetPaginatedRefundsQuery; use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaginatedRefundsQueryFactory extends Factory { public function create(): GetPaginatedRefundsQuery diff --git a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php index cbf53e8a6..665547a42 100644 --- a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php @@ -4,6 +4,7 @@ use Mollie\Api\Http\Query\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaginatedSettlementCapturesQueryFactory extends Factory { public function create(): GetPaginatedSettlementCapturesQuery diff --git a/src/Factories/GetPaymentRefundQueryFactory.php b/src/Factories/GetPaymentRefundQueryFactory.php index 879990e34..aac2e7258 100644 --- a/src/Factories/GetPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaymentRefundQueryFactory.php @@ -4,6 +4,7 @@ use Mollie\Api\Http\Query\GetPaymentRefundQuery; use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaymentRefundQueryFactory extends Factory { public function create(): GetPaymentRefundQuery diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index bc17dadeb..511457c27 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -88,7 +88,7 @@ public static function wrap($array): array /** * Check if a value exists in an array of includes. - * @param array $array + * * @param string|array $key * @param mixed $value * diff --git a/src/Http/Query/GetClientQuery.php b/src/Http/Query/GetClientQuery.php index 98608b449..d8776ce02 100644 --- a/src/Http/Query/GetClientQuery.php +++ b/src/Http/Query/GetClientQuery.php @@ -8,6 +8,7 @@ class GetClientQuery extends Query { private bool $embedOrganization; + private bool $embedOnboarding; public function __construct( diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index 4435822c8..094fb447f 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -4,11 +4,13 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\ClientQuery; + class GetPaginatedClientQuery extends Query { private PaginatedQuery $paginatedQuery; private bool $embedOrganization; + private bool $embedOnboarding; public function __construct( diff --git a/src/Http/Query/GetPaymentCaptureQuery.php b/src/Http/Query/GetPaymentCaptureQuery.php index 0501c22d7..712752795 100644 --- a/src/Http/Query/GetPaymentCaptureQuery.php +++ b/src/Http/Query/GetPaymentCaptureQuery.php @@ -4,6 +4,7 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; + class GetPaymentCaptureQuery extends Query { public bool $includePayment = false; diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php index 86e9e7a50..90791dc6e 100644 --- a/src/Http/Query/GetPaymentMethodQuery.php +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -8,9 +8,13 @@ class GetPaymentMethodQuery extends Query { private ?string $locale; + private ?string $currency; + private ?string $profileId; + private bool $includeIssuers; + private bool $includePricing; public function __construct( diff --git a/src/Http/Requests/CreateSessionRequest.php b/src/Http/Requests/CreateSessionRequest.php index 87568e767..cca615035 100644 --- a/src/Http/Requests/CreateSessionRequest.php +++ b/src/Http/Requests/CreateSessionRequest.php @@ -18,6 +18,7 @@ class CreateSessionRequest extends ResourceHydratableRequest implements HasPaylo public static string $targetResourceClass = Session::class; private AnyPayload $payload; + private AnyQuery $query; public function __construct(AnyPayload $payload, AnyQuery $query) diff --git a/src/Http/Requests/GetSessionRequest.php b/src/Http/Requests/GetSessionRequest.php index 63f570e3e..80f6b9ec1 100644 --- a/src/Http/Requests/GetSessionRequest.php +++ b/src/Http/Requests/GetSessionRequest.php @@ -13,6 +13,7 @@ class GetSessionRequest extends ResourceHydratableRequest public static string $targetResourceClass = Session::class; private string $sessionId; + private AnyQuery $query; public function __construct(string $sessionId, AnyQuery $query) diff --git a/src/Http/Requests/GetTerminalRequest.php b/src/Http/Requests/GetTerminalRequest.php index e777435db..6b7c5a1ff 100644 --- a/src/Http/Requests/GetTerminalRequest.php +++ b/src/Http/Requests/GetTerminalRequest.php @@ -5,6 +5,7 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\Terminal; use Mollie\Api\Types\Method; + class GetTerminalRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { protected static string $method = Method::GET; diff --git a/src/Http/Requests/UpdateSessionRequest.php b/src/Http/Requests/UpdateSessionRequest.php index 7ac512cff..6423d87ef 100644 --- a/src/Http/Requests/UpdateSessionRequest.php +++ b/src/Http/Requests/UpdateSessionRequest.php @@ -17,6 +17,7 @@ class UpdateSessionRequest extends ResourceHydratableRequest implements HasPaylo public static string $targetResourceClass = Session::class; private string $sessionId; + private AnyPayload $payload; public function __construct(string $sessionId, AnyPayload $payload) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 65a8ca79d..2e18fceb2 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -33,6 +33,7 @@ use Mollie\Api\EndpointCollection\ProfileEndpointCollection; use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; @@ -55,7 +56,6 @@ use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; -use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\Traits\SendsRequests; /** diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 6fce32bab..8d9cfb206 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -28,6 +28,7 @@ use Mollie\Api\EndpointCollection\ProfileEndpointCollection; use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; @@ -37,7 +38,6 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\MollieApiClient; /** diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 5589e524c..f71e5821a 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -9,11 +9,11 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; +use Tests\TestCase; class BalanceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index 36f0af811..5878fa1ca 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -7,11 +7,11 @@ use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; +use Tests\TestCase; class BalanceReportEndpointCollectionTest extends TestCase { @@ -29,7 +29,7 @@ public function get_for_id() $report = $client->balanceReports->getForId('bal_gVMhHKqSSRYJyPsuoPNFH', [ 'from' => '2021-01-01', 'until' => '2021-02-01', - 'grouping' => 'transaction-categories' + 'grouping' => 'transaction-categories', ]); $this->assertBalanceReport($report, 'bal_gVMhHKqSSRYJyPsuoPNFH'); @@ -49,7 +49,7 @@ public function get_for_balance() $report = $client->balanceReports->getFor($balance, [ 'from' => '2021-01-01', 'until' => '2021-02-01', - 'grouping' => 'transaction-categories' + 'grouping' => 'transaction-categories', ]); $this->assertBalanceReport($report, 'bal_gVMhHKqSSRYJyPsuoPNFH'); @@ -66,7 +66,7 @@ public function get_for_primary() $report = $client->balanceReports->getForPrimary([ 'from' => '2024-01-01', 'until' => '2024-01-31', - 'grouping' => 'transaction-categories' + 'grouping' => 'transaction-categories', ]); $this->assertBalanceReport($report, 'bal_primary'); diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 2a13224a5..190c79eae 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class BalanceTransactionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index 257fe90f1..237eb8c72 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class ChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php index c8ac9434b..fa73c9db9 100644 --- a/tests/EndpointCollection/ClientEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class ClientEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index 2ccb50e6d..c1f91fa5d 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Payload\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class ClientLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php index 720968933..010b34ac6 100644 --- a/tests/EndpointCollection/CustomerEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -3,16 +3,16 @@ namespace Tests\EndpointCollection; use Mollie\Api\Http\Requests\CreateCustomerRequest; +use Mollie\Api\Http\Requests\DeleteCustomerRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetCustomerRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Http\Requests\UpdateCustomerRequest; -use Mollie\Api\Http\Requests\DeleteCustomerRequest; -use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class CustomerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 75e68ea8f..e6d8d659b 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -4,16 +4,15 @@ use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class CustomerPaymentsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php index 94f6e8bcd..e2dfe10e4 100644 --- a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class InvoiceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 13251c849..482a4e564 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -11,9 +11,9 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class MandateEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php index eab70af85..4c0c2deef 100644 --- a/tests/EndpointCollection/MethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class MethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php index 85dccdf54..db90e2a0e 100644 --- a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; +use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class MethodIssuerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php index 8057494a7..04d588c17 100644 --- a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\GetOnboardingRequest; use Mollie\Api\Resources\Onboarding; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class OnboardingEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php index f7cb1a510..37478a9c9 100644 --- a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class OrganizationEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php index 15e45764a..789ef496a 100644 --- a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class OrganizationPartnerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index 2faa59fda..520da5202 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -6,13 +6,13 @@ use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; +use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentCaptureEndpointCollectionTest extends TestCase { @@ -67,7 +67,7 @@ public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list','captures'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'captures'), ]); foreach ($client->paymentCaptures->iteratorForId('tr_7UhSN1zuXS') as $capture) { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index ad261d38b..09861ed4f 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; +use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index f78c94732..2ae5a85a4 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -16,9 +16,9 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index 6b64c32ed..cebf2bab2 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -9,14 +9,14 @@ use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\GetPaymentLinkRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; +use Mollie\Api\Http\Requests\GetPaymentLinkRequest; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php index 62889bb36..6edba93f3 100644 --- a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentLinkPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index 70e4a7fea..99673c57e 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -2,17 +2,17 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; -use Mollie\Api\Http\Requests\GetPaymentRefundRequest; -use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; +use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; +use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php index e8d9f8355..5842509a3 100644 --- a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PaymentRouteEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php index ae2f1d675..96274fa37 100644 --- a/tests/EndpointCollection/PermissionEndpointCollectionTest.php +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class PermissionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index ecadaa460..c3f317c5d 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -7,14 +7,14 @@ use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; +use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class ProfileEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php index cbf87e2be..8d83d2104 100644 --- a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Http\Requests\DisableProfileMethodRequest; +use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class ProfileMethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php index 2a50a47c4..aec800e13 100644 --- a/tests/EndpointCollection/RefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class RefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index ebf69071e..9f7d2398b 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -13,9 +13,9 @@ use Mollie\Api\Http\Requests\UpdateSessionRequest; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SessionEndpointCollectionTest extends TestCase { @@ -42,7 +42,7 @@ public function create() /** @var Session $session */ $session = $client->sessions->create(new AnyPayload([ 'amount' => new Money('EUR', '10.00'), - 'description' => 'Test Session' + 'description' => 'Test Session', ])); $this->assertSession($session); @@ -57,7 +57,7 @@ public function update() /** @var Session $session */ $session = $client->sessions->update('ses_123', new AnyPayload([ - 'description' => 'Updated Session' + 'description' => 'Updated Session', ])); $this->assertSession($session); @@ -106,6 +106,7 @@ public function iterator() $this->assertSession($session); } } + protected function assertSession(Session $session) { $this->assertInstanceOf(Session::class, $session); diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index 4cd76fa3b..556d1bacd 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SettlementCaptureEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 8ce917e90..78f99be1b 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SettlementChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php index efc068b46..2e6bc1062 100644 --- a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SettlementPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index 3c35b10e7..b05034927 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Requests\DynamicGetRequest; +use Tests\TestCase; class SettlementRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php index 2ea3e8055..d95c13c74 100644 --- a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SettlementsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 91c8039e3..21eb9f931 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -2,19 +2,19 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Http\Requests\CreateSubscriptionRequest; -use Mollie\Api\Http\Requests\GetSubscriptionRequest; +use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest; +use Mollie\Api\Http\Requests\GetSubscriptionRequest; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; -use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; +use Tests\TestCase; class SubscriptionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php index 1d2c8dc47..c9e1e48ba 100644 --- a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class SubscriptionPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index 291324c8c..337af014a 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; -use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class TerminalEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index 8db783c09..f3be60d21 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\TestCase; class WalletEndpointCollectionTest extends TestCase { diff --git a/tests/Fixtures/Requests/DynamicGetRequest.php b/tests/Fixtures/Requests/DynamicGetRequest.php index 710eee701..189ae9351 100644 --- a/tests/Fixtures/Requests/DynamicGetRequest.php +++ b/tests/Fixtures/Requests/DynamicGetRequest.php @@ -2,9 +2,7 @@ namespace Tests\Fixtures\Requests; -use Mollie\Api\Http\Requests\DynamicGetRequest as BaseDynamicGetRequest; use Mollie\Api\Contracts\SupportsTestmodeInQuery; +use Mollie\Api\Http\Requests\DynamicGetRequest as BaseDynamicGetRequest; -class DynamicGetRequest extends BaseDynamicGetRequest implements SupportsTestmodeInQuery -{ -} +class DynamicGetRequest extends BaseDynamicGetRequest implements SupportsTestmodeInQuery {} diff --git a/tests/Helpers/HandlersTest.php b/tests/Helpers/HandlersTest.php index 069379c97..218918d07 100644 --- a/tests/Helpers/HandlersTest.php +++ b/tests/Helpers/HandlersTest.php @@ -13,7 +13,7 @@ class HandlersTest extends TestCase /** @test */ public function add(): void { - $handlers = new Handlers(); + $handlers = new Handlers; $handlers->add(fn () => null); $this->assertCount(1, $handlers->getHandlers()); @@ -24,7 +24,7 @@ public function handlers_are_executed_in_the_correct_order(): void { $output = []; - $handlers = new Handlers(); + $handlers = new Handlers; $handlers->add(function ($value) use (&$output) { $output[] = 1; @@ -48,7 +48,7 @@ public function handlers_are_executed_in_the_correct_order(): void } } -class TestViableResponse implements ViableResponse, Arrayable +class TestViableResponse implements Arrayable, ViableResponse { public array $output = []; diff --git a/tests/Helpers/MiddlewareHandlersTest.php b/tests/Helpers/MiddlewareHandlersTest.php index f2b4005a7..48c4c8bb7 100644 --- a/tests/Helpers/MiddlewareHandlersTest.php +++ b/tests/Helpers/MiddlewareHandlersTest.php @@ -5,8 +5,8 @@ use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; -use Tests\TestCase; use Tests\Fixtures\MockClient; +use Tests\TestCase; class MiddlewareHandlersTest extends TestCase { diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index cf7cc3221..0ef3d9217 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -10,9 +10,9 @@ use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Tests\TestCase; use Psr\Http\Message\RequestInterface; use Tests\Fixtures\MockClient; +use Tests\TestCase; class GuzzleMollieHttpAdapterTest extends TestCase { diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index b9dc92782..f59c47094 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -12,15 +12,14 @@ use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Payload\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; -use Tests\Fixtures\Requests\DynamicDeleteRequest; -use Tests\Fixtures\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response as HttpResponse; use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; -use Tests\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\Fixtures\Requests\DynamicDeleteRequest; +use Tests\Fixtures\Requests\DynamicGetRequest; class MollieApiClientTest extends TestCase { diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 1c32eee50..60b476ae9 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -5,11 +5,11 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; -use Tests\TestCase; use stdClass; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; +use Tests\TestCase; class CursorCollectionTest extends TestCase { From c5ef68de858350fcc45eaf986d91150205d149f9 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:34:51 +0100 Subject: [PATCH 071/131] wip --- src/Resources/AnyResource.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index 32fc79dab..e8bae6792 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -14,7 +14,10 @@ public function __get(string $name): mixed return Arr::get($this->attributes, $name); } - public function fill(array|stdClass $attributes): void + /** + * @param array|stdClass $attributes + */ + public function fill($attributes): void { $this->attributes = $attributes instanceof stdClass ? (array) $attributes : $attributes; } From 79e75b55c85ab59abc78b298a1799b3b0150d37d Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 3 Dec 2024 11:35:28 +0000 Subject: [PATCH 072/131] Fixes coding style --- src/Resources/AnyResource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index e8bae6792..775601712 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -15,7 +15,7 @@ public function __get(string $name): mixed } /** - * @param array|stdClass $attributes + * @param array|stdClass $attributes */ public function fill($attributes): void { From 6a06935f6c3bcb5e3ce4e41b52b9de95ef7ba733 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:39:26 +0100 Subject: [PATCH 073/131] fix phpstan --- phpstan-baseline.neon | 80 ------------------------------------------- 1 file changed, 80 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 36c738bb7..cafdcd681 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -75,61 +75,6 @@ parameters: count: 1 path: examples/mandates/revoke-mandate.php - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 2 - path: examples/orders/cancel-order-lines.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/cancel-order.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/create-order.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/list-methods.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/list-orders.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/refund-order-completely.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/refund-order-partially.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/update-order-line.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/update-order-lines-multiple.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/update-order.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/orders/webhook.php - - message: "#^Variable \\$mollie might not be defined\\.$#" count: 2 @@ -245,31 +190,6 @@ parameters: count: 1 path: examples/settlements/list-settlements.php - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/shipments/create-shipment-all.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/shipments/create-shipment-partial.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/shipments/get-shipment.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/shipments/list-shipments.php - - - - message: "#^Variable \\$mollie might not be defined\\.$#" - count: 1 - path: examples/shipments/update-shipment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" count: 1 From edd5d01bc333c35eab9e29e2a02de5a7eea1d681 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:40:25 +0100 Subject: [PATCH 074/131] fix php7.4 compatibility --- src/Factories/CreateProfilePayloadFactory.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Factories/CreateProfilePayloadFactory.php b/src/Factories/CreateProfilePayloadFactory.php index 1d018b55d..b3e9161dd 100644 --- a/src/Factories/CreateProfilePayloadFactory.php +++ b/src/Factories/CreateProfilePayloadFactory.php @@ -9,13 +9,13 @@ class CreateProfilePayloadFactory extends Factory public function create(): CreateProfilePayload { return new CreateProfilePayload( - name: $this->get('name'), - website: $this->get('website'), - email: $this->get('email'), - phone: $this->get('phone'), - description: $this->get('description'), - countriesOfActivity: $this->get('countriesOfActivity'), - businessCategory: $this->get('businessCategory') + $this->get('name'), + $this->get('website'), + $this->get('email'), + $this->get('phone'), + $this->get('description'), + $this->get('countriesOfActivity'), + $this->get('businessCategory') ); } } From c0dd9dde1391a9727331fb26489d1939791f933f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:42:14 +0100 Subject: [PATCH 075/131] fix php7.4 compatibility --- src/Factories/UpdateProfilePayloadFactory.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Factories/UpdateProfilePayloadFactory.php b/src/Factories/UpdateProfilePayloadFactory.php index acda6c700..b58d2243f 100644 --- a/src/Factories/UpdateProfilePayloadFactory.php +++ b/src/Factories/UpdateProfilePayloadFactory.php @@ -9,14 +9,14 @@ class UpdateProfilePayloadFactory extends Factory public function create(): UpdateProfilePayload { return new UpdateProfilePayload( - name: $this->get('name'), - website: $this->get('website'), - email: $this->get('email'), - phone: $this->get('phone'), - description: $this->get('description'), - countriesOfActivity: $this->get('countriesOfActivity'), - businessCategory: $this->get('businessCategory'), - mode: $this->get('mode') + $this->get('name'), + $this->get('website'), + $this->get('email'), + $this->get('phone'), + $this->get('description'), + $this->get('countriesOfActivity'), + $this->get('businessCategory'), + $this->get('mode') ); } } From cfea22e3f7cda7a061ccc68bcf8e713aed4aa3c0 Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 3 Dec 2024 11:42:42 +0000 Subject: [PATCH 076/131] Fixes coding style --- src/Factories/UpdateProfilePayloadFactory.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Factories/UpdateProfilePayloadFactory.php b/src/Factories/UpdateProfilePayloadFactory.php index b58d2243f..94514d904 100644 --- a/src/Factories/UpdateProfilePayloadFactory.php +++ b/src/Factories/UpdateProfilePayloadFactory.php @@ -10,13 +10,13 @@ public function create(): UpdateProfilePayload { return new UpdateProfilePayload( $this->get('name'), - $this->get('website'), - $this->get('email'), - $this->get('phone'), - $this->get('description'), - $this->get('countriesOfActivity'), - $this->get('businessCategory'), - $this->get('mode') + $this->get('website'), + $this->get('email'), + $this->get('phone'), + $this->get('description'), + $this->get('countriesOfActivity'), + $this->get('businessCategory'), + $this->get('mode') ); } } From f3de9460df524039b9262c8e1c2e48cea3d4f6b9 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:44:09 +0100 Subject: [PATCH 077/131] fix php7.4 compatibility --- src/Http/Requests/GetPaymentCaptureRequest.php | 2 +- src/Http/Requests/GetPaymentChargebackRequest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Http/Requests/GetPaymentCaptureRequest.php b/src/Http/Requests/GetPaymentCaptureRequest.php index da1437d2f..4c5e1864d 100644 --- a/src/Http/Requests/GetPaymentCaptureRequest.php +++ b/src/Http/Requests/GetPaymentCaptureRequest.php @@ -34,7 +34,7 @@ public function __construct(string $paymentId, string $captureId, ?GetPaymentCap protected function defaultQuery(): array { - return $this->query?->toArray() ?? []; + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentChargebackRequest.php b/src/Http/Requests/GetPaymentChargebackRequest.php index d1c029d5d..8a18ca56a 100644 --- a/src/Http/Requests/GetPaymentChargebackRequest.php +++ b/src/Http/Requests/GetPaymentChargebackRequest.php @@ -34,7 +34,7 @@ public function __construct(string $paymentId, string $chargebackId, ?GetPayment protected function defaultQuery(): array { - return $this->query?->toArray() ?? []; + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string From f80f4f1c6b7caf86e2d4d366c659b30ce7036824 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:45:48 +0100 Subject: [PATCH 078/131] fix php7.4 compatibility --- src/Http/Payload/CreateMandatePayload.php | 2 +- src/Http/Payload/CreateRefundPaymentPayload.php | 2 +- src/Http/Payload/CreateSubscriptionPayload.php | 2 +- src/Http/Payload/UpdatePaymentLinkPayload.php | 2 +- src/Http/Payload/UpdatePaymentRoutePayload.php | 2 +- src/Http/Query/CreatePaymentQuery.php | 2 +- src/Http/Query/GetAllMethodsQuery.php | 2 +- src/Http/Query/GetBalanceReportQuery.php | 2 +- src/Http/Query/GetClientQuery.php | 2 +- src/Http/Query/GetEnabledPaymentMethodsQuery.php | 2 +- src/Http/Query/GetPaginatedClientQuery.php | 2 +- src/Http/Query/GetPaginatedSettlementsQuery.php | 2 +- src/Http/Query/GetPaymentMethodQuery.php | 2 +- src/Http/Query/GetPaymentQuery.php | 2 +- src/Http/Query/GetPaymentRefundQuery.php | 2 +- src/Http/Query/PaginatedQuery.php | 2 +- src/Http/Query/SortablePaginatedQuery.php | 2 +- src/Http/Requests/CreateCustomerPaymentRequest.php | 2 +- tests/EndpointCollection/BalanceEndpointCollectionTest.php | 2 +- tests/Fixtures/MockResponse.php | 2 +- tests/Traits/ResolvesValuesTest.php | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Http/Payload/CreateMandatePayload.php b/src/Http/Payload/CreateMandatePayload.php index a26230104..fda0ccbfc 100644 --- a/src/Http/Payload/CreateMandatePayload.php +++ b/src/Http/Payload/CreateMandatePayload.php @@ -30,7 +30,7 @@ public function __construct( ?string $consumerEmail = null, ?DateTimeInterface $signatureDate = null, ?string $mandateReference = null, - ?string $paypalBillingAgreementId = null, + ?string $paypalBillingAgreementId = null ) { $this->method = $method; $this->consumerName = $consumerName; diff --git a/src/Http/Payload/CreateRefundPaymentPayload.php b/src/Http/Payload/CreateRefundPaymentPayload.php index cb813bfaa..add71a44d 100644 --- a/src/Http/Payload/CreateRefundPaymentPayload.php +++ b/src/Http/Payload/CreateRefundPaymentPayload.php @@ -26,7 +26,7 @@ public function __construct( Money $amount, ?Metadata $metadata = null, ?bool $reverseRouting = null, - ?DataCollection $routingReversals = null, + ?DataCollection $routingReversals = null ) { $this->description = $description; $this->amount = $amount; diff --git a/src/Http/Payload/CreateSubscriptionPayload.php b/src/Http/Payload/CreateSubscriptionPayload.php index ad7faba6e..648ba89a2 100644 --- a/src/Http/Payload/CreateSubscriptionPayload.php +++ b/src/Http/Payload/CreateSubscriptionPayload.php @@ -42,7 +42,7 @@ public function __construct( ?Metadata $metadata = null, ?string $webhookUrl = null, ?string $mandateId = null, - ?string $profileId = null, + ?string $profileId = null ) { $this->amount = $amount; $this->interval = $interval; diff --git a/src/Http/Payload/UpdatePaymentLinkPayload.php b/src/Http/Payload/UpdatePaymentLinkPayload.php index 92c56b66d..83444ff76 100644 --- a/src/Http/Payload/UpdatePaymentLinkPayload.php +++ b/src/Http/Payload/UpdatePaymentLinkPayload.php @@ -10,7 +10,7 @@ class UpdatePaymentLinkPayload extends DataBag public function __construct( string $description, - bool $archived = false, + bool $archived = false ) { $this->description = $description; $this->archived = $archived; diff --git a/src/Http/Payload/UpdatePaymentRoutePayload.php b/src/Http/Payload/UpdatePaymentRoutePayload.php index 967e14ada..490bc810d 100644 --- a/src/Http/Payload/UpdatePaymentRoutePayload.php +++ b/src/Http/Payload/UpdatePaymentRoutePayload.php @@ -9,7 +9,7 @@ class UpdatePaymentRoutePayload extends DataBag private DateTimeInterface $releaseDate; public function __construct( - DateTimeInterface $releaseDate, + DateTimeInterface $releaseDate ) { $this->releaseDate = $releaseDate; } diff --git a/src/Http/Query/CreatePaymentQuery.php b/src/Http/Query/CreatePaymentQuery.php index ebe90b01e..ecb207176 100644 --- a/src/Http/Query/CreatePaymentQuery.php +++ b/src/Http/Query/CreatePaymentQuery.php @@ -12,7 +12,7 @@ class CreatePaymentQuery extends Query private bool $includeQrCode; public function __construct( - bool $includeQrCode = false, + bool $includeQrCode = false ) { $this->includeQrCode = $includeQrCode; } diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php index 55b82d93f..85040dd59 100644 --- a/src/Http/Query/GetAllMethodsQuery.php +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -19,7 +19,7 @@ public function __construct( bool $includeIssuers = false, bool $includePricing = false, ?string $locale = null, - ?Money $amount = null, + ?Money $amount = null ) { $this->locale = $locale; $this->includeIssuers = $includeIssuers; diff --git a/src/Http/Query/GetBalanceReportQuery.php b/src/Http/Query/GetBalanceReportQuery.php index f469e9983..c3d0070d7 100644 --- a/src/Http/Query/GetBalanceReportQuery.php +++ b/src/Http/Query/GetBalanceReportQuery.php @@ -15,7 +15,7 @@ class GetBalanceReportQuery extends Query public function __construct( DateTimeInterface $from, DateTimeInterface $until, - ?string $grouping = null, + ?string $grouping = null ) { $this->from = $from; $this->until = $until; diff --git a/src/Http/Query/GetClientQuery.php b/src/Http/Query/GetClientQuery.php index d8776ce02..20d9b315b 100644 --- a/src/Http/Query/GetClientQuery.php +++ b/src/Http/Query/GetClientQuery.php @@ -13,7 +13,7 @@ class GetClientQuery extends Query public function __construct( bool $embedOrganization = false, - bool $embedOnboarding = false, + bool $embedOnboarding = false ) { $this->embedOrganization = $embedOrganization; $this->embedOnboarding = $embedOnboarding; diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index e877e37b1..90cc6f6d3 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -18,7 +18,7 @@ public function __construct( private ?array $orderLineCategories = null, private ?string $profileId = null, private ?bool $includeIssuers = null, - private ?bool $includePricing = null, + private ?bool $includePricing = null ) {} public function toArray(): array diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index 094fb447f..ccb8081a3 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -16,7 +16,7 @@ class GetPaginatedClientQuery extends Query public function __construct( PaginatedQuery $paginatedQuery, bool $embedOrganization = false, - bool $embedOnboarding = false, + bool $embedOnboarding = false ) { $this->paginatedQuery = $paginatedQuery; $this->embedOrganization = $embedOrganization; diff --git a/src/Http/Query/GetPaginatedSettlementsQuery.php b/src/Http/Query/GetPaginatedSettlementsQuery.php index 535323724..8b6eb9821 100644 --- a/src/Http/Query/GetPaginatedSettlementsQuery.php +++ b/src/Http/Query/GetPaginatedSettlementsQuery.php @@ -10,7 +10,7 @@ class GetPaginatedSettlementsQuery extends Query public function __construct( PaginatedQuery $query, - ?string $balanceId = null, + ?string $balanceId = null ) { $this->query = $query; $this->balanceId = $balanceId; diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php index 90791dc6e..92bb45a88 100644 --- a/src/Http/Query/GetPaymentMethodQuery.php +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -22,7 +22,7 @@ public function __construct( ?string $currency = null, ?string $profileId = null, bool $includeIssuers = false, - bool $includePricing = false, + bool $includePricing = false ) { $this->locale = $locale; $this->currency = $currency; diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php index f5778188a..1b24a355d 100644 --- a/src/Http/Query/GetPaymentQuery.php +++ b/src/Http/Query/GetPaymentQuery.php @@ -22,7 +22,7 @@ public function __construct( bool $embedRefunds = false, bool $embedChargebacks = false, bool $includeQrCode = false, - bool $includeRemainderDetails = false, + bool $includeRemainderDetails = false ) { $this->embedCaptures = $embedCaptures; $this->embedRefunds = $embedRefunds; diff --git a/src/Http/Query/GetPaymentRefundQuery.php b/src/Http/Query/GetPaymentRefundQuery.php index 54b7b0e4a..233a82610 100644 --- a/src/Http/Query/GetPaymentRefundQuery.php +++ b/src/Http/Query/GetPaymentRefundQuery.php @@ -9,7 +9,7 @@ class GetPaymentRefundQuery extends Query private bool $includePayment; public function __construct( - bool $includePayment = false, + bool $includePayment = false ) { $this->includePayment = $includePayment; } diff --git a/src/Http/Query/PaginatedQuery.php b/src/Http/Query/PaginatedQuery.php index 78820ec94..bab71b3d4 100644 --- a/src/Http/Query/PaginatedQuery.php +++ b/src/Http/Query/PaginatedQuery.php @@ -10,7 +10,7 @@ class PaginatedQuery extends Query public function __construct( ?string $from = null, - ?int $limit = null, + ?int $limit = null ) { $this->from = $from; $this->limit = $limit; diff --git a/src/Http/Query/SortablePaginatedQuery.php b/src/Http/Query/SortablePaginatedQuery.php index 83e8b72d4..7159b8c35 100644 --- a/src/Http/Query/SortablePaginatedQuery.php +++ b/src/Http/Query/SortablePaginatedQuery.php @@ -9,7 +9,7 @@ class SortablePaginatedQuery extends PaginatedQuery public function __construct( ?string $from = null, ?int $limit = null, - ?string $sort = null, + ?string $sort = null ) { parent::__construct($from, $limit); diff --git a/src/Http/Requests/CreateCustomerPaymentRequest.php b/src/Http/Requests/CreateCustomerPaymentRequest.php index a6f16fbdb..352acbd6a 100644 --- a/src/Http/Requests/CreateCustomerPaymentRequest.php +++ b/src/Http/Requests/CreateCustomerPaymentRequest.php @@ -14,7 +14,7 @@ class CreateCustomerPaymentRequest extends CreatePaymentRequest implements HasPa public function __construct( string $customerId, CreatePaymentPayload $payload, - ?CreatePaymentQuery $query = null, + ?CreatePaymentQuery $query = null ) { parent::__construct($payload, $query); diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index f71e5821a..78df81ab9 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -112,7 +112,7 @@ public function iterate() */ protected function assertBalance( Balance $balance, - string $balanceId, + string $balanceId ) { $this->assertInstanceOf(Balance::class, $balance); $this->assertEquals('balance', $balance->resource); diff --git a/tests/Fixtures/MockResponse.php b/tests/Fixtures/MockResponse.php index afe19bfdb..eabcbcceb 100644 --- a/tests/Fixtures/MockResponse.php +++ b/tests/Fixtures/MockResponse.php @@ -20,7 +20,7 @@ class MockResponse public function __construct( int $status = 200, string $body = '', - string $resourceId = '', + string $resourceId = '' ) { $this->status = $status; $this->resourceId = $resourceId; diff --git a/tests/Traits/ResolvesValuesTest.php b/tests/Traits/ResolvesValuesTest.php index 63b8ba91f..752af8d74 100644 --- a/tests/Traits/ResolvesValuesTest.php +++ b/tests/Traits/ResolvesValuesTest.php @@ -38,7 +38,7 @@ class FooData implements Arrayable public function __construct( Bar $bar, - string $name, + string $name ) { $this->bar = $bar; $this->name = $name; From 7c70d2ca591f3de132736f055ff20556aa28aa28 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:48:48 +0100 Subject: [PATCH 079/131] fix php7.4 compatibility --- src/Http/Payload/CreateMandatePayload.php | 2 +- src/Http/Payload/CreatePaymentLinkPayload.php | 2 +- src/Http/Payload/CreateSubscriptionPayload.php | 2 +- src/Http/Payload/UpdateSubscriptionPayload.php | 2 +- src/Http/Query/GetAllMethodsQuery.php | 2 +- src/Http/Query/GetEnabledPaymentMethodsQuery.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Http/Payload/CreateMandatePayload.php b/src/Http/Payload/CreateMandatePayload.php index fda0ccbfc..db799c11f 100644 --- a/src/Http/Payload/CreateMandatePayload.php +++ b/src/Http/Payload/CreateMandatePayload.php @@ -50,7 +50,7 @@ public function data(): array 'consumerAccount' => $this->consumerAccount, 'consumerBic' => $this->consumerBic, 'consumerEmail' => $this->consumerEmail, - 'signatureDate' => $this->signatureDate?->format('Y-m-d'), + 'signatureDate' => $this->signatureDate ? $this->signatureDate->format('Y-m-d') : null, 'mandateReference' => $this->mandateReference, 'paypalBillingAgreementId' => $this->paypalBillingAgreementId, ]; diff --git a/src/Http/Payload/CreatePaymentLinkPayload.php b/src/Http/Payload/CreatePaymentLinkPayload.php index c131c3411..a66c62cf5 100644 --- a/src/Http/Payload/CreatePaymentLinkPayload.php +++ b/src/Http/Payload/CreatePaymentLinkPayload.php @@ -47,7 +47,7 @@ public function data(): array 'webhookUrl' => $this->webhookUrl, 'profileId' => $this->profileId, 'reusable' => $this->reusable, - 'expiresAt' => $this->expiresAt?->format('Y-m-d'), + 'expiresAt' => $this->expiresAt ? $this->expiresAt->format('Y-m-d') : null, ]; } } diff --git a/src/Http/Payload/CreateSubscriptionPayload.php b/src/Http/Payload/CreateSubscriptionPayload.php index 648ba89a2..49769e411 100644 --- a/src/Http/Payload/CreateSubscriptionPayload.php +++ b/src/Http/Payload/CreateSubscriptionPayload.php @@ -66,7 +66,7 @@ public function data(): array 'description' => $this->description, 'status' => $this->status, 'times' => $this->times, - 'startDate' => $this->startDate?->format('Y-m-d'), + 'startDate' => $this->startDate ? $this->startDate->format('Y-m-d') : null, 'method' => $this->method, 'applicationFee' => $this->applicationFee, 'metadata' => $this->metadata, diff --git a/src/Http/Payload/UpdateSubscriptionPayload.php b/src/Http/Payload/UpdateSubscriptionPayload.php index 76cb09ad8..669f6cec0 100644 --- a/src/Http/Payload/UpdateSubscriptionPayload.php +++ b/src/Http/Payload/UpdateSubscriptionPayload.php @@ -48,7 +48,7 @@ public function data(): array 'amount' => $this->amount, 'description' => $this->description, 'interval' => $this->interval, - 'startDate' => $this->startDate?->format('Y-m-d'), + 'startDate' => $this->startDate ? $this->startDate->format('Y-m-d') : null, 'times' => $this->times, 'metadata' => $this->metadata, 'webhookUrl' => $this->webhookUrl, diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php index 85040dd59..00ef7495b 100644 --- a/src/Http/Query/GetAllMethodsQuery.php +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -35,7 +35,7 @@ public function toArray(): array $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, ]), 'locale' => $this->locale, - 'amount' => $this->amount?->data(), + 'amount' => $this->amount ? $this->amount->data() : null, ]; } } diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index 90cc6f6d3..b0f11d96a 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -26,7 +26,7 @@ public function toArray(): array return [ 'sequenceType' => $this->sequenceType, 'locale' => $this->locale, - 'amount' => $this->amount?->data(), + 'amount' => $this->amount ? $this->amount->data() : null, 'resource' => $this->resource, 'billingCountry' => $this->billingCountry, 'includeWallets' => Arr::join($this->includeWallets ?? []), From 3736cfecd0419214c6117002bcf6046ca2271520 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 3 Dec 2024 12:49:55 +0100 Subject: [PATCH 080/131] fix php7.4 compatibility --- .../Query/GetEnabledPaymentMethodsQuery.php | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index b0f11d96a..e4bf3b3b2 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -8,18 +8,40 @@ class GetEnabledPaymentMethodsQuery extends Query { + private string $sequenceType; + private string $resource; + private ?string $locale; + private ?Money $amount; + private ?string $billingCountry; + private ?array $includeWallets; + private ?array $orderLineCategories; + private ?string $profileId; + private ?bool $includeIssuers; + private ?bool $includePricing; + public function __construct( - private string $sequenceType = MethodQuery::SEQUENCE_TYPE_ONEOFF, - private string $resource = MethodQuery::RESOURCE_PAYMENTS, - private ?string $locale = null, - private ?Money $amount = null, - private ?string $billingCountry = null, - private ?array $includeWallets = null, - private ?array $orderLineCategories = null, - private ?string $profileId = null, - private ?bool $includeIssuers = null, - private ?bool $includePricing = null - ) {} + string $sequenceType = MethodQuery::SEQUENCE_TYPE_ONEOFF, + string $resource = MethodQuery::RESOURCE_PAYMENTS, + ?string $locale = null, + ?Money $amount = null, + ?string $billingCountry = null, + ?array $includeWallets = null, + ?array $orderLineCategories = null, + ?string $profileId = null, + ?bool $includeIssuers = null, + ?bool $includePricing = null + ) { + $this->sequenceType = $sequenceType; + $this->resource = $resource; + $this->locale = $locale; + $this->amount = $amount; + $this->billingCountry = $billingCountry; + $this->includeWallets = $includeWallets; + $this->orderLineCategories = $orderLineCategories; + $this->profileId = $profileId; + $this->includeIssuers = $includeIssuers; + $this->includePricing = $includePricing; + } public function toArray(): array { From d5a21501d34d8e04d675d940bd86b6fcae2b8b60 Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 3 Dec 2024 11:50:25 +0000 Subject: [PATCH 081/131] Fixes coding style --- src/Http/Query/GetEnabledPaymentMethodsQuery.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index e4bf3b3b2..83d61cacf 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -9,14 +9,23 @@ class GetEnabledPaymentMethodsQuery extends Query { private string $sequenceType; + private string $resource; + private ?string $locale; + private ?Money $amount; + private ?string $billingCountry; + private ?array $includeWallets; + private ?array $orderLineCategories; + private ?string $profileId; + private ?bool $includeIssuers; + private ?bool $includePricing; public function __construct( From 4c472c9fd28d927d6d1508e887e34eb953fa0e21 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 13:29:30 +0100 Subject: [PATCH 082/131] fix all phpstan errors --- phpstan-baseline.neon | 40 ++++++++ src/Contracts/SupportsDebuggingContract.php | 4 +- .../BalanceTransactionEndpointCollection.php | 2 +- .../ClientLinkEndpointCollection.php | 10 +- .../PaymentLinkEndpointCollection.php | 2 +- .../PaymentRouteEndpointCollection.php | 2 +- .../ProfileEndpointCollection.php | 2 +- .../SessionEndpointCollection.php | 5 +- .../SettlementEndpointCollection.php | 61 ++++-------- .../SettlementPaymentEndpointCollection.php | 5 +- .../SettlementsEndpointCollection.php | 80 ---------------- src/Endpoints/BaseEndpoint.php | 95 ------------------- src/Endpoints/EndpointCollection.php | 90 ------------------ src/Factories/CreateMandatePayloadFactory.php | 1 - src/Factories/Factory.php | 1 + .../GetEnabledPaymentMethodsQueryFactory.php | 1 - .../UpdateCustomerPayloadFactory.php | 1 - src/Helpers/Handlers.php | 2 +- src/Helpers/MiddlewareHandlers.php | 2 +- src/Http/Middleware/GuardResponse.php | 2 +- src/Http/Requests/GetOrganizationRequest.php | 9 +- .../GetPaginatedSettlementCapturesRequest.php | 2 - ...tPaginatedSettlementChargebacksRequest.php | 2 - .../GetPaginatedSettlementRefundsRequest.php | 2 - src/MollieApiClient.php | 9 +- src/Resources/AnyResource.php | 3 + src/Resources/Balance.php | 5 +- src/Resources/BalanceReport.php | 7 +- src/Resources/BalanceTransaction.php | 3 + src/Resources/BaseResource.php | 2 - src/Resources/Capture.php | 10 ++ src/Resources/Chargeback.php | 3 + src/Resources/Client.php | 3 + src/Resources/ClientLink.php | 3 + src/Resources/CurrentProfile.php | 8 +- src/Resources/Customer.php | 10 +- src/Resources/Invoice.php | 5 +- src/Resources/Issuer.php | 3 + src/Resources/Mandate.php | 8 +- src/Resources/Method.php | 3 + src/Resources/MethodPrice.php | 3 + src/Resources/Onboarding.php | 3 + src/Resources/Organization.php | 5 +- src/Resources/Partner.php | 3 + src/Resources/Payment.php | 6 +- src/Resources/PaymentLink.php | 5 +- src/Resources/Permission.php | 3 + src/Resources/Profile.php | 11 ++- src/Resources/Refund.php | 5 +- src/Resources/Route.php | 5 +- src/Resources/Session.php | 9 +- src/Resources/Settlement.php | 21 ++-- src/Resources/Subscription.php | 5 +- src/Resources/Terminal.php | 5 +- src/Traits/ComposableFromArray.php | 1 + src/Traits/HandlesDebugging.php | 9 +- src/Traits/HandlesIdempotency.php | 9 +- src/Traits/HasDefaultFactories.php | 2 +- src/Traits/HasEndpoints.php | 4 +- src/Traits/IsDebuggableAdapter.php | 4 - .../SessionEndpointCollectionTest.php | 1 - .../WalletEndpointCollectionTest.php | 6 ++ tests/Helpers/HandlersTest.php | 1 + 63 files changed, 222 insertions(+), 412 deletions(-) delete mode 100644 src/EndpointCollection/SettlementsEndpointCollection.php delete mode 100644 src/Endpoints/BaseEndpoint.php delete mode 100644 src/Endpoints/EndpointCollection.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cafdcd681..0bb3ae845 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -204,3 +204,43 @@ parameters: message: "#^Variable \\$mollie might not be defined\\.$#" count: 1 path: examples/subscriptions/update-subscription.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/CompatibilityChecker.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Http/Payload/CreateRefundPaymentPayload.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 5 + path: src/Http/Payload/DataCollection.php + + - + message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$_links\\.$#" + count: 1 + path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php + + - + message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$description\\.$#" + count: 1 + path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php + + - + message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$status\\.$#" + count: 1 + path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php + + - + message: "#^Unsafe access to private property Tests\\\\Fixtures\\\\MockResponse\\:\\:\\$factories through static\\:\\:\\.$#" + count: 4 + path: tests/Fixtures/MockResponse.php + + - + message: "#^Unsafe access to private property Tests\\\\Http\\\\Adapter\\\\MockMollieHttpAdapter\\:\\:\\$factories through static\\:\\:\\.$#" + count: 4 + path: tests/Http/Adapter/MockMollieHttpAdapter.php diff --git a/src/Contracts/SupportsDebuggingContract.php b/src/Contracts/SupportsDebuggingContract.php index 07371f257..0c67aa8bb 100644 --- a/src/Contracts/SupportsDebuggingContract.php +++ b/src/Contracts/SupportsDebuggingContract.php @@ -7,14 +7,14 @@ interface SupportsDebuggingContract /** * Enable debugging for the current request. * - * @return $this + * @return HttpAdapterContract|Connector */ public function enableDebugging(); /** * Disable debugging for the current request. * - * @return $this + * @return HttpAdapterContract|Connector */ public function disableDebugging(); } diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php index 1036c78f9..276f807fc 100644 --- a/src/EndpointCollection/BalanceTransactionEndpointCollection.php +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -63,7 +63,7 @@ public function iteratorForPrimary($query = [], bool $iterateBackwards = false, * List the transactions for a specific Balance ID. * * @param array|PaginatedQuery $query - * @param bool|null $testmode + * @param bool $testmode * * @throws \Mollie\Api\Exceptions\ApiException */ diff --git a/src/EndpointCollection/ClientLinkEndpointCollection.php b/src/EndpointCollection/ClientLinkEndpointCollection.php index 1c2e1d2c1..7db5b872b 100644 --- a/src/EndpointCollection/ClientLinkEndpointCollection.php +++ b/src/EndpointCollection/ClientLinkEndpointCollection.php @@ -13,18 +13,18 @@ class ClientLinkEndpointCollection extends EndpointCollection /** * Creates a client link in Mollie. * - * @param array $data An array containing details on the client link. + * @param array|CreateClientLinkPayload $payload An array containing details on the client link. * * @throws ApiException */ - public function create($data = []): ClientLink + public function create($payload = []): ClientLink { - if (! $data instanceof CreateClientLinkPayload) { - $data = CreateClientLinkPayloadFactory::new($data) + if (! $payload instanceof CreateClientLinkPayload) { + $payload = CreateClientLinkPayloadFactory::new($payload) ->create(); } /** @var ClientLink */ - return $this->send(new CreateClientLinkRequest($data)); + return $this->send(new CreateClientLinkRequest($payload)); } } diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index f3dd1cbb6..a09512695 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -113,7 +113,7 @@ public function page(?string $from = null, ?int $limit = null, $testmode = []): public function iterator( ?string $from = null, ?int $limit = null, - $testmode = [], + bool $testmode = false, bool $iterateBackwards = false ): LazyCollection { $testmode = Helpers::extractBool($testmode, 'testmode', false); diff --git a/src/EndpointCollection/PaymentRouteEndpointCollection.php b/src/EndpointCollection/PaymentRouteEndpointCollection.php index 2798da10e..fe2eca406 100644 --- a/src/EndpointCollection/PaymentRouteEndpointCollection.php +++ b/src/EndpointCollection/PaymentRouteEndpointCollection.php @@ -26,7 +26,7 @@ public function updateReleaseDateFor(Payment $payment, string $routeId, string $ /** * Update the release date for a payment route using payment ID. * - * @param DateTimeInterface $releaseDate UTC datetime when the funds will become available + * @param string $releaseDate UTC datetime when the funds will become available * * @throws ApiException */ diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index 8962f4c01..702b27e3d 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -77,7 +77,7 @@ public function getCurrent($testmode = []): CurrentProfile * * Will throw an ApiException if the profile id is invalid or the resource cannot be found. * - * @param array|UpdateProfilePayload $data + * @param array|UpdateProfilePayload $payload * * @throws ApiException */ diff --git a/src/EndpointCollection/SessionEndpointCollection.php b/src/EndpointCollection/SessionEndpointCollection.php index a99668056..38ed8aacb 100644 --- a/src/EndpointCollection/SessionEndpointCollection.php +++ b/src/EndpointCollection/SessionEndpointCollection.php @@ -84,10 +84,9 @@ public function update(string $id, $payload = []): Session * * @throws ApiException */ - public function cancel(string $id): ?Session + public function cancel(string $id): void { - /** @var Session|null */ - return $this->send(new CancelSessionRequest($id)); + $this->send(new CancelSessionRequest($id)); } /** diff --git a/src/EndpointCollection/SettlementEndpointCollection.php b/src/EndpointCollection/SettlementEndpointCollection.php index 0d6536a85..c24f96e64 100644 --- a/src/EndpointCollection/SettlementEndpointCollection.php +++ b/src/EndpointCollection/SettlementEndpointCollection.php @@ -3,9 +3,8 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Helpers; -use Mollie\Api\Http\Requests\GetPaginatedSettlementRequest; +use Mollie\Api\Factories\GetPaginatedSettlementsQueryFactory; +use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; @@ -16,90 +15,66 @@ class SettlementEndpointCollection extends EndpointCollection /** * Retrieve a single settlement from Mollie. * - * Will throw an ApiException if the settlement id is invalid or the resource cannot be found. - * - * @param array|bool $testmode + * Will throw a ApiException if the settlement id is invalid or the resource cannot be found. * * @throws ApiException */ - public function get(string $settlementId, $testmode = []): Settlement + public function get(string $settlementId): Settlement { - $testmode = Helpers::extractBool($testmode, 'testmode', false); - - /** @var Settlement */ - return $this->send((new GetSettlementRequest($settlementId))->test($testmode)); + return $this->send(new GetSettlementRequest($settlementId)); } /** - * Retrieve the next settlement from Mollie. - * - * @param array|bool $testmode + * Retrieve the details of the current settlement that has not yet been paid out. * * @throws ApiException */ - public function next($testmode = []): ?Settlement + public function next(): Settlement { - return $this->get('next', $testmode); + return $this->send(new GetSettlementRequest('next')); } /** - * Retrieve the open balance from Mollie. - * - * @param array|bool $testmode + * Retrieve the details of the open balance of the organization. * * @throws ApiException */ - public function open($testmode = []): ?Settlement + public function open(): Settlement { - return $this->get('open', $testmode); + return $this->send(new GetSettlementRequest('open')); } /** - * Retrieve a collection of settlements from Mollie. - * - * @param string|null $from The first settlement ID you want to include in your list. + * Retrieves a collection of Settlements from Mollie. * * @throws ApiException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); - - $query = PaginatedQueryFactory::new([ + $query = GetPaginatedSettlementsQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, ])->create(); - /** @var SettlementCollection */ - return $this->send((new GetPaginatedSettlementRequest($query))->test($testmode)); + return $this->send(new GetPaginatedSettlementsRequest($query)); } /** * Create an iterator for iterating over settlements retrieved from Mollie. - * - * @param string|null $from The first settlement ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function iterator( - ?string $from = null, - ?int $limit = null, - array $filters = [], - bool $iterateBackwards = false - ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); - - $query = PaginatedQueryFactory::new([ + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection + { + $query = GetPaginatedSettlementsQueryFactory::new([ 'from' => $from, 'limit' => $limit, 'filters' => $filters, ])->create(); return $this->send( - (new GetPaginatedSettlementRequest($query)) + (new GetPaginatedSettlementsRequest($query)) ->useIterator() ->setIterationDirection($iterateBackwards) - ->test($testmode) ); } } diff --git a/src/EndpointCollection/SettlementPaymentEndpointCollection.php b/src/EndpointCollection/SettlementPaymentEndpointCollection.php index 2f921267b..39e37b827 100644 --- a/src/EndpointCollection/SettlementPaymentEndpointCollection.php +++ b/src/EndpointCollection/SettlementPaymentEndpointCollection.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; use Mollie\Api\Helpers; -use Mollie\Api\Http\Query\GetPaginatedSettlementPaymentsQuery; use Mollie\Api\Http\Query\SortablePaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\LazyCollection; @@ -17,7 +16,7 @@ class SettlementPaymentEndpointCollection extends EndpointCollection /** * Retrieves a collection of Settlement Payments from Mollie. * - * @param array|GetPaginatedSettlementPaymentsQuery $query + * @param array|SortablePaginatedQuery $query * * @throws ApiException */ @@ -29,7 +28,7 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa /** * Retrieves a collection of Settlement Payments from Mollie. * - * @param array|GetPaginatedSettlementPaymentsQuery $query + * @param array|SortablePaginatedQuery $query * * @throws ApiException */ diff --git a/src/EndpointCollection/SettlementsEndpointCollection.php b/src/EndpointCollection/SettlementsEndpointCollection.php deleted file mode 100644 index ae02aba8c..000000000 --- a/src/EndpointCollection/SettlementsEndpointCollection.php +++ /dev/null @@ -1,80 +0,0 @@ -send(new GetSettlementRequest($settlementId)); - } - - /** - * Retrieve the details of the current settlement that has not yet been paid out. - * - * @throws ApiException - */ - public function next(): Settlement - { - return $this->send(new GetSettlementRequest('next')); - } - - /** - * Retrieve the details of the open balance of the organization. - * - * @throws ApiException - */ - public function open(): Settlement - { - return $this->send(new GetSettlementRequest('open')); - } - - /** - * Retrieves a collection of Settlements from Mollie. - * - * @throws ApiException - */ - public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection - { - $query = GetPaginatedSettlementsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - - return $this->send(new GetPaginatedSettlementsRequest($query)); - } - - /** - * Create an iterator for iterating over settlements retrieved from Mollie. - */ - public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection - { - $query = GetPaginatedSettlementsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - - return $this->send( - (new GetPaginatedSettlementsRequest($query)) - ->useIterator() - ->setIterationDirection($iterateBackwards) - ); - } -} diff --git a/src/Endpoints/BaseEndpoint.php b/src/Endpoints/BaseEndpoint.php deleted file mode 100644 index a32862fda..000000000 --- a/src/Endpoints/BaseEndpoint.php +++ /dev/null @@ -1,95 +0,0 @@ -client = $api; - } - - protected function buildQueryString(array $filters): string - { - if (empty($filters)) { - return ''; - } - - foreach ($filters as $key => $value) { - if ($value === true) { - $filters[$key] = 'true'; - } - - if ($value === false) { - $filters[$key] = 'false'; - } - } - - return '?'.http_build_query($filters, '', '&'); - } - - /** - * @throws ApiException - */ - public function getResourcePath(): string - { - if (strpos($this->resourcePath, '_') !== false) { - [$parentResource, $childResource] = explode('_', $this->resourcePath, 2); - - $this->guardAgainstMissingParentId($parentResource); - - return "$parentResource/{$this->parentId}/$childResource"; - } - - return $this->resourcePath; - } - - protected function getPathToSingleResource(string $id): string - { - if ($this instanceof SingleResourceEndpointContract) { - return $this->getResourcePath(); - } - - return "{$this->getResourcePath()}/{$id}"; - } - - protected function parseRequestBody(array $body): ?string - { - if (empty($body)) { - return null; - } - - return @json_encode($body); - } - - private function guardAgainstMissingParentId(string $parentResource): void - { - if (empty($this->parentId)) { - throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID."); - } - } -} diff --git a/src/Endpoints/EndpointCollection.php b/src/Endpoints/EndpointCollection.php deleted file mode 100644 index 6b4135ec1..000000000 --- a/src/Endpoints/EndpointCollection.php +++ /dev/null @@ -1,90 +0,0 @@ -getResourcePath().$this->buildQueryString( - $this->getMergedFilters($filters, $from, $limit) - ); - - $response = $this - ->client - ->send(new DynamicGetRequest( - $apiPath, - $this->getResourceCollectionClass(), - )); - - return $this->buildResultCollection($response->json()); - } - - /** - * Create a generator for iterating over a resource's collection using REST API calls. - * - * This function fetches paginated data from a RESTful resource endpoint and returns a generator - * that allows you to iterate through the items in the collection one by one. It supports forward - * and backward iteration, pagination, and filtering. - * - * @param string $from The first resource ID you want to include in your list. - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). - */ - protected function createIterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection - { - /** @var CursorCollection $page */ - $page = $this->fetchCollection($from, $limit, $filters); - - return $page->getAutoIterator($iterateBackwards); - } - - protected function getMergedFilters(array $filters = [], ?string $from = null, ?int $limit = null): array - { - return array_merge(['from' => $from, 'limit' => $limit], $filters); - } - - protected function buildResultCollection(object $result): BaseCollection - { - $collectionClass = $this->getResourceCollectionClass(); - - return ResourceFactory::createBaseResourceCollection( - $this->client, - static::getResourceClass(), - $result->_embedded->{$collectionClass::getCollectionResourceName()}, - $result->_links, - $collectionClass - ); - } - - /** - * Get the collection class that is used by this API endpoint. Every API endpoint uses one type of collection object. - */ - private function getResourceCollectionClass(): string - { - if (! isset(static::$resourceCollection)) { - throw new RuntimeException('The resource collection class is not set on the endpoint.'); - } - - return static::$resourceCollection; - } -} diff --git a/src/Factories/CreateMandatePayloadFactory.php b/src/Factories/CreateMandatePayloadFactory.php index fe0eeb44a..b412033bb 100644 --- a/src/Factories/CreateMandatePayloadFactory.php +++ b/src/Factories/CreateMandatePayloadFactory.php @@ -22,7 +22,6 @@ public function create(): CreateMandatePayload $this->mapIfNotNull('signatureDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('mandateReference'), $this->get('paypalBillingAgreementId'), - $this->get('testmode') ); } } diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 13b8ab907..9269bde76 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -17,6 +17,7 @@ public function __construct(array $data) public static function new(array $data): self { + /** @phpstan-ignore-next-line */ return new static($data); } diff --git a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php index 2bbed79ca..0898bd992 100644 --- a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php +++ b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php @@ -23,7 +23,6 @@ public function create(): GetEnabledPaymentMethodsQuery $this->get('profileId'), $this->get('includeIssuers', $includeIssuers), $this->get('includePricing', $includePricing), - $this->get('testmode') ); } } diff --git a/src/Factories/UpdateCustomerPayloadFactory.php b/src/Factories/UpdateCustomerPayloadFactory.php index 5870b7c3d..100247838 100644 --- a/src/Factories/UpdateCustomerPayloadFactory.php +++ b/src/Factories/UpdateCustomerPayloadFactory.php @@ -14,7 +14,6 @@ public function create(): UpdateCustomerPayload $this->get('email'), $this->get('locale'), $this->mapIfNotNull('metadata', Metadata::class), - $this->get('testmode') ); } } diff --git a/src/Helpers/Handlers.php b/src/Helpers/Handlers.php index d0081ca54..2a2a49517 100644 --- a/src/Helpers/Handlers.php +++ b/src/Helpers/Handlers.php @@ -40,7 +40,7 @@ public function getHandlers(): array /** * Execute the handlers * - * @param PendingRequest|Response $payload + * @param PendingRequest|Response|mixed $payload * @return PendingRequest|Response|ViableResponse */ public function execute($payload) diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Helpers/MiddlewareHandlers.php index e9e894fc5..ab9efe5d6 100644 --- a/src/Helpers/MiddlewareHandlers.php +++ b/src/Helpers/MiddlewareHandlers.php @@ -61,7 +61,7 @@ public function executeOnResponse(Response $response) } /** - * @param array ...$handlers + * @param array ...$handlersCollection */ public function merge(...$handlersCollection): self { diff --git a/src/Http/Middleware/GuardResponse.php b/src/Http/Middleware/GuardResponse.php index 2bca2cb20..68e76f0bd 100644 --- a/src/Http/Middleware/GuardResponse.php +++ b/src/Http/Middleware/GuardResponse.php @@ -10,7 +10,7 @@ class GuardResponse { public function __invoke(Response $response) { - if ($isEmpty = $response->isEmpty() && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { + if (($isEmpty = $response->isEmpty()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { throw new ApiException('No response body found.'); } diff --git a/src/Http/Requests/GetOrganizationRequest.php b/src/Http/Requests/GetOrganizationRequest.php index 250a99335..4d9e4a47b 100644 --- a/src/Http/Requests/GetOrganizationRequest.php +++ b/src/Http/Requests/GetOrganizationRequest.php @@ -12,8 +12,15 @@ class GetOrganizationRequest extends ResourceHydratableRequest implements Suppor public static string $targetResourceClass = Organization::class; + private string $id; + + public function __construct(string $id) + { + $this->id = $id; + } + public function resolveResourcePath(): string { - return 'organizations'; + return "organizations/{$this->id}"; } } diff --git a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php index 03788e0da..e5c2a1291 100644 --- a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php @@ -19,8 +19,6 @@ class GetPaginatedSettlementCapturesRequest extends PaginatedRequest implements private string $settlementId; - private ?GetPaginatedSettlementCapturesQuery $query; - public function __construct(string $settlementId, ?GetPaginatedSettlementCapturesQuery $query = null) { $this->settlementId = $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php index 1bfa5b996..cf196428a 100644 --- a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php @@ -19,8 +19,6 @@ class GetPaginatedSettlementChargebacksRequest extends PaginatedRequest implemen private string $settlementId; - private ?GetPaginatedSettlementChargebacksQuery $query; - public function __construct(string $settlementId, ?GetPaginatedSettlementChargebacksQuery $query = null) { $this->settlementId = $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php index c8a4a55a4..6561b2a1e 100644 --- a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php @@ -19,8 +19,6 @@ class GetPaginatedSettlementRefundsRequest extends PaginatedRequest implements I private string $settlementId; - private ?GetPaginatedSettlementRefundsQuery $query; - public function __construct(string $settlementId, ?GetPaginatedSettlementRefundsQuery $query = null) { $this->settlementId = $settlementId; diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 2e18fceb2..5f453d886 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -21,7 +21,7 @@ use Mollie\Api\EndpointCollection\OrderEndpointCollection; use Mollie\Api\EndpointCollection\OrderShipmentEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; -use Mollie\Api\EndpointCollection\OrganizationPartnerEndpoint; +use Mollie\Api\EndpointCollection\OrganizationPartnerEndpointCollection; use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; use Mollie\Api\EndpointCollection\PaymentChargebackEndpointCollection; use Mollie\Api\EndpointCollection\PaymentEndpointCollection; @@ -38,7 +38,7 @@ use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; -use Mollie\Api\EndpointCollection\SettlementsEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; @@ -57,6 +57,7 @@ use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; use Mollie\Api\Traits\SendsRequests; +use Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection; /** * @property BalanceEndpointCollection $balances @@ -74,7 +75,7 @@ * @property OnboardingEndpointCollection $onboarding * @property OrderEndpointCollection $orders * @property OrganizationEndpointCollection $organizations - * @property OrganizationPartnerEndpoint $organizationPartners + * @property OrganizationPartnerEndpointCollection $organizationPartners * @property PaymentEndpointCollection $payments * @property PaymentCaptureEndpointCollection $paymentCaptures * @property PaymentChargebackEndpointCollection $paymentChargebacks @@ -86,7 +87,7 @@ * @property ProfileEndpointCollection $profiles * @property ProfileMethodEndpointCollection $profileMethods * @property RefundEndpointCollection $refunds - * @property SettlementsEndpointCollection $settlements + * @property SettlementEndpointCollection $settlements * @property SettlementCaptureEndpointCollection $settlementCaptures * @property SettlementChargebackEndpointCollection $settlementChargebacks * @property SettlementPaymentEndpointCollection $settlementPayments diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index 775601712..d1fcb3b57 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -5,6 +5,9 @@ use Mollie\Api\Helpers\Arr; use stdClass; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class AnyResource extends BaseResource { public array $attributes = []; diff --git a/src/Resources/Balance.php b/src/Resources/Balance.php index 89b62b807..f011ff576 100644 --- a/src/Resources/Balance.php +++ b/src/Resources/Balance.php @@ -4,6 +4,9 @@ use Mollie\Api\Traits\HasMode; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Balance extends BaseResource { use HasMode; @@ -11,8 +14,6 @@ class Balance extends BaseResource /** * Resource id prefix. Used to validate resource id's. */ - public static string $resourceIdPrefix = 'bal_'; - /** * Indicates this is a balance resource. The value will always be "balance" here. * diff --git a/src/Resources/BalanceReport.php b/src/Resources/BalanceReport.php index 14c2ca3ad..505c2f699 100644 --- a/src/Resources/BalanceReport.php +++ b/src/Resources/BalanceReport.php @@ -4,6 +4,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class BalanceReport extends BaseResource { /** @@ -34,7 +37,7 @@ class BalanceReport extends BaseResource public $timeZone; /** - * The start date of the report, in YYYY-MM-DD format. The "from" date is ‘inclusive’, and in Central European Time. + * The start date of the report, in YYYY-MM-DD format. The "from" date is 'inclusive', and in Central European Time. * This means a report with for example "from: 2020-01-01" will include movements of "2020-01-01 0:00:00 CET" and * onwards. * @@ -46,7 +49,7 @@ class BalanceReport extends BaseResource public $from; /** - * The end date of the report, in YYYY-MM-DD format. The "until" date is ‘exclusive’, and in Central European Time. + * The end date of the report, in YYYY-MM-DD format. The "until" date is 'exclusive', and in Central European Time. * This means a report with for example "until: 2020-02-01" will include movements up * until "2020-01-31 23:59:59 CET". * diff --git a/src/Resources/BalanceTransaction.php b/src/Resources/BalanceTransaction.php index 42443ed26..288ffdd81 100644 --- a/src/Resources/BalanceTransaction.php +++ b/src/Resources/BalanceTransaction.php @@ -6,6 +6,9 @@ use Mollie\Api\Traits\HasMode; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class BalanceTransaction extends BaseResource { use HasMode; diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 8795427e8..6108cebc4 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -6,12 +6,10 @@ use Mollie\Api\Contracts\HasResponse; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; -use Mollie\Api\MollieApiClient; #[\AllowDynamicProperties] abstract class BaseResource implements HasResponse { - /** @var MollieApiClient */ protected Connector $connector; protected ?Response $response; diff --git a/src/Resources/Capture.php b/src/Resources/Capture.php index cd0992936..a3a65b1b5 100644 --- a/src/Resources/Capture.php +++ b/src/Resources/Capture.php @@ -4,6 +4,9 @@ use Mollie\Api\Traits\HasMode; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Capture extends BaseResource { use HasMode; @@ -29,6 +32,13 @@ class Capture extends BaseResource */ public $mode; + /** + * Description of the capture. + * + * @var string + */ + public $description; + /** * Status of the capture. * diff --git a/src/Resources/Chargeback.php b/src/Resources/Chargeback.php index 672cebc26..7ec1cb979 100644 --- a/src/Resources/Chargeback.php +++ b/src/Resources/Chargeback.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Chargeback extends BaseResource { /** diff --git a/src/Resources/Client.php b/src/Resources/Client.php index 67a9b8d6a..958a03d3b 100644 --- a/src/Resources/Client.php +++ b/src/Resources/Client.php @@ -4,6 +4,9 @@ use Mollie\Api\Contracts\EmbeddedResourcesContract; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Client extends BaseResource implements EmbeddedResourcesContract { /** diff --git a/src/Resources/ClientLink.php b/src/Resources/ClientLink.php index e2b0b79ff..a74f47c59 100644 --- a/src/Resources/ClientLink.php +++ b/src/Resources/ClientLink.php @@ -4,6 +4,9 @@ use Mollie\Api\Types\ApprovalPrompt; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class ClientLink extends BaseResource { /** diff --git a/src/Resources/CurrentProfile.php b/src/Resources/CurrentProfile.php index b75d20936..48d22f85c 100644 --- a/src/Resources/CurrentProfile.php +++ b/src/Resources/CurrentProfile.php @@ -13,9 +13,9 @@ class CurrentProfile extends Profile * * @throws ApiException */ - public function enableMethod($methodId, array $data = []): Method + public function enableMethod(string $methodId): Method { - return $this->connector->profileMethods->createForCurrentProfile($methodId, $data); + return $this->connector->profileMethods->createForCurrentProfile($methodId); } /** @@ -25,8 +25,8 @@ public function enableMethod($methodId, array $data = []): Method * * @throws ApiException */ - public function disableMethod($methodId, array $data = []): ?Method + public function disableMethod(string $methodId): void { - return $this->connector->profileMethods->deleteForCurrentProfile($methodId, $data); + $this->connector->profileMethods->deleteForCurrentProfile($methodId); } } diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index f06adfacd..58f99348e 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -5,12 +5,13 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Traits\HasMode; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Customer extends BaseResource { use HasMode; - public static string $resourceIdPrefix = 'cst_'; - /** * Id of the customer. * @@ -170,13 +171,12 @@ public function getMandate($mandateId, array $parameters = []) /** * @param string $mandateId - * @return null * * @throws ApiException */ - public function revokeMandate($mandateId) + public function revokeMandate($mandateId): void { - return $this->connector->mandates->revokeFor($this, $mandateId, $this->withMode()); + $this->connector->mandates->revokeFor($this, $mandateId, $this->withMode()); } /** diff --git a/src/Resources/Invoice.php b/src/Resources/Invoice.php index 98c2e3ee5..2a9a26922 100644 --- a/src/Resources/Invoice.php +++ b/src/Resources/Invoice.php @@ -4,10 +4,11 @@ use Mollie\Api\Types\InvoiceStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Invoice extends BaseResource { - public static string $resourceIdPrefix = 'inv_'; - /** * @var string */ diff --git a/src/Resources/Issuer.php b/src/Resources/Issuer.php index e315a689e..a3d77c731 100644 --- a/src/Resources/Issuer.php +++ b/src/Resources/Issuer.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Issuer extends BaseResource { /** diff --git a/src/Resources/Mandate.php b/src/Resources/Mandate.php index f3eeaaf68..06bab5762 100644 --- a/src/Resources/Mandate.php +++ b/src/Resources/Mandate.php @@ -5,6 +5,9 @@ use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Types\MandateStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Mandate extends BaseResource { /** @@ -33,7 +36,7 @@ class Mandate extends BaseResource public $details; /** - * @var string + * @var string|null */ public $customerId; @@ -79,7 +82,7 @@ public function isInvalid(): bool */ public function revoke(): ?Mandate { - if (! isset($this->id, $this->customerId)) { + if (! isset($this->customerId)) { return $this; } @@ -88,7 +91,6 @@ public function revoke(): ?Mandate ->send((new RevokeMandateRequest( $this->customerId, $this->id, - $this->mode === 'test' ))->test($this->mode === 'test')) ->toResource(); } diff --git a/src/Resources/Method.php b/src/Resources/Method.php index 81d8ed6a3..669eb66e9 100644 --- a/src/Resources/Method.php +++ b/src/Resources/Method.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Method extends BaseResource { /** diff --git a/src/Resources/MethodPrice.php b/src/Resources/MethodPrice.php index 80bc5fa56..697ee6a6a 100644 --- a/src/Resources/MethodPrice.php +++ b/src/Resources/MethodPrice.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class MethodPrice extends BaseResource { /** diff --git a/src/Resources/Onboarding.php b/src/Resources/Onboarding.php index a0dd94ca9..73d373cb9 100644 --- a/src/Resources/Onboarding.php +++ b/src/Resources/Onboarding.php @@ -4,6 +4,9 @@ use Mollie\Api\Types\OnboardingStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Onboarding extends BaseResource { /** diff --git a/src/Resources/Organization.php b/src/Resources/Organization.php index 60187c04d..37ea60545 100644 --- a/src/Resources/Organization.php +++ b/src/Resources/Organization.php @@ -2,13 +2,14 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Organization extends BaseResource { /** * Resource id prefix. Used to validate resource id's. */ - public static string $resourceIdPrefix = 'org_'; - /** * Id of the payment method. * diff --git a/src/Resources/Partner.php b/src/Resources/Partner.php index 2c00ac1f1..0767fbd23 100644 --- a/src/Resources/Partner.php +++ b/src/Resources/Partner.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Partner extends BaseResource { /** diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 434871230..2df5aace0 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -12,7 +12,11 @@ use Mollie\Api\Types\PaymentMethod; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; +use Mollie\Api\MollieApiClient; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Payment extends BaseResource implements EmbeddedResourcesContract { use HasMode; @@ -20,8 +24,6 @@ class Payment extends BaseResource implements EmbeddedResourcesContract /** * Resource id prefix. Used to validate resource id's. */ - public static string $resourceIdPrefix = 'tr_'; - /** * Id of the payment (on the Mollie platform). * diff --git a/src/Resources/PaymentLink.php b/src/Resources/PaymentLink.php index 524643ab1..397de6c19 100644 --- a/src/Resources/PaymentLink.php +++ b/src/Resources/PaymentLink.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class PaymentLink extends BaseResource { - public static string $resourceIdPrefix = 'pl_'; - /** * Id of the payment link (on the Mollie platform). * diff --git a/src/Resources/Permission.php b/src/Resources/Permission.php index fb140b1a8..e1a380ce1 100644 --- a/src/Resources/Permission.php +++ b/src/Resources/Permission.php @@ -2,6 +2,9 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Permission extends BaseResource { /** diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index 36b2866dc..a3786585b 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -6,6 +6,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\ProfileStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Profile extends BaseResource { /** @@ -158,9 +161,9 @@ public function methods(): MethodCollection * * @throws ApiException */ - public function enableMethod($methodId, array $data = []): Method + public function enableMethod(string $methodId): Method { - return $this->connector->profileMethods->createFor($this, $methodId, $data); + return $this->connector->profileMethods->createFor($this, $methodId); } /** @@ -170,9 +173,9 @@ public function enableMethod($methodId, array $data = []): Method * * @throws ApiException */ - public function disableMethod($methodId, array $data = []): ?Method + public function disableMethod(string $methodId): void { - return $this->connector->profileMethods->deleteFor($this, $methodId, $data); + $this->connector->profileMethods->deleteFor($this, $methodId); } /** diff --git a/src/Resources/Refund.php b/src/Resources/Refund.php index f4d2acb08..4b04186b0 100644 --- a/src/Resources/Refund.php +++ b/src/Resources/Refund.php @@ -6,12 +6,13 @@ use Mollie\Api\Traits\HasMode; use Mollie\Api\Types\RefundStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Refund extends BaseResource { use HasMode; - public static string $resourceIdPrefix = 're_'; - /** * Id of the payment method. * diff --git a/src/Resources/Route.php b/src/Resources/Route.php index a2bfa8331..30c12743f 100644 --- a/src/Resources/Route.php +++ b/src/Resources/Route.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Resources; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Route extends BaseResource { - public static string $resourceIdPrefix = 'rt_'; - /** * Id of the payment method. * diff --git a/src/Resources/Session.php b/src/Resources/Session.php index 01d71483c..3f8140875 100644 --- a/src/Resources/Session.php +++ b/src/Resources/Session.php @@ -5,6 +5,9 @@ use Mollie\Api\Traits\HasMode; use Mollie\Api\Types\SessionStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Session extends BaseResource { use HasMode; @@ -160,13 +163,11 @@ public function update() /** * Cancels this session. * - * @return Session - * * @throws \Mollie\Api\Exceptions\ApiException */ - public function cancel() + public function cancel(): void { - return $this->connector->sessions->cancel($this->id, $this->withMode()); + $this->connector->sessions->cancel($this->id); } /** diff --git a/src/Resources/Settlement.php b/src/Resources/Settlement.php index 9dd9f0389..5d5f96fef 100644 --- a/src/Resources/Settlement.php +++ b/src/Resources/Settlement.php @@ -5,10 +5,11 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Types\SettlementStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Settlement extends BaseResource { - public static string $resourceIdPrefix = 'stl_'; - /** * Id of the settlement. * @@ -115,9 +116,7 @@ public function payments(?int $limit = null, array $parameters = []): PaymentCol { return $this->connector->settlementPayments->pageForId( $this->id, - null, - $limit, - $parameters + array_merge($parameters, ['limit' => $limit]) ); } @@ -130,9 +129,7 @@ public function refunds(?int $limit = null, array $parameters = []): RefundColle { return $this->connector->settlementRefunds->pageForId( $this->id, - null, - $limit, - $parameters + array_merge($parameters, ['limit' => $limit]) ); } @@ -145,9 +142,7 @@ public function chargebacks(?int $limit = null, array $parameters = []): Chargeb { return $this->connector->settlementChargebacks->pageForId( $this->id, - null, - $limit, - $parameters + array_merge($parameters, ['limit' => $limit]) ); } @@ -160,9 +155,7 @@ public function captures(?int $limit = null, array $parameters = []): CaptureCol { return $this->connector->settlementCaptures->pageForId( $this->id, - null, - $limit, - $parameters + array_merge($parameters, ['limit' => $limit]) ); } } diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index 2cd447e81..a2dde239f 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -6,10 +6,11 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Types\SubscriptionStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Subscription extends BaseResource { - public static string $resourceIdPrefix = 'sub_'; - /** * @var string */ diff --git a/src/Resources/Terminal.php b/src/Resources/Terminal.php index e419a3ec7..b1c7baf9e 100644 --- a/src/Resources/Terminal.php +++ b/src/Resources/Terminal.php @@ -4,10 +4,11 @@ use Mollie\Api\Types\TerminalStatus; +/** + * @property \Mollie\Api\MollieApiClient $connector + */ class Terminal extends BaseResource { - public static string $resourceIdPrefix = 'term_'; - /** * @var string */ diff --git a/src/Traits/ComposableFromArray.php b/src/Traits/ComposableFromArray.php index 4f9fe50a4..6ddad919c 100644 --- a/src/Traits/ComposableFromArray.php +++ b/src/Traits/ComposableFromArray.php @@ -6,6 +6,7 @@ trait ComposableFromArray { public static function fromArray(array $data = []): self { + /** @phpstan-ignore-next-line */ return new static(...$data); } } diff --git a/src/Traits/HandlesDebugging.php b/src/Traits/HandlesDebugging.php index f30e98e43..9cd4bec07 100644 --- a/src/Traits/HandlesDebugging.php +++ b/src/Traits/HandlesDebugging.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Traits; +use Mollie\Api\Contracts\Connector; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; @@ -15,9 +16,11 @@ trait HandlesDebugging * * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException */ - public function enableDebugging(): void + public function enableDebugging(): Connector { $this->setDebugging(true); + + return $this; } /** @@ -25,9 +28,11 @@ public function enableDebugging(): void * * @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException */ - public function disableDebugging(): void + public function disableDebugging(): Connector { $this->setDebugging(false); + + return $this; } /** diff --git a/src/Traits/HandlesIdempotency.php b/src/Traits/HandlesIdempotency.php index bb8bbef72..736f7e6a1 100644 --- a/src/Traits/HandlesIdempotency.php +++ b/src/Traits/HandlesIdempotency.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Traits; use Mollie\Api\Contracts\IdempotencyKeyGeneratorContract; +use Mollie\Api\Contracts\Connector; /** * @mixin \Mollie\Api\MollieApiClient @@ -59,10 +60,10 @@ public function resetIdempotencyKey(): self } /** - * @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator - * @return \Mollie\Api\Contracts\Connector + * @param IdempotencyKeyGeneratorContract $generator + * @return $this */ - public function setIdempotencyKeyGenerator($generator): self + public function setIdempotencyKeyGenerator(IdempotencyKeyGeneratorContract $generator): self { $this->idempotencyKeyGenerator = $generator; @@ -70,7 +71,7 @@ public function setIdempotencyKeyGenerator($generator): self } /** - * @return \Mollie\Api\Contracts\Connector + * @return $this */ public function clearIdempotencyKeyGenerator(): self { diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php index 5dc03e213..cf2a4716c 100644 --- a/src/Traits/HasDefaultFactories.php +++ b/src/Traits/HasDefaultFactories.php @@ -11,7 +11,7 @@ trait HasDefaultFactories public function factories(): Factories { - if (static::$factories) { + if (isset(static::$factories) && static::$factories !== null) { return static::$factories; } diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 8d9cfb206..9d3039146 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -33,7 +33,7 @@ use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; -use Mollie\Api\EndpointCollection\SettlementsEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; @@ -87,7 +87,7 @@ protected function initializeHasEndpoints(): void 'settlementChargebacks' => SettlementChargebackEndpointCollection::class, 'settlementPayments' => SettlementPaymentEndpointCollection::class, 'settlementRefunds' => SettlementRefundEndpointCollection::class, - 'settlements' => SettlementsEndpointCollection::class, + 'settlements' => SettlementEndpointCollection::class, 'subscriptions' => SubscriptionEndpointCollection::class, 'subscriptionPayments' => SubscriptionPaymentEndpointCollection::class, 'terminals' => TerminalEndpointCollection::class, diff --git a/src/Traits/IsDebuggableAdapter.php b/src/Traits/IsDebuggableAdapter.php index 21fa593ad..d57c1469a 100644 --- a/src/Traits/IsDebuggableAdapter.php +++ b/src/Traits/IsDebuggableAdapter.php @@ -15,8 +15,6 @@ trait IsDebuggableAdapter * Enable debugging. If debugging mode is enabled, the request will * be included in the ApiException. By default, debugging is disabled to prevent * sensitive request data from leaking into exception logs. - * - * @return $this */ public function enableDebugging(): HttpAdapterContract { @@ -29,8 +27,6 @@ public function enableDebugging(): HttpAdapterContract * Disable debugging. If debugging mode is enabled, the request will * be included in the ApiException. By default, debugging is disabled to prevent * sensitive request data from leaking into exception logs. - * - * @return $this */ public function disableDebugging(): HttpAdapterContract { diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index 9f7d2398b..663a1fa1e 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -113,7 +113,6 @@ protected function assertSession(Session $session) $this->assertEquals('session', $session->resource); $this->assertNotEmpty($session->id); $this->assertNotEmpty($session->mode); - $this->assertNotEmpty($session->createdAt); $this->assertNotEmpty($session->status); $this->assertNotEmpty($session->amount); $this->assertNotEmpty($session->description); diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index f3be60d21..eb9f5e11a 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -26,11 +26,17 @@ public function request_apple_pay_payment_session() ); $this->assertInstanceOf(AnyResource::class, $applePaySession); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->domainName); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->displayName); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->merchantIdentifier); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->merchantSessionIdentifier); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->nonce); + /** @phpstan-ignore-next-line */ $this->assertNotEmpty($applePaySession->signature); } } diff --git a/tests/Helpers/HandlersTest.php b/tests/Helpers/HandlersTest.php index 218918d07..8eab87014 100644 --- a/tests/Helpers/HandlersTest.php +++ b/tests/Helpers/HandlersTest.php @@ -41,6 +41,7 @@ public function handlers_are_executed_in_the_correct_order(): void $this->assertCount(3, $handlers->getHandlers()); + /** @var TestViableResponse $response */ $response = $handlers->execute($output); $this->assertInstanceOf(TestViableResponse::class, $response); From fa4577459147a85a1be0d8ba8dbd9a9b0df13da1 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 4 Dec 2024 12:30:10 +0000 Subject: [PATCH 083/131] Fixes coding style --- .../BalanceTransactionEndpointCollection.php | 1 - src/EndpointCollection/PaymentLinkEndpointCollection.php | 1 - src/EndpointCollection/PaymentRouteEndpointCollection.php | 1 - src/MollieApiClient.php | 4 ++-- src/Resources/CurrentProfile.php | 2 -- src/Resources/Payment.php | 1 - src/Resources/Profile.php | 2 -- src/Traits/HandlesIdempotency.php | 2 -- src/Traits/HasEndpoints.php | 2 +- 9 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php index 276f807fc..40d2ee042 100644 --- a/src/EndpointCollection/BalanceTransactionEndpointCollection.php +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -63,7 +63,6 @@ public function iteratorForPrimary($query = [], bool $iterateBackwards = false, * List the transactions for a specific Balance ID. * * @param array|PaginatedQuery $query - * @param bool $testmode * * @throws \Mollie\Api\Exceptions\ApiException */ diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index a09512695..e6df50433 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -107,7 +107,6 @@ public function page(?string $from = null, ?int $limit = null, $testmode = []): * Create an iterator for iterating over payment links retrieved from Mollie. * * @param string|null $from The first resource ID you want to include in your list. - * @param bool $testmode * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iterator( diff --git a/src/EndpointCollection/PaymentRouteEndpointCollection.php b/src/EndpointCollection/PaymentRouteEndpointCollection.php index fe2eca406..20522e3f5 100644 --- a/src/EndpointCollection/PaymentRouteEndpointCollection.php +++ b/src/EndpointCollection/PaymentRouteEndpointCollection.php @@ -2,7 +2,6 @@ namespace Mollie\Api\EndpointCollection; -use DateTimeInterface; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\UpdatePaymentRoutePayloadFactory; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 5f453d886..77b75bbcf 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -8,6 +8,7 @@ use Mollie\Api\Contracts\MollieHttpAdapterPickerContract; use Mollie\Api\EndpointCollection\BalanceEndpointCollection; use Mollie\Api\EndpointCollection\BalanceReportEndpointCollection; +use Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection; use Mollie\Api\EndpointCollection\ChargebackEndpointCollection; use Mollie\Api\EndpointCollection\ClientEndpointCollection; use Mollie\Api\EndpointCollection\ClientLinkEndpointCollection; @@ -36,9 +37,9 @@ use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; -use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; @@ -57,7 +58,6 @@ use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; use Mollie\Api\Traits\SendsRequests; -use Mollie\Api\EndpointCollection\BalanceTransactionEndpointCollection; /** * @property BalanceEndpointCollection $balances diff --git a/src/Resources/CurrentProfile.php b/src/Resources/CurrentProfile.php index 48d22f85c..de28f45c3 100644 --- a/src/Resources/CurrentProfile.php +++ b/src/Resources/CurrentProfile.php @@ -9,7 +9,6 @@ class CurrentProfile extends Profile /** * Enable a payment method for this profile. * - * @param string $methodId * * @throws ApiException */ @@ -21,7 +20,6 @@ public function enableMethod(string $methodId): Method /** * Disable a payment method for this profile. * - * @param string $methodId * * @throws ApiException */ diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 2df5aace0..f79340578 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -12,7 +12,6 @@ use Mollie\Api\Types\PaymentMethod; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; -use Mollie\Api\MollieApiClient; /** * @property \Mollie\Api\MollieApiClient $connector diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index a3786585b..d5973b284 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -157,7 +157,6 @@ public function methods(): MethodCollection /** * Enable a payment method for this profile. * - * @param string $methodId * * @throws ApiException */ @@ -169,7 +168,6 @@ public function enableMethod(string $methodId): Method /** * Disable a payment method for this profile. * - * @param string $methodId * * @throws ApiException */ diff --git a/src/Traits/HandlesIdempotency.php b/src/Traits/HandlesIdempotency.php index 736f7e6a1..aa9251cde 100644 --- a/src/Traits/HandlesIdempotency.php +++ b/src/Traits/HandlesIdempotency.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Traits; use Mollie\Api\Contracts\IdempotencyKeyGeneratorContract; -use Mollie\Api\Contracts\Connector; /** * @mixin \Mollie\Api\MollieApiClient @@ -60,7 +59,6 @@ public function resetIdempotencyKey(): self } /** - * @param IdempotencyKeyGeneratorContract $generator * @return $this */ public function setIdempotencyKeyGenerator(IdempotencyKeyGeneratorContract $generator): self diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 9d3039146..b13f653f9 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -31,9 +31,9 @@ use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; +use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SettlementPaymentEndpointCollection; use Mollie\Api\EndpointCollection\SettlementRefundEndpointCollection; -use Mollie\Api\EndpointCollection\SettlementEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionEndpointCollection; use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; From 25aefc7b28afafd99a4fab69f5ddc64cc1a23c7f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 13:37:11 +0100 Subject: [PATCH 084/131] fix all phpstan errors, this time for sure :fire: --- composer.json | 2 +- phpstan-baseline.neon | 211 +++++++++++++----- src/Http/Adapter/CurlMollieHttpAdapter.php | 4 - src/MollieApiClient.php | 4 - src/Resources/Payment.php | 2 +- src/Traits/HasDefaultFactories.php | 2 +- .../Adapter/GuzzleMollieHttpAdapterTest.php | 1 - tests/Http/Middleware/GuardResponseTest.php | 3 - 8 files changed, 163 insertions(+), 66 deletions(-) diff --git a/composer.json b/composer.json index 81790c527..fb2fce4e7 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.6" }, "suggest": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0bb3ae845..6bc67aa4e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,246 +1,355 @@ parameters: ignoreErrors: - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/create-capture.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/get-capture.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/captures/list-captures.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/client-links/create-client-link.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-first-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer-recurring-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/create-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/delete-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/list-customer-payments.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/customers/update-customer.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/invoices/list-invoices.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/create-mandate.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/list-mandates.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/mandates/revoke-mandate.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/pagination/backwards.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/pagination/basic_usage.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payment-links/create-payment-link.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payment-links/list-payment-links.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/create-capturable-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/payments/create-ideal-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 2 path: examples/payments/create-payment-oauth.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/create-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/list-methods.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/list-payments.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/refund-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/return.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/update-payment.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/payments/webhook.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/create-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/delete-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/list-profiles.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/profiles/update-profile.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/cancel-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/create-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/list-sessions.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/sessions/update-session.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/settlements/list-settlements.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/cancel-subscription.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/create-subscription.php - - message: "#^Variable \\$mollie might not be defined\\.$#" + message: '#^Variable \$mollie might not be defined\.$#' + identifier: variable.undefined count: 1 path: examples/subscriptions/update-subscription.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 1 path: src/CompatibilityChecker.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 1 path: src/Http/Payload/CreateRefundPaymentPayload.php - - message: "#^Unsafe usage of new static\\(\\)\\.$#" + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static count: 5 path: src/Http/Payload/DataCollection.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$_links\\.$#" + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/CustomerEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/MandateEndpointCollectionTest.php + + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$_links\.$#' + identifier: property.notFound + count: 1 + path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php + + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$description\.$#' + identifier: property.notFound count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$description\\.$#" + message: '#^Access to an undefined property Mollie\\Api\\Resources\\Issuer\:\:\$status\.$#' + identifier: property.notFound count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Access to an undefined property Mollie\\\\Api\\\\Resources\\\\Issuer\\:\\:\\$status\\.$#" + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType count: 1 path: tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php - - message: "#^Unsafe access to private property Tests\\\\Fixtures\\\\MockResponse\\:\\:\\$factories through static\\:\\:\\.$#" - count: 4 + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/ProfileEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 2 + path: tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/SessionEndpointCollectionTest.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/SubscriptionEndpointCollectionTest.php + + - + message: '#^Unsafe access to private property Tests\\Fixtures\\MockResponse\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 path: tests/Fixtures/MockResponse.php - - message: "#^Unsafe access to private property Tests\\\\Http\\\\Adapter\\\\MockMollieHttpAdapter\\:\\:\\$factories through static\\:\\:\\.$#" - count: 4 + message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 path: tests/Http/Adapter/MockMollieHttpAdapter.php + + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/Http/Middleware/GuardResponseTest.php diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index dc394df38..8a0a1dd8a 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -53,10 +53,6 @@ public function sendRequest(PendingRequest $pendingRequest): Response return $this->createResponse($pendingRequest, 504, [], null, $e); } } - - throw new CurlConnectTimeoutException( - 'Unable to connect to Mollie. Maximum number of retries ('.self::MAX_RETRIES.') reached.' - ); } protected function createResponse(PendingRequest $pendingRequest, int $statusCode, $headers = [], $body = null, ?Throwable $error = null): Response diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 77b75bbcf..02747e766 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -19,8 +19,6 @@ use Mollie\Api\EndpointCollection\MethodEndpointCollection; use Mollie\Api\EndpointCollection\MethodIssuerEndpointCollection; use Mollie\Api\EndpointCollection\OnboardingEndpointCollection; -use Mollie\Api\EndpointCollection\OrderEndpointCollection; -use Mollie\Api\EndpointCollection\OrderShipmentEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationEndpointCollection; use Mollie\Api\EndpointCollection\OrganizationPartnerEndpointCollection; use Mollie\Api\EndpointCollection\PaymentCaptureEndpointCollection; @@ -73,7 +71,6 @@ * @property MethodEndpointCollection $methods * @property MethodIssuerEndpointCollection $methodIssuers * @property OnboardingEndpointCollection $onboarding - * @property OrderEndpointCollection $orders * @property OrganizationEndpointCollection $organizations * @property OrganizationPartnerEndpointCollection $organizationPartners * @property PaymentEndpointCollection $payments @@ -92,7 +89,6 @@ * @property SettlementChargebackEndpointCollection $settlementChargebacks * @property SettlementPaymentEndpointCollection $settlementPayments * @property SettlementRefundEndpointCollection $settlementRefunds - * @property OrderShipmentEndpointCollection $shipments * @property SubscriptionEndpointCollection $subscriptions * @property SubscriptionPaymentEndpointCollection $subscriptionPayments * @property TerminalEndpointCollection $terminals diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index f79340578..fa4f7e895 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -289,7 +289,7 @@ class Payment extends BaseResource implements EmbeddedResourcesContract /** * Used to restrict the payment methods available to your customer to those from a single country. * - * @var string|null; + * @var string|null */ public $restrictPaymentMethodsToCountry; diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php index cf2a4716c..5dc03e213 100644 --- a/src/Traits/HasDefaultFactories.php +++ b/src/Traits/HasDefaultFactories.php @@ -11,7 +11,7 @@ trait HasDefaultFactories public function factories(): Factories { - if (isset(static::$factories) && static::$factories !== null) { + if (static::$factories) { return static::$factories; } diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index 0ef3d9217..a3b93d311 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -20,7 +20,6 @@ class GuzzleMollieHttpAdapterTest extends TestCase public function test_debugging_is_supported() { $adapter = GuzzleMollieHttpAdapter::createDefault(); - $this->assertTrue($adapter instanceof SupportsDebuggingContract); $this->assertFalse($adapter->debuggingIsActive()); $adapter->enableDebugging(); diff --git a/tests/Http/Middleware/GuardResponseTest.php b/tests/Http/Middleware/GuardResponseTest.php index ed4b1ecf2..148e45725 100644 --- a/tests/Http/Middleware/GuardResponseTest.php +++ b/tests/Http/Middleware/GuardResponseTest.php @@ -57,9 +57,6 @@ public function it_does_not_throw_exception_if_http_no_content(): void // No exception should be thrown $guardResponse($responseMock); - - // If the test reaches here without exceptions, it passes - $this->assertTrue(true); } /** From 81deec07cf9258b499a09d35f94140fdfe1bc226 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 4 Dec 2024 12:37:53 +0000 Subject: [PATCH 085/131] Fixes coding style --- tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index a3b93d311..a43226d3d 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -5,7 +5,6 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\Request; -use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\PendingRequest; From b448e2f52b80973fe1673e6c86cf96d9289a0db6 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 15:07:54 +0100 Subject: [PATCH 086/131] wip --- phpstan-baseline.neon | 1116 +++++++++++++++++ .../GetPaginatedChargebackQueryFactory.php | 12 +- .../GetPaginatedInvoiceQueryFactory.php | 11 +- src/Resources/AnyResource.php | 6 +- tests/Http/Adapter/MockMollieHttpAdapter.php | 6 +- 5 files changed, 1127 insertions(+), 24 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6bc67aa4e..a15d51f0b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -252,6 +252,1122 @@ parameters: count: 1 path: src/CompatibilityChecker.php + - + message: '#^Parameter \#1 \$domain of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/ApplePayPaymentSessionPayloadFactory.php + + - + message: '#^Parameter \#2 \$validationUrl of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/ApplePayPaymentSessionPayloadFactory.php + + - + message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/ApplePayPaymentSessionPayloadFactory.php + + - + message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Http\\Payload\\Owner\:\:fromArray\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateClientLinkPayloadFactory.php + + - + message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Http\\Payload\\OwnerAddress\:\:fromArray\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateClientLinkPayloadFactory.php + + - + message: '#^Parameter \#2 \$name of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateClientLinkPayloadFactory.php + + - + message: '#^Parameter \#4 \$registrationNumber of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateClientLinkPayloadFactory.php + + - + message: '#^Parameter \#5 \$vatNumber of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateClientLinkPayloadFactory.php + + - + message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateCustomerPayloadFactory.php + + - + message: '#^Parameter \#2 \$email of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateCustomerPayloadFactory.php + + - + message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateCustomerPayloadFactory.php + + - + message: '#^Parameter \#4 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateCustomerPayloadFactory.php + + - + message: '#^Parameter \#1 \$method of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#2 \$consumerName of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#3 \$consumerAccount of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#4 \$consumerBic of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#5 \$consumerEmail of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#6 \$signatureDate of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#7 \$mandateReference of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#8 \$paypalBillingAgreementId of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateMandatePayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentCapturePayloadFactory.php + + - + message: '#^Parameter \#2 \$amount of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentCapturePayloadFactory.php + + - + message: '#^Parameter \#3 \$metadata of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentCapturePayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#2 \$amount of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#3 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#4 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#5 \$profileId of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#6 \$reusable of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#7 \$expiresAt of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentLinkPayloadFactory.php + + - + message: '#^Expression on left side of \?\? is not nullable\.$#' + identifier: nullCoalesce.expr + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#10 \$method of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#11 \$issuer of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#12 \$restrictPaymentMethodsToCountry of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#13 \$metadata of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#14 \$captureMode of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#15 \$captureDelay of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#16 \$applicationFee of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\ApplicationFee\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#17 \$routing of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#18 \$sequenceType of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#19 \$mandateId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#20 \$customerId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#21 \$profileId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#22 \$additional of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#3 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#4 \$cancelUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#5 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#6 \$lines of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#7 \$billingAddress of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Address\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#8 \$shippingAddress of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Address\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#9 \$locale of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreatePaymentPayloadFactory.php + + - + message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#2 \$website of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#3 \$email of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#4 \$phone of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#5 \$description of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#6 \$countriesOfActivity of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#7 \$businessCategory of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateProfilePayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateRefundPaymentPayloadFactory.php + + - + message: '#^Parameter \#3 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateRefundPaymentPayloadFactory.php + + - + message: '#^Parameter \#4 \$reverseRouting of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateRefundPaymentPayloadFactory.php + + - + message: '#^Parameter \#5 \$routingReversals of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateRefundPaymentPayloadFactory.php + + - + message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#10 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#11 \$mandateId of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#12 \$profileId of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#2 \$interval of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#3 \$description of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#4 \$status of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#5 \$times of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#6 \$startDate of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#7 \$method of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#8 \$applicationFee of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\ApplicationFee\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#9 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/CreateSubscriptionPayloadFactory.php + + - + message: '#^Method Mollie\\Api\\Factories\\Factory\:\:get\(\) has invalid return type Mollie\\Api\\Factories\\mixed\.$#' + identifier: class.notFound + count: 1 + path: src/Factories/Factory.php + + - + message: '#^Method Mollie\\Api\\Factories\\Factory\:\:mapIfNotNull\(\) has invalid return type Mollie\\Api\\Factories\\mixed\.$#' + identifier: class.notFound + count: 1 + path: src/Factories/Factory.php + + - + message: '#^PHPDoc tag @return with type mixed is not subtype of native type Mollie\\Api\\Factories\\mixed\.$#' + identifier: return.phpDocType + count: 1 + path: src/Factories/Factory.php + + - + message: '#^Parameter \#2 \$profileId of class Mollie\\Api\\Http\\Query\\GetAllPaginatedSubscriptionsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php + + - + message: '#^Parameter \#1 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetAllPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#2 \$includePricing of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetAllPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetAllPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#4 \$amount of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetAllPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#2 \$datetime of static method DateTimeImmutable\:\:createFromFormat\(\) expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Factories/GetBalanceReportQueryFactory.php + + - + message: '#^Parameter \#3 \$grouping of class Mollie\\Api\\Http\\Query\\GetBalanceReportQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetBalanceReportQueryFactory.php + + - + message: '#^Parameter \#1 \$embedOrganization of class Mollie\\Api\\Http\\Query\\GetClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetClientQueryFactory.php + + - + message: '#^Parameter \#2 \$embedOnboarding of class Mollie\\Api\\Http\\Query\\GetClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetClientQueryFactory.php + + - + message: '#^Parameter \#1 \$sequenceType of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#10 \$includePricing of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#2 \$resource of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#4 \$amount of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#5 \$billingCountry of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#6 \$includeWallets of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#7 \$orderLineCategories of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#8 \$profileId of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#9 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php + + - + message: '#^Parameter \#2 \$currency of class Mollie\\Api\\Http\\Query\\GetPaginatedBalanceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedBalanceQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedChargebackQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedChargebackQueryFactory.php + + - + message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedChargebackQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedChargebackQueryFactory.php + + - + message: '#^Parameter \#2 \$embedOrganization of class Mollie\\Api\\Http\\Query\\GetPaginatedClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedClientQueryFactory.php + + - + message: '#^Parameter \#3 \$embedOnboarding of class Mollie\\Api\\Http\\Query\\GetPaginatedClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedClientQueryFactory.php + + - + message: '#^Parameter \#2 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedCustomerPaymentsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php + + - + message: '#^Parameter \#2 \$reference of class Mollie\\Api\\Http\\Query\\GetPaginatedInvoiceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedInvoiceQueryFactory.php + + - + message: '#^Parameter \#3 \$year of class Mollie\\Api\\Http\\Query\\GetPaginatedInvoiceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedInvoiceQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentCapturesQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedPaymentCapturesQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentChargebacksQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentRefundQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedPaymentRefundQueryFactory.php + + - + message: '#^Parameter \#2 \$embedPayment of class Mollie\\Api\\Http\\Query\\GetPaginatedRefundsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedRefundsQueryFactory.php + + - + message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedRefundsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedRefundsQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementCapturesQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedSettlementCapturesQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementChargebacksQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php + + - + message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementChargebacksQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php + + - + message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementRefundsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedSettlementRefundsQueryFactory.php + + - + message: '#^Parameter \#2 \$balanceId of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaginatedSettlementsQueryFactory.php + + - + message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentCaptureQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentCaptureQueryFactory.php + + - + message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentChargebackQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentChargebackQueryFactory.php + + - + message: '#^Parameter \#1 \$locale of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentMethodQueryFactory.php + + - + message: '#^Parameter \#2 \$currency of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentMethodQueryFactory.php + + - + message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentMethodQueryFactory.php + + - + message: '#^Parameter \#4 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentMethodQueryFactory.php + + - + message: '#^Parameter \#5 \$includePricing of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentMethodQueryFactory.php + + - + message: '#^Parameter \#1 \$embedCaptures of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentQueryFactory.php + + - + message: '#^Parameter \#2 \$embedRefunds of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentQueryFactory.php + + - + message: '#^Parameter \#3 \$embedChargebacks of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentQueryFactory.php + + - + message: '#^Parameter \#4 \$includeQrCode of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentQueryFactory.php + + - + message: '#^Parameter \#5 \$includeRemainderDetails of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentQueryFactory.php + + - + message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentRefundQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/GetPaymentRefundQueryFactory.php + + - + message: '#^Parameter \#1 \$currency of class Mollie\\Api\\Http\\Payload\\Money constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/MoneyFactory.php + + - + message: '#^Parameter \#2 \$value of class Mollie\\Api\\Http\\Payload\\Money constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/MoneyFactory.php + + - + message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#10 \$vatAmount of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#11 \$sku of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#12 \$imageUrl of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#13 \$productUrl of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#2 \$quantity of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects int, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#5 \$type of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#6 \$quantityUnit of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#7 \$discountAmount of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#8 \$recurring of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\RecurringBillingCycle\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#9 \$vatRate of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/OrderLineFactory.php + + - + message: '#^Parameter \#1 \$from of class Mollie\\Api\\Http\\Query\\PaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/PaginatedQueryFactory.php + + - + message: '#^Parameter \#2 \$limit of class Mollie\\Api\\Http\\Query\\PaginatedQuery constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/PaginatedQueryFactory.php + + - + message: '#^Parameter \#1 \$interval of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/RecurringBillingCycleFactory.php + + - + message: '#^Parameter \#2 \$description of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/RecurringBillingCycleFactory.php + + - + message: '#^Parameter \#3 \$amount of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/RecurringBillingCycleFactory.php + + - + message: '#^Parameter \#4 \$times of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/RecurringBillingCycleFactory.php + + - + message: '#^Parameter \#5 \$startDate of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/RecurringBillingCycleFactory.php + + - + message: '#^Parameter \#1 \$from of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/SortablePaginatedQueryFactory.php + + - + message: '#^Parameter \#2 \$limit of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/SortablePaginatedQueryFactory.php + + - + message: '#^Parameter \#3 \$sort of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/SortablePaginatedQueryFactory.php + + - + message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateCustomerPayloadFactory.php + + - + message: '#^Parameter \#2 \$email of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateCustomerPayloadFactory.php + + - + message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateCustomerPayloadFactory.php + + - + message: '#^Parameter \#4 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateCustomerPayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\UpdatePaymentLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentLinkPayloadFactory.php + + - + message: '#^Parameter \#2 \$archived of class Mollie\\Api\\Http\\Payload\\UpdatePaymentLinkPayload constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentLinkPayloadFactory.php + + - + message: '#^Expression on left side of \?\? is not nullable\.$#' + identifier: nullCoalesce.expr + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#2 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#3 \$cancelUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#4 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#5 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#6 \$method of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#7 \$locale of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#8 \$restrictPaymentMethodsToCountry of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#9 \$additional of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects array, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentPayloadFactory.php + + - + message: '#^Parameter \#2 \$datetime of static method DateTimeImmutable\:\:createFromFormat\(\) expects string, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdatePaymentRoutePayloadFactory.php + + - + message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#2 \$website of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#3 \$email of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#4 \$phone of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#5 \$description of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#6 \$countriesOfActivity of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#7 \$businessCategory of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#8 \$mode of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateProfilePayloadFactory.php + + - + message: '#^Parameter \#1 \$amount of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#2 \$description of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#3 \$interval of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#4 \$startDate of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#5 \$times of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#6 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#7 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + + - + message: '#^Parameter \#8 \$mandateId of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Factories/UpdateSubscriptionPayloadFactory.php + - message: '#^Unsafe usage of new static\(\)\.$#' identifier: new.static diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php index 6c47e1015..2b342f9d5 100644 --- a/src/Factories/GetPaginatedChargebackQueryFactory.php +++ b/src/Factories/GetPaginatedChargebackQueryFactory.php @@ -6,18 +6,10 @@ class GetPaginatedChargebackQueryFactory extends Factory { - private PaginatedQueryFactory $paginatedQueryFactory; - - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - $this->paginatedQueryFactory = new PaginatedQueryFactory($attributes); - } - - public function create(): GetPaginatedChargebackQuery + public function create(): GetPaginatedChargebackQuery { return new GetPaginatedChargebackQuery( - $this->paginatedQueryFactory->create(), + PaginatedQueryFactory::new($this->data)->create(), $this->get('includePayment', false), $this->get('profileId') ); diff --git a/src/Factories/GetPaginatedInvoiceQueryFactory.php b/src/Factories/GetPaginatedInvoiceQueryFactory.php index b33e04ed9..b4a2ccc01 100644 --- a/src/Factories/GetPaginatedInvoiceQueryFactory.php +++ b/src/Factories/GetPaginatedInvoiceQueryFactory.php @@ -6,22 +6,13 @@ class GetPaginatedInvoiceQueryFactory extends Factory { - private PaginatedQueryFactory $paginatedQueryFactory; - - public function __construct(array $attributes = []) - { - parent::__construct($attributes); - - $this->paginatedQueryFactory = new PaginatedQueryFactory($attributes); - } - public function create(): GetPaginatedInvoiceQuery { $reference = $this->get('filters.reference'); $year = $this->get('filters.year'); return new GetPaginatedInvoiceQuery( - $this->paginatedQueryFactory->create(), + PaginatedQueryFactory::new($this->data)->create(), $this->get('reference', $reference), $this->get('year', $year) ); diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index d1fcb3b57..6101059ac 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -12,7 +12,11 @@ class AnyResource extends BaseResource { public array $attributes = []; - public function __get(string $name): mixed + /** + * @param string $name + * @return mixed + */ + public function __get(string $name) { return Arr::get($this->attributes, $name); } diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 225b3b72f..a54a2d5b4 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -29,11 +29,11 @@ public function __construct(array $expectedResponses = []) */ public function sendRequest(PendingRequest $pendingRequest): Response { - if (! Arr::has($this->expectedResponses, $pendingRequest->getRequest()::class)) { - throw new \RuntimeException('The request class '.$pendingRequest->getRequest()::class.' is not expected.'); + if (! Arr::has($this->expectedResponses, $requestClass = get_class($pendingRequest->getRequest()))) { + throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); } - $mockedResponse = $this->expectedResponses[$pendingRequest->getRequest()::class]; + $mockedResponse = $this->expectedResponses[$requestClass]; if ($mockedResponse instanceof SequenceMockResponse) { $mockedResponse = $mockedResponse->pop(); From e15fb88ebe0c29393bf242bf234d47374a821882 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 4 Dec 2024 14:08:27 +0000 Subject: [PATCH 087/131] Fixes coding style --- src/Factories/GetPaginatedChargebackQueryFactory.php | 2 +- src/Resources/AnyResource.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php index 2b342f9d5..47cd66c8b 100644 --- a/src/Factories/GetPaginatedChargebackQueryFactory.php +++ b/src/Factories/GetPaginatedChargebackQueryFactory.php @@ -6,7 +6,7 @@ class GetPaginatedChargebackQueryFactory extends Factory { - public function create(): GetPaginatedChargebackQuery + public function create(): GetPaginatedChargebackQuery { return new GetPaginatedChargebackQuery( PaginatedQueryFactory::new($this->data)->create(), diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index 6101059ac..ce0c470d6 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -13,7 +13,6 @@ class AnyResource extends BaseResource public array $attributes = []; /** - * @param string $name * @return mixed */ public function __get(string $name) From 7757a3901068668460e33dc2c38a7ccbbf972e80 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 15:09:41 +0100 Subject: [PATCH 088/131] wip --- phpstan-baseline.neon | 1116 --------------------------------- src/Factories/Factory.php | 4 +- tests/MollieApiClientTest.php | 2 +- 3 files changed, 3 insertions(+), 1119 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a15d51f0b..6bc67aa4e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -252,1122 +252,6 @@ parameters: count: 1 path: src/CompatibilityChecker.php - - - message: '#^Parameter \#1 \$domain of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/ApplePayPaymentSessionPayloadFactory.php - - - - message: '#^Parameter \#2 \$validationUrl of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/ApplePayPaymentSessionPayloadFactory.php - - - - message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Payload\\RequestApplePayPaymentSessionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/ApplePayPaymentSessionPayloadFactory.php - - - - message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Http\\Payload\\Owner\:\:fromArray\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateClientLinkPayloadFactory.php - - - - message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Http\\Payload\\OwnerAddress\:\:fromArray\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateClientLinkPayloadFactory.php - - - - message: '#^Parameter \#2 \$name of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateClientLinkPayloadFactory.php - - - - message: '#^Parameter \#4 \$registrationNumber of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateClientLinkPayloadFactory.php - - - - message: '#^Parameter \#5 \$vatNumber of class Mollie\\Api\\Http\\Payload\\CreateClientLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateClientLinkPayloadFactory.php - - - - message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateCustomerPayloadFactory.php - - - - message: '#^Parameter \#2 \$email of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateCustomerPayloadFactory.php - - - - message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateCustomerPayloadFactory.php - - - - message: '#^Parameter \#4 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateCustomerPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateCustomerPayloadFactory.php - - - - message: '#^Parameter \#1 \$method of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#2 \$consumerName of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#3 \$consumerAccount of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#4 \$consumerBic of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#5 \$consumerEmail of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#6 \$signatureDate of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#7 \$mandateReference of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#8 \$paypalBillingAgreementId of class Mollie\\Api\\Http\\Payload\\CreateMandatePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateMandatePayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentCapturePayloadFactory.php - - - - message: '#^Parameter \#2 \$amount of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentCapturePayloadFactory.php - - - - message: '#^Parameter \#3 \$metadata of class Mollie\\Api\\Http\\Payload\\CreatePaymentCapturePayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentCapturePayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#2 \$amount of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#3 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#4 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#5 \$profileId of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#6 \$reusable of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#7 \$expiresAt of class Mollie\\Api\\Http\\Payload\\CreatePaymentLinkPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentLinkPayloadFactory.php - - - - message: '#^Expression on left side of \?\? is not nullable\.$#' - identifier: nullCoalesce.expr - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#10 \$method of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#11 \$issuer of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#12 \$restrictPaymentMethodsToCountry of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#13 \$metadata of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#14 \$captureMode of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#15 \$captureDelay of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#16 \$applicationFee of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\ApplicationFee\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#17 \$routing of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#18 \$sequenceType of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#19 \$mandateId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#20 \$customerId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#21 \$profileId of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#22 \$additional of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#3 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#4 \$cancelUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#5 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#6 \$lines of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#7 \$billingAddress of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Address\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#8 \$shippingAddress of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Address\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#9 \$locale of class Mollie\\Api\\Http\\Payload\\CreatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreatePaymentPayloadFactory.php - - - - message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#2 \$website of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#3 \$email of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#4 \$phone of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#5 \$description of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#6 \$countriesOfActivity of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#7 \$businessCategory of class Mollie\\Api\\Http\\Payload\\CreateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateProfilePayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateRefundPaymentPayloadFactory.php - - - - message: '#^Parameter \#3 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateRefundPaymentPayloadFactory.php - - - - message: '#^Parameter \#4 \$reverseRouting of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateRefundPaymentPayloadFactory.php - - - - message: '#^Parameter \#5 \$routingReversals of class Mollie\\Api\\Http\\Payload\\CreateRefundPaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\DataCollection\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateRefundPaymentPayloadFactory.php - - - - message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#10 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#11 \$mandateId of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#12 \$profileId of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#2 \$interval of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#3 \$description of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#4 \$status of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#5 \$times of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#6 \$startDate of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#7 \$method of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#8 \$applicationFee of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\ApplicationFee\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#9 \$metadata of class Mollie\\Api\\Http\\Payload\\CreateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/CreateSubscriptionPayloadFactory.php - - - - message: '#^Method Mollie\\Api\\Factories\\Factory\:\:get\(\) has invalid return type Mollie\\Api\\Factories\\mixed\.$#' - identifier: class.notFound - count: 1 - path: src/Factories/Factory.php - - - - message: '#^Method Mollie\\Api\\Factories\\Factory\:\:mapIfNotNull\(\) has invalid return type Mollie\\Api\\Factories\\mixed\.$#' - identifier: class.notFound - count: 1 - path: src/Factories/Factory.php - - - - message: '#^PHPDoc tag @return with type mixed is not subtype of native type Mollie\\Api\\Factories\\mixed\.$#' - identifier: return.phpDocType - count: 1 - path: src/Factories/Factory.php - - - - message: '#^Parameter \#2 \$profileId of class Mollie\\Api\\Http\\Query\\GetAllPaginatedSubscriptionsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php - - - - message: '#^Parameter \#1 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetAllPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#2 \$includePricing of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetAllPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetAllPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#4 \$amount of class Mollie\\Api\\Http\\Query\\GetAllMethodsQuery constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetAllPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#2 \$datetime of static method DateTimeImmutable\:\:createFromFormat\(\) expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Factories/GetBalanceReportQueryFactory.php - - - - message: '#^Parameter \#3 \$grouping of class Mollie\\Api\\Http\\Query\\GetBalanceReportQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetBalanceReportQueryFactory.php - - - - message: '#^Parameter \#1 \$embedOrganization of class Mollie\\Api\\Http\\Query\\GetClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetClientQueryFactory.php - - - - message: '#^Parameter \#2 \$embedOnboarding of class Mollie\\Api\\Http\\Query\\GetClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetClientQueryFactory.php - - - - message: '#^Parameter \#1 \$sequenceType of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#10 \$includePricing of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#2 \$resource of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#4 \$amount of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#5 \$billingCountry of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#6 \$includeWallets of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#7 \$orderLineCategories of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#8 \$profileId of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#9 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetEnabledPaymentMethodsQuery constructor expects bool\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetEnabledPaymentMethodsQueryFactory.php - - - - message: '#^Parameter \#2 \$currency of class Mollie\\Api\\Http\\Query\\GetPaginatedBalanceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedBalanceQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedChargebackQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedChargebackQueryFactory.php - - - - message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedChargebackQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedChargebackQueryFactory.php - - - - message: '#^Parameter \#2 \$embedOrganization of class Mollie\\Api\\Http\\Query\\GetPaginatedClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedClientQueryFactory.php - - - - message: '#^Parameter \#3 \$embedOnboarding of class Mollie\\Api\\Http\\Query\\GetPaginatedClientQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedClientQueryFactory.php - - - - message: '#^Parameter \#2 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedCustomerPaymentsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php - - - - message: '#^Parameter \#2 \$reference of class Mollie\\Api\\Http\\Query\\GetPaginatedInvoiceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedInvoiceQueryFactory.php - - - - message: '#^Parameter \#3 \$year of class Mollie\\Api\\Http\\Query\\GetPaginatedInvoiceQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedInvoiceQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentCapturesQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedPaymentCapturesQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentChargebacksQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedPaymentRefundQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedPaymentRefundQueryFactory.php - - - - message: '#^Parameter \#2 \$embedPayment of class Mollie\\Api\\Http\\Query\\GetPaginatedRefundsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedRefundsQueryFactory.php - - - - message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedRefundsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedRefundsQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementCapturesQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedSettlementCapturesQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementChargebacksQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php - - - - message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementChargebacksQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php - - - - message: '#^Parameter \#2 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementRefundsQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedSettlementRefundsQueryFactory.php - - - - message: '#^Parameter \#2 \$balanceId of class Mollie\\Api\\Http\\Query\\GetPaginatedSettlementsQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaginatedSettlementsQueryFactory.php - - - - message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentCaptureQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentCaptureQueryFactory.php - - - - message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentChargebackQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentChargebackQueryFactory.php - - - - message: '#^Parameter \#1 \$locale of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentMethodQueryFactory.php - - - - message: '#^Parameter \#2 \$currency of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentMethodQueryFactory.php - - - - message: '#^Parameter \#3 \$profileId of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentMethodQueryFactory.php - - - - message: '#^Parameter \#4 \$includeIssuers of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentMethodQueryFactory.php - - - - message: '#^Parameter \#5 \$includePricing of class Mollie\\Api\\Http\\Query\\GetPaymentMethodQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentMethodQueryFactory.php - - - - message: '#^Parameter \#1 \$embedCaptures of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentQueryFactory.php - - - - message: '#^Parameter \#2 \$embedRefunds of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentQueryFactory.php - - - - message: '#^Parameter \#3 \$embedChargebacks of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentQueryFactory.php - - - - message: '#^Parameter \#4 \$includeQrCode of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentQueryFactory.php - - - - message: '#^Parameter \#5 \$includeRemainderDetails of class Mollie\\Api\\Http\\Query\\GetPaymentQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentQueryFactory.php - - - - message: '#^Parameter \#1 \$includePayment of class Mollie\\Api\\Http\\Query\\GetPaymentRefundQuery constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/GetPaymentRefundQueryFactory.php - - - - message: '#^Parameter \#1 \$currency of class Mollie\\Api\\Http\\Payload\\Money constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/MoneyFactory.php - - - - message: '#^Parameter \#2 \$value of class Mollie\\Api\\Http\\Payload\\Money constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/MoneyFactory.php - - - - message: '#^Parameter \#1 \$data of static method Mollie\\Api\\Factories\\Factory\:\:new\(\) expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 2 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#10 \$vatAmount of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#11 \$sku of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#12 \$imageUrl of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#13 \$productUrl of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#2 \$quantity of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects int, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#5 \$type of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#6 \$quantityUnit of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#7 \$discountAmount of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#8 \$recurring of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects Mollie\\Api\\Http\\Payload\\RecurringBillingCycle\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#9 \$vatRate of class Mollie\\Api\\Http\\Payload\\OrderLine constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/OrderLineFactory.php - - - - message: '#^Parameter \#1 \$from of class Mollie\\Api\\Http\\Query\\PaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/PaginatedQueryFactory.php - - - - message: '#^Parameter \#2 \$limit of class Mollie\\Api\\Http\\Query\\PaginatedQuery constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/PaginatedQueryFactory.php - - - - message: '#^Parameter \#1 \$interval of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/RecurringBillingCycleFactory.php - - - - message: '#^Parameter \#2 \$description of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/RecurringBillingCycleFactory.php - - - - message: '#^Parameter \#3 \$amount of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/RecurringBillingCycleFactory.php - - - - message: '#^Parameter \#4 \$times of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/RecurringBillingCycleFactory.php - - - - message: '#^Parameter \#5 \$startDate of class Mollie\\Api\\Http\\Payload\\RecurringBillingCycle constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/RecurringBillingCycleFactory.php - - - - message: '#^Parameter \#1 \$from of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/SortablePaginatedQueryFactory.php - - - - message: '#^Parameter \#2 \$limit of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/SortablePaginatedQueryFactory.php - - - - message: '#^Parameter \#3 \$sort of class Mollie\\Api\\Http\\Query\\SortablePaginatedQuery constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/SortablePaginatedQueryFactory.php - - - - message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateCustomerPayloadFactory.php - - - - message: '#^Parameter \#2 \$email of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateCustomerPayloadFactory.php - - - - message: '#^Parameter \#3 \$locale of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateCustomerPayloadFactory.php - - - - message: '#^Parameter \#4 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdateCustomerPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateCustomerPayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\UpdatePaymentLinkPayload constructor expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentLinkPayloadFactory.php - - - - message: '#^Parameter \#2 \$archived of class Mollie\\Api\\Http\\Payload\\UpdatePaymentLinkPayload constructor expects bool, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentLinkPayloadFactory.php - - - - message: '#^Expression on left side of \?\? is not nullable\.$#' - identifier: nullCoalesce.expr - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#1 \$description of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#2 \$redirectUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#3 \$cancelUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#4 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#5 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#6 \$method of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#7 \$locale of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#8 \$restrictPaymentMethodsToCountry of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#9 \$additional of class Mollie\\Api\\Http\\Payload\\UpdatePaymentPayload constructor expects array, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentPayloadFactory.php - - - - message: '#^Parameter \#2 \$datetime of static method DateTimeImmutable\:\:createFromFormat\(\) expects string, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdatePaymentRoutePayloadFactory.php - - - - message: '#^Parameter \#1 \$name of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#2 \$website of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#3 \$email of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#4 \$phone of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#5 \$description of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#6 \$countriesOfActivity of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects array\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#7 \$businessCategory of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#8 \$mode of class Mollie\\Api\\Http\\Payload\\UpdateProfilePayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateProfilePayloadFactory.php - - - - message: '#^Parameter \#1 \$amount of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Money\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#2 \$description of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#3 \$interval of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#4 \$startDate of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects DateTimeInterface\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#5 \$times of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects int\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#6 \$metadata of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects Mollie\\Api\\Http\\Payload\\Metadata\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#7 \$webhookUrl of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - - - message: '#^Parameter \#8 \$mandateId of class Mollie\\Api\\Http\\Payload\\UpdateSubscriptionPayload constructor expects string\|null, Mollie\\Api\\Factories\\mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Factories/UpdateSubscriptionPayloadFactory.php - - message: '#^Unsafe usage of new static\(\)\.$#' identifier: new.static diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 9269bde76..20decae7f 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -27,7 +27,7 @@ public static function new(array $data): self * @param string|array $key * @param mixed $default */ - protected function get($key, $default = null, $backupKey = 'filters.'): mixed + protected function get($key, $default = null, $backupKey = 'filters.') { $keys = (array) $key; @@ -66,7 +66,7 @@ protected function includes($key, $value, $backupKey = 'filters.'): bool * @param string $backupKey The key to retrieve the value from the data array if the first key is null. * @return mixed The transformed value, a new class instance, or null if the value is null. */ - protected function mapIfNotNull($key, $composable, $backupKey = 'filters.'): mixed + protected function mapIfNotNull($key, $composable, $backupKey = 'filters.') { return Helpers::compose($this->get($key, null, $backupKey), $composable); } diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index f59c47094..dba10d77c 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -202,7 +202,7 @@ public function no_idempotency_is_set_if_no_key_nor_generator_are_set() public function idempotency_key_is_used_on_mutating_requests($request, $response) { $client = new MockClient([ - $request::class => $response, + get_class($request) => $response, ]); $client->setIdempotencyKey('idempotentFooBar'); From 2a21c7091bddd653379cf7d2a86de301762cec61 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 4 Dec 2024 16:06:50 +0100 Subject: [PATCH 089/131] wip --- src/Contracts/Hydratable.php | 2 +- src/EndpointCollection/EndpointCollection.php | 2 +- src/Helpers/Arr.php | 39 +++++++++++ src/Resources/CursorCollection.php | 40 +++++++++++- src/Traits/HandlesAutoHydration.php | 2 +- tests/Fixtures/SequenceMockResponse.php | 5 ++ tests/Helpers/ArrTest.php | 19 ++++++ tests/Http/Adapter/MockMollieHttpAdapter.php | 34 ++++++++-- .../Requests/CreatePaymentRequestTest.php | 39 +++++++++++ .../GetPaginatedPaymentsRequestTest.php | 65 +++++++++++++++++++ tests/Resources/CursorCollectionTest.php | 17 +++-- tests/TestCase.php | 2 +- 12 files changed, 246 insertions(+), 20 deletions(-) create mode 100644 tests/Http/Requests/CreatePaymentRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentsRequestTest.php diff --git a/src/Contracts/Hydratable.php b/src/Contracts/Hydratable.php index 5ec2d0b79..53563a5e3 100644 --- a/src/Contracts/Hydratable.php +++ b/src/Contracts/Hydratable.php @@ -4,7 +4,7 @@ interface Hydratable { - public static function shouldAutoHydrate(bool $shouldAutoHydrate = true): void; + public static function setAutoHydrate(bool $shouldAutoHydrate = true): void; /** * @return mixed diff --git a/src/EndpointCollection/EndpointCollection.php b/src/EndpointCollection/EndpointCollection.php index 4825f403b..11bf8e471 100644 --- a/src/EndpointCollection/EndpointCollection.php +++ b/src/EndpointCollection/EndpointCollection.php @@ -16,7 +16,7 @@ public function __construct(Connector $connector) /** * Default hydration decision to true to maintain legacy compatibility. */ - $connector::shouldAutoHydrate(); + $connector::setAutoHydrate(); } /** diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index 511457c27..588e86448 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -26,6 +26,45 @@ public static function get(array $array, string $keys, $default = null) return $value; } + /** + * Get and remove an item from an array using "dot" notation. + * + * @param array $array + * @param string $key + * @param mixed $default + * @return mixed + */ + public static function pull(array &$array, string $key, $default = null) + { + $value = static::get($array, $key, $default); + + static::forget($array, $key); + + return $value; + } + + /** + * Remove an item from an array using "dot" notation. + * + * @param array $array + * @param string $key + */ + public static function forget(array &$array, string $key): void + { + $keys = explode('.', $key); + $last = array_pop($keys); + $array = &$array; + + foreach ($keys as $segment) { + if (!is_array($array) || !array_key_exists($segment, $array)) { + break; + } + $array = &$array[$segment]; + } + + unset($array[$last]); + } + /** * Checks if the given key/s exist in the provided array. * diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 68280ee00..31b55b1cd 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -4,15 +4,43 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; abstract class CursorCollection extends ResourceCollection { + private bool $autoHydrate = false; + + public function setAutoHydrate(bool $shouldAutoHydrate = true): void + { + $this->autoHydrate = $shouldAutoHydrate; + } + + public function shouldAutoHydrate(): bool + { + if ($this->response === null) { + return $this->autoHydrate; + } + + $request = $this->response->getRequest(); + + /** + * Don't try to hydrate when the request + * already has auto-hydration enabled. The + * Hydrate Middleware will take care of that. + */ + if ($request instanceof ResourceHydratableRequest && $request->shouldAutoHydrate()) { + return false; + } + + return $this->autoHydrate; + } + /** * Return the next set of resources when available * * @throws \Mollie\Api\Exceptions\ApiException */ - final public function next(): ?CursorCollection + public function next(): ?CursorCollection { if (! $this->hasNext()) { return null; @@ -26,7 +54,7 @@ final public function next(): ?CursorCollection * * @throws \Mollie\Api\Exceptions\ApiException */ - final public function previous(): ?CursorCollection + public function previous(): ?CursorCollection { if (! $this->hasPrevious()) { return null; @@ -37,9 +65,13 @@ final public function previous(): ?CursorCollection private function fetchCollection(string $url): CursorCollection { - return $this + $response = $this ->connector ->send(new DynamicGetRequest($url, static::class)); + + return $this->shouldAutoHydrate() + ? $response->toResource() + : $response; } /** @@ -66,6 +98,8 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection $page = $this; return new LazyCollection(function () use ($page, $iterateBackwards): Generator { + $page->setAutoHydrate(); + while (true) { foreach ($page as $item) { yield $item; diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php index 26736eee7..0c8685293 100644 --- a/src/Traits/HandlesAutoHydration.php +++ b/src/Traits/HandlesAutoHydration.php @@ -8,7 +8,7 @@ trait HandlesAutoHydration { protected static $hydrationSettingResolver = null; - public static function shouldAutoHydrate(bool $shouldAutoHydrate = true): void + public static function setAutoHydrate(bool $shouldAutoHydrate = true): void { static::$hydrationSettingResolver = static function () use ($shouldAutoHydrate) { ResourceHydratableRequest::hydrate($shouldAutoHydrate); diff --git a/tests/Fixtures/SequenceMockResponse.php b/tests/Fixtures/SequenceMockResponse.php index f7d2bed1b..7e4fad96c 100644 --- a/tests/Fixtures/SequenceMockResponse.php +++ b/tests/Fixtures/SequenceMockResponse.php @@ -30,4 +30,9 @@ public function pop(): MockResponse return $response; } + + public function isEmpty(): bool + { + return count($this->responses) === 0; + } } diff --git a/tests/Helpers/ArrTest.php b/tests/Helpers/ArrTest.php index 4d65138f6..22f2af878 100644 --- a/tests/Helpers/ArrTest.php +++ b/tests/Helpers/ArrTest.php @@ -17,6 +17,25 @@ public function get(): void $this->assertEquals('default', Arr::get($array, 'foo.baz', 'default')); } + /** @test */ + public function pull(): void + { + $array = ['foo' => ['bar' => 'baz']]; + + $this->assertEquals('baz', Arr::pull($array, 'foo.bar')); + $this->assertEquals(['foo' => []], $array); + } + + /** @test */ + public function forget(): void + { + $array = ['foo' => ['bar' => 'baz']]; + + Arr::forget($array, 'foo.bar'); + + $this->assertEquals(['foo' => []], $array); + } + /** @test */ public function has(): void { diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index a54a2d5b4..789e09cdc 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -29,15 +29,13 @@ public function __construct(array $expectedResponses = []) */ public function sendRequest(PendingRequest $pendingRequest): Response { - if (! Arr::has($this->expectedResponses, $requestClass = get_class($pendingRequest->getRequest()))) { + $requestClass = get_class($pendingRequest->getRequest()); + + if (! Arr::has($this->expectedResponses, $requestClass)) { throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); } - $mockedResponse = $this->expectedResponses[$requestClass]; - - if ($mockedResponse instanceof SequenceMockResponse) { - $mockedResponse = $mockedResponse->pop(); - } + $mockedResponse = $this->getResponse($requestClass); return new Response( $mockedResponse->createPsrResponse(), @@ -46,6 +44,30 @@ public function sendRequest(PendingRequest $pendingRequest): Response ); } + /** + * Get the mocked response and remove it from the expected responses. + * + * @param string $requestClass + * @return MockResponse + */ + private function getResponse(string $requestClass): MockResponse + { + $mockedResponse = Arr::get($this->expectedResponses, $requestClass); + + if (!($mockedResponse instanceof SequenceMockResponse)) { + Arr::forget($this->expectedResponses, $requestClass); + return $mockedResponse; + } + + $response = $mockedResponse->pop(); + + if ($mockedResponse->isEmpty()) { + Arr::forget($this->expectedResponses, $requestClass); + } + + return $response; + } + /** * {@inheritDoc} */ diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php new file mode 100644 index 000000000..14f0700c7 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -0,0 +1,39 @@ + new MockResponse(201, 'payment'), + ]); + + $payload = new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + ); + + $request = new CreatePaymentRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php new file mode 100644 index 000000000..6517fd92a --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -0,0 +1,65 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedPaymentsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_payments() + { + $client = new MockClient([ + GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), + ]); + + $request = (new GetPaginatedPaymentsRequest())->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + } +} diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 60b476ae9..3500064c1 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -13,13 +13,6 @@ class CursorCollectionTest extends TestCase { - protected function setUp(): void - { - parent::setUp(); - - MockClient::shouldAutoHydrate(); - } - /** @test */ public function can_get_next_collection_result_when_next_link_is_available() { @@ -37,6 +30,8 @@ public function can_get_next_collection_result_when_next_link_is_available() ]) ); + $collection->setAutoHydrate(); + $this->assertTrue($collection->hasNext()); $nextPage = $collection->next(); @@ -54,6 +49,8 @@ public function test_will_return_null_if_no_next_result_is_available() (object) [] ); + $collection->setAutoHydrate(); + $this->assertFalse($collection->hasNext()); $this->assertNull($collection->next()); } @@ -74,6 +71,8 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av ]) ); + $collection->setAutoHydrate(); + $this->assertTrue($collection->hasPrevious()); $previousPage = $collection->previous(); @@ -91,6 +90,8 @@ public function test_will_return_null_if_no_previous_result_is_available() (object) [] ); + $collection->setAutoHydrate(); + $this->assertFalse($collection->hasPrevious()); $this->assertNull($collection->previous()); } @@ -105,6 +106,8 @@ public function test_auto_paginator_returns_lazy_collection() (object) [] ); + $collection->setAutoHydrate(); + $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 66d6a3860..3a0f5f903 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,6 +11,6 @@ protected function setUp(): void { parent::setUp(); - MockClient::shouldAutoHydrate(false); + MockClient::setAutoHydrate(false); } } From e72d0e6fe09b8bbe3d112348c17e18760285b510 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 4 Dec 2024 15:07:16 +0000 Subject: [PATCH 090/131] Fixes coding style --- src/Helpers/Arr.php | 7 +------ tests/Http/Adapter/MockMollieHttpAdapter.php | 6 ++---- tests/Http/Requests/CreatePaymentRequestTest.php | 1 - tests/Http/Requests/GetPaginatedPaymentsRequestTest.php | 4 ++-- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index 588e86448..f07aba29b 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -29,8 +29,6 @@ public static function get(array $array, string $keys, $default = null) /** * Get and remove an item from an array using "dot" notation. * - * @param array $array - * @param string $key * @param mixed $default * @return mixed */ @@ -45,9 +43,6 @@ public static function pull(array &$array, string $key, $default = null) /** * Remove an item from an array using "dot" notation. - * - * @param array $array - * @param string $key */ public static function forget(array &$array, string $key): void { @@ -56,7 +51,7 @@ public static function forget(array &$array, string $key): void $array = &$array; foreach ($keys as $segment) { - if (!is_array($array) || !array_key_exists($segment, $array)) { + if (! is_array($array) || ! array_key_exists($segment, $array)) { break; } $array = &$array[$segment]; diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 789e09cdc..54b405ba4 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -46,16 +46,14 @@ public function sendRequest(PendingRequest $pendingRequest): Response /** * Get the mocked response and remove it from the expected responses. - * - * @param string $requestClass - * @return MockResponse */ private function getResponse(string $requestClass): MockResponse { $mockedResponse = Arr::get($this->expectedResponses, $requestClass); - if (!($mockedResponse instanceof SequenceMockResponse)) { + if (! ($mockedResponse instanceof SequenceMockResponse)) { Arr::forget($this->expectedResponses, $requestClass); + return $mockedResponse; } diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index 14f0700c7..4758be8a5 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -4,7 +4,6 @@ use Mollie\Api\Http\Payload\CreatePaymentPayload; use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Query\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index 6517fd92a..b804844c6 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -21,7 +21,7 @@ public function it_can_get_paginated_payments() GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); - $request = new GetPaginatedPaymentsRequest(); + $request = new GetPaginatedPaymentsRequest; /** @var Response */ $response = $client->send($request); @@ -49,7 +49,7 @@ public function it_can_iterate_over_payments() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); - $request = (new GetPaginatedPaymentsRequest())->useIterator(); + $request = (new GetPaginatedPaymentsRequest)->useIterator(); /** @var Response */ $response = $client->send($request); From 9a58ddf311525d749466f18534a645282c3fdba0 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 5 Dec 2024 09:53:29 +0100 Subject: [PATCH 091/131] fix tests --- src/Resources/CursorCollection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 31b55b1cd..84c159474 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -98,9 +98,9 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection $page = $this; return new LazyCollection(function () use ($page, $iterateBackwards): Generator { - $page->setAutoHydrate(); - while (true) { + $page->setAutoHydrate(); + foreach ($page as $item) { yield $item; } From 82cc0359fa2da36938d41e3fe11b95c6ed8e8044 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 5 Dec 2024 08:54:05 +0000 Subject: [PATCH 092/131] Fixes coding style --- src/Resources/CursorCollection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 84c159474..078a478ef 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -100,7 +100,7 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection return new LazyCollection(function () use ($page, $iterateBackwards): Generator { while (true) { $page->setAutoHydrate(); - + foreach ($page as $item) { yield $item; } From 34f8dd5e82d54ef8841cf068fbb42a96e955b033 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 5 Dec 2024 13:33:54 +0100 Subject: [PATCH 093/131] wip --- src/Http/Requests/GetAllMethodsRequest.php | 4 +- src/Http/Requests/GetClientRequest.php | 6 +- .../Requests/GetEnabledMethodsRequest.php | 6 +- .../GetPaginatedBalanceTransactionRequest.php | 2 +- .../GetPaginatedCustomerPaymentsRequest.php | 2 +- .../Requests/GetPaginatedMandateRequest.php | 2 +- ...etPaginatedSubscriptionPaymentsRequest.php | 2 +- .../GetPaginatedSubscriptionsRequest.php | 2 +- src/Http/Requests/GetPaymentMethodRequest.php | 6 +- src/Http/Requests/GetPaymentRefundRequest.php | 6 +- src/Http/Requests/GetPaymentRequest.php | 6 +- src/Http/Response.php | 13 ++- src/Resources/CursorCollection.php | 54 ++++------- src/Traits/DelegatesToResource.php | 90 +++++++++++++++++++ .../ChargebackEndpointCollectionTest.php | 2 + ...aymentChargebackEndpointCollectionTest.php | 2 + ...lementChargebackEndpointCollectionTest.php | 2 + .../TerminalEndpointCollectionTest.php | 1 + tests/Fixtures/MockClient.php | 16 ++++ tests/Fixtures/Responses/chargeback-list.json | 5 +- tests/Fixtures/Responses/terminal-list.json | 5 +- tests/Http/Adapter/MockMollieHttpAdapter.php | 65 +++++++++++--- .../ApplePayPaymentSessionRequestTest.php | 53 +++++++++++ .../CancelPaymentRefundRequestTest.php | 45 ++++++++++ .../Requests/CancelPaymentRequestTest.php | 42 +++++++++ .../Requests/CancelSessionRequestTest.php | 42 +++++++++ .../CancelSubscriptionRequestTest.php | 44 +++++++++ .../Requests/CreateClientLinkRequestTest.php | 38 ++++++++ .../CreateCustomerPaymentRequestTest.php | 55 ++++++++++++ .../Requests/CreateCustomerRequestTest.php | 46 ++++++++++ .../Requests/CreateMandateRequestTest.php | 55 ++++++++++++ .../CreatePaymentCaptureRequestTest.php | 47 ++++++++++ .../Requests/CreatePaymentLinkRequestTest.php | 47 ++++++++++ .../CreatePaymentRefundRequestTest.php | 54 +++++++++++ .../Requests/CreatePaymentRequestTest.php | 13 +++ .../Requests/CreateProfileRequestTest.php | 52 +++++++++++ .../Requests/CreateSessionRequestTest.php | 42 +++++++++ .../CreateSubscriptionRequestTest.php | 47 ++++++++++ .../Requests/DeleteCustomerRequestTest.php | 36 ++++++++ .../Requests/DeletePaymentLinkRequestTest.php | 36 ++++++++ .../Requests/DeleteProfileRequestTest.php | 41 +++++++++ .../DisableMethodIssuerRequestTest.php | 45 ++++++++++ .../DisableProfileMethodRequestTest.php | 43 +++++++++ tests/Http/Requests/DynamicGetRequestTest.php | 42 +++++++++ tests/Http/Requests/DynamicRequestTest.php | 45 ++++++++++ .../EnableMethodIssuerRequestTest.php | 45 ++++++++++ .../EnableProfileMethodRequestTest.php | 43 +++++++++ .../Requests/GetAllMethodsRequestTest.php | 38 ++++++++ ...etAllPaginatedSubscriptionsRequestTest.php | 38 ++++++++ .../Requests/GetBalanceReportRequestTest.php | 49 ++++++++++ tests/Http/Requests/GetBalanceRequestTest.php | 42 +++++++++ tests/Http/Requests/GetClientRequestTest.php | 39 ++++++++ .../Http/Requests/GetCustomerRequestTest.php | 42 +++++++++ .../Requests/GetEnabledMethodsRequestTest.php | 38 ++++++++ tests/Http/Requests/GetInvoiceRequestTest.php | 38 ++++++++ tests/Http/Requests/GetMandateRequestTest.php | 44 +++++++++ .../Requests/GetOnboardingRequestTest.php | 37 ++++++++ ...etOrganizationPartnerStatusRequestTest.php | 38 ++++++++ .../Requests/GetOrganizationRequestTest.php | 39 ++++++++ .../GetPaginatedBalanceRequestTest.php | 37 ++++++++ ...PaginatedBalanceTransactionRequestTest.php | 40 +++++++++ .../GetPaginatedChargebacksRequestTest.php | 38 ++++++++ .../GetPaginatedClientRequestTest.php | 38 ++++++++ ...etPaginatedCustomerPaymentsRequestTest.php | 40 +++++++++ .../GetPaginatedCustomerRequestTest.php | 38 ++++++++ .../GetPaginatedInvoiceRequestTest.php | 38 ++++++++ .../GetPaginatedMandateRequestTest.php | 79 ++++++++++++++++ ...GetPaginatedPaymentCapturesRequestTest.php | 79 ++++++++++++++++ ...PaginatedPaymentChargebacksRequestTest.php | 79 ++++++++++++++++ ...aginatedPaymentLinkPaymentsRequestTest.php | 79 ++++++++++++++++ .../GetPaginatedPaymentLinksRequestTest.php | 78 ++++++++++++++++ .../GetPaginatedPaymentRefundsRequestTest.php | 79 ++++++++++++++++ .../GetPaginatedPaymentsRequestTest.php | 17 +++- .../GetPaginatedProfilesRequestTest.php | 78 ++++++++++++++++ .../GetPaginatedRefundsRequestTest.php | 78 ++++++++++++++++ .../GetPaginatedSessionsRequestTest.php | 78 ++++++++++++++++ ...PaginatedSettlementCapturesRequestTest.php | 79 ++++++++++++++++ ...inatedSettlementChargebacksRequestTest.php | 79 ++++++++++++++++ ...PaginatedSettlementPaymentsRequestTest.php | 79 ++++++++++++++++ ...tPaginatedSettlementRefundsRequestTest.php | 79 ++++++++++++++++ .../GetPaginatedSettlementsRequestTest.php | 78 ++++++++++++++++ ...ginatedSubscriptionPaymentsRequestTest.php | 81 +++++++++++++++++ .../GetPaginatedSubscriptionsRequestTest.php | 80 +++++++++++++++++ .../GetPaginatedTerminalsRequestTest.php | 78 ++++++++++++++++ .../Requests/GetPaymentCaptureRequestTest.php | 44 +++++++++ .../GetPaymentChargebackRequestTest.php | 44 +++++++++ .../Requests/GetPaymentLinkRequestTest.php | 43 +++++++++ .../Requests/GetPaymentMethodRequestTest.php | 44 +++++++++ .../Requests/GetPaymentRefundRequestTest.php | 47 ++++++++++ tests/Http/Requests/GetPaymentRequestTest.php | 45 ++++++++++ .../Requests/GetPermissionRequestTest.php | 45 ++++++++++ tests/Http/Requests/GetProfileRequestTest.php | 45 ++++++++++ tests/Http/Requests/GetSessionRequestTest.php | 54 +++++++++++ .../Requests/GetSettlementRequestTest.php | 45 ++++++++++ .../Requests/GetSubscriptionRequestTest.php | 45 ++++++++++ .../Http/Requests/GetTerminalRequestTest.php | 45 ++++++++++ .../Requests/ListPermissionsRequestTest.php | 48 ++++++++++ tests/Http/Requests/PaginatedRequestTest.php | 53 +++++++++++ .../ResourceHydratableRequestTest.php | 61 +++++++++++++ .../Requests/RevokeMandateRequestTest.php | 43 +++++++++ .../Requests/UpdateCustomerRequestTest.php | 49 ++++++++++ .../Requests/UpdatePaymentLinkRequestTest.php | 48 ++++++++++ .../Requests/UpdatePaymentRequestTest.php | 49 ++++++++++ .../UpdatePaymentRouteRequestTest.php | 48 ++++++++++ .../Requests/UpdateProfileRequestTest.php | 47 ++++++++++ .../Requests/UpdateSessionRequestTest.php | 51 +++++++++++ .../UpdateSubscriptionRequestTest.php | 60 +++++++++++++ tests/Resources/CursorCollectionTest.php | 18 +--- 108 files changed, 4535 insertions(+), 91 deletions(-) create mode 100644 src/Traits/DelegatesToResource.php create mode 100644 tests/Http/Requests/ApplePayPaymentSessionRequestTest.php create mode 100644 tests/Http/Requests/CancelPaymentRefundRequestTest.php create mode 100644 tests/Http/Requests/CancelPaymentRequestTest.php create mode 100644 tests/Http/Requests/CancelSessionRequestTest.php create mode 100644 tests/Http/Requests/CancelSubscriptionRequestTest.php create mode 100644 tests/Http/Requests/CreateClientLinkRequestTest.php create mode 100644 tests/Http/Requests/CreateCustomerPaymentRequestTest.php create mode 100644 tests/Http/Requests/CreateCustomerRequestTest.php create mode 100644 tests/Http/Requests/CreateMandateRequestTest.php create mode 100644 tests/Http/Requests/CreatePaymentCaptureRequestTest.php create mode 100644 tests/Http/Requests/CreatePaymentLinkRequestTest.php create mode 100644 tests/Http/Requests/CreatePaymentRefundRequestTest.php create mode 100644 tests/Http/Requests/CreateProfileRequestTest.php create mode 100644 tests/Http/Requests/CreateSessionRequestTest.php create mode 100644 tests/Http/Requests/CreateSubscriptionRequestTest.php create mode 100644 tests/Http/Requests/DeleteCustomerRequestTest.php create mode 100644 tests/Http/Requests/DeletePaymentLinkRequestTest.php create mode 100644 tests/Http/Requests/DeleteProfileRequestTest.php create mode 100644 tests/Http/Requests/DisableMethodIssuerRequestTest.php create mode 100644 tests/Http/Requests/DisableProfileMethodRequestTest.php create mode 100644 tests/Http/Requests/DynamicGetRequestTest.php create mode 100644 tests/Http/Requests/DynamicRequestTest.php create mode 100644 tests/Http/Requests/EnableMethodIssuerRequestTest.php create mode 100644 tests/Http/Requests/EnableProfileMethodRequestTest.php create mode 100644 tests/Http/Requests/GetAllMethodsRequestTest.php create mode 100644 tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php create mode 100644 tests/Http/Requests/GetBalanceReportRequestTest.php create mode 100644 tests/Http/Requests/GetBalanceRequestTest.php create mode 100644 tests/Http/Requests/GetClientRequestTest.php create mode 100644 tests/Http/Requests/GetCustomerRequestTest.php create mode 100644 tests/Http/Requests/GetEnabledMethodsRequestTest.php create mode 100644 tests/Http/Requests/GetInvoiceRequestTest.php create mode 100644 tests/Http/Requests/GetMandateRequestTest.php create mode 100644 tests/Http/Requests/GetOnboardingRequestTest.php create mode 100644 tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php create mode 100644 tests/Http/Requests/GetOrganizationRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedBalanceRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedChargebacksRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedClientRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedCustomerRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedInvoiceRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedMandateRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedProfilesRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedRefundsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSessionsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSettlementsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedTerminalsRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentCaptureRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentChargebackRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentLinkRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentMethodRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentRefundRequestTest.php create mode 100644 tests/Http/Requests/GetPaymentRequestTest.php create mode 100644 tests/Http/Requests/GetPermissionRequestTest.php create mode 100644 tests/Http/Requests/GetProfileRequestTest.php create mode 100644 tests/Http/Requests/GetSessionRequestTest.php create mode 100644 tests/Http/Requests/GetSettlementRequestTest.php create mode 100644 tests/Http/Requests/GetSubscriptionRequestTest.php create mode 100644 tests/Http/Requests/GetTerminalRequestTest.php create mode 100644 tests/Http/Requests/ListPermissionsRequestTest.php create mode 100644 tests/Http/Requests/PaginatedRequestTest.php create mode 100644 tests/Http/Requests/ResourceHydratableRequestTest.php create mode 100644 tests/Http/Requests/RevokeMandateRequestTest.php create mode 100644 tests/Http/Requests/UpdateCustomerRequestTest.php create mode 100644 tests/Http/Requests/UpdatePaymentLinkRequestTest.php create mode 100644 tests/Http/Requests/UpdatePaymentRequestTest.php create mode 100644 tests/Http/Requests/UpdatePaymentRouteRequestTest.php create mode 100644 tests/Http/Requests/UpdateProfileRequestTest.php create mode 100644 tests/Http/Requests/UpdateSessionRequestTest.php create mode 100644 tests/Http/Requests/UpdateSubscriptionRequestTest.php diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index 4cb739c58..ee5b11eda 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -20,9 +20,9 @@ class GetAllMethodsRequest extends ResourceHydratableRequest private GetAllMethodsQuery $query; - public function __construct(GetAllMethodsQuery $query) + public function __construct(?GetAllMethodsQuery $query = null) { - $this->query = $query; + $this->query = $query ?: new GetAllMethodsQuery(); } protected function defaultQuery(): array diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 2073dda97..5644822f9 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -20,9 +20,9 @@ class GetClientRequest extends ResourceHydratableRequest private string $id; - private GetClientQuery $query; + private ?GetClientQuery $query; - public function __construct(string $id, GetClientQuery $query) + public function __construct(string $id, ?GetClientQuery $query = null) { $this->id = $id; $this->query = $query; @@ -30,7 +30,7 @@ public function __construct(string $id, GetClientQuery $query) protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php index 8888b4d5b..c628a16ce 100644 --- a/src/Http/Requests/GetEnabledMethodsRequest.php +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -13,16 +13,16 @@ class GetEnabledMethodsRequest extends ResourceHydratableRequest implements Supp public static string $targetResourceClass = MethodCollection::class; - private GetEnabledPaymentMethodsQuery $query; + private ?GetEnabledPaymentMethodsQuery $query = null; - public function __construct(GetEnabledPaymentMethodsQuery $query) + public function __construct(?GetEnabledPaymentMethodsQuery $query = null) { $this->query = $query; } protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php index 4b85f3345..44cd639e4 100644 --- a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -20,7 +20,7 @@ class GetPaginatedBalanceTransactionRequest extends PaginatedRequest implements public function __construct( string $balanceId, - PaginatedQuery $query + ?PaginatedQuery $query = null ) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php index 52c1e403e..26de07c6f 100644 --- a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php @@ -21,7 +21,7 @@ class GetPaginatedCustomerPaymentsRequest extends PaginatedRequest implements Is public function __construct( string $customerId, - GetPaginatedCustomerPaymentsQuery $query + ?GetPaginatedCustomerPaymentsQuery $query = null ) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedMandateRequest.php b/src/Http/Requests/GetPaginatedMandateRequest.php index 026224241..25a407729 100644 --- a/src/Http/Requests/GetPaginatedMandateRequest.php +++ b/src/Http/Requests/GetPaginatedMandateRequest.php @@ -19,7 +19,7 @@ class GetPaginatedMandateRequest extends PaginatedRequest implements IsIteratabl private string $customerId; - public function __construct(string $customerId, PaginatedQuery $query) + public function __construct(string $customerId, ?PaginatedQuery $query = null) { parent::__construct($query); diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index e90b3e577..332e8fb17 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -21,7 +21,7 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement private string $subscriptionId; - public function __construct(string $customerId, string $subscriptionId, PaginatedQuery $query) + public function __construct(string $customerId, string $subscriptionId, ?PaginatedQuery $query = null) { $this->customerId = $customerId; $this->subscriptionId = $subscriptionId; diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index 62f027d32..2e6eb379c 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -19,7 +19,7 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte private string $customerId; - public function __construct(string $customerId, PaginatedQuery $query) + public function __construct(string $customerId, ?PaginatedQuery $query = null) { $this->customerId = $customerId; diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php index 968f0e663..376867345 100644 --- a/src/Http/Requests/GetPaymentMethodRequest.php +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -13,11 +13,11 @@ class GetPaymentMethodRequest extends ResourceHydratableRequest implements Suppo public static string $targetResourceClass = Method::class; - private GetPaymentMethodQuery $query; + private ?GetPaymentMethodQuery $query = null; private string $methodId; - public function __construct(string $methodId, GetPaymentMethodQuery $query) + public function __construct(string $methodId, ?GetPaymentMethodQuery $query = null) { $this->methodId = $methodId; $this->query = $query; @@ -25,7 +25,7 @@ public function __construct(string $methodId, GetPaymentMethodQuery $query) protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index 51b6e2a95..e0917158f 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -23,9 +23,9 @@ class GetPaymentRefundRequest extends ResourceHydratableRequest implements Suppo private string $refundId; - private GetPaymentRefundQuery $query; + private ?GetPaymentRefundQuery $query = null; - public function __construct(string $paymentId, string $refundId, GetPaymentRefundQuery $query) + public function __construct(string $paymentId, string $refundId, ?GetPaymentRefundQuery $query = null) { $this->paymentId = $paymentId; $this->refundId = $refundId; @@ -34,7 +34,7 @@ public function __construct(string $paymentId, string $refundId, GetPaymentRefun protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } /** diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 4e723d00a..d20314114 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -21,11 +21,11 @@ class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTes private string $id; - private GetPaymentQuery $query; + private ?GetPaymentQuery $query = null; public function __construct( string $id, - GetPaymentQuery $query + ?GetPaymentQuery $query = null ) { $this->id = $id; $this->query = $query; @@ -33,7 +33,7 @@ public function __construct( protected function defaultQuery(): array { - return $this->query->toArray(); + return $this->query ? $this->query->toArray() : []; } /** diff --git a/src/Http/Response.php b/src/Http/Response.php index 32be2f4e9..276da8351 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -5,6 +5,9 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Requests\ResourceHydratableRequest; +use Mollie\Api\Resources\BaseResource; +use Mollie\Api\Resources\ResourceCollection; +use Mollie\Api\Traits\DelegatesToResource; use Mollie\Api\Traits\HandlesResourceHydration; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -14,6 +17,7 @@ class Response { + use DelegatesToResource; use HandlesResourceHydration; protected ResponseInterface $psrResponse; @@ -24,6 +28,11 @@ class Response protected ?Throwable $senderException = null; + /** + * @var null|BaseResource|ResourceCollection + */ + protected $resource = null; + /** * The decoded JSON response. */ @@ -42,7 +51,7 @@ public function __construct( } /** - * @return mixed + * @return self|BaseResource|ResourceCollection|null */ public function toResource() { @@ -50,7 +59,7 @@ public function toResource() return $this; } - return $this->hydrate($this->getRequest(), $this); + return $this->resource ?: $this->resource = $this->hydrate($this->getRequest(), $this); } /** diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 078a478ef..6959751d7 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -4,43 +4,17 @@ use Generator; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Requests\ResourceHydratableRequest; +use Mollie\Api\Http\Response; abstract class CursorCollection extends ResourceCollection { - private bool $autoHydrate = false; - - public function setAutoHydrate(bool $shouldAutoHydrate = true): void - { - $this->autoHydrate = $shouldAutoHydrate; - } - - public function shouldAutoHydrate(): bool - { - if ($this->response === null) { - return $this->autoHydrate; - } - - $request = $this->response->getRequest(); - - /** - * Don't try to hydrate when the request - * already has auto-hydration enabled. The - * Hydrate Middleware will take care of that. - */ - if ($request instanceof ResourceHydratableRequest && $request->shouldAutoHydrate()) { - return false; - } - - return $this->autoHydrate; - } - /** * Return the next set of resources when available * + * @return null|CursorCollection|Response * @throws \Mollie\Api\Exceptions\ApiException */ - public function next(): ?CursorCollection + public function next() { if (! $this->hasNext()) { return null; @@ -52,9 +26,10 @@ public function next(): ?CursorCollection /** * Return the previous set of resources when available * + * @return null|CursorCollection|Response * @throws \Mollie\Api\Exceptions\ApiException */ - public function previous(): ?CursorCollection + public function previous() { if (! $this->hasPrevious()) { return null; @@ -63,15 +38,14 @@ public function previous(): ?CursorCollection return $this->fetchCollection($this->_links->previous->href); } - private function fetchCollection(string $url): CursorCollection + /** + * @return CursorCollection|Response + */ + private function fetchCollection(string $url) { - $response = $this + return $this ->connector ->send(new DynamicGetRequest($url, static::class)); - - return $this->shouldAutoHydrate() - ? $response->toResource() - : $response; } /** @@ -99,8 +73,6 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection return new LazyCollection(function () use ($page, $iterateBackwards): Generator { while (true) { - $page->setAutoHydrate(); - foreach ($page as $item) { yield $item; } @@ -109,9 +81,13 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection break; } - $page = $iterateBackwards + $response = $iterateBackwards ? $page->previous() : $page->next(); + + $page = $response instanceof Response + ? $response->toResource() + : $response; } }); } diff --git a/src/Traits/DelegatesToResource.php b/src/Traits/DelegatesToResource.php new file mode 100644 index 000000000..3d3824a7c --- /dev/null +++ b/src/Traits/DelegatesToResource.php @@ -0,0 +1,90 @@ +ensureResourceIsLoaded(); + + return isset($this->resource->{$key}); + } + + /** + * Unset an attribute on the resource. + * + * @param string $key + * @return void + */ + public function __unset($key) + { + $this->ensureResourceIsLoaded(); + + unset($this->resource->{$key}); + } + + /** + * Dynamically get properties from the underlying resource. + * + * @param string $key + * @return mixed + */ + public function __get($key) + { + $this->ensureResourceIsLoaded(); + + if (!property_exists($this->resource, $key)) { + throw new \InvalidArgumentException("Property {$key} does not exist on resource."); + } + + $reflectionProperty = new ReflectionProperty($this->resource, $key); + + return $reflectionProperty->getValue($this->resource); + } + + /** + * Dynamically pass method calls to the underlying resource. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + $this->ensureResourceIsLoaded(); + + if (method_exists($this->resource, $method)) { + return call_user_func_array([$this->resource, $method], $parameters); + } + + throw new \BadMethodCallException("Method {$method} does not exist on resource."); + } + + /** + * Ensure the resource is loaded. + */ + private function ensureResourceIsLoaded(): void + { + if ($this->resource) { + return; + } + + $this->toResource(); + } +} diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index 237eb8c72..000cc8136 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -34,6 +35,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); foreach ($client->chargebacks->iterator() as $chargeback) { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index 09861ed4f..b4a28673e 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; @@ -49,6 +50,7 @@ public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); foreach ($client->paymentChargebacks->iteratorForId('tr_7UhSN1zuXS') as $chargeback) { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 78f99be1b..6b6ac696a 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -2,6 +2,7 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -38,6 +39,7 @@ public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), ]); $settlement = new Settlement($client); diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index 337af014a..a3dcf54c9 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -50,6 +50,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'terminals'), ]); foreach ($client->terminals->iterator() as $terminal) { diff --git a/tests/Fixtures/MockClient.php b/tests/Fixtures/MockClient.php index 79983cb0f..c5ce8e5bf 100644 --- a/tests/Fixtures/MockClient.php +++ b/tests/Fixtures/MockClient.php @@ -5,6 +5,9 @@ use Mollie\Api\MollieApiClient; use Tests\Http\Adapter\MockMollieHttpAdapter; +/** + * @property MockMollieHttpAdapter $httpClient + */ class MockClient extends MollieApiClient { public function __construct(array $expectedResponses = []) @@ -15,4 +18,17 @@ public function __construct(array $expectedResponses = []) $this->setAccessToken('access_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); } + + /** + * @param string|callable $callback + */ + public function assertSent($callback): void + { + $this->httpClient->assertSent($callback); + } + + public function assertSentCount(int $count): void + { + $this->httpClient->assertSentCount($count); + } } diff --git a/tests/Fixtures/Responses/chargeback-list.json b/tests/Fixtures/Responses/chargeback-list.json index 440c06eaf..91e36fd18 100644 --- a/tests/Fixtures/Responses/chargeback-list.json +++ b/tests/Fixtures/Responses/chargeback-list.json @@ -202,6 +202,9 @@ "type": "application/hal+json" }, "previous": null, - "next": null + "next": { + "href": "...", + "type": "application/hal+json" + } } } diff --git a/tests/Fixtures/Responses/terminal-list.json b/tests/Fixtures/Responses/terminal-list.json index 2a4f48102..bf081f8f6 100644 --- a/tests/Fixtures/Responses/terminal-list.json +++ b/tests/Fixtures/Responses/terminal-list.json @@ -29,7 +29,10 @@ "type": "application/hal+json" }, "previous": null, - "next": null, + "next": { + "href": "...", + "type": "application/hal+json" + }, "documentation": { "href": "...", "type": "text/html" diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 54b405ba4..6f155f377 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -9,6 +9,7 @@ use Mollie\Api\Traits\HasDefaultFactories; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; +use PHPUnit\Framework\Assert as PHPUnit; class MockMollieHttpAdapter implements HttpAdapterContract { @@ -17,11 +18,13 @@ class MockMollieHttpAdapter implements HttpAdapterContract /** * @var array */ - private array $expectedResponses; + private array $expected; + + private array $recorded = []; public function __construct(array $expectedResponses = []) { - $this->expectedResponses = $expectedResponses; + $this->expected = $expectedResponses; } /** @@ -29,19 +32,28 @@ public function __construct(array $expectedResponses = []) */ public function sendRequest(PendingRequest $pendingRequest): Response { - $requestClass = get_class($pendingRequest->getRequest()); + $requestClass = get_class($request = $pendingRequest->getRequest()); - if (! Arr::has($this->expectedResponses, $requestClass)) { - throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); - } + $this->guardAgainstStrayRequests($requestClass); $mockedResponse = $this->getResponse($requestClass); - return new Response( + $response = new Response( $mockedResponse->createPsrResponse(), $pendingRequest->createPsrRequest(), $pendingRequest, ); + + $this->recorded[] = [$request, $response]; + + return $response; + } + + private function guardAgainstStrayRequests(string $requestClass): void + { + if (! Arr::has($this->expected, $requestClass)) { + throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); + } } /** @@ -49,10 +61,10 @@ public function sendRequest(PendingRequest $pendingRequest): Response */ private function getResponse(string $requestClass): MockResponse { - $mockedResponse = Arr::get($this->expectedResponses, $requestClass); + $mockedResponse = Arr::get($this->expected, $requestClass); if (! ($mockedResponse instanceof SequenceMockResponse)) { - Arr::forget($this->expectedResponses, $requestClass); + Arr::forget($this->expected, $requestClass); return $mockedResponse; } @@ -60,12 +72,45 @@ private function getResponse(string $requestClass): MockResponse $response = $mockedResponse->pop(); if ($mockedResponse->isEmpty()) { - Arr::forget($this->expectedResponses, $requestClass); + Arr::forget($this->expected, $requestClass); } return $response; } + public function recorded(callable $callback = null): array + { + if ($callback === null) { + return $this->recorded; + } + + return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); + } + + /** + * @param string|callable $callback + */ + public function assertSent($callback): void + { + if (is_string($callback)) { + $callback = fn ($request) => get_class($request) === $callback; + } + + PHPUnit::assertTrue( + count($this->recorded($callback)) > 0, + 'No requests were sent.' + ); + } + + public function assertSentCount(int $count): void + { + PHPUnit::assertEquals( + $count, + count($this->recorded), + 'The expected number of requests was not sent.' + ); + } + /** * {@inheritDoc} */ diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php new file mode 100644 index 000000000..6c4898801 --- /dev/null +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -0,0 +1,53 @@ + new MockResponse(200, 'apple-pay-session'), + ]); + + $payload = new RequestApplePayPaymentSessionPayload( + 'https://example.com', + 'Example Domain', + 'EUR' + ); + + $request = new ApplePayPaymentSessionRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(AnyResource::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $payload = new RequestApplePayPaymentSessionPayload( + 'https://example.com', + 'Example Domain', + 'EUR' + ); + + $request = new ApplePayPaymentSessionRequest($payload); + + $this->assertEquals( + 'wallets/applepay/sessions', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelPaymentRefundRequestTest.php b/tests/Http/Requests/CancelPaymentRefundRequestTest.php new file mode 100644 index 000000000..bf1d15d81 --- /dev/null +++ b/tests/Http/Requests/CancelPaymentRefundRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $paymentId = 'tr_7UhSN1zuXS'; + $refundId = 're_4qqhO89gsT'; + + $request = new CancelPaymentRefundRequest($paymentId, $refundId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_7UhSN1zuXS'; + $refundId = 're_4qqhO89gsT'; + + $request = new CancelPaymentRefundRequest($paymentId, $refundId); + + $this->assertEquals( + "payments/{$paymentId}/refunds/{$refundId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelPaymentRequestTest.php b/tests/Http/Requests/CancelPaymentRequestTest.php new file mode 100644 index 000000000..e1fb1e951 --- /dev/null +++ b/tests/Http/Requests/CancelPaymentRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'payment'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $request = new CancelPaymentRequest($paymentId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new CancelPaymentRequest($paymentId); + + $this->assertEquals( + "payments/{$paymentId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelSessionRequestTest.php b/tests/Http/Requests/CancelSessionRequestTest.php new file mode 100644 index 000000000..1eb90c80d --- /dev/null +++ b/tests/Http/Requests/CancelSessionRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'session'), + ]); + + $sessionId = 'sess_pNxqdWEFws'; + $request = new CancelSessionRequest($sessionId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Session::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $sessionId = 'sess_pNxqdWEFws'; + $request = new CancelSessionRequest($sessionId); + + $this->assertEquals( + "sessions/{$sessionId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CancelSubscriptionRequestTest.php b/tests/Http/Requests/CancelSubscriptionRequestTest.php new file mode 100644 index 000000000..b468e2f54 --- /dev/null +++ b/tests/Http/Requests/CancelSubscriptionRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'subscription'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new CancelSubscriptionRequest($customerId, $subscriptionId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new CancelSubscriptionRequest($customerId, $subscriptionId); + + $this->assertEquals( + "customers/{$customerId}/subscriptions/{$subscriptionId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php new file mode 100644 index 000000000..45aece5d1 --- /dev/null +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(201, 'client-link'), + ]); + + $payload = new CreateClientLinkPayload( + new Owner('test@example.org', 'John', 'Doe'), + 'Test', + new OwnerAddress('NL') + ); + + $request = new CreateClientLinkRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ClientLink::class, $response->toResource()); + } +} diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php new file mode 100644 index 000000000..a6f587497 --- /dev/null +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -0,0 +1,55 @@ + new MockResponse(201, 'payment'), + ]); + + $payload = new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect' + ); + + $request = new CreateCustomerPaymentRequest( + 'cst_123', + $payload, + new CreatePaymentQuery(true) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_123'; + $request = new CreateCustomerPaymentRequest($customerId, new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect' + )); + + $this->assertEquals("customers/{$customerId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php new file mode 100644 index 000000000..890bfcad9 --- /dev/null +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -0,0 +1,46 @@ + new MockResponse(201, 'customer'), + ]); + + $payload = new CreateCustomerPayload( + 'John Doe', + 'john@example.org' + ); + + $request = new CreateCustomerRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Customer::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateCustomerRequest(new CreateCustomerPayload( + 'John Doe', + 'john@example.org' + )); + + $this->assertEquals('customers', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php new file mode 100644 index 000000000..e91618f94 --- /dev/null +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -0,0 +1,55 @@ + new MockResponse(201, 'mandate'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $payload = new CreateMandatePayload( + 'directdebit', + 'John Doe', + 'NL55INGB0000000000' + ); + + $request = new CreateMandateRequest($customerId, $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Mandate::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $payload = new CreateMandatePayload( + 'directdebit', + 'John Doe', + 'NL55INGB0000000000' + ); + + $request = new CreateMandateRequest($customerId, $payload); + + $this->assertEquals( + "customers/{$customerId}/mandates", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php new file mode 100644 index 000000000..ce9908b76 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'capture'), + ]); + + $payload = new CreatePaymentCapturePayload( + 'Test capture', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentCaptureRequest('tr_123', $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Capture::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentCaptureRequest('tr_123', new CreatePaymentCapturePayload( + 'Test capture', + new Money('EUR', '10.00') + )); + + $this->assertEquals('payments/tr_123/captures', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php new file mode 100644 index 000000000..ba854938a --- /dev/null +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'payment-link'), + ]); + + $payload = new CreatePaymentLinkPayload( + 'Test payment link', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentLinkRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(PaymentLink::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentLinkRequest(new CreatePaymentLinkPayload( + 'Test payment link', + new Money('EUR', '10.00') + )); + + $this->assertEquals('payment-links', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php new file mode 100644 index 000000000..fda09f844 --- /dev/null +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -0,0 +1,54 @@ + new MockResponse(201, 'refund'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $payload = new CreateRefundPaymentPayload( + 'Order cancellation', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentRefundRequest($paymentId, $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Refund::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $payload = new CreateRefundPaymentPayload( + 'Order cancellation', + new Money('EUR', '10.00') + ); + + $request = new CreatePaymentRefundRequest($paymentId, $payload); + + $this->assertEquals( + "payments/{$paymentId}/refunds", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index 4758be8a5..b7c01a7d6 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -35,4 +35,17 @@ public function it_can_create_payment() $this->assertTrue($response->successful()); $this->assertInstanceOf(Payment::class, $response->toResource()); } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreatePaymentRequest(new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + )); + + $this->assertEquals('payments', $request->resolveResourcePath()); + } } diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php new file mode 100644 index 000000000..f1a5e3055 --- /dev/null +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -0,0 +1,52 @@ + new MockResponse(201, 'profile'), + ]); + + $payload = new CreateProfilePayload( + 'Test profile', + 'https://example.org', + 'test@example.org', + 'en_US', + '+31612345678' + ); + + $request = new CreateProfileRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Profile::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateProfileRequest(new CreateProfilePayload( + 'Test profile', + 'https://example.org', + 'test@example.org', + 'en_US', + '+31612345678' + )); + + $this->assertEquals('profiles', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php new file mode 100644 index 000000000..2c47d5c77 --- /dev/null +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(201, 'session'), + ]); + + $request = new CreateSessionRequest( + new AnyPayload(['foo' => 'bar']), + new AnyQuery(['baz' => 'qux']) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Session::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateSessionRequest(new AnyPayload(['foo' => 'bar']), new AnyQuery(['baz' => 'qux'])); + + $this->assertEquals('sessions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php new file mode 100644 index 000000000..e08a183cc --- /dev/null +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(201, 'subscription'), + ]); + + $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( + new Money('EUR', '10.00'), + '1 month', + 'Test subscription' + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( + new Money('EUR', '10.00'), + '1 month', + 'Test subscription' + )); + + $this->assertEquals('customers/cst_123/subscriptions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeleteCustomerRequestTest.php b/tests/Http/Requests/DeleteCustomerRequestTest.php new file mode 100644 index 000000000..3fe352d80 --- /dev/null +++ b/tests/Http/Requests/DeleteCustomerRequestTest.php @@ -0,0 +1,36 @@ + new MockResponse(204), + ]); + + $request = new DeleteCustomerRequest('cst_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new DeleteCustomerRequest('cst_123'); + + $this->assertEquals('customers/cst_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeletePaymentLinkRequestTest.php b/tests/Http/Requests/DeletePaymentLinkRequestTest.php new file mode 100644 index 000000000..0a112a243 --- /dev/null +++ b/tests/Http/Requests/DeletePaymentLinkRequestTest.php @@ -0,0 +1,36 @@ + new MockResponse(204), + ]); + + $request = new DeletePaymentLinkRequest('pl_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new DeletePaymentLinkRequest('pl_123'); + + $this->assertEquals('payment-links/pl_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeleteProfileRequestTest.php b/tests/Http/Requests/DeleteProfileRequestTest.php new file mode 100644 index 000000000..339fc2686 --- /dev/null +++ b/tests/Http/Requests/DeleteProfileRequestTest.php @@ -0,0 +1,41 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $request = new DeleteProfileRequest($profileId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $request = new DeleteProfileRequest($profileId); + + $this->assertEquals( + "profiles/{$profileId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DisableMethodIssuerRequestTest.php b/tests/Http/Requests/DisableMethodIssuerRequestTest.php new file mode 100644 index 000000000..60741dbb1 --- /dev/null +++ b/tests/Http/Requests/DisableMethodIssuerRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new DisableMethodIssuerRequest($profileId, $methodId, $issuerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new DisableMethodIssuerRequest($profileId, $methodId, $issuerId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}/issuers/{$issuerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DisableProfileMethodRequestTest.php b/tests/Http/Requests/DisableProfileMethodRequestTest.php new file mode 100644 index 000000000..fbb39aea1 --- /dev/null +++ b/tests/Http/Requests/DisableProfileMethodRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new DisableProfileMethodRequest($profileId, $methodId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new DisableProfileMethodRequest($profileId, $methodId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/DynamicGetRequestTest.php b/tests/Http/Requests/DynamicGetRequestTest.php new file mode 100644 index 000000000..7db9ee1a4 --- /dev/null +++ b/tests/Http/Requests/DynamicGetRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'payment'), + ]); + + $request = new DynamicGetRequest( + 'payments/tr_WDqYK6vllg', + Payment::class, + ['testmode' => 'true'] + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Payment::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $path = 'payments/tr_WDqYK6vllg'; + $request = new DynamicGetRequest($path, Payment::class); + + $this->assertEquals($path, $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php new file mode 100644 index 000000000..700924ed9 --- /dev/null +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -0,0 +1,45 @@ +expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("The resource class 'NonExistentClass' does not exist."); + + /** @phpstan-ignore-next-line */ + new class('some-url', 'NonExistentClass') extends DynamicRequest { + protected static string $method = Method::GET; + }; + } + + /** @test */ + public function it_accepts_valid_resource_class() + { + $request = new class('some-url', Payment::class) extends DynamicRequest { + protected static string $method = Method::GET; + }; + + $this->assertEquals(Payment::class, $request->getTargetResourceClass()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $url = 'https://example.org'; + $request = new class($url, Payment::class) extends DynamicRequest { + protected static string $method = Method::GET; + }; + + $this->assertEquals($url, $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/EnableMethodIssuerRequestTest.php b/tests/Http/Requests/EnableMethodIssuerRequestTest.php new file mode 100644 index 000000000..a0a1939df --- /dev/null +++ b/tests/Http/Requests/EnableMethodIssuerRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new EnableMethodIssuerRequest($profileId, $methodId, $issuerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $issuerId = 'INGBNL2A'; + $request = new EnableMethodIssuerRequest($profileId, $methodId, $issuerId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}/issuers/{$issuerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/EnableProfileMethodRequestTest.php b/tests/Http/Requests/EnableProfileMethodRequestTest.php new file mode 100644 index 000000000..95ab9c582 --- /dev/null +++ b/tests/Http/Requests/EnableProfileMethodRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new EnableProfileMethodRequest($profileId, $methodId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $profileId = 'pfl_v9hTwCvYqw'; + $methodId = 'ideal'; + $request = new EnableProfileMethodRequest($profileId, $methodId); + + $this->assertEquals( + "profiles/{$profileId}/methods/{$methodId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php new file mode 100644 index 000000000..be2aeeb7e --- /dev/null +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'method-list'), + ]); + + $request = new GetAllMethodsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetAllMethodsRequest(); + + $this->assertEquals('methods/all', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php new file mode 100644 index 000000000..94cfa4f3e --- /dev/null +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'subscription-list'), + ]); + + $request = new GetAllPaginatedSubscriptionsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(SubscriptionCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetAllPaginatedSubscriptionsRequest(); + + $this->assertEquals('subscriptions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php new file mode 100644 index 000000000..cae89d72f --- /dev/null +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'balance-report'), + ]); + + $request = new GetBalanceReportRequest( + 'bal_12345', + new GetBalanceReportQuery( + new DateTime('2024-01-01'), + new DateTime('2024-01-31'), + ) + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceReport::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetBalanceReportRequest('bal_12345', new GetBalanceReportQuery( + new DateTime('2024-01-01'), + new DateTime('2024-01-31'), + )); + + $this->assertEquals('balances/bal_12345/report', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetBalanceRequestTest.php b/tests/Http/Requests/GetBalanceRequestTest.php new file mode 100644 index 000000000..602301636 --- /dev/null +++ b/tests/Http/Requests/GetBalanceRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'balance'), + ]); + + $balanceId = 'bal_12345678'; + $request = new GetBalanceRequest($balanceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Balance::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $balanceId = 'bal_12345678'; + $request = new GetBalanceRequest($balanceId); + + $this->assertEquals( + "balances/{$balanceId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php new file mode 100644 index 000000000..bff99d570 --- /dev/null +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -0,0 +1,39 @@ + new MockResponse(200, 'client'), + ]); + + $request = new GetClientRequest('client_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Client::class, $response->toResource()); + $this->assertEquals('client', $response->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetClientRequest('client_123'); + + $this->assertEquals('clients/client_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetCustomerRequestTest.php b/tests/Http/Requests/GetCustomerRequestTest.php new file mode 100644 index 000000000..4626f72c9 --- /dev/null +++ b/tests/Http/Requests/GetCustomerRequestTest.php @@ -0,0 +1,42 @@ + new MockResponse(200, 'customer'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $request = new GetCustomerRequest($customerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Customer::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetCustomerRequest($customerId); + + $this->assertEquals( + "customers/{$customerId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php new file mode 100644 index 000000000..34c77ac64 --- /dev/null +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'method-list'), + ]); + + $request = new GetEnabledMethodsRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetEnabledMethodsRequest(); + + $this->assertEquals('methods', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetInvoiceRequestTest.php b/tests/Http/Requests/GetInvoiceRequestTest.php new file mode 100644 index 000000000..4dda901b9 --- /dev/null +++ b/tests/Http/Requests/GetInvoiceRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'invoice'), + ]); + + $invoiceId = 'inv_xBEbP9rvAq'; + $request = new GetInvoiceRequest($invoiceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Invoice::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetInvoiceRequest('inv_xBEbP9rvAq'); + + $this->assertEquals('invoices/inv_xBEbP9rvAq', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetMandateRequestTest.php b/tests/Http/Requests/GetMandateRequestTest.php new file mode 100644 index 000000000..2178d288d --- /dev/null +++ b/tests/Http/Requests/GetMandateRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'mandate'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new GetMandateRequest($customerId, $mandateId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Mandate::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new GetMandateRequest($customerId, $mandateId); + + $this->assertEquals( + "customers/{$customerId}/mandates/{$mandateId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetOnboardingRequestTest.php b/tests/Http/Requests/GetOnboardingRequestTest.php new file mode 100644 index 000000000..aa03c01f6 --- /dev/null +++ b/tests/Http/Requests/GetOnboardingRequestTest.php @@ -0,0 +1,37 @@ + new MockResponse(200, 'onboarding'), + ]); + + $request = new GetOnboardingRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Onboarding::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetOnboardingRequest(); + + $this->assertEquals('onboarding/me', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php new file mode 100644 index 000000000..fb4ad513d --- /dev/null +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'partner-status'), + ]); + + $request = new GetOrganizationPartnerStatusRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Partner::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetOrganizationPartnerStatusRequest(); + + $this->assertEquals('organizations/me/partner', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetOrganizationRequestTest.php b/tests/Http/Requests/GetOrganizationRequestTest.php new file mode 100644 index 000000000..97fb103e4 --- /dev/null +++ b/tests/Http/Requests/GetOrganizationRequestTest.php @@ -0,0 +1,39 @@ + new MockResponse(200, 'organization'), + ]); + + $organizationId = 'org_1337'; + $request = new GetOrganizationRequest($organizationId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Organization::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $organizationId = 'org_1337'; + $request = new GetOrganizationRequest($organizationId); + + $this->assertEquals("organizations/{$organizationId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php new file mode 100644 index 000000000..a65e8915d --- /dev/null +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -0,0 +1,37 @@ + new MockResponse(200, 'balance-list'), + ]); + + $request = new GetPaginatedBalanceRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedBalanceRequest(); + + $this->assertEquals('balances', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php new file mode 100644 index 000000000..0b1aae7bd --- /dev/null +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -0,0 +1,40 @@ + new MockResponse(200, 'balance-transactions'), + ]); + + $balanceId = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + $request = new GetPaginatedBalanceTransactionRequest($balanceId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(BalanceTransactionCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $balanceId = 'bal_gVMhHKqSSRYJyPsuoPNFH'; + $request = new GetPaginatedBalanceTransactionRequest($balanceId); + + $this->assertEquals("balances/{$balanceId}/transactions", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php new file mode 100644 index 000000000..001fab9cd --- /dev/null +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedChargebacksRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ChargebackCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedChargebacksRequest(); + + $this->assertEquals('chargebacks', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php new file mode 100644 index 000000000..cce9a83b6 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'client-list'), + ]); + + $request = new GetPaginatedClientRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(ClientCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedClientRequest(); + + $this->assertEquals('clients', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php new file mode 100644 index 000000000..facbbdd90 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -0,0 +1,40 @@ + new MockResponse(200, 'payment-list'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedCustomerPaymentsRequest($customerId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(PaymentCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedCustomerPaymentsRequest($customerId); + + $this->assertEquals("customers/{$customerId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php new file mode 100644 index 000000000..654b58a25 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'customer-list'), + ]); + + $request = new GetPaginatedCustomerRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(CustomerCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedCustomerRequest(); + + $this->assertEquals('customers', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php new file mode 100644 index 000000000..3437ce5de --- /dev/null +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -0,0 +1,38 @@ + new MockResponse(200, 'invoice-list'), + ]); + + $request = new GetPaginatedInvoiceRequest(); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(InvoiceCollection::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedInvoiceRequest(); + + $this->assertEquals('invoices', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedMandateRequestTest.php b/tests/Http/Requests/GetPaginatedMandateRequestTest.php new file mode 100644 index 000000000..33f8155c6 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedMandateRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'mandate-list'), + ]); + + $request = new GetPaginatedMandateRequest('cst_kEn1PlbGa'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var MandateCollection */ + $mandates = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(MandateCollection::class, $mandates); + $this->assertGreaterThan(0, $mandates->count()); + + foreach ($mandates as $mandate) { + $this->assertInstanceOf(Mandate::class, $mandate); + $this->assertEquals('mandate', $mandate->resource); + } + } + + /** @test */ + public function it_can_iterate_over_mandates() + { + $client = new MockClient([ + GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'mandate-list'), + new MockResponse(200, 'empty-list', 'mandates'), + ), + ]); + + $request = (new GetPaginatedMandateRequest('cst_kEn1PlbGa'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $mandates = $response->toResource(); + + foreach ($mandates as $mandate) { + $this->assertInstanceOf(Mandate::class, $mandate); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedMandateRequest($customerId); + + $this->assertEquals("customers/{$customerId}/mandates", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php new file mode 100644 index 000000000..806af8489 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'capture-list'), + ]); + + $request = new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var CaptureCollection */ + $captures = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertGreaterThan(0, $captures->count()); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + } + + /** @test */ + public function it_can_iterate_over_captures() + { + $client = new MockClient([ + GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'capture-list'), + new MockResponse(200, 'empty-list', 'captures'), + ), + ]); + + $request = (new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $captures = $response->toResource(); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentCapturesRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/captures", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php new file mode 100644 index 000000000..36b8cc131 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ChargebackCollection */ + $chargebacks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + } + + /** @test */ + public function it_can_iterate_over_chargebacks() + { + $client = new MockClient([ + GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'chargeback-list'), + new MockResponse(200, 'empty-list', 'chargebacks'), + ), + ]); + + $request = (new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $chargebacks = $response->toResource(); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentChargebacksRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/chargebacks", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php new file mode 100644 index 000000000..3514d3d42 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_payment_link_payments() + { + $client = new MockClient([ + GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentLinkId = 'pl_4Y0eZitmBnQ5jsBYZIBw'; + $request = new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId); + + $this->assertEquals("payment-links/{$paymentLinkId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php new file mode 100644 index 000000000..ad2623695 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'payment-link-list'), + ]); + + $request = new GetPaginatedPaymentLinksRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLinkCollection */ + $paymentLinks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentLinkCollection::class, $paymentLinks); + $this->assertGreaterThan(0, $paymentLinks->count()); + + foreach ($paymentLinks as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + } + + /** @test */ + public function it_can_iterate_over_payment_links() + { + $client = new MockClient([ + GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-link-list'), + new MockResponse(200, 'empty-list', 'payment_links'), + ), + ]); + + $request = (new GetPaginatedPaymentLinksRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $paymentLinks = $response->toResource(); + + foreach ($paymentLinks as $paymentLink) { + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedPaymentLinksRequest(); + + $this->assertEquals('payment-links', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php new file mode 100644 index 000000000..d5029305c --- /dev/null +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_refunds() + { + $client = new MockClient([ + GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaginatedPaymentRefundsRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}/refunds", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index b804844c6..a3d8171c8 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -10,6 +10,7 @@ use Mollie\Api\Resources\PaymentCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; +use Tests\Fixtures\SequenceMockResponse; use Tests\TestCase; class GetPaginatedPaymentsRequestTest extends TestCase @@ -45,8 +46,10 @@ public function it_can_iterate_over_payments() { $client = new MockClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), - DynamicGetRequest::class => new MockResponse(200, 'payment-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), ]); $request = (new GetPaginatedPaymentsRequest)->useIterator(); @@ -61,5 +64,15 @@ public function it_can_iterate_over_payments() foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedPaymentsRequest(); + + $this->assertEquals('payments', $request->resolveResourcePath()); } } diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php new file mode 100644 index 000000000..e1dd95dba --- /dev/null +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'profile-list'), + ]); + + $request = new GetPaginatedProfilesRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ProfileCollection */ + $profiles = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ProfileCollection::class, $profiles); + $this->assertGreaterThan(0, $profiles->count()); + + foreach ($profiles as $profile) { + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + } + + /** @test */ + public function it_can_iterate_over_profiles() + { + $client = new MockClient([ + GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'profile-list'), + new MockResponse(200, 'empty-list', 'profiles'), + ), + ]); + + $request = (new GetPaginatedProfilesRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $profiles = $response->toResource(); + + foreach ($profiles as $profile) { + $this->assertInstanceOf(Profile::class, $profile); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedProfilesRequest(); + + $this->assertEquals('profiles', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php new file mode 100644 index 000000000..42b9f2d5d --- /dev/null +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedRefundsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_refunds() + { + $client = new MockClient([ + GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedRefundsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedRefundsRequest(); + + $this->assertEquals('refunds', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php new file mode 100644 index 000000000..08e577f29 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'session-list'), + ]); + + $request = new GetPaginatedSessionsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SessionCollection */ + $sessions = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SessionCollection::class, $sessions); + $this->assertGreaterThan(0, $sessions->count()); + + foreach ($sessions as $session) { + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + } + + /** @test */ + public function it_can_iterate_over_sessions() + { + $client = new MockClient([ + GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'session-list'), + new MockResponse(200, 'empty-list', 'sessions'), + ), + ]); + + $request = (new GetPaginatedSessionsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $sessions = $response->toResource(); + + foreach ($sessions as $session) { + $this->assertInstanceOf(Session::class, $session); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedSessionsRequest(); + + $this->assertEquals('sessions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php new file mode 100644 index 000000000..e8dbdde0e --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'capture-list'), + ]); + + $request = new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var CaptureCollection */ + $captures = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(CaptureCollection::class, $captures); + $this->assertGreaterThan(0, $captures->count()); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_captures() + { + $client = new MockClient([ + GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'capture-list'), + new MockResponse(200, 'empty-list', 'captures'), + ), + ]); + + $request = (new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $captures = $response->toResource(); + + foreach ($captures as $capture) { + $this->assertInstanceOf(Capture::class, $capture); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementCapturesRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/captures", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php new file mode 100644 index 000000000..87a0838e9 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'chargeback-list'), + ]); + + $request = new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var ChargebackCollection */ + $chargebacks = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); + $this->assertGreaterThan(0, $chargebacks->count()); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_chargebacks() + { + $client = new MockClient([ + GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'chargeback-list'), + new MockResponse(200, 'empty-list', 'chargebacks'), + ), + ]); + + $request = (new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $chargebacks = $response->toResource(); + + foreach ($chargebacks as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementChargebacksRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/chargebacks", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php new file mode 100644 index 000000000..617fc25b5 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_payments() + { + $client = new MockClient([ + GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementPaymentsRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php new file mode 100644 index 000000000..dd4679b27 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -0,0 +1,79 @@ + new MockResponse(200, 'refund-list'), + ]); + + $request = new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var RefundCollection */ + $refunds = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertGreaterThan(0, $refunds->count()); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlement_refunds() + { + $client = new MockClient([ + GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'refund-list'), + new MockResponse(200, 'empty-list', 'refunds'), + ), + ]); + + $request = (new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $refunds = $response->toResource(); + + foreach ($refunds as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $settlementId = 'stl_jDk30akdN'; + $request = new GetPaginatedSettlementRefundsRequest($settlementId); + + $this->assertEquals("settlements/{$settlementId}/refunds", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php new file mode 100644 index 000000000..c19505284 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'settlement-list'), + ]); + + $request = new GetPaginatedSettlementsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SettlementCollection */ + $settlements = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SettlementCollection::class, $settlements); + $this->assertGreaterThan(0, $settlements->count()); + + foreach ($settlements as $settlement) { + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals('settlement', $settlement->resource); + } + } + + /** @test */ + public function it_can_iterate_over_settlements() + { + $client = new MockClient([ + GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'settlement-list'), + new MockResponse(200, 'empty-list', 'settlements'), + ), + ]); + + $request = (new GetPaginatedSettlementsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $settlements = $response->toResource(); + + foreach ($settlements as $settlement) { + $this->assertInstanceOf(Settlement::class, $settlement); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedSettlementsRequest(); + + $this->assertEquals('settlements', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php new file mode 100644 index 000000000..6b7d7748a --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -0,0 +1,81 @@ + new MockResponse(200, 'payment-list'), + ]); + + $request = new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentCollection */ + $payments = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(PaymentCollection::class, $payments); + $this->assertGreaterThan(0, $payments->count()); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + } + + /** @test */ + public function it_can_iterate_over_subscription_payments() + { + $client = new MockClient([ + GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'payment-list'), + new MockResponse(200, 'empty-list', 'payments'), + ), + ]); + + $request = (new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $payments = $response->toResource(); + + foreach ($payments as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId); + + $this->assertEquals("customers/{$customerId}/subscriptions/{$subscriptionId}/payments", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php new file mode 100644 index 000000000..4731b4716 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -0,0 +1,80 @@ + new MockResponse(200, 'subscription-list'), + ]); + + $request = new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SubscriptionCollection */ + $subscriptions = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); + $this->assertGreaterThan(0, $subscriptions->count()); + + foreach ($subscriptions as $subscription) { + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertEquals('subscription', $subscription->resource); + } + } + + /** @test */ + public function it_can_iterate_over_subscriptions() + { + $client = new MockClient([ + GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'subscription-list'), + new MockResponse(200, 'empty-list', 'subscriptions'), + ), + ]); + + $request = (new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'))->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $subscriptions = $response->toResource(); + + foreach ($subscriptions as $subscription) { + $this->assertInstanceOf(Subscription::class, $subscription); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $request = new GetPaginatedSubscriptionsRequest($customerId); + + $this->assertEquals("customers/{$customerId}/subscriptions", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php new file mode 100644 index 000000000..19e1fd61e --- /dev/null +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -0,0 +1,78 @@ + new MockResponse(200, 'terminal-list'), + ]); + + $request = new GetPaginatedTerminalsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var TerminalCollection */ + $terminals = $response->toResource(); + // Assert response was properly handled + $this->assertInstanceOf(TerminalCollection::class, $terminals); + $this->assertGreaterThan(0, $terminals->count()); + + foreach ($terminals as $terminal) { + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals('terminal', $terminal->resource); + } + } + + /** @test */ + public function it_can_iterate_over_terminals() + { + $client = new MockClient([ + GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'terminal-list'), + new MockResponse(200, 'empty-list', 'terminals'), + ), + ]); + + $request = (new GetPaginatedTerminalsRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $terminals = $response->toResource(); + + foreach ($terminals as $terminal) { + $this->assertInstanceOf(Terminal::class, $terminal); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedTerminalsRequest; + + $this->assertEquals('terminals', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentCaptureRequestTest.php b/tests/Http/Requests/GetPaymentCaptureRequestTest.php new file mode 100644 index 000000000..10c3d60a6 --- /dev/null +++ b/tests/Http/Requests/GetPaymentCaptureRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'capture'), + ]); + + $request = new GetPaymentCaptureRequest('tr_WDqYK6vllg', 'cpt_4qqhO89gsT'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Capture */ + $capture = $response->toResource(); + + $this->assertInstanceOf(Capture::class, $capture); + $this->assertEquals('capture', $capture->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $captureId = 'cpt_4qqhO89gsT'; + $request = new GetPaymentCaptureRequest($paymentId, $captureId); + + $this->assertEquals("payments/{$paymentId}/captures/{$captureId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentChargebackRequestTest.php b/tests/Http/Requests/GetPaymentChargebackRequestTest.php new file mode 100644 index 000000000..116a46e9d --- /dev/null +++ b/tests/Http/Requests/GetPaymentChargebackRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'chargeback'), + ]); + + $request = new GetPaymentChargebackRequest('tr_WDqYK6vllg', 'chb_n9z0tp'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Chargeback */ + $chargeback = $response->toResource(); + + $this->assertInstanceOf(Chargeback::class, $chargeback); + $this->assertEquals('chargeback', $chargeback->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $chargebackId = 'chb_n9z0tp'; + $request = new GetPaymentChargebackRequest($paymentId, $chargebackId); + + $this->assertEquals("payments/{$paymentId}/chargebacks/{$chargebackId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentLinkRequestTest.php b/tests/Http/Requests/GetPaymentLinkRequestTest.php new file mode 100644 index 000000000..8914a2b84 --- /dev/null +++ b/tests/Http/Requests/GetPaymentLinkRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(200, 'payment-link'), + ]); + + $request = new GetPaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLink */ + $paymentLink = $response->toResource(); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentLinkId = 'pl_4Y0eZitmBnQ5jsBYZIBw'; + $request = new GetPaymentLinkRequest($paymentLinkId); + + $this->assertEquals("payment-links/{$paymentLinkId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php new file mode 100644 index 000000000..cc572e906 --- /dev/null +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'method'), + ]); + + $request = new GetPaymentMethodRequest('ideal'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Method */ + $method = $response->toResource(); + + $this->assertInstanceOf(Method::class, $method); + $this->assertEquals('method', $method->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $methodId = 'ideal'; + $request = new GetPaymentMethodRequest($methodId); + + $this->assertEquals("methods/{$methodId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php new file mode 100644 index 000000000..a90463e71 --- /dev/null +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(200, 'refund'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $refundId = 're_4qqhO89gsT'; + $request = new GetPaymentRefundRequest($paymentId, $refundId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Refund */ + $refund = $response->toResource(); + + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals('refund', $refund->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $refundId = 're_4qqhO89gsT'; + $request = new GetPaymentRefundRequest($paymentId, $refundId); + + $this->assertEquals("payments/{$paymentId}/refunds/{$refundId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php new file mode 100644 index 000000000..c1264a678 --- /dev/null +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'payment'), + ]); + + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaymentRequest($paymentId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Payment */ + $payment = $response->toResource(); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $paymentId = 'tr_WDqYK6vllg'; + $request = new GetPaymentRequest($paymentId); + + $this->assertEquals("payments/{$paymentId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPermissionRequestTest.php b/tests/Http/Requests/GetPermissionRequestTest.php new file mode 100644 index 000000000..dacdf72e0 --- /dev/null +++ b/tests/Http/Requests/GetPermissionRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'permission'), + ]); + + $request = new GetPermissionRequest('payments.read'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Permission */ + $permission = $response->toResource(); + + $this->assertInstanceOf(Permission::class, $permission); + $this->assertEquals('permission', $permission->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPermissionRequest('payments.read'); + + $this->assertEquals( + 'permissions/payments.read', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetProfileRequestTest.php b/tests/Http/Requests/GetProfileRequestTest.php new file mode 100644 index 000000000..8637aff66 --- /dev/null +++ b/tests/Http/Requests/GetProfileRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'profile'), + ]); + + $request = new GetProfileRequest('pfl_v9hTwCvYqw'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Profile */ + $profile = $response->toResource(); + + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetProfileRequest('pfl_v9hTwCvYqw'); + + $this->assertEquals( + 'profiles/pfl_v9hTwCvYqw', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php new file mode 100644 index 000000000..db2829768 --- /dev/null +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -0,0 +1,54 @@ + new MockResponse(200, 'session'), + ]); + + $query = new AnyQuery([ + 'testmode' => true, + ]); + + $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Session */ + $session = $response->toResource(); + + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $query = new AnyQuery([ + 'testmode' => true, + ]); + + $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + + $this->assertEquals( + 'sessions/ses_LQNz4v4Qvk', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSettlementRequestTest.php b/tests/Http/Requests/GetSettlementRequestTest.php new file mode 100644 index 000000000..c48d15371 --- /dev/null +++ b/tests/Http/Requests/GetSettlementRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'settlement'), + ]); + + $request = new GetSettlementRequest('stl_jDk30akdN'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Settlement */ + $settlement = $response->toResource(); + + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals('settlement', $settlement->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetSettlementRequest('stl_jDk30akdN'); + + $this->assertEquals( + 'settlements/stl_jDk30akdN', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetSubscriptionRequestTest.php b/tests/Http/Requests/GetSubscriptionRequestTest.php new file mode 100644 index 000000000..5b2b93dec --- /dev/null +++ b/tests/Http/Requests/GetSubscriptionRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'subscription'), + ]); + + $request = new GetSubscriptionRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Subscription */ + $subscription = $response->toResource(); + + $this->assertInstanceOf(Subscription::class, $subscription); + $this->assertEquals('subscription', $subscription->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetSubscriptionRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); + + $this->assertEquals( + 'customers/cst_kEn1PlbGa/subscriptions/sub_rVKGtNd6s3', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/GetTerminalRequestTest.php b/tests/Http/Requests/GetTerminalRequestTest.php new file mode 100644 index 000000000..537b80e92 --- /dev/null +++ b/tests/Http/Requests/GetTerminalRequestTest.php @@ -0,0 +1,45 @@ + new MockResponse(200, 'terminal'), + ]); + + $request = new GetTerminalRequest('term_7MgL4wea'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Terminal */ + $terminal = $response->toResource(); + + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals('terminal', $terminal->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetTerminalRequest('term_7MgL4wea'); + + $this->assertEquals( + 'terminals/term_7MgL4wea', + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/ListPermissionsRequestTest.php b/tests/Http/Requests/ListPermissionsRequestTest.php new file mode 100644 index 000000000..7fb0630c6 --- /dev/null +++ b/tests/Http/Requests/ListPermissionsRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'permission-list'), + ]); + + $request = new ListPermissionsRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PermissionCollection */ + $permissions = $response->toResource(); + + $this->assertInstanceOf(PermissionCollection::class, $permissions); + $this->assertGreaterThan(0, $permissions->count()); + + foreach ($permissions as $permission) { + $this->assertInstanceOf(Permission::class, $permission); + $this->assertEquals('permission', $permission->resource); + } + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new ListPermissionsRequest; + + $this->assertEquals('permissions', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/PaginatedRequestTest.php b/tests/Http/Requests/PaginatedRequestTest.php new file mode 100644 index 000000000..ac0cc2051 --- /dev/null +++ b/tests/Http/Requests/PaginatedRequestTest.php @@ -0,0 +1,53 @@ +assertEquals([], $request->query()->all()); + } + + /** @test */ + public function it_can_handle_query() + { + $query = new ConcreteQuery(['limit' => 10]); + $request = new ConcretePaginatedRequest($query); + + $this->assertEquals(['limit' => 10], $request->query()->all()); + } +} + +class ConcretePaginatedRequest extends PaginatedRequest +{ + public static string $targetResourceClass = BaseCollection::class; + + public function resolveResourcePath(): string + { + return 'test'; + } +} + +class ConcreteQuery extends Query +{ + private array $parameters; + + public function __construct(array $parameters) + { + $this->parameters = $parameters; + } + + public function toArray(): array + { + return $this->parameters; + } +} diff --git a/tests/Http/Requests/ResourceHydratableRequestTest.php b/tests/Http/Requests/ResourceHydratableRequestTest.php new file mode 100644 index 000000000..5e650c7c8 --- /dev/null +++ b/tests/Http/Requests/ResourceHydratableRequestTest.php @@ -0,0 +1,61 @@ +assertEquals(BaseResource::class, $request->getTargetResourceClass()); + } + + /** @test */ + public function it_can_toggle_auto_hydration() + { + $request = new ConcreteResourceHydratableRequest; + + $this->assertFalse($request->shouldAutoHydrate()); + + ConcreteResourceHydratableRequest::hydrate(true); + $this->assertTrue($request->shouldAutoHydrate()); + + ConcreteResourceHydratableRequest::hydrate(false); + $this->assertFalse($request->shouldAutoHydrate()); + } + + /** @test */ + public function it_throws_exception_when_target_resource_class_is_not_set() + { + $request = new InvalidResourceHydratableRequest; + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Resource class is not set.'); + + $request->getTargetResourceClass(); + } +} + +class ConcreteResourceHydratableRequest extends ResourceHydratableRequest +{ + public static string $targetResourceClass = BaseResource::class; + + public function resolveResourcePath(): string + { + return 'test'; + } +} + +class InvalidResourceHydratableRequest extends ResourceHydratableRequest +{ + public function resolveResourcePath(): string + { + return 'test'; + } +} diff --git a/tests/Http/Requests/RevokeMandateRequestTest.php b/tests/Http/Requests/RevokeMandateRequestTest.php new file mode 100644 index 000000000..f41e7d78f --- /dev/null +++ b/tests/Http/Requests/RevokeMandateRequestTest.php @@ -0,0 +1,43 @@ + new MockResponse(204, ''), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new RevokeMandateRequest($customerId, $mandateId); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $mandateId = 'mdt_h3gAaD5zP'; + $request = new RevokeMandateRequest($customerId, $mandateId); + + $this->assertEquals( + "customers/{$customerId}/mandates/{$mandateId}", + $request->resolveResourcePath() + ); + } +} diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php new file mode 100644 index 000000000..1ba140832 --- /dev/null +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'customer'), + ]); + + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( + 'Updated Customer Name', + 'updated@example.com', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Customer */ + $customer = $response->toResource(); + + $this->assertInstanceOf(Customer::class, $customer); + $this->assertEquals('customer', $customer->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( + 'Updated Customer Name', + 'updated@example.com', + )); + + $this->assertEquals('customers/cst_kEn1PlbGa', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php new file mode 100644 index 000000000..aeb38ba5d --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'payment-link'), + ]); + + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( + 'Updated payment link', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var PaymentLink */ + $paymentLink = $response->toResource(); + + $this->assertInstanceOf(PaymentLink::class, $paymentLink); + $this->assertEquals('payment-link', $paymentLink->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( + 'Updated payment link', + )); + + $this->assertEquals('payment-links/pl_4Y0eZitmBnQ5jsBYZIBw', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php new file mode 100644 index 000000000..94805f3f4 --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -0,0 +1,49 @@ + new MockResponse(200, 'payment'), + ]); + + $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + 'Updated payment description', + 'https://example.com/redirect', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Payment */ + $payment = $response->toResource(); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('payment', $payment->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + 'Updated payment description', + 'https://example.com/redirect', + )); + + $this->assertEquals('payments/tr_WDqYK6vllg', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php new file mode 100644 index 000000000..a410da746 --- /dev/null +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -0,0 +1,48 @@ + new MockResponse(200, 'route'), + ]); + + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( + new DateTime('2024-01-01'), + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Route */ + $route = $response->toResource(); + + $this->assertInstanceOf(Route::class, $route); + $this->assertEquals('route', $route->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( + new DateTime('2024-01-01'), + )); + + $this->assertEquals('payments/tr_WDqYK6vllg/routes/rt_H2wvxEyQcP', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php new file mode 100644 index 000000000..94071d247 --- /dev/null +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -0,0 +1,47 @@ + new MockResponse(200, 'profile'), + ]); + + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( + 'Updated Profile Name', + )); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Profile */ + $profile = $response->toResource(); + + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('profile', $profile->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( + 'Updated Profile Name', + )); + + $this->assertEquals('profiles/pfl_v9hTwCvYqw', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php new file mode 100644 index 000000000..cdae6c845 --- /dev/null +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -0,0 +1,51 @@ + new MockResponse(200, 'session'), + ]); + + $payload = new AnyPayload([ + 'status' => 'completed', + 'metadata' => [ + 'order_id' => '12345', + ], + ]); + + $request = new UpdateSessionRequest('ses_LQNz4v4Qvk', $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var Session */ + $session = $response->toResource(); + + $this->assertInstanceOf(Session::class, $session); + $this->assertEquals('session', $session->resource); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $sessionId = 'ses_LQNz4v4Qvk'; + $request = new UpdateSessionRequest($sessionId, new AnyPayload()); + + $this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php new file mode 100644 index 000000000..cb27e5aae --- /dev/null +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -0,0 +1,60 @@ + new MockResponse(200, 'subscription'), + ]); + + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + + $money = new Money('EUR', '20.00'); + $payload = new UpdateSubscriptionPayload( + $money, + 'Updated subscription', + '1 month' + ); + + $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, $payload); + + $this->assertEquals( + "customers/{$customerId}/subscriptions/{$subscriptionId}", + $request->resolveResourcePath() + ); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(Subscription::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $customerId = 'cst_kEn1PlbGa'; + $subscriptionId = 'sub_rVKGtNd6s3'; + $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, new UpdateSubscriptionPayload( + new Money('EUR', '20.00'), + 'Updated subscription', + '1 month' + )); + + $this->assertEquals("customers/{$customerId}/subscriptions/{$subscriptionId}", $request->resolveResourcePath()); + } +} diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 3500064c1..848837f94 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -30,8 +30,6 @@ public function can_get_next_collection_result_when_next_link_is_available() ]) ); - $collection->setAutoHydrate(); - $this->assertTrue($collection->hasNext()); $nextPage = $collection->next(); @@ -49,8 +47,6 @@ public function test_will_return_null_if_no_next_result_is_available() (object) [] ); - $collection->setAutoHydrate(); - $this->assertFalse($collection->hasNext()); $this->assertNull($collection->next()); } @@ -71,8 +67,6 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av ]) ); - $collection->setAutoHydrate(); - $this->assertTrue($collection->hasPrevious()); $previousPage = $collection->previous(); @@ -90,8 +84,6 @@ public function test_will_return_null_if_no_previous_result_is_available() (object) [] ); - $collection->setAutoHydrate(); - $this->assertFalse($collection->hasPrevious()); $this->assertNull($collection->previous()); } @@ -106,8 +98,6 @@ public function test_auto_paginator_returns_lazy_collection() (object) [] ); - $collection->setAutoHydrate(); - $this->assertInstanceOf(LazyCollection::class, $collection->getAutoIterator()); } @@ -131,12 +121,12 @@ public function test_auto_paginator_can_handle_consecutive_calls() ]) ); - $orderIds = []; - foreach ($collection->getAutoIterator() as $order) { - $orderIds[] = $order->id; + $paymentIds = []; + foreach ($collection->getAutoIterator() as $payment) { + $paymentIds[] = $payment->id; } - $this->assertEquals(['tr_stTC2WHAuF', 'tr_stTC2WHAuS', 'tr_stTC2WHAuB'], $orderIds); + $this->assertEquals(['tr_stTC2WHAuF', 'tr_stTC2WHAuS', 'tr_stTC2WHAuB'], $paymentIds); } /** From 02ca3a2667cc87838ab73dc361156cafb0bf7cf7 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 5 Dec 2024 12:34:27 +0000 Subject: [PATCH 094/131] Fixes coding style --- src/Http/Requests/GetAllMethodsRequest.php | 2 +- src/Resources/CursorCollection.php | 2 ++ src/Traits/DelegatesToResource.php | 3 ++- .../ChargebackEndpointCollectionTest.php | 2 +- .../PaymentChargebackEndpointCollectionTest.php | 2 +- .../SettlementChargebackEndpointCollectionTest.php | 2 +- tests/Http/Adapter/MockMollieHttpAdapter.php | 4 ++-- tests/Http/Requests/DynamicRequestTest.php | 9 ++++++--- tests/Http/Requests/GetAllMethodsRequestTest.php | 5 ++--- .../Requests/GetAllPaginatedSubscriptionsRequestTest.php | 5 ++--- tests/Http/Requests/GetBalanceReportRequestTest.php | 1 - tests/Http/Requests/GetClientRequestTest.php | 1 - tests/Http/Requests/GetEnabledMethodsRequestTest.php | 5 ++--- tests/Http/Requests/GetOnboardingRequestTest.php | 4 ++-- .../Requests/GetOrganizationPartnerStatusRequestTest.php | 5 ++--- tests/Http/Requests/GetPaginatedBalanceRequestTest.php | 4 ++-- .../GetPaginatedBalanceTransactionRequestTest.php | 1 - .../Http/Requests/GetPaginatedChargebacksRequestTest.php | 5 ++--- tests/Http/Requests/GetPaginatedClientRequestTest.php | 5 ++--- .../Requests/GetPaginatedCustomerPaymentsRequestTest.php | 1 - tests/Http/Requests/GetPaginatedCustomerRequestTest.php | 5 ++--- tests/Http/Requests/GetPaginatedInvoiceRequestTest.php | 5 ++--- .../GetPaginatedPaymentLinkPaymentsRequestTest.php | 2 +- .../Requests/GetPaginatedPaymentLinksRequestTest.php | 4 ++-- .../Requests/GetPaginatedPaymentRefundsRequestTest.php | 2 +- tests/Http/Requests/GetPaginatedPaymentsRequestTest.php | 2 +- tests/Http/Requests/GetPaginatedProfilesRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedRefundsRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedSessionsRequestTest.php | 4 ++-- .../GetPaginatedSettlementPaymentsRequestTest.php | 2 +- .../GetPaginatedSettlementRefundsRequestTest.php | 2 +- .../Http/Requests/GetPaginatedSettlementsRequestTest.php | 4 ++-- .../GetPaginatedSubscriptionPaymentsRequestTest.php | 2 +- .../Requests/GetPaginatedSubscriptionsRequestTest.php | 3 +-- tests/Http/Requests/GetPaginatedTerminalsRequestTest.php | 2 +- tests/Http/Requests/GetPaymentMethodRequestTest.php | 1 - tests/Http/Requests/GetPaymentRefundRequestTest.php | 1 - tests/Http/Requests/GetPaymentRequestTest.php | 1 - tests/Http/Requests/UpdatePaymentLinkRequestTest.php | 1 - tests/Http/Requests/UpdateSessionRequestTest.php | 2 +- tests/Http/Requests/UpdateSubscriptionRequestTest.php | 2 +- 41 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index ee5b11eda..7d600411e 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -22,7 +22,7 @@ class GetAllMethodsRequest extends ResourceHydratableRequest public function __construct(?GetAllMethodsQuery $query = null) { - $this->query = $query ?: new GetAllMethodsQuery(); + $this->query = $query ?: new GetAllMethodsQuery; } protected function defaultQuery(): array diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 6959751d7..498f9fc26 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -12,6 +12,7 @@ abstract class CursorCollection extends ResourceCollection * Return the next set of resources when available * * @return null|CursorCollection|Response + * * @throws \Mollie\Api\Exceptions\ApiException */ public function next() @@ -27,6 +28,7 @@ public function next() * Return the previous set of resources when available * * @return null|CursorCollection|Response + * * @throws \Mollie\Api\Exceptions\ApiException */ public function previous() diff --git a/src/Traits/DelegatesToResource.php b/src/Traits/DelegatesToResource.php index 3d3824a7c..1ef396d8d 100644 --- a/src/Traits/DelegatesToResource.php +++ b/src/Traits/DelegatesToResource.php @@ -9,6 +9,7 @@ /** * @mixin Response + * * @property null|BaseResource|ResourceCollection $resource */ trait DelegatesToResource @@ -49,7 +50,7 @@ public function __get($key) { $this->ensureResourceIsLoaded(); - if (!property_exists($this->resource, $key)) { + if (! property_exists($this->resource, $key)) { throw new \InvalidArgumentException("Property {$key} does not exist on resource."); } diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index 000cc8136..a0ad4190c 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -35,7 +35,7 @@ public function iterator() { $client = new MockClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); foreach ($client->chargebacks->iterator() as $chargeback) { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index b4a28673e..a25cffb96 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -50,7 +50,7 @@ public function iterator_for_id() { $client = new MockClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); foreach ($client->paymentChargebacks->iteratorForId('tr_7UhSN1zuXS') as $chargeback) { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 6b6ac696a..9d27b5861 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -39,7 +39,7 @@ public function iterator_for() { $client = new MockClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), - DynamicGetRequest::class => new MockResponse(200, 'empty-list','chargebacks'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); $settlement = new Settlement($client); diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 6f155f377..d009464e4 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\HasDefaultFactories; +use PHPUnit\Framework\Assert as PHPUnit; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use PHPUnit\Framework\Assert as PHPUnit; class MockMollieHttpAdapter implements HttpAdapterContract { @@ -78,7 +78,7 @@ private function getResponse(string $requestClass): MockResponse return $response; } - public function recorded(callable $callback = null): array + public function recorded(?callable $callback = null): array { if ($callback === null) { return $this->recorded; diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php index 700924ed9..77c389748 100644 --- a/tests/Http/Requests/DynamicRequestTest.php +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -17,7 +17,8 @@ public function it_throws_exception_for_invalid_resource_class() $this->expectExceptionMessage("The resource class 'NonExistentClass' does not exist."); /** @phpstan-ignore-next-line */ - new class('some-url', 'NonExistentClass') extends DynamicRequest { + new class('some-url', 'NonExistentClass') extends DynamicRequest + { protected static string $method = Method::GET; }; } @@ -25,7 +26,8 @@ public function it_throws_exception_for_invalid_resource_class() /** @test */ public function it_accepts_valid_resource_class() { - $request = new class('some-url', Payment::class) extends DynamicRequest { + $request = new class('some-url', Payment::class) extends DynamicRequest + { protected static string $method = Method::GET; }; @@ -36,7 +38,8 @@ public function it_accepts_valid_resource_class() public function it_resolves_correct_resource_path() { $url = 'https://example.org'; - $request = new class($url, Payment::class) extends DynamicRequest { + $request = new class($url, Payment::class) extends DynamicRequest + { protected static string $method = Method::GET; }; diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php index be2aeeb7e..d4fefdf7e 100644 --- a/tests/Http/Requests/GetAllMethodsRequestTest.php +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetAllMethodsQuery; use Mollie\Api\Http\Requests\GetAllMethodsRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\MethodCollection; @@ -19,7 +18,7 @@ public function it_can_get_all_methods() GetAllMethodsRequest::class => new MockResponse(200, 'method-list'), ]); - $request = new GetAllMethodsRequest(); + $request = new GetAllMethodsRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_all_methods() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetAllMethodsRequest(); + $request = new GetAllMethodsRequest; $this->assertEquals('methods/all', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php index 94cfa4f3e..260a365b7 100644 --- a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\SubscriptionCollection; @@ -19,7 +18,7 @@ public function it_can_get_paginated_subscriptions() GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); - $request = new GetAllPaginatedSubscriptionsRequest(); + $request = new GetAllPaginatedSubscriptionsRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_paginated_subscriptions() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetAllPaginatedSubscriptionsRequest(); + $request = new GetAllPaginatedSubscriptionsRequest; $this->assertEquals('subscriptions', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index cae89d72f..70bf12477 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -6,7 +6,6 @@ use Mollie\Api\Http\Query\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php index bff99d570..1684dddd2 100644 --- a/tests/Http/Requests/GetClientRequestTest.php +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetClientQuery; use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Client; diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php index 34c77ac64..46dae1dd9 100644 --- a/tests/Http/Requests/GetEnabledMethodsRequestTest.php +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; use Mollie\Api\Http\Requests\GetEnabledMethodsRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\MethodCollection; @@ -19,7 +18,7 @@ public function it_can_get_enabled_methods() GetEnabledMethodsRequest::class => new MockResponse(200, 'method-list'), ]); - $request = new GetEnabledMethodsRequest(); + $request = new GetEnabledMethodsRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_enabled_methods() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetEnabledMethodsRequest(); + $request = new GetEnabledMethodsRequest; $this->assertEquals('methods', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetOnboardingRequestTest.php b/tests/Http/Requests/GetOnboardingRequestTest.php index aa03c01f6..e621f0807 100644 --- a/tests/Http/Requests/GetOnboardingRequestTest.php +++ b/tests/Http/Requests/GetOnboardingRequestTest.php @@ -18,7 +18,7 @@ public function it_can_get_onboarding() GetOnboardingRequest::class => new MockResponse(200, 'onboarding'), ]); - $request = new GetOnboardingRequest(); + $request = new GetOnboardingRequest; /** @var Response */ $response = $client->send($request); @@ -30,7 +30,7 @@ public function it_can_get_onboarding() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetOnboardingRequest(); + $request = new GetOnboardingRequest; $this->assertEquals('onboarding/me', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php index fb4ad513d..a2dbde763 100644 --- a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -4,7 +4,6 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; @@ -19,7 +18,7 @@ public function it_can_get_organization_partner_status() GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); - $request = new GetOrganizationPartnerStatusRequest(); + $request = new GetOrganizationPartnerStatusRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_organization_partner_status() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetOrganizationPartnerStatusRequest(); + $request = new GetOrganizationPartnerStatusRequest; $this->assertEquals('organizations/me/partner', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php index a65e8915d..7fd73bee3 100644 --- a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -18,7 +18,7 @@ public function it_can_get_paginated_balances() GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), ]); - $request = new GetPaginatedBalanceRequest(); + $request = new GetPaginatedBalanceRequest; /** @var Response */ $response = $client->send($request); @@ -30,7 +30,7 @@ public function it_can_get_paginated_balances() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedBalanceRequest(); + $request = new GetPaginatedBalanceRequest; $this->assertEquals('balances', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php index 0b1aae7bd..c7b81b294 100644 --- a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\BalanceTransactionCollection; diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php index 001fab9cd..3fb260273 100644 --- a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\ChargebackCollection; @@ -19,7 +18,7 @@ public function it_can_get_paginated_chargebacks() GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); - $request = new GetPaginatedChargebacksRequest(); + $request = new GetPaginatedChargebacksRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_paginated_chargebacks() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedChargebacksRequest(); + $request = new GetPaginatedChargebacksRequest; $this->assertEquals('chargebacks', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php index cce9a83b6..6ba609150 100644 --- a/tests/Http/Requests/GetPaginatedClientRequestTest.php +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\ClientCollection; @@ -19,7 +18,7 @@ public function it_can_get_paginated_clients() GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), ]); - $request = new GetPaginatedClientRequest(); + $request = new GetPaginatedClientRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_paginated_clients() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedClientRequest(); + $request = new GetPaginatedClientRequest; $this->assertEquals('clients', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php index facbbdd90..4118819bc 100644 --- a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetPaginatedCustomerPaymentsQuery; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentCollection; diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php index 654b58a25..306edf79d 100644 --- a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\CustomerCollection; @@ -19,7 +18,7 @@ public function it_can_get_paginated_customers() GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), ]); - $request = new GetPaginatedCustomerRequest(); + $request = new GetPaginatedCustomerRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_paginated_customers() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedCustomerRequest(); + $request = new GetPaginatedCustomerRequest; $this->assertEquals('customers', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php index 3437ce5de..aa9519502 100644 --- a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\InvoiceCollection; @@ -19,7 +18,7 @@ public function it_can_get_paginated_invoices() GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), ]); - $request = new GetPaginatedInvoiceRequest(); + $request = new GetPaginatedInvoiceRequest; /** @var Response */ $response = $client->send($request); @@ -31,7 +30,7 @@ public function it_can_get_paginated_invoices() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedInvoiceRequest(); + $request = new GetPaginatedInvoiceRequest; $this->assertEquals('invoices', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php index 3514d3d42..3473e1da9 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php index ad2623695..8a5ff6bbf 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -71,7 +71,7 @@ public function it_can_iterate_over_payment_links() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedPaymentLinksRequest(); + $request = new GetPaginatedPaymentLinksRequest; $this->assertEquals('payment-links', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php index d5029305c..8666739d3 100644 --- a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index a3d8171c8..35dfcd146 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -71,7 +71,7 @@ public function it_can_iterate_over_payments() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedPaymentsRequest(); + $request = new GetPaginatedPaymentsRequest; $this->assertEquals('payments', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php index e1dd95dba..6551351f1 100644 --- a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -71,7 +71,7 @@ public function it_can_iterate_over_profiles() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedProfilesRequest(); + $request = new GetPaginatedProfilesRequest; $this->assertEquals('profiles', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php index 42b9f2d5d..63ae9abc1 100644 --- a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -71,7 +71,7 @@ public function it_can_iterate_over_refunds() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedRefundsRequest(); + $request = new GetPaginatedRefundsRequest; $this->assertEquals('refunds', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php index 08e577f29..3cb416129 100644 --- a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -71,7 +71,7 @@ public function it_can_iterate_over_sessions() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedSessionsRequest(); + $request = new GetPaginatedSessionsRequest; $this->assertEquals('sessions', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php index 617fc25b5..fa4145a01 100644 --- a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php index dd4679b27..d4659701d 100644 --- a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php index c19505284..09f772510 100644 --- a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -71,7 +71,7 @@ public function it_can_iterate_over_settlements() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetPaginatedSettlementsRequest(); + $request = new GetPaginatedSettlementsRequest; $this->assertEquals('settlements', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index 6b7d7748a..c4f8d6832 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php index 4731b4716..d96f427e0 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -2,13 +2,12 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php index 19e1fd61e..fef5a9665 100644 --- a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; -use Mollie\Api\Resources\LazyCollection; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php index cc572e906..27bf0e226 100644 --- a/tests/Http/Requests/GetPaymentMethodRequestTest.php +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetPaymentMethodQuery; use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Method; diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php index a90463e71..0e7778ec9 100644 --- a/tests/Http/Requests/GetPaymentRefundRequestTest.php +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetPaymentRefundQuery; use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Refund; diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php index c1264a678..67239067f 100644 --- a/tests/Http/Requests/GetPaymentRequestTest.php +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\GetPaymentQuery; use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php index aeb38ba5d..8f34ea67a 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use DateTime; use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Http\Response; diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index cdae6c845..9cc1ddd15 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -44,7 +44,7 @@ public function it_can_update_session() public function it_resolves_correct_resource_path() { $sessionId = 'ses_LQNz4v4Qvk'; - $request = new UpdateSessionRequest($sessionId, new AnyPayload()); + $request = new UpdateSessionRequest($sessionId, new AnyPayload); $this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index cb27e5aae..4612d8855 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdateSubscriptionPayload; use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; From 8aefdb1d00341741f273fa434b637a4bbfc84dcb Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 6 Dec 2024 13:38:27 +0100 Subject: [PATCH 095/131] wip --- README.md | 237 +----- docs/endpoint-collections.md | 718 ++++++++++++++++++ docs/http-adapters.md | 74 ++ docs/idempotency.md | 57 ++ docs/payments.md | 93 +++ docs/requests.md | 47 ++ docs/responses.md | 43 ++ docs/testing.md | 55 ++ examples/captures/create-capture.php | 18 +- examples/captures/get-capture.php | 6 +- examples/captures/list-captures.php | 13 +- examples/client-links/create-client-link.php | 31 +- .../create-customer-first-payment.php | 32 +- phpstan-baseline.neon | 26 +- .../CustomerEndpointCollection.php | 1 + .../PaymentEndpointCollection.php | 12 +- src/Factories/Factory.php | 19 +- src/Helpers.php | 15 +- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 3 +- src/Http/Payload/Metadata.php | 8 +- tests/Helpers/HelpersTest.php | 141 ++++ 21 files changed, 1379 insertions(+), 270 deletions(-) create mode 100644 docs/endpoint-collections.md create mode 100644 docs/http-adapters.md create mode 100644 docs/idempotency.md create mode 100644 docs/payments.md create mode 100644 docs/requests.md create mode 100644 docs/responses.md create mode 100644 docs/testing.md create mode 100644 tests/Helpers/HelpersTest.php diff --git a/README.md b/README.md index 97abdfb54..39e03df3a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -****

          +

          @@ -32,14 +32,6 @@ The easiest way to install the Mollie API client is by using [Composer](http://g composer require mollie/mollie-api-php ``` -To work with the most recent API version, ensure that you are using a version of this API client that is equal to or greater than 2.0.0. If you prefer to continue using the v1 API, make sure your client version is below 2.0.0. For guidance on transitioning from v1 to v2, please refer to the [migration notes](https://docs.mollie.com/docs/migrating-from-v1-to-v2). - -### Manual Installation ### -If you're not familiar with using composer we've added a ZIP file to the releases containing the API client and all the packages normally installed by composer. -Download the ``mollie-api-php.zip`` from the [releases page](https://github.com/mollie/mollie-api-php/releases). - -Include the ``vendor/autoload.php`` as shown in [Initialize example](https://github.com/mollie/mollie-api-php/blob/master/examples/initialize.php). - ## Usage ## Initializing the Mollie API client, and setting your API key. @@ -49,79 +41,12 @@ $mollie = new \Mollie\Api\MollieApiClient(); $mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); ``` -With the `MollieApiClient` you can now access any of the following endpoints by selecting them as a property of the client: - -| API | Resource | Code | Link to Endpoint file | -| ----------------------- | ----------------------- | -------------------------- | -------------------------------------------------------------------------- | -| **[Balances API](https://docs.mollie.com/reference/v2/balances-api/overview)** | Balance | `$mollie->balances` | [BalanceEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceEndpoint.php) | -| | Balance Report | `$mollie->balanceReports` | [BalanceReportEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceReportEndpoint.php) | -| | Balance Transaction | `$mollie->balanceTransactions` | [BalanceTransactionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/BalanceTransactionEndpoint.php) | -| **[Chargebacks API](https://docs.mollie.com/reference/v2/chargebacks-api/overview)** | Chargeback |`$mollie->chargebacks` | [ChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ChargebackEndpoint.php) | -| | Payment Chargeback | `$mollie->paymentChargebacks` | [PaymentChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentChargebackEndpoint.php) | -| **[Clients API](https://docs.mollie.com/reference/v2/clients-api/overview)** | Client | `$mollie->clients` | [ClientEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ClientEndpoint.php) | -| **[Client Links API](https://docs.mollie.com/reference/v2/client-links-api/overview)** | Client Link | `$mollie->clientLinks` | [ClientLinkEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ClientLinkEndpoint.php) | -| **[Customers API](https://docs.mollie.com/reference/v2/customers-api/overview)** | Customer | `$mollie->customers` | [CustomerEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/CustomerEndpoint.php) | -| | Customer Payment | `$mollie->customerPayments` | [CustomerPaymentsEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/CustomerPaymentsEndpoint.php) | -| **[Invoices API](https://docs.mollie.com/reference/v2/invoices-api/overview)** | Invoice | `$mollie->invoices` | [InvoiceEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/InvoiceEndpoint.php) | -| **[Mandates API](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MandateEndpoint.php)** | Mandate | `$mollie->mandates` | [MandateEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MandateEndpoint.php) | -| **[Methods API](https://docs.mollie.com/reference/v2/methods-api/overview)** | Payment Method | `$mollie->methods` | [MethodEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/MethodEndpoint.php) | -| **[Onboarding API](https://docs.mollie.com/reference/v2/onboarding-api/overview)** | Onboarding |`$mollie->onboarding` | [OnboardingEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OnboardingEndpoint.php) | -| **[Orders API](https://docs.mollie.com/reference/v2/orders-api/overview)** | Order | `$mollie->orders` | [OrderEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderEndpoint.php) | -| | Order Line | `$mollie->orderLines` | [OrderLineEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderLineEndpoint.php) | -| | Order Payment | `$mollie->orderPayments` | [OrderPaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderPaymentEndpoint.php) | -| **[Organizations API](https://docs.mollie.com/reference/v2/organizations-api/overview)** | Organization | `$mollie->organizations` | [OrganizationEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrganizationEndpoint.php) | -| | Organization Partner | `$mollie->organizationPartners` | [OrganizationPartnerEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrganizationPartnerEndpoint.php) | -| **[Captures API](https://docs.mollie.com/reference/v2/captures-api/overview)** | Payment Captures | `$mollie->organizations` | [PaymentCaptureEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentCaptureEndpoint.php) | -| **[Payments API](https://docs.mollie.com/reference/v2/payments-api/overview)** | Payment | `$mollie->payments` | [PaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentEndpoint.php) | -| | Payment Route | `$mollie->paymentRoutes` | [PaymentRouteEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentRouteEndpoint.php) | -| **[Payment links API](https://docs.mollie.com/reference/v2/payment-links-api/overview)** | Payment Link | `$mollie->paymentLinks` | [PaymentLinkEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentLinkEndpoint.php) | -| **[Permissions API](https://docs.mollie.com/reference/v2/permissions-api/overview)** | Permission | `$mollie->permissions` | [PermissionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PermissionEndpoint.php) | -| **[Profile API](https://docs.mollie.com/reference/v2/profiles-api/overview)** | Profile | `$mollie->profiles` | [ProfileEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ProfileEndpoint.php) | -| | Profile Method | `$mollie->profileMethods` | [ProfileMethodEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ProfileMethodEndpoint.php) | -| **[Refund API](https://docs.mollie.com/reference/v2/refunds-api/overview)** | Refund | `$mollie->refunds` | [RefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/RefundEndpoint.php) | -| | Order Refund | `$mollie->orderRefunds` | [OrderRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/OrderRefundEndpoint.php) | -| | Payment Refund | `$mollie->paymentRefunds` | [PaymentRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/PaymentRefundEndpoint.php) | -| **[Settlements API](https://docs.mollie.com/reference/v2/settlements-api/overview)** | Settlement | `$mollie->settlements` | [SettlementsEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementsEndpoint.php) | -| | Settlement Capture | `$mollie->settlementCaptures` | [SettlementCaptureEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementCaptureEndpoint.php) | -| | Settlement Chargeback | `$mollie->settlementChargebacks` | [SettlementChargebackEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementChargebackEndpoint.php) | -| | Settlement Payment | `$mollie->settlementPayments` | [SettlementPaymentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementPaymentEndpoint.php) | -| | Settlement Refund | `$mollie->settlementRefunds` | [SettlementRefundEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SettlementRefundEndpoint.php) | -| **[Shipments API](https://docs.mollie.com/reference/v2/shipments-api/overview)** | Shipment | `$mollie->shipments` | [ShipmentEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/ShipmentEndpoint.php) | -| **[Subscriptions API](https://docs.mollie.com/reference/v2/subscriptions-api/overview)** | Subscription | `$mollie->subscriptions` | [SubscriptionEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/SubscriptionEndpoint.php) | -| **[Terminal API](https://docs.mollie.com/reference/v2/terminals-api/overview)** | Terminal | `$mollie->terminals` | [TerminalEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/TerminalEndpoint.php) | -| **[Wallets API](https://docs.mollie.com/reference/v2/wallets-api/overview)** | Wallet | `$mollie->wallets` | [WalletEndpoint](https://github.com/mollie/mollie-api-php/blob/master/src/Endpoints/WalletEndpoint.php) | - Find our full documentation online on [docs.mollie.com](https://docs.mollie.com). -#### Creating Payments #### -**[Create Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/create-payment)** - +#### Example usage #### ```php -// old way of creating a payment -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00" - ], - "description" => "My first API payment", - "redirectUrl" => "https://webshop.example.org/order/12345/", - "webhookUrl" => "https://webshop.example.org/mollie-webhook/", -]); - -// newish way use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Payload\CreatePaymentPayload; - -$payload = new CreatePaymentPayload( - description: 'My first API payment', - amount: new Money('EUR', '10.00'), - redirectUrl: 'https://webshop.example.org/order/12345/', - webhookUrl: 'https://webshop.example.org/mollie-webhook/' -); - -$payment = $mollie->payments->create($payload); - -// newest ;-) use Mollie\Api\Http\Requests\CreatePaymentRequest; $payload = new CreatePaymentPayload( @@ -131,148 +56,58 @@ $payload = new CreatePaymentPayload( webhookUrl: 'https://webshop.example.org/mollie-webhook/' ); -$payment = $mollie->send($payload); -``` -_After creation, the payment id is available in the `$payment->id` property. You should store this id with your order._ - -After storing the payment id you can send the customer to the checkout using `$payment->getCheckoutUrl()`. +/** @var Mollie\Api\Http\Response $response */ +$response = $mollie->send(new CreatePaymentRequest($payload)); -```php -header("Location: " . $payment->getCheckoutUrl(), true, 303); -``` - -_This header location should always be a GET, thus we enforce 303 http response code_ - -For a payment create example, see [Example - New Payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-payment.php). - -##### Multicurrency ##### -Since API v2.0 it is now possible to create non-EUR payments for your customers. -A full list of available currencies can be found [in our documentation](https://docs.mollie.com/guides/multicurrency). - -```php -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "USD", - "value" => "10.00" - ], - //... -]); +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $response->toResource(); ``` -_After creation, the `settlementAmount` will contain the EUR amount that will be settled on your account._ - -##### Create fully integrated iDEAL payments ##### -To fully integrate iDEAL payments on your website, follow these additional steps: - -1. Retrieve the list of issuers (banks) that support iDEAL. - -```php -$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]); -``` - -Use the `$method->issuers` list to let the customer pick their preferred issuer. - -_`$method->issuers` will be a list of objects. Use the property `$id` of this object in the - API call, and the property `$name` for displaying the issuer to your customer._ - -2. Create a payment with the selected issuer: -```php -$payment = $mollie->payments->create([ - "amount" => [ - "currency" => "EUR", - "value" => "10.00" - ], - "description" => "My first API payment", - "redirectUrl" => "https://webshop.example.org/order/12345/", - "webhookUrl" => "https://webshop.example.org/mollie-webhook/", - "method" => \Mollie\Api\Types\PaymentMethod::IDEAL, - "issuer" => $selectedIssuerId, // e.g. "ideal_INGBNL2A" -]); -``` - -_The `_links` property of the `$payment` object will contain an object `checkout` with a `href` property, which is a URL that points directly to the online banking environment of the selected issuer. -A short way of retrieving this URL can be achieved by using the `$payment->getCheckoutUrl()`._ - -For a more in-depth example, see [Example - iDEAL payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-ideal-payment.php). - -#### Retrieving Payments #### -**[Retrieve Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/get-payment)** - -We can use the `$payment->id` to retrieve a payment and check if the payment `isPaid`. - -```php -$payment = $mollie->payments->get($payment->id); - -if ($payment->isPaid()) -{ - echo "Payment received."; -} -``` - -Or retrieve a collection of payments. - -```php -$payments = $mollie->payments->page(); -``` - -For an extensive example of listing payments with the details and status, see [Example - List Payments](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/list-payments.php). +## Upgrading -#### Refunding payments #### -**[Refund Payment Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund)** +Please see [UPGRADING](UPGRADING.md) for details. -Our API provides support for refunding payments. It's important to note that there is no confirmation step, and all refunds are immediate and final. Refunds are available for all payment methods except for paysafecard and gift cards. +## API documentation ## +For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. -```php -$payment = $mollie->payments->get($payment->id); - -// Refund € 2 of this payment -$refund = $payment->refund([ - "amount" => [ - "currency" => "EUR", - "value" => "2.00" - ] -]); -``` +## Documentation -#### Payment webhook #### -When the payment status changes, the `webhookUrl` you specified during payment creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/webhook.php). +For detailed documentation about using this PHP client, see the following guides: -For a working example, see [Example - Refund payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/refund-payment.php). +- [Endpoint Collections](docs/endpoint-collections.md) - Learn how to interact with all available API endpoints. +- [HTTP Adapters](docs/http-adapters.md) - Information on customizing HTTP communication. +- [Idempotency](docs/idempotency.md) - Best practices and setup for idempotent requests. +- [Payments](docs/payments.md) - Comprehensive guide on handling payments. +- [Requests](docs/requests.md) - Overview and usage of request objects in the API client. +- [Responses](docs/responses.md) - Handling and understanding responses from the API. +- [Testing](docs/testing.md) - Guidelines for testing with the Mollie API client. -### Enabling debug mode ### +These guides provide in-depth explanations and examples for advanced usage of the client. -When troubleshooting, it can be highly beneficial to have access to the submitted request within the `ApiException`. To safeguard against inadvertently exposing sensitive request data in your local application logs, the debugging feature is initially turned off. +## Examples -To enable debugging and inspect the request: +The Mollie API client comes with a variety of examples to help you understand how to implement various API features. These examples are a great resource for learning how to integrate Mollie payments into your application. -```php -/** @var $mollie \Mollie\Api\MollieApiClient */ -$mollie->enableDebugging(); - -try { - $mollie->payments->get('tr_12345678'); -} catch (\Mollie\Api\Exceptions\ApiException $exception) { - $request = $exception->getRequest(); -} -``` +Here are some of the key examples included: -If you are recording instances of `ApiException`, the request details will be included in the logs. It is vital to ensure that no sensitive information is retained within these logs and to perform cleanup after debugging is complete. +- **Create Payment**: Demonstrates how to create a new payment. + - [Create a simple payment](examples/payments/create-payment.php) + - [Create an iDEAL payment](examples/payments/create-ideal-payment.php) + - [Create a payment with manual capture](examples/payments/create-capturable-payment.php) -To disable debugging again: +- **Manage Customers**: Shows how to manage customers in your Mollie account. + - [Create a customer](examples/customers/create-customer.php) + - [Update a customer](examples/customers/update-customer.php) + - [Delete a customer](examples/customers/delete-customer.php) -```php -/** @var $mollie \Mollie\Api\MollieApiClient */ -$mollie->disableDebugging(); -``` +- **Subscriptions and Recurring Payments**: + - [Create a customer for recurring payments](examples/customers/create-customer-first-payment.php) + - [Create a recurring payment](examples/customers/create-customer-recurring-payment.php) -Please note that debugging is only available when using the default Guzzle http adapter (`GuzzleMollieHttpAdapter`). +For a full list of examples, please refer to the [examples directory](examples/). -## Upgrading +These examples are designed to be run in a safe testing environment. Make sure to use your test API keys and review each example's code before integrating it into your production environment. -Please see [UPGRADING](UPGRADING.md) for details. - -## API documentation ## -For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. ## Contributing to Our API Client ## Would you like to contribute to improving our API client? We welcome [pull requests](https://github.com/mollie/mollie-api-php/pulls?utf8=%E2%9C%93&q=is%3Apr). But, if you're interested in contributing to a technology-focused organization, Mollie is actively recruiting developers and system engineers. Discover our current [job openings](https://jobs.mollie.com/) or [reach out](mailto:personeel@mollie.com). diff --git a/docs/endpoint-collections.md b/docs/endpoint-collections.md new file mode 100644 index 000000000..6a0f7c2c1 --- /dev/null +++ b/docs/endpoint-collections.md @@ -0,0 +1,718 @@ +# Introduction +Endpoint collections provide a fluent interface for interacting with Mollie's API. Each collection manages specific resource types like payments, customers, and subscriptions, offering methods to create, retrieve, update, and delete these resources. + +## Setup + +1. **Initialize the Mollie Client:** + +```php +$mollie = new \Mollie\Api\MollieApiClient(); +$mollie->setApiKey("test_*************************"); +``` + +2. **Access Endpoints via the Client:** +```php +// Payments endpoint +$mollie->payments->... + +// Customers endpoint +$mollie->customers->... + +// Other endpoints +$mollie->balances->... +$mollie->orders->... +``` + +3. **Call methods** + +**Simple: Using arrays** +This approach is direct but provides less type safety: +```php +$payment = $mollie->payments->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00' + ], + 'description' => 'My first API payment' +]); +``` + +**Advanced: Using typed payloads/queries** +This approach provides full IDE support and type safety: +```php +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\CreatePaymentPayload; + +$payment = $mollie->payments->create( + new CreatePaymentPayload( + description: 'My first API payment', + amount: new Money('EUR', '10.00') + ) +); +``` + +If you have an array and need to interact with the payload or query, you can use a dedicated factory to convert the array into a typed class. + +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Factories\CreatePaymentPayloadFactory; + +// Fully untyped data +$createPaymentPayload = CreatePaymentPayloadFactory::new([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00' + ], + 'description' => 'My first API payment' +]); + +// Partially untyped +$createPaymentPayload = CreatePaymentPayloadFactory::new([ + 'amount' => new Money('EUR', '10.00'), + 'description' => 'My first API payment' +]); + +// Access payload +$createPaymentPayload->amount->... +``` + +This approach allows you to seamlessly convert arrays into typed objects, providing better IDE support and type safety while working with your data. + +# Available Endpoints + +## Balances + +[Official Documentation](https://docs.mollie.com/reference/v2/balances-api/get-balance) + +**Available Queries:** +- `GetPaginatedBalanceQuery` - For listing balances with pagination + +### Balance Information + +```php +// Get primary balance +$balance = $mollie->balances->primary(); + +// Get specific balance +$balance = $mollie->balances->get('bal_12345'); + +// List balances +$balances = $mollie->balances->page(); +``` + +## Balance Reports + +[Official Documentation](https://docs.mollie.com/reference/v2/balance-reports-api/get-balance-report) + +**Available Queries:** +- `GetBalanceReportQuery` - For retrieving balance reports + +### Balance Report Details + +```php +// Get report for specific balance +$report = $mollie->balanceReports->getForId('bal_12345', [ + 'from' => '2024-01-01', + 'until' => '2024-01-31', + 'grouping' => 'transaction-categories' +]); +``` + +## Balance Transactions + +[Official Documentation](https://docs.mollie.com/reference/v2/balance-transactions-api/list-balance-transactions) + +**Available Queries:** +- `GetPaginatedBalanceQuery` - For listing balance transactions with pagination + +### Balance Transaction Management + +```php +// Get transactions for a balance +$transactions = $mollie->balanceTransactions->pageFor($balance); + +// Use iterator for all transactions +foreach ($mollie->balanceTransactions->iteratorFor($balance) as $transaction) { + echo $transaction->id; +} +``` + +## Chargebacks + +[Official Documentation](https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback) + +**Available Queries:** +- `GetPaginatedChargebacksQuery` - For listing chargebacks with pagination + +### Chargeback Management + +```php +// Get all chargebacks +$chargebacks = $mollie->chargebacks->page(); + +// Use iterator for all chargebacks +foreach ($mollie->chargebacks->iterator() as $chargeback) { + echo $chargeback->id; +} +``` + +## Clients + +[Official Documentation](https://docs.mollie.com/reference/v2/clients-api/get-client) + +**Available Queries:** +- `GetClientQuery` - For retrieving client details + +### Client Management + +```php +// Get a specific client +$client = $mollie->clients->get('org_12345678', [ + 'testmode' => true +]); + +// List all clients +$clients = $mollie->clients->page( + from: 'org_12345678', + limit: 50 +); +``` + +## Customers + +[Official Documentation](https://docs.mollie.com/reference/v2/customers-api/create-customer) + +**Available Payloads:** +- `CreateCustomerPayload` - For creating new customers +- `UpdateCustomerPayload` - For updating existing customers + +### Customer Management + +```php +// Create a customer +$customer = $mollie->customers->create([ + 'name' => 'John Doe', + 'email' => 'john@example.org', +]); + +// Get a customer +$customer = $mollie->customers->get('cst_8wmqcHMN4U'); + +// Update a customer +$customer = $mollie->customers->update('cst_8wmqcHMN4U', [ + 'name' => 'Updated Name' +]); + +// Delete a customer +$mollie->customers->delete('cst_8wmqcHMN4U'); + +// List customers +$customers = $mollie->customers->page(); +``` + +## Invoices + +[Official Documentation](https://docs.mollie.com/reference/v2/invoices-api/get-invoice) + +**Available Queries:** +- `GetPaginatedInvoiceQuery` - For listing invoices with pagination + +### Invoice Management + +```php +// Get a specific invoice +$invoice = $mollie->invoices->get('inv_xBEbP9rvAq'); + +// List all invoices +$invoices = $mollie->invoices->page( + from: 'inv_xBEbP9rvAq', + limit: 50 +); +``` + +## Mandates + +[Official Documentation](https://docs.mollie.com/reference/v2/mandates-api/create-mandate) + +**Available Payloads:** +- `CreateMandatePayload` - For creating new mandates + +### Mandate Management + +```php +// Create a mandate for a customer +$mandate = $mollie->mandates->createFor($customer, [ + 'method' => \Mollie\Api\Types\PaymentMethod::DIRECTDEBIT, + 'consumerName' => 'John Doe', + 'consumerAccount' => 'NL55INGB0000000000', + 'consumerBic' => 'INGBNL2A', + 'signatureDate' => '2024-01-01', + 'mandateReference' => 'YOUR-COMPANY-MD13804' +]); + +// Get a mandate +$mandate = $mollie->mandates->getFor($customer, 'mdt_h3gAaD5zP'); + +// Revoke a mandate +$mollie->mandates->revokeFor($customer, 'mdt_h3gAaD5zP'); + +// List mandates +$mandates = $mollie->mandates->pageFor($customer); +``` + +## Methods + +[Official Documentation](https://docs.mollie.com/reference/v2/methods-api/get-method) + +**Available Queries:** +- `GetPaymentMethodQuery` - For retrieving method details +- `GetAllMethodsQuery` - For listing all available methods +- `GetEnabledPaymentMethodsQuery` - For listing enabled methods + +### Payment Methods + +```php +// Get a method +$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL); + +// List all methods +$methods = $mollie->methods->all(); + +// List enabled methods +$methods = $mollie->methods->allEnabled([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00' + ] +]); +``` + +### Method Issuers + +```php +// Enable an issuer +$issuer = $mollie->methodIssuers->enable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL, + 'ideal_INGBNL2A' +); + +// Disable an issuer +$mollie->methodIssuers->disable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL, + 'ideal_INGBNL2A' +); +``` + +## Onboarding + +[Official Documentation](https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status) + +**Available Queries:** +- `GetOnboardingStatusQuery` - For retrieving onboarding status + +### Onboarding Management + +```php +// Get onboarding status +$onboarding = $mollie->onboarding->status(); +``` + +## Organizations + +[Official Documentation](https://docs.mollie.com/reference/v2/organizations-api/get-organization) + +**Available Queries:** +- `GetOrganizationQuery` - For retrieving organization details + +### Organization Management + +```php +// Get an organization +$organization = $mollie->organizations->get('org_12345678'); + +// Get current organization +$organization = $mollie->organizations->current(); + +// Get partner status +$partner = $mollie->organizations->partnerStatus(); +``` + +## Permissions + +[Official Documentation](https://docs.mollie.com/reference/v2/permissions-api/get-permission) + +**Available Queries:** +- `GetPermissionQuery` - For retrieving permission details + +### Permission Management + +```php +// Get a permission +$permission = $mollie->permissions->get('payments.read'); + +// List all permissions +$permissions = $mollie->permissions->list(); +``` + +## Payments + +[Official Documentation](https://docs.mollie.com/reference/v2/payments-api/create-payment) + +**Available Payloads:** +- `CreatePaymentPayload` - For creating new payments +- `UpdatePaymentPayload` - For updating existing payments + +**Available Queries:** +- `GetPaymentQuery` - For retrieving payments with optional embeds +- `GetPaginatedPaymentsQuery` - For listing payments with pagination + +### Payment Management + +```php +// Create a payment using typed payload +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\CreatePaymentPayload; + +$payload = new CreatePaymentPayload( + description: 'Order #12345', + amount: new Money('EUR', '10.00'), + redirectUrl: 'https://webshop.example.org/order/12345/', + webhookUrl: 'https://webshop.example.org/mollie-webhook/' +); + +$payment = $mollie->payments->create($payload); + +// Get a payment +$payment = $mollie->payments->get('tr_7UhSN1zuXS'); + +// Update a payment +$payment = $mollie->payments->update('tr_7UhSN1zuXS', [ + 'description' => 'Updated description' +]); + +// Cancel a payment +$mollie->payments->cancel('tr_7UhSN1zuXS'); + +// List payments +$payments = $mollie->payments->page(); +``` + +### Payment Links + +[Official Documentation](https://docs.mollie.com/reference/v2/payment-links-api/create-payment-link) + +**Available Payloads:** +- `CreatePaymentLinkPayload` - For creating payment links +- `UpdatePaymentLinkPayload` - For updating payment links + +### Payment Captures + +[Official Documentation](https://docs.mollie.com/reference/v2/captures-api/get-capture) + +**Available Payloads:** +- `CreatePaymentCapturePayload` - For creating captures + +**Available Queries:** +- `GetPaymentCaptureQuery` - For retrieving capture details +- `GetPaginatedPaymentCapturesQuery` - For listing captures + +### Payment Chargebacks + +```php +// Get a chargeback +$chargeback = $mollie->paymentChargebacks->getFor($payment, 'chb_n9z0tp'); + +// List chargebacks for payment +$chargebacks = $mollie->paymentChargebacks->pageFor($payment); +``` + +### Payment Routes + +```php +// Update release date for a route +$route = $mollie->paymentRoutes->updateReleaseDateFor( + $payment, + 'rt_abc123', + '2024-01-01' +); +``` + +## Profiles + +[Official Documentation](https://docs.mollie.com/reference/v2/profiles-api/create-profile) + +**Available Payloads:** +- `CreateProfilePayload` - For creating new profiles + +**Available Factories:** +- `ProfileFactory` - For creating profile instances + +### Profile Management + +```php +// Create a profile +$profile = $mollie->profiles->create(new CreateProfilePayload( + 'My Test Profile', + 'https://example.org', + 'info@example.org', + '+31612345678', + 'test' +)); + +// Get a profile +$profile = $mollie->profiles->get('pfl_v9hTwCvYqw'); + +// Get current profile +$profile = $mollie->profiles->getCurrent(); + +// Update a profile +$profile = $mollie->profiles->update('pfl_v9hTwCvYqw', [ + 'name' => 'Updated Profile Name' +]); + +// Delete a profile +$mollie->profiles->delete('pfl_v9hTwCvYqw'); + +// List profiles +$profiles = $mollie->profiles->page(); +``` + +### Profile Methods + +```php +// Enable a method +$method = $mollie->profileMethods->enable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL +); + +// Disable a method +$mollie->profileMethods->disable( + 'pfl_v9hTwCvYqw', + \Mollie\Api\Types\PaymentMethod::IDEAL +); +``` + +## Refunds + +[Official Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-refund) + +**Available Payloads:** +- `CreateRefundPaymentPayload` - For creating refunds on payments +- `CreateRefundOrderPayload` - For creating refunds on orders + +**Available Queries:** +- `GetPaginatedRefundsQuery` - For listing refunds with pagination + +### Refund Management + +```php +// Create a refund for a payment +$refund = $mollie->refunds->createForPayment($paymentId, [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '15.00' + ], + 'description' => 'Refund for returned item' +]); + +// List refunds +$refunds = $mollie->refunds->page(); +``` + +## Sessions + +[Official Documentation](https://docs.mollie.com/reference/v2/sessions-api/create-session) + +**Available Payloads:** +- `CreateSessionPayload` - For creating sessions + +**Available Queries:** +- `GetPaginatedSessionsQuery` - For listing sessions with pagination + +### Session Management + +```php +// Create a session +$session = $mollie->sessions->create([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00' + ], + 'description' => 'Session for service' +]); + +// Get a session +$session = $mollie->sessions->get('sessionId'); +``` + +## Settlements + +[Official Documentation](https://docs.mollie.com/reference/v2/settlements-api/get-settlement) + +**Available Queries:** +- `GetPaginatedSettlementsQuery` - For listing settlements with pagination + +### Settlement Management + +```php +// Get a settlement +$settlement = $mollie->settlements->get('settlementId'); + +// List settlements +$settlements = $mollie->settlements->page(); +``` + +### Settlement Captures + +```php +// Get captures for a settlement +$captures = $mollie->settlementCaptures->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementCaptures->iteratorFor($settlement) as $capture) { + echo $capture->id; +} +``` + +### Settlement Chargebacks + +```php +// List chargebacks for a settlement +$chargebacks = $mollie->settlementChargebacks->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementChargebacks->iteratorFor($settlement) as $chargeback) { + echo $chargeback->id; +} +``` + +### Settlement Payments + +```php +// List payments in a settlement +$payments = $mollie->settlementPayments->pageFor($settlement); + +// Use iterator +foreach ($mollie->settlementPayments->iteratorFor($settlement) as $payment) { + echo $payment->id; +} +``` + +## Subscriptions + +[Official Documentation](https://docs.mollie.com/reference/v2/subscriptions-api/create-subscription) + +**Available Payloads:** +- `CreateSubscriptionPayload` - For creating subscriptions + +**Available Queries:** +- `GetAllPaginatedSubscriptionsQuery` - For listing all subscriptions + +### Subscription Management + +```php +// Create a subscription +$subscription = $mollie->subscriptions->createForCustomer('customerId', [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '25.00' + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription' +]); + +// List subscriptions +$subscriptions = $mollie->subscriptions->pageForCustomer('customerId'); +``` + +## Terminals + +[Official Documentation](https://docs.mollie.com/reference/v2/terminals-api/get-terminal) + +**Available Queries:** +- `GetPaginatedTerminalsQuery` - For listing terminals with pagination + +### Terminal Management + +```php +// Get a terminal +$terminal = $mollie->terminals->get('terminalId'); + +// List terminals +$terminals = $mollie->terminals->page(); +``` + +## Wallets + +[Official Documentation](https://docs.mollie.com/reference/v2/wallets-api/request-apple-pay-payment-session) + +**Available Payloads:** +- `RequestApplePayPaymentSessionPayload` - For requesting Apple Pay payment sessions + +### Wallet Management + +```php +// Request an Apple Pay payment session +$session = $mollie->wallets->requestApplePayPaymentSession([ + 'domainName' => 'example.com', + 'validationUrl' => 'https://apple-pay-gateway.apple.com/paymentservices/startSession' +]); +``` + +## Common Patterns + +### Pagination + +Most list methods support pagination: + +```php +// Get first page +$payments = $mollie->payments->page(); + +// Get specific page +$payments = $mollie->payments->page( + from: 'tr_7UhSN1zuXS', // Start from this ID + limit: 50 // Items per page +); + +// Get all items using iterator +foreach ($mollie->payments->iterator() as $payment) { + echo $payment->id; +} +``` + +### Error Handling + +Handle errors using `ApiException`: + +```php +try { + $payment = $mollie->payments->get('tr_xxx'); +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: {$e->getMessage()}"; +} +``` + +## Common Data Types + +**Shared Payloads:** +- `Money` - For handling currency amounts +- `Address` - For handling address information +- `Metadata` - For handling custom metadata +- `DataCollection` - For handling collections of data +- `ApplicationFee` - For handling application fees + +**Base Classes:** +- `DataBag` - Base class for payload objects +- `Query` - Base class for query objects + +## Factories + +**Query Factories:** +- `PaginatedQueryFactory` - For creating paginated queries +- `SortablePaginatedQueryFactory` - For creating sortable paginated queries + +**Payload Factories:** +- `CreatePaymentPayloadFactory` - For creating payment payloads diff --git a/docs/http-adapters.md b/docs/http-adapters.md new file mode 100644 index 000000000..46d05aa25 --- /dev/null +++ b/docs/http-adapters.md @@ -0,0 +1,74 @@ +# HTTP Adapters + +## Overview + +An HTTP adapter is a component that manages the communication between your application and an API. It abstracts the details of making HTTP requests and handling responses, allowing you to use different HTTP clients (like Guzzle, cURL, or custom clients) interchangeably without changing the way you interact with the API. + +## MollieHttpAdapterPicker + +The `MollieHttpAdapterPicker` is responsible for selecting the appropriate HTTP adapter based on the environment or the provided HTTP client. If no client is specified in the `MollieApiClient` constructor, it picks a default adapter. + +### How It Works + +1. **No Client Specified**: If no client is provided, it checks if Guzzle is available and picks the appropriate version of the Guzzle adapter. +2. **Custom Client Provided**: If a custom client is provided and it implements the `HttpAdapterContract`, it is used directly. If it's a Guzzle client, it is wrapped in a `GuzzleMollieHttpAdapter`. +3. **Unrecognized Client**: Throws an `UnrecognizedClientException` if the client is not recognized. + +## Creating a Custom Adapter + +To create a custom HTTP adapter: +1. Implement HttpAdapterContract. +2. Use HasDefaultFactories Trait to simplify adapter implementation. + +```php +use Mollie\Api\Contracts\HttpAdapterContract; +use Mollie\Api\Traits\HasDefaultFactories; + +class MyCustomHttpAdapter implements HttpAdapterContract { + use HasDefaultFactories; + + public function sendRequest(PendingRequest $pendingRequest): Response { + // Implementation for sending HTTP request + } + + public function version(): ?string { + return 'my-custom-adapter/1.0'; + } +} +``` + +### Debugging + +When debugging mode is enabled, adapters remove sensitive information before they fire an exception. + +Adapters that support debugging must implement the `SupportsDebuggingContract`. This contract defines methods `enableDebugging()` and `disableDebugging()` to control debugging behavior. + +```php +use Mollie\Api\Contracts\SupportsDebuggingContract; + +class MyCustomHttpAdapter implements HttpAdapterContract, SupportsDebuggingContract { + // Implementation of debugging methods +} +``` + +## Available Adapters + +Out of the box, the Mollie API client provides several adapters: + +- **GuzzleMollieHttpAdapter**: Wraps a Guzzle HTTP client for sending requests. +- **CurlMollieHttpAdapter**: Uses cURL for sending HTTP requests. This is the default if Guzzle is not available. + +## Enabling Debugging + +Debugging can be enabled through the `HandlesDebugging` trait. This trait allows you to toggle debugging on the HTTP client, which is useful for development and troubleshooting. + +### How to Enable Debugging + +1. **Enable Debugging**: Call `enableDebugging()` on the Mollie API client instance. This sets the debugging mode on the underlying HTTP adapter, if it supports debugging. + +2. **Disable Debugging**: Call `disableDebugging()` to turn off debugging. + +```php +$mollieClient->enableDebugging(); +$mollieClient->disableDebugging(); +``` diff --git a/docs/idempotency.md b/docs/idempotency.md new file mode 100644 index 000000000..020afd3f8 --- /dev/null +++ b/docs/idempotency.md @@ -0,0 +1,57 @@ +# Idempotency + +## Overview + +Idempotency ensures that multiple identical requests to an API result in the same outcome without creating duplicate resources or effects. This is crucial for operations that involve financial transactions to prevent unintended charges or state changes. + +Mollie API supports idempotent requests for critical operations such as creating payments or refunds. This is automatically managed by the API client using the `ApplyIdempotencyKey` middleware. + +For more detailed information, refer to the [Mollie API Idempotency Documentation](https://docs.mollie.com/reference/api-idempotency). + +## Automatic Idempotency Key Handling + +The Mollie API client automatically handles idempotency for mutating requests (POST, PATCH, DELETE) through the `ApplyIdempotencyKey` middleware. This middleware checks if the request is a mutating type and applies an idempotency key if one is not already provided. + +### How It Works + +1. **Check Request Type**: The middleware checks if the request method is POST, PATCH, or DELETE. +2. **Apply Idempotency Key**: If the request is mutating, the middleware will: + - Use a custom idempotency key if provided. + - Otherwise, generate a key using the configured `IdempotencyKeyGenerator` if available. + - If no generator is set and no key is provided, no idempotency key is applied. + +### Customizing Idempotency Key + +You can customize how idempotency keys are generated or applied in several ways: + +- **Provide a Custom Key**: Manually set an idempotency key for a specific request. +- **Use a Custom Generator**: Implement the `IdempotencyKeyGeneratorContract` to provide a custom method of generating idempotency keys. + +#### Example: Setting a Custom Key + +```php +$mollie->setIdempotencyKey('your_custom_key_here'); +``` + +#### Example: Using a Custom Key Generator + +Implement your key generator: + +```php +class MyCustomKeyGenerator implements IdempotencyKeyGeneratorContract { + public function generate(): string { + return 'custom_' . bin2hex(random_bytes(10)); + } +} + +$mollie->setIdempotencyKeyGenerator(new MyCustomKeyGenerator()); +``` + +## Best Practices + +- **Unique Keys**: Ensure that each idempotency key is unique to each operation. Typically, UUIDs are used for this purpose. +- **Handling Errors**: Handle errors gracefully, especially when an API call with an idempotency key fails. Check the error message to understand whether you should retry the request with the same key or a new key. + +## Conclusionz + +Using idempotency keys in your API requests to Mollie can significantly enhance the reliability of your payment processing system, ensuring that payments are not unintentionally duplicated and that your application behaves predictably even in the face of network and service interruptions. diff --git a/docs/payments.md b/docs/payments.md new file mode 100644 index 000000000..2d98141d4 --- /dev/null +++ b/docs/payments.md @@ -0,0 +1,93 @@ +##### Multicurrency ##### +Since API v2.0 it is now possible to create non-EUR payments for your customers. +A full list of available currencies can be found [in our documentation](https://docs.mollie.com/guides/multicurrency). + +```php +$payment = $mollie->payments->create([ + "amount" => [ + "currency" => "USD", + "value" => "10.00" + ], + //... +]); +``` +_After creation, the `settlementAmount` will contain the EUR amount that will be settled on your account._ + +##### Create fully integrated iDEAL payments ##### +To fully integrate iDEAL payments on your website, follow these additional steps: + +1. Retrieve the list of issuers (banks) that support iDEAL. + +```php +$method = $mollie->methods->get(\Mollie\Api\Types\PaymentMethod::IDEAL, ["include" => "issuers"]); +``` + +Use the `$method->issuers` list to let the customer pick their preferred issuer. + +_`$method->issuers` will be a list of objects. Use the property `$id` of this object in the + API call, and the property `$name` for displaying the issuer to your customer._ + +2. Create a payment with the selected issuer: + +```php +$payment = $mollie->payments->create([ + "amount" => [ + "currency" => "EUR", + "value" => "10.00" + ], + "description" => "My first API payment", + "redirectUrl" => "https://webshop.example.org/order/12345/", + "webhookUrl" => "https://webshop.example.org/mollie-webhook/", + "method" => \Mollie\Api\Types\PaymentMethod::IDEAL, + "issuer" => $selectedIssuerId, // e.g. "ideal_INGBNL2A" +]); +``` + +_The `_links` property of the `$payment` object will contain an object `checkout` with a `href` property, which is a URL that points directly to the online banking environment of the selected issuer. +A short way of retrieving this URL can be achieved by using the `$payment->getCheckoutUrl()`._ + +For a more in-depth example, see [Example - iDEAL payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/create-ideal-payment.php). + +#### Retrieving Payments #### +**[Retrieve Payment Documentation](https://docs.mollie.com/reference/v2/payments-api/get-payment)** + +We can use the `$payment->id` to retrieve a payment and check if the payment `isPaid`. + +```php +$payment = $mollie->payments->get($payment->id); + +if ($payment->isPaid()) +{ + echo "Payment received."; +} +``` + +Or retrieve a collection of payments. + +```php +$payments = $mollie->payments->page(); +``` + +For an extensive example of listing payments with the details and status, see [Example - List Payments](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/list-payments.php). + +#### Refunding payments #### +**[Refund Payment Documentation](https://docs.mollie.com/reference/v2/refunds-api/create-payment-refund)** + +Our API provides support for refunding payments. It's important to note that there is no confirmation step, and all refunds are immediate and final. Refunds are available for all payment methods except for paysafecard and gift cards. + +```php +$payment = $mollie->payments->get($payment->id); + +// Refund € 2 of this payment +$refund = $payment->refund([ + "amount" => [ + "currency" => "EUR", + "value" => "2.00" + ] +]); +``` + +#### Payment webhook #### +When the payment status changes, the `webhookUrl` you specified during payment creation will be called. You can use the `id` from the POST parameters to check the status and take appropriate actions. For more details, refer to [Example - Webhook](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/webhook.php). + +For a working example, see [Example - Refund payment](https://github.com/mollie/mollie-api-php/blob/master/examples/payments/refund-payment.php). diff --git a/docs/requests.md b/docs/requests.md new file mode 100644 index 000000000..cae956b9a --- /dev/null +++ b/docs/requests.md @@ -0,0 +1,47 @@ +# Requests + +## Overview + +The Mollie API client uses request classes to communicate with the Mollie API. Each request class handles specific API endpoints and operations. + +## Sending a Request + +To send a request using the Mollie API client, you typically need to: + +1. **Create an instance of the client**: + ```php + use Mollie\Api\MollieApiClient; + + $mollie = new MollieApiClient(); + $mollie->setApiKey('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM'); + ``` + +2. **Create and configure the request**: + Depending on the operation, you might need to create an instance of a specific request class and configure it with necessary parameters. + +3. **Send the request**: + Use the client to send the request and handle the response. + ```php + use Mollie\Api\MollieApiClient; + use Mollie\Api\Http\Payload\Money; + use Mollie\Api\Http\Payload\CreatePaymentPayload; + use Mollie\Api\Http\Requests\CreatePaymentRequest; + + $mollie = new MollieApiClient(); + $createPaymentRequest = new CreatePaymentRequest( + new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + ) + ); + + /** @var \Mollie\Api\Http\Response $response */ + $response = $mollie->send($createPaymentRequest); + + $this->assertEquals(200, $response->status()); + + /** @var \Mollie\Api\Resources\Payment */ + $payment = $response->toResource(); + ``` diff --git a/docs/responses.md b/docs/responses.md new file mode 100644 index 000000000..cd7058112 --- /dev/null +++ b/docs/responses.md @@ -0,0 +1,43 @@ +# Responses + +Whether you interact with the endpoints using the traditional method (`$mollie->payments->...`) or the new `Request` classes, you can always inspect the `Response`. + +## Resource Hydration +By default, the response from the `EndpointCollection`s automatically hydrates into the corresponding `Resource` or `ResourceCollection` objects. You can still access the raw response using the `->getResponse()` method. + +```php +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $mollie->payments->get('tr_*********'); + +$response = $payment->getResponse(); +``` + +With the Request-based approach, you get a Response by default: + +```php +/** @var Mollie\Api\Http\Response $response */ +$response = $mollie->send(new GetPaymentRequest('tr_*********')); + +/** + * Accessing the response is mainly for debugging, + * like checking the status or inspecting the payload or URL. + */ +$status = $response->status(); +$sentPayload = $response->getPendingRequest()->payload; +$sentUrlWithFilters = $response->getPendingRequest()->getUri(); + +/** @var Mollie\Api\Resources\Payment $payment */ +$payment = $response->toResource(); +``` + +Thanks to the DelegatesToResource Trait in Response, you can still access methods and attributes from the underlying Resource: + +```php +// calling a method on the underlying Mollie\Api\Resources\Payment object +$response->hasSplitPayments(); + +// accessing an attribute on the underlying Mollie\Api\Resources\Payment object +$amount = $response->amount; +``` + +If you prefer the old approach of directly receiving the Resource class, you can enable **auto-hydration** by calling `MollieApiClient::setAutoHydrate()`. diff --git a/docs/testing.md b/docs/testing.md new file mode 100644 index 000000000..2e3e9b95d --- /dev/null +++ b/docs/testing.md @@ -0,0 +1,55 @@ +# Testing with Mollie API Client + +## Overview + +Version 3 of the Mollie API client refines the handling of the test mode parameter: + +- **Automatic Removal of Test Mode**: When using an API key, the test mode parameter is managed based on the key prefix (`test_` or `live_`). +- **Explicit Test Mode Control**: For operations requiring explicit control, such as when using OAuth tokens, you can still pass the `testmode` parameter. + +## Enabling Test Mode + +### Global Test Mode + +You can enable test mode globally on the Mollie client. This setting will apply test mode to all operations performed with the client. + +```php +use Mollie\Api\MollieApiClient; + +$mollie = new MollieApiClient(); +$mollie->setApiKey("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"); +$mollie->test(true); // Enable test mode globally +``` + +### Per Request Test Mode + +For specific control, you can enable test mode per request. This is useful for mixed-mode operations. + +```php +// Creating a payment in test mode +use Mollie\Api\MollieApiClient; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Requests\CreatePaymentRequest; + +$mollie = new MollieApiClient(); +$createPaymentRequest = new CreatePaymentRequest( + new CreatePaymentPayload( + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', + 'https://example.org/webhook' + ) +); + +$mollie->send($createPaymentRequest->test(true)); +``` + +### Using Test Mode with Endpoint Collections + +When using endpoint collections, pass the test mode parameter directly to methods that support it. + +```php +// Fetch a customer in test mode +$customer = $mollie->customers->get('cust_12345678', testmode: true); +``` diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index 2ccc3a5af..580323df8 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -4,6 +4,10 @@ * How to prepare a new payment with the Mollie API. */ +use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; + try { /* * Initialize the Mollie API library with your API key. @@ -18,14 +22,12 @@ * description Description of the capture. * metadata Custom metadata that is stored with the payment. */ - $capture = $mollie - ->paymentCaptures->createForId('tr_WDqYK6vllg', [ - 'amount' => [ - 'currency' => 'EUR', - 'value' => '5.00', - ], - 'description' => 'Order #12345', - ]); + $response = $mollie->send(new CreatePaymentCaptureRequest('tr_WDqYK6vllg', new CreatePaymentCapturePayload( + 'Order #12345', + new Money('EUR', '5.00') + ))); + + $capture = $response->toResource(); echo '

          New capture created '.htmlspecialchars($capture->id).' ('.htmlspecialchars($capture->description).').

          '; } catch (\Mollie\Api\Exceptions\ApiException $e) { diff --git a/examples/captures/get-capture.php b/examples/captures/get-capture.php index 6978271c9..0f6e076dd 100644 --- a/examples/captures/get-capture.php +++ b/examples/captures/get-capture.php @@ -4,6 +4,8 @@ * Retrieve a payment capture using the Mollie API. */ +use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; + try { /* * Initialize the Mollie API library with your API key or OAuth access token. @@ -17,9 +19,9 @@ * See: https://docs.mollie.com/reference/v2/captures-api/get-capture */ - $payment = $mollie->payments->get('tr_WDqYK6vllg'); - $capture = $payment->getCapture('cpt_4qqhO89gsT'); + $response = $mollie->send(new GetPaymentCaptureRequest('tr_WDqYK6vllg', 'cpt_4qqhO89gsT')); + $capture = $response->toResource(); $amount = $capture->amount->currency.' '.$capture->amount->value; echo 'Captured '.$amount; diff --git a/examples/captures/list-captures.php b/examples/captures/list-captures.php index 1bd9b7a63..5045ba1bb 100644 --- a/examples/captures/list-captures.php +++ b/examples/captures/list-captures.php @@ -4,6 +4,8 @@ * List captures for a payment using the Mollie API. */ +use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; + try { /* * Initialize the Mollie API library with your API key or OAuth access token. @@ -16,13 +18,12 @@ * See: https://docs.mollie.com/reference/v2/captures-api/list-captures */ - $payment = $mollie->payments->get('tr_WDqYK6vllg'); - $captures = $payment->captures(); + $response = $mollie->send(new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg')); - foreach ($captures as $capture) { - $amount = $capture->amount->currency.' '.$capture->amount->value; - echo 'Captured '.$amount.' for payment '.$payment->id; + foreach ($payment = $response->toResource() as $capture) { + $amount = $capture->amount->currency . ' ' . $capture->amount->value; + echo 'Captured ' . $amount . ' for payment ' . $payment->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: '.htmlspecialchars($e->getMessage()); + echo 'API call failed: ' . htmlspecialchars($e->getMessage()); } diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index ffdddc110..e4c3a9d1c 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -4,6 +4,11 @@ * How to create a new client link in the Mollie API. */ +use Mollie\Api\Http\Payload\CreateClientLinkPayload; +use Mollie\Api\Http\Payload\Owner; +use Mollie\Api\Http\Payload\OwnerAddress; +use Mollie\Api\Http\Requests\CreateClientLinkRequest; + try { /* * Initialize the Mollie API library with your API key or OAuth access token. @@ -22,23 +27,15 @@ * * See: https://docs.mollie.com/reference/v2/client-links-api/create-client-link */ - $clientLink = $mollie->clientLinks->create([ - 'owner' => [ - 'email' => 'foo@test.com', - 'givenName' => 'foo', - 'familyName' => 'bar', - 'locale' => 'nl_NL', - ], - 'name' => 'Foo Company', - 'address' => [ - 'streetAndNumber' => 'Keizersgracht 313', - 'postalCode' => '1016 EE', - 'city' => 'Amsterdam', - 'country' => 'nl', - ], - 'registrationNumber' => '30204462', - 'vatNumber' => 'NL123456789B01', - ]); + $response = $mollie->send(new CreateClientLinkRequest(new CreateClientLinkPayload( + new Owner('foo@test.com', 'foo', 'bar', 'nl_NL'), + 'Foo Company', + new OwnerAddress('NL', 'Keizersgracht 313', '1016 EE', 'Amsterdam'), + '30204462', + 'NL123456789B01', + ))); + + $clientLink = $response->toResource(); /** * Get the redirect url for the client link, by passing in the 'client_id' of the your app, diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index ba740c32e..d1b8417f8 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -4,6 +4,13 @@ * How to create a first payment to allow recurring payments later. */ +use Mollie\Api\Factories\CreatePaymentPayloadFactory; +use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; +use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; +use Mollie\Api\Types\SequenceType; + try { /* * Initialize the Mollie API library with your API key or OAuth access token. @@ -14,7 +21,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run the create-customer example. */ - $customer = $mollie->customers->collect(null, 1)[0]; + $customer = $mollie->send(new GetPaginatedCustomerRequest())->toResource()[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute @@ -33,21 +40,20 @@ * * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ - $payment = $customer->createPayment([ - 'amount' => [ - 'value' => '10.00', // You must send the correct number of decimals, thus we enforce the use of strings - 'currency' => 'EUR', - ], + $payload = CreatePaymentPayloadFactory::new([ 'description' => "First payment - Order #{$orderId}", + 'amount' => new Money('EUR', '10.00'), 'redirectUrl' => "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", 'webhookUrl' => "{$protocol}://{$hostname}/payments/webhook.php", - 'metadata' => [ + 'metadata' => new Metadata([ 'order_id' => $orderId, - ], + ]), + 'sequenceType' => SequenceType::FIRST, + ])->create(); - // Flag this payment as a first payment to allow recurring payments later. - 'sequenceType' => \Mollie\Api\Types\SequenceType::FIRST, - ]); + $payment = $mollie->send( + new CreateCustomerPaymentRequest($customer->id, $payload) + ); /* * In this example we store the order with its payment status in a database. @@ -61,7 +67,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header('Location: '.$payment->getCheckoutUrl(), true, 303); + header('Location: ' . $payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: '.htmlspecialchars($e->getMessage()); + echo 'API call failed: ' . htmlspecialchars($e->getMessage()); } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6bc67aa4e..d9e527865 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -27,7 +27,7 @@ parameters: - message: '#^Variable \$mollie might not be defined\.$#' identifier: variable.undefined - count: 1 + count: 2 path: examples/customers/create-customer-first-payment.php - @@ -342,6 +342,30 @@ parameters: count: 3 path: tests/Fixtures/MockResponse.php + - + message: '#^Property Tests\\Helpers\\TestPropertiesClass\:\:\$privateProp is unused\.$#' + identifier: property.unused + count: 1 + path: tests/Helpers/HelpersTest.php + + - + message: '#^Trait Tests\\Helpers\\TestTraitBase is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: tests/Helpers/HelpersTest.php + + - + message: '#^Trait Tests\\Helpers\\TestTraitMain is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: tests/Helpers/HelpersTest.php + + - + message: '#^Trait Tests\\Helpers\\TestTraitNested is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: tests/Helpers/HelpersTest.php + - message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' identifier: staticClassAccess.privateProperty diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index b5ca5fa99..9b0d3fe45 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -45,6 +45,7 @@ public function create($data = [], $testmode = []): Customer * * Will throw a ApiException if the customer id is invalid or the resource cannot be found. * + * @param bool|array $testmode * @throws ApiException */ public function get(string $id, $testmode = []): Customer diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index 8b64a2c08..9a87e7f3e 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -50,16 +50,16 @@ public function get(string $id, $query = [], bool $testmode = false): Payment /** * Creates a payment in Mollie. * - * @param CreatePaymentPayload|array $data An array containing details on the payment. + * @param CreatePaymentPayload|array $payload An array containing details on the payment. * @param CreatePaymentQuery|array|string $query An array of strings or a single string containing the details to include. * * @throws ApiException */ - public function create($data = [], $query = [], bool $testmode = false): Payment + public function create($payload = [], $query = [], bool $testmode = false): Payment { - if (! $data instanceof CreatePaymentPayload) { - $testmode = Helpers::extractBool($data, 'testmode', $testmode); - $data = CreatePaymentPayloadFactory::new($data) + if (! $payload instanceof CreatePaymentPayload) { + $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $payload = CreatePaymentPayloadFactory::new($payload) ->create(); } @@ -68,7 +68,7 @@ public function create($data = [], $query = [], bool $testmode = false): Payment } /** @var Payment */ - return $this->send((new CreatePaymentRequest($data, $query))->test($testmode)); + return $this->send((new CreatePaymentRequest($payload, $query))->test($testmode)); } /** diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 20decae7f..6cbd7eead 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -2,20 +2,29 @@ namespace Mollie\Api\Factories; +use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Contracts\DataProvider; use Mollie\Api\Contracts\Factory as FactoryContract; use Mollie\Api\Helpers; use Mollie\Api\Helpers\Arr; +use Mollie\Api\Http\Payload\DataBag; abstract class Factory implements FactoryContract { protected array $data; - public function __construct(array $data) + public function __construct($data) { - $this->data = $data; + if ($data instanceof Arrayable) { + $this->data = $data->toArray(); + } else if ($data instanceof DataProvider) { + $this->data = $data->data(); + } else { + $this->data = $data; + } } - public static function new(array $data): self + public static function new($data): self { /** @phpstan-ignore-next-line */ return new static($data); @@ -32,7 +41,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey.$key; + $keys[] = $backupKey . $key; } foreach ($keys as $key) { @@ -55,7 +64,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey.$key, $key], $value); + return Arr::includes($this->data, [$backupKey . $key, $key], $value); } /** diff --git a/src/Helpers.php b/src/Helpers.php index d2379a804..8ada088ee 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -69,13 +69,13 @@ public static function getProperties($class, $flag = ReflectionProperty::IS_PUBL public static function filterByProperties($class, array $array): array { $properties = array_map( - fn (ReflectionProperty $prop) => $prop->getName(), + fn(ReflectionProperty $prop) => $prop->getName(), static::getProperties($class) ); return array_filter( $array, - fn ($key) => ! in_array($key, $properties, true), + fn($key) => ! in_array($key, $properties, true), ARRAY_FILTER_USE_KEY ); } @@ -90,9 +90,14 @@ public static function filterByProperties($class, array $array): array */ public static function compose($value, $composable, $default = null) { - $composable = is_callable($composable) - ? $composable - : fn ($value) => new $composable($value); + // If the value is an instance of the composable class, return it. + if (is_string($composable) && $value instanceof $composable) { + return $value; + } + + $composable = is_string($composable) + ? fn($value) => new $composable($value) + : $composable; return (bool) $value ? $composable($value) : $default; } diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index c9eba6692..844301402 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -9,7 +9,6 @@ use GuzzleHttp\Exception\RequestException; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\HttpFactory; -use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions as GuzzleRequestOptions; use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; @@ -133,6 +132,6 @@ protected function createResponse( */ public function version(): string { - return 'Guzzle/'.ClientInterface::MAJOR_VERSION; + return 'Guzzle/' . ClientInterface::MAJOR_VERSION; } } diff --git a/src/Http/Payload/Metadata.php b/src/Http/Payload/Metadata.php index 2fdd7b49d..1b8a2e128 100644 --- a/src/Http/Payload/Metadata.php +++ b/src/Http/Payload/Metadata.php @@ -6,15 +6,15 @@ class Metadata implements DataProvider { - public array $metadata; + public array $data; - public function __construct(array $metadata) + public function __construct(array $data) { - $this->metadata = $metadata; + $this->data = $data; } public function data(): string { - return @json_encode($this->metadata); + return @json_encode($this->data); } } diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php new file mode 100644 index 000000000..655a2a2a9 --- /dev/null +++ b/tests/Helpers/HelpersTest.php @@ -0,0 +1,141 @@ +assertContains(TestTrait1::class, $result); + $this->assertContains(TestTrait2::class, $result); + $this->assertContains(TestTrait3::class, $result); + } + + /** @test */ + public function trait_uses_recursive() + { + $result = Helpers::traitUsesRecursive(TestTraitMain::class); + + $this->assertContains(TestTraitBase::class, $result); + $this->assertContains(TestTraitNested::class, $result); + } + + /** @test */ + public function get_properties() + { + // Test getting all properties + $allProps = Helpers::getProperties(TestPropertiesClass::class); + $this->assertCount(3, $allProps); + $this->assertContainsOnlyInstancesOf(ReflectionProperty::class, $allProps); + + // Test getting only public properties + $publicProps = Helpers::getProperties(TestPropertiesClass::class, ReflectionProperty::IS_PUBLIC); + $this->assertCount(1, $publicProps); + $this->assertEquals('publicProp', $publicProps[0]->getName()); + } + + /** @test */ + public function filter_by_properties() + { + $array = [ + 'prop1' => 'value1', + 'prop2' => 'value2', + 'extraProp' => 'extraValue' + ]; + + $filtered = Helpers::filterByProperties(TestFilterClass::class, $array); + + $this->assertArrayHasKey('extraProp', $filtered); + $this->assertArrayNotHasKey('prop1', $filtered); + $this->assertArrayNotHasKey('prop2', $filtered); + } + + /** @test */ + public function compose() + { + // Test with callable + $composedWithCallable = Helpers::compose(5, fn($x) => $x * 2); + $this->assertEquals(10, $composedWithCallable); + + $composedWithClass = Helpers::compose('test', TestComposable::class); + $this->assertInstanceOf(TestComposable::class, $composedWithClass); + $this->assertEquals('test', $composedWithClass->value); + + // Test with falsy value + $composedWithDefault = Helpers::compose(false, fn($x) => $x * 2, 'default'); + $this->assertEquals('default', $composedWithDefault); + + $existingValueIsNotOverriden = Helpers::compose(new Metadata(['key' => 'value']), Metadata::class); + $this->assertInstanceOf(Metadata::class, $existingValueIsNotOverriden); + $this->assertEquals(['key' => 'value'], $existingValueIsNotOverriden->data); + } + + /** @test */ + public function extract_bool() + { + // Test with direct boolean + $this->assertTrue(Helpers::extractBool(true, 'key')); + $this->assertFalse(Helpers::extractBool(false, 'key')); + + // Test with array + $array = ['enabled' => true]; + $this->assertTrue(Helpers::extractBool($array, 'enabled')); + $this->assertFalse(Helpers::extractBool($array, 'nonexistent')); + + // Test with default value + $this->assertTrue(Helpers::extractBool([], 'key', true)); + } +} + +trait TestTrait1 {} +trait TestTrait2 {} +trait TestTrait3 +{ + use TestTrait1; +} + +class TestParentClass +{ + use TestTrait1; +} + +class TestChildClass extends TestParentClass +{ + use TestTrait2, TestTrait3; +} + +trait TestTraitBase {} +trait TestTraitNested +{ + use TestTraitBase; +} +trait TestTraitMain +{ + use TestTraitNested; +} + +class TestPropertiesClass +{ + public $publicProp; + protected $protectedProp; + private $privateProp; +} + +class TestFilterClass +{ + public $prop1; + public $prop2; +} + +class TestComposable +{ + public function __construct(public $value) {} +} From 16785c5e4c4b427462e474ad8744d665dcdbf03b Mon Sep 17 00:00:00 2001 From: Naoray Date: Fri, 6 Dec 2024 12:39:06 +0000 Subject: [PATCH 096/131] Fixes coding style --- examples/captures/list-captures.php | 6 +++--- .../customers/create-customer-first-payment.php | 6 +++--- .../CustomerEndpointCollection.php | 1 + src/Factories/Factory.php | 7 +++---- src/Helpers.php | 6 +++--- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 2 +- tests/Helpers/HelpersTest.php | 13 ++++++++----- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/captures/list-captures.php b/examples/captures/list-captures.php index 5045ba1bb..2ead8b80f 100644 --- a/examples/captures/list-captures.php +++ b/examples/captures/list-captures.php @@ -21,9 +21,9 @@ $response = $mollie->send(new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg')); foreach ($payment = $response->toResource() as $capture) { - $amount = $capture->amount->currency . ' ' . $capture->amount->value; - echo 'Captured ' . $amount . ' for payment ' . $payment->id; + $amount = $capture->amount->currency.' '.$capture->amount->value; + echo 'Captured '.$amount.' for payment '.$payment->id; } } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: ' . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index d1b8417f8..3a85afd42 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -21,7 +21,7 @@ * Retrieve the last created customer for this example. * If no customers are created yet, run the create-customer example. */ - $customer = $mollie->send(new GetPaginatedCustomerRequest())->toResource()[0]; + $customer = $mollie->send(new GetPaginatedCustomerRequest)->toResource()[0]; /* * Generate a unique order id for this example. It is important to include this unique attribute @@ -67,7 +67,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header('Location: ' . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: ' . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index 9b0d3fe45..ca3e5f77e 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -46,6 +46,7 @@ public function create($data = [], $testmode = []): Customer * Will throw a ApiException if the customer id is invalid or the resource cannot be found. * * @param bool|array $testmode + * * @throws ApiException */ public function get(string $id, $testmode = []): Customer diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 6cbd7eead..3032309e2 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -7,7 +7,6 @@ use Mollie\Api\Contracts\Factory as FactoryContract; use Mollie\Api\Helpers; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Http\Payload\DataBag; abstract class Factory implements FactoryContract { @@ -17,7 +16,7 @@ public function __construct($data) { if ($data instanceof Arrayable) { $this->data = $data->toArray(); - } else if ($data instanceof DataProvider) { + } elseif ($data instanceof DataProvider) { $this->data = $data->data(); } else { $this->data = $data; @@ -41,7 +40,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey . $key; + $keys[] = $backupKey.$key; } foreach ($keys as $key) { @@ -64,7 +63,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey . $key, $key], $value); + return Arr::includes($this->data, [$backupKey.$key, $key], $value); } /** diff --git a/src/Helpers.php b/src/Helpers.php index 8ada088ee..5bd2e57d0 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -69,13 +69,13 @@ public static function getProperties($class, $flag = ReflectionProperty::IS_PUBL public static function filterByProperties($class, array $array): array { $properties = array_map( - fn(ReflectionProperty $prop) => $prop->getName(), + fn (ReflectionProperty $prop) => $prop->getName(), static::getProperties($class) ); return array_filter( $array, - fn($key) => ! in_array($key, $properties, true), + fn ($key) => ! in_array($key, $properties, true), ARRAY_FILTER_USE_KEY ); } @@ -96,7 +96,7 @@ public static function compose($value, $composable, $default = null) } $composable = is_string($composable) - ? fn($value) => new $composable($value) + ? fn ($value) => new $composable($value) : $composable; return (bool) $value ? $composable($value) : $default; diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 844301402..b166f975a 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -132,6 +132,6 @@ protected function createResponse( */ public function version(): string { - return 'Guzzle/' . ClientInterface::MAJOR_VERSION; + return 'Guzzle/'.ClientInterface::MAJOR_VERSION; } } diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php index 655a2a2a9..d2fce6e04 100644 --- a/tests/Helpers/HelpersTest.php +++ b/tests/Helpers/HelpersTest.php @@ -4,15 +4,15 @@ use Mollie\Api\Helpers; use Mollie\Api\Http\Payload\Metadata; -use Tests\TestCase; use ReflectionProperty; +use Tests\TestCase; class HelpersTest extends TestCase { /** @test */ public function class_uses_recursive() { - $result = Helpers::classUsesRecursive(new TestChildClass()); + $result = Helpers::classUsesRecursive(new TestChildClass); $this->assertContains(TestTrait1::class, $result); $this->assertContains(TestTrait2::class, $result); @@ -48,7 +48,7 @@ public function filter_by_properties() $array = [ 'prop1' => 'value1', 'prop2' => 'value2', - 'extraProp' => 'extraValue' + 'extraProp' => 'extraValue', ]; $filtered = Helpers::filterByProperties(TestFilterClass::class, $array); @@ -62,7 +62,7 @@ public function filter_by_properties() public function compose() { // Test with callable - $composedWithCallable = Helpers::compose(5, fn($x) => $x * 2); + $composedWithCallable = Helpers::compose(5, fn ($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); $composedWithClass = Helpers::compose('test', TestComposable::class); @@ -70,7 +70,7 @@ public function compose() $this->assertEquals('test', $composedWithClass->value); // Test with falsy value - $composedWithDefault = Helpers::compose(false, fn($x) => $x * 2, 'default'); + $composedWithDefault = Helpers::compose(false, fn ($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); $existingValueIsNotOverriden = Helpers::compose(new Metadata(['key' => 'value']), Metadata::class); @@ -125,13 +125,16 @@ trait TestTraitMain class TestPropertiesClass { public $publicProp; + protected $protectedProp; + private $privateProp; } class TestFilterClass { public $prop1; + public $prop2; } From b5f66654ac307fbce86077332802bc5d962cd694 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 6 Dec 2024 13:40:19 +0100 Subject: [PATCH 097/131] wip --- tests/Helpers/HelpersTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php index d2fce6e04..276c7597b 100644 --- a/tests/Helpers/HelpersTest.php +++ b/tests/Helpers/HelpersTest.php @@ -140,5 +140,10 @@ class TestFilterClass class TestComposable { - public function __construct(public $value) {} + public $value; + + public function __construct($value) + { + $this->value = $value; + } } From ab6772d1ee37fb697f7e94b978584dcd6beea590 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 6 Dec 2024 13:48:44 +0100 Subject: [PATCH 098/131] wip --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 39e03df3a..e0eb9a60b 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,8 @@ $response = $mollie->send(new CreatePaymentRequest($payload)); $payment = $response->toResource(); ``` -## Upgrading - -Please see [UPGRADING](UPGRADING.md) for details. - -## API documentation ## -For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. - ## Documentation +For an in-depth understanding of our API, please explore the [Mollie Developer Portal](https://www.mollie.com/developers). Our API documentation is available in English. For detailed documentation about using this PHP client, see the following guides: @@ -108,6 +102,9 @@ For a full list of examples, please refer to the [examples directory](examples/) These examples are designed to be run in a safe testing environment. Make sure to use your test API keys and review each example's code before integrating it into your production environment. +## Upgrading + +Please see [UPGRADING](UPGRADING.md) for details. ## Contributing to Our API Client ## Would you like to contribute to improving our API client? We welcome [pull requests](https://github.com/mollie/mollie-api-php/pulls?utf8=%E2%9C%93&q=is%3Apr). But, if you're interested in contributing to a technology-focused organization, Mollie is actively recruiting developers and system engineers. Discover our current [job openings](https://jobs.mollie.com/) or [reach out](mailto:personeel@mollie.com). From 80070906e8c7cbe880f5369664ae82970a27a48b Mon Sep 17 00:00:00 2001 From: Sander van Hooft Date: Mon, 9 Dec 2024 13:31:48 +0100 Subject: [PATCH 099/131] Add support for php8.4 to GH test workflow --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2f8b06ac7..8f356a39a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: true matrix: - php: [7.4, 8.0, 8.1, 8.2, 8.3] + php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4] name: PHP - ${{ matrix.php }} steps: - name: Checkout code From 8f31fbd10e003aa4e012852feb08badb99a7f6d5 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 13:50:24 +0100 Subject: [PATCH 100/131] add sales invoices endpoint --- docs/endpoint-collections.md | 66 +++++++ .../SalesInvoiceEndpointCollection.php | 109 ++++++++++++ .../CreateSalesInvoicePayloadFactory.php | 40 +++++ .../InvoiceLineCollectionFactory.php | 16 ++ src/Factories/InvoiceLineFactory.php | 20 +++ src/Factories/RecipientFactory.php | 30 ++++ .../UpdateSalesInvoicePayloadFactory.php | 36 ++++ .../Payload/CreateSalesInvoicePayload.php | 93 ++++++++++ src/Http/Payload/Discount.php | 31 ++++ src/Http/Payload/EmailDetails.php | 30 ++++ src/Http/Payload/InvoiceLine.php | 41 +++++ src/Http/Payload/PaymentDetails.php | 31 ++++ src/Http/Payload/Recipient.php | 98 ++++++++++ .../Payload/UpdateSalesInvoicePayload.php | 69 ++++++++ .../Requests/CreateSalesInvoiceRequest.php | 34 ++++ .../Requests/DeleteSalesInvoiceRequest.php | 23 +++ .../GetPaginatedSalesInvoicesRequest.php | 20 +++ src/Http/Requests/GetSalesInvoiceRequest.php | 31 ++++ .../Requests/UpdateSalesInvoiceRequest.php | 36 ++++ src/MollieApiClient.php | 6 +- src/Resources/SalesInvoice.php | 167 ++++++++++++++++++ src/Resources/SalesInvoiceCollection.php | 16 ++ src/Traits/HasEndpoints.php | 2 + src/Types/PaymentTerm.php | 14 ++ src/Types/RecipientType.php | 9 + src/Types/SalesInvoiceStatus.php | 21 +++ src/Types/VatMode.php | 9 + src/Types/VatScheme.php | 9 + .../SalesInvoiceEndpointCollectionTest.php | 136 ++++++++++++++ .../Responses/sales-invoice-list.json | 83 +++++++++ tests/Fixtures/Responses/sales-invoice.json | 81 +++++++++ .../CreateSalesInvoiceRequestTest.php | 98 ++++++++++ .../DeleteSalesInvoiceRequestTest.php | 34 ++++ .../GetPaginatedSalesInvoicesRequestTest.php | 69 ++++++++ .../Requests/GetSalesInvoiceRequestTest.php | 26 +++ .../UpdateSalesInvoiceRequestTest.php | 44 +++++ 36 files changed, 1676 insertions(+), 2 deletions(-) create mode 100644 src/EndpointCollection/SalesInvoiceEndpointCollection.php create mode 100644 src/Factories/CreateSalesInvoicePayloadFactory.php create mode 100644 src/Factories/InvoiceLineCollectionFactory.php create mode 100644 src/Factories/InvoiceLineFactory.php create mode 100644 src/Factories/RecipientFactory.php create mode 100644 src/Factories/UpdateSalesInvoicePayloadFactory.php create mode 100644 src/Http/Payload/CreateSalesInvoicePayload.php create mode 100644 src/Http/Payload/Discount.php create mode 100644 src/Http/Payload/EmailDetails.php create mode 100644 src/Http/Payload/InvoiceLine.php create mode 100644 src/Http/Payload/PaymentDetails.php create mode 100644 src/Http/Payload/Recipient.php create mode 100644 src/Http/Payload/UpdateSalesInvoicePayload.php create mode 100644 src/Http/Requests/CreateSalesInvoiceRequest.php create mode 100644 src/Http/Requests/DeleteSalesInvoiceRequest.php create mode 100644 src/Http/Requests/GetPaginatedSalesInvoicesRequest.php create mode 100644 src/Http/Requests/GetSalesInvoiceRequest.php create mode 100644 src/Http/Requests/UpdateSalesInvoiceRequest.php create mode 100644 src/Resources/SalesInvoice.php create mode 100644 src/Resources/SalesInvoiceCollection.php create mode 100644 src/Types/PaymentTerm.php create mode 100644 src/Types/RecipientType.php create mode 100644 src/Types/SalesInvoiceStatus.php create mode 100644 src/Types/VatMode.php create mode 100644 src/Types/VatScheme.php create mode 100644 tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php create mode 100644 tests/Fixtures/Responses/sales-invoice-list.json create mode 100644 tests/Fixtures/Responses/sales-invoice.json create mode 100644 tests/Http/Requests/CreateSalesInvoiceRequestTest.php create mode 100644 tests/Http/Requests/DeleteSalesInvoiceRequestTest.php create mode 100644 tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php create mode 100644 tests/Http/Requests/GetSalesInvoiceRequestTest.php create mode 100644 tests/Http/Requests/UpdateSalesInvoiceRequestTest.php diff --git a/docs/endpoint-collections.md b/docs/endpoint-collections.md index 6a0f7c2c1..4dee3bf8a 100644 --- a/docs/endpoint-collections.md +++ b/docs/endpoint-collections.md @@ -521,6 +521,72 @@ $refund = $mollie->refunds->createForPayment($paymentId, [ $refunds = $mollie->refunds->page(); ``` +## Sales Invoices + +[Official Documentation TBA] + +**Available Payloads:** +- `CreateSalesInvoicePayload` - For creating sales invoices +- `UpdateSalesInvoicePayload` - For updating existing sales invoices + +**Available Queries:** +- `GetPaginatedSalesInvoiceQuery` - For listing sales invoices with pagination + +### Sales Invoice Management + +```php +use Mollie\Api\Types\VatMode; +use Mollie\Api\Types\VatScheme; +use Mollie\Api\Types\PaymentTerm; +use Mollie\Api\Types\RecipientType; +use Mollie\Api\Types\RecipientType; +use Mollie\Api\Types\SalesInvoiceStatus; + +// Create a sales invoice +$salesInvoice = $mollie->salesInvoices->create([ + 'currency' => 'EUR', + 'status' => SalesInvoiceStatus::DRAFT, + 'vatScheme' => VatScheme::STANDARD, + 'vatMode' => VatMode::INCLUSIVE, + 'paymentTerm' => PaymentTerm::DAYS_30, + 'recipientIdentifier' => 'XXXXX', + 'recipient' => [ + 'type' => RecipientType::CONSUMER, + 'email' => 'darth@vader.deathstar', + 'streetAndNumber' => 'Sample Street 12b', + 'postalCode' => '2000 AA', + 'city' => 'Amsterdam', + 'country' => 'NL', + 'locale' => 'nl_NL' + ], + 'lines' => [ + [ + 'description' => 'Monthly subscription fee', + 'quantity' => 1, + 'vatRate' => '21', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10,00' + ] + ] + ] +]); + +// Get a sales invoice +$salesInvoice = $mollie->salesInvoices->get('invoice_12345'); + +// Update a sales invoice +$salesInvoice = $mollie->salesInvoices->update('invoice_12345', [ + 'description' => 'Updated description' +]); + +// Delete a sales invoice +$mollie->salesInvoices->delete('invoice_12345'); + +// List sales invoices +$salesInvoices = $mollie->salesInvoices->page(); +``` + ## Sessions [Official Documentation](https://docs.mollie.com/reference/v2/sessions-api/create-session) diff --git a/src/EndpointCollection/SalesInvoiceEndpointCollection.php b/src/EndpointCollection/SalesInvoiceEndpointCollection.php new file mode 100644 index 000000000..c1b28f78d --- /dev/null +++ b/src/EndpointCollection/SalesInvoiceEndpointCollection.php @@ -0,0 +1,109 @@ +send(new GetSalesInvoiceRequest($id)); + } + + /** + * Creates a SalesInvoice in Mollie. + * + * @param array|CreateSalesInvoicePayload $payload + * + * @throws ApiException + */ + public function create($payload = []): SalesInvoice + { + if (! $payload instanceof CreateSalesInvoicePayload) { + $payload = CreateSalesInvoicePayloadFactory::new($payload)->create(); + } + + return $this->send(new CreateSalesInvoiceRequest($payload)); + } + + /** + * Update a specific SalesInvoice resource. + * + * @throws ApiException + */ + public function update(string $id, $payload = []): ?SalesInvoice + { + if (! $payload instanceof UpdateSalesInvoicePayload) { + $payload = UpdateSalesInvoicePayloadFactory::new($payload)->create(); + } + + return $this->send(new UpdateSalesInvoiceRequest($id, $payload)); + } + + /** + * Delete a SalesInvoice from Mollie. + * + * @throws ApiException + */ + public function delete(string $id): void + { + $this->send(new DeleteSalesInvoiceRequest($id)); + } + + /** + * Retrieves a collection of SalesInvoices from Mollie. + * + * @throws ApiException + */ + public function page(?string $from = null, ?int $limit = null): SalesInvoiceCollection + { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send(new GetPaginatedSalesInvoicesRequest($query)); + } + + /** + * Create an iterator for iterating over sales invoices retrieved from Mollie. + * + * @param string|null $from The first resource ID you want to include in your list. + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + */ + public function iterator( + ?string $from = null, + ?int $limit = null, + bool $iterateBackwards = false + ): LazyCollection { + $query = PaginatedQueryFactory::new([ + 'from' => $from, + 'limit' => $limit, + ])->create(); + + return $this->send( + (new GetPaginatedSalesInvoicesRequest($query)) + ->useIterator() + ->setIterationDirection($iterateBackwards) + ); + } +} diff --git a/src/Factories/CreateSalesInvoicePayloadFactory.php b/src/Factories/CreateSalesInvoicePayloadFactory.php new file mode 100644 index 000000000..de6200a65 --- /dev/null +++ b/src/Factories/CreateSalesInvoicePayloadFactory.php @@ -0,0 +1,40 @@ +get('currency'), + $this->get('status'), + $this->get('vatScheme'), + $this->get('vatMode'), + $this->get('paymentTerm'), + $this->get('recipientIdentifier'), + RecipientFactory::new($this->get('recipient'))->create(), + $this + ->mapIfNotNull( + 'lines', + fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + ), + $this->get('profileId'), + $this->get('memo'), + $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), + $this->get('webhookUrl'), + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + ); + } +} diff --git a/src/Factories/InvoiceLineCollectionFactory.php b/src/Factories/InvoiceLineCollectionFactory.php new file mode 100644 index 000000000..d90f10f33 --- /dev/null +++ b/src/Factories/InvoiceLineCollectionFactory.php @@ -0,0 +1,16 @@ + InvoiceLineFactory::new($item)->create(), + $this->data + )); + } +} diff --git a/src/Factories/InvoiceLineFactory.php b/src/Factories/InvoiceLineFactory.php new file mode 100644 index 000000000..bd9297922 --- /dev/null +++ b/src/Factories/InvoiceLineFactory.php @@ -0,0 +1,20 @@ +get('description'), + $this->get('quantity'), + $this->get('vatRate'), + MoneyFactory::new($this->get('unitPrice'))->create(), + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + ); + } +} diff --git a/src/Factories/RecipientFactory.php b/src/Factories/RecipientFactory.php new file mode 100644 index 000000000..31d64a878 --- /dev/null +++ b/src/Factories/RecipientFactory.php @@ -0,0 +1,30 @@ +get('type'), + $this->get('email'), + $this->get('streetAndNumber'), + $this->get('postalCode'), + $this->get('city'), + $this->get('country'), + $this->get('locale'), + $this->get('title'), + $this->get('givenName'), + $this->get('familyName'), + $this->get('organizationName'), + $this->get('organizationNumber'), + $this->get('vatNumber'), + $this->get('phone'), + $this->get('streetAdditional'), + $this->get('region'), + ); + } +} diff --git a/src/Factories/UpdateSalesInvoicePayloadFactory.php b/src/Factories/UpdateSalesInvoicePayloadFactory.php new file mode 100644 index 000000000..005780d25 --- /dev/null +++ b/src/Factories/UpdateSalesInvoicePayloadFactory.php @@ -0,0 +1,36 @@ +get('status'), + $this->get('recipientIdentifier'), + $this->get('paymentTerm'), + $this->get('memo'), + $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('recipient', fn(array $data) => RecipientFactory::new($data)->create()), + $this + ->mapIfNotNull( + 'lines', + fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + ), + $this->get('webhookUrl'), + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + ); + } +} diff --git a/src/Http/Payload/CreateSalesInvoicePayload.php b/src/Http/Payload/CreateSalesInvoicePayload.php new file mode 100644 index 000000000..4ff3b3084 --- /dev/null +++ b/src/Http/Payload/CreateSalesInvoicePayload.php @@ -0,0 +1,93 @@ + + */ + public DataCollection $lines; + + public ?string $webhookUrl; + + public ?Discount $discount; + + public function __construct( + string $currency, + string $status, + string $vatScheme, + string $vatMode, + string $paymentTerm, + string $recipientIdentifier, + Recipient $recipient, + DataCollection $lines, + ?string $profileId = null, + ?string $memo = null, + ?PaymentDetails $paymentDetails = null, + ?EmailDetails $emailDetails = null, + ?string $webhookUrl = null, + ?Discount $discount = null, + ) { + $this->profileId = $profileId; + $this->currency = $currency; + $this->status = $status; + $this->vatScheme = $vatScheme; + $this->vatMode = $vatMode; + $this->memo = $memo; + $this->paymentTerm = $paymentTerm; + $this->paymentDetails = $paymentDetails; + $this->emailDetails = $emailDetails; + $this->recipientIdentifier = $recipientIdentifier; + $this->recipient = $recipient; + $this->lines = $lines; + $this->webhookUrl = $webhookUrl; + $this->discount = $discount; + } + + public function data(): array + { + return [ + 'profileId' => $this->profileId, + 'currency' => $this->currency, + 'status' => $this->status, + 'vatScheme' => $this->vatScheme, + 'vatMode' => $this->vatMode, + 'memo' => $this->memo, + 'paymentTerm' => $this->paymentTerm, + 'paymentDetails' => $this->paymentDetails, + 'emailDetails' => $this->emailDetails, + 'recipientIdentifier' => $this->recipientIdentifier, + 'recipient' => $this->recipient, + 'lines' => $this->lines, + 'webhookUrl' => $this->webhookUrl, + 'discount' => $this->discount, + ]; + } +} diff --git a/src/Http/Payload/Discount.php b/src/Http/Payload/Discount.php new file mode 100644 index 000000000..3207fe1e9 --- /dev/null +++ b/src/Http/Payload/Discount.php @@ -0,0 +1,31 @@ +type = $type; + $this->value = $value; + } + + public function data() + { + return [ + 'type' => $this->type, + 'value' => $this->value, + ]; + } +} diff --git a/src/Http/Payload/EmailDetails.php b/src/Http/Payload/EmailDetails.php new file mode 100644 index 000000000..be78009d0 --- /dev/null +++ b/src/Http/Payload/EmailDetails.php @@ -0,0 +1,30 @@ +subject = $subject; + $this->body = $body; + } + + public function data() + { + return [ + 'subject' => $this->subject, + 'body' => $this->body, + ]; + } +} diff --git a/src/Http/Payload/InvoiceLine.php b/src/Http/Payload/InvoiceLine.php new file mode 100644 index 000000000..ced72bd6b --- /dev/null +++ b/src/Http/Payload/InvoiceLine.php @@ -0,0 +1,41 @@ +description = $description; + $this->quantity = $quantity; + $this->vatRate = $vatRate; + $this->unitPrice = $unitPrice; + $this->discount = $discount; + } + + public function data() + { + return [ + 'description' => $this->description, + 'quantity' => $this->quantity, + 'vatRate' => $this->vatRate, + 'unitPrice' => $this->unitPrice, + 'discount' => $this->discount, + ]; + } +} diff --git a/src/Http/Payload/PaymentDetails.php b/src/Http/Payload/PaymentDetails.php new file mode 100644 index 000000000..ad224023a --- /dev/null +++ b/src/Http/Payload/PaymentDetails.php @@ -0,0 +1,31 @@ +source = $source; + $this->sourceDescription = $sourceDescription; + } + + public function data() + { + return [ + 'source' => $this->source, + 'sourceDescription' => $this->sourceDescription, + ]; + } +} diff --git a/src/Http/Payload/Recipient.php b/src/Http/Payload/Recipient.php new file mode 100644 index 000000000..bff225947 --- /dev/null +++ b/src/Http/Payload/Recipient.php @@ -0,0 +1,98 @@ +type = $type; + $this->title = $title; + $this->givenName = $givenName; + $this->familyName = $familyName; + $this->organizationName = $organizationName; + $this->organizationNumber = $organizationNumber; + $this->vatNumber = $vatNumber; + $this->email = $email; + $this->phone = $phone; + $this->streetAndNumber = $streetAndNumber; + $this->streetAdditional = $streetAdditional; + $this->postalCode = $postalCode; + $this->city = $city; + $this->region = $region; + $this->country = $country; + $this->locale = $locale; + } + + public function data() + { + return [ + 'type' => $this->type, + 'title' => $this->title, + 'givenName' => $this->givenName, + 'familyName' => $this->familyName, + 'organizationName' => $this->organizationName, + 'organizationNumber' => $this->organizationNumber, + 'vatNumber' => $this->vatNumber, + 'email' => $this->email, + 'phone' => $this->phone, + 'streetAndNumber' => $this->streetAndNumber, + 'streetAdditional' => $this->streetAdditional, + 'postalCode' => $this->postalCode, + 'city' => $this->city, + 'region' => $this->region, + 'country' => $this->country, + 'locale' => $this->locale, + ]; + } +} diff --git a/src/Http/Payload/UpdateSalesInvoicePayload.php b/src/Http/Payload/UpdateSalesInvoicePayload.php new file mode 100644 index 000000000..634a25f0d --- /dev/null +++ b/src/Http/Payload/UpdateSalesInvoicePayload.php @@ -0,0 +1,69 @@ + + */ + public ?DataCollection $lines; + + public ?string $webhookUrl; + + public ?Discount $discount; + + public function __construct( + string $status, + string $recipientIdentifier, + ?string $paymentTerm = null, + ?string $memo = null, + ?PaymentDetails $paymentDetails = null, + ?EmailDetails $emailDetails = null, + ?Recipient $recipient = null, + ?DataCollection $lines = null, + ?string $webhookUrl = null, + ?Discount $discount = null, + ) { + $this->status = $status; + $this->paymentTerm = $paymentTerm; + $this->recipientIdentifier = $recipientIdentifier; + $this->memo = $memo; + $this->paymentDetails = $paymentDetails; + $this->emailDetails = $emailDetails; + $this->recipient = $recipient; + $this->lines = $lines; + $this->webhookUrl = $webhookUrl; + $this->discount = $discount; + } + + public function data(): array + { + return [ + 'status' => $this->status, + 'memo' => $this->memo, + 'paymentTerm' => $this->paymentTerm, + 'paymentDetails' => $this->paymentDetails, + 'emailDetails' => $this->emailDetails, + 'recipientIdentifier' => $this->recipientIdentifier, + 'recipient' => $this->recipient, + 'lines' => $this->lines, + 'webhookUrl' => $this->webhookUrl, + 'discount' => $this->discount, + ]; + } +} diff --git a/src/Http/Requests/CreateSalesInvoiceRequest.php b/src/Http/Requests/CreateSalesInvoiceRequest.php new file mode 100644 index 000000000..181687709 --- /dev/null +++ b/src/Http/Requests/CreateSalesInvoiceRequest.php @@ -0,0 +1,34 @@ +payload = $payload; + } + + public function resolveResourcePath(): string + { + return 'sales-invoices'; + } + + public function defaultPayload(): array + { + return $this->payload->toArray(); + } +} diff --git a/src/Http/Requests/DeleteSalesInvoiceRequest.php b/src/Http/Requests/DeleteSalesInvoiceRequest.php new file mode 100644 index 000000000..c1d56cf21 --- /dev/null +++ b/src/Http/Requests/DeleteSalesInvoiceRequest.php @@ -0,0 +1,23 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "sales-invoices/{$this->id}"; + } +} diff --git a/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php b/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php new file mode 100644 index 000000000..d88095a95 --- /dev/null +++ b/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php @@ -0,0 +1,20 @@ +id = $id; + } + + public function resolveResourcePath(): string + { + return "sales-invoices/{$this->id}"; + } +} diff --git a/src/Http/Requests/UpdateSalesInvoiceRequest.php b/src/Http/Requests/UpdateSalesInvoiceRequest.php new file mode 100644 index 000000000..1584378dc --- /dev/null +++ b/src/Http/Requests/UpdateSalesInvoiceRequest.php @@ -0,0 +1,36 @@ +id = $id; + $this->payload = $payload; + } + + public function resolveResourcePath(): string + { + return "sales-invoices/{$this->id}"; + } + + public function defaultPayload(): array + { + return $this->payload->toArray(); + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 02747e766..77935bc67 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -42,6 +42,7 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; +use Mollie\Api\EndpointCollection\SalesInvoiceEndpointCollection; use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; @@ -84,15 +85,16 @@ * @property ProfileEndpointCollection $profiles * @property ProfileMethodEndpointCollection $profileMethods * @property RefundEndpointCollection $refunds - * @property SettlementEndpointCollection $settlements + * @property SalesInvoiceEndpointCollection $salesInvoices + * @property SessionEndpointCollection $sessions * @property SettlementCaptureEndpointCollection $settlementCaptures * @property SettlementChargebackEndpointCollection $settlementChargebacks + * @property SettlementEndpointCollection $settlements * @property SettlementPaymentEndpointCollection $settlementPayments * @property SettlementRefundEndpointCollection $settlementRefunds * @property SubscriptionEndpointCollection $subscriptions * @property SubscriptionPaymentEndpointCollection $subscriptionPayments * @property TerminalEndpointCollection $terminals - * @property SessionEndpointCollection $sessions * @property WalletEndpointCollection $wallets * @property HttpAdapterContract $httpClient */ diff --git a/src/Resources/SalesInvoice.php b/src/Resources/SalesInvoice.php new file mode 100644 index 000000000..432d0cded --- /dev/null +++ b/src/Resources/SalesInvoice.php @@ -0,0 +1,167 @@ +status === SalesInvoiceStatus::DRAFT; + } + + /** + * Returns whether the sales invoice is issued. + * + * @return bool + */ + public function isIssued() + { + return $this->status === SalesInvoiceStatus::ISSUED; + } + + /** + * Returns whether the sales invoice is paid. + * + * @return bool + */ + public function isPaid() + { + return $this->status === SalesInvoiceStatus::PAID; + } +} diff --git a/src/Resources/SalesInvoiceCollection.php b/src/Resources/SalesInvoiceCollection.php new file mode 100644 index 000000000..4123f8b82 --- /dev/null +++ b/src/Resources/SalesInvoiceCollection.php @@ -0,0 +1,16 @@ + ProfileEndpointCollection::class, 'profileMethods' => ProfileMethodEndpointCollection::class, 'refunds' => RefundEndpointCollection::class, + 'salesInvoices' => SalesInvoiceEndpointCollection::class, 'sessions' => SessionEndpointCollection::class, 'settlementCaptures' => SettlementCaptureEndpointCollection::class, 'settlementChargebacks' => SettlementChargebackEndpointCollection::class, diff --git a/src/Types/PaymentTerm.php b/src/Types/PaymentTerm.php new file mode 100644 index 000000000..9b9e43728 --- /dev/null +++ b/src/Types/PaymentTerm.php @@ -0,0 +1,14 @@ + new MockResponse(200, 'sales-invoice'), + ]); + + $salesInvoice = $client->salesInvoices->get('inv_123'); + + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); + } + + /** @test */ + public function create() + { + $client = new MockClient([ + CreateSalesInvoiceRequest::class => new MockResponse(201, 'sales-invoice'), + ]); + + $invoiceLines = [ + new InvoiceLine( + 'Monthly subscription fee', + 1, + '21', + new Money('EUR', '10,00'), + ) + ]; + + // Create a sales invoice + $payload = new CreateSalesInvoicePayload( + 'EUR', + SalesInvoiceStatus::DRAFT, + VatScheme::STANDARD, + VatMode::INCLUSIVE, + PaymentTerm::DAYS_30, + 'XXXXX', + new Recipient( + RecipientType::CONSUMER, + 'darth@vader.deathstar', + 'Sample Street 12b', + '2000 AA', + 'Amsterdam', + 'NL', + 'nl_NL' + ), + new DataCollection($invoiceLines) + ); + + $salesInvoice = $client->salesInvoices->create($payload); + + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); + } + + /** @test */ + public function update() + { + $client = new MockClient([ + UpdateSalesInvoiceRequest::class => new MockResponse(200, 'sales-invoice'), + ]); + + $payload = new UpdateSalesInvoicePayload( + SalesInvoiceStatus::PAID, + 'XXXXX', + ); + $salesInvoice = $client->salesInvoices->update('invoice_123', $payload); + + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); + } + + /** @test */ + public function delete() + { + $client = new MockClient([ + DeleteSalesInvoiceRequest::class => new MockResponse(204), + ]); + + $client->salesInvoices->delete('invoice_123'); + + $this->assertTrue(true); // Test passes if no exception is thrown + } + + /** @test */ + public function page() + { + $client = new MockClient([ + GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), + ]); + + $salesInvoices = $client->salesInvoices->page(); + + $this->assertInstanceOf(SalesInvoiceCollection::class, $salesInvoices); + } + + /** @test */ + public function iterate() + { + $client = new MockClient([ + GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), + DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'sales_invoices'), + ]); + + /** @var SalesInvoice $salesInvoice */ + foreach ($client->salesInvoices->iterator() as $salesInvoice) { + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); + } + } +} diff --git a/tests/Fixtures/Responses/sales-invoice-list.json b/tests/Fixtures/Responses/sales-invoice-list.json new file mode 100644 index 000000000..fdd397d29 --- /dev/null +++ b/tests/Fixtures/Responses/sales-invoice-list.json @@ -0,0 +1,83 @@ +{ + "count": 1, + "_embedded": { + "sales_invoices": [ + { + "resource": "sales-invoice", + "id": "invoice_4Y0eZitmBnQ6IDoMqZQKh", + "profileId": "pfl_QkEhN94Ba", + "invoiceNumber": null, + "currency": "EUR", + "status": "draft", + "vatScheme": "standard", + "paymentTerm": "30 days", + "recipientIdentifier": "123532354", + "recipient": { + "title": null, + "givenName": "Given", + "familyName": "Family", + "email": "given.family@mollie.com", + "phone": null, + "streetAndNumber": "Street 1", + "streetAdditional": null, + "postalCode": "1000 AA", + "city": "Amsterdam", + "region": null, + "country": "NL" + }, + "lines": [ + { + "description": "LEGO 4440 Forest Police Station", + "quantity": 1, + "vatRate": "21", + "unitPrice": { + "value": "89.00", + "currency": "EUR" + }, + "discount": null + } + ], + "discount": null, + "amountDue": { + "value": "107.69", + "currency": "EUR" + }, + "subtotalAmount": { + "value": "89.00", + "currency": "EUR" + }, + "totalAmount": { + "value": "107.69", + "currency": "EUR" + }, + "totalVatAmount": { + "value": "18.69", + "currency": "EUR" + }, + "discountedSubtotalAmount": { + "value": "89.00", + "currency": "EUR" + }, + "createdAt": "2024-10-03T10:47:38.457381+00:00", + "issuedAt": null, + "dueAt": null, + "memo": null + } + ] + }, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "previous": null, + "next": { + "href": "https://api.mollie.com/v2/sales/invoices?from=invoice_4yUfQpbKnd2DUTouUdUwH&limit=5", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Fixtures/Responses/sales-invoice.json b/tests/Fixtures/Responses/sales-invoice.json new file mode 100644 index 000000000..bda9bba00 --- /dev/null +++ b/tests/Fixtures/Responses/sales-invoice.json @@ -0,0 +1,81 @@ +{ + "resource": "sales-invoice", + "id": "invoice_4Y0eZitmBnQ6IDoMqZQKh", + "profileId": "pfl_QkEhN94Ba", + "invoiceNumber": null, + "currency": "EUR", + "status": "draft", + "vatScheme": "standard", + "paymentTerm": "30 days", + "recipientIdentifier": "123532354", + "recipient": { + "type": "consumer", + "title": null, + "givenName": "Given", + "familyName": "Family", + "email": "given.family@mollie.com", + "phone": null, + "streetAndNumber": "Street 1", + "streetAdditional": null, + "postalCode": "1000 AA", + "city": "Amsterdam", + "region": null, + "country": "NL", + "locale": "nl_NL" + }, + "lines": [ + { + "description": "LEGO 4440 Forest Police Station", + "quantity": 1, + "vatRate": "21", + "unitPrice": { + "value": "89.00", + "currency": "EUR" + }, + "discount": null + } + ], + "discount": null, + "amountDue": { + "value": "107.69", + "currency": "EUR" + }, + "subtotalAmount": { + "value": "89.00", + "currency": "EUR" + }, + "totalAmount": { + "value": "107.69", + "currency": "EUR" + }, + "totalVatAmount": { + "value": "18.69", + "currency": "EUR" + }, + "discountedSubtotalAmount": { + "value": "89.00", + "currency": "EUR" + }, + "createdAt": "2024-10-03T10:47:38.457381+00:00", + "issuedAt": null, + "dueAt": null, + "memo": null, + "_links": { + "self": { + "href": "...", + "type": "application/hal+json" + }, + "invoicePayment": { + "href": "...", + "type": "application/hal+json" + }, + "pdfLink": { + "href": "...", + "type": "application/hal+json" + }, + "documentation": { + "href": "...", + "type": "text/html" + } + } +} diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php new file mode 100644 index 000000000..60f71ef56 --- /dev/null +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -0,0 +1,98 @@ + new MockResponse(201, 'sales-invoice'), + ]); + + $invoiceLines = [ + new InvoiceLine( + 'Monthly subscription fee', + 1, + '21', + new Money('EUR', '10,00'), + ) + ]; + + // Create a sales invoice + $payload = new CreateSalesInvoicePayload( + 'EUR', + SalesInvoiceStatus::DRAFT, + VatScheme::STANDARD, + VatMode::INCLUSIVE, + PaymentTerm::DAYS_30, + 'XXXXX', + new Recipient( + RecipientType::CONSUMER, + 'darth@vader.deathstar', + 'Sample Street 12b', + '2000 AA', + 'Amsterdam', + 'NL', + 'nl_NL' + ), + new DataCollection($invoiceLines) + ); + $request = new CreateSalesInvoiceRequest($payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new CreateSalesInvoiceRequest(new CreateSalesInvoicePayload( + 'EUR', + SalesInvoiceStatus::DRAFT, + VatScheme::STANDARD, + VatMode::INCLUSIVE, + PaymentTerm::DAYS_30, + 'XXXXX', + new Recipient( + RecipientType::CONSUMER, + 'darth@vader.deathstar', + 'Sample Street 12b', + '2000 AA', + 'Amsterdam', + 'NL', + 'nl_NL' + ), + new DataCollection([ + new InvoiceLine( + 'Monthly subscription fee', + 1, + '21', + new Money('EUR', '10,00'), + ) + ]) + )); + + $this->assertEquals('sales-invoices', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php new file mode 100644 index 000000000..dfa4397b6 --- /dev/null +++ b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php @@ -0,0 +1,34 @@ + new MockResponse(204), + ]); + + $request = new DeleteSalesInvoiceRequest('invoice_123'); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertEquals(204, $response->status()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new DeleteSalesInvoiceRequest('invoice_123'); + $this->assertEquals('sales-invoices/invoice_123', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php new file mode 100644 index 000000000..399741e94 --- /dev/null +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -0,0 +1,69 @@ + new MockResponse(200, 'sales-invoice-list'), + ]); + + $request = new GetPaginatedSalesInvoicesRequest; + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + + /** @var SalesInvoiceCollection */ + $salesInvoices = $response->toResource(); + $this->assertInstanceOf(SalesInvoiceCollection::class, $salesInvoices); + $this->assertGreaterThan(0, $salesInvoices->count()); + } + + /** @test */ + public function it_can_iterate_over_sales_invoices() + { + $client = new MockClient([ + GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), + DynamicGetRequest::class => new SequenceMockResponse( + new MockResponse(200, 'sales-invoice-list'), + new MockResponse(200, 'empty-list', 'sales_invoices'), + ), + ]); + + $request = (new GetPaginatedSalesInvoicesRequest)->useIterator(); + + /** @var Response */ + $response = $client->send($request); + $this->assertTrue($response->successful()); + + /** @var LazyCollection */ + $salesInvoices = $response->toResource(); + + foreach ($salesInvoices as $salesInvoice) { + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); + } + + $client->assertSentCount(3); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new GetPaginatedSalesInvoicesRequest; + $this->assertEquals('sales-invoices', $request->resolveResourcePath()); + } +} diff --git a/tests/Http/Requests/GetSalesInvoiceRequestTest.php b/tests/Http/Requests/GetSalesInvoiceRequestTest.php new file mode 100644 index 000000000..b38fc6553 --- /dev/null +++ b/tests/Http/Requests/GetSalesInvoiceRequestTest.php @@ -0,0 +1,26 @@ + new MockResponse(200, 'sales-invoice'), + ]); + + $request = new GetSalesInvoiceRequest('invoice_123'); + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + } +} diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php new file mode 100644 index 000000000..a58b65aea --- /dev/null +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -0,0 +1,44 @@ + new MockResponse(200, 'sales-invoice'), + ]); + + $payload = new UpdateSalesInvoicePayload( + SalesInvoiceStatus::PAID, + 'XXXXX', + ); + $request = new UpdateSalesInvoiceRequest('invoice_123', $payload); + + /** @var Response */ + $response = $client->send($request); + + $this->assertTrue($response->successful()); + $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + } + + /** @test */ + public function it_resolves_correct_resource_path() + { + $request = new UpdateSalesInvoiceRequest('invoice_123', new UpdateSalesInvoicePayload( + SalesInvoiceStatus::PAID, + 'XXXXX', + )); + $this->assertEquals('sales-invoices/invoice_123', $request->resolveResourcePath()); + } +} From 3f1c1fa925232899331e58547ff68aefc7930175 Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 10 Dec 2024 12:50:52 +0000 Subject: [PATCH 101/131] Fixes coding style --- .../SalesInvoiceEndpointCollection.php | 2 +- .../CreateSalesInvoicePayloadFactory.php | 14 ++++++-------- src/Factories/InvoiceLineCollectionFactory.php | 2 +- src/Factories/InvoiceLineFactory.php | 2 +- .../UpdateSalesInvoicePayloadFactory.php | 18 ++++++++---------- src/Http/Payload/EmailDetails.php | 1 + .../Requests/CreateSalesInvoiceRequest.php | 1 + .../Requests/UpdateSalesInvoiceRequest.php | 2 ++ src/MollieApiClient.php | 2 +- src/Resources/SalesInvoice.php | 1 + src/Traits/HasEndpoints.php | 2 +- src/Types/PaymentTerm.php | 6 ++++++ src/Types/RecipientType.php | 1 + src/Types/VatMode.php | 1 + src/Types/VatScheme.php | 1 + .../SalesInvoiceEndpointCollectionTest.php | 2 +- .../Requests/CreateSalesInvoiceRequestTest.php | 4 ++-- 17 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/EndpointCollection/SalesInvoiceEndpointCollection.php b/src/EndpointCollection/SalesInvoiceEndpointCollection.php index c1b28f78d..5d5ed5b0e 100644 --- a/src/EndpointCollection/SalesInvoiceEndpointCollection.php +++ b/src/EndpointCollection/SalesInvoiceEndpointCollection.php @@ -32,7 +32,7 @@ public function get(string $id): SalesInvoice /** * Creates a SalesInvoice in Mollie. * - * @param array|CreateSalesInvoicePayload $payload + * @param array|CreateSalesInvoicePayload $payload * * @throws ApiException */ diff --git a/src/Factories/CreateSalesInvoicePayloadFactory.php b/src/Factories/CreateSalesInvoicePayloadFactory.php index de6200a65..cfb2d67d4 100644 --- a/src/Factories/CreateSalesInvoicePayloadFactory.php +++ b/src/Factories/CreateSalesInvoicePayloadFactory.php @@ -3,16 +3,14 @@ namespace Mollie\Api\Factories; use Mollie\Api\Http\Payload\CreateSalesInvoicePayload; -use Mollie\Api\Http\Payload\PaymentDetails; -use Mollie\Api\Http\Payload\EmailDetails; use Mollie\Api\Http\Payload\Discount; +use Mollie\Api\Http\Payload\EmailDetails; +use Mollie\Api\Http\Payload\PaymentDetails; class CreateSalesInvoicePayloadFactory extends Factory { /** * Create a new CreateSalesInvoicePayload instance. - * - * @return CreateSalesInvoicePayload */ public function create(): CreateSalesInvoicePayload { @@ -27,14 +25,14 @@ public function create(): CreateSalesInvoicePayload $this ->mapIfNotNull( 'lines', - fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('profileId'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/InvoiceLineCollectionFactory.php b/src/Factories/InvoiceLineCollectionFactory.php index d90f10f33..e457ebef9 100644 --- a/src/Factories/InvoiceLineCollectionFactory.php +++ b/src/Factories/InvoiceLineCollectionFactory.php @@ -9,7 +9,7 @@ class InvoiceLineCollectionFactory extends Factory public function create(): DataCollection { return new DataCollection(array_map( - fn(array $item) => InvoiceLineFactory::new($item)->create(), + fn (array $item) => InvoiceLineFactory::new($item)->create(), $this->data )); } diff --git a/src/Factories/InvoiceLineFactory.php b/src/Factories/InvoiceLineFactory.php index bd9297922..bb5a2c2b7 100644 --- a/src/Factories/InvoiceLineFactory.php +++ b/src/Factories/InvoiceLineFactory.php @@ -14,7 +14,7 @@ public function create(): InvoiceLine $this->get('quantity'), $this->get('vatRate'), MoneyFactory::new($this->get('unitPrice'))->create(), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/UpdateSalesInvoicePayloadFactory.php b/src/Factories/UpdateSalesInvoicePayloadFactory.php index 005780d25..e0f323c2c 100644 --- a/src/Factories/UpdateSalesInvoicePayloadFactory.php +++ b/src/Factories/UpdateSalesInvoicePayloadFactory.php @@ -2,17 +2,15 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; -use Mollie\Api\Http\Payload\PaymentDetails; -use Mollie\Api\Http\Payload\EmailDetails; use Mollie\Api\Http\Payload\Discount; +use Mollie\Api\Http\Payload\EmailDetails; +use Mollie\Api\Http\Payload\PaymentDetails; +use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; class UpdateSalesInvoicePayloadFactory extends Factory { /** * Create a new UpdateSalesInvoicePayload instance. - * - * @return UpdateSalesInvoicePayload */ public function create(): UpdateSalesInvoicePayload { @@ -21,16 +19,16 @@ public function create(): UpdateSalesInvoicePayload $this->get('recipientIdentifier'), $this->get('paymentTerm'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), - $this->mapIfNotNull('recipient', fn(array $data) => RecipientFactory::new($data)->create()), + $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('recipient', fn (array $data) => RecipientFactory::new($data)->create()), $this ->mapIfNotNull( 'lines', - fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Http/Payload/EmailDetails.php b/src/Http/Payload/EmailDetails.php index be78009d0..48bb178a5 100644 --- a/src/Http/Payload/EmailDetails.php +++ b/src/Http/Payload/EmailDetails.php @@ -8,6 +8,7 @@ class EmailDetails implements DataProvider { use ComposableFromArray; + public string $subject; public string $body; diff --git a/src/Http/Requests/CreateSalesInvoiceRequest.php b/src/Http/Requests/CreateSalesInvoiceRequest.php index 181687709..0bf03545b 100644 --- a/src/Http/Requests/CreateSalesInvoiceRequest.php +++ b/src/Http/Requests/CreateSalesInvoiceRequest.php @@ -13,6 +13,7 @@ class CreateSalesInvoiceRequest extends ResourceHydratableRequest implements Has use HasJsonPayload; protected static string $method = Method::POST; + public static string $targetResourceClass = SalesInvoice::class; private CreateSalesInvoicePayload $payload; diff --git a/src/Http/Requests/UpdateSalesInvoiceRequest.php b/src/Http/Requests/UpdateSalesInvoiceRequest.php index 1584378dc..421eb1985 100644 --- a/src/Http/Requests/UpdateSalesInvoiceRequest.php +++ b/src/Http/Requests/UpdateSalesInvoiceRequest.php @@ -13,9 +13,11 @@ class UpdateSalesInvoiceRequest extends ResourceHydratableRequest implements Has use HasJsonPayload; protected static string $method = Method::PATCH; + public static string $targetResourceClass = SalesInvoice::class; private string $id; + private UpdateSalesInvoicePayload $payload; public function __construct(string $id, UpdateSalesInvoicePayload $payload) diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 77935bc67..7ffb52afe 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -32,6 +32,7 @@ use Mollie\Api\EndpointCollection\ProfileEndpointCollection; use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SalesInvoiceEndpointCollection; use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; @@ -42,7 +43,6 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\EndpointCollection\SalesInvoiceEndpointCollection; use Mollie\Api\Helpers\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; diff --git a/src/Resources/SalesInvoice.php b/src/Resources/SalesInvoice.php index 432d0cded..58b489176 100644 --- a/src/Resources/SalesInvoice.php +++ b/src/Resources/SalesInvoice.php @@ -60,6 +60,7 @@ class SalesInvoice extends BaseResource * @var object */ public $paymentDetails; + /** * @var object */ diff --git a/src/Traits/HasEndpoints.php b/src/Traits/HasEndpoints.php index 22d339a0d..a6de71cfe 100644 --- a/src/Traits/HasEndpoints.php +++ b/src/Traits/HasEndpoints.php @@ -28,6 +28,7 @@ use Mollie\Api\EndpointCollection\ProfileEndpointCollection; use Mollie\Api\EndpointCollection\ProfileMethodEndpointCollection; use Mollie\Api\EndpointCollection\RefundEndpointCollection; +use Mollie\Api\EndpointCollection\SalesInvoiceEndpointCollection; use Mollie\Api\EndpointCollection\SessionEndpointCollection; use Mollie\Api\EndpointCollection\SettlementCaptureEndpointCollection; use Mollie\Api\EndpointCollection\SettlementChargebackEndpointCollection; @@ -38,7 +39,6 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\EndpointCollection\SalesInvoiceEndpointCollection; use Mollie\Api\MollieApiClient; /** diff --git a/src/Types/PaymentTerm.php b/src/Types/PaymentTerm.php index 9b9e43728..7691a2e0b 100644 --- a/src/Types/PaymentTerm.php +++ b/src/Types/PaymentTerm.php @@ -5,10 +5,16 @@ class PaymentTerm { const DAYS_7 = '7 days'; + const DAYS_14 = '14 days'; + const DAYS_30 = '30 days'; + const DAYS_45 = '45 days'; + const DAYS_60 = '60 days'; + const DAYS_90 = '90 days'; + const DAYS_120 = '120 days'; } diff --git a/src/Types/RecipientType.php b/src/Types/RecipientType.php index c6befc024..e40f617f3 100644 --- a/src/Types/RecipientType.php +++ b/src/Types/RecipientType.php @@ -5,5 +5,6 @@ class RecipientType { const CONSUMER = 'consumer'; + const BUSINESS = 'business'; } diff --git a/src/Types/VatMode.php b/src/Types/VatMode.php index 4178502bb..da566ecaf 100644 --- a/src/Types/VatMode.php +++ b/src/Types/VatMode.php @@ -5,5 +5,6 @@ class VatMode { const EXCLUSIVE = 'exclusive'; + const INCLUSIVE = 'inclusive'; } diff --git a/src/Types/VatScheme.php b/src/Types/VatScheme.php index f331c17b9..d51cd3e46 100644 --- a/src/Types/VatScheme.php +++ b/src/Types/VatScheme.php @@ -5,5 +5,6 @@ class VatScheme { const STANDARD = 'standard'; + const ONE_STOP_SHOP = 'one-stop-shop'; } diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index 8886e132e..3c9b93126 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -52,7 +52,7 @@ public function create() 1, '21', new Money('EUR', '10,00'), - ) + ), ]; // Create a sales invoice diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index 60f71ef56..f8edc7a4c 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -33,7 +33,7 @@ public function it_creates_sales_invoice() 1, '21', new Money('EUR', '10,00'), - ) + ), ]; // Create a sales invoice @@ -89,7 +89,7 @@ public function it_resolves_correct_resource_path() 1, '21', new Money('EUR', '10,00'), - ) + ), ]) )); From fcdbbb0f54d0a22d393263ef82e27f1e9cf6d8af Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 13:51:55 +0100 Subject: [PATCH 102/131] fix phpstan --- src/Http/Payload/CreateSalesInvoicePayload.php | 2 +- src/Http/Payload/Discount.php | 2 +- src/Http/Payload/EmailDetails.php | 2 +- src/Http/Payload/InvoiceLine.php | 2 +- src/Http/Payload/PaymentDetails.php | 2 +- src/Http/Payload/Recipient.php | 2 +- src/Http/Payload/UpdateSalesInvoicePayload.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Http/Payload/CreateSalesInvoicePayload.php b/src/Http/Payload/CreateSalesInvoicePayload.php index 4ff3b3084..362ebb910 100644 --- a/src/Http/Payload/CreateSalesInvoicePayload.php +++ b/src/Http/Payload/CreateSalesInvoicePayload.php @@ -53,7 +53,7 @@ public function __construct( ?PaymentDetails $paymentDetails = null, ?EmailDetails $emailDetails = null, ?string $webhookUrl = null, - ?Discount $discount = null, + ?Discount $discount = null ) { $this->profileId = $profileId; $this->currency = $currency; diff --git a/src/Http/Payload/Discount.php b/src/Http/Payload/Discount.php index 3207fe1e9..ed0e17972 100644 --- a/src/Http/Payload/Discount.php +++ b/src/Http/Payload/Discount.php @@ -15,7 +15,7 @@ class Discount implements DataProvider public function __construct( string $type, - string $value, + string $value ) { $this->type = $type; $this->value = $value; diff --git a/src/Http/Payload/EmailDetails.php b/src/Http/Payload/EmailDetails.php index 48bb178a5..6d30e6e40 100644 --- a/src/Http/Payload/EmailDetails.php +++ b/src/Http/Payload/EmailDetails.php @@ -15,7 +15,7 @@ class EmailDetails implements DataProvider public function __construct( string $subject, - string $body, + string $body ) { $this->subject = $subject; $this->body = $body; diff --git a/src/Http/Payload/InvoiceLine.php b/src/Http/Payload/InvoiceLine.php index ced72bd6b..160c37f93 100644 --- a/src/Http/Payload/InvoiceLine.php +++ b/src/Http/Payload/InvoiceLine.php @@ -19,7 +19,7 @@ public function __construct( int $quantity, string $vatRate, Money $unitPrice, - ?Discount $discount = null, + ?Discount $discount = null ) { $this->description = $description; $this->quantity = $quantity; diff --git a/src/Http/Payload/PaymentDetails.php b/src/Http/Payload/PaymentDetails.php index ad224023a..c2e4fa9ca 100644 --- a/src/Http/Payload/PaymentDetails.php +++ b/src/Http/Payload/PaymentDetails.php @@ -15,7 +15,7 @@ class PaymentDetails implements DataProvider public function __construct( string $source, - ?string $sourceDescription = null, + ?string $sourceDescription = null ) { $this->source = $source; $this->sourceDescription = $sourceDescription; diff --git a/src/Http/Payload/Recipient.php b/src/Http/Payload/Recipient.php index bff225947..151a9ea85 100644 --- a/src/Http/Payload/Recipient.php +++ b/src/Http/Payload/Recipient.php @@ -54,7 +54,7 @@ public function __construct( ?string $vatNumber = null, ?string $phone = null, ?string $streetAdditional = null, - ?string $region = null, + ?string $region = null ) { $this->type = $type; $this->title = $title; diff --git a/src/Http/Payload/UpdateSalesInvoicePayload.php b/src/Http/Payload/UpdateSalesInvoicePayload.php index 634a25f0d..56634fc26 100644 --- a/src/Http/Payload/UpdateSalesInvoicePayload.php +++ b/src/Http/Payload/UpdateSalesInvoicePayload.php @@ -37,7 +37,7 @@ public function __construct( ?Recipient $recipient = null, ?DataCollection $lines = null, ?string $webhookUrl = null, - ?Discount $discount = null, + ?Discount $discount = null ) { $this->status = $status; $this->paymentTerm = $paymentTerm; From be3dbe7d17bf67b3ac7a224f58dd372ca9a139a8 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:00:14 +0100 Subject: [PATCH 103/131] wip --- src/Endpoints/SalesInvoiceEndpoint.php | 123 +++++++++++++++++ src/MollieApiClient.php | 9 ++ src/Resources/SalesInvoice.php | 167 +++++++++++++++++++++++ src/Resources/SalesInvoiceCollection.php | 22 +++ src/Types/SalesInvoiceStatus.php | 21 +++ 5 files changed, 342 insertions(+) create mode 100644 src/Endpoints/SalesInvoiceEndpoint.php create mode 100644 src/Resources/SalesInvoice.php create mode 100644 src/Resources/SalesInvoiceCollection.php create mode 100644 src/Types/SalesInvoiceStatus.php diff --git a/src/Endpoints/SalesInvoiceEndpoint.php b/src/Endpoints/SalesInvoiceEndpoint.php new file mode 100644 index 000000000..9be1aded1 --- /dev/null +++ b/src/Endpoints/SalesInvoiceEndpoint.php @@ -0,0 +1,123 @@ +client); + } + + /** + * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. + * + * @param int $count + * @param \stdClass $_links + * + * @return SalesInvoiceCollection + */ + protected function getResourceCollectionObject($count, $_links): SalesInvoiceCollection + { + return new SalesInvoiceCollection($this->client, $count, $_links); + } + + /** + * Creates a payment in Mollie. + * + * @param array $data An array containing details on the payment. + * @param array $filters + * + * @return SalesInvoice + * @throws ApiException + */ + public function create(array $data = []): SalesInvoice + { + return $this->rest_create($data, []); + } + + /** + * Update the given Payment. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * + * @param string $salesInvoiceId + * + * @param array $data + * @return SalesInvoice + * @throws ApiException + */ + public function update($salesInvoiceId, array $data = []): SalesInvoice + { + if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) { + throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + } + + return parent::rest_update($salesInvoiceId, $data); + } + + /** + * @param string $salesInvoiceId + * @param array $parameters + * @return SalesInvoice + * @throws ApiException + */ + public function get($salesInvoiceId, array $parameters = []): SalesInvoice + { + if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) { + throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + } + + return parent::rest_read($salesInvoiceId, $parameters); + } + + /** + * @param string $salesInvoiceId + * + * @param array $data + * @throws ApiException + */ + public function delete($salesInvoiceId, array $data = []): void + { + $this->rest_delete($salesInvoiceId, $data); + } + + /** + * @param string $from The first payment ID you want to include in your list. + * @param int $limit + * + * @return SalesInvoiceCollection + * @throws ApiException + */ + public function page($from = null, $limit = null) + { + return $this->rest_list($from, $limit, []); + } + + /** + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return LazyCollection + */ + public function iterator(?string $from = null, ?int $limit = null, bool $iterateBackwards = false): LazyCollection + { + return $this->rest_iterator($from, $limit, [], $iterateBackwards); + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 6ae63f254..04b02d745 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -32,6 +32,7 @@ use Mollie\Api\Endpoints\ProfileEndpoint; use Mollie\Api\Endpoints\ProfileMethodEndpoint; use Mollie\Api\Endpoints\RefundEndpoint; +use Mollie\Api\Endpoints\SalesInvoiceEndpoint; use Mollie\Api\Endpoints\SessionEndpoint; use Mollie\Api\Endpoints\SettlementCaptureEndpoint; use Mollie\Api\Endpoints\SettlementChargebackEndpoint; @@ -122,6 +123,13 @@ class MollieApiClient */ public $customerPayments; + /** + * RESTful Sales Invoice resource. + * + * @var SalesInvoiceEndpoint + */ + public $salesInvoices; + /** * RESTful Settlement resource. * @@ -444,6 +452,7 @@ public function initializeEndpoints() $this->profileMethods = new ProfileMethodEndpoint($this); $this->profiles = new ProfileEndpoint($this); $this->refunds = new RefundEndpoint($this); + $this->salesInvoices = new SalesInvoiceEndpoint($this); $this->settlementCaptures = new SettlementCaptureEndpoint($this); $this->settlementChargebacks = new SettlementChargebackEndpoint($this); $this->settlementPayments = new SettlementPaymentEndpoint($this); diff --git a/src/Resources/SalesInvoice.php b/src/Resources/SalesInvoice.php new file mode 100644 index 000000000..432d0cded --- /dev/null +++ b/src/Resources/SalesInvoice.php @@ -0,0 +1,167 @@ +status === SalesInvoiceStatus::DRAFT; + } + + /** + * Returns whether the sales invoice is issued. + * + * @return bool + */ + public function isIssued() + { + return $this->status === SalesInvoiceStatus::ISSUED; + } + + /** + * Returns whether the sales invoice is paid. + * + * @return bool + */ + public function isPaid() + { + return $this->status === SalesInvoiceStatus::PAID; + } +} diff --git a/src/Resources/SalesInvoiceCollection.php b/src/Resources/SalesInvoiceCollection.php new file mode 100644 index 000000000..6a76b9953 --- /dev/null +++ b/src/Resources/SalesInvoiceCollection.php @@ -0,0 +1,22 @@ +client); + } +} diff --git a/src/Types/SalesInvoiceStatus.php b/src/Types/SalesInvoiceStatus.php new file mode 100644 index 000000000..02dc13694 --- /dev/null +++ b/src/Types/SalesInvoiceStatus.php @@ -0,0 +1,21 @@ + Date: Tue, 10 Dec 2024 14:08:24 +0100 Subject: [PATCH 104/131] wip --- .../sales-invoices/create-sales-invoice.php | 51 +++++++++++++++++++ .../sales-invoices/delete-sales-invoice.php | 25 +++++++++ .../sales-invoices/list-sales-invoices.php | 28 ++++++++++ .../sales-invoices/update-sales-invoice.php | 40 +++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 examples/sales-invoices/create-sales-invoice.php create mode 100644 examples/sales-invoices/delete-sales-invoice.php create mode 100644 examples/sales-invoices/list-sales-invoices.php create mode 100644 examples/sales-invoices/update-sales-invoice.php diff --git a/examples/sales-invoices/create-sales-invoice.php b/examples/sales-invoices/create-sales-invoice.php new file mode 100644 index 000000000..ffdc52159 --- /dev/null +++ b/examples/sales-invoices/create-sales-invoice.php @@ -0,0 +1,51 @@ +salesInvoices->create([ + 'currency' => 'EUR', + 'status' => SalesInvoiceStatus::DRAFT, + 'vatScheme' => 'standard', + 'vatMode' => 'inclusive', + 'paymentTerm' => PaymentTerm::DAYS_30, + 'recipientIdentifier' => 'XXXXX', + 'recipient' => [ + 'type' => 'consumer', + 'email' => 'darth@vader.deathstar', + 'streetAndNumber' => 'Sample Street 12b', + 'postalCode' => '2000 AA', + 'city' => 'Amsterdam', + 'country' => 'NL', + 'locale' => 'nl_NL' + ], + 'lines' => [ + [ + 'description' => 'Monthly subscription fee', + 'quantity' => 1, + 'vatRate' => '21', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00' // Corrected the format from '10,00' to '10.00' to match typical API expectations + ] + ] + ] + ]); + + echo "

          New sales invoice created with ID: " . htmlspecialchars($salesInvoice->id) . "

          "; +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/examples/sales-invoices/delete-sales-invoice.php b/examples/sales-invoices/delete-sales-invoice.php new file mode 100644 index 000000000..3b154b802 --- /dev/null +++ b/examples/sales-invoices/delete-sales-invoice.php @@ -0,0 +1,25 @@ +salesInvoices->delete($invoiceId); + + echo "

          Sales invoice deleted with ID: " . htmlspecialchars($invoiceId) . "

          "; +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/examples/sales-invoices/list-sales-invoices.php b/examples/sales-invoices/list-sales-invoices.php new file mode 100644 index 000000000..49d6d3611 --- /dev/null +++ b/examples/sales-invoices/list-sales-invoices.php @@ -0,0 +1,28 @@ +'; + $salesInvoices = $mollie->salesInvoices->page(); + foreach ($salesInvoices as $invoice) { + echo '
        • Invoice ' . htmlspecialchars($invoice->id) . ': (' . htmlspecialchars($invoice->issuedAt) . ')'; + echo '
          Status: ' . htmlspecialchars($invoice->status) . ''; + echo '
          Total Amount: ' . htmlspecialchars($invoice->amount->currency) . ' ' . htmlspecialchars($invoice->amount->value) . ''; + echo '
        • '; + } + echo '
        '; +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/examples/sales-invoices/update-sales-invoice.php b/examples/sales-invoices/update-sales-invoice.php new file mode 100644 index 000000000..2442be423 --- /dev/null +++ b/examples/sales-invoices/update-sales-invoice.php @@ -0,0 +1,40 @@ +salesInvoices->update($invoiceId, [ + 'status' => \Mollie\Api\Types\SalesInvoiceStatus::PAID, + 'recipientIdentifier' => 'XXXXX', + 'lines' => [ + [ + 'id' => 'line_001', + 'description' => 'Updated subscription fee', + 'quantity' => 2, + 'vatRate' => '21', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '15.00' + ] + ] + ] + ]); + + echo "

        Sales invoice updated with ID: " . htmlspecialchars($updatedInvoice->id) . "

        "; +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} From 34f2335fb6a9adcde6b26983b39025d78395d417 Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 10 Dec 2024 13:08:45 +0000 Subject: [PATCH 105/131] Fix styling --- examples/sales-invoices/create-sales-invoice.php | 10 +++++----- examples/sales-invoices/update-sales-invoice.php | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/sales-invoices/create-sales-invoice.php b/examples/sales-invoices/create-sales-invoice.php index ffdc52159..69f93a84a 100644 --- a/examples/sales-invoices/create-sales-invoice.php +++ b/examples/sales-invoices/create-sales-invoice.php @@ -30,7 +30,7 @@ 'postalCode' => '2000 AA', 'city' => 'Amsterdam', 'country' => 'NL', - 'locale' => 'nl_NL' + 'locale' => 'nl_NL', ], 'lines' => [ [ @@ -39,10 +39,10 @@ 'vatRate' => '21', 'unitPrice' => [ 'currency' => 'EUR', - 'value' => '10.00' // Corrected the format from '10,00' to '10.00' to match typical API expectations - ] - ] - ] + 'value' => '10.00', // Corrected the format from '10,00' to '10.00' to match typical API expectations + ], + ], + ], ]); echo "

        New sales invoice created with ID: " . htmlspecialchars($salesInvoice->id) . "

        "; diff --git a/examples/sales-invoices/update-sales-invoice.php b/examples/sales-invoices/update-sales-invoice.php index 2442be423..08c6e671b 100644 --- a/examples/sales-invoices/update-sales-invoice.php +++ b/examples/sales-invoices/update-sales-invoice.php @@ -28,10 +28,10 @@ 'vatRate' => '21', 'unitPrice' => [ 'currency' => 'EUR', - 'value' => '15.00' - ] - ] - ] + 'value' => '15.00', + ], + ], + ], ]); echo "

        Sales invoice updated with ID: " . htmlspecialchars($updatedInvoice->id) . "

        "; From 6915f0d440b53ebf5ddf5f69dc23201dc59f7234 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:10:13 +0100 Subject: [PATCH 106/131] fix phpstan --- phpstan-baseline.neon | 25 +++++++++++++++++++++++++ src/Endpoints/SalesInvoiceEndpoint.php | 1 - 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a8db7218f..67a10b8f9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -220,6 +220,31 @@ parameters: count: 1 path: examples/profiles/update-profile.php + - + message: "#^Access to constant DAYS_30 on an unknown class Mollie\\\\Api\\\\Types\\\\PaymentTerm\\.$#" + count: 1 + path: examples/sales-invoices/create-sales-invoice.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/sales-invoices/create-sales-invoice.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/sales-invoices/delete-sales-invoice.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/sales-invoices/list-sales-invoices.php + + - + message: "#^Variable \\$mollie might not be defined\\.$#" + count: 1 + path: examples/sales-invoices/update-sales-invoice.php + - message: "#^Variable \\$mollie might not be defined\\.$#" count: 1 diff --git a/src/Endpoints/SalesInvoiceEndpoint.php b/src/Endpoints/SalesInvoiceEndpoint.php index 9be1aded1..e0379d32d 100644 --- a/src/Endpoints/SalesInvoiceEndpoint.php +++ b/src/Endpoints/SalesInvoiceEndpoint.php @@ -41,7 +41,6 @@ protected function getResourceCollectionObject($count, $_links): SalesInvoiceCol * Creates a payment in Mollie. * * @param array $data An array containing details on the payment. - * @param array $filters * * @return SalesInvoice * @throws ApiException From 261cad3e2bf414a480d0bf870e6f5dc3361e1cdf Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:13:36 +0100 Subject: [PATCH 107/131] fix phpstan --- phpstan-baseline.neon | 6 ++++++ tests/Http/Requests/CreateSalesInvoiceRequestTest.php | 1 + tests/Http/Requests/DeleteSalesInvoiceRequestTest.php | 1 + .../Http/Requests/GetPaginatedSalesInvoicesRequestTest.php | 2 ++ tests/Http/Requests/UpdateSalesInvoiceRequestTest.php | 1 + 5 files changed, 11 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d9e527865..35e3c570b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -324,6 +324,12 @@ parameters: count: 2 path: tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType + count: 1 + path: tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php + - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' identifier: method.alreadyNarrowedType diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index f8edc7a4c..1d7312e55 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -8,6 +8,7 @@ use Mollie\Api\Http\Payload\Money; use Mollie\Api\Http\Payload\Recipient; use Mollie\Api\Http\Requests\CreateSalesInvoiceRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\PaymentTerm; use Mollie\Api\Types\RecipientType; diff --git a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php index dfa4397b6..eae213fc8 100644 --- a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php @@ -3,6 +3,7 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; +use Mollie\Api\Http\Response; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\TestCase; diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php index 399741e94..4d2dc1818 100644 --- a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -4,6 +4,8 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSalesInvoicesRequest; +use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Resources\SalesInvoiceCollection; use Tests\Fixtures\MockClient; diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index a58b65aea..22ed2c28f 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -4,6 +4,7 @@ use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; use Mollie\Api\Http\Requests\UpdateSalesInvoiceRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\SalesInvoiceStatus; use Tests\Fixtures\MockClient; From 8cddaf6c155085de893d7455380aa6dbb5047580 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:42:43 +0100 Subject: [PATCH 108/131] wip --- src/Contracts/DataProvider.php | 11 ----------- src/Factories/Factory.php | 7 ++----- src/Http/Payload/Address.php | 6 +++--- src/Http/Payload/AnyPayload.php | 2 +- src/Http/Payload/ApplicationFee.php | 2 +- src/Http/Payload/CreateClientLinkPayload.php | 2 +- src/Http/Payload/CreateCustomerPayload.php | 2 +- src/Http/Payload/CreateMandatePayload.php | 2 +- src/Http/Payload/CreatePaymentCapturePayload.php | 2 +- src/Http/Payload/CreatePaymentLinkPayload.php | 2 +- src/Http/Payload/CreatePaymentPayload.php | 2 +- src/Http/Payload/CreateProfilePayload.php | 2 +- src/Http/Payload/CreateRefundPaymentPayload.php | 2 +- src/Http/Payload/CreateSalesInvoicePayload.php | 2 +- src/Http/Payload/CreateSubscriptionPayload.php | 2 +- src/Http/Payload/DataBag.php | 8 +------- src/Http/Payload/DataCollection.php | 12 +----------- src/Http/Payload/Discount.php | 6 +++--- src/Http/Payload/EmailDetails.php | 6 +++--- src/Http/Payload/InvoiceLine.php | 2 +- src/Http/Payload/Metadata.php | 6 +++--- src/Http/Payload/Money.php | 6 +++--- src/Http/Payload/OrderLine.php | 2 +- src/Http/Payload/Owner.php | 6 +++--- src/Http/Payload/OwnerAddress.php | 6 +++--- src/Http/Payload/PaymentDetails.php | 6 +++--- src/Http/Payload/PaymentRoute.php | 2 +- src/Http/Payload/Recipient.php | 6 +++--- src/Http/Payload/RecurringBillingCycle.php | 2 +- src/Http/Payload/RefundRoute.php | 2 +- .../Payload/RequestApplePayPaymentSessionPayload.php | 2 +- src/Http/Payload/UpdatePaymentLinkPayload.php | 2 +- src/Http/Payload/UpdatePaymentPayload.php | 2 +- src/Http/Payload/UpdatePaymentRoutePayload.php | 2 +- src/Http/Payload/UpdateProfilePayload.php | 2 +- src/Http/Payload/UpdateSalesInvoicePayload.php | 2 +- src/Http/Payload/UpdateSubscriptionPayload.php | 2 +- src/Http/Requests/CreateClientLinkRequest.php | 2 +- src/Traits/ResolvesValues.php | 11 ++++++++--- tests/Traits/ResolvesValuesTest.php | 7 +++---- 40 files changed, 67 insertions(+), 93 deletions(-) delete mode 100644 src/Contracts/DataProvider.php diff --git a/src/Contracts/DataProvider.php b/src/Contracts/DataProvider.php deleted file mode 100644 index ae50396d8..000000000 --- a/src/Contracts/DataProvider.php +++ /dev/null @@ -1,11 +0,0 @@ -data = $data->toArray(); - } elseif ($data instanceof DataProvider) { - $this->data = $data->data(); } else { $this->data = $data; } @@ -40,7 +37,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey.$key; + $keys[] = $backupKey . $key; } foreach ($keys as $key) { @@ -63,7 +60,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey.$key, $key], $value); + return Arr::includes($this->data, [$backupKey . $key, $key], $value); } /** diff --git a/src/Http/Payload/Address.php b/src/Http/Payload/Address.php index 5b48cb3a1..caf389aad 100644 --- a/src/Http/Payload/Address.php +++ b/src/Http/Payload/Address.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class Address implements DataProvider +class Address implements Arrayable { use ComposableFromArray; @@ -61,7 +61,7 @@ public function __construct( $this->country = $country; } - public function data(): array + public function toArray(): array { return [ 'title' => $this->title, diff --git a/src/Http/Payload/AnyPayload.php b/src/Http/Payload/AnyPayload.php index 7fc8cb5fb..0c4babb41 100644 --- a/src/Http/Payload/AnyPayload.php +++ b/src/Http/Payload/AnyPayload.php @@ -15,7 +15,7 @@ public function __construct(?array $data = []) $this->data = $data; } - public function data(): array + public function toArray(): array { return $this->data ?? []; } diff --git a/src/Http/Payload/ApplicationFee.php b/src/Http/Payload/ApplicationFee.php index e2bf0b55a..b300c3d79 100644 --- a/src/Http/Payload/ApplicationFee.php +++ b/src/Http/Payload/ApplicationFee.php @@ -16,7 +16,7 @@ public function __construct( $this->description = $description; } - public function data(): array + public function toArray(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/CreateClientLinkPayload.php b/src/Http/Payload/CreateClientLinkPayload.php index eb47645f8..a97258264 100644 --- a/src/Http/Payload/CreateClientLinkPayload.php +++ b/src/Http/Payload/CreateClientLinkPayload.php @@ -28,7 +28,7 @@ public function __construct( $this->vatNumber = $vatNumber; } - public function data(): array + public function toArray(): array { return [ 'owner' => $this->owner, diff --git a/src/Http/Payload/CreateCustomerPayload.php b/src/Http/Payload/CreateCustomerPayload.php index 330149854..086b2c79d 100644 --- a/src/Http/Payload/CreateCustomerPayload.php +++ b/src/Http/Payload/CreateCustomerPayload.php @@ -24,7 +24,7 @@ public function __construct( $this->metadata = $metadata; } - public function data() + public function toArray(): array { return [ 'name' => $this->name, diff --git a/src/Http/Payload/CreateMandatePayload.php b/src/Http/Payload/CreateMandatePayload.php index db799c11f..b9516dee3 100644 --- a/src/Http/Payload/CreateMandatePayload.php +++ b/src/Http/Payload/CreateMandatePayload.php @@ -42,7 +42,7 @@ public function __construct( $this->paypalBillingAgreementId = $paypalBillingAgreementId; } - public function data(): array + public function toArray(): array { return [ 'method' => $this->method, diff --git a/src/Http/Payload/CreatePaymentCapturePayload.php b/src/Http/Payload/CreatePaymentCapturePayload.php index dfd5339cf..d4ee76084 100644 --- a/src/Http/Payload/CreatePaymentCapturePayload.php +++ b/src/Http/Payload/CreatePaymentCapturePayload.php @@ -20,7 +20,7 @@ public function __construct( $this->metadata = $metadata; } - public function data(): array + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/CreatePaymentLinkPayload.php b/src/Http/Payload/CreatePaymentLinkPayload.php index a66c62cf5..9d7c0cab1 100644 --- a/src/Http/Payload/CreatePaymentLinkPayload.php +++ b/src/Http/Payload/CreatePaymentLinkPayload.php @@ -38,7 +38,7 @@ public function __construct( $this->expiresAt = $expiresAt; } - public function data(): array + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/CreatePaymentPayload.php b/src/Http/Payload/CreatePaymentPayload.php index fbcd681a5..d1a857582 100644 --- a/src/Http/Payload/CreatePaymentPayload.php +++ b/src/Http/Payload/CreatePaymentPayload.php @@ -107,7 +107,7 @@ public function __construct( $this->additional = $additional; } - public function data(): array + public function toArray(): array { return array_merge([ 'description' => $this->description, diff --git a/src/Http/Payload/CreateProfilePayload.php b/src/Http/Payload/CreateProfilePayload.php index 2c865fe4a..95e0a1dda 100644 --- a/src/Http/Payload/CreateProfilePayload.php +++ b/src/Http/Payload/CreateProfilePayload.php @@ -36,7 +36,7 @@ public function __construct( $this->businessCategory = $businessCategory; } - public function data(): array + public function toArray(): array { return [ 'name' => $this->name, diff --git a/src/Http/Payload/CreateRefundPaymentPayload.php b/src/Http/Payload/CreateRefundPaymentPayload.php index add71a44d..3da56777c 100644 --- a/src/Http/Payload/CreateRefundPaymentPayload.php +++ b/src/Http/Payload/CreateRefundPaymentPayload.php @@ -35,7 +35,7 @@ public function __construct( $this->routingReversals = $routingReversals; } - public function data(): array + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/CreateSalesInvoicePayload.php b/src/Http/Payload/CreateSalesInvoicePayload.php index 362ebb910..208987a3e 100644 --- a/src/Http/Payload/CreateSalesInvoicePayload.php +++ b/src/Http/Payload/CreateSalesInvoicePayload.php @@ -71,7 +71,7 @@ public function __construct( $this->discount = $discount; } - public function data(): array + public function toArray(): array { return [ 'profileId' => $this->profileId, diff --git a/src/Http/Payload/CreateSubscriptionPayload.php b/src/Http/Payload/CreateSubscriptionPayload.php index 49769e411..cd60de8d5 100644 --- a/src/Http/Payload/CreateSubscriptionPayload.php +++ b/src/Http/Payload/CreateSubscriptionPayload.php @@ -58,7 +58,7 @@ public function __construct( $this->profileId = $profileId; } - public function data(): array + public function toArray(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/DataBag.php b/src/Http/Payload/DataBag.php index 338261024..b883020d9 100644 --- a/src/Http/Payload/DataBag.php +++ b/src/Http/Payload/DataBag.php @@ -3,16 +3,10 @@ namespace Mollie\Api\Http\Payload; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Contracts\DataProvider; use Mollie\Api\Contracts\DataResolver; use Mollie\Api\Traits\ResolvesValues; -abstract class DataBag implements Arrayable, DataProvider, DataResolver +abstract class DataBag implements Arrayable, DataResolver { use ResolvesValues; - - public function toArray(): array - { - return $this->resolve(); - } } diff --git a/src/Http/Payload/DataCollection.php b/src/Http/Payload/DataCollection.php index 186bb6e10..bb3378d2a 100644 --- a/src/Http/Payload/DataCollection.php +++ b/src/Http/Payload/DataCollection.php @@ -3,14 +3,13 @@ namespace Mollie\Api\Http\Payload; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Contracts\DataProvider; use Mollie\Api\Contracts\DataResolver; use Mollie\Api\Traits\ResolvesValues; /** * @template T of \Mollie\Api\Contracts\DataResolver */ -class DataCollection implements Arrayable, DataProvider, DataResolver +class DataCollection implements Arrayable, DataResolver { use ResolvesValues; @@ -33,10 +32,6 @@ public static function wrap(object $subject): self return $subject; } - if ($subject instanceof DataProvider) { - return new static($subject->data()); - } - if ($subject instanceof Arrayable) { return new static($subject->toArray()); } @@ -44,11 +39,6 @@ public static function wrap(object $subject): self return new static((array) $subject); } - public function data(): array - { - return $this->toArray(); - } - public function toArray(): array { return $this->items; diff --git a/src/Http/Payload/Discount.php b/src/Http/Payload/Discount.php index ed0e17972..8d34be771 100644 --- a/src/Http/Payload/Discount.php +++ b/src/Http/Payload/Discount.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class Discount implements DataProvider +class Discount implements Arrayable { use ComposableFromArray; @@ -21,7 +21,7 @@ public function __construct( $this->value = $value; } - public function data() + public function toArray(): array { return [ 'type' => $this->type, diff --git a/src/Http/Payload/EmailDetails.php b/src/Http/Payload/EmailDetails.php index 6d30e6e40..2a830eeb5 100644 --- a/src/Http/Payload/EmailDetails.php +++ b/src/Http/Payload/EmailDetails.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class EmailDetails implements DataProvider +class EmailDetails implements Arrayable { use ComposableFromArray; @@ -21,7 +21,7 @@ public function __construct( $this->body = $body; } - public function data() + public function toArray(): array { return [ 'subject' => $this->subject, diff --git a/src/Http/Payload/InvoiceLine.php b/src/Http/Payload/InvoiceLine.php index 160c37f93..f3ad2af3b 100644 --- a/src/Http/Payload/InvoiceLine.php +++ b/src/Http/Payload/InvoiceLine.php @@ -28,7 +28,7 @@ public function __construct( $this->discount = $discount; } - public function data() + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/Metadata.php b/src/Http/Payload/Metadata.php index 1b8a2e128..7e5b3c909 100644 --- a/src/Http/Payload/Metadata.php +++ b/src/Http/Payload/Metadata.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Stringable; -class Metadata implements DataProvider +class Metadata implements Stringable { public array $data; @@ -13,7 +13,7 @@ public function __construct(array $data) $this->data = $data; } - public function data(): string + public function __toString(): string { return @json_encode($this->data); } diff --git a/src/Http/Payload/Money.php b/src/Http/Payload/Money.php index 45214ba38..a72286ce6 100644 --- a/src/Http/Payload/Money.php +++ b/src/Http/Payload/Money.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; -class Money implements DataProvider +class Money implements Arrayable { public string $currency; @@ -18,7 +18,7 @@ public function __construct( $this->value = $value; } - public function data(): array + public function toArray(): array { return [ 'currency' => $this->currency, diff --git a/src/Http/Payload/OrderLine.php b/src/Http/Payload/OrderLine.php index 113e6cffa..827ed2b47 100644 --- a/src/Http/Payload/OrderLine.php +++ b/src/Http/Payload/OrderLine.php @@ -60,7 +60,7 @@ public function __construct( $this->productUrl = $productUrl; } - public function data(): array + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/Owner.php b/src/Http/Payload/Owner.php index be4287710..174662ad6 100644 --- a/src/Http/Payload/Owner.php +++ b/src/Http/Payload/Owner.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class Owner implements DataProvider +class Owner implements Arrayable { use ComposableFromArray; @@ -29,7 +29,7 @@ public function __construct( $this->locale = $locale; } - public function data(): array + public function toArray(): array { return [ 'email' => $this->email, diff --git a/src/Http/Payload/OwnerAddress.php b/src/Http/Payload/OwnerAddress.php index f80c8027c..92d5e57db 100644 --- a/src/Http/Payload/OwnerAddress.php +++ b/src/Http/Payload/OwnerAddress.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class OwnerAddress implements DataProvider +class OwnerAddress implements Arrayable { use ComposableFromArray; @@ -33,7 +33,7 @@ public function __construct( $this->region = $region; } - public function data(): array + public function toArray(): array { return [ 'streetAndNumber' => $this->streetAndNumber, diff --git a/src/Http/Payload/PaymentDetails.php b/src/Http/Payload/PaymentDetails.php index c2e4fa9ca..daa6b2736 100644 --- a/src/Http/Payload/PaymentDetails.php +++ b/src/Http/Payload/PaymentDetails.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class PaymentDetails implements DataProvider +class PaymentDetails implements Arrayable { use ComposableFromArray; @@ -21,7 +21,7 @@ public function __construct( $this->sourceDescription = $sourceDescription; } - public function data() + public function toArray(): array { return [ 'source' => $this->source, diff --git a/src/Http/Payload/PaymentRoute.php b/src/Http/Payload/PaymentRoute.php index cc9698dcc..b61e56151 100644 --- a/src/Http/Payload/PaymentRoute.php +++ b/src/Http/Payload/PaymentRoute.php @@ -22,7 +22,7 @@ public function __construct( $this->delayUntil = $delayUntil; } - public function data(): array + public function toArray(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/Recipient.php b/src/Http/Payload/Recipient.php index 151a9ea85..5afd881e5 100644 --- a/src/Http/Payload/Recipient.php +++ b/src/Http/Payload/Recipient.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Payload; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; -class Recipient implements DataProvider +class Recipient implements Arrayable { public string $type; @@ -74,7 +74,7 @@ public function __construct( $this->locale = $locale; } - public function data() + public function toArray(): array { return [ 'type' => $this->type, diff --git a/src/Http/Payload/RecurringBillingCycle.php b/src/Http/Payload/RecurringBillingCycle.php index e468e6d5b..73892d472 100644 --- a/src/Http/Payload/RecurringBillingCycle.php +++ b/src/Http/Payload/RecurringBillingCycle.php @@ -35,7 +35,7 @@ public function __construct( $this->startDate = $startDate; } - public function data(): array + public function toArray(): array { return [ 'interval' => $this->interval, diff --git a/src/Http/Payload/RefundRoute.php b/src/Http/Payload/RefundRoute.php index 240a55558..09b29054d 100644 --- a/src/Http/Payload/RefundRoute.php +++ b/src/Http/Payload/RefundRoute.php @@ -16,7 +16,7 @@ public function __construct( $this->organizationId = $organizationId; } - public function data(): array + public function toArray(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Payload/RequestApplePayPaymentSessionPayload.php b/src/Http/Payload/RequestApplePayPaymentSessionPayload.php index cdd550e50..c4b1e6516 100644 --- a/src/Http/Payload/RequestApplePayPaymentSessionPayload.php +++ b/src/Http/Payload/RequestApplePayPaymentSessionPayload.php @@ -20,7 +20,7 @@ public function __construct( $this->profileId = $profileId; } - public function data(): array + public function toArray(): array { return [ 'domain' => $this->domain, diff --git a/src/Http/Payload/UpdatePaymentLinkPayload.php b/src/Http/Payload/UpdatePaymentLinkPayload.php index 83444ff76..c7aa67e30 100644 --- a/src/Http/Payload/UpdatePaymentLinkPayload.php +++ b/src/Http/Payload/UpdatePaymentLinkPayload.php @@ -16,7 +16,7 @@ public function __construct( $this->archived = $archived; } - public function data(): array + public function toArray(): array { return [ 'description' => $this->description, diff --git a/src/Http/Payload/UpdatePaymentPayload.php b/src/Http/Payload/UpdatePaymentPayload.php index 1f390d3c4..455d01c74 100644 --- a/src/Http/Payload/UpdatePaymentPayload.php +++ b/src/Http/Payload/UpdatePaymentPayload.php @@ -49,7 +49,7 @@ public function __construct( $this->additional = $additional; } - public function data(): array + public function toArray(): array { return array_merge([ 'description' => $this->description, diff --git a/src/Http/Payload/UpdatePaymentRoutePayload.php b/src/Http/Payload/UpdatePaymentRoutePayload.php index 490bc810d..0b5354f2d 100644 --- a/src/Http/Payload/UpdatePaymentRoutePayload.php +++ b/src/Http/Payload/UpdatePaymentRoutePayload.php @@ -14,7 +14,7 @@ public function __construct( $this->releaseDate = $releaseDate; } - public function data(): array + public function toArray(): array { return [ 'releaseDate' => $this->releaseDate->format('Y-m-d'), diff --git a/src/Http/Payload/UpdateProfilePayload.php b/src/Http/Payload/UpdateProfilePayload.php index ebe735c25..53167ae3d 100644 --- a/src/Http/Payload/UpdateProfilePayload.php +++ b/src/Http/Payload/UpdateProfilePayload.php @@ -40,7 +40,7 @@ public function __construct( $this->mode = $mode; } - public function data(): array + public function toArray(): array { return [ 'name' => $this->name, diff --git a/src/Http/Payload/UpdateSalesInvoicePayload.php b/src/Http/Payload/UpdateSalesInvoicePayload.php index 56634fc26..0ecc1627c 100644 --- a/src/Http/Payload/UpdateSalesInvoicePayload.php +++ b/src/Http/Payload/UpdateSalesInvoicePayload.php @@ -51,7 +51,7 @@ public function __construct( $this->discount = $discount; } - public function data(): array + public function toArray(): array { return [ 'status' => $this->status, diff --git a/src/Http/Payload/UpdateSubscriptionPayload.php b/src/Http/Payload/UpdateSubscriptionPayload.php index 669f6cec0..d0dde9983 100644 --- a/src/Http/Payload/UpdateSubscriptionPayload.php +++ b/src/Http/Payload/UpdateSubscriptionPayload.php @@ -42,7 +42,7 @@ public function __construct( $this->mandateId = $mandateId; } - public function data(): array + public function toArray(): array { return [ 'amount' => $this->amount, diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index c7c97c283..f6b9cf64e 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -31,7 +31,7 @@ public function __construct(CreateClientLinkPayload $payload) protected function defaultPayload(): array { - return $this->payload->data(); + return $this->payload->toArray(); } public function resolveResourcePath(): string diff --git a/src/Traits/ResolvesValues.php b/src/Traits/ResolvesValues.php index 87ba78821..41566556b 100644 --- a/src/Traits/ResolvesValues.php +++ b/src/Traits/ResolvesValues.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Contracts\DataProvider; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Contracts\DataResolver; use Mollie\Api\Http\Payload\DataCollection; +use Stringable; trait ResolvesValues { @@ -16,8 +17,12 @@ public function resolve(): array return $value->resolve(); } - if ($value instanceof DataProvider) { - return $value->data(); + if ($value instanceof Arrayable) { + return $value->toArray(); + } + + if ($value instanceof Stringable) { + return $value->__toString(); } return $value; diff --git a/tests/Traits/ResolvesValuesTest.php b/tests/Traits/ResolvesValuesTest.php index 752af8d74..81a90bf23 100644 --- a/tests/Traits/ResolvesValuesTest.php +++ b/tests/Traits/ResolvesValuesTest.php @@ -3,7 +3,6 @@ namespace Tests\Traits; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Contracts\DataProvider; use Mollie\Api\Contracts\DataResolver; use Mollie\Api\Traits\ResolvesValues; use Tests\TestCase; @@ -64,7 +63,7 @@ public function __construct(Baz $baz) $this->baz = $baz; } - public function data(): array + public function toArray(): array { return [ 'baz' => $this->baz, @@ -72,7 +71,7 @@ public function data(): array } } -class Baz implements DataProvider +class Baz implements Arrayable { public string $value; @@ -81,7 +80,7 @@ public function __construct(string $value) $this->value = $value; } - public function data(): array + public function toArray(): array { return [ 'value' => $this->value, From 7578a2c17a342cfd60c2593236627ceab791a3cf Mon Sep 17 00:00:00 2001 From: Naoray Date: Tue, 10 Dec 2024 13:43:20 +0000 Subject: [PATCH 109/131] Fixes coding style --- src/Factories/Factory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index bb19e11a7..cc85ce59e 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -37,7 +37,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey . $key; + $keys[] = $backupKey.$key; } foreach ($keys as $key) { @@ -60,7 +60,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey . $key, $key], $value); + return Arr::includes($this->data, [$backupKey.$key, $key], $value); } /** From 1f7a76f0cfc8fae2ee0271f327ff4cf7b2925c45 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 11 Dec 2024 16:56:54 +0100 Subject: [PATCH 110/131] wip --- examples/sales-invoices/create-sales-invoice.php | 3 +-- phpstan-baseline.neon | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/examples/sales-invoices/create-sales-invoice.php b/examples/sales-invoices/create-sales-invoice.php index 69f93a84a..a3a4aed11 100644 --- a/examples/sales-invoices/create-sales-invoice.php +++ b/examples/sales-invoices/create-sales-invoice.php @@ -1,6 +1,5 @@ SalesInvoiceStatus::DRAFT, 'vatScheme' => 'standard', 'vatMode' => 'inclusive', - 'paymentTerm' => PaymentTerm::DAYS_30, + 'paymentTerm' => '30 days', 'recipientIdentifier' => 'XXXXX', 'recipient' => [ 'type' => 'consumer', diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 67a10b8f9..17bb3a20d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -220,11 +220,6 @@ parameters: count: 1 path: examples/profiles/update-profile.php - - - message: "#^Access to constant DAYS_30 on an unknown class Mollie\\\\Api\\\\Types\\\\PaymentTerm\\.$#" - count: 1 - path: examples/sales-invoices/create-sales-invoice.php - - message: "#^Variable \\$mollie might not be defined\\.$#" count: 1 From 94d5a76c9594891aa024dbca568e2cae8dd93181 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:49:45 +0100 Subject: [PATCH 111/131] wip --- src/Http/Query/AnyQuery.php | 3 ++- src/Http/Query/CreatePaymentQuery.php | 3 ++- src/Http/Query/GetAllMethodsQuery.php | 5 +++-- src/Http/Query/GetAllPaginatedSubscriptionsQuery.php | 4 +++- src/Http/Query/GetBalanceReportQuery.php | 3 ++- src/Http/Query/GetClientQuery.php | 3 ++- src/Http/Query/GetEnabledPaymentMethodsQuery.php | 5 +++-- src/Http/Query/GetPaginatedBalanceQuery.php | 4 +++- src/Http/Query/GetPaginatedChargebackQuery.php | 3 ++- src/Http/Query/GetPaginatedClientQuery.php | 3 ++- src/Http/Query/GetPaginatedCustomerPaymentsQuery.php | 4 +++- src/Http/Query/GetPaginatedInvoiceQuery.php | 4 +++- src/Http/Query/GetPaginatedPaymentCapturesQuery.php | 3 ++- src/Http/Query/GetPaginatedPaymentChargebacksQuery.php | 3 ++- src/Http/Query/GetPaginatedPaymentRefundQuery.php | 3 ++- src/Http/Query/GetPaginatedRefundsQuery.php | 3 ++- src/Http/Query/GetPaginatedSettlementsQuery.php | 4 +++- src/Http/Query/GetPaymentCaptureQuery.php | 3 ++- src/Http/Query/GetPaymentChargebackQuery.php | 3 ++- src/Http/Query/GetPaymentMethodQuery.php | 3 ++- src/Http/Query/GetPaymentQuery.php | 3 ++- src/Http/Query/GetPaymentRefundQuery.php | 3 ++- src/Http/Query/PaginatedQuery.php | 4 +++- src/Http/Query/Query.php | 7 ------- src/Http/Requests/PaginatedRequest.php | 6 +++--- tests/Http/Requests/PaginatedRequestTest.php | 4 ++-- 26 files changed, 59 insertions(+), 37 deletions(-) delete mode 100644 src/Http/Query/Query.php diff --git a/src/Http/Query/AnyQuery.php b/src/Http/Query/AnyQuery.php index a704cbfe0..6d7ffec94 100644 --- a/src/Http/Query/AnyQuery.php +++ b/src/Http/Query/AnyQuery.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; -class AnyQuery extends Query +class AnyQuery implements Arrayable { use ComposableFromArray; diff --git a/src/Http/Query/CreatePaymentQuery.php b/src/Http/Query/CreatePaymentQuery.php index ecb207176..8dd268728 100644 --- a/src/Http/Query/CreatePaymentQuery.php +++ b/src/Http/Query/CreatePaymentQuery.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Traits\ComposableFromArray; use Mollie\Api\Types\PaymentQuery; -class CreatePaymentQuery extends Query +class CreatePaymentQuery implements Arrayable { use ComposableFromArray; diff --git a/src/Http/Query/GetAllMethodsQuery.php b/src/Http/Query/GetAllMethodsQuery.php index 00ef7495b..c5535701b 100644 --- a/src/Http/Query/GetAllMethodsQuery.php +++ b/src/Http/Query/GetAllMethodsQuery.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Http\Payload\Money; use Mollie\Api\Types\MethodQuery; -class GetAllMethodsQuery extends Query +class GetAllMethodsQuery implements Arrayable { private ?string $locale; @@ -35,7 +36,7 @@ public function toArray(): array $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, ]), 'locale' => $this->locale, - 'amount' => $this->amount ? $this->amount->data() : null, + 'amount' => $this->amount, ]; } } diff --git a/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php b/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php index 9576683a9..1f6d08def 100644 --- a/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php +++ b/src/Http/Query/GetAllPaginatedSubscriptionsQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class GetAllPaginatedSubscriptionsQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class GetAllPaginatedSubscriptionsQuery implements Arrayable { private ?string $profileId; diff --git a/src/Http/Query/GetBalanceReportQuery.php b/src/Http/Query/GetBalanceReportQuery.php index c3d0070d7..e1467973d 100644 --- a/src/Http/Query/GetBalanceReportQuery.php +++ b/src/Http/Query/GetBalanceReportQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use DateTimeInterface; +use Mollie\Api\Contracts\Arrayable; -class GetBalanceReportQuery extends Query +class GetBalanceReportQuery implements Arrayable { public DateTimeInterface $from; diff --git a/src/Http/Query/GetClientQuery.php b/src/Http/Query/GetClientQuery.php index 20d9b315b..9c10a51ac 100644 --- a/src/Http/Query/GetClientQuery.php +++ b/src/Http/Query/GetClientQuery.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\ClientQuery; -class GetClientQuery extends Query +class GetClientQuery implements Arrayable { private bool $embedOrganization; diff --git a/src/Http/Query/GetEnabledPaymentMethodsQuery.php b/src/Http/Query/GetEnabledPaymentMethodsQuery.php index 83d61cacf..831940b66 100644 --- a/src/Http/Query/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Query/GetEnabledPaymentMethodsQuery.php @@ -2,11 +2,12 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Http\Payload\Money; use Mollie\Api\Types\MethodQuery; -class GetEnabledPaymentMethodsQuery extends Query +class GetEnabledPaymentMethodsQuery implements Arrayable { private string $sequenceType; @@ -57,7 +58,7 @@ public function toArray(): array return [ 'sequenceType' => $this->sequenceType, 'locale' => $this->locale, - 'amount' => $this->amount ? $this->amount->data() : null, + 'amount' => $this->amount, 'resource' => $this->resource, 'billingCountry' => $this->billingCountry, 'includeWallets' => Arr::join($this->includeWallets ?? []), diff --git a/src/Http/Query/GetPaginatedBalanceQuery.php b/src/Http/Query/GetPaginatedBalanceQuery.php index 7e23d507f..9f54de630 100644 --- a/src/Http/Query/GetPaginatedBalanceQuery.php +++ b/src/Http/Query/GetPaginatedBalanceQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedBalanceQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class GetPaginatedBalanceQuery implements Arrayable { private SortablePaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedChargebackQuery.php b/src/Http/Query/GetPaginatedChargebackQuery.php index edb4afb77..574f150b0 100644 --- a/src/Http/Query/GetPaginatedChargebackQuery.php +++ b/src/Http/Query/GetPaginatedChargebackQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedChargebackQuery extends Query +class GetPaginatedChargebackQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index ccb8081a3..908b0cb4d 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -4,8 +4,9 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\ClientQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedClientQuery extends Query +class GetPaginatedClientQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php b/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php index c19c1876e..75de921df 100644 --- a/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php +++ b/src/Http/Query/GetPaginatedCustomerPaymentsQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedCustomerPaymentsQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class GetPaginatedCustomerPaymentsQuery implements Arrayable { private SortablePaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedInvoiceQuery.php b/src/Http/Query/GetPaginatedInvoiceQuery.php index 9e7336592..3c9da3cc6 100644 --- a/src/Http/Query/GetPaginatedInvoiceQuery.php +++ b/src/Http/Query/GetPaginatedInvoiceQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedInvoiceQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class GetPaginatedInvoiceQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php index 4bfbaff4c..7cd59ebb1 100644 --- a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php @@ -4,8 +4,9 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedPaymentCapturesQuery extends Query +class GetPaginatedPaymentCapturesQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php index c0b2f54c9..4b50a3f53 100644 --- a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php +++ b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedPaymentChargebacksQuery extends Query +class GetPaginatedPaymentChargebacksQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedPaymentRefundQuery.php b/src/Http/Query/GetPaginatedPaymentRefundQuery.php index 57eb50c49..87fefc250 100644 --- a/src/Http/Query/GetPaginatedPaymentRefundQuery.php +++ b/src/Http/Query/GetPaginatedPaymentRefundQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedPaymentRefundQuery extends Query +class GetPaginatedPaymentRefundQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedRefundsQuery.php b/src/Http/Query/GetPaginatedRefundsQuery.php index b26c870ea..f51805b75 100644 --- a/src/Http/Query/GetPaginatedRefundsQuery.php +++ b/src/Http/Query/GetPaginatedRefundsQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaginatedRefundsQuery extends Query +class GetPaginatedRefundsQuery implements Arrayable { private PaginatedQuery $paginatedQuery; diff --git a/src/Http/Query/GetPaginatedSettlementsQuery.php b/src/Http/Query/GetPaginatedSettlementsQuery.php index 8b6eb9821..fc518dfff 100644 --- a/src/Http/Query/GetPaginatedSettlementsQuery.php +++ b/src/Http/Query/GetPaginatedSettlementsQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class GetPaginatedSettlementsQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class GetPaginatedSettlementsQuery implements Arrayable { private ?string $balanceId = null; diff --git a/src/Http/Query/GetPaymentCaptureQuery.php b/src/Http/Query/GetPaymentCaptureQuery.php index 712752795..2d3cba80d 100644 --- a/src/Http/Query/GetPaymentCaptureQuery.php +++ b/src/Http/Query/GetPaymentCaptureQuery.php @@ -4,8 +4,9 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaymentCaptureQuery extends Query +class GetPaymentCaptureQuery implements Arrayable { public bool $includePayment = false; diff --git a/src/Http/Query/GetPaymentChargebackQuery.php b/src/Http/Query/GetPaymentChargebackQuery.php index fc00c064a..d87e213f7 100644 --- a/src/Http/Query/GetPaymentChargebackQuery.php +++ b/src/Http/Query/GetPaymentChargebackQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaymentChargebackQuery extends Query +class GetPaymentChargebackQuery implements Arrayable { private bool $includePayment; diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php index 92bb45a88..f906a83ce 100644 --- a/src/Http/Query/GetPaymentMethodQuery.php +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -4,8 +4,9 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\MethodQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaymentMethodQuery extends Query +class GetPaymentMethodQuery implements Arrayable { private ?string $locale; diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php index 1b24a355d..f5e9caaa9 100644 --- a/src/Http/Query/GetPaymentQuery.php +++ b/src/Http/Query/GetPaymentQuery.php @@ -4,8 +4,9 @@ use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaymentQuery extends Query +class GetPaymentQuery implements Arrayable { public bool $embedCaptures = false; diff --git a/src/Http/Query/GetPaymentRefundQuery.php b/src/Http/Query/GetPaymentRefundQuery.php index 233a82610..108a25422 100644 --- a/src/Http/Query/GetPaymentRefundQuery.php +++ b/src/Http/Query/GetPaymentRefundQuery.php @@ -3,8 +3,9 @@ namespace Mollie\Api\Http\Query; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Contracts\Arrayable; -class GetPaymentRefundQuery extends Query +class GetPaymentRefundQuery implements Arrayable { private bool $includePayment; diff --git a/src/Http/Query/PaginatedQuery.php b/src/Http/Query/PaginatedQuery.php index bab71b3d4..2ae54e8d7 100644 --- a/src/Http/Query/PaginatedQuery.php +++ b/src/Http/Query/PaginatedQuery.php @@ -2,7 +2,9 @@ namespace Mollie\Api\Http\Query; -class PaginatedQuery extends Query +use Mollie\Api\Contracts\Arrayable; + +class PaginatedQuery implements Arrayable { public ?string $from = null; diff --git a/src/Http/Query/Query.php b/src/Http/Query/Query.php deleted file mode 100644 index 55b880486..000000000 --- a/src/Http/Query/Query.php +++ /dev/null @@ -1,7 +0,0 @@ -query = $query; } diff --git a/tests/Http/Requests/PaginatedRequestTest.php b/tests/Http/Requests/PaginatedRequestTest.php index ac0cc2051..58d77e58b 100644 --- a/tests/Http/Requests/PaginatedRequestTest.php +++ b/tests/Http/Requests/PaginatedRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Http\Requests\PaginatedRequest; use Mollie\Api\Resources\BaseCollection; use Tests\TestCase; @@ -37,7 +37,7 @@ public function resolveResourcePath(): string } } -class ConcreteQuery extends Query +class ConcreteQuery implements Arrayable { private array $parameters; From 5fd78ed6778cd170d6599eb891ebd90e2286d17b Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 12 Dec 2024 12:01:03 +0000 Subject: [PATCH 112/131] Fixes coding style --- examples/sales-invoices/create-sales-invoice.php | 6 +++--- examples/sales-invoices/delete-sales-invoice.php | 7 ++++--- examples/sales-invoices/list-sales-invoices.php | 11 ++++++----- examples/sales-invoices/update-sales-invoice.php | 7 ++++--- src/Http/Query/GetPaginatedChargebackQuery.php | 2 +- src/Http/Query/GetPaginatedClientQuery.php | 2 +- src/Http/Query/GetPaginatedPaymentCapturesQuery.php | 2 +- .../Query/GetPaginatedPaymentChargebacksQuery.php | 2 +- src/Http/Query/GetPaginatedPaymentRefundQuery.php | 2 +- src/Http/Query/GetPaginatedRefundsQuery.php | 2 +- src/Http/Query/GetPaymentCaptureQuery.php | 2 +- src/Http/Query/GetPaymentChargebackQuery.php | 2 +- src/Http/Query/GetPaymentMethodQuery.php | 2 +- src/Http/Query/GetPaymentQuery.php | 2 +- src/Http/Query/GetPaymentRefundQuery.php | 2 +- 15 files changed, 28 insertions(+), 25 deletions(-) diff --git a/examples/sales-invoices/create-sales-invoice.php b/examples/sales-invoices/create-sales-invoice.php index a3a4aed11..e1d6cd0e4 100644 --- a/examples/sales-invoices/create-sales-invoice.php +++ b/examples/sales-invoices/create-sales-invoice.php @@ -10,7 +10,7 @@ /* * Initialize the Mollie API library with your API key or OAuth access token. */ - require "../initialize.php"; + require '../initialize.php'; /* * Create a sales invoice @@ -44,7 +44,7 @@ ], ]); - echo "

        New sales invoice created with ID: " . htmlspecialchars($salesInvoice->id) . "

        "; + echo '

        New sales invoice created with ID: '.htmlspecialchars($salesInvoice->id).'

        '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/sales-invoices/delete-sales-invoice.php b/examples/sales-invoices/delete-sales-invoice.php index 3b154b802..eb75be6bf 100644 --- a/examples/sales-invoices/delete-sales-invoice.php +++ b/examples/sales-invoices/delete-sales-invoice.php @@ -1,4 +1,5 @@ salesInvoices->delete($invoiceId); - echo "

        Sales invoice deleted with ID: " . htmlspecialchars($invoiceId) . "

        "; + echo '

        Sales invoice deleted with ID: '.htmlspecialchars($invoiceId).'

        '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/sales-invoices/list-sales-invoices.php b/examples/sales-invoices/list-sales-invoices.php index 49d6d3611..7eb1d6e03 100644 --- a/examples/sales-invoices/list-sales-invoices.php +++ b/examples/sales-invoices/list-sales-invoices.php @@ -1,4 +1,5 @@ '; $salesInvoices = $mollie->salesInvoices->page(); foreach ($salesInvoices as $invoice) { - echo '
      • Invoice ' . htmlspecialchars($invoice->id) . ': (' . htmlspecialchars($invoice->issuedAt) . ')'; - echo '
        Status: ' . htmlspecialchars($invoice->status) . ''; - echo '
        Total Amount: ' . htmlspecialchars($invoice->amount->currency) . ' ' . htmlspecialchars($invoice->amount->value) . ''; + echo '
      • Invoice '.htmlspecialchars($invoice->id).': ('.htmlspecialchars($invoice->issuedAt).')'; + echo '
        Status: '.htmlspecialchars($invoice->status).''; + echo '
        Total Amount: '.htmlspecialchars($invoice->amount->currency).' '.htmlspecialchars($invoice->amount->value).''; echo '
      • '; } echo '
      '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/sales-invoices/update-sales-invoice.php b/examples/sales-invoices/update-sales-invoice.php index 08c6e671b..27433ecb8 100644 --- a/examples/sales-invoices/update-sales-invoice.php +++ b/examples/sales-invoices/update-sales-invoice.php @@ -1,4 +1,5 @@ Sales invoice updated with ID: " . htmlspecialchars($updatedInvoice->id) . "

      "; + echo '

      Sales invoice updated with ID: '.htmlspecialchars($updatedInvoice->id).'

      '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo "API call failed: " . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/src/Http/Query/GetPaginatedChargebackQuery.php b/src/Http/Query/GetPaginatedChargebackQuery.php index 574f150b0..109e45f03 100644 --- a/src/Http/Query/GetPaginatedChargebackQuery.php +++ b/src/Http/Query/GetPaginatedChargebackQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedChargebackQuery implements Arrayable { diff --git a/src/Http/Query/GetPaginatedClientQuery.php b/src/Http/Query/GetPaginatedClientQuery.php index 908b0cb4d..af3519809 100644 --- a/src/Http/Query/GetPaginatedClientQuery.php +++ b/src/Http/Query/GetPaginatedClientQuery.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\ClientQuery; -use Mollie\Api\Contracts\Arrayable; class GetPaginatedClientQuery implements Arrayable { diff --git a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php index 7cd59ebb1..c39e48689 100644 --- a/src/Http/Query/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Query/GetPaginatedPaymentCapturesQuery.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; -use Mollie\Api\Contracts\Arrayable; class GetPaginatedPaymentCapturesQuery implements Arrayable { diff --git a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php index 4b50a3f53..daf9b91fe 100644 --- a/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php +++ b/src/Http/Query/GetPaginatedPaymentChargebacksQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentChargebacksQuery implements Arrayable { diff --git a/src/Http/Query/GetPaginatedPaymentRefundQuery.php b/src/Http/Query/GetPaginatedPaymentRefundQuery.php index 87fefc250..86f911f9a 100644 --- a/src/Http/Query/GetPaginatedPaymentRefundQuery.php +++ b/src/Http/Query/GetPaginatedPaymentRefundQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentRefundQuery implements Arrayable { diff --git a/src/Http/Query/GetPaginatedRefundsQuery.php b/src/Http/Query/GetPaginatedRefundsQuery.php index f51805b75..859b55d7a 100644 --- a/src/Http/Query/GetPaginatedRefundsQuery.php +++ b/src/Http/Query/GetPaginatedRefundsQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedRefundsQuery implements Arrayable { diff --git a/src/Http/Query/GetPaymentCaptureQuery.php b/src/Http/Query/GetPaymentCaptureQuery.php index 2d3cba80d..1276a4482 100644 --- a/src/Http/Query/GetPaymentCaptureQuery.php +++ b/src/Http/Query/GetPaymentCaptureQuery.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; -use Mollie\Api\Contracts\Arrayable; class GetPaymentCaptureQuery implements Arrayable { diff --git a/src/Http/Query/GetPaymentChargebackQuery.php b/src/Http/Query/GetPaymentChargebackQuery.php index d87e213f7..50e836159 100644 --- a/src/Http/Query/GetPaymentChargebackQuery.php +++ b/src/Http/Query/GetPaymentChargebackQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentChargebackQuery implements Arrayable { diff --git a/src/Http/Query/GetPaymentMethodQuery.php b/src/Http/Query/GetPaymentMethodQuery.php index f906a83ce..369192c45 100644 --- a/src/Http/Query/GetPaymentMethodQuery.php +++ b/src/Http/Query/GetPaymentMethodQuery.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\MethodQuery; -use Mollie\Api\Contracts\Arrayable; class GetPaymentMethodQuery implements Arrayable { diff --git a/src/Http/Query/GetPaymentQuery.php b/src/Http/Query/GetPaymentQuery.php index f5e9caaa9..051ab8a7b 100644 --- a/src/Http/Query/GetPaymentQuery.php +++ b/src/Http/Query/GetPaymentQuery.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Query; +use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentQuery; -use Mollie\Api\Contracts\Arrayable; class GetPaymentQuery implements Arrayable { diff --git a/src/Http/Query/GetPaymentRefundQuery.php b/src/Http/Query/GetPaymentRefundQuery.php index 108a25422..faa0288d0 100644 --- a/src/Http/Query/GetPaymentRefundQuery.php +++ b/src/Http/Query/GetPaymentRefundQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Query; -use Mollie\Api\Types\PaymentIncludesQuery; use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentRefundQuery implements Arrayable { From 46a0bdc20e4f386d4d55ac318a7d9e4f31036c7b Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 12 Dec 2024 13:59:22 +0100 Subject: [PATCH 113/131] wip --- README.md | 4 +- UPGRADING.md | 8 +- docs/endpoint-collections.md | 18 ++-- docs/requests.md | 4 +- docs/testing.md | 4 +- examples/captures/create-capture.php | 8 +- examples/client-links/create-client-link.php | 10 +-- .../create-customer-first-payment.php | 8 +- phpstan-baseline.neon | 14 +-- src/CompatibilityChecker.php | 10 ++- src/Contracts/DataResolver.php | 11 --- .../BalanceReportEndpointCollection.php | 2 +- .../BalanceTransactionEndpointCollection.php | 2 +- .../ClientEndpointCollection.php | 2 +- .../ClientLinkEndpointCollection.php | 2 +- .../CustomerEndpointCollection.php | 4 +- .../CustomerPaymentsEndpointCollection.php | 4 +- .../MandateEndpointCollection.php | 2 +- .../MethodEndpointCollection.php | 6 +- .../PaymentCaptureEndpointCollection.php | 6 +- .../PaymentChargebackEndpointCollection.php | 4 +- .../PaymentEndpointCollection.php | 10 +-- .../PaymentLinkEndpointCollection.php | 4 +- .../PaymentRefundEndpointCollection.php | 4 +- .../ProfileEndpointCollection.php | 4 +- .../SalesInvoiceEndpointCollection.php | 4 +- .../SessionEndpointCollection.php | 27 +++--- .../SettlementCaptureEndpointCollection.php | 2 +- ...SettlementChargebackEndpointCollection.php | 2 +- .../SettlementPaymentEndpointCollection.php | 2 +- .../SettlementRefundEndpointCollection.php | 2 +- .../SubscriptionEndpointCollection.php | 4 +- .../ApplePayPaymentSessionPayloadFactory.php | 2 +- src/Factories/ApplicationFeeFactory.php | 2 +- .../CreateClientLinkPayloadFactory.php | 6 +- .../CreateCustomerPayloadFactory.php | 4 +- src/Factories/CreateMandatePayloadFactory.php | 4 +- .../CreatePaymentCapturePayloadFactory.php | 6 +- .../CreatePaymentLinkPayloadFactory.php | 4 +- src/Factories/CreatePaymentPayloadFactory.php | 16 ++-- src/Factories/CreateProfilePayloadFactory.php | 2 +- .../CreateRefundPaymentPayloadFactory.php | 6 +- .../CreateSalesInvoicePayloadFactory.php | 16 ++-- .../CreateSubscriptionPayloadFactory.php | 8 +- ...tAllPaginatedSubscriptionsQueryFactory.php | 2 +- .../GetAllPaymentMethodsQueryFactory.php | 2 +- .../GetBalanceReportQueryFactory.php | 2 +- src/Factories/GetClientQueryFactory.php | 2 +- .../GetEnabledPaymentMethodsQueryFactory.php | 2 +- .../GetPaginatedBalanceQueryFactory.php | 2 +- .../GetPaginatedChargebackQueryFactory.php | 2 +- .../GetPaginatedClientQueryFactory.php | 2 +- ...tPaginatedCustomerPaymentsQueryFactory.php | 2 +- .../GetPaginatedInvoiceQueryFactory.php | 2 +- ...etPaginatedPaymentCapturesQueryFactory.php | 2 +- ...aginatedPaymentChargebacksQueryFactory.php | 2 +- .../GetPaginatedPaymentRefundQueryFactory.php | 2 +- .../GetPaginatedRefundsQueryFactory.php | 2 +- ...aginatedSettlementCapturesQueryFactory.php | 2 +- ...natedSettlementChargebacksQueryFactory.php | 2 +- ...PaginatedSettlementRefundsQueryFactory.php | 2 +- .../GetPaginatedSettlementsQueryFactory.php | 2 +- .../GetPaymentCaptureQueryFactory.php | 2 +- .../GetPaymentChargebackQueryFactory.php | 2 +- .../GetPaymentMethodQueryFactory.php | 2 +- src/Factories/GetPaymentQueryFactory.php | 2 +- .../GetPaymentRefundQueryFactory.php | 2 +- .../InvoiceLineCollectionFactory.php | 4 +- src/Factories/InvoiceLineFactory.php | 6 +- src/Factories/MoneyFactory.php | 2 +- src/Factories/OrderLineCollectionFactory.php | 4 +- src/Factories/OrderLineFactory.php | 8 +- src/Factories/PaginatedQueryFactory.php | 2 +- .../PaymentRouteCollectionFactory.php | 6 +- src/Factories/RecipientFactory.php | 2 +- .../RecurringBillingCycleFactory.php | 6 +- .../RefundRouteCollectionFactory.php | 4 +- .../SortablePaginatedQueryFactory.php | 2 +- .../UpdateCustomerPayloadFactory.php | 4 +- .../UpdatePaymentLinkPayloadFactory.php | 2 +- src/Factories/UpdatePaymentPayloadFactory.php | 4 +- .../UpdatePaymentRoutePayloadFactory.php | 2 +- src/Factories/UpdateProfilePayloadFactory.php | 2 +- .../UpdateSalesInvoicePayloadFactory.php | 18 ++-- .../UpdateSubscriptionPayloadFactory.php | 8 +- src/Helpers/Arr.php | 37 ++++++++ src/Http/{Payload => Data}/Address.php | 2 +- .../AnyPayload.php => Data/AnyData.php} | 4 +- src/Http/{Payload => Data}/ApplicationFee.php | 4 +- .../CreateClientLinkPayload.php | 4 +- .../CreateCustomerPayload.php | 4 +- .../CreateMandatePayload.php | 4 +- .../CreatePaymentCapturePayload.php | 4 +- .../CreatePaymentLinkPayload.php | 4 +- .../CreatePaymentPayload.php | 4 +- .../{Query => Data}/CreatePaymentQuery.php | 5 +- .../CreateProfilePayload.php | 4 +- .../CreateRefundPaymentPayload.php | 8 +- .../CreateSalesInvoicePayload.php | 4 +- .../CreateSubscriptionPayload.php | 4 +- src/Http/Data/Data.php | 14 +++ src/Http/{Payload => Data}/DataCollection.php | 15 ++-- src/Http/{Payload => Data}/Discount.php | 2 +- src/Http/{Payload => Data}/EmailDetails.php | 2 +- .../{Query => Data}/GetAllMethodsQuery.php | 7 +- .../GetAllPaginatedSubscriptionsQuery.php | 6 +- .../{Query => Data}/GetBalanceReportQuery.php | 9 +- src/Http/{Query => Data}/GetClientQuery.php | 5 +- .../GetEnabledPaymentMethodsQuery.php | 7 +- .../GetPaginatedBalanceQuery.php | 6 +- .../GetPaginatedChargebackQuery.php | 5 +- .../GetPaginatedClientQuery.php | 4 +- .../GetPaginatedCustomerPaymentsQuery.php | 6 +- .../GetPaginatedInvoiceQuery.php | 6 +- .../GetPaginatedPaymentCapturesQuery.php | 4 +- .../GetPaginatedPaymentChargebacksQuery.php | 5 +- .../GetPaginatedPaymentRefundQuery.php | 5 +- .../GetPaginatedRefundsQuery.php | 5 +- .../GetPaginatedSettlementCapturesQuery.php | 2 +- ...GetPaginatedSettlementChargebacksQuery.php | 2 +- .../GetPaginatedSettlementRefundsQuery.php | 2 +- .../GetPaginatedSettlementsQuery.php | 6 +- .../GetPaymentCaptureQuery.php | 4 +- .../GetPaymentChargebackQuery.php | 5 +- .../{Query => Data}/GetPaymentMethodQuery.php | 4 +- src/Http/{Query => Data}/GetPaymentQuery.php | 4 +- .../{Query => Data}/GetPaymentRefundQuery.php | 5 +- src/Http/{Payload => Data}/InvoiceLine.php | 4 +- src/Http/{Payload => Data}/Metadata.php | 2 +- src/Http/{Payload => Data}/Money.php | 2 +- src/Http/{Payload => Data}/OrderLine.php | 4 +- src/Http/{Payload => Data}/Owner.php | 2 +- src/Http/{Payload => Data}/OwnerAddress.php | 2 +- src/Http/{Query => Data}/PaginatedQuery.php | 6 +- src/Http/{Payload => Data}/PaymentDetails.php | 2 +- src/Http/{Payload => Data}/PaymentRoute.php | 6 +- src/Http/{Payload => Data}/Recipient.php | 2 +- .../RecurringBillingCycle.php | 6 +- src/Http/{Payload => Data}/RefundRoute.php | 4 +- .../RequestApplePayPaymentSessionPayload.php | 4 +- .../SortablePaginatedQuery.php | 2 +- .../UpdateCustomerPayload.php | 2 +- .../UpdatePaymentLinkPayload.php | 4 +- .../UpdatePaymentPayload.php | 4 +- .../UpdatePaymentRoutePayload.php | 6 +- .../UpdateProfilePayload.php | 4 +- .../UpdateSalesInvoicePayload.php | 4 +- .../UpdateSubscriptionPayload.php | 6 +- src/Http/Payload/DataBag.php | 12 --- src/Http/Query/AnyQuery.php | 23 ----- .../ApplePayPaymentSessionRequest.php | 2 +- src/Http/Requests/CreateClientLinkRequest.php | 2 +- .../Requests/CreateCustomerPaymentRequest.php | 4 +- src/Http/Requests/CreateCustomerRequest.php | 2 +- src/Http/Requests/CreateMandateRequest.php | 2 +- .../Requests/CreatePaymentCaptureRequest.php | 2 +- .../Requests/CreatePaymentLinkRequest.php | 2 +- .../Requests/CreatePaymentRefundRequest.php | 2 +- src/Http/Requests/CreatePaymentRequest.php | 4 +- src/Http/Requests/CreateProfileRequest.php | 2 +- .../Requests/CreateSalesInvoiceRequest.php | 2 +- src/Http/Requests/CreateSessionRequest.php | 9 +- .../Requests/CreateSubscriptionRequest.php | 2 +- src/Http/Requests/GetAllMethodsRequest.php | 2 +- src/Http/Requests/GetBalanceReportRequest.php | 2 +- src/Http/Requests/GetClientRequest.php | 2 +- .../Requests/GetEnabledMethodsRequest.php | 2 +- .../GetPaginatedBalanceTransactionRequest.php | 2 +- .../GetPaginatedCustomerPaymentsRequest.php | 2 +- .../Requests/GetPaginatedMandateRequest.php | 2 +- .../GetPaginatedPaymentCapturesRequest.php | 2 +- .../GetPaginatedPaymentChargebacksRequest.php | 2 +- ...GetPaginatedPaymentLinkPaymentsRequest.php | 2 +- .../GetPaginatedPaymentRefundsRequest.php | 2 +- .../GetPaginatedSettlementCapturesRequest.php | 2 +- ...tPaginatedSettlementChargebacksRequest.php | 2 +- .../GetPaginatedSettlementPaymentsRequest.php | 2 +- .../GetPaginatedSettlementRefundsRequest.php | 2 +- ...etPaginatedSubscriptionPaymentsRequest.php | 2 +- .../GetPaginatedSubscriptionsRequest.php | 2 +- .../Requests/GetPaymentCaptureRequest.php | 2 +- .../Requests/GetPaymentChargebackRequest.php | 2 +- src/Http/Requests/GetPaymentMethodRequest.php | 2 +- src/Http/Requests/GetPaymentRefundRequest.php | 2 +- src/Http/Requests/GetPaymentRequest.php | 2 +- src/Http/Requests/GetSessionRequest.php | 6 +- src/Http/Requests/UpdateCustomerRequest.php | 2 +- .../Requests/UpdatePaymentLinkRequest.php | 2 +- src/Http/Requests/UpdatePaymentRequest.php | 2 +- .../Requests/UpdatePaymentRouteRequest.php | 2 +- src/Http/Requests/UpdateProfileRequest.php | 2 +- .../Requests/UpdateSalesInvoiceRequest.php | 2 +- src/Http/Requests/UpdateSessionRequest.php | 6 +- .../Requests/UpdateSubscriptionRequest.php | 2 +- src/Resources/Payment.php | 4 +- src/Traits/Makeable.php | 11 --- src/Traits/ResolvesValues.php | 33 ------- .../ClientLinkEndpointCollectionTest.php | 6 +- ...CustomerPaymentsEndpointCollectionTest.php | 4 +- .../MandateEndpointCollectionTest.php | 2 +- .../PaymentCaptureEndpointCollectionTest.php | 4 +- .../PaymentEndpointCollectionTest.php | 8 +- .../PaymentLinkEndpointCollectionTest.php | 6 +- .../ProfileEndpointCollectionTest.php | 4 +- .../SalesInvoiceEndpointCollectionTest.php | 12 +-- .../SessionEndpointCollectionTest.php | 11 ++- tests/Helpers/ArrTest.php | 57 ++++++++++++ tests/Helpers/HelpersTest.php | 6 +- .../ApplePayPaymentSessionRequestTest.php | 2 +- .../Requests/CreateClientLinkRequestTest.php | 6 +- .../CreateCustomerPaymentRequestTest.php | 6 +- .../Requests/CreateCustomerRequestTest.php | 2 +- .../Requests/CreateMandateRequestTest.php | 2 +- .../CreatePaymentCaptureRequestTest.php | 4 +- .../Requests/CreatePaymentLinkRequestTest.php | 4 +- .../CreatePaymentRefundRequestTest.php | 4 +- .../Requests/CreatePaymentRequestTest.php | 4 +- .../Requests/CreateProfileRequestTest.php | 2 +- .../CreateSalesInvoiceRequestTest.php | 10 +-- .../Requests/CreateSessionRequestTest.php | 9 +- .../CreateSubscriptionRequestTest.php | 4 +- .../Requests/GetBalanceReportRequestTest.php | 2 +- ...ginatedSubscriptionPaymentsRequestTest.php | 2 +- tests/Http/Requests/GetSessionRequestTest.php | 6 +- .../Requests/UpdateCustomerRequestTest.php | 2 +- .../Requests/UpdatePaymentLinkRequestTest.php | 2 +- .../Requests/UpdatePaymentRequestTest.php | 2 +- .../UpdatePaymentRouteRequestTest.php | 2 +- .../Requests/UpdateProfileRequestTest.php | 2 +- .../UpdateSalesInvoiceRequestTest.php | 2 +- .../Requests/UpdateSessionRequestTest.php | 6 +- .../UpdateSubscriptionRequestTest.php | 4 +- tests/MollieApiClientTest.php | 6 +- tests/Traits/ResolvesValuesTest.php | 89 ------------------- 234 files changed, 551 insertions(+), 672 deletions(-) delete mode 100644 src/Contracts/DataResolver.php rename src/Http/{Payload => Data}/Address.php (98%) rename src/Http/{Payload/AnyPayload.php => Data/AnyData.php} (81%) rename src/Http/{Payload => Data}/ApplicationFee.php (85%) rename src/Http/{Payload => Data}/CreateClientLinkPayload.php (91%) rename src/Http/{Payload => Data}/CreateCustomerPayload.php (89%) rename src/Http/{Payload => Data}/CreateMandatePayload.php (95%) rename src/Http/{Payload => Data}/CreatePaymentCapturePayload.php (87%) rename src/Http/{Payload => Data}/CreatePaymentLinkPayload.php (93%) rename src/Http/{Payload => Data}/CreatePaymentPayload.php (98%) rename src/Http/{Query => Data}/CreatePaymentQuery.php (79%) rename src/Http/{Payload => Data}/CreateProfilePayload.php (93%) rename src/Http/{Payload => Data}/CreateRefundPaymentPayload.php (88%) rename src/Http/{Payload => Data}/CreateSalesInvoicePayload.php (96%) rename src/Http/{Payload => Data}/CreateSubscriptionPayload.php (95%) create mode 100644 src/Http/Data/Data.php rename src/Http/{Payload => Data}/DataCollection.php (72%) rename src/Http/{Payload => Data}/Discount.php (93%) rename src/Http/{Payload => Data}/EmailDetails.php (93%) rename src/Http/{Query => Data}/GetAllMethodsQuery.php (85%) rename src/Http/{Query => Data}/GetAllPaginatedSubscriptionsQuery.php (77%) rename src/Http/{Query => Data}/GetBalanceReportQuery.php (69%) rename src/Http/{Query => Data}/GetClientQuery.php (85%) rename src/Http/{Query => Data}/GetEnabledPaymentMethodsQuery.php (92%) rename src/Http/{Query => Data}/GetPaginatedBalanceQuery.php (80%) rename src/Http/{Query => Data}/GetPaginatedChargebackQuery.php (86%) rename src/Http/{Query => Data}/GetPaginatedClientQuery.php (91%) rename src/Http/{Query => Data}/GetPaginatedCustomerPaymentsQuery.php (80%) rename src/Http/{Query => Data}/GetPaginatedInvoiceQuery.php (83%) rename src/Http/{Query => Data}/GetPaginatedPaymentCapturesQuery.php (88%) rename src/Http/{Query => Data}/GetPaginatedPaymentChargebacksQuery.php (82%) rename src/Http/{Query => Data}/GetPaginatedPaymentRefundQuery.php (82%) rename src/Http/{Query => Data}/GetPaginatedRefundsQuery.php (86%) rename src/Http/{Query => Data}/GetPaginatedSettlementCapturesQuery.php (74%) rename src/Http/{Query => Data}/GetPaginatedSettlementChargebacksQuery.php (75%) rename src/Http/{Query => Data}/GetPaginatedSettlementRefundsQuery.php (75%) rename src/Http/{Query => Data}/GetPaginatedSettlementsQuery.php (78%) rename src/Http/{Query => Data}/GetPaymentCaptureQuery.php (85%) rename src/Http/{Query => Data}/GetPaymentChargebackQuery.php (76%) rename src/Http/{Query => Data}/GetPaymentMethodQuery.php (93%) rename src/Http/{Query => Data}/GetPaymentQuery.php (94%) rename src/Http/{Query => Data}/GetPaymentRefundQuery.php (76%) rename src/Http/{Payload => Data}/InvoiceLine.php (92%) rename src/Http/{Payload => Data}/Metadata.php (88%) rename src/Http/{Payload => Data}/Money.php (92%) rename src/Http/{Payload => Data}/OrderLine.php (96%) rename src/Http/{Payload => Data}/Owner.php (95%) rename src/Http/{Payload => Data}/OwnerAddress.php (96%) rename src/Http/{Query => Data}/PaginatedQuery.php (77%) rename src/Http/{Payload => Data}/PaymentDetails.php (94%) rename src/Http/{Payload => Data}/PaymentRoute.php (83%) rename src/Http/{Payload => Data}/Recipient.php (98%) rename src/Http/{Payload => Data}/RecurringBillingCycle.php (87%) rename src/Http/{Payload => Data}/RefundRoute.php (88%) rename src/Http/{Payload => Data}/RequestApplePayPaymentSessionPayload.php (86%) rename src/Http/{Query => Data}/SortablePaginatedQuery.php (93%) rename src/Http/{Payload => Data}/UpdateCustomerPayload.php (68%) rename src/Http/{Payload => Data}/UpdatePaymentLinkPayload.php (83%) rename src/Http/{Payload => Data}/UpdatePaymentPayload.php (95%) rename src/Http/{Payload => Data}/UpdatePaymentRoutePayload.php (65%) rename src/Http/{Payload => Data}/UpdateProfilePayload.php (94%) rename src/Http/{Payload => Data}/UpdateSalesInvoicePayload.php (95%) rename src/Http/{Payload => Data}/UpdateSubscriptionPayload.php (88%) delete mode 100644 src/Http/Payload/DataBag.php delete mode 100644 src/Http/Query/AnyQuery.php delete mode 100644 src/Traits/Makeable.php delete mode 100644 src/Traits/ResolvesValues.php delete mode 100644 tests/Traits/ResolvesValuesTest.php diff --git a/README.md b/README.md index e0eb9a60b..a96330bf7 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,8 @@ Find our full documentation online on [docs.mollie.com](https://docs.mollie.com) #### Example usage #### ```php -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; $payload = new CreatePaymentPayload( diff --git a/UPGRADING.md b/UPGRADING.md index 57d09c1a2..a482b5927 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -191,8 +191,8 @@ With this approach you can use new Objects and therefore actually know what data ```php // improved -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; $payload = new CreatePaymentPayload( description: 'My first API payment', @@ -213,8 +213,8 @@ Finally, the new way of interacting with the client: ```php // newest ;-) -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; $payload = new CreatePaymentPayload( diff --git a/docs/endpoint-collections.md b/docs/endpoint-collections.md index 4dee3bf8a..c1f326a9a 100644 --- a/docs/endpoint-collections.md +++ b/docs/endpoint-collections.md @@ -40,8 +40,8 @@ $payment = $mollie->payments->create([ **Advanced: Using typed payloads/queries** This approach provides full IDE support and type safety: ```php -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; $payment = $mollie->payments->create( new CreatePaymentPayload( @@ -53,7 +53,7 @@ $payment = $mollie->payments->create( If you have an array and need to interact with the payload or query, you can use a dedicated factory to convert the array into a typed class. -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Factories\CreatePaymentPayloadFactory; // Fully untyped data @@ -371,8 +371,8 @@ $permissions = $mollie->permissions->list(); ```php // Create a payment using typed payload -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; $payload = new CreatePaymentPayload( description: 'Order #12345', @@ -763,16 +763,10 @@ try { ## Common Data Types -**Shared Payloads:** - `Money` - For handling currency amounts -- `Address` - For handling address information - `Metadata` - For handling custom metadata - `DataCollection` - For handling collections of data -- `ApplicationFee` - For handling application fees - -**Base Classes:** -- `DataBag` - Base class for payload objects -- `Query` - Base class for query objects +- `Data` - Base class for payload/query objects ## Factories diff --git a/docs/requests.md b/docs/requests.md index cae956b9a..6af82fecf 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -23,8 +23,8 @@ To send a request using the Mollie API client, you typically need to: Use the client to send the request and handle the response. ```php use Mollie\Api\MollieApiClient; - use Mollie\Api\Http\Payload\Money; - use Mollie\Api\Http\Payload\CreatePaymentPayload; + use Mollie\Api\Http\Data\Money; + use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; $mollie = new MollieApiClient(); diff --git a/docs/testing.md b/docs/testing.md index 2e3e9b95d..f5888d9c7 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -28,8 +28,8 @@ For specific control, you can enable test mode per request. This is useful for m ```php // Creating a payment in test mode use Mollie\Api\MollieApiClient; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; $mollie = new MollieApiClient(); diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index 580323df8..13b765181 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -4,8 +4,8 @@ * How to prepare a new payment with the Mollie API. */ -use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; try { @@ -29,7 +29,7 @@ $capture = $response->toResource(); - echo '

      New capture created '.htmlspecialchars($capture->id).' ('.htmlspecialchars($capture->description).').

      '; + echo '

      New capture created ' . htmlspecialchars($capture->id) . ' (' . htmlspecialchars($capture->description) . ').

      '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: '.htmlspecialchars($e->getMessage()); + echo 'API call failed: ' . htmlspecialchars($e->getMessage()); } diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index e4c3a9d1c..a837d4d3d 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -4,9 +4,9 @@ * How to create a new client link in the Mollie API. */ -use Mollie\Api\Http\Payload\CreateClientLinkPayload; -use Mollie\Api\Http\Payload\Owner; -use Mollie\Api\Http\Payload\OwnerAddress; +use Mollie\Api\Http\Data\CreateClientLinkPayload; +use Mollie\Api\Http\Data\Owner; +use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; try { @@ -53,7 +53,7 @@ * Send the customer off to finalize the organization creation. * This request should always be a GET, thus we enforce 303 http response code */ - header('Location: '.$redirectUrl, true, 303); + header('Location: ' . $redirectUrl, true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: '.htmlspecialchars($e->getMessage()); + echo 'API call failed: ' . htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index 3a85afd42..bd2cc177c 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -5,8 +5,8 @@ */ use Mollie\Api\Factories\CreatePaymentPayloadFactory; -use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Types\SequenceType; @@ -67,7 +67,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header('Location: '.$payment->getCheckoutUrl(), true, 303); + header('Location: ' . $payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: '.htmlspecialchars($e->getMessage()); + echo 'API call failed: ' . htmlspecialchars($e->getMessage()); } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 740418359..9dd9e3cce 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -270,23 +270,11 @@ parameters: count: 1 path: examples/subscriptions/update-subscription.php - - - message: '#^Unsafe usage of new static\(\)\.$#' - identifier: new.static - count: 1 - path: src/CompatibilityChecker.php - - - - message: '#^Unsafe usage of new static\(\)\.$#' - identifier: new.static - count: 1 - path: src/Http/Payload/CreateRefundPaymentPayload.php - - message: '#^Unsafe usage of new static\(\)\.$#' identifier: new.static count: 4 - path: src/Http/Payload/DataCollection.php + path: src/Http/Data/DataCollection.php - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index 79d9b1bff..9725ec166 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -3,17 +3,19 @@ namespace Mollie\Api; use Mollie\Api\Exceptions\IncompatiblePlatform; -use Mollie\Api\Traits\Makeable; class CompatibilityChecker { - use Makeable; - /** * @var string */ public const MIN_PHP_VERSION = '7.4'; + public static function make(): self + { + return new self; + } + /** * @return void * @@ -23,7 +25,7 @@ public function checkCompatibility() { if (! $this->satisfiesPhpVersion()) { throw new IncompatiblePlatform( - 'The client requires PHP version >= '.self::MIN_PHP_VERSION.', you have '.PHP_VERSION.'.', + 'The client requires PHP version >= ' . self::MIN_PHP_VERSION . ', you have ' . PHP_VERSION . '.', IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION ); } diff --git a/src/Contracts/DataResolver.php b/src/Contracts/DataResolver.php deleted file mode 100644 index d660ce4ad..000000000 --- a/src/Contracts/DataResolver.php +++ /dev/null @@ -1,11 +0,0 @@ -get('consumerAccount'), $this->get('consumerBic'), $this->get('consumerEmail'), - $this->mapIfNotNull('signatureDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('signatureDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('mandateReference'), $this->get('paypalBillingAgreementId'), ); diff --git a/src/Factories/CreatePaymentCapturePayloadFactory.php b/src/Factories/CreatePaymentCapturePayloadFactory.php index b1795d2bb..a67d45973 100644 --- a/src/Factories/CreatePaymentCapturePayloadFactory.php +++ b/src/Factories/CreatePaymentCapturePayloadFactory.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; -use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Data\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\Metadata; class CreatePaymentCapturePayloadFactory extends Factory { @@ -11,7 +11,7 @@ public function create(): CreatePaymentCapturePayload { return new CreatePaymentCapturePayload( $this->get('description'), - $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('amount', fn(array $item) => MoneyFactory::new($item)->create()), $this->mapIfNotNull('metadata', Metadata::class) ); } diff --git a/src/Factories/CreatePaymentLinkPayloadFactory.php b/src/Factories/CreatePaymentLinkPayloadFactory.php index 269537597..de773cf16 100644 --- a/src/Factories/CreatePaymentLinkPayloadFactory.php +++ b/src/Factories/CreatePaymentLinkPayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreatePaymentLinkPayload; +use Mollie\Api\Http\Data\CreatePaymentLinkPayload; class CreatePaymentLinkPayloadFactory extends Factory { @@ -10,7 +10,7 @@ public function create(): CreatePaymentLinkPayload { return new CreatePaymentLinkPayload( $this->get('description'), - $this->mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), + $this->mapIfNotNull('amount', fn(array $amount) => MoneyFactory::new($amount)->create()), $this->get('redirectUrl'), $this->get('webhookUrl'), $this->get('profileId'), diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index 96cfade12..a58f9fe98 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Factories; use Mollie\Api\Helpers; -use Mollie\Api\Http\Payload\Address; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Data\Address; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\Metadata; class CreatePaymentPayloadFactory extends Factory { @@ -20,10 +20,10 @@ public function create(): CreatePaymentPayload $this ->mapIfNotNull( 'lines', - fn (array $items) => OrderLineCollectionFactory::new($items)->create() + fn(array $items) => OrderLineCollectionFactory::new($items)->create() ), - $this->mapIfNotNull('billingAddress', fn (array $item) => Address::fromArray($item)), - $this->mapIfNotNull('shippingAddress', fn (array $item) => Address::fromArray($item)), + $this->mapIfNotNull('billingAddress', fn(array $item) => Address::fromArray($item)), + $this->mapIfNotNull('shippingAddress', fn(array $item) => Address::fromArray($item)), $this->get('locale'), $this->get('method'), $this->get('issuer'), @@ -33,11 +33,11 @@ public function create(): CreatePaymentPayload $this->get('captureDelay'), $this->mapIfNotNull( 'applicationFee', - fn (array $item) => ApplicationFeeFactory::new($item)->create() + fn(array $item) => ApplicationFeeFactory::new($item)->create() ), $this->mapIfNotNull( 'routing', - fn (array $items) => PaymentRouteCollectionFactory::new($items)->create() + fn(array $items) => PaymentRouteCollectionFactory::new($items)->create() ), $this->get('sequenceType'), $this->get('mandateId'), diff --git a/src/Factories/CreateProfilePayloadFactory.php b/src/Factories/CreateProfilePayloadFactory.php index b3e9161dd..c0357b5fd 100644 --- a/src/Factories/CreateProfilePayloadFactory.php +++ b/src/Factories/CreateProfilePayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreateProfilePayload; +use Mollie\Api\Http\Data\CreateProfilePayload; class CreateProfilePayloadFactory extends Factory { diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php index ad8e03db2..2255461c4 100644 --- a/src/Factories/CreateRefundPaymentPayloadFactory.php +++ b/src/Factories/CreateRefundPaymentPayloadFactory.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; -use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Data\CreateRefundPaymentPayload; +use Mollie\Api\Http\Data\Metadata; class CreateRefundPaymentPayloadFactory extends Factory { @@ -17,7 +17,7 @@ public function create(): CreateRefundPaymentPayload $this ->mapIfNotNull( 'routingReversals', - fn (array $items) => RefundRouteCollectionFactory::new($items)->create() + fn(array $items) => RefundRouteCollectionFactory::new($items)->create() ), ); } diff --git a/src/Factories/CreateSalesInvoicePayloadFactory.php b/src/Factories/CreateSalesInvoicePayloadFactory.php index cfb2d67d4..3712263a7 100644 --- a/src/Factories/CreateSalesInvoicePayloadFactory.php +++ b/src/Factories/CreateSalesInvoicePayloadFactory.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\CreateSalesInvoicePayload; -use Mollie\Api\Http\Payload\Discount; -use Mollie\Api\Http\Payload\EmailDetails; -use Mollie\Api\Http\Payload\PaymentDetails; +use Mollie\Api\Http\Data\CreateSalesInvoicePayload; +use Mollie\Api\Http\Data\Discount; +use Mollie\Api\Http\Data\EmailDetails; +use Mollie\Api\Http\Data\PaymentDetails; class CreateSalesInvoicePayloadFactory extends Factory { @@ -25,14 +25,14 @@ public function create(): CreateSalesInvoicePayload $this ->mapIfNotNull( 'lines', - fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('profileId'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/CreateSubscriptionPayloadFactory.php b/src/Factories/CreateSubscriptionPayloadFactory.php index 2e55fe61a..02037be97 100644 --- a/src/Factories/CreateSubscriptionPayloadFactory.php +++ b/src/Factories/CreateSubscriptionPayloadFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Http\Payload\CreateSubscriptionPayload; -use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Data\CreateSubscriptionPayload; +use Mollie\Api\Http\Data\Metadata; class CreateSubscriptionPayloadFactory extends Factory { @@ -16,9 +16,9 @@ public function create(): CreateSubscriptionPayload $this->get('description'), $this->get('status'), $this->get('times'), - $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('startDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('method'), - $this->mapIfNotNull('applicationFee', fn (array $fee) => ApplicationFeeFactory::new($fee)->create()), + $this->mapIfNotNull('applicationFee', fn(array $fee) => ApplicationFeeFactory::new($fee)->create()), $this->mapIfNotNull('metadata', Metadata::class), $this->get('webhookUrl'), $this->get('mandateId'), diff --git a/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php b/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php index 2264597a6..23837a335 100644 --- a/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php +++ b/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetAllPaginatedSubscriptionsQuery; +use Mollie\Api\Http\Data\GetAllPaginatedSubscriptionsQuery; class GetAllPaginatedSubscriptionsQueryFactory extends Factory { diff --git a/src/Factories/GetAllPaymentMethodsQueryFactory.php b/src/Factories/GetAllPaymentMethodsQueryFactory.php index 2c82b718d..eba8e55f2 100644 --- a/src/Factories/GetAllPaymentMethodsQueryFactory.php +++ b/src/Factories/GetAllPaymentMethodsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetAllMethodsQuery; +use Mollie\Api\Http\Data\GetAllMethodsQuery; use Mollie\Api\Types\MethodQuery; class GetAllPaymentMethodsQueryFactory extends Factory diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php index 10e519808..f0da20016 100644 --- a/src/Factories/GetBalanceReportQueryFactory.php +++ b/src/Factories/GetBalanceReportQueryFactory.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Http\Query\GetBalanceReportQuery; +use Mollie\Api\Http\Data\GetBalanceReportQuery; class GetBalanceReportQueryFactory extends Factory { diff --git a/src/Factories/GetClientQueryFactory.php b/src/Factories/GetClientQueryFactory.php index 5809702d6..7e8e47c4d 100644 --- a/src/Factories/GetClientQueryFactory.php +++ b/src/Factories/GetClientQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetClientQuery; +use Mollie\Api\Http\Data\GetClientQuery; use Mollie\Api\Types\ClientQuery; class GetClientQueryFactory extends Factory diff --git a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php index 0898bd992..8d7a32225 100644 --- a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php +++ b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; +use Mollie\Api\Http\Data\GetEnabledPaymentMethodsQuery; use Mollie\Api\Types\MethodQuery; class GetEnabledPaymentMethodsQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedBalanceQueryFactory.php b/src/Factories/GetPaginatedBalanceQueryFactory.php index cde0fb5ed..438e0e8f1 100644 --- a/src/Factories/GetPaginatedBalanceQueryFactory.php +++ b/src/Factories/GetPaginatedBalanceQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedBalanceQuery; +use Mollie\Api\Http\Data\GetPaginatedBalanceQuery; class GetPaginatedBalanceQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php index 47cd66c8b..9823d81af 100644 --- a/src/Factories/GetPaginatedChargebackQueryFactory.php +++ b/src/Factories/GetPaginatedChargebackQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedChargebackQuery; +use Mollie\Api\Http\Data\GetPaginatedChargebackQuery; class GetPaginatedChargebackQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php index bb0389efe..214b32629 100644 --- a/src/Factories/GetPaginatedClientQueryFactory.php +++ b/src/Factories/GetPaginatedClientQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedClientQuery; +use Mollie\Api\Http\Data\GetPaginatedClientQuery; use Mollie\Api\Types\ClientQuery; class GetPaginatedClientQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php b/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php index b0f7ca188..1317452eb 100644 --- a/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php +++ b/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedCustomerPaymentsQuery; +use Mollie\Api\Http\Data\GetPaginatedCustomerPaymentsQuery; class GetPaginatedCustomerPaymentsQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedInvoiceQueryFactory.php b/src/Factories/GetPaginatedInvoiceQueryFactory.php index b4a2ccc01..c7cb97481 100644 --- a/src/Factories/GetPaginatedInvoiceQueryFactory.php +++ b/src/Factories/GetPaginatedInvoiceQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedInvoiceQuery; +use Mollie\Api\Http\Data\GetPaginatedInvoiceQuery; class GetPaginatedInvoiceQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php index 7ff046330..eff146b1d 100644 --- a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedPaymentCapturesQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentCapturesQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php index 407720bb0..47998792e 100644 --- a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedPaymentChargebacksQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentChargebacksQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php index 1af7b443d..ecc44959d 100644 --- a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedPaymentRefundQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentRefundQuery; class GetPaginatedPaymentRefundQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedRefundsQueryFactory.php b/src/Factories/GetPaginatedRefundsQueryFactory.php index 22c441518..780ca39a3 100644 --- a/src/Factories/GetPaginatedRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedRefundsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedRefundsQuery; +use Mollie\Api\Http\Data\GetPaginatedRefundsQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedRefundsQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php index 665547a42..27e769c7a 100644 --- a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedSettlementCapturesQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedSettlementCapturesQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php b/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php index 102f585cf..196f236eb 100644 --- a/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedSettlementChargebacksQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; class GetPaginatedSettlementChargebacksQueryFactory extends Factory { diff --git a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php index 7f688d3b1..50b42c5e1 100644 --- a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedSettlementRefundsQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedSettlementRefundsQueryFactory extends Factory diff --git a/src/Factories/GetPaginatedSettlementsQueryFactory.php b/src/Factories/GetPaginatedSettlementsQueryFactory.php index 23f91401a..e31c6e436 100644 --- a/src/Factories/GetPaginatedSettlementsQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementsQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaginatedSettlementsQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementsQuery; class GetPaginatedSettlementsQueryFactory extends Factory { diff --git a/src/Factories/GetPaymentCaptureQueryFactory.php b/src/Factories/GetPaymentCaptureQueryFactory.php index 7e06edd8a..cd8c538ea 100644 --- a/src/Factories/GetPaymentCaptureQueryFactory.php +++ b/src/Factories/GetPaymentCaptureQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaymentCaptureQuery; +use Mollie\Api\Http\Data\GetPaymentCaptureQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentCaptureQueryFactory extends Factory diff --git a/src/Factories/GetPaymentChargebackQueryFactory.php b/src/Factories/GetPaymentChargebackQueryFactory.php index 53f9bb119..b1bf16a24 100644 --- a/src/Factories/GetPaymentChargebackQueryFactory.php +++ b/src/Factories/GetPaymentChargebackQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaymentChargebackQuery; +use Mollie\Api\Http\Data\GetPaymentChargebackQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentChargebackQueryFactory extends Factory diff --git a/src/Factories/GetPaymentMethodQueryFactory.php b/src/Factories/GetPaymentMethodQueryFactory.php index 809ecacb1..330d50c4e 100644 --- a/src/Factories/GetPaymentMethodQueryFactory.php +++ b/src/Factories/GetPaymentMethodQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaymentMethodQuery; +use Mollie\Api\Http\Data\GetPaymentMethodQuery; use Mollie\Api\Types\MethodQuery; class GetPaymentMethodQueryFactory extends Factory diff --git a/src/Factories/GetPaymentQueryFactory.php b/src/Factories/GetPaymentQueryFactory.php index 1af71fc43..4740ab13a 100644 --- a/src/Factories/GetPaymentQueryFactory.php +++ b/src/Factories/GetPaymentQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaymentQuery; +use Mollie\Api\Http\Data\GetPaymentQuery; use Mollie\Api\Types\PaymentQuery; class GetPaymentQueryFactory extends Factory diff --git a/src/Factories/GetPaymentRefundQueryFactory.php b/src/Factories/GetPaymentRefundQueryFactory.php index aac2e7258..626627836 100644 --- a/src/Factories/GetPaymentRefundQueryFactory.php +++ b/src/Factories/GetPaymentRefundQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\GetPaymentRefundQuery; +use Mollie\Api\Http\Data\GetPaymentRefundQuery; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentRefundQueryFactory extends Factory diff --git a/src/Factories/InvoiceLineCollectionFactory.php b/src/Factories/InvoiceLineCollectionFactory.php index e457ebef9..3752b0973 100644 --- a/src/Factories/InvoiceLineCollectionFactory.php +++ b/src/Factories/InvoiceLineCollectionFactory.php @@ -2,14 +2,14 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\DataCollection; +use Mollie\Api\Http\Data\DataCollection; class InvoiceLineCollectionFactory extends Factory { public function create(): DataCollection { return new DataCollection(array_map( - fn (array $item) => InvoiceLineFactory::new($item)->create(), + fn(array $item) => InvoiceLineFactory::new($item)->create(), $this->data )); } diff --git a/src/Factories/InvoiceLineFactory.php b/src/Factories/InvoiceLineFactory.php index bb5a2c2b7..6dac4317d 100644 --- a/src/Factories/InvoiceLineFactory.php +++ b/src/Factories/InvoiceLineFactory.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\Discount; -use Mollie\Api\Http\Payload\InvoiceLine; +use Mollie\Api\Http\Data\Discount; +use Mollie\Api\Http\Data\InvoiceLine; class InvoiceLineFactory extends Factory { @@ -14,7 +14,7 @@ public function create(): InvoiceLine $this->get('quantity'), $this->get('vatRate'), MoneyFactory::new($this->get('unitPrice'))->create(), - $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/MoneyFactory.php b/src/Factories/MoneyFactory.php index fb9fd2f10..7386921c2 100644 --- a/src/Factories/MoneyFactory.php +++ b/src/Factories/MoneyFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\Money; class MoneyFactory extends Factory { diff --git a/src/Factories/OrderLineCollectionFactory.php b/src/Factories/OrderLineCollectionFactory.php index 1af655510..3b114aa6e 100644 --- a/src/Factories/OrderLineCollectionFactory.php +++ b/src/Factories/OrderLineCollectionFactory.php @@ -2,14 +2,14 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\DataCollection; +use Mollie\Api\Http\Data\DataCollection; class OrderLineCollectionFactory extends Factory { public function create(): DataCollection { return new DataCollection(array_map( - fn (array $item) => OrderLineFactory::new($item)->create(), + fn(array $item) => OrderLineFactory::new($item)->create(), $this->data )); } diff --git a/src/Factories/OrderLineFactory.php b/src/Factories/OrderLineFactory.php index e8920704e..dd9e6714b 100644 --- a/src/Factories/OrderLineFactory.php +++ b/src/Factories/OrderLineFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\OrderLine; +use Mollie\Api\Http\Data\OrderLine; class OrderLineFactory extends Factory { @@ -15,10 +15,10 @@ public function create(): OrderLine MoneyFactory::new($this->get('totalAmount'))->create(), $this->get('type'), $this->get('quantityUnit'), - $this->mapIfNotNull('discountAmount', fn (array $item) => MoneyFactory::new($item)->create()), - $this->mapIfNotNull('recurring', fn (array $item) => RecurringBillingCycleFactory::new($item)->create()), + $this->mapIfNotNull('discountAmount', fn(array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('recurring', fn(array $item) => RecurringBillingCycleFactory::new($item)->create()), $this->get('vatRate'), - $this->mapIfNotNull('vatAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('vatAmount', fn(array $item) => MoneyFactory::new($item)->create()), $this->get('sku'), $this->get('imageUrl'), $this->get('productUrl'), diff --git a/src/Factories/PaginatedQueryFactory.php b/src/Factories/PaginatedQueryFactory.php index d4c62fe6b..98498c459 100644 --- a/src/Factories/PaginatedQueryFactory.php +++ b/src/Factories/PaginatedQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; class PaginatedQueryFactory extends Factory { diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index 678714c80..6700b005b 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -5,8 +5,8 @@ use DateTimeImmutable; use Mollie\Api\Helpers; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Http\Payload\DataCollection; -use Mollie\Api\Http\Payload\PaymentRoute; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\PaymentRoute; class PaymentRouteCollectionFactory extends Factory { @@ -22,7 +22,7 @@ public function create(): DataCollection Arr::get($item, 'destination.organizationId'), Helpers::compose( Arr::get($item, 'delayUntil'), - fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) + fn($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) ) ); }, $this->data); diff --git a/src/Factories/RecipientFactory.php b/src/Factories/RecipientFactory.php index 31d64a878..34a8d0c14 100644 --- a/src/Factories/RecipientFactory.php +++ b/src/Factories/RecipientFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\Recipient; +use Mollie\Api\Http\Data\Recipient; class RecipientFactory extends Factory { diff --git a/src/Factories/RecurringBillingCycleFactory.php b/src/Factories/RecurringBillingCycleFactory.php index 0c0c9c208..a4e051503 100644 --- a/src/Factories/RecurringBillingCycleFactory.php +++ b/src/Factories/RecurringBillingCycleFactory.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Http\Payload\RecurringBillingCycle; +use Mollie\Api\Http\Data\RecurringBillingCycle; class RecurringBillingCycleFactory extends Factory { @@ -12,9 +12,9 @@ public function create(): RecurringBillingCycle return new RecurringBillingCycle( $this->get('interval'), $this->get('descriptipn'), - $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('amount', fn(array $item) => MoneyFactory::new($item)->create()), $this->get('times'), - $this->mapIfNotNull('startDate', fn (string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), + $this->mapIfNotNull('startDate', fn(string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), ); } } diff --git a/src/Factories/RefundRouteCollectionFactory.php b/src/Factories/RefundRouteCollectionFactory.php index 7bb613e1e..271ad282b 100644 --- a/src/Factories/RefundRouteCollectionFactory.php +++ b/src/Factories/RefundRouteCollectionFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Factories; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Http\Payload\DataCollection; -use Mollie\Api\Http\Payload\RefundRoute; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\RefundRoute; class RefundRouteCollectionFactory extends Factory { diff --git a/src/Factories/SortablePaginatedQueryFactory.php b/src/Factories/SortablePaginatedQueryFactory.php index b964bf537..37dad3873 100644 --- a/src/Factories/SortablePaginatedQueryFactory.php +++ b/src/Factories/SortablePaginatedQueryFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Query\SortablePaginatedQuery; +use Mollie\Api\Http\Data\SortablePaginatedQuery; class SortablePaginatedQueryFactory extends Factory { diff --git a/src/Factories/UpdateCustomerPayloadFactory.php b/src/Factories/UpdateCustomerPayloadFactory.php index 100247838..53105dcc9 100644 --- a/src/Factories/UpdateCustomerPayloadFactory.php +++ b/src/Factories/UpdateCustomerPayloadFactory.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\UpdateCustomerPayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\UpdateCustomerPayload; class UpdateCustomerPayloadFactory extends Factory { diff --git a/src/Factories/UpdatePaymentLinkPayloadFactory.php b/src/Factories/UpdatePaymentLinkPayloadFactory.php index e1d12ebbc..5203b6600 100644 --- a/src/Factories/UpdatePaymentLinkPayloadFactory.php +++ b/src/Factories/UpdatePaymentLinkPayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; +use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; class UpdatePaymentLinkPayloadFactory extends Factory { diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php index ba016f2dc..618c350b6 100644 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Factories; use Mollie\Api\Helpers; -use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\UpdatePaymentPayload; class UpdatePaymentPayloadFactory extends Factory { diff --git a/src/Factories/UpdatePaymentRoutePayloadFactory.php b/src/Factories/UpdatePaymentRoutePayloadFactory.php index ea6c48417..f657aa8bd 100644 --- a/src/Factories/UpdatePaymentRoutePayloadFactory.php +++ b/src/Factories/UpdatePaymentRoutePayloadFactory.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Http\Payload\UpdatePaymentRoutePayload; +use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; class UpdatePaymentRoutePayloadFactory extends Factory { diff --git a/src/Factories/UpdateProfilePayloadFactory.php b/src/Factories/UpdateProfilePayloadFactory.php index 94514d904..1c23baeda 100644 --- a/src/Factories/UpdateProfilePayloadFactory.php +++ b/src/Factories/UpdateProfilePayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\UpdateProfilePayload; +use Mollie\Api\Http\Data\UpdateProfilePayload; class UpdateProfilePayloadFactory extends Factory { diff --git a/src/Factories/UpdateSalesInvoicePayloadFactory.php b/src/Factories/UpdateSalesInvoicePayloadFactory.php index e0f323c2c..c995f5241 100644 --- a/src/Factories/UpdateSalesInvoicePayloadFactory.php +++ b/src/Factories/UpdateSalesInvoicePayloadFactory.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Payload\Discount; -use Mollie\Api\Http\Payload\EmailDetails; -use Mollie\Api\Http\Payload\PaymentDetails; -use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; +use Mollie\Api\Http\Data\Discount; +use Mollie\Api\Http\Data\EmailDetails; +use Mollie\Api\Http\Data\PaymentDetails; +use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; class UpdateSalesInvoicePayloadFactory extends Factory { @@ -19,16 +19,16 @@ public function create(): UpdateSalesInvoicePayload $this->get('recipientIdentifier'), $this->get('paymentTerm'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), - $this->mapIfNotNull('recipient', fn (array $data) => RecipientFactory::new($data)->create()), + $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('recipient', fn(array $data) => RecipientFactory::new($data)->create()), $this ->mapIfNotNull( 'lines', - fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/UpdateSubscriptionPayloadFactory.php b/src/Factories/UpdateSubscriptionPayloadFactory.php index ac08e6745..1f8ca482f 100644 --- a/src/Factories/UpdateSubscriptionPayloadFactory.php +++ b/src/Factories/UpdateSubscriptionPayloadFactory.php @@ -3,18 +3,18 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\UpdateSubscriptionPayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\UpdateSubscriptionPayload; class UpdateSubscriptionPayloadFactory extends Factory { public function create(): UpdateSubscriptionPayload { return new UpdateSubscriptionPayload( - $this->mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), + $this->mapIfNotNull('amount', fn(array $amount) => MoneyFactory::new($amount)->create()), $this->get('description'), $this->get('interval'), - $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('startDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('times'), $this->mapIfNotNull('metadata', Metadata::class), $this->get('webhookUrl'), diff --git a/src/Helpers/Arr.php b/src/Helpers/Arr.php index f07aba29b..613871f62 100644 --- a/src/Helpers/Arr.php +++ b/src/Helpers/Arr.php @@ -2,6 +2,12 @@ namespace Mollie\Api\Helpers; +use DateTimeInterface; +use Mollie\Api\Contracts\Arrayable; +use Mollie\Api\Http\Data\Data; +use Mollie\Api\Http\Data\DataCollection; +use Stringable; + class Arr { /** @@ -142,4 +148,35 @@ public static function includes(array $array, $key, $value): bool return false; } + + /** + * Resolve the values of the given array. + * + * @param mixed $values + */ + public static function resolve($values): array + { + return DataCollection::wrap($values) + ->map(function ($value) { + if ($value instanceof Data) { + return static::resolve($value->toArray()); + } + + if ($value instanceof Arrayable) { + return $value->toArray(); + } + + if ($value instanceof Stringable) { + return $value->__toString(); + } + + if ($value instanceof DateTimeInterface) { + return $value->format('Y-m-d'); + } + + return $value; + }) + ->filter() + ->toArray(); + } } diff --git a/src/Http/Payload/Address.php b/src/Http/Data/Address.php similarity index 98% rename from src/Http/Payload/Address.php rename to src/Http/Data/Address.php index caf389aad..dcd4c26e8 100644 --- a/src/Http/Payload/Address.php +++ b/src/Http/Data/Address.php @@ -1,6 +1,6 @@ */ @@ -26,7 +22,10 @@ public function __construct(array $items) $this->items = $items; } - public static function wrap(object $subject): self + /** + * @param mixed $subject + */ + public static function wrap($subject): self { if ($subject instanceof static) { return $subject; diff --git a/src/Http/Payload/Discount.php b/src/Http/Data/Discount.php similarity index 93% rename from src/Http/Payload/Discount.php rename to src/Http/Data/Discount.php index 8d34be771..6434e6a95 100644 --- a/src/Http/Payload/Discount.php +++ b/src/Http/Data/Discount.php @@ -1,6 +1,6 @@ $this->from->format('Y-m-d'), - 'until' => $this->until->format('Y-m-d'), + 'from' => $this->from, + 'until' => $this->until, 'grouping' => $this->grouping, ]; } diff --git a/src/Http/Query/GetClientQuery.php b/src/Http/Data/GetClientQuery.php similarity index 85% rename from src/Http/Query/GetClientQuery.php rename to src/Http/Data/GetClientQuery.php index 9c10a51ac..3d422fdb7 100644 --- a/src/Http/Query/GetClientQuery.php +++ b/src/Http/Data/GetClientQuery.php @@ -1,12 +1,11 @@ $this->organizationId, ], 'delayUntil' => $this->delayUntil - ? $this->delayUntil->format('Y-m-d') - : null, ]; } } diff --git a/src/Http/Payload/Recipient.php b/src/Http/Data/Recipient.php similarity index 98% rename from src/Http/Payload/Recipient.php rename to src/Http/Data/Recipient.php index 5afd881e5..394f7c648 100644 --- a/src/Http/Payload/Recipient.php +++ b/src/Http/Data/Recipient.php @@ -1,6 +1,6 @@ $this->description, 'amount' => $this->amount, 'times' => $this->times, - 'startDate' => $this->startDate->format('Y-m-d'), + 'startDate' => $this->startDate, ]; } } diff --git a/src/Http/Payload/RefundRoute.php b/src/Http/Data/RefundRoute.php similarity index 88% rename from src/Http/Payload/RefundRoute.php rename to src/Http/Data/RefundRoute.php index 09b29054d..e8c2dd7b5 100644 --- a/src/Http/Payload/RefundRoute.php +++ b/src/Http/Data/RefundRoute.php @@ -1,8 +1,8 @@ $this->releaseDate->format('Y-m-d'), + 'releaseDate' => $this->releaseDate, ]; } } diff --git a/src/Http/Payload/UpdateProfilePayload.php b/src/Http/Data/UpdateProfilePayload.php similarity index 94% rename from src/Http/Payload/UpdateProfilePayload.php rename to src/Http/Data/UpdateProfilePayload.php index 53167ae3d..9db3d36cf 100644 --- a/src/Http/Payload/UpdateProfilePayload.php +++ b/src/Http/Data/UpdateProfilePayload.php @@ -1,8 +1,8 @@ $this->amount, 'description' => $this->description, 'interval' => $this->interval, - 'startDate' => $this->startDate ? $this->startDate->format('Y-m-d') : null, + 'startDate' => $this->startDate, 'times' => $this->times, 'metadata' => $this->metadata, 'webhookUrl' => $this->webhookUrl, diff --git a/src/Http/Payload/DataBag.php b/src/Http/Payload/DataBag.php deleted file mode 100644 index b883020d9..000000000 --- a/src/Http/Payload/DataBag.php +++ /dev/null @@ -1,12 +0,0 @@ -data = $data; - } - - public function toArray(): array - { - return $this->data ?? []; - } -} diff --git a/src/Http/Requests/ApplePayPaymentSessionRequest.php b/src/Http/Requests/ApplePayPaymentSessionRequest.php index a445cb4c6..51a95b47f 100644 --- a/src/Http/Requests/ApplePayPaymentSessionRequest.php +++ b/src/Http/Requests/ApplePayPaymentSessionRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\RequestApplePayPaymentSessionPayload; +use Mollie\Api\Http\Data\RequestApplePayPaymentSessionPayload; use Mollie\Api\Resources\AnyResource; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index f6b9cf64e..ce0f6a86a 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\CreateClientLinkPayload; +use Mollie\Api\Http\Data\CreateClientLinkPayload; use Mollie\Api\Resources\ClientLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateCustomerPaymentRequest.php b/src/Http/Requests/CreateCustomerPaymentRequest.php index 352acbd6a..146353ceb 100644 --- a/src/Http/Requests/CreateCustomerPaymentRequest.php +++ b/src/Http/Requests/CreateCustomerPaymentRequest.php @@ -4,8 +4,8 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Query\CreatePaymentQuery; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\CreatePaymentQuery; class CreateCustomerPaymentRequest extends CreatePaymentRequest implements HasPayload, SupportsTestmodeInPayload { diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php index 756ae998a..1e8c8f202 100644 --- a/src/Http/Requests/CreateCustomerRequest.php +++ b/src/Http/Requests/CreateCustomerRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreateCustomerPayload; +use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Resources\Customer; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateMandateRequest.php b/src/Http/Requests/CreateMandateRequest.php index f01a02fac..1495c194b 100644 --- a/src/Http/Requests/CreateMandateRequest.php +++ b/src/Http/Requests/CreateMandateRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreateMandatePayload; +use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Resources\Mandate; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreatePaymentCaptureRequest.php b/src/Http/Requests/CreatePaymentCaptureRequest.php index 473a3bad6..1990cd260 100644 --- a/src/Http/Requests/CreatePaymentCaptureRequest.php +++ b/src/Http/Requests/CreatePaymentCaptureRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Resources\Capture; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreatePaymentLinkRequest.php b/src/Http/Requests/CreatePaymentLinkRequest.php index 677f2f7ab..b29a02fe0 100644 --- a/src/Http/Requests/CreatePaymentLinkRequest.php +++ b/src/Http/Requests/CreatePaymentLinkRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\CreatePaymentLinkPayload; +use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreatePaymentRefundRequest.php b/src/Http/Requests/CreatePaymentRefundRequest.php index 9c7d451ea..b383ef200 100644 --- a/src/Http/Requests/CreatePaymentRefundRequest.php +++ b/src/Http/Requests/CreatePaymentRefundRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; +use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index 6f434ccd0..b01e17aca 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -4,8 +4,8 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Query\CreatePaymentQuery; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateProfileRequest.php b/src/Http/Requests/CreateProfileRequest.php index a16262501..84581b8a3 100644 --- a/src/Http/Requests/CreateProfileRequest.php +++ b/src/Http/Requests/CreateProfileRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\CreateProfilePayload; +use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Resources\Profile; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateSalesInvoiceRequest.php b/src/Http/Requests/CreateSalesInvoiceRequest.php index 0bf03545b..a25ff173c 100644 --- a/src/Http/Requests/CreateSalesInvoiceRequest.php +++ b/src/Http/Requests/CreateSalesInvoiceRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\CreateSalesInvoicePayload; +use Mollie\Api\Http\Data\CreateSalesInvoicePayload; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/CreateSessionRequest.php b/src/Http/Requests/CreateSessionRequest.php index cca615035..b73f1a43a 100644 --- a/src/Http/Requests/CreateSessionRequest.php +++ b/src/Http/Requests/CreateSessionRequest.php @@ -3,8 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\AnyPayload; -use Mollie\Api\Http\Query\AnyQuery; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -17,11 +16,11 @@ class CreateSessionRequest extends ResourceHydratableRequest implements HasPaylo public static string $targetResourceClass = Session::class; - private AnyPayload $payload; + private AnyData $payload; - private AnyQuery $query; + private AnyData $query; - public function __construct(AnyPayload $payload, AnyQuery $query) + public function __construct(AnyData $payload, AnyData $query) { $this->payload = $payload; $this->query = $query; diff --git a/src/Http/Requests/CreateSubscriptionRequest.php b/src/Http/Requests/CreateSubscriptionRequest.php index 91e461411..ecc375676 100644 --- a/src/Http/Requests/CreateSubscriptionRequest.php +++ b/src/Http/Requests/CreateSubscriptionRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\CreateSubscriptionPayload; +use Mollie\Api\Http\Data\CreateSubscriptionPayload; use Mollie\Api\Resources\Subscription; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index 7d600411e..929359c39 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Query\GetAllMethodsQuery; +use Mollie\Api\Http\Data\GetAllMethodsQuery; use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Types\Method as HttpMethod; diff --git a/src/Http/Requests/GetBalanceReportRequest.php b/src/Http/Requests/GetBalanceReportRequest.php index a426ba2ec..b6b7c2633 100644 --- a/src/Http/Requests/GetBalanceReportRequest.php +++ b/src/Http/Requests/GetBalanceReportRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetBalanceReportQuery; +use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Resources\BalanceReport; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 5644822f9..510f2bf2e 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Query\GetClientQuery; +use Mollie\Api\Http\Data\GetClientQuery; use Mollie\Api\Resources\Client; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php index c628a16ce..80d727925 100644 --- a/src/Http/Requests/GetEnabledMethodsRequest.php +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery; +use Mollie\Api\Http\Data\GetEnabledPaymentMethodsQuery; use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Types\Method as HttpMethod; diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php index 44cd639e4..b881c1fef 100644 --- a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php index 26de07c6f..1a2f97735 100644 --- a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedCustomerPaymentsQuery; +use Mollie\Api\Http\Data\GetPaginatedCustomerPaymentsQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedMandateRequest.php b/src/Http/Requests/GetPaginatedMandateRequest.php index 25a407729..970bf17c2 100644 --- a/src/Http/Requests/GetPaginatedMandateRequest.php +++ b/src/Http/Requests/GetPaginatedMandateRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\MandateCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php index 6ff9d314d..94aecd420 100644 --- a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedPaymentCapturesQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Traits\IsIteratableRequest; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php index ec95c5b78..b8701e19a 100644 --- a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedPaymentChargebacksQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Traits\IsIteratableRequest; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php index 6f2f05a4e..0672976e0 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\SortablePaginatedQuery; +use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php index 06291d7f7..2f9a89245 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedPaymentRefundQuery; +use Mollie\Api\Http\Data\GetPaginatedPaymentRefundQuery; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php index e5c2a1291..9cc59d0d2 100644 --- a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedSettlementCapturesQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php index cf196428a..25e2dd09e 100644 --- a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedSettlementChargebacksQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php index caf029d9d..80fe8d3de 100644 --- a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\SortablePaginatedQuery; +use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php index 6561b2a1e..7a5ffbd4f 100644 --- a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaginatedSettlementRefundsQuery; +use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index 332e8fb17..93146000a 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index 2e6eb379c..f3acce33c 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\SubscriptionCollection; use Mollie\Api\Traits\IsIteratableRequest; diff --git a/src/Http/Requests/GetPaymentCaptureRequest.php b/src/Http/Requests/GetPaymentCaptureRequest.php index 4c5e1864d..fbfce2b46 100644 --- a/src/Http/Requests/GetPaymentCaptureRequest.php +++ b/src/Http/Requests/GetPaymentCaptureRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaymentCaptureQuery; +use Mollie\Api\Http\Data\GetPaymentCaptureQuery; use Mollie\Api\Resources\Capture; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetPaymentChargebackRequest.php b/src/Http/Requests/GetPaymentChargebackRequest.php index 8a18ca56a..b123d3ebc 100644 --- a/src/Http/Requests/GetPaymentChargebackRequest.php +++ b/src/Http/Requests/GetPaymentChargebackRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaymentChargebackQuery; +use Mollie\Api\Http\Data\GetPaymentChargebackQuery; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php index 376867345..fb8f32f8a 100644 --- a/src/Http/Requests/GetPaymentMethodRequest.php +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaymentMethodQuery; +use Mollie\Api\Http\Data\GetPaymentMethodQuery; use Mollie\Api\Resources\Method; use Mollie\Api\Types\Method as HttpMethod; diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index e0917158f..a2e74899c 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaymentRefundQuery; +use Mollie\Api\Http\Data\GetPaymentRefundQuery; use Mollie\Api\Resources\Refund; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index d20314114..06e3f2902 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Query\GetPaymentQuery; +use Mollie\Api\Http\Data\GetPaymentQuery; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/GetSessionRequest.php b/src/Http/Requests/GetSessionRequest.php index 80f6b9ec1..7c0738e86 100644 --- a/src/Http/Requests/GetSessionRequest.php +++ b/src/Http/Requests/GetSessionRequest.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Query\AnyQuery; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Types\Method; @@ -14,9 +14,9 @@ class GetSessionRequest extends ResourceHydratableRequest private string $sessionId; - private AnyQuery $query; + private AnyData $query; - public function __construct(string $sessionId, AnyQuery $query) + public function __construct(string $sessionId, AnyData $query) { $this->sessionId = $sessionId; $this->query = $query; diff --git a/src/Http/Requests/UpdateCustomerRequest.php b/src/Http/Requests/UpdateCustomerRequest.php index f54bc4aad..05a87c19c 100644 --- a/src/Http/Requests/UpdateCustomerRequest.php +++ b/src/Http/Requests/UpdateCustomerRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\UpdateCustomerPayload; +use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Resources\Customer; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdatePaymentLinkRequest.php b/src/Http/Requests/UpdatePaymentLinkRequest.php index 2c5ee98df..c03abbe1f 100644 --- a/src/Http/Requests/UpdatePaymentLinkRequest.php +++ b/src/Http/Requests/UpdatePaymentLinkRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; +use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdatePaymentRequest.php b/src/Http/Requests/UpdatePaymentRequest.php index 8bd9d7f8d..9797b001e 100644 --- a/src/Http/Requests/UpdatePaymentRequest.php +++ b/src/Http/Requests/UpdatePaymentRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdatePaymentRouteRequest.php b/src/Http/Requests/UpdatePaymentRouteRequest.php index 180fe27ab..f1ac3d56d 100644 --- a/src/Http/Requests/UpdatePaymentRouteRequest.php +++ b/src/Http/Requests/UpdatePaymentRouteRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Payload\UpdatePaymentRoutePayload; +use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; use Mollie\Api\Resources\Route; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdateProfileRequest.php b/src/Http/Requests/UpdateProfileRequest.php index 78a096501..f3c07064a 100644 --- a/src/Http/Requests/UpdateProfileRequest.php +++ b/src/Http/Requests/UpdateProfileRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\UpdateProfilePayload; +use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Resources\Profile; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdateSalesInvoiceRequest.php b/src/Http/Requests/UpdateSalesInvoiceRequest.php index 421eb1985..881f59b24 100644 --- a/src/Http/Requests/UpdateSalesInvoiceRequest.php +++ b/src/Http/Requests/UpdateSalesInvoiceRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; +use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Http/Requests/UpdateSessionRequest.php b/src/Http/Requests/UpdateSessionRequest.php index 6423d87ef..8e49e71d6 100644 --- a/src/Http/Requests/UpdateSessionRequest.php +++ b/src/Http/Requests/UpdateSessionRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Payload\AnyPayload; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -18,9 +18,9 @@ class UpdateSessionRequest extends ResourceHydratableRequest implements HasPaylo private string $sessionId; - private AnyPayload $payload; + private AnyData $payload; - public function __construct(string $sessionId, AnyPayload $payload) + public function __construct(string $sessionId, AnyData $payload) { $this->sessionId = $sessionId; $this->payload = $payload; diff --git a/src/Http/Requests/UpdateSubscriptionRequest.php b/src/Http/Requests/UpdateSubscriptionRequest.php index 0cc526dd3..fdcff799c 100644 --- a/src/Http/Requests/UpdateSubscriptionRequest.php +++ b/src/Http/Requests/UpdateSubscriptionRequest.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Payload\UpdateSubscriptionPayload; +use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Resources\Subscription; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index fa4f7e895..dc1fad05b 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -4,8 +4,8 @@ use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\Payload\Metadata; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Traits\HasMode; diff --git a/src/Traits/Makeable.php b/src/Traits/Makeable.php deleted file mode 100644 index 443cc2b8e..000000000 --- a/src/Traits/Makeable.php +++ /dev/null @@ -1,11 +0,0 @@ -map(function ($value) { - if ($value instanceof DataResolver) { - return $value->resolve(); - } - - if ($value instanceof Arrayable) { - return $value->toArray(); - } - - if ($value instanceof Stringable) { - return $value->__toString(); - } - - return $value; - }) - ->filter() - ->toArray(); - } -} diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index c1f91fa5d..96ede1fc0 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -2,9 +2,9 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreateClientLinkPayload; -use Mollie\Api\Http\Payload\Owner; -use Mollie\Api\Http\Payload\OwnerAddress; +use Mollie\Api\Http\Data\CreateClientLinkPayload; +use Mollie\Api\Http\Data\Owner; +use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; use Tests\Fixtures\MockClient; diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index e6d8d659b..51b0e186b 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -2,8 +2,8 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 482a4e564..05e6a7275 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -3,7 +3,7 @@ namespace Tests\EndpointCollection; use DateTimeImmutable; -use Mollie\Api\Http\Payload\CreateMandatePayload; +use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index 520da5202..e10985c37 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -2,8 +2,8 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index 2ae5a85a4..b1b6de205 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -2,10 +2,10 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\CreateRefundPaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRequest; diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index cebf2bab2..d8ac444ce 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -3,9 +3,9 @@ namespace Tests\EndpointCollection; use DateTimeImmutable; -use Mollie\Api\Http\Payload\CreatePaymentLinkPayload; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; +use Mollie\Api\Http\Data\CreatePaymentLinkPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index c3f317c5d..879314c55 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -2,8 +2,8 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreateProfilePayload; -use Mollie\Api\Http\Payload\UpdateProfilePayload; +use Mollie\Api\Http\Data\CreateProfilePayload; +use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index 3c9b93126..2465fc529 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\CreateSalesInvoicePayload; -use Mollie\Api\Http\Payload\DataCollection; -use Mollie\Api\Http\Payload\InvoiceLine; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\Recipient; -use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; +use Mollie\Api\Http\Data\CreateSalesInvoicePayload; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\InvoiceLine; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\Recipient; +use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; use Mollie\Api\Http\Requests\CreateSalesInvoiceRequest; use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index 663a1fa1e..f6b146495 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -2,9 +2,8 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Payload\AnyPayload; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Query\AnyQuery; +use Mollie\Api\Http\Data\AnyData; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -27,7 +26,7 @@ public function get() ]); /** @var Session $session */ - $session = $client->sessions->get('ses_123', new AnyQuery(['include' => 'details'])); + $session = $client->sessions->get('ses_123', new AnyData(['include' => 'details'])); $this->assertSession($session); } @@ -40,7 +39,7 @@ public function create() ]); /** @var Session $session */ - $session = $client->sessions->create(new AnyPayload([ + $session = $client->sessions->create(new AnyData([ 'amount' => new Money('EUR', '10.00'), 'description' => 'Test Session', ])); @@ -56,7 +55,7 @@ public function update() ]); /** @var Session $session */ - $session = $client->sessions->update('ses_123', new AnyPayload([ + $session = $client->sessions->update('ses_123', new AnyData([ 'description' => 'Updated Session', ])); diff --git a/tests/Helpers/ArrTest.php b/tests/Helpers/ArrTest.php index 22f2af878..703aadd65 100644 --- a/tests/Helpers/ArrTest.php +++ b/tests/Helpers/ArrTest.php @@ -2,7 +2,11 @@ namespace Tests\Helpers; +use DateTimeImmutable; use Mollie\Api\Helpers\Arr; +use Mollie\Api\Http\Data\AnyData; +use Mollie\Api\Http\Data\Data; +use Stringable; use Tests\TestCase; class ArrTest extends TestCase @@ -85,4 +89,57 @@ public function includes(): void $this->assertTrue(Arr::includes($array, 'includes', 'payment')); $this->assertFalse(Arr::includes($array, 'includes', 'refund')); } + + /** @test */ + public function resolve(): void + { + $foo = new Foo('bar', new Bar('baz')); + $anyData = new AnyData(['foo' => $foo]); + + $this->assertEquals(['foo' => ['foo' => 'bar', 'bar' => 'baz']], Arr::resolve($anyData)); + + $nullResult = Arr::resolve(null); + $this->assertEquals([], $nullResult); + + $resolvesDateTime = Arr::resolve(['dateTime' => DateTimeImmutable::createFromFormat('Y-m-d', '2024-01-01')]); + $this->assertEquals(['dateTime' => '2024-01-01'], $resolvesDateTime); + + $filtersResult = Arr::resolve(['some' => null, 'bar' => 'baz']); + $this->assertEquals(['bar' => 'baz'], $filtersResult); + } +} + +class Foo extends Data +{ + public string $foo; + public Bar $bar; + + public function __construct(string $foo, Bar $bar) + { + $this->foo = $foo; + $this->bar = $bar; + } + + public function toArray(): array + { + return [ + 'foo' => $this->foo, + 'bar' => $this->bar, + ]; + } +} + +class Bar implements Stringable +{ + public string $bar; + + public function __construct(string $bar) + { + $this->bar = $bar; + } + + public function __toString(): string + { + return $this->bar; + } } diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php index 276c7597b..daec0c61d 100644 --- a/tests/Helpers/HelpersTest.php +++ b/tests/Helpers/HelpersTest.php @@ -3,7 +3,7 @@ namespace Tests\Helpers; use Mollie\Api\Helpers; -use Mollie\Api\Http\Payload\Metadata; +use Mollie\Api\Http\Data\Metadata; use ReflectionProperty; use Tests\TestCase; @@ -62,7 +62,7 @@ public function filter_by_properties() public function compose() { // Test with callable - $composedWithCallable = Helpers::compose(5, fn ($x) => $x * 2); + $composedWithCallable = Helpers::compose(5, fn($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); $composedWithClass = Helpers::compose('test', TestComposable::class); @@ -70,7 +70,7 @@ public function compose() $this->assertEquals('test', $composedWithClass->value); // Test with falsy value - $composedWithDefault = Helpers::compose(false, fn ($x) => $x * 2, 'default'); + $composedWithDefault = Helpers::compose(false, fn($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); $existingValueIsNotOverriden = Helpers::compose(new Metadata(['key' => 'value']), Metadata::class); diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php index 6c4898801..bcc3875e0 100644 --- a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\RequestApplePayPaymentSessionPayload; +use Mollie\Api\Http\Data\RequestApplePayPaymentSessionPayload; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\AnyResource; diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php index 45aece5d1..cbc9273c2 100644 --- a/tests/Http/Requests/CreateClientLinkRequestTest.php +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -2,9 +2,9 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateClientLinkPayload; -use Mollie\Api\Http\Payload\Owner; -use Mollie\Api\Http\Payload\OwnerAddress; +use Mollie\Api\Http\Data\CreateClientLinkPayload; +use Mollie\Api\Http\Data\Owner; +use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\ClientLink; diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index a6f587497..e6062df17 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -2,9 +2,9 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Query\CreatePaymentQuery; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php index 890bfcad9..d9a3384b4 100644 --- a/tests/Http/Requests/CreateCustomerRequestTest.php +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateCustomerPayload; +use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Http\Requests\CreateCustomerRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php index e91618f94..91b1b9bbe 100644 --- a/tests/Http/Requests/CreateMandateRequestTest.php +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateMandatePayload; +use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Mandate; diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php index ce9908b76..7b8d6d1b0 100644 --- a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreatePaymentCapturePayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php index ba854938a..cefa3469d 100644 --- a/tests/Http/Requests/CreatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreatePaymentLinkPayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentLinkPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentLink; diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php index fda09f844..133c64b18 100644 --- a/tests/Http/Requests/CreatePaymentRefundRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateRefundPaymentPayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreateRefundPaymentPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Refund; diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index b7c01a7d6..f690492ac 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php index f1a5e3055..5f0b9ecf8 100644 --- a/tests/Http/Requests/CreateProfileRequestTest.php +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateProfilePayload; +use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Profile; diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index 1d7312e55..6aa974f7a 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateSalesInvoicePayload; -use Mollie\Api\Http\Payload\DataCollection; -use Mollie\Api\Http\Payload\InvoiceLine; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\Recipient; +use Mollie\Api\Http\Data\CreateSalesInvoicePayload; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\InvoiceLine; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\Recipient; use Mollie\Api\Http\Requests\CreateSalesInvoiceRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php index 2c47d5c77..345284fa4 100644 --- a/tests/Http/Requests/CreateSessionRequestTest.php +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -2,8 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\AnyPayload; -use Mollie\Api\Http\Query\AnyQuery; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; @@ -21,8 +20,8 @@ public function it_can_create_session() ]); $request = new CreateSessionRequest( - new AnyPayload(['foo' => 'bar']), - new AnyQuery(['baz' => 'qux']) + new AnyData(['foo' => 'bar']), + new AnyData(['baz' => 'qux']) ); /** @var Response */ @@ -35,7 +34,7 @@ public function it_can_create_session() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateSessionRequest(new AnyPayload(['foo' => 'bar']), new AnyQuery(['baz' => 'qux'])); + $request = new CreateSessionRequest(new AnyData(['foo' => 'bar']), new AnyData(['baz' => 'qux'])); $this->assertEquals('sessions', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php index e08a183cc..e20b56502 100644 --- a/tests/Http/Requests/CreateSubscriptionRequestTest.php +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\CreateSubscriptionPayload; -use Mollie\Api\Http\Payload\Money; +use Mollie\Api\Http\Data\CreateSubscriptionPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateSubscriptionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index 70bf12477..187b5a6d5 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -3,7 +3,7 @@ namespace Tests\Http\Requests; use DateTime; -use Mollie\Api\Http\Query\GetBalanceReportQuery; +use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\BalanceReport; diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index c4f8d6832..554675312 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\PaginatedQuery; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Http\Response; diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php index db2829768..280da3d38 100644 --- a/tests/Http/Requests/GetSessionRequestTest.php +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Query\AnyQuery; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\GetSessionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; @@ -19,7 +19,7 @@ public function it_can_get_session() GetSessionRequest::class => new MockResponse(200, 'session'), ]); - $query = new AnyQuery([ + $query = new AnyData([ 'testmode' => true, ]); @@ -40,7 +40,7 @@ public function it_can_get_session() /** @test */ public function it_resolves_correct_resource_path() { - $query = new AnyQuery([ + $query = new AnyData([ 'testmode' => true, ]); diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php index 1ba140832..895003fb8 100644 --- a/tests/Http/Requests/UpdateCustomerRequestTest.php +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdateCustomerPayload; +use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php index 8f34ea67a..531964f9e 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdatePaymentLinkPayload; +use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentLink; diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php index 94805f3f4..58503c36c 100644 --- a/tests/Http/Requests/UpdatePaymentRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php index a410da746..7484fca51 100644 --- a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -3,7 +3,7 @@ namespace Tests\Http\Requests; use DateTime; -use Mollie\Api\Http\Payload\UpdatePaymentRoutePayload; +use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Route; diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php index 94071d247..9767b603e 100644 --- a/tests/Http/Requests/UpdateProfileRequestTest.php +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdateProfilePayload; +use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Profile; diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index 22ed2c28f..572e7f1e4 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\UpdateSalesInvoicePayload; +use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; use Mollie\Api\Http\Requests\UpdateSalesInvoiceRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index 9cc1ddd15..c8043cde6 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -2,7 +2,7 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\AnyPayload; +use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\UpdateSessionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; @@ -19,7 +19,7 @@ public function it_can_update_session() UpdateSessionRequest::class => new MockResponse(200, 'session'), ]); - $payload = new AnyPayload([ + $payload = new AnyData([ 'status' => 'completed', 'metadata' => [ 'order_id' => '12345', @@ -44,7 +44,7 @@ public function it_can_update_session() public function it_resolves_correct_resource_path() { $sessionId = 'ses_LQNz4v4Qvk'; - $request = new UpdateSessionRequest($sessionId, new AnyPayload); + $request = new UpdateSessionRequest($sessionId, new AnyData); $this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index 4612d8855..b2c803b83 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -2,8 +2,8 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\UpdateSubscriptionPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index dba10d77c..a270d89dc 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -8,9 +8,9 @@ use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; -use Mollie\Api\Http\Payload\CreatePaymentPayload; -use Mollie\Api\Http\Payload\Money; -use Mollie\Api\Http\Payload\UpdatePaymentPayload; +use Mollie\Api\Http\Data\CreatePaymentPayload; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response as HttpResponse; diff --git a/tests/Traits/ResolvesValuesTest.php b/tests/Traits/ResolvesValuesTest.php deleted file mode 100644 index 81a90bf23..000000000 --- a/tests/Traits/ResolvesValuesTest.php +++ /dev/null @@ -1,89 +0,0 @@ -assertEquals([ - 'name' => 'foo', - 'bar' => [ - 'baz' => [ - 'value' => 'baz', - ], - ], - ], $fooData->resolve()); - } -} - -class FooData implements Arrayable -{ - use ResolvesValues; - - public Bar $bar; - - public string $name; - - public function __construct( - Bar $bar, - string $name - ) { - $this->bar = $bar; - $this->name = $name; - } - - public function toArray(): array - { - return [ - 'name' => $this->name, - 'bar' => $this->bar, - ]; - } -} - -class Bar implements DataResolver -{ - use ResolvesValues; - - public Baz $baz; - - public function __construct(Baz $baz) - { - $this->baz = $baz; - } - - public function toArray(): array - { - return [ - 'baz' => $this->baz, - ]; - } -} - -class Baz implements Arrayable -{ - public string $value; - - public function __construct(string $value) - { - $this->value = $value; - } - - public function toArray(): array - { - return [ - 'value' => $this->value, - ]; - } -} From 8c5684512c4c5b3d672aae874b7c3b2d6c33bcd0 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 12 Dec 2024 13:01:38 +0000 Subject: [PATCH 114/131] Fixes coding style --- examples/captures/create-capture.php | 4 ++-- examples/client-links/create-client-link.php | 4 ++-- examples/customers/create-customer-first-payment.php | 4 ++-- src/CompatibilityChecker.php | 2 +- src/EndpointCollection/PaymentEndpointCollection.php | 4 ++-- src/Factories/CreateMandatePayloadFactory.php | 2 +- src/Factories/CreatePaymentCapturePayloadFactory.php | 2 +- src/Factories/CreatePaymentLinkPayloadFactory.php | 2 +- src/Factories/CreatePaymentPayloadFactory.php | 10 +++++----- src/Factories/CreateRefundPaymentPayloadFactory.php | 2 +- src/Factories/CreateSalesInvoicePayloadFactory.php | 8 ++++---- src/Factories/CreateSubscriptionPayloadFactory.php | 4 ++-- src/Factories/InvoiceLineCollectionFactory.php | 2 +- src/Factories/InvoiceLineFactory.php | 2 +- src/Factories/OrderLineCollectionFactory.php | 2 +- src/Factories/OrderLineFactory.php | 6 +++--- src/Factories/PaymentRouteCollectionFactory.php | 2 +- src/Factories/RecurringBillingCycleFactory.php | 4 ++-- src/Factories/UpdateSalesInvoicePayloadFactory.php | 10 +++++----- src/Factories/UpdateSubscriptionPayloadFactory.php | 4 ++-- src/Http/Data/GetAllMethodsQuery.php | 1 - src/Http/Data/GetEnabledPaymentMethodsQuery.php | 1 - src/Http/Data/GetPaginatedClientQuery.php | 1 - src/Http/Data/GetPaginatedPaymentCapturesQuery.php | 1 - src/Http/Data/GetPaymentCaptureQuery.php | 1 - src/Http/Data/GetPaymentMethodQuery.php | 1 - src/Http/Data/GetPaymentQuery.php | 1 - src/Http/Data/PaymentRoute.php | 2 +- tests/Helpers/ArrTest.php | 1 + tests/Helpers/HelpersTest.php | 4 ++-- .../Http/Requests/CreateCustomerPaymentRequestTest.php | 2 +- tests/MollieApiClientTest.php | 2 +- 32 files changed, 46 insertions(+), 52 deletions(-) diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index 13b765181..65d374406 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -29,7 +29,7 @@ $capture = $response->toResource(); - echo '

      New capture created ' . htmlspecialchars($capture->id) . ' (' . htmlspecialchars($capture->description) . ').

      '; + echo '

      New capture created '.htmlspecialchars($capture->id).' ('.htmlspecialchars($capture->description).').

      '; } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: ' . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index a837d4d3d..941a1babb 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -53,7 +53,7 @@ * Send the customer off to finalize the organization creation. * This request should always be a GET, thus we enforce 303 http response code */ - header('Location: ' . $redirectUrl, true, 303); + header('Location: '.$redirectUrl, true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: ' . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index bd2cc177c..96761e314 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -67,7 +67,7 @@ * After completion, the customer will have a pending or valid mandate that can be * used for recurring payments and subscriptions. */ - header('Location: ' . $payment->getCheckoutUrl(), true, 303); + header('Location: '.$payment->getCheckoutUrl(), true, 303); } catch (\Mollie\Api\Exceptions\ApiException $e) { - echo 'API call failed: ' . htmlspecialchars($e->getMessage()); + echo 'API call failed: '.htmlspecialchars($e->getMessage()); } diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index 9725ec166..fc07f16b4 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -25,7 +25,7 @@ public function checkCompatibility() { if (! $this->satisfiesPhpVersion()) { throw new IncompatiblePlatform( - 'The client requires PHP version >= ' . self::MIN_PHP_VERSION . ', you have ' . PHP_VERSION . '.', + 'The client requires PHP version >= '.self::MIN_PHP_VERSION.', you have '.PHP_VERSION.'.', IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION ); } diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index 2f1a3c479..eb6ce6e2e 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -11,10 +11,10 @@ use Mollie\Api\Helpers; use Mollie\Api\Helpers\Arr; use Mollie\Api\Http\Data\CreatePaymentPayload; -use Mollie\Api\Http\Data\CreateRefundPaymentPayload; -use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; +use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\GetPaymentQuery; +use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRequest; diff --git a/src/Factories/CreateMandatePayloadFactory.php b/src/Factories/CreateMandatePayloadFactory.php index d6f6aa0d5..b339b6cd9 100644 --- a/src/Factories/CreateMandatePayloadFactory.php +++ b/src/Factories/CreateMandatePayloadFactory.php @@ -19,7 +19,7 @@ public function create(): CreateMandatePayload $this->get('consumerAccount'), $this->get('consumerBic'), $this->get('consumerEmail'), - $this->mapIfNotNull('signatureDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('signatureDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('mandateReference'), $this->get('paypalBillingAgreementId'), ); diff --git a/src/Factories/CreatePaymentCapturePayloadFactory.php b/src/Factories/CreatePaymentCapturePayloadFactory.php index a67d45973..2e207dcca 100644 --- a/src/Factories/CreatePaymentCapturePayloadFactory.php +++ b/src/Factories/CreatePaymentCapturePayloadFactory.php @@ -11,7 +11,7 @@ public function create(): CreatePaymentCapturePayload { return new CreatePaymentCapturePayload( $this->get('description'), - $this->mapIfNotNull('amount', fn(array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), $this->mapIfNotNull('metadata', Metadata::class) ); } diff --git a/src/Factories/CreatePaymentLinkPayloadFactory.php b/src/Factories/CreatePaymentLinkPayloadFactory.php index de773cf16..9c6eed9c7 100644 --- a/src/Factories/CreatePaymentLinkPayloadFactory.php +++ b/src/Factories/CreatePaymentLinkPayloadFactory.php @@ -10,7 +10,7 @@ public function create(): CreatePaymentLinkPayload { return new CreatePaymentLinkPayload( $this->get('description'), - $this->mapIfNotNull('amount', fn(array $amount) => MoneyFactory::new($amount)->create()), + $this->mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), $this->get('redirectUrl'), $this->get('webhookUrl'), $this->get('profileId'), diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index a58f9fe98..e4da5d21d 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -20,10 +20,10 @@ public function create(): CreatePaymentPayload $this ->mapIfNotNull( 'lines', - fn(array $items) => OrderLineCollectionFactory::new($items)->create() + fn (array $items) => OrderLineCollectionFactory::new($items)->create() ), - $this->mapIfNotNull('billingAddress', fn(array $item) => Address::fromArray($item)), - $this->mapIfNotNull('shippingAddress', fn(array $item) => Address::fromArray($item)), + $this->mapIfNotNull('billingAddress', fn (array $item) => Address::fromArray($item)), + $this->mapIfNotNull('shippingAddress', fn (array $item) => Address::fromArray($item)), $this->get('locale'), $this->get('method'), $this->get('issuer'), @@ -33,11 +33,11 @@ public function create(): CreatePaymentPayload $this->get('captureDelay'), $this->mapIfNotNull( 'applicationFee', - fn(array $item) => ApplicationFeeFactory::new($item)->create() + fn (array $item) => ApplicationFeeFactory::new($item)->create() ), $this->mapIfNotNull( 'routing', - fn(array $items) => PaymentRouteCollectionFactory::new($items)->create() + fn (array $items) => PaymentRouteCollectionFactory::new($items)->create() ), $this->get('sequenceType'), $this->get('mandateId'), diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php index 2255461c4..42e561847 100644 --- a/src/Factories/CreateRefundPaymentPayloadFactory.php +++ b/src/Factories/CreateRefundPaymentPayloadFactory.php @@ -17,7 +17,7 @@ public function create(): CreateRefundPaymentPayload $this ->mapIfNotNull( 'routingReversals', - fn(array $items) => RefundRouteCollectionFactory::new($items)->create() + fn (array $items) => RefundRouteCollectionFactory::new($items)->create() ), ); } diff --git a/src/Factories/CreateSalesInvoicePayloadFactory.php b/src/Factories/CreateSalesInvoicePayloadFactory.php index 3712263a7..3d7eeb857 100644 --- a/src/Factories/CreateSalesInvoicePayloadFactory.php +++ b/src/Factories/CreateSalesInvoicePayloadFactory.php @@ -25,14 +25,14 @@ public function create(): CreateSalesInvoicePayload $this ->mapIfNotNull( 'lines', - fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('profileId'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/CreateSubscriptionPayloadFactory.php b/src/Factories/CreateSubscriptionPayloadFactory.php index 02037be97..27e7a3721 100644 --- a/src/Factories/CreateSubscriptionPayloadFactory.php +++ b/src/Factories/CreateSubscriptionPayloadFactory.php @@ -16,9 +16,9 @@ public function create(): CreateSubscriptionPayload $this->get('description'), $this->get('status'), $this->get('times'), - $this->mapIfNotNull('startDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('method'), - $this->mapIfNotNull('applicationFee', fn(array $fee) => ApplicationFeeFactory::new($fee)->create()), + $this->mapIfNotNull('applicationFee', fn (array $fee) => ApplicationFeeFactory::new($fee)->create()), $this->mapIfNotNull('metadata', Metadata::class), $this->get('webhookUrl'), $this->get('mandateId'), diff --git a/src/Factories/InvoiceLineCollectionFactory.php b/src/Factories/InvoiceLineCollectionFactory.php index 3752b0973..920f4cd31 100644 --- a/src/Factories/InvoiceLineCollectionFactory.php +++ b/src/Factories/InvoiceLineCollectionFactory.php @@ -9,7 +9,7 @@ class InvoiceLineCollectionFactory extends Factory public function create(): DataCollection { return new DataCollection(array_map( - fn(array $item) => InvoiceLineFactory::new($item)->create(), + fn (array $item) => InvoiceLineFactory::new($item)->create(), $this->data )); } diff --git a/src/Factories/InvoiceLineFactory.php b/src/Factories/InvoiceLineFactory.php index 6dac4317d..560bf271c 100644 --- a/src/Factories/InvoiceLineFactory.php +++ b/src/Factories/InvoiceLineFactory.php @@ -14,7 +14,7 @@ public function create(): InvoiceLine $this->get('quantity'), $this->get('vatRate'), MoneyFactory::new($this->get('unitPrice'))->create(), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/OrderLineCollectionFactory.php b/src/Factories/OrderLineCollectionFactory.php index 3b114aa6e..f41d15ae3 100644 --- a/src/Factories/OrderLineCollectionFactory.php +++ b/src/Factories/OrderLineCollectionFactory.php @@ -9,7 +9,7 @@ class OrderLineCollectionFactory extends Factory public function create(): DataCollection { return new DataCollection(array_map( - fn(array $item) => OrderLineFactory::new($item)->create(), + fn (array $item) => OrderLineFactory::new($item)->create(), $this->data )); } diff --git a/src/Factories/OrderLineFactory.php b/src/Factories/OrderLineFactory.php index dd9e6714b..99b4d0eca 100644 --- a/src/Factories/OrderLineFactory.php +++ b/src/Factories/OrderLineFactory.php @@ -15,10 +15,10 @@ public function create(): OrderLine MoneyFactory::new($this->get('totalAmount'))->create(), $this->get('type'), $this->get('quantityUnit'), - $this->mapIfNotNull('discountAmount', fn(array $item) => MoneyFactory::new($item)->create()), - $this->mapIfNotNull('recurring', fn(array $item) => RecurringBillingCycleFactory::new($item)->create()), + $this->mapIfNotNull('discountAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('recurring', fn (array $item) => RecurringBillingCycleFactory::new($item)->create()), $this->get('vatRate'), - $this->mapIfNotNull('vatAmount', fn(array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('vatAmount', fn (array $item) => MoneyFactory::new($item)->create()), $this->get('sku'), $this->get('imageUrl'), $this->get('productUrl'), diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index 6700b005b..603c7ac1e 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -22,7 +22,7 @@ public function create(): DataCollection Arr::get($item, 'destination.organizationId'), Helpers::compose( Arr::get($item, 'delayUntil'), - fn($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) + fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) ) ); }, $this->data); diff --git a/src/Factories/RecurringBillingCycleFactory.php b/src/Factories/RecurringBillingCycleFactory.php index a4e051503..c55a8d7cd 100644 --- a/src/Factories/RecurringBillingCycleFactory.php +++ b/src/Factories/RecurringBillingCycleFactory.php @@ -12,9 +12,9 @@ public function create(): RecurringBillingCycle return new RecurringBillingCycle( $this->get('interval'), $this->get('descriptipn'), - $this->mapIfNotNull('amount', fn(array $item) => MoneyFactory::new($item)->create()), + $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), $this->get('times'), - $this->mapIfNotNull('startDate', fn(string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), + $this->mapIfNotNull('startDate', fn (string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), ); } } diff --git a/src/Factories/UpdateSalesInvoicePayloadFactory.php b/src/Factories/UpdateSalesInvoicePayloadFactory.php index c995f5241..8023d83fc 100644 --- a/src/Factories/UpdateSalesInvoicePayloadFactory.php +++ b/src/Factories/UpdateSalesInvoicePayloadFactory.php @@ -19,16 +19,16 @@ public function create(): UpdateSalesInvoicePayload $this->get('recipientIdentifier'), $this->get('paymentTerm'), $this->get('memo'), - $this->mapIfNotNull('paymentDetails', fn(array $data) => PaymentDetails::fromArray($data)), - $this->mapIfNotNull('emailDetails', fn(array $data) => EmailDetails::fromArray($data)), - $this->mapIfNotNull('recipient', fn(array $data) => RecipientFactory::new($data)->create()), + $this->mapIfNotNull('paymentDetails', fn (array $data) => PaymentDetails::fromArray($data)), + $this->mapIfNotNull('emailDetails', fn (array $data) => EmailDetails::fromArray($data)), + $this->mapIfNotNull('recipient', fn (array $data) => RecipientFactory::new($data)->create()), $this ->mapIfNotNull( 'lines', - fn(array $items) => InvoiceLineCollectionFactory::new($items)->create() + fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() ), $this->get('webhookUrl'), - $this->mapIfNotNull('discount', fn(array $data) => Discount::fromArray($data)) + $this->mapIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/UpdateSubscriptionPayloadFactory.php b/src/Factories/UpdateSubscriptionPayloadFactory.php index 1f8ca482f..c833394f1 100644 --- a/src/Factories/UpdateSubscriptionPayloadFactory.php +++ b/src/Factories/UpdateSubscriptionPayloadFactory.php @@ -11,10 +11,10 @@ class UpdateSubscriptionPayloadFactory extends Factory public function create(): UpdateSubscriptionPayload { return new UpdateSubscriptionPayload( - $this->mapIfNotNull('amount', fn(array $amount) => MoneyFactory::new($amount)->create()), + $this->mapIfNotNull('amount', fn (array $amount) => MoneyFactory::new($amount)->create()), $this->get('description'), $this->get('interval'), - $this->mapIfNotNull('startDate', fn(string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), + $this->mapIfNotNull('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date)), $this->get('times'), $this->mapIfNotNull('metadata', Metadata::class), $this->get('webhookUrl'), diff --git a/src/Http/Data/GetAllMethodsQuery.php b/src/Http/Data/GetAllMethodsQuery.php index fc517f0f9..00f02ce91 100644 --- a/src/Http/Data/GetAllMethodsQuery.php +++ b/src/Http/Data/GetAllMethodsQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Http\Data\Money; use Mollie\Api\Types\MethodQuery; class GetAllMethodsQuery extends Data diff --git a/src/Http/Data/GetEnabledPaymentMethodsQuery.php b/src/Http/Data/GetEnabledPaymentMethodsQuery.php index 15a5196e4..c2aa7b353 100644 --- a/src/Http/Data/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Data/GetEnabledPaymentMethodsQuery.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Data; use Mollie\Api\Helpers\Arr; -use Mollie\Api\Http\Data\Money; use Mollie\Api\Types\MethodQuery; class GetEnabledPaymentMethodsQuery extends Data diff --git a/src/Http/Data/GetPaginatedClientQuery.php b/src/Http/Data/GetPaginatedClientQuery.php index 077976b3e..0b8efbad7 100644 --- a/src/Http/Data/GetPaginatedClientQuery.php +++ b/src/Http/Data/GetPaginatedClientQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\ClientQuery; diff --git a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php index 5522fd594..6dcfacdf6 100644 --- a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; diff --git a/src/Http/Data/GetPaymentCaptureQuery.php b/src/Http/Data/GetPaymentCaptureQuery.php index 630b12a23..bb8706db4 100644 --- a/src/Http/Data/GetPaymentCaptureQuery.php +++ b/src/Http/Data/GetPaymentCaptureQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentIncludesQuery; diff --git a/src/Http/Data/GetPaymentMethodQuery.php b/src/Http/Data/GetPaymentMethodQuery.php index 21c20dfe3..22eb50bfb 100644 --- a/src/Http/Data/GetPaymentMethodQuery.php +++ b/src/Http/Data/GetPaymentMethodQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\MethodQuery; diff --git a/src/Http/Data/GetPaymentQuery.php b/src/Http/Data/GetPaymentQuery.php index f0036a3f1..b9a2d44f9 100644 --- a/src/Http/Data/GetPaymentQuery.php +++ b/src/Http/Data/GetPaymentQuery.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Helpers\Arr; use Mollie\Api\Types\PaymentQuery; diff --git a/src/Http/Data/PaymentRoute.php b/src/Http/Data/PaymentRoute.php index e4e296f1e..c6da0ee62 100644 --- a/src/Http/Data/PaymentRoute.php +++ b/src/Http/Data/PaymentRoute.php @@ -30,7 +30,7 @@ public function toArray(): array 'type' => 'organization', 'organizationId' => $this->organizationId, ], - 'delayUntil' => $this->delayUntil + 'delayUntil' => $this->delayUntil, ]; } } diff --git a/tests/Helpers/ArrTest.php b/tests/Helpers/ArrTest.php index 703aadd65..eb7e82f78 100644 --- a/tests/Helpers/ArrTest.php +++ b/tests/Helpers/ArrTest.php @@ -112,6 +112,7 @@ public function resolve(): void class Foo extends Data { public string $foo; + public Bar $bar; public function __construct(string $foo, Bar $bar) diff --git a/tests/Helpers/HelpersTest.php b/tests/Helpers/HelpersTest.php index daec0c61d..931454183 100644 --- a/tests/Helpers/HelpersTest.php +++ b/tests/Helpers/HelpersTest.php @@ -62,7 +62,7 @@ public function filter_by_properties() public function compose() { // Test with callable - $composedWithCallable = Helpers::compose(5, fn($x) => $x * 2); + $composedWithCallable = Helpers::compose(5, fn ($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); $composedWithClass = Helpers::compose('test', TestComposable::class); @@ -70,7 +70,7 @@ public function compose() $this->assertEquals('test', $composedWithClass->value); // Test with falsy value - $composedWithDefault = Helpers::compose(false, fn($x) => $x * 2, 'default'); + $composedWithDefault = Helpers::compose(false, fn ($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); $existingValueIsNotOverriden = Helpers::compose(new Metadata(['key' => 'value']), Metadata::class); diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index e6062df17..d280436c3 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -3,8 +3,8 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Data\CreatePaymentPayload; -use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\CreatePaymentQuery; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index a270d89dc..d41455e7a 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -7,10 +7,10 @@ use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; -use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\UpdatePaymentPayload; +use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Http\Response as HttpResponse; From 9f693e45181bd94d54cfc0e70e72dd18d8059b9e Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 12 Dec 2024 14:32:07 +0100 Subject: [PATCH 115/131] wip --- docs/requests.md | 1 + phpstan-baseline.neon | 38 +++++++++---------- src/Contracts/Connector.php | 4 +- src/Contracts/HttpAdapterContract.php | 2 +- .../BalanceEndpointCollection.php | 8 ++-- .../BalanceReportEndpointCollection.php | 4 +- .../ChargebackEndpointCollection.php | 6 +-- .../CustomerEndpointCollection.php | 12 +++--- .../CustomerPaymentsEndpointCollection.php | 10 ++--- .../MandateEndpointCollection.php | 12 +++--- .../MethodEndpointCollection.php | 6 +-- .../OrganizationEndpointCollection.php | 4 +- .../PaymentCaptureEndpointCollection.php | 10 ++--- .../PaymentChargebackEndpointCollection.php | 8 ++-- .../PaymentEndpointCollection.php | 18 ++++----- .../PaymentLinkEndpointCollection.php | 8 ++-- .../PaymentLinkPaymentEndpointCollection.php | 6 +-- .../PaymentRefundEndpointCollection.php | 14 +++---- .../PermissionEndpointCollection.php | 4 +- .../ProfileEndpointCollection.php | 4 +- .../RefundEndpointCollection.php | 6 +-- .../SettlementCaptureEndpointCollection.php | 6 +-- ...SettlementChargebackEndpointCollection.php | 6 +-- .../SettlementPaymentEndpointCollection.php | 6 +-- .../SettlementRefundEndpointCollection.php | 6 +-- .../SubscriptionEndpointCollection.php | 16 ++++---- .../SubscriptionPaymentEndpointCollection.php | 6 +-- .../TerminalEndpointCollection.php | 8 ++-- src/Factories/CreatePaymentPayloadFactory.php | 4 +- src/Factories/Factory.php | 10 ++--- .../PaymentRouteCollectionFactory.php | 6 +-- .../RefundRouteCollectionFactory.php | 2 +- src/Factories/UpdatePaymentPayloadFactory.php | 4 +- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 4 +- src/Http/Adapter/PSR18MollieHttpAdapter.php | 4 +- src/Http/Data/Data.php | 2 +- src/Http/Data/GetClientQuery.php | 2 +- .../Data/GetEnabledPaymentMethodsQuery.php | 2 +- src/Http/Data/GetPaginatedClientQuery.php | 2 +- .../Data/GetPaginatedPaymentCapturesQuery.php | 2 +- src/Http/Data/GetPaymentCaptureQuery.php | 2 +- src/Http/Data/GetPaymentMethodQuery.php | 2 +- src/Http/Data/GetPaymentQuery.php | 2 +- .../Middleware.php} | 10 +++-- src/{Helpers => Http/Middleware}/Handler.php | 2 +- src/{Helpers => Http/Middleware}/Handlers.php | 2 +- .../Middleware}/MiddlewarePriority.php | 2 +- src/Http/PendingRequest.php | 5 +-- src/Http/PendingRequest/SetUserAgent.php | 2 +- src/MollieApiClient.php | 2 +- src/Repositories/ArrayStore.php | 2 +- src/Resources/AnyResource.php | 2 +- src/Traits/HasDefaultFactories.php | 2 +- src/Traits/HasMiddleware.php | 8 ++-- src/Traits/Initializable.php | 6 +-- src/Traits/ManagesPsrRequests.php | 4 +- src/{Helpers => Utils}/Arr.php | 2 +- src/{Helpers => Utils}/Factories.php | 2 +- src/{Helpers => Utils}/Url.php | 4 +- src/{Helpers.php => Utils/Utility.php} | 12 +++--- tests/Fixtures/MockResponse.php | 4 +- tests/Http/Adapter/MockMollieHttpAdapter.php | 8 ++-- .../Middleware}/HandlersTest.php | 8 ++-- .../MiddlewareTest.php} | 13 ++++--- tests/{Helpers => Utils}/ArrTest.php | 4 +- tests/{Helpers => Utils}/UrlTest.php | 4 +- .../HelpersTest.php => Utils/UtilityTest.php} | 34 ++++++++--------- 67 files changed, 218 insertions(+), 215 deletions(-) rename src/{Helpers/MiddlewareHandlers.php => Http/Middleware.php} (90%) rename src/{Helpers => Http/Middleware}/Handler.php (93%) rename src/{Helpers => Http/Middleware}/Handlers.php (98%) rename src/{Helpers => Http/Middleware}/MiddlewarePriority.php (78%) rename src/{Helpers => Utils}/Arr.php (99%) rename src/{Helpers => Utils}/Factories.php (96%) rename src/{Helpers => Utils}/Url.php (92%) rename src/{Helpers.php => Utils/Utility.php} (92%) rename tests/{Helpers => Http/Middleware}/HandlersTest.php (89%) rename tests/{Helpers/MiddlewareHandlersTest.php => Http/MiddlewareTest.php} (87%) rename tests/{Helpers => Utils}/ArrTest.php (98%) rename tests/{Helpers => Utils}/UrlTest.php (94%) rename tests/{Helpers/HelpersTest.php => Utils/UtilityTest.php} (73%) diff --git a/docs/requests.md b/docs/requests.md index 6af82fecf..aa889d6fe 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -21,6 +21,7 @@ To send a request using the Mollie API client, you typically need to: 3. **Send the request**: Use the client to send the request and handle the response. + ```php use Mollie\Api\MollieApiClient; use Mollie\Api\Http\Data\Money; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9dd9e3cce..792c7ec6f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -361,37 +361,37 @@ parameters: path: tests/Fixtures/MockResponse.php - - message: '#^Property Tests\\Helpers\\TestPropertiesClass\:\:\$privateProp is unused\.$#' - identifier: property.unused - count: 1 - path: tests/Helpers/HelpersTest.php + message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 + path: tests/Http/Adapter/MockMollieHttpAdapter.php - - message: '#^Trait Tests\\Helpers\\TestTraitBase is used zero times and is not analysed\.$#' - identifier: trait.unused + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' + identifier: method.alreadyNarrowedType count: 1 - path: tests/Helpers/HelpersTest.php + path: tests/Http/Middleware/GuardResponseTest.php - - message: '#^Trait Tests\\Helpers\\TestTraitMain is used zero times and is not analysed\.$#' - identifier: trait.unused + message: '#^Property Tests\\Utils\\TestPropertiesClass\:\:\$privateProp is unused\.$#' + identifier: property.unused count: 1 - path: tests/Helpers/HelpersTest.php + path: tests/Utils/UtilityTest.php - - message: '#^Trait Tests\\Helpers\\TestTraitNested is used zero times and is not analysed\.$#' + message: '#^Trait Tests\\Utils\\TestTraitBase is used zero times and is not analysed\.$#' identifier: trait.unused count: 1 - path: tests/Helpers/HelpersTest.php + path: tests/Utils/UtilityTest.php - - message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' - identifier: staticClassAccess.privateProperty - count: 3 - path: tests/Http/Adapter/MockMollieHttpAdapter.php + message: '#^Trait Tests\\Utils\\TestTraitMain is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: tests/Utils/UtilityTest.php - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' - identifier: method.alreadyNarrowedType + message: '#^Trait Tests\\Utils\\TestTraitNested is used zero times and is not analysed\.$#' + identifier: trait.unused count: 1 - path: tests/Http/Middleware/GuardResponseTest.php + path: tests/Utils/UtilityTest.php diff --git a/src/Contracts/Connector.php b/src/Contracts/Connector.php index 6a428f01e..9210504a3 100644 --- a/src/Contracts/Connector.php +++ b/src/Contracts/Connector.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Contracts; -use Mollie\Api\Helpers\MiddlewareHandlers; +use Mollie\Api\Http\Middleware; use Mollie\Api\Http\Request; interface Connector extends Authenticatable, Hydratable, IdempotencyContract, SupportsDebuggingContract, Testable @@ -15,7 +15,7 @@ public function headers(): ArrayRepository; public function query(): ArrayRepository; - public function middleware(): MiddlewareHandlers; + public function middleware(): Middleware; public function addVersionString($versionString): self; diff --git a/src/Contracts/HttpAdapterContract.php b/src/Contracts/HttpAdapterContract.php index 4087eaac8..9fae64565 100644 --- a/src/Contracts/HttpAdapterContract.php +++ b/src/Contracts/HttpAdapterContract.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Contracts; -use Mollie\Api\Helpers\Factories; +use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; diff --git a/src/EndpointCollection/BalanceEndpointCollection.php b/src/EndpointCollection/BalanceEndpointCollection.php index 7ec843564..71eea6651 100644 --- a/src/EndpointCollection/BalanceEndpointCollection.php +++ b/src/EndpointCollection/BalanceEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedBalanceQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetBalanceRequest; use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; @@ -24,7 +24,7 @@ class BalanceEndpointCollection extends EndpointCollection */ public function get(string $id, $testmode = []): Balance { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Balance */ return $this->send((new GetBalanceRequest($id))->test($testmode)); @@ -48,7 +48,7 @@ public function primary(array $testmode = []): Balance */ public function page(?string $from = null, ?int $limit = null, array $filters = []): BalanceCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedBalanceQueryFactory::new([ 'from' => $from, @@ -67,7 +67,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedBalanceQueryFactory::new([ 'from' => $from, diff --git a/src/EndpointCollection/BalanceReportEndpointCollection.php b/src/EndpointCollection/BalanceReportEndpointCollection.php index 3a45b8db0..4985d9d4a 100644 --- a/src/EndpointCollection/BalanceReportEndpointCollection.php +++ b/src/EndpointCollection/BalanceReportEndpointCollection.php @@ -3,7 +3,7 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Factories\GetBalanceReportQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; @@ -20,7 +20,7 @@ class BalanceReportEndpointCollection extends EndpointCollection */ public function getForId(string $balanceId, $query = []): ?BalanceReport { - $testmode = Helpers::extractBool($query, 'testmode', false); + $testmode = Utility::extractBool($query, 'testmode', false); $query = GetBalanceReportQueryFactory::new($query) ->create(); diff --git a/src/EndpointCollection/ChargebackEndpointCollection.php b/src/EndpointCollection/ChargebackEndpointCollection.php index 68200b13d..ee68dc2e5 100644 --- a/src/EndpointCollection/ChargebackEndpointCollection.php +++ b/src/EndpointCollection/ChargebackEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedChargebackQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; @@ -20,7 +20,7 @@ class ChargebackEndpointCollection extends EndpointCollection */ public function page(?string $from = null, ?int $limit = null, array $filters = []): ChargebackCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedChargebackQueryFactory::new([ 'from' => $from, @@ -41,7 +41,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, $filters = [], bool $iterateBackwards = false): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedChargebackQueryFactory::new([ 'from' => $from, diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index 489ec5d04..d97b51e7e 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -6,7 +6,7 @@ use Mollie\Api\Factories\CreateCustomerPayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateCustomerPayloadFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Http\Requests\CreateCustomerRequest; @@ -30,7 +30,7 @@ class CustomerEndpointCollection extends EndpointCollection */ public function create($data = [], $testmode = []): Customer { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); if (! $data instanceof CreateCustomerPayload) { $data = CreateCustomerPayloadFactory::new($data)->create(); @@ -51,7 +51,7 @@ public function create($data = [], $testmode = []): Customer */ public function get(string $id, $testmode = []): Customer { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Customer */ return $this->send((new GetCustomerRequest($id))->test($testmode)); @@ -86,7 +86,7 @@ public function update(string $id, $data = []): ?Customer */ public function delete(string $id, $testmode = []): void { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $this->send((new DeleteCustomerRequest($id))->test($testmode)); } @@ -100,7 +100,7 @@ public function delete(string $id, $testmode = []): void */ public function page(?string $from = null, ?int $limit = null, array $filters = []): CustomerCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, @@ -120,7 +120,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, diff --git a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php index 5ac7c407a..67038c35f 100644 --- a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php +++ b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php @@ -5,8 +5,8 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\CreatePaymentPayloadFactory; use Mollie\Api\Factories\GetPaginatedCustomerPaymentsQueryFactory; -use Mollie\Api\Helpers; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Utility; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; @@ -43,7 +43,7 @@ public function createFor(Customer $customer, $payload = [], $query = [], bool $ public function createForId($customerId, $payload = [], $query = [], bool $testmode = false): Payment { if (! $payload instanceof CreatePaymentPayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreatePaymentPayloadFactory::new($payload) ->create(); } @@ -73,7 +73,7 @@ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = */ public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedCustomerPaymentsQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -115,7 +115,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedCustomerPaymentsQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php index c49dc7eb9..8d8b8190c 100644 --- a/src/EndpointCollection/MandateEndpointCollection.php +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -5,7 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\CreateMandatePayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; @@ -40,7 +40,7 @@ public function createFor(Customer $customer, $payload = [], bool $testmode = fa public function createForId(string $customerId, $payload = [], bool $testmode = false): Mandate { if (! $payload instanceof CreateMandatePayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreateMandatePayloadFactory::new($payload)->create(); } @@ -68,7 +68,7 @@ public function getFor(Customer $customer, string $mandateId, array $parameters */ public function getForId(string $customerId, string $mandateId, $testmode = []): Mandate { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Mandate */ return $this->send((new GetMandateRequest($customerId, $mandateId))->test($testmode)); @@ -94,7 +94,7 @@ public function revokeFor(Customer $customer, string $mandateId, $data = []): vo */ public function revokeForId(string $customerId, string $mandateId, $testmode = []): void { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $this->send((new RevokeMandateRequest($customerId, $mandateId))->test($testmode)); } @@ -120,7 +120,7 @@ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = */ public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): MandateCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -160,7 +160,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/MethodEndpointCollection.php b/src/EndpointCollection/MethodEndpointCollection.php index 54466647a..d08cb965c 100644 --- a/src/EndpointCollection/MethodEndpointCollection.php +++ b/src/EndpointCollection/MethodEndpointCollection.php @@ -6,7 +6,7 @@ use Mollie\Api\Factories\GetAllPaymentMethodsQueryFactory; use Mollie\Api\Factories\GetEnabledPaymentMethodsQueryFactory; use Mollie\Api\Factories\GetPaymentMethodQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetAllMethodsQuery as GetAllPaymentMethodsQuery; use Mollie\Api\Http\Data\GetEnabledPaymentMethodsQuery; use Mollie\Api\Http\Data\GetPaymentMethodQuery; @@ -47,7 +47,7 @@ public function all($query = []): MethodCollection public function allEnabled($query = [], bool $testmode = false): MethodCollection { if (! $query instanceof GetEnabledPaymentMethodsQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetEnabledPaymentMethodsQueryFactory::new($query) ->create(); } @@ -76,7 +76,7 @@ public function allActive($query = [], ?bool $testmode = null): MethodCollection public function get(string $methodId, $query = [], bool $testmode = false): Method { if (! $query instanceof GetPaymentMethodQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaymentMethodQueryFactory::new($query) ->create(); } diff --git a/src/EndpointCollection/OrganizationEndpointCollection.php b/src/EndpointCollection/OrganizationEndpointCollection.php index 36f8a6ea7..961ee16fc 100644 --- a/src/EndpointCollection/OrganizationEndpointCollection.php +++ b/src/EndpointCollection/OrganizationEndpointCollection.php @@ -3,7 +3,7 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; @@ -22,7 +22,7 @@ class OrganizationEndpointCollection extends EndpointCollection */ public function get(string $id, $testmode = []): Organization { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Organization */ return $this->send((new GetOrganizationRequest($id))->test($testmode)); diff --git a/src/EndpointCollection/PaymentCaptureEndpointCollection.php b/src/EndpointCollection/PaymentCaptureEndpointCollection.php index 80b9e663d..1b9a52650 100644 --- a/src/EndpointCollection/PaymentCaptureEndpointCollection.php +++ b/src/EndpointCollection/PaymentCaptureEndpointCollection.php @@ -6,7 +6,7 @@ use Mollie\Api\Factories\CreatePaymentCapturePayloadFactory; use Mollie\Api\Factories\GetPaginatedPaymentCapturesQueryFactory; use Mollie\Api\Factories\GetPaymentCaptureQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; use Mollie\Api\Http\Data\GetPaymentCaptureQuery; @@ -42,7 +42,7 @@ public function createFor(Payment $payment, $payload = [], ?bool $testmode = nul public function createForId(string $paymentId, $payload = [], bool $testmode = false): Capture { if (! $payload instanceof CreatePaymentCapturePayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreatePaymentCapturePayloadFactory::new($payload)->create(); } @@ -68,7 +68,7 @@ public function getFor(Payment $payment, string $captureId, $query = [], ?bool $ public function getForId(string $paymentId, string $captureId, $query = [], bool $testmode = false): Capture { if (! $query instanceof GetPaymentCaptureQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaymentCaptureQueryFactory::new($query)->create(); } @@ -94,7 +94,7 @@ public function pageFor(Payment $payment, $query = [], ?bool $testmode = null): public function pageForId(string $paymentId, $query = [], bool $testmode = false): CaptureCollection { if (! $query instanceof GetPaginatedPaymentCapturesQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaginatedPaymentCapturesQueryFactory::new($query)->create(); } @@ -131,7 +131,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedPaymentCapturesQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PaymentChargebackEndpointCollection.php b/src/EndpointCollection/PaymentChargebackEndpointCollection.php index d2be5714f..174df4e98 100644 --- a/src/EndpointCollection/PaymentChargebackEndpointCollection.php +++ b/src/EndpointCollection/PaymentChargebackEndpointCollection.php @@ -5,7 +5,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedPaymentChargebacksQueryFactory; use Mollie\Api\Factories\GetPaymentChargebackQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; use Mollie\Api\Http\Data\GetPaymentChargebackQuery; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; @@ -35,7 +35,7 @@ public function getFor(Payment $payment, string $chargebackId, $query = [], ?boo public function getForId(string $paymentId, string $chargebackId, $query = [], bool $testmode = false): Chargeback { if (! $query instanceof GetPaymentChargebackQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaymentChargebackQueryFactory::new($query)->create(); } @@ -61,7 +61,7 @@ public function pageFor(Payment $payment, $query = []): ChargebackCollection public function pageForId(string $paymentId, $query = [], bool $testmode = false): ChargebackCollection { if (! $query instanceof GetPaginatedPaymentChargebacksQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaginatedPaymentChargebacksQueryFactory::new($query)->create(); } @@ -98,7 +98,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedPaymentChargebacksQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index eb6ce6e2e..03a324ec6 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -8,8 +8,8 @@ use Mollie\Api\Factories\GetPaymentQueryFactory; use Mollie\Api\Factories\SortablePaginatedQueryFactory; use Mollie\Api\Factories\UpdatePaymentPayloadFactory; -use Mollie\Api\Helpers; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Utility; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; @@ -39,7 +39,7 @@ class PaymentEndpointCollection extends EndpointCollection public function get(string $id, $query = [], bool $testmode = false): Payment { if (! $query instanceof GetPaymentQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaymentQueryFactory::new($query) ->create(); } @@ -58,7 +58,7 @@ public function get(string $id, $query = [], bool $testmode = false): Payment public function create($payload = [], $query = [], bool $testmode = false): Payment { if (! $payload instanceof CreatePaymentPayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreatePaymentPayloadFactory::new($payload) ->create(); } @@ -84,7 +84,7 @@ public function create($payload = [], $query = [], bool $testmode = false): Paym public function update($id, $data = [], bool $testmode = false): ?Payment { if (! $data instanceof UpdatePaymentPayload) { - $testmode = Helpers::extractBool($data, 'testmode', $testmode); + $testmode = Utility::extractBool($data, 'testmode', $testmode); $data = UpdatePaymentPayloadFactory::new($data) ->create(); } @@ -119,7 +119,7 @@ public function delete(string $id, $data = []): ?Payment */ public function cancel(string $id, $data = []): ?Payment { - $testmode = Helpers::extractBool($data, 'testmode', false); + $testmode = Utility::extractBool($data, 'testmode', false); /** @var null|Payment */ return $this->send((new CancelPaymentRequest($id))->test($testmode)); @@ -138,7 +138,7 @@ public function cancel(string $id, $data = []): ?Payment public function refund(Payment $payment, $payload = [], bool $testmode = false): Refund { if (! $payload instanceof CreateRefundPaymentPayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreateRefundPaymentPayloadFactory::new($payload) ->create(); } @@ -154,7 +154,7 @@ public function refund(Payment $payment, $payload = [], bool $testmode = false): */ public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -172,7 +172,7 @@ public function page(?string $from = null, ?int $limit = null, array $filters = */ public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index 659a7902e..7674ff487 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -6,7 +6,7 @@ use Mollie\Api\Factories\CreatePaymentLinkPayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdatePaymentLinkPayloadFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; @@ -48,7 +48,7 @@ public function create($payload = []): PaymentLink */ public function get(string $paymentLinkId, $testmode = []): PaymentLink { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var PaymentLink */ return $this->send((new GetPaymentLinkRequest($paymentLinkId))->test($testmode)); @@ -92,7 +92,7 @@ public function delete(string $paymentLinkId, bool $testmode = false): void */ public function page(?string $from = null, ?int $limit = null, $testmode = []): PaymentLinkCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, @@ -115,7 +115,7 @@ public function iterator( bool $testmode = false, bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php index 7c975392a..e0b726d18 100644 --- a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; @@ -34,7 +34,7 @@ public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $li */ public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -80,7 +80,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php index b6f3deb01..77e956cb0 100644 --- a/src/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -5,7 +5,7 @@ use Mollie\Api\Factories\CreateRefundPaymentPayloadFactory; use Mollie\Api\Factories\GetPaginatedPaymentRefundQueryFactory; use Mollie\Api\Factories\GetPaymentRefundQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\GetPaymentRefundQuery; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; @@ -40,9 +40,9 @@ public function createFor(Payment $payment, array $data, $testmode = []): Refund */ public function createForId(string $paymentId, $payload = [], $testmode = []): Refund { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); if (! $payload instanceof CreateRefundPaymentPayload) { - $testmode = Helpers::extractBool($payload, 'testmode', $testmode); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); $payload = CreateRefundPaymentPayloadFactory::new($payload) ->create(); } @@ -67,7 +67,7 @@ public function getFor(Payment $payment, string $refundId, array $parameters = [ public function getForId(string $paymentId, string $refundId, $query = [], bool $testmode = false): Refund { if (! $query instanceof GetPaymentRefundQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaymentRefundQueryFactory::new($query) ->create(); } @@ -95,7 +95,7 @@ public function cancelForPayment(Payment $payment, string $refundId, $testmode = */ public function cancelForId(string $paymentId, string $refundId, $testmode = []) { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); return $this->send((new CancelPaymentRefundRequest($paymentId, $refundId))->test($testmode)); } @@ -105,7 +105,7 @@ public function cancelForId(string $paymentId, string $refundId, $testmode = []) */ public function pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedPaymentRefundQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -152,7 +152,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedPaymentRefundQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/PermissionEndpointCollection.php b/src/EndpointCollection/PermissionEndpointCollection.php index 4509e7486..07e1d597a 100644 --- a/src/EndpointCollection/PermissionEndpointCollection.php +++ b/src/EndpointCollection/PermissionEndpointCollection.php @@ -3,7 +3,7 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; @@ -22,7 +22,7 @@ class PermissionEndpointCollection extends EndpointCollection */ public function get(string $permissionId, $testmode = []): Permission { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Permission */ return $this->send((new GetPermissionRequest($permissionId))->test($testmode)); diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index c9fd66c34..3f110d2ab 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -6,7 +6,7 @@ use Mollie\Api\Factories\CreateProfilePayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateProfilePayloadFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; @@ -51,7 +51,7 @@ public function create($payload = []): Profile */ public function get(string $profileId, $testmode = []): Profile { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var Profile */ return $this->send((new GetProfileRequest($profileId))->test($testmode)); diff --git a/src/EndpointCollection/RefundEndpointCollection.php b/src/EndpointCollection/RefundEndpointCollection.php index 0b7afbb69..9e6351910 100644 --- a/src/EndpointCollection/RefundEndpointCollection.php +++ b/src/EndpointCollection/RefundEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedRefundsQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\RefundCollection; @@ -20,7 +20,7 @@ class RefundEndpointCollection extends EndpointCollection */ public function page(?string $from = null, ?int $limit = null, array $filters = []): RefundCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedRefundsQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -43,7 +43,7 @@ public function iterator( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedRefundsQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SettlementCaptureEndpointCollection.php b/src/EndpointCollection/SettlementCaptureEndpointCollection.php index c81afb3ad..c6fc3d3d6 100644 --- a/src/EndpointCollection/SettlementCaptureEndpointCollection.php +++ b/src/EndpointCollection/SettlementCaptureEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementCapturesQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Resources\CaptureCollection; @@ -35,7 +35,7 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa public function pageForId(string $settlementId, $query = [], bool $testmode = false): CaptureCollection { if (! $query instanceof GetPaginatedSettlementCapturesQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaginatedSettlementCapturesQueryFactory::new($query)->create(); } @@ -72,7 +72,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedSettlementCapturesQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SettlementChargebackEndpointCollection.php b/src/EndpointCollection/SettlementChargebackEndpointCollection.php index 6bd8738fa..85e45536a 100644 --- a/src/EndpointCollection/SettlementChargebackEndpointCollection.php +++ b/src/EndpointCollection/SettlementChargebackEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementChargebacksQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; @@ -35,7 +35,7 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa public function pageForId(string $settlementId, $query = [], bool $testmode = false): ChargebackCollection { if (! $query instanceof GetPaginatedSettlementChargebacksQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaginatedSettlementChargebacksQueryFactory::new($query)->create(); } @@ -72,7 +72,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedSettlementChargebacksQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SettlementPaymentEndpointCollection.php b/src/EndpointCollection/SettlementPaymentEndpointCollection.php index c4f62de97..8c87d48ae 100644 --- a/src/EndpointCollection/SettlementPaymentEndpointCollection.php +++ b/src/EndpointCollection/SettlementPaymentEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\LazyCollection; @@ -35,7 +35,7 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa public function pageForId(string $settlementId, $query = [], bool $testmode = false): PaymentCollection { if (! $query instanceof SortablePaginatedQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = SortablePaginatedQueryFactory::new($query)->create(); } @@ -62,7 +62,7 @@ public function iteratorForId( array $parameters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($parameters, 'testmode', false); + $testmode = Utility::extractBool($parameters, 'testmode', false); $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SettlementRefundEndpointCollection.php b/src/EndpointCollection/SettlementRefundEndpointCollection.php index e98530559..cb4974b87 100644 --- a/src/EndpointCollection/SettlementRefundEndpointCollection.php +++ b/src/EndpointCollection/SettlementRefundEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementRefundsQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Resources\LazyCollection; @@ -35,7 +35,7 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa public function pageForId(string $settlementId, $query = [], bool $testmode = false): RefundCollection { if (! $query instanceof GetPaginatedSettlementRefundsQuery) { - $testmode = Helpers::extractBool($query, 'testmode', $testmode); + $testmode = Utility::extractBool($query, 'testmode', $testmode); $query = GetPaginatedSettlementRefundsQueryFactory::new($query)->create(); } @@ -65,7 +65,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetPaginatedSettlementRefundsQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SubscriptionEndpointCollection.php b/src/EndpointCollection/SubscriptionEndpointCollection.php index c84fa7e9a..5afb7d845 100644 --- a/src/EndpointCollection/SubscriptionEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionEndpointCollection.php @@ -7,7 +7,7 @@ use Mollie\Api\Factories\GetAllPaginatedSubscriptionsQueryFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateSubscriptionPayloadFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateSubscriptionPayload; use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; @@ -42,7 +42,7 @@ public function getFor(Customer $customer, string $subscriptionId, $testmode = [ */ public function getForId(string $customerId, string $subscriptionId, $testmode = []): Subscription { - $testmode = Helpers::extractBool($testmode, 'testmode'); + $testmode = Utility::extractBool($testmode, 'testmode'); return $this->send((new GetSubscriptionRequest($customerId, $subscriptionId))->test($testmode)); } @@ -69,7 +69,7 @@ public function createFor(Customer $customer, $data = [], bool $testmode = false public function createForId(string $customerId, $data = [], bool $testmode = false): Subscription { if (! $data instanceof CreateSubscriptionPayload) { - $testmode = Helpers::extractBool($data, 'testmode', $testmode); + $testmode = Utility::extractBool($data, 'testmode', $testmode); $data = CreateSubscriptionPayloadFactory::new($data)->create(); } @@ -86,7 +86,7 @@ public function createForId(string $customerId, $data = [], bool $testmode = fal public function update(string $customerId, string $subscriptionId, $data = [], bool $testmode = false): ?Subscription { if (! $data instanceof UpdateSubscriptionPayload) { - $testmode = Helpers::extractBool($data, 'testmode', $testmode); + $testmode = Utility::extractBool($data, 'testmode', $testmode); $data = UpdateSubscriptionPayloadFactory::new($data)->create(); } @@ -130,7 +130,7 @@ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = */ public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -162,7 +162,7 @@ public function iteratorForId( array $filters = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -186,7 +186,7 @@ public function allForId( ?int $limit = null, array $filters = [] ): SubscriptionCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetAllPaginatedSubscriptionsQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -202,7 +202,7 @@ public function iteratorForAll( array $filters = [], bool $iterateBackwards = true ): LazyCollection { - $testmode = Helpers::extractBool($filters, 'testmode', false); + $testmode = Utility::extractBool($filters, 'testmode', false); $query = GetAllPaginatedSubscriptionsQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php index 0c4a30fcf..377fbfcbe 100644 --- a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; @@ -42,7 +42,7 @@ public function pageForIds( ?int $limit = null, $testmode = [] ): PaymentCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -75,7 +75,7 @@ public function iteratorForIds( $testmode = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/EndpointCollection/TerminalEndpointCollection.php b/src/EndpointCollection/TerminalEndpointCollection.php index d98ef49b5..964fbd3a0 100644 --- a/src/EndpointCollection/TerminalEndpointCollection.php +++ b/src/EndpointCollection/TerminalEndpointCollection.php @@ -4,7 +4,7 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\LazyCollection; @@ -24,7 +24,7 @@ class TerminalEndpointCollection extends EndpointCollection */ public function get(string $id, $testmode = []): Terminal { - $testmode = Helpers::extractBool($testmode, 'testmode'); + $testmode = Utility::extractBool($testmode, 'testmode'); /** @var Terminal */ return $this->send((new GetTerminalRequest($id))->test($testmode)); @@ -39,7 +39,7 @@ public function get(string $id, $testmode = []): Terminal */ public function page(?string $from = null, ?int $limit = null, $testmode = []): TerminalCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -61,7 +61,7 @@ public function iterator( $testmode = [], bool $iterateBackwards = false ): LazyCollection { - $testmode = Helpers::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($testmode, 'testmode', false); $query = PaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index e4da5d21d..ee368bb11 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\Address; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Metadata; @@ -43,7 +43,7 @@ public function create(): CreatePaymentPayload $this->get('mandateId'), $this->get('customerId'), $this->get('profileId'), - $this->get('additional') ?? Helpers::filterByProperties(CreatePaymentPayload::class, $this->data), + $this->get('additional') ?? Utility::filterByProperties(CreatePaymentPayload::class, $this->data), ); } } diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index cc85ce59e..e97d28d36 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -4,8 +4,8 @@ use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Contracts\Factory as FactoryContract; -use Mollie\Api\Helpers; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Utility; +use Mollie\Api\Utils\Arr; abstract class Factory implements FactoryContract { @@ -37,7 +37,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey.$key; + $keys[] = $backupKey . $key; } foreach ($keys as $key) { @@ -60,7 +60,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey.$key, $key], $value); + return Arr::includes($this->data, [$backupKey . $key, $key], $value); } /** @@ -73,6 +73,6 @@ protected function includes($key, $value, $backupKey = 'filters.'): bool */ protected function mapIfNotNull($key, $composable, $backupKey = 'filters.') { - return Helpers::compose($this->get($key, null, $backupKey), $composable); + return Utility::compose($this->get($key, null, $backupKey), $composable); } } diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index 603c7ac1e..4d83ee465 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Helpers; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Utility; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\PaymentRoute; @@ -20,7 +20,7 @@ public function create(): DataCollection return new PaymentRoute( MoneyFactory::new(Arr::get($item, 'amount'))->create(), Arr::get($item, 'destination.organizationId'), - Helpers::compose( + Utility::compose( Arr::get($item, 'delayUntil'), fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) ) diff --git a/src/Factories/RefundRouteCollectionFactory.php b/src/Factories/RefundRouteCollectionFactory.php index 271ad282b..c56f9605c 100644 --- a/src/Factories/RefundRouteCollectionFactory.php +++ b/src/Factories/RefundRouteCollectionFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\RefundRoute; diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php index 618c350b6..7a289d8be 100644 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\Metadata; use Mollie\Api\Http\Data\UpdatePaymentPayload; @@ -19,7 +19,7 @@ public function create(): UpdatePaymentPayload $this->get('method'), $this->get('locale'), $this->get('restrictPaymentMethodsToCountry'), - $this->get('additional') ?? Helpers::filterByProperties(UpdatePaymentPayload::class, $this->data), + $this->get('additional') ?? Utility::filterByProperties(UpdatePaymentPayload::class, $this->data), ); } } diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index b166f975a..74ab5ee32 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -13,7 +13,7 @@ use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Helpers\Factories; +use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\IsDebuggableAdapter; @@ -132,6 +132,6 @@ protected function createResponse( */ public function version(): string { - return 'Guzzle/'.ClientInterface::MAJOR_VERSION; + return 'Guzzle/' . ClientInterface::MAJOR_VERSION; } } diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 09dc23228..9d23aac56 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -5,7 +5,7 @@ use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Helpers\Factories; +use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\IsDebuggableAdapter; @@ -78,7 +78,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response } throw new ApiException( - 'Error while sending request to Mollie API: '.$e->getMessage(), + 'Error while sending request to Mollie API: ' . $e->getMessage(), 0, $e, $request, diff --git a/src/Http/Data/Data.php b/src/Http/Data/Data.php index 8a17458d2..a752c8250 100644 --- a/src/Http/Data/Data.php +++ b/src/Http/Data/Data.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Data; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; abstract class Data implements Arrayable { diff --git a/src/Http/Data/GetClientQuery.php b/src/Http/Data/GetClientQuery.php index 3d422fdb7..13085b7a9 100644 --- a/src/Http/Data/GetClientQuery.php +++ b/src/Http/Data/GetClientQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\ClientQuery; class GetClientQuery extends Data diff --git a/src/Http/Data/GetEnabledPaymentMethodsQuery.php b/src/Http/Data/GetEnabledPaymentMethodsQuery.php index c2aa7b353..d979eeca9 100644 --- a/src/Http/Data/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Data/GetEnabledPaymentMethodsQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\MethodQuery; class GetEnabledPaymentMethodsQuery extends Data diff --git a/src/Http/Data/GetPaginatedClientQuery.php b/src/Http/Data/GetPaginatedClientQuery.php index 0b8efbad7..36a0143b2 100644 --- a/src/Http/Data/GetPaginatedClientQuery.php +++ b/src/Http/Data/GetPaginatedClientQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\ClientQuery; class GetPaginatedClientQuery extends Data diff --git a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php index 6dcfacdf6..9be1254eb 100644 --- a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentCapturesQuery extends Data diff --git a/src/Http/Data/GetPaymentCaptureQuery.php b/src/Http/Data/GetPaymentCaptureQuery.php index bb8706db4..56058bcdc 100644 --- a/src/Http/Data/GetPaymentCaptureQuery.php +++ b/src/Http/Data/GetPaymentCaptureQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentCaptureQuery extends Data diff --git a/src/Http/Data/GetPaymentMethodQuery.php b/src/Http/Data/GetPaymentMethodQuery.php index 22eb50bfb..3dfa7d61c 100644 --- a/src/Http/Data/GetPaymentMethodQuery.php +++ b/src/Http/Data/GetPaymentMethodQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\MethodQuery; class GetPaymentMethodQuery extends Data diff --git a/src/Http/Data/GetPaymentQuery.php b/src/Http/Data/GetPaymentQuery.php index b9a2d44f9..725a03c47 100644 --- a/src/Http/Data/GetPaymentQuery.php +++ b/src/Http/Data/GetPaymentQuery.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentQuery; class GetPaymentQuery extends Data diff --git a/src/Helpers/MiddlewareHandlers.php b/src/Http/Middleware.php similarity index 90% rename from src/Helpers/MiddlewareHandlers.php rename to src/Http/Middleware.php index ab9efe5d6..200f4851d 100644 --- a/src/Helpers/MiddlewareHandlers.php +++ b/src/Http/Middleware.php @@ -1,12 +1,14 @@ ...$handlersCollection + * @param array ...$handlersCollection */ public function merge(...$handlersCollection): self { - /** @var MiddlewareHandlers $handlers */ + /** @var Middleware $handlers */ foreach ($handlersCollection as $handlers) { $onRequestHandlers = array_merge( $this->onRequest->getHandlers(), diff --git a/src/Helpers/Handler.php b/src/Http/Middleware/Handler.php similarity index 93% rename from src/Helpers/Handler.php rename to src/Http/Middleware/Handler.php index b5944a64d..b3cc7eefd 100644 --- a/src/Helpers/Handler.php +++ b/src/Http/Middleware/Handler.php @@ -1,6 +1,6 @@ onResponse(new GuardResponse, MiddlewarePriority::HIGH) ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH) ->onResponse(new Hydrate, 'hydration', MiddlewarePriority::LOW); - } public function setTestmode(bool $testmode): self diff --git a/src/Http/PendingRequest/SetUserAgent.php b/src/Http/PendingRequest/SetUserAgent.php index 678b7c091..f821430af 100644 --- a/src/Http/PendingRequest/SetUserAgent.php +++ b/src/Http/PendingRequest/SetUserAgent.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Http\PendingRequest; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Auth\AccessTokenAuthenticator; use Mollie\Api\Http\PendingRequest; diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 7ffb52afe..2ab0653d9 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -43,7 +43,7 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\Helpers\Url; +use Mollie\Api\Utils\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Traits\HandlesAuthentication; diff --git a/src/Repositories/ArrayStore.php b/src/Repositories/ArrayStore.php index aefc684d2..635967abf 100644 --- a/src/Repositories/ArrayStore.php +++ b/src/Repositories/ArrayStore.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Repositories; use Mollie\Api\Contracts\ArrayRepository; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; class ArrayStore implements ArrayRepository { diff --git a/src/Resources/AnyResource.php b/src/Resources/AnyResource.php index ce0c470d6..adaca3035 100644 --- a/src/Resources/AnyResource.php +++ b/src/Resources/AnyResource.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use stdClass; /** diff --git a/src/Traits/HasDefaultFactories.php b/src/Traits/HasDefaultFactories.php index 5dc03e213..00336a0e9 100644 --- a/src/Traits/HasDefaultFactories.php +++ b/src/Traits/HasDefaultFactories.php @@ -2,7 +2,7 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Helpers\Factories; +use Mollie\Api\Utils\Factories; use Nyholm\Psr7\Factory\Psr17Factory; trait HasDefaultFactories diff --git a/src/Traits/HasMiddleware.php b/src/Traits/HasMiddleware.php index 53bd5cf5d..444c95ed1 100644 --- a/src/Traits/HasMiddleware.php +++ b/src/Traits/HasMiddleware.php @@ -2,14 +2,14 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Helpers\MiddlewareHandlers; +use Mollie\Api\Http\Middleware; trait HasMiddleware { - protected MiddlewareHandlers $middleware; + protected Middleware $middleware; - public function middleware(): MiddlewareHandlers + public function middleware(): Middleware { - return $this->middleware ??= new MiddlewareHandlers; + return $this->middleware ??= new Middleware; } } diff --git a/src/Traits/Initializable.php b/src/Traits/Initializable.php index 7e456944b..74abba59f 100644 --- a/src/Traits/Initializable.php +++ b/src/Traits/Initializable.php @@ -2,17 +2,17 @@ namespace Mollie\Api\Traits; -use Mollie\Api\Helpers; +use Mollie\Api\Utils\Utility; use ReflectionClass; trait Initializable { protected function initializeTraits(): void { - foreach (Helpers::classUsesRecursive(static::class) as $trait) { + foreach (Utility::classUsesRecursive(static::class) as $trait) { $trait = new ReflectionClass($trait); - $method = 'initialize'.$trait->getShortName(); + $method = 'initialize' . $trait->getShortName(); if (method_exists($this, $method)) { $this->{$method}(); diff --git a/src/Traits/ManagesPsrRequests.php b/src/Traits/ManagesPsrRequests.php index cec2ba752..35d16d92c 100644 --- a/src/Traits/ManagesPsrRequests.php +++ b/src/Traits/ManagesPsrRequests.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Traits; use Mollie\Api\Contracts\PayloadRepository; -use Mollie\Api\Helpers\Factories; -use Mollie\Api\Helpers\Url; +use Mollie\Api\Utils\Factories; +use Mollie\Api\Utils\Url; use Mollie\Api\Http\PendingRequest; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; diff --git a/src/Helpers/Arr.php b/src/Utils/Arr.php similarity index 99% rename from src/Helpers/Arr.php rename to src/Utils/Arr.php index 613871f62..8479b3aad 100644 --- a/src/Helpers/Arr.php +++ b/src/Utils/Arr.php @@ -1,6 +1,6 @@ $prop->getName(), + fn(ReflectionProperty $prop) => $prop->getName(), static::getProperties($class) ); return array_filter( $array, - fn ($key) => ! in_array($key, $properties, true), + fn($key) => ! in_array($key, $properties, true), ARRAY_FILTER_USE_KEY ); } @@ -96,7 +96,7 @@ public static function compose($value, $composable, $default = null) } $composable = is_string($composable) - ? fn ($value) => new $composable($value) + ? fn($value) => new $composable($value) : $composable; return (bool) $value ? $composable($value) : $default; diff --git a/tests/Fixtures/MockResponse.php b/tests/Fixtures/MockResponse.php index eabcbcceb..7b4352778 100644 --- a/tests/Fixtures/MockResponse.php +++ b/tests/Fixtures/MockResponse.php @@ -2,7 +2,7 @@ namespace Tests\Fixtures; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Traits\HasDefaultFactories; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; @@ -55,7 +55,7 @@ public function body(): string $path = Arr::join([ __DIR__, 'Responses', - $body.'.json', + $body . '.json', ], DIRECTORY_SEPARATOR); $contents = file_get_contents($path); diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index d009464e4..62c4f7e6b 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -3,7 +3,7 @@ namespace Tests\Http\Adapter; use Mollie\Api\Contracts\HttpAdapterContract; -use Mollie\Api\Helpers\Arr; +use Mollie\Api\Utils\Arr; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\HasDefaultFactories; @@ -52,7 +52,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response private function guardAgainstStrayRequests(string $requestClass): void { if (! Arr::has($this->expected, $requestClass)) { - throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); + throw new \RuntimeException('The request class ' . $requestClass . ' is not expected.'); } } @@ -84,7 +84,7 @@ public function recorded(?callable $callback = null): array return $this->recorded; } - return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); + return array_filter($this->recorded, fn($recorded) => $callback($recorded[0], $recorded[1])); } /** @@ -93,7 +93,7 @@ public function recorded(?callable $callback = null): array public function assertSent($callback): void { if (is_string($callback)) { - $callback = fn ($request) => get_class($request) === $callback; + $callback = fn($request) => get_class($request) === $callback; } PHPUnit::assertTrue( diff --git a/tests/Helpers/HandlersTest.php b/tests/Http/Middleware/HandlersTest.php similarity index 89% rename from tests/Helpers/HandlersTest.php rename to tests/Http/Middleware/HandlersTest.php index 8eab87014..86c8e5490 100644 --- a/tests/Helpers/HandlersTest.php +++ b/tests/Http/Middleware/HandlersTest.php @@ -1,11 +1,11 @@ add(fn () => null); + $handlers->add(fn() => null); $this->assertCount(1, $handlers->getHandlers()); } diff --git a/tests/Helpers/MiddlewareHandlersTest.php b/tests/Http/MiddlewareTest.php similarity index 87% rename from tests/Helpers/MiddlewareHandlersTest.php rename to tests/Http/MiddlewareTest.php index 48c4c8bb7..b29bad56e 100644 --- a/tests/Helpers/MiddlewareHandlersTest.php +++ b/tests/Http/MiddlewareTest.php @@ -1,21 +1,22 @@ onRequest(function (PendingRequest $pendingRequest) { $pendingRequest->headers()->add('Foo', 'Bar'); @@ -35,7 +36,7 @@ public function it_can_add_request_middleware_and_execute_it(): void */ public function it_can_add_response_middleware_and_execute_it(): void { - $middlewareHandlers = new MiddlewareHandlers; + $middlewareHandlers = new Middleware; $middlewareHandlers->onResponse(function (Response $response) { $this->assertTrue($response->successful()); @@ -57,8 +58,8 @@ public function it_can_add_response_middleware_and_execute_it(): void */ public function it_can_merge_middleware_handlers(): void { - $middlewareHandlers1 = new MiddlewareHandlers; - $middlewareHandlers2 = new MiddlewareHandlers; + $middlewareHandlers1 = new Middleware; + $middlewareHandlers2 = new Middleware; $middlewareHandlers1->onRequest(function (PendingRequest $pendingRequest) { $pendingRequest->headers()->add('Request-One', 'One'); diff --git a/tests/Helpers/ArrTest.php b/tests/Utils/ArrTest.php similarity index 98% rename from tests/Helpers/ArrTest.php rename to tests/Utils/ArrTest.php index eb7e82f78..916d57dbd 100644 --- a/tests/Helpers/ArrTest.php +++ b/tests/Utils/ArrTest.php @@ -1,9 +1,9 @@ assertContains(TestTrait1::class, $result); $this->assertContains(TestTrait2::class, $result); @@ -22,7 +22,7 @@ public function class_uses_recursive() /** @test */ public function trait_uses_recursive() { - $result = Helpers::traitUsesRecursive(TestTraitMain::class); + $result = Utility::traitUsesRecursive(TestTraitMain::class); $this->assertContains(TestTraitBase::class, $result); $this->assertContains(TestTraitNested::class, $result); @@ -32,12 +32,12 @@ public function trait_uses_recursive() public function get_properties() { // Test getting all properties - $allProps = Helpers::getProperties(TestPropertiesClass::class); + $allProps = Utility::getProperties(TestPropertiesClass::class); $this->assertCount(3, $allProps); $this->assertContainsOnlyInstancesOf(ReflectionProperty::class, $allProps); // Test getting only public properties - $publicProps = Helpers::getProperties(TestPropertiesClass::class, ReflectionProperty::IS_PUBLIC); + $publicProps = Utility::getProperties(TestPropertiesClass::class, ReflectionProperty::IS_PUBLIC); $this->assertCount(1, $publicProps); $this->assertEquals('publicProp', $publicProps[0]->getName()); } @@ -51,7 +51,7 @@ public function filter_by_properties() 'extraProp' => 'extraValue', ]; - $filtered = Helpers::filterByProperties(TestFilterClass::class, $array); + $filtered = Utility::filterByProperties(TestFilterClass::class, $array); $this->assertArrayHasKey('extraProp', $filtered); $this->assertArrayNotHasKey('prop1', $filtered); @@ -62,18 +62,18 @@ public function filter_by_properties() public function compose() { // Test with callable - $composedWithCallable = Helpers::compose(5, fn ($x) => $x * 2); + $composedWithCallable = Utility::compose(5, fn($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); - $composedWithClass = Helpers::compose('test', TestComposable::class); + $composedWithClass = Utility::compose('test', TestComposable::class); $this->assertInstanceOf(TestComposable::class, $composedWithClass); $this->assertEquals('test', $composedWithClass->value); // Test with falsy value - $composedWithDefault = Helpers::compose(false, fn ($x) => $x * 2, 'default'); + $composedWithDefault = Utility::compose(false, fn($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); - $existingValueIsNotOverriden = Helpers::compose(new Metadata(['key' => 'value']), Metadata::class); + $existingValueIsNotOverriden = Utility::compose(new Metadata(['key' => 'value']), Metadata::class); $this->assertInstanceOf(Metadata::class, $existingValueIsNotOverriden); $this->assertEquals(['key' => 'value'], $existingValueIsNotOverriden->data); } @@ -82,16 +82,16 @@ public function compose() public function extract_bool() { // Test with direct boolean - $this->assertTrue(Helpers::extractBool(true, 'key')); - $this->assertFalse(Helpers::extractBool(false, 'key')); + $this->assertTrue(Utility::extractBool(true, 'key')); + $this->assertFalse(Utility::extractBool(false, 'key')); // Test with array $array = ['enabled' => true]; - $this->assertTrue(Helpers::extractBool($array, 'enabled')); - $this->assertFalse(Helpers::extractBool($array, 'nonexistent')); + $this->assertTrue(Utility::extractBool($array, 'enabled')); + $this->assertFalse(Utility::extractBool($array, 'nonexistent')); // Test with default value - $this->assertTrue(Helpers::extractBool([], 'key', true)); + $this->assertTrue(Utility::extractBool([], 'key', true)); } } From fbf8e3ec85ff80e4b0fc98bc673aafbee126e141 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 12 Dec 2024 13:32:42 +0000 Subject: [PATCH 116/131] Fixes coding style --- src/Contracts/HttpAdapterContract.php | 2 +- src/EndpointCollection/BalanceEndpointCollection.php | 2 +- .../BalanceReportEndpointCollection.php | 2 +- src/EndpointCollection/ChargebackEndpointCollection.php | 2 +- src/EndpointCollection/CustomerEndpointCollection.php | 2 +- .../CustomerPaymentsEndpointCollection.php | 4 ++-- src/EndpointCollection/MandateEndpointCollection.php | 2 +- src/EndpointCollection/MethodEndpointCollection.php | 2 +- src/EndpointCollection/OrganizationEndpointCollection.php | 2 +- .../PaymentCaptureEndpointCollection.php | 2 +- .../PaymentChargebackEndpointCollection.php | 2 +- src/EndpointCollection/PaymentEndpointCollection.php | 4 ++-- src/EndpointCollection/PaymentLinkEndpointCollection.php | 2 +- .../PaymentLinkPaymentEndpointCollection.php | 2 +- .../PaymentRefundEndpointCollection.php | 2 +- src/EndpointCollection/PermissionEndpointCollection.php | 2 +- src/EndpointCollection/ProfileEndpointCollection.php | 2 +- src/EndpointCollection/RefundEndpointCollection.php | 2 +- .../SettlementCaptureEndpointCollection.php | 2 +- .../SettlementChargebackEndpointCollection.php | 2 +- .../SettlementPaymentEndpointCollection.php | 2 +- .../SettlementRefundEndpointCollection.php | 2 +- src/EndpointCollection/SubscriptionEndpointCollection.php | 2 +- .../SubscriptionPaymentEndpointCollection.php | 2 +- src/EndpointCollection/TerminalEndpointCollection.php | 2 +- src/Factories/CreatePaymentPayloadFactory.php | 2 +- src/Factories/Factory.php | 6 +++--- src/Factories/PaymentRouteCollectionFactory.php | 4 ++-- src/Factories/RefundRouteCollectionFactory.php | 2 +- src/Factories/UpdatePaymentPayloadFactory.php | 2 +- src/Http/Adapter/GuzzleMollieHttpAdapter.php | 4 ++-- src/Http/Adapter/PSR18MollieHttpAdapter.php | 4 ++-- src/Http/Data/GetClientQuery.php | 2 +- src/Http/Data/GetEnabledPaymentMethodsQuery.php | 2 +- src/Http/Data/GetPaginatedClientQuery.php | 2 +- src/Http/Data/GetPaginatedPaymentCapturesQuery.php | 2 +- src/Http/Data/GetPaymentCaptureQuery.php | 2 +- src/Http/Data/GetPaymentMethodQuery.php | 2 +- src/Http/Data/GetPaymentQuery.php | 2 +- src/Http/Middleware.php | 2 -- src/Http/PendingRequest.php | 4 ++-- src/Http/PendingRequest/SetUserAgent.php | 2 +- src/MollieApiClient.php | 2 +- src/Traits/Initializable.php | 2 +- src/Traits/ManagesPsrRequests.php | 2 +- src/Utils/Url.php | 2 +- src/Utils/Utility.php | 7 +++---- tests/Fixtures/MockResponse.php | 4 ++-- tests/Http/Adapter/MockMollieHttpAdapter.php | 8 ++++---- tests/Http/Middleware/HandlersTest.php | 2 +- tests/Http/MiddlewareTest.php | 2 +- tests/Utils/ArrTest.php | 2 +- tests/Utils/UtilityTest.php | 6 +++--- 53 files changed, 68 insertions(+), 71 deletions(-) diff --git a/src/Contracts/HttpAdapterContract.php b/src/Contracts/HttpAdapterContract.php index 9fae64565..d8ef4b8b3 100644 --- a/src/Contracts/HttpAdapterContract.php +++ b/src/Contracts/HttpAdapterContract.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Contracts; -use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; +use Mollie\Api\Utils\Factories; interface HttpAdapterContract { diff --git a/src/EndpointCollection/BalanceEndpointCollection.php b/src/EndpointCollection/BalanceEndpointCollection.php index 71eea6651..39030d7d6 100644 --- a/src/EndpointCollection/BalanceEndpointCollection.php +++ b/src/EndpointCollection/BalanceEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedBalanceQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetBalanceRequest; use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; use Mollie\Api\Resources\LazyCollection; +use Mollie\Api\Utils\Utility; class BalanceEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/BalanceReportEndpointCollection.php b/src/EndpointCollection/BalanceReportEndpointCollection.php index 4985d9d4a..7abe127e6 100644 --- a/src/EndpointCollection/BalanceReportEndpointCollection.php +++ b/src/EndpointCollection/BalanceReportEndpointCollection.php @@ -3,11 +3,11 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Factories\GetBalanceReportQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; +use Mollie\Api\Utils\Utility; class BalanceReportEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/ChargebackEndpointCollection.php b/src/EndpointCollection/ChargebackEndpointCollection.php index ee68dc2e5..4db3798bd 100644 --- a/src/EndpointCollection/ChargebackEndpointCollection.php +++ b/src/EndpointCollection/ChargebackEndpointCollection.php @@ -4,10 +4,10 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedChargebackQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; +use Mollie\Api\Utils\Utility; class ChargebackEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index d97b51e7e..cb6168f8b 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -6,7 +6,6 @@ use Mollie\Api\Factories\CreateCustomerPayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateCustomerPayloadFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Http\Requests\CreateCustomerRequest; @@ -17,6 +16,7 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Resources\LazyCollection; +use Mollie\Api\Utils\Utility; class CustomerEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php index 67038c35f..a602c29eb 100644 --- a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php +++ b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php @@ -5,8 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\CreatePaymentPayloadFactory; use Mollie\Api\Factories\GetPaginatedCustomerPaymentsQueryFactory; -use Mollie\Api\Utils\Utility; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; @@ -15,6 +13,8 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use Mollie\Api\Utils\Arr; +use Mollie\Api\Utils\Utility; class CustomerPaymentsEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php index 8d8b8190c..89572be6f 100644 --- a/src/EndpointCollection/MandateEndpointCollection.php +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\CreateMandatePayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; @@ -15,6 +14,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; +use Mollie\Api\Utils\Utility; class MandateEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/MethodEndpointCollection.php b/src/EndpointCollection/MethodEndpointCollection.php index d08cb965c..41fb5de7d 100644 --- a/src/EndpointCollection/MethodEndpointCollection.php +++ b/src/EndpointCollection/MethodEndpointCollection.php @@ -6,7 +6,6 @@ use Mollie\Api\Factories\GetAllPaymentMethodsQueryFactory; use Mollie\Api\Factories\GetEnabledPaymentMethodsQueryFactory; use Mollie\Api\Factories\GetPaymentMethodQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetAllMethodsQuery as GetAllPaymentMethodsQuery; use Mollie\Api\Http\Data\GetEnabledPaymentMethodsQuery; use Mollie\Api\Http\Data\GetPaymentMethodQuery; @@ -15,6 +14,7 @@ use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; +use Mollie\Api\Utils\Utility; class MethodEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/OrganizationEndpointCollection.php b/src/EndpointCollection/OrganizationEndpointCollection.php index 961ee16fc..28432b713 100644 --- a/src/EndpointCollection/OrganizationEndpointCollection.php +++ b/src/EndpointCollection/OrganizationEndpointCollection.php @@ -3,11 +3,11 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; +use Mollie\Api\Utils\Utility; class OrganizationEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentCaptureEndpointCollection.php b/src/EndpointCollection/PaymentCaptureEndpointCollection.php index 1b9a52650..613e90d7c 100644 --- a/src/EndpointCollection/PaymentCaptureEndpointCollection.php +++ b/src/EndpointCollection/PaymentCaptureEndpointCollection.php @@ -6,7 +6,6 @@ use Mollie\Api\Factories\CreatePaymentCapturePayloadFactory; use Mollie\Api\Factories\GetPaginatedPaymentCapturesQueryFactory; use Mollie\Api\Factories\GetPaymentCaptureQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; use Mollie\Api\Http\Data\GetPaymentCaptureQuery; @@ -17,6 +16,7 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; +use Mollie\Api\Utils\Utility; class PaymentCaptureEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentChargebackEndpointCollection.php b/src/EndpointCollection/PaymentChargebackEndpointCollection.php index 174df4e98..fd6bbcd91 100644 --- a/src/EndpointCollection/PaymentChargebackEndpointCollection.php +++ b/src/EndpointCollection/PaymentChargebackEndpointCollection.php @@ -5,7 +5,6 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedPaymentChargebacksQueryFactory; use Mollie\Api\Factories\GetPaymentChargebackQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; use Mollie\Api\Http\Data\GetPaymentChargebackQuery; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; @@ -14,6 +13,7 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; +use Mollie\Api\Utils\Utility; class PaymentChargebackEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index 03a324ec6..9926833b8 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -8,8 +8,6 @@ use Mollie\Api\Factories\GetPaymentQueryFactory; use Mollie\Api\Factories\SortablePaginatedQueryFactory; use Mollie\Api\Factories\UpdatePaymentPayloadFactory; -use Mollie\Api\Utils\Utility; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; @@ -25,6 +23,8 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; +use Mollie\Api\Utils\Arr; +use Mollie\Api\Utils\Utility; class PaymentEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index 7674ff487..a6afb5248 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -6,7 +6,6 @@ use Mollie\Api\Factories\CreatePaymentLinkPayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdatePaymentLinkPayloadFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; @@ -17,6 +16,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; +use Mollie\Api\Utils\Utility; class PaymentLinkEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php index e0b726d18..dbe1c4c76 100644 --- a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\PaymentLink; +use Mollie\Api\Utils\Utility; class PaymentLinkPaymentEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php index 77e956cb0..75ac14e45 100644 --- a/src/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -5,7 +5,6 @@ use Mollie\Api\Factories\CreateRefundPaymentPayloadFactory; use Mollie\Api\Factories\GetPaginatedPaymentRefundQueryFactory; use Mollie\Api\Factories\GetPaymentRefundQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\GetPaymentRefundQuery; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; @@ -16,6 +15,7 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use Mollie\Api\Utils\Utility; class PaymentRefundEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/PermissionEndpointCollection.php b/src/EndpointCollection/PermissionEndpointCollection.php index 07e1d597a..c3672ae31 100644 --- a/src/EndpointCollection/PermissionEndpointCollection.php +++ b/src/EndpointCollection/PermissionEndpointCollection.php @@ -3,11 +3,11 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; +use Mollie\Api\Utils\Utility; class PermissionEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index 3f110d2ab..a70456762 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -6,7 +6,6 @@ use Mollie\Api\Factories\CreateProfilePayloadFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateProfilePayloadFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; @@ -18,6 +17,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; +use Mollie\Api\Utils\Utility; class ProfileEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/RefundEndpointCollection.php b/src/EndpointCollection/RefundEndpointCollection.php index 9e6351910..2cfa43a28 100644 --- a/src/EndpointCollection/RefundEndpointCollection.php +++ b/src/EndpointCollection/RefundEndpointCollection.php @@ -4,10 +4,10 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedRefundsQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\RefundCollection; +use Mollie\Api\Utils\Utility; class RefundEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SettlementCaptureEndpointCollection.php b/src/EndpointCollection/SettlementCaptureEndpointCollection.php index c6fc3d3d6..aea502dbf 100644 --- a/src/EndpointCollection/SettlementCaptureEndpointCollection.php +++ b/src/EndpointCollection/SettlementCaptureEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementCapturesQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; +use Mollie\Api\Utils\Utility; class SettlementCaptureEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SettlementChargebackEndpointCollection.php b/src/EndpointCollection/SettlementChargebackEndpointCollection.php index 85e45536a..78651f22b 100644 --- a/src/EndpointCollection/SettlementChargebackEndpointCollection.php +++ b/src/EndpointCollection/SettlementChargebackEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementChargebacksQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; +use Mollie\Api\Utils\Utility; class SettlementChargebackEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SettlementPaymentEndpointCollection.php b/src/EndpointCollection/SettlementPaymentEndpointCollection.php index 8c87d48ae..f5866b2fa 100644 --- a/src/EndpointCollection/SettlementPaymentEndpointCollection.php +++ b/src/EndpointCollection/SettlementPaymentEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; +use Mollie\Api\Utils\Utility; class SettlementPaymentEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SettlementRefundEndpointCollection.php b/src/EndpointCollection/SettlementRefundEndpointCollection.php index cb4974b87..26368fa82 100644 --- a/src/EndpointCollection/SettlementRefundEndpointCollection.php +++ b/src/EndpointCollection/SettlementRefundEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\GetPaginatedSettlementRefundsQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; +use Mollie\Api\Utils\Utility; class SettlementRefundEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SubscriptionEndpointCollection.php b/src/EndpointCollection/SubscriptionEndpointCollection.php index 5afb7d845..c73d19a97 100644 --- a/src/EndpointCollection/SubscriptionEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionEndpointCollection.php @@ -7,7 +7,6 @@ use Mollie\Api\Factories\GetAllPaginatedSubscriptionsQueryFactory; use Mollie\Api\Factories\PaginatedQueryFactory; use Mollie\Api\Factories\UpdateSubscriptionPayloadFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\CreateSubscriptionPayload; use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; @@ -20,6 +19,7 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; +use Mollie\Api\Utils\Utility; class SubscriptionEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php index 377fbfcbe..d6bfd1e01 100644 --- a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php @@ -4,11 +4,11 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; +use Mollie\Api\Utils\Utility; class SubscriptionPaymentEndpointCollection extends EndpointCollection { diff --git a/src/EndpointCollection/TerminalEndpointCollection.php b/src/EndpointCollection/TerminalEndpointCollection.php index 964fbd3a0..fd3fdad2d 100644 --- a/src/EndpointCollection/TerminalEndpointCollection.php +++ b/src/EndpointCollection/TerminalEndpointCollection.php @@ -4,12 +4,12 @@ use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; +use Mollie\Api\Utils\Utility; class TerminalEndpointCollection extends EndpointCollection { diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php index ee368bb11..c9aeaeca6 100644 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ b/src/Factories/CreatePaymentPayloadFactory.php @@ -2,10 +2,10 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\Address; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Utils\Utility; class CreatePaymentPayloadFactory extends Factory { diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index e97d28d36..0ac9262de 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -4,8 +4,8 @@ use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Contracts\Factory as FactoryContract; -use Mollie\Api\Utils\Utility; use Mollie\Api\Utils\Arr; +use Mollie\Api\Utils\Utility; abstract class Factory implements FactoryContract { @@ -37,7 +37,7 @@ protected function get($key, $default = null, $backupKey = 'filters.') $keys = (array) $key; if ($backupKey !== null) { - $keys[] = $backupKey . $key; + $keys[] = $backupKey.$key; } foreach ($keys as $key) { @@ -60,7 +60,7 @@ protected function has($keys): bool */ protected function includes($key, $value, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey . $key, $key], $value); + return Arr::includes($this->data, [$backupKey.$key, $key], $value); } /** diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index 4d83ee465..a430ae229 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -3,10 +3,10 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; -use Mollie\Api\Utils\Utility; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\PaymentRoute; +use Mollie\Api\Utils\Arr; +use Mollie\Api\Utils\Utility; class PaymentRouteCollectionFactory extends Factory { diff --git a/src/Factories/RefundRouteCollectionFactory.php b/src/Factories/RefundRouteCollectionFactory.php index c56f9605c..788cfa649 100644 --- a/src/Factories/RefundRouteCollectionFactory.php +++ b/src/Factories/RefundRouteCollectionFactory.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\RefundRoute; +use Mollie\Api\Utils\Arr; class RefundRouteCollectionFactory extends Factory { diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php index 7a289d8be..7c3b2992b 100644 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ b/src/Factories/UpdatePaymentPayloadFactory.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\Metadata; use Mollie\Api\Http\Data\UpdatePaymentPayload; +use Mollie\Api\Utils\Utility; class UpdatePaymentPayloadFactory extends Factory { diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index 74ab5ee32..5500bbab0 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -13,10 +13,10 @@ use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\IsDebuggableAdapter; +use Mollie\Api\Utils\Factories; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Throwable; @@ -132,6 +132,6 @@ protected function createResponse( */ public function version(): string { - return 'Guzzle/' . ClientInterface::MAJOR_VERSION; + return 'Guzzle/'.ClientInterface::MAJOR_VERSION; } } diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 9d23aac56..7e2f082cb 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -5,10 +5,10 @@ use Mollie\Api\Contracts\HttpAdapterContract; use Mollie\Api\Contracts\SupportsDebuggingContract; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Utils\Factories; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\IsDebuggableAdapter; +use Mollie\Api\Utils\Factories; use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; @@ -78,7 +78,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response } throw new ApiException( - 'Error while sending request to Mollie API: ' . $e->getMessage(), + 'Error while sending request to Mollie API: '.$e->getMessage(), 0, $e, $request, diff --git a/src/Http/Data/GetClientQuery.php b/src/Http/Data/GetClientQuery.php index 13085b7a9..804d7f0b7 100644 --- a/src/Http/Data/GetClientQuery.php +++ b/src/Http/Data/GetClientQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\ClientQuery; +use Mollie\Api\Utils\Arr; class GetClientQuery extends Data { diff --git a/src/Http/Data/GetEnabledPaymentMethodsQuery.php b/src/Http/Data/GetEnabledPaymentMethodsQuery.php index d979eeca9..47ab4eb50 100644 --- a/src/Http/Data/GetEnabledPaymentMethodsQuery.php +++ b/src/Http/Data/GetEnabledPaymentMethodsQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\MethodQuery; +use Mollie\Api\Utils\Arr; class GetEnabledPaymentMethodsQuery extends Data { diff --git a/src/Http/Data/GetPaginatedClientQuery.php b/src/Http/Data/GetPaginatedClientQuery.php index 36a0143b2..1acc72136 100644 --- a/src/Http/Data/GetPaginatedClientQuery.php +++ b/src/Http/Data/GetPaginatedClientQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\ClientQuery; +use Mollie\Api\Utils\Arr; class GetPaginatedClientQuery extends Data { diff --git a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php index 9be1254eb..1fe966962 100644 --- a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php +++ b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Utils\Arr; class GetPaginatedPaymentCapturesQuery extends Data { diff --git a/src/Http/Data/GetPaymentCaptureQuery.php b/src/Http/Data/GetPaymentCaptureQuery.php index 56058bcdc..d4f4caeb6 100644 --- a/src/Http/Data/GetPaymentCaptureQuery.php +++ b/src/Http/Data/GetPaymentCaptureQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Utils\Arr; class GetPaymentCaptureQuery extends Data { diff --git a/src/Http/Data/GetPaymentMethodQuery.php b/src/Http/Data/GetPaymentMethodQuery.php index 3dfa7d61c..4d85fee2b 100644 --- a/src/Http/Data/GetPaymentMethodQuery.php +++ b/src/Http/Data/GetPaymentMethodQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\MethodQuery; +use Mollie\Api\Utils\Arr; class GetPaymentMethodQuery extends Data { diff --git a/src/Http/Data/GetPaymentQuery.php b/src/Http/Data/GetPaymentQuery.php index 725a03c47..cece7d96d 100644 --- a/src/Http/Data/GetPaymentQuery.php +++ b/src/Http/Data/GetPaymentQuery.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Data; -use Mollie\Api\Utils\Arr; use Mollie\Api\Types\PaymentQuery; +use Mollie\Api\Utils\Arr; class GetPaymentQuery extends Data { diff --git a/src/Http/Middleware.php b/src/Http/Middleware.php index 200f4851d..2d13ce953 100644 --- a/src/Http/Middleware.php +++ b/src/Http/Middleware.php @@ -5,8 +5,6 @@ use Mollie\Api\Contracts\ViableResponse; use Mollie\Api\Http\Middleware\Handlers; use Mollie\Api\Http\Middleware\MiddlewarePriority; -use Mollie\Api\Http\PendingRequest; -use Mollie\Api\Http\Response; class Middleware { diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index fa9784f96..de7325514 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -7,12 +7,11 @@ use Mollie\Api\Contracts\PayloadRepository; use Mollie\Api\Contracts\SupportsTestmodeInPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Middleware\MiddlewarePriority; -use Mollie\Api\Utils\Url; use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; use Mollie\Api\Http\Middleware\EvaluateHydrationSetting; use Mollie\Api\Http\Middleware\GuardResponse; use Mollie\Api\Http\Middleware\Hydrate; +use Mollie\Api\Http\Middleware\MiddlewarePriority; use Mollie\Api\Http\Middleware\ResetIdempotencyKey; use Mollie\Api\Http\Middleware\ThrowExceptionIfRequestFailed; use Mollie\Api\Http\PendingRequest\AddTestmodeIfEnabled; @@ -24,6 +23,7 @@ use Mollie\Api\Traits\HasMiddleware; use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\ManagesPsrRequests; +use Mollie\Api\Utils\Url; class PendingRequest { diff --git a/src/Http/PendingRequest/SetUserAgent.php b/src/Http/PendingRequest/SetUserAgent.php index f821430af..55e34187e 100644 --- a/src/Http/PendingRequest/SetUserAgent.php +++ b/src/Http/PendingRequest/SetUserAgent.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\PendingRequest; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Auth\AccessTokenAuthenticator; use Mollie\Api\Http\PendingRequest; +use Mollie\Api\Utils\Arr; class SetUserAgent { diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 2ab0653d9..d95f0858c 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -43,7 +43,6 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; -use Mollie\Api\Utils\Url; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Traits\HandlesAuthentication; @@ -57,6 +56,7 @@ use Mollie\Api\Traits\HasRequestProperties; use Mollie\Api\Traits\Initializable; use Mollie\Api\Traits\SendsRequests; +use Mollie\Api\Utils\Url; /** * @property BalanceEndpointCollection $balances diff --git a/src/Traits/Initializable.php b/src/Traits/Initializable.php index 74abba59f..b4610978e 100644 --- a/src/Traits/Initializable.php +++ b/src/Traits/Initializable.php @@ -12,7 +12,7 @@ protected function initializeTraits(): void foreach (Utility::classUsesRecursive(static::class) as $trait) { $trait = new ReflectionClass($trait); - $method = 'initialize' . $trait->getShortName(); + $method = 'initialize'.$trait->getShortName(); if (method_exists($this, $method)) { $this->{$method}(); diff --git a/src/Traits/ManagesPsrRequests.php b/src/Traits/ManagesPsrRequests.php index 35d16d92c..3ed95bda0 100644 --- a/src/Traits/ManagesPsrRequests.php +++ b/src/Traits/ManagesPsrRequests.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Traits; use Mollie\Api\Contracts\PayloadRepository; +use Mollie\Api\Http\PendingRequest; use Mollie\Api\Utils\Factories; use Mollie\Api\Utils\Url; -use Mollie\Api\Http\PendingRequest; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; diff --git a/src/Utils/Url.php b/src/Utils/Url.php index 5748408ac..965f28a7c 100644 --- a/src/Utils/Url.php +++ b/src/Utils/Url.php @@ -13,7 +13,7 @@ public static function join(string $baseUrl, string $endpoint): string return $endpoint; } - return rtrim($baseUrl, '/') . '/' . ltrim($endpoint, '/'); + return rtrim($baseUrl, '/').'/'.ltrim($endpoint, '/'); } /** diff --git a/src/Utils/Utility.php b/src/Utils/Utility.php index 0251b432e..9176b5cb0 100644 --- a/src/Utils/Utility.php +++ b/src/Utils/Utility.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Utils; -use Mollie\Api\Utils\Arr; use ReflectionClass; use ReflectionProperty; @@ -69,13 +68,13 @@ public static function getProperties($class, $flag = ReflectionProperty::IS_PUBL public static function filterByProperties($class, array $array): array { $properties = array_map( - fn(ReflectionProperty $prop) => $prop->getName(), + fn (ReflectionProperty $prop) => $prop->getName(), static::getProperties($class) ); return array_filter( $array, - fn($key) => ! in_array($key, $properties, true), + fn ($key) => ! in_array($key, $properties, true), ARRAY_FILTER_USE_KEY ); } @@ -96,7 +95,7 @@ public static function compose($value, $composable, $default = null) } $composable = is_string($composable) - ? fn($value) => new $composable($value) + ? fn ($value) => new $composable($value) : $composable; return (bool) $value ? $composable($value) : $default; diff --git a/tests/Fixtures/MockResponse.php b/tests/Fixtures/MockResponse.php index 7b4352778..7d2bde886 100644 --- a/tests/Fixtures/MockResponse.php +++ b/tests/Fixtures/MockResponse.php @@ -2,8 +2,8 @@ namespace Tests\Fixtures; -use Mollie\Api\Utils\Arr; use Mollie\Api\Traits\HasDefaultFactories; +use Mollie\Api\Utils\Arr; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; @@ -55,7 +55,7 @@ public function body(): string $path = Arr::join([ __DIR__, 'Responses', - $body . '.json', + $body.'.json', ], DIRECTORY_SEPARATOR); $contents = file_get_contents($path); diff --git a/tests/Http/Adapter/MockMollieHttpAdapter.php b/tests/Http/Adapter/MockMollieHttpAdapter.php index 62c4f7e6b..4047db076 100644 --- a/tests/Http/Adapter/MockMollieHttpAdapter.php +++ b/tests/Http/Adapter/MockMollieHttpAdapter.php @@ -3,10 +3,10 @@ namespace Tests\Http\Adapter; use Mollie\Api\Contracts\HttpAdapterContract; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Response; use Mollie\Api\Traits\HasDefaultFactories; +use Mollie\Api\Utils\Arr; use PHPUnit\Framework\Assert as PHPUnit; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; @@ -52,7 +52,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response private function guardAgainstStrayRequests(string $requestClass): void { if (! Arr::has($this->expected, $requestClass)) { - throw new \RuntimeException('The request class ' . $requestClass . ' is not expected.'); + throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); } } @@ -84,7 +84,7 @@ public function recorded(?callable $callback = null): array return $this->recorded; } - return array_filter($this->recorded, fn($recorded) => $callback($recorded[0], $recorded[1])); + return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); } /** @@ -93,7 +93,7 @@ public function recorded(?callable $callback = null): array public function assertSent($callback): void { if (is_string($callback)) { - $callback = fn($request) => get_class($request) === $callback; + $callback = fn ($request) => get_class($request) === $callback; } PHPUnit::assertTrue( diff --git a/tests/Http/Middleware/HandlersTest.php b/tests/Http/Middleware/HandlersTest.php index 86c8e5490..dd798e001 100644 --- a/tests/Http/Middleware/HandlersTest.php +++ b/tests/Http/Middleware/HandlersTest.php @@ -14,7 +14,7 @@ class HandlersTest extends TestCase public function add(): void { $handlers = new Handlers; - $handlers->add(fn() => null); + $handlers->add(fn () => null); $this->assertCount(1, $handlers->getHandlers()); } diff --git a/tests/Http/MiddlewareTest.php b/tests/Http/MiddlewareTest.php index b29bad56e..67bd5cb8e 100644 --- a/tests/Http/MiddlewareTest.php +++ b/tests/Http/MiddlewareTest.php @@ -2,10 +2,10 @@ namespace Tests\Http; +use Mollie\Api\Http\Middleware; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; -use Mollie\Api\Http\Middleware; use Tests\Fixtures\MockClient; use Tests\TestCase; diff --git a/tests/Utils/ArrTest.php b/tests/Utils/ArrTest.php index 916d57dbd..8b346d0c5 100644 --- a/tests/Utils/ArrTest.php +++ b/tests/Utils/ArrTest.php @@ -3,9 +3,9 @@ namespace Tests\Utils; use DateTimeImmutable; -use Mollie\Api\Utils\Arr; use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Data\Data; +use Mollie\Api\Utils\Arr; use Stringable; use Tests\TestCase; diff --git a/tests/Utils/UtilityTest.php b/tests/Utils/UtilityTest.php index 100cb8c60..dc744199b 100644 --- a/tests/Utils/UtilityTest.php +++ b/tests/Utils/UtilityTest.php @@ -2,8 +2,8 @@ namespace Tests\Utils; -use Mollie\Api\Utils\Utility; use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Utils\Utility; use ReflectionProperty; use Tests\TestCase; @@ -62,7 +62,7 @@ public function filter_by_properties() public function compose() { // Test with callable - $composedWithCallable = Utility::compose(5, fn($x) => $x * 2); + $composedWithCallable = Utility::compose(5, fn ($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); $composedWithClass = Utility::compose('test', TestComposable::class); @@ -70,7 +70,7 @@ public function compose() $this->assertEquals('test', $composedWithClass->value); // Test with falsy value - $composedWithDefault = Utility::compose(false, fn($x) => $x * 2, 'default'); + $composedWithDefault = Utility::compose(false, fn ($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); $existingValueIsNotOverriden = Utility::compose(new Metadata(['key' => 'value']), Metadata::class); From 983595a94e517bd4254af2a6869927788eba312a Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 17 Dec 2024 14:15:44 +0100 Subject: [PATCH 117/131] remove hydration setting and always hydrate --- .github/ISSUE_TEMPLATE.md | 4 +- composer.json | 1 + src/Contracts/Connector.php | 2 +- src/Contracts/HasResponse.php | 2 +- src/Contracts/Hydratable.php | 15 --- src/Contracts/PayloadRepository.php | 4 + src/Contracts/RequestMiddleware.php | 13 ++ src/Contracts/ResponseMiddleware.php | 14 +++ src/Contracts/SupportsResourceHydration.php | 12 -- src/EndpointCollection/EndpointCollection.php | 5 - .../ProfileEndpointCollection.php | 8 +- src/Http/Middleware/ApplyIdempotencyKey.php | 3 +- .../Middleware/EvaluateHydrationSetting.php | 13 -- src/Http/Middleware/GuardResponse.php | 5 +- src/Http/Middleware/Hydrate.php | 23 ---- src/Http/Middleware/ResetIdempotencyKey.php | 3 +- .../ThrowExceptionIfRequestFailed.php | 5 +- src/Http/PendingRequest.php | 17 ++- .../ApplePayPaymentSessionRequest.php | 2 +- src/Http/Requests/CancelPaymentRequest.php | 2 +- src/Http/Requests/CancelSessionRequest.php | 2 +- .../Requests/CancelSubscriptionRequest.php | 2 +- src/Http/Requests/CreateClientLinkRequest.php | 2 +- src/Http/Requests/CreateCustomerRequest.php | 2 +- src/Http/Requests/CreateMandateRequest.php | 2 +- .../Requests/CreatePaymentCaptureRequest.php | 2 +- .../Requests/CreatePaymentLinkRequest.php | 2 +- .../Requests/CreatePaymentRefundRequest.php | 2 +- src/Http/Requests/CreatePaymentRequest.php | 2 +- src/Http/Requests/CreateProfileRequest.php | 2 +- .../Requests/CreateSalesInvoiceRequest.php | 2 +- src/Http/Requests/CreateSessionRequest.php | 2 +- .../Requests/CreateSubscriptionRequest.php | 2 +- src/Http/Requests/DynamicGetRequest.php | 3 +- src/Http/Requests/DynamicRequest.php | 14 +-- .../Requests/EnableMethodIssuerRequest.php | 2 +- .../Requests/EnableProfileMethodRequest.php | 2 +- src/Http/Requests/GetAllMethodsRequest.php | 2 +- .../GetAllPaginatedSubscriptionsRequest.php | 2 +- src/Http/Requests/GetBalanceReportRequest.php | 2 +- src/Http/Requests/GetBalanceRequest.php | 2 +- src/Http/Requests/GetClientRequest.php | 2 +- src/Http/Requests/GetCustomerRequest.php | 2 +- .../Requests/GetEnabledMethodsRequest.php | 2 +- src/Http/Requests/GetInvoiceRequest.php | 2 +- src/Http/Requests/GetMandateRequest.php | 2 +- src/Http/Requests/GetOnboardingRequest.php | 2 +- .../GetOrganizationPartnerStatusRequest.php | 2 +- src/Http/Requests/GetOrganizationRequest.php | 2 +- .../Requests/GetPaginatedBalanceRequest.php | 2 +- .../GetPaginatedBalanceTransactionRequest.php | 2 +- .../GetPaginatedChargebacksRequest.php | 2 +- .../Requests/GetPaginatedClientRequest.php | 2 +- .../GetPaginatedCustomerPaymentsRequest.php | 2 +- .../Requests/GetPaginatedCustomerRequest.php | 2 +- .../Requests/GetPaginatedInvoiceRequest.php | 2 +- .../Requests/GetPaginatedMandateRequest.php | 2 +- .../GetPaginatedPaymentCapturesRequest.php | 2 +- .../GetPaginatedPaymentChargebacksRequest.php | 2 +- ...GetPaginatedPaymentLinkPaymentsRequest.php | 2 +- .../GetPaginatedPaymentLinksRequest.php | 2 +- .../GetPaginatedPaymentRefundsRequest.php | 2 +- .../Requests/GetPaginatedPaymentsRequest.php | 2 +- .../Requests/GetPaginatedProfilesRequest.php | 9 +- .../Requests/GetPaginatedRefundsRequest.php | 2 +- .../GetPaginatedSalesInvoicesRequest.php | 2 +- .../Requests/GetPaginatedSessionsRequest.php | 2 +- .../GetPaginatedSettlementCapturesRequest.php | 2 +- ...tPaginatedSettlementChargebacksRequest.php | 2 +- .../GetPaginatedSettlementPaymentsRequest.php | 2 +- .../GetPaginatedSettlementRefundsRequest.php | 2 +- .../GetPaginatedSettlementsRequest.php | 2 +- ...etPaginatedSubscriptionPaymentsRequest.php | 2 +- .../GetPaginatedSubscriptionsRequest.php | 2 +- .../Requests/GetPaginatedTerminalsRequest.php | 2 +- .../Requests/GetPaymentCaptureRequest.php | 2 +- .../Requests/GetPaymentChargebackRequest.php | 2 +- src/Http/Requests/GetPaymentLinkRequest.php | 2 +- src/Http/Requests/GetPaymentMethodRequest.php | 2 +- src/Http/Requests/GetPaymentRefundRequest.php | 2 +- src/Http/Requests/GetPaymentRequest.php | 2 +- src/Http/Requests/GetPermissionRequest.php | 2 +- src/Http/Requests/GetProfileRequest.php | 2 +- src/Http/Requests/GetSalesInvoiceRequest.php | 2 +- src/Http/Requests/GetSessionRequest.php | 2 +- src/Http/Requests/GetSettlementRequest.php | 2 +- src/Http/Requests/GetSubscriptionRequest.php | 2 +- src/Http/Requests/GetTerminalRequest.php | 2 +- src/Http/Requests/ListPermissionsRequest.php | 2 +- .../Requests/ResourceHydratableRequest.php | 41 ++++--- src/Http/Requests/UpdateCustomerRequest.php | 2 +- .../Requests/UpdatePaymentLinkRequest.php | 2 +- src/Http/Requests/UpdatePaymentRequest.php | 2 +- .../Requests/UpdatePaymentRouteRequest.php | 2 +- src/Http/Requests/UpdateProfileRequest.php | 2 +- .../Requests/UpdateSalesInvoiceRequest.php | 2 +- src/Http/Requests/UpdateSessionRequest.php | 2 +- .../Requests/UpdateSubscriptionRequest.php | 2 +- src/Http/Response.php | 25 ---- src/MollieApiClient.php | 4 +- src/Repositories/JsonPayloadRepository.php | 12 ++ src/Resources/BaseCollection.php | 8 +- src/Resources/BaseResource.php | 14 +-- src/Resources/CursorCollection.php | 10 +- src/Resources/LazyCollection.php | 20 +++- src/Resources/Method.php | 2 + src/Resources/Payment.php | 24 +--- src/Resources/Profile.php | 28 ++--- src/Resources/ResourceFactory.php | 44 ++++--- src/Resources/ResourceHydrator.php | 70 +++++++++++ src/Resources/Subscription.php | 7 +- src/Traits/DelegatesToResource.php | 91 -------------- src/Traits/HandlesAutoHydration.php | 34 ------ src/Traits/HandlesResourceHydration.php | 65 +++------- src/Traits/IsIteratableRequest.php | 5 + src/Traits/SendsRequests.php | 6 +- src/Types/SalesInvoiceStatus.php | 6 +- .../BalanceEndpointCollectionTest.php | 2 +- .../BalanceReportEndpointCollectionTest.php | 5 +- ...lanceTransactionEndpointCollectionTest.php | 10 +- .../ChargebackEndpointCollectionTest.php | 2 +- .../ClientEndpointCollectionTest.php | 2 +- .../ClientLinkEndpointCollectionTest.php | 2 +- .../CustomerEndpointCollectionTest.php | 2 +- ...CustomerPaymentsEndpointCollectionTest.php | 18 ++- .../InvoiceEndpointCollectionTest.php | 2 +- .../MandateEndpointCollectionTest.php | 23 +++- .../MethodEndpointCollectionTest.php | 2 +- .../MethodIssuerEndpointCollectionTest.php | 2 +- .../OnboardingEndpointCollectionTest.php | 2 +- .../OrganizationEndpointCollectionTest.php | 2 +- ...anizationPartnerEndpointCollectionTest.php | 2 +- .../PaymentCaptureEndpointCollectionTest.php | 2 +- ...aymentChargebackEndpointCollectionTest.php | 2 +- .../PaymentEndpointCollectionTest.php | 8 +- .../PaymentLinkEndpointCollectionTest.php | 2 +- ...ymentLinkPaymentEndpointCollectionTest.php | 2 +- .../PaymentRefundEndpointCollectionTest.php | 28 ++++- .../PaymentRouteEndpointCollectionTest.php | 2 +- .../PermissionEndpointCollectionTest.php | 2 +- .../ProfileEndpointCollectionTest.php | 2 +- .../ProfileMethodEndpointCollectionTest.php | 2 +- .../RefundEndpointCollectionTest.php | 2 +- .../SalesInvoiceEndpointCollectionTest.php | 2 +- .../SessionEndpointCollectionTest.php | 2 +- ...ettlementCaptureEndpointCollectionTest.php | 13 +- ...lementChargebackEndpointCollectionTest.php | 13 +- ...ettlementPaymentEndpointCollectionTest.php | 7 +- ...SettlementRefundEndpointCollectionTest.php | 13 +- .../SettlementsEndpointCollectionTest.php | 2 +- .../SubscriptionEndpointCollectionTest.php | 29 +++-- ...scriptionPaymentEndpointCollectionTest.php | 13 +- .../TerminalEndpointCollectionTest.php | 2 +- .../WalletEndpointCollectionTest.php | 2 +- .../Requests/DynamicDeleteRequest.php | 3 +- .../Adapter/GuzzleMollieHttpAdapterTest.php | 2 +- .../Adapter/MollieHttpAdapterPickerTest.php | 2 +- .../Adapter/RetryMiddlewareFactoryTest.php | 2 +- .../Auth/BearetTokenAuthenticatorTest.php | 2 +- tests/Http/Middleware/GuardResponseTest.php | 2 +- tests/Http/Middleware/HandlersTest.php | 2 +- tests/Http/MiddlewareTest.php | 2 +- .../ApplePayPaymentSessionRequestTest.php | 11 +- .../CancelPaymentRefundRequestTest.php | 2 +- .../Requests/CancelPaymentRequestTest.php | 11 +- .../Requests/CancelSessionRequestTest.php | 11 +- .../CancelSubscriptionRequestTest.php | 11 +- .../Requests/CreateClientLinkRequestTest.php | 11 +- .../CreateCustomerPaymentRequestTest.php | 11 +- .../Requests/CreateCustomerRequestTest.php | 11 +- .../Requests/CreateMandateRequestTest.php | 11 +- .../CreatePaymentCaptureRequestTest.php | 11 +- .../Requests/CreatePaymentLinkRequestTest.php | 11 +- .../CreatePaymentRefundRequestTest.php | 11 +- .../Requests/CreatePaymentRequestTest.php | 11 +- .../Requests/CreateProfileRequestTest.php | 11 +- .../CreateSalesInvoiceRequestTest.php | 11 +- .../Requests/CreateSessionRequestTest.php | 11 +- .../CreateSubscriptionRequestTest.php | 11 +- .../Requests/DeleteCustomerRequestTest.php | 2 +- .../Requests/DeletePaymentLinkRequestTest.php | 2 +- .../Requests/DeleteProfileRequestTest.php | 2 +- .../DeleteSalesInvoiceRequestTest.php | 2 +- .../DisableMethodIssuerRequestTest.php | 2 +- .../DisableProfileMethodRequestTest.php | 2 +- tests/Http/Requests/DynamicGetRequestTest.php | 17 +-- tests/Http/Requests/DynamicRequestTest.php | 17 ++- .../EnableMethodIssuerRequestTest.php | 12 +- .../EnableProfileMethodRequestTest.php | 12 +- .../Requests/GetAllMethodsRequestTest.php | 11 +- ...etAllPaginatedSubscriptionsRequestTest.php | 11 +- .../Requests/GetBalanceReportRequestTest.php | 11 +- tests/Http/Requests/GetBalanceRequestTest.php | 11 +- tests/Http/Requests/GetClientRequestTest.php | 13 +- .../Http/Requests/GetCustomerRequestTest.php | 11 +- .../Requests/GetEnabledMethodsRequestTest.php | 11 +- tests/Http/Requests/GetInvoiceRequestTest.php | 11 +- tests/Http/Requests/GetMandateRequestTest.php | 11 +- .../Requests/GetOnboardingRequestTest.php | 11 +- ...etOrganizationPartnerStatusRequestTest.php | 11 +- .../Requests/GetOrganizationRequestTest.php | 11 +- .../GetPaginatedBalanceRequestTest.php | 11 +- ...PaginatedBalanceTransactionRequestTest.php | 11 +- .../GetPaginatedChargebacksRequestTest.php | 11 +- .../GetPaginatedClientRequestTest.php | 11 +- ...etPaginatedCustomerPaymentsRequestTest.php | 11 +- .../GetPaginatedCustomerRequestTest.php | 11 +- .../GetPaginatedInvoiceRequestTest.php | 11 +- .../GetPaginatedMandateRequestTest.php | 23 ++-- ...GetPaginatedPaymentCapturesRequestTest.php | 23 ++-- ...PaginatedPaymentChargebacksRequestTest.php | 23 ++-- ...aginatedPaymentLinkPaymentsRequestTest.php | 22 ++-- .../GetPaginatedPaymentLinksRequestTest.php | 24 ++-- .../GetPaginatedPaymentRefundsRequestTest.php | 24 +--- .../GetPaginatedPaymentsRequestTest.php | 17 +-- .../GetPaginatedProfilesRequestTest.php | 25 ++-- .../GetPaginatedRefundsRequestTest.php | 25 ++-- .../GetPaginatedSalesInvoicesRequestTest.php | 17 +-- .../GetPaginatedSessionsRequestTest.php | 22 +--- ...PaginatedSettlementCapturesRequestTest.php | 22 +--- ...inatedSettlementChargebacksRequestTest.php | 23 +--- ...PaginatedSettlementPaymentsRequestTest.php | 19 +-- ...tPaginatedSettlementRefundsRequestTest.php | 19 +-- .../GetPaginatedSettlementsRequestTest.php | 20 +--- ...ginatedSubscriptionPaymentsRequestTest.php | 20 +--- .../GetPaginatedSubscriptionsRequestTest.php | 20 +--- .../GetPaginatedTerminalsRequestTest.php | 22 +--- .../Requests/GetPaymentCaptureRequestTest.php | 13 +- .../GetPaymentChargebackRequestTest.php | 13 +- .../Requests/GetPaymentLinkRequestTest.php | 13 +- .../Requests/GetPaymentMethodRequestTest.php | 12 +- .../Requests/GetPaymentRefundRequestTest.php | 12 +- tests/Http/Requests/GetPaymentRequestTest.php | 12 +- .../Requests/GetPermissionRequestTest.php | 12 +- tests/Http/Requests/GetProfileRequestTest.php | 12 +- .../Requests/GetSalesInvoiceRequestTest.php | 10 +- tests/Http/Requests/GetSessionRequestTest.php | 12 +- .../Requests/GetSettlementRequestTest.php | 12 +- .../Requests/GetSubscriptionRequestTest.php | 12 +- .../Http/Requests/GetTerminalRequestTest.php | 12 +- .../Requests/ListPermissionsRequestTest.php | 11 +- tests/Http/Requests/PaginatedRequestTest.php | 4 +- .../ResourceHydratableRequestTest.php | 22 +--- .../Requests/RevokeMandateRequestTest.php | 2 +- .../Requests/UpdateCustomerRequestTest.php | 12 +- .../Requests/UpdatePaymentLinkRequestTest.php | 12 +- .../Requests/UpdatePaymentRequestTest.php | 12 +- .../UpdatePaymentRouteRequestTest.php | 12 +- .../Requests/UpdateProfileRequestTest.php | 12 +- .../UpdateSalesInvoiceRequestTest.php | 11 +- .../Requests/UpdateSessionRequestTest.php | 12 +- .../UpdateSubscriptionRequestTest.php | 11 +- tests/MollieApiClientTest.php | 1 + tests/Resources/CursorCollectionTest.php | 9 +- tests/Resources/InvoiceTest.php | 8 +- tests/Resources/LazyCollectionTest.php | 5 +- tests/Resources/MandateCollectionTest.php | 12 +- tests/Resources/MethodTest.php | 8 +- tests/Resources/OnboardingTest.php | 10 +- tests/Resources/PaymentTest.php | 111 ++++++++++++++---- tests/Resources/ProfileTest.php | 6 +- tests/Resources/RefundTest.php | 11 +- tests/Resources/ResourceFactoryTest.php | 16 ++- tests/Resources/SettlementTest.php | 6 +- tests/Resources/SubscriptionTest.php | 6 +- tests/TestCase.php | 16 --- tests/Types/MandateMethodTest.php | 2 +- tests/Utils/ArrTest.php | 2 +- tests/Utils/UrlTest.php | 2 +- tests/Utils/UtilityTest.php | 2 +- 270 files changed, 1105 insertions(+), 1377 deletions(-) delete mode 100644 src/Contracts/Hydratable.php create mode 100644 src/Contracts/RequestMiddleware.php create mode 100644 src/Contracts/ResponseMiddleware.php delete mode 100644 src/Contracts/SupportsResourceHydration.php delete mode 100644 src/Http/Middleware/EvaluateHydrationSetting.php delete mode 100644 src/Http/Middleware/Hydrate.php create mode 100644 src/Resources/ResourceHydrator.php delete mode 100644 src/Traits/DelegatesToResource.php delete mode 100644 src/Traits/HandlesAutoHydration.php delete mode 100644 tests/TestCase.php diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 99c16e624..35810719a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,8 +1,8 @@ ## Specifications - - API Version: + - API Version: + - SDK Version: ## Describe the issue ... - diff --git a/composer.json b/composer.json index fb2fce4e7..bb38e898d 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", + "laravel/pint": "^1.18", "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.6" }, diff --git a/src/Contracts/Connector.php b/src/Contracts/Connector.php index 9210504a3..40e06b235 100644 --- a/src/Contracts/Connector.php +++ b/src/Contracts/Connector.php @@ -5,7 +5,7 @@ use Mollie\Api\Http\Middleware; use Mollie\Api\Http\Request; -interface Connector extends Authenticatable, Hydratable, IdempotencyContract, SupportsDebuggingContract, Testable +interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract, Testable { public function send(Request $request): ?object; diff --git a/src/Contracts/HasResponse.php b/src/Contracts/HasResponse.php index a802c2ad1..e44209b8d 100644 --- a/src/Contracts/HasResponse.php +++ b/src/Contracts/HasResponse.php @@ -6,5 +6,5 @@ interface HasResponse extends ViableResponse { - public function getResponse(): ?Response; + public function getResponse(): Response; } diff --git a/src/Contracts/Hydratable.php b/src/Contracts/Hydratable.php deleted file mode 100644 index 53563a5e3..000000000 --- a/src/Contracts/Hydratable.php +++ /dev/null @@ -1,15 +0,0 @@ -connector = $connector; - - /** - * Default hydration decision to true to maintain legacy compatibility. - */ - $connector::setAutoHydrate(); } /** diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index a70456762..6687fdb5a 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -66,10 +66,14 @@ public function get(string $profileId, $testmode = []): Profile */ public function getCurrent($testmode = []): CurrentProfile { - GetProfileRequest::$targetResourceClass = CurrentProfile::class; + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var CurrentProfile */ - return $this->get('me', $testmode); + return $this->send( + (new GetProfileRequest('me')) + ->setHydratableResource(CurrentProfile::class) + ->test($testmode) + ); } /** diff --git a/src/Http/Middleware/ApplyIdempotencyKey.php b/src/Http/Middleware/ApplyIdempotencyKey.php index a11db03d9..9f7e67d96 100644 --- a/src/Http/Middleware/ApplyIdempotencyKey.php +++ b/src/Http/Middleware/ApplyIdempotencyKey.php @@ -2,10 +2,11 @@ namespace Mollie\Api\Http\Middleware; +use Mollie\Api\Contracts\RequestMiddleware; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Types\Method; -class ApplyIdempotencyKey +class ApplyIdempotencyKey implements RequestMiddleware { const IDEMPOTENCY_KEY_HEADER = 'Idempotency-Key'; diff --git a/src/Http/Middleware/EvaluateHydrationSetting.php b/src/Http/Middleware/EvaluateHydrationSetting.php deleted file mode 100644 index e728045fc..000000000 --- a/src/Http/Middleware/EvaluateHydrationSetting.php +++ /dev/null @@ -1,13 +0,0 @@ -getConnector()->evaluateHydrationSetting(); - } -} diff --git a/src/Http/Middleware/GuardResponse.php b/src/Http/Middleware/GuardResponse.php index 68e76f0bd..b4426a33d 100644 --- a/src/Http/Middleware/GuardResponse.php +++ b/src/Http/Middleware/GuardResponse.php @@ -2,13 +2,14 @@ namespace Mollie\Api\Http\Middleware; +use Mollie\Api\Contracts\ResponseMiddleware; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Response; use Mollie\Api\Http\ResponseStatusCode; -class GuardResponse +class GuardResponse implements ResponseMiddleware { - public function __invoke(Response $response) + public function __invoke(Response $response): void { if (($isEmpty = $response->isEmpty()) && $response->status() !== ResponseStatusCode::HTTP_NO_CONTENT) { throw new ApiException('No response body found.'); diff --git a/src/Http/Middleware/Hydrate.php b/src/Http/Middleware/Hydrate.php deleted file mode 100644 index 0a0a51d92..000000000 --- a/src/Http/Middleware/Hydrate.php +++ /dev/null @@ -1,23 +0,0 @@ -getRequest(); - - if (! $request instanceof ResourceHydratableRequest || ! $request->shouldAutoHydrate()) { - return $response; - } - - return $this->hydrate($request, $response); - } -} diff --git a/src/Http/Middleware/ResetIdempotencyKey.php b/src/Http/Middleware/ResetIdempotencyKey.php index b72cb56ff..e1e1b2693 100644 --- a/src/Http/Middleware/ResetIdempotencyKey.php +++ b/src/Http/Middleware/ResetIdempotencyKey.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Http\Middleware; +use Mollie\Api\Contracts\ResponseMiddleware; use Mollie\Api\Http\Response; -class ResetIdempotencyKey +class ResetIdempotencyKey implements ResponseMiddleware { public function __invoke(Response $response): void { diff --git a/src/Http/Middleware/ThrowExceptionIfRequestFailed.php b/src/Http/Middleware/ThrowExceptionIfRequestFailed.php index 3bb837de5..b4e60ac3a 100644 --- a/src/Http/Middleware/ThrowExceptionIfRequestFailed.php +++ b/src/Http/Middleware/ThrowExceptionIfRequestFailed.php @@ -2,12 +2,13 @@ namespace Mollie\Api\Http\Middleware; +use Mollie\Api\Contracts\ResponseMiddleware; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Http\Response; -class ThrowExceptionIfRequestFailed +class ThrowExceptionIfRequestFailed implements ResponseMiddleware { - public function __invoke(Response $response) + public function __invoke(Response $response): void { if ($response->successful()) { return; diff --git a/src/Http/PendingRequest.php b/src/Http/PendingRequest.php index de7325514..027121a88 100644 --- a/src/Http/PendingRequest.php +++ b/src/Http/PendingRequest.php @@ -8,9 +8,7 @@ use Mollie\Api\Contracts\SupportsTestmodeInPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Http\Middleware\ApplyIdempotencyKey; -use Mollie\Api\Http\Middleware\EvaluateHydrationSetting; use Mollie\Api\Http\Middleware\GuardResponse; -use Mollie\Api\Http\Middleware\Hydrate; use Mollie\Api\Http\Middleware\MiddlewarePriority; use Mollie\Api\Http\Middleware\ResetIdempotencyKey; use Mollie\Api\Http\Middleware\ThrowExceptionIfRequestFailed; @@ -68,14 +66,12 @@ public function __construct(Connector $connector, Request $request) ->middleware() /** On request */ - ->onRequest(new EvaluateHydrationSetting, 'hydration') ->onRequest(new ApplyIdempotencyKey, 'idempotency') /** On response */ ->onResponse(new ResetIdempotencyKey, 'idempotency') ->onResponse(new GuardResponse, MiddlewarePriority::HIGH) - ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH) - ->onResponse(new Hydrate, 'hydration', MiddlewarePriority::LOW); + ->onResponse(new ThrowExceptionIfRequestFailed, MiddlewarePriority::HIGH); } public function setTestmode(bool $testmode): self @@ -89,6 +85,17 @@ public function setTestmode(bool $testmode): self return $this; } + public function getTestmode(): bool + { + if (! $this->request instanceof SupportsTestmodeInQuery && ! $this->request instanceof SupportsTestmodeInPayload) { + return false; + } + + return $this->request instanceof SupportsTestmodeInQuery + ? $this->query()->get('testmode', false) + : $this->payload()->get('testmode', false); + } + public function setPayload(PayloadRepository $bodyRepository): self { $this->payload = $bodyRepository; diff --git a/src/Http/Requests/ApplePayPaymentSessionRequest.php b/src/Http/Requests/ApplePayPaymentSessionRequest.php index 51a95b47f..a42e49af6 100644 --- a/src/Http/Requests/ApplePayPaymentSessionRequest.php +++ b/src/Http/Requests/ApplePayPaymentSessionRequest.php @@ -14,7 +14,7 @@ class ApplePayPaymentSessionRequest extends ResourceHydratableRequest implements protected static string $method = Method::POST; - public static string $targetResourceClass = AnyResource::class; + protected $hydratableResource = AnyResource::class; private RequestApplePayPaymentSessionPayload $payload; diff --git a/src/Http/Requests/CancelPaymentRequest.php b/src/Http/Requests/CancelPaymentRequest.php index 6ee73d4d7..df2e8ea9b 100644 --- a/src/Http/Requests/CancelPaymentRequest.php +++ b/src/Http/Requests/CancelPaymentRequest.php @@ -10,7 +10,7 @@ class CancelPaymentRequest extends ResourceHydratableRequest implements Supports { protected static string $method = Method::DELETE; - public static string $targetResourceClass = Payment::class; + protected $hydratableResource = Payment::class; protected string $id; diff --git a/src/Http/Requests/CancelSessionRequest.php b/src/Http/Requests/CancelSessionRequest.php index f28c62a17..1618d0978 100644 --- a/src/Http/Requests/CancelSessionRequest.php +++ b/src/Http/Requests/CancelSessionRequest.php @@ -9,7 +9,7 @@ class CancelSessionRequest extends ResourceHydratableRequest { protected static string $method = Method::DELETE; - public static string $targetResourceClass = Session::class; + protected $hydratableResource = Session::class; private string $sessionId; diff --git a/src/Http/Requests/CancelSubscriptionRequest.php b/src/Http/Requests/CancelSubscriptionRequest.php index 0d76f7ad6..e2c59a05b 100644 --- a/src/Http/Requests/CancelSubscriptionRequest.php +++ b/src/Http/Requests/CancelSubscriptionRequest.php @@ -16,7 +16,7 @@ class CancelSubscriptionRequest extends ResourceHydratableRequest implements Sup /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Subscription::class; + protected $hydratableResource = Subscription::class; private string $customerId; diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index ce0f6a86a..70c77be03 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -20,7 +20,7 @@ class CreateClientLinkRequest extends ResourceHydratableRequest implements HasPa /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ClientLink::class; + protected $hydratableResource = ClientLink::class; private CreateClientLinkPayload $payload; diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php index 1e8c8f202..8ad7cbc41 100644 --- a/src/Http/Requests/CreateCustomerRequest.php +++ b/src/Http/Requests/CreateCustomerRequest.php @@ -15,7 +15,7 @@ class CreateCustomerRequest extends ResourceHydratableRequest implements HasPayl protected static string $method = Method::POST; - public static string $targetResourceClass = Customer::class; + protected $hydratableResource = Customer::class; private CreateCustomerPayload $payload; diff --git a/src/Http/Requests/CreateMandateRequest.php b/src/Http/Requests/CreateMandateRequest.php index 1495c194b..6167de575 100644 --- a/src/Http/Requests/CreateMandateRequest.php +++ b/src/Http/Requests/CreateMandateRequest.php @@ -21,7 +21,7 @@ class CreateMandateRequest extends ResourceHydratableRequest implements HasPaylo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Mandate::class; + protected $hydratableResource = Mandate::class; private string $customerId; diff --git a/src/Http/Requests/CreatePaymentCaptureRequest.php b/src/Http/Requests/CreatePaymentCaptureRequest.php index 1990cd260..383899594 100644 --- a/src/Http/Requests/CreatePaymentCaptureRequest.php +++ b/src/Http/Requests/CreatePaymentCaptureRequest.php @@ -21,7 +21,7 @@ class CreatePaymentCaptureRequest extends ResourceHydratableRequest implements H /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Capture::class; + protected $hydratableResource = Capture::class; private string $paymentId; diff --git a/src/Http/Requests/CreatePaymentLinkRequest.php b/src/Http/Requests/CreatePaymentLinkRequest.php index b29a02fe0..cea9aa42f 100644 --- a/src/Http/Requests/CreatePaymentLinkRequest.php +++ b/src/Http/Requests/CreatePaymentLinkRequest.php @@ -20,7 +20,7 @@ class CreatePaymentLinkRequest extends ResourceHydratableRequest implements HasP /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentLink::class; + protected $hydratableResource = PaymentLink::class; private CreatePaymentLinkPayload $payload; diff --git a/src/Http/Requests/CreatePaymentRefundRequest.php b/src/Http/Requests/CreatePaymentRefundRequest.php index b383ef200..9e36bafce 100644 --- a/src/Http/Requests/CreatePaymentRefundRequest.php +++ b/src/Http/Requests/CreatePaymentRefundRequest.php @@ -20,7 +20,7 @@ class CreatePaymentRefundRequest extends ResourceHydratableRequest implements Ha /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = \Mollie\Api\Resources\Refund::class; + protected $hydratableResource = \Mollie\Api\Resources\Refund::class; private string $paymentId; diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index b01e17aca..186fd774a 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -22,7 +22,7 @@ class CreatePaymentRequest extends ResourceHydratableRequest implements HasPaylo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Payment::class; + protected $hydratableResource = Payment::class; private CreatePaymentPayload $payload; diff --git a/src/Http/Requests/CreateProfileRequest.php b/src/Http/Requests/CreateProfileRequest.php index 84581b8a3..2984c25c9 100644 --- a/src/Http/Requests/CreateProfileRequest.php +++ b/src/Http/Requests/CreateProfileRequest.php @@ -20,7 +20,7 @@ class CreateProfileRequest extends ResourceHydratableRequest implements HasPaylo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Profile::class; + protected $hydratableResource = Profile::class; private CreateProfilePayload $payload; diff --git a/src/Http/Requests/CreateSalesInvoiceRequest.php b/src/Http/Requests/CreateSalesInvoiceRequest.php index a25ff173c..31f696064 100644 --- a/src/Http/Requests/CreateSalesInvoiceRequest.php +++ b/src/Http/Requests/CreateSalesInvoiceRequest.php @@ -14,7 +14,7 @@ class CreateSalesInvoiceRequest extends ResourceHydratableRequest implements Has protected static string $method = Method::POST; - public static string $targetResourceClass = SalesInvoice::class; + protected $hydratableResource = SalesInvoice::class; private CreateSalesInvoicePayload $payload; diff --git a/src/Http/Requests/CreateSessionRequest.php b/src/Http/Requests/CreateSessionRequest.php index b73f1a43a..94be5ebba 100644 --- a/src/Http/Requests/CreateSessionRequest.php +++ b/src/Http/Requests/CreateSessionRequest.php @@ -14,7 +14,7 @@ class CreateSessionRequest extends ResourceHydratableRequest implements HasPaylo protected static string $method = Method::POST; - public static string $targetResourceClass = Session::class; + protected $hydratableResource = Session::class; private AnyData $payload; diff --git a/src/Http/Requests/CreateSubscriptionRequest.php b/src/Http/Requests/CreateSubscriptionRequest.php index ecc375676..9030a9a9e 100644 --- a/src/Http/Requests/CreateSubscriptionRequest.php +++ b/src/Http/Requests/CreateSubscriptionRequest.php @@ -21,7 +21,7 @@ class CreateSubscriptionRequest extends ResourceHydratableRequest implements Has /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Subscription::class; + protected $hydratableResource = Subscription::class; private string $customerId; diff --git a/src/Http/Requests/DynamicGetRequest.php b/src/Http/Requests/DynamicGetRequest.php index 5a77d4ead..b3b959723 100644 --- a/src/Http/Requests/DynamicGetRequest.php +++ b/src/Http/Requests/DynamicGetRequest.php @@ -15,10 +15,9 @@ class DynamicGetRequest extends DynamicRequest public function __construct( string $url, - string $resourceClass = '', array $query = [] ) { - parent::__construct($url, $resourceClass); + parent::__construct($url); $this->query = $query; } diff --git a/src/Http/Requests/DynamicRequest.php b/src/Http/Requests/DynamicRequest.php index 214083dce..1d5b7a27f 100644 --- a/src/Http/Requests/DynamicRequest.php +++ b/src/Http/Requests/DynamicRequest.php @@ -6,21 +6,9 @@ abstract class DynamicRequest extends ResourceHydratableRequest { private string $url; - private string $resourceClass; - - public function __construct(string $url, string $resourceClass = '') + public function __construct(string $url) { - if (! empty($resourceClass) && ! class_exists($resourceClass)) { - throw new \InvalidArgumentException("The resource class '{$resourceClass}' does not exist."); - } - $this->url = $url; - $this->resourceClass = $resourceClass; - } - - public function getTargetResourceClass(): string - { - return $this->resourceClass; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/EnableMethodIssuerRequest.php b/src/Http/Requests/EnableMethodIssuerRequest.php index 9a58eedb1..aeec0d4d7 100644 --- a/src/Http/Requests/EnableMethodIssuerRequest.php +++ b/src/Http/Requests/EnableMethodIssuerRequest.php @@ -19,7 +19,7 @@ class EnableMethodIssuerRequest extends ResourceHydratableRequest implements Has /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Issuer::class; + protected $hydratableResource = Issuer::class; private string $profileId; diff --git a/src/Http/Requests/EnableProfileMethodRequest.php b/src/Http/Requests/EnableProfileMethodRequest.php index 4356e82e9..f0309cfc6 100644 --- a/src/Http/Requests/EnableProfileMethodRequest.php +++ b/src/Http/Requests/EnableProfileMethodRequest.php @@ -15,7 +15,7 @@ class EnableProfileMethodRequest extends ResourceHydratableRequest /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Method::class; + protected $hydratableResource = Method::class; private string $profileId; diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index 929359c39..5ddab9469 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -16,7 +16,7 @@ class GetAllMethodsRequest extends ResourceHydratableRequest /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = MethodCollection::class; + protected $hydratableResource = MethodCollection::class; private GetAllMethodsQuery $query; diff --git a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php index 0457a1b78..ca69d815f 100644 --- a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php @@ -14,7 +14,7 @@ class GetAllPaginatedSubscriptionsRequest extends PaginatedRequest implements Is /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = SubscriptionCollection::class; + protected $hydratableResource = SubscriptionCollection::class; /** * The resource path. diff --git a/src/Http/Requests/GetBalanceReportRequest.php b/src/Http/Requests/GetBalanceReportRequest.php index b6b7c2633..8d8338747 100644 --- a/src/Http/Requests/GetBalanceReportRequest.php +++ b/src/Http/Requests/GetBalanceReportRequest.php @@ -17,7 +17,7 @@ class GetBalanceReportRequest extends ResourceHydratableRequest implements Suppo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = BalanceReport::class; + protected $hydratableResource = BalanceReport::class; private string $balanceId; diff --git a/src/Http/Requests/GetBalanceRequest.php b/src/Http/Requests/GetBalanceRequest.php index 332c25fc0..9373c8e41 100644 --- a/src/Http/Requests/GetBalanceRequest.php +++ b/src/Http/Requests/GetBalanceRequest.php @@ -10,7 +10,7 @@ class GetBalanceRequest extends ResourceHydratableRequest implements SupportsTes { protected static string $method = Method::GET; - public static string $targetResourceClass = Balance::class; + protected $hydratableResource = Balance::class; private string $id; diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 510f2bf2e..5f707ce43 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -16,7 +16,7 @@ class GetClientRequest extends ResourceHydratableRequest /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Client::class; + protected $hydratableResource = Client::class; private string $id; diff --git a/src/Http/Requests/GetCustomerRequest.php b/src/Http/Requests/GetCustomerRequest.php index df134090c..c16eac87f 100644 --- a/src/Http/Requests/GetCustomerRequest.php +++ b/src/Http/Requests/GetCustomerRequest.php @@ -10,7 +10,7 @@ class GetCustomerRequest extends ResourceHydratableRequest implements SupportsTe { protected static string $method = Method::GET; - public static string $targetResourceClass = Customer::class; + protected $hydratableResource = Customer::class; private string $id; diff --git a/src/Http/Requests/GetEnabledMethodsRequest.php b/src/Http/Requests/GetEnabledMethodsRequest.php index 80d727925..60551bcef 100644 --- a/src/Http/Requests/GetEnabledMethodsRequest.php +++ b/src/Http/Requests/GetEnabledMethodsRequest.php @@ -11,7 +11,7 @@ class GetEnabledMethodsRequest extends ResourceHydratableRequest implements Supp { protected static string $method = HttpMethod::GET; - public static string $targetResourceClass = MethodCollection::class; + protected $hydratableResource = MethodCollection::class; private ?GetEnabledPaymentMethodsQuery $query = null; diff --git a/src/Http/Requests/GetInvoiceRequest.php b/src/Http/Requests/GetInvoiceRequest.php index cf3a582ab..83c870202 100644 --- a/src/Http/Requests/GetInvoiceRequest.php +++ b/src/Http/Requests/GetInvoiceRequest.php @@ -9,7 +9,7 @@ class GetInvoiceRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; - public static string $targetResourceClass = Invoice::class; + protected $hydratableResource = Invoice::class; private string $id; diff --git a/src/Http/Requests/GetMandateRequest.php b/src/Http/Requests/GetMandateRequest.php index 49174bb90..04d0ff03b 100644 --- a/src/Http/Requests/GetMandateRequest.php +++ b/src/Http/Requests/GetMandateRequest.php @@ -16,7 +16,7 @@ class GetMandateRequest extends ResourceHydratableRequest implements SupportsTes /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Mandate::class; + protected $hydratableResource = Mandate::class; private string $customerId; diff --git a/src/Http/Requests/GetOnboardingRequest.php b/src/Http/Requests/GetOnboardingRequest.php index 2247c4545..12d1a0070 100644 --- a/src/Http/Requests/GetOnboardingRequest.php +++ b/src/Http/Requests/GetOnboardingRequest.php @@ -9,7 +9,7 @@ class GetOnboardingRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; - public static string $targetResourceClass = Onboarding::class; + protected $hydratableResource = Onboarding::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetOrganizationPartnerStatusRequest.php b/src/Http/Requests/GetOrganizationPartnerStatusRequest.php index e267ec1b3..9cdc6c44e 100644 --- a/src/Http/Requests/GetOrganizationPartnerStatusRequest.php +++ b/src/Http/Requests/GetOrganizationPartnerStatusRequest.php @@ -9,7 +9,7 @@ class GetOrganizationPartnerStatusRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; - public static string $targetResourceClass = Partner::class; + protected $hydratableResource = Partner::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetOrganizationRequest.php b/src/Http/Requests/GetOrganizationRequest.php index 4d9e4a47b..e17165ba4 100644 --- a/src/Http/Requests/GetOrganizationRequest.php +++ b/src/Http/Requests/GetOrganizationRequest.php @@ -10,7 +10,7 @@ class GetOrganizationRequest extends ResourceHydratableRequest implements Suppor { protected static string $method = Method::GET; - public static string $targetResourceClass = Organization::class; + protected $hydratableResource = Organization::class; private string $id; diff --git a/src/Http/Requests/GetPaginatedBalanceRequest.php b/src/Http/Requests/GetPaginatedBalanceRequest.php index 1c55a2fdf..4b7b6394b 100644 --- a/src/Http/Requests/GetPaginatedBalanceRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceRequest.php @@ -14,7 +14,7 @@ class GetPaginatedBalanceRequest extends PaginatedRequest implements IsIteratabl /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = BalanceCollection::class; + protected $hydratableResource = BalanceCollection::class; /** * Resolve the resource path. diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php index b881c1fef..b61140f5c 100644 --- a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -14,7 +14,7 @@ class GetPaginatedBalanceTransactionRequest extends PaginatedRequest implements /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = BalanceTransactionCollection::class; + protected $hydratableResource = BalanceTransactionCollection::class; private string $balanceId; diff --git a/src/Http/Requests/GetPaginatedChargebacksRequest.php b/src/Http/Requests/GetPaginatedChargebacksRequest.php index 67435de3f..488a3bdad 100644 --- a/src/Http/Requests/GetPaginatedChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedChargebacksRequest.php @@ -14,7 +14,7 @@ class GetPaginatedChargebacksRequest extends PaginatedRequest implements IsItera /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ChargebackCollection::class; + protected $hydratableResource = ChargebackCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedClientRequest.php b/src/Http/Requests/GetPaginatedClientRequest.php index edfe6522a..0ade79a34 100644 --- a/src/Http/Requests/GetPaginatedClientRequest.php +++ b/src/Http/Requests/GetPaginatedClientRequest.php @@ -13,7 +13,7 @@ class GetPaginatedClientRequest extends PaginatedRequest implements IsIteratable /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ClientCollection::class; + protected $hydratableResource = ClientCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php index 1a2f97735..aa50501be 100644 --- a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedCustomerPaymentsRequest extends PaginatedRequest implements Is /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentCollection::class; + protected $hydratableResource = PaymentCollection::class; private string $customerId; diff --git a/src/Http/Requests/GetPaginatedCustomerRequest.php b/src/Http/Requests/GetPaginatedCustomerRequest.php index 0b1f32bf1..fbd7e1b2a 100644 --- a/src/Http/Requests/GetPaginatedCustomerRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerRequest.php @@ -11,7 +11,7 @@ class GetPaginatedCustomerRequest extends PaginatedRequest implements IsIteratab { use IsIteratableRequest; - public static string $targetResourceClass = CustomerCollection::class; + protected $hydratableResource = CustomerCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedInvoiceRequest.php b/src/Http/Requests/GetPaginatedInvoiceRequest.php index bedddc8c4..f66895993 100644 --- a/src/Http/Requests/GetPaginatedInvoiceRequest.php +++ b/src/Http/Requests/GetPaginatedInvoiceRequest.php @@ -13,7 +13,7 @@ class GetPaginatedInvoiceRequest extends PaginatedRequest implements IsIteratabl /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = InvoiceCollection::class; + protected $hydratableResource = InvoiceCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedMandateRequest.php b/src/Http/Requests/GetPaginatedMandateRequest.php index 970bf17c2..f2f3f90a6 100644 --- a/src/Http/Requests/GetPaginatedMandateRequest.php +++ b/src/Http/Requests/GetPaginatedMandateRequest.php @@ -15,7 +15,7 @@ class GetPaginatedMandateRequest extends PaginatedRequest implements IsIteratabl /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = MandateCollection::class; + protected $hydratableResource = MandateCollection::class; private string $customerId; diff --git a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php index 94aecd420..6cbbd8188 100644 --- a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php @@ -21,7 +21,7 @@ class GetPaginatedPaymentCapturesRequest extends PaginatedRequest implements IsI /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = CaptureCollection::class; + protected $hydratableResource = CaptureCollection::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php index b8701e19a..ed51d048b 100644 --- a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php @@ -21,7 +21,7 @@ class GetPaginatedPaymentChargebacksRequest extends PaginatedRequest implements /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ChargebackCollection::class; + protected $hydratableResource = ChargebackCollection::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php index 0672976e0..d23914a28 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedPaymentLinkPaymentsRequest extends PaginatedRequest implements /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentCollection::class; + protected $hydratableResource = PaymentCollection::class; private string $paymentLinkId; diff --git a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php index 3f1120932..5c05b2180 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php @@ -20,7 +20,7 @@ class GetPaginatedPaymentLinksRequest extends PaginatedRequest implements IsIter /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentLinkCollection::class; + protected $hydratableResource = PaymentLinkCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php index 2f9a89245..82040b67f 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedPaymentRefundsRequest extends PaginatedRequest implements IsIt /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = RefundCollection::class; + protected $hydratableResource = RefundCollection::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php index 67c916877..18c7f0f6c 100644 --- a/src/Http/Requests/GetPaginatedPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -14,7 +14,7 @@ class GetPaginatedPaymentsRequest extends PaginatedRequest implements IsIteratab /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentCollection::class; + protected $hydratableResource = PaymentCollection::class; /** * Resolve the resource path. diff --git a/src/Http/Requests/GetPaginatedProfilesRequest.php b/src/Http/Requests/GetPaginatedProfilesRequest.php index c8340d431..1a9113b9f 100644 --- a/src/Http/Requests/GetPaginatedProfilesRequest.php +++ b/src/Http/Requests/GetPaginatedProfilesRequest.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\ProfileCollection; use Mollie\Api\Traits\IsIteratableRequest; use Mollie\Api\Types\Method; @@ -19,7 +20,13 @@ class GetPaginatedProfilesRequest extends PaginatedRequest implements IsIteratab /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ProfileCollection::class; + protected $hydratableResource = ProfileCollection::class; + + public function __construct( + ?PaginatedQuery $query = null + ) { + parent::__construct($query); + } /** * Resolve the resource path. diff --git a/src/Http/Requests/GetPaginatedRefundsRequest.php b/src/Http/Requests/GetPaginatedRefundsRequest.php index 00c3dea6d..69723cdfe 100644 --- a/src/Http/Requests/GetPaginatedRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedRefundsRequest.php @@ -20,7 +20,7 @@ class GetPaginatedRefundsRequest extends PaginatedRequest implements IsIteratabl /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = RefundCollection::class; + protected $hydratableResource = RefundCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php b/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php index d88095a95..7f3d26aab 100644 --- a/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php +++ b/src/Http/Requests/GetPaginatedSalesInvoicesRequest.php @@ -11,7 +11,7 @@ class GetPaginatedSalesInvoicesRequest extends PaginatedRequest implements IsIte { use IsIteratableRequest; - public static string $targetResourceClass = SalesInvoiceCollection::class; + protected $hydratableResource = SalesInvoiceCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedSessionsRequest.php b/src/Http/Requests/GetPaginatedSessionsRequest.php index aa4f36fb4..2c010cf05 100644 --- a/src/Http/Requests/GetPaginatedSessionsRequest.php +++ b/src/Http/Requests/GetPaginatedSessionsRequest.php @@ -10,7 +10,7 @@ class GetPaginatedSessionsRequest extends PaginatedRequest implements IsIteratab { use IsIteratableRequest; - public static string $targetResourceClass = SessionCollection::class; + protected $hydratableResource = SessionCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php index 9cc59d0d2..b1ecd2326 100644 --- a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSettlementCapturesRequest extends PaginatedRequest implements /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = CaptureCollection::class; + protected $hydratableResource = CaptureCollection::class; private string $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php index 25e2dd09e..b846929ad 100644 --- a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSettlementChargebacksRequest extends PaginatedRequest implemen /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = ChargebackCollection::class; + protected $hydratableResource = ChargebackCollection::class; private string $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php index 80fe8d3de..20770a80e 100644 --- a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSettlementPaymentsRequest extends PaginatedRequest implements /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentCollection::class; + protected $hydratableResource = PaymentCollection::class; private string $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php index 7a5ffbd4f..4d33a662b 100644 --- a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSettlementRefundsRequest extends PaginatedRequest implements I /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = RefundCollection::class; + protected $hydratableResource = RefundCollection::class; private string $settlementId; diff --git a/src/Http/Requests/GetPaginatedSettlementsRequest.php b/src/Http/Requests/GetPaginatedSettlementsRequest.php index 687155bad..427d59c1c 100644 --- a/src/Http/Requests/GetPaginatedSettlementsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementsRequest.php @@ -13,7 +13,7 @@ class GetPaginatedSettlementsRequest extends PaginatedRequest implements IsItera /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = SettlementCollection::class; + protected $hydratableResource = SettlementCollection::class; /** * Resolve the resource path. diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index 93146000a..073e1e8c9 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentCollection::class; + protected $hydratableResource = PaymentCollection::class; private string $customerId; diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index f3acce33c..aa7bfedcf 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -15,7 +15,7 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = SubscriptionCollection::class; + protected $hydratableResource = SubscriptionCollection::class; private string $customerId; diff --git a/src/Http/Requests/GetPaginatedTerminalsRequest.php b/src/Http/Requests/GetPaginatedTerminalsRequest.php index 321d592ad..d85d0f965 100644 --- a/src/Http/Requests/GetPaginatedTerminalsRequest.php +++ b/src/Http/Requests/GetPaginatedTerminalsRequest.php @@ -14,7 +14,7 @@ class GetPaginatedTerminalsRequest extends PaginatedRequest implements IsIterata /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = TerminalCollection::class; + protected $hydratableResource = TerminalCollection::class; /** * The resource path. diff --git a/src/Http/Requests/GetPaymentCaptureRequest.php b/src/Http/Requests/GetPaymentCaptureRequest.php index fbfce2b46..e29ac88d8 100644 --- a/src/Http/Requests/GetPaymentCaptureRequest.php +++ b/src/Http/Requests/GetPaymentCaptureRequest.php @@ -17,7 +17,7 @@ class GetPaymentCaptureRequest extends ResourceHydratableRequest implements Supp /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Capture::class; + protected $hydratableResource = Capture::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaymentChargebackRequest.php b/src/Http/Requests/GetPaymentChargebackRequest.php index b123d3ebc..a1ac16903 100644 --- a/src/Http/Requests/GetPaymentChargebackRequest.php +++ b/src/Http/Requests/GetPaymentChargebackRequest.php @@ -17,7 +17,7 @@ class GetPaymentChargebackRequest extends ResourceHydratableRequest implements S /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Chargeback::class; + protected $hydratableResource = Chargeback::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaymentLinkRequest.php b/src/Http/Requests/GetPaymentLinkRequest.php index 37a3b5587..f50229d66 100644 --- a/src/Http/Requests/GetPaymentLinkRequest.php +++ b/src/Http/Requests/GetPaymentLinkRequest.php @@ -16,7 +16,7 @@ class GetPaymentLinkRequest extends ResourceHydratableRequest implements Support /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentLink::class; + protected $hydratableResource = PaymentLink::class; private string $id; diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php index fb8f32f8a..882a2c4f3 100644 --- a/src/Http/Requests/GetPaymentMethodRequest.php +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -11,7 +11,7 @@ class GetPaymentMethodRequest extends ResourceHydratableRequest implements Suppo { protected static string $method = HttpMethod::GET; - public static string $targetResourceClass = Method::class; + protected $hydratableResource = Method::class; private ?GetPaymentMethodQuery $query = null; diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index a2e74899c..ebdfed5d6 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -17,7 +17,7 @@ class GetPaymentRefundRequest extends ResourceHydratableRequest implements Suppo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Refund::class; + protected $hydratableResource = Refund::class; private string $paymentId; diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 06e3f2902..683e9dfac 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -17,7 +17,7 @@ class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTes /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Payment::class; + protected $hydratableResource = Payment::class; private string $id; diff --git a/src/Http/Requests/GetPermissionRequest.php b/src/Http/Requests/GetPermissionRequest.php index e8f630861..95e5184df 100644 --- a/src/Http/Requests/GetPermissionRequest.php +++ b/src/Http/Requests/GetPermissionRequest.php @@ -13,7 +13,7 @@ class GetPermissionRequest extends ResourceHydratableRequest implements Supports /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Permission::class; + protected $hydratableResource = Permission::class; private string $id; diff --git a/src/Http/Requests/GetProfileRequest.php b/src/Http/Requests/GetProfileRequest.php index c8cb8ff43..b95d553dc 100644 --- a/src/Http/Requests/GetProfileRequest.php +++ b/src/Http/Requests/GetProfileRequest.php @@ -13,7 +13,7 @@ class GetProfileRequest extends ResourceHydratableRequest implements SupportsTes /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Profile::class; + protected $hydratableResource = Profile::class; private string $id; diff --git a/src/Http/Requests/GetSalesInvoiceRequest.php b/src/Http/Requests/GetSalesInvoiceRequest.php index 282a42378..224da3b90 100644 --- a/src/Http/Requests/GetSalesInvoiceRequest.php +++ b/src/Http/Requests/GetSalesInvoiceRequest.php @@ -15,7 +15,7 @@ class GetSalesInvoiceRequest extends ResourceHydratableRequest /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = SalesInvoice::class; + protected $hydratableResource = SalesInvoice::class; private string $id; diff --git a/src/Http/Requests/GetSessionRequest.php b/src/Http/Requests/GetSessionRequest.php index 7c0738e86..4bf471fb0 100644 --- a/src/Http/Requests/GetSessionRequest.php +++ b/src/Http/Requests/GetSessionRequest.php @@ -10,7 +10,7 @@ class GetSessionRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; - public static string $targetResourceClass = Session::class; + protected $hydratableResource = Session::class; private string $sessionId; diff --git a/src/Http/Requests/GetSettlementRequest.php b/src/Http/Requests/GetSettlementRequest.php index 149a5a161..bb25e8973 100644 --- a/src/Http/Requests/GetSettlementRequest.php +++ b/src/Http/Requests/GetSettlementRequest.php @@ -9,7 +9,7 @@ class GetSettlementRequest extends ResourceHydratableRequest { protected static string $method = Method::GET; - public static string $targetResourceClass = Settlement::class; + protected $hydratableResource = Settlement::class; private string $id; diff --git a/src/Http/Requests/GetSubscriptionRequest.php b/src/Http/Requests/GetSubscriptionRequest.php index c75449de1..722465ac0 100644 --- a/src/Http/Requests/GetSubscriptionRequest.php +++ b/src/Http/Requests/GetSubscriptionRequest.php @@ -16,7 +16,7 @@ class GetSubscriptionRequest extends ResourceHydratableRequest implements Suppor /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Subscription::class; + protected $hydratableResource = Subscription::class; private string $customerId; diff --git a/src/Http/Requests/GetTerminalRequest.php b/src/Http/Requests/GetTerminalRequest.php index 6b7c5a1ff..c9cc5bf14 100644 --- a/src/Http/Requests/GetTerminalRequest.php +++ b/src/Http/Requests/GetTerminalRequest.php @@ -13,7 +13,7 @@ class GetTerminalRequest extends ResourceHydratableRequest implements SupportsTe /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Terminal::class; + protected $hydratableResource = Terminal::class; private string $id; diff --git a/src/Http/Requests/ListPermissionsRequest.php b/src/Http/Requests/ListPermissionsRequest.php index 1380435a2..b2c4c2d76 100644 --- a/src/Http/Requests/ListPermissionsRequest.php +++ b/src/Http/Requests/ListPermissionsRequest.php @@ -12,7 +12,7 @@ class ListPermissionsRequest extends ResourceHydratableRequest /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PermissionCollection::class; + protected $hydratableResource = PermissionCollection::class; public function resolveResourcePath(): string { diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index a01b7ea0a..5a69e3620 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -2,37 +2,44 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Contracts\SupportsResourceHydration; use Mollie\Api\Http\Request; -abstract class ResourceHydratableRequest extends Request implements SupportsResourceHydration +abstract class ResourceHydratableRequest extends Request { /** - * Whether the request should be automatically hydrated. + * The resource class the request should be hydrated into. + * + * @var string|null */ - protected static bool $shouldAutoHydrate = false; + protected $hydratableResource = null; - /** - * The resource class the request should be casted to. - */ - public static string $targetResourceClass; - - public static function hydrate(bool $shouldAutoHydrate = true): void + public function isHydratable(): bool { - self::$shouldAutoHydrate = $shouldAutoHydrate; + return $this->hydratableResource !== null; } - public function shouldAutoHydrate(): bool + public function getHydratableResource(): string { - return self::$shouldAutoHydrate; + if (! $this->isHydratable()) { + throw new \RuntimeException('Resource class is not set.'); + } + + return $this->hydratableResource; } - public function getTargetResourceClass(): string + public function setHydratableResource(string $hydratableResource): self { - if (empty(static::$targetResourceClass)) { - throw new \RuntimeException('Resource class is not set.'); + if (! class_exists($hydratableResource)) { + throw new \InvalidArgumentException("The resource class '{$hydratableResource}' does not exist."); } - return static::$targetResourceClass; + /** @phpstan-ignore-next-line */ + if ($this->hydratableResource && ! is_subclass_of($hydratableResource, $this->hydratableResource)) { + throw new \InvalidArgumentException("The resource class '{$hydratableResource}' does not match the existing resource class '{$this->hydratableResource}'."); + } + + $this->hydratableResource = $hydratableResource; + + return $this; } } diff --git a/src/Http/Requests/UpdateCustomerRequest.php b/src/Http/Requests/UpdateCustomerRequest.php index 05a87c19c..3059034b9 100644 --- a/src/Http/Requests/UpdateCustomerRequest.php +++ b/src/Http/Requests/UpdateCustomerRequest.php @@ -17,7 +17,7 @@ class UpdateCustomerRequest extends ResourceHydratableRequest implements HasPayl /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Customer::class; + protected $hydratableResource = Customer::class; private string $id; diff --git a/src/Http/Requests/UpdatePaymentLinkRequest.php b/src/Http/Requests/UpdatePaymentLinkRequest.php index c03abbe1f..ee312fba8 100644 --- a/src/Http/Requests/UpdatePaymentLinkRequest.php +++ b/src/Http/Requests/UpdatePaymentLinkRequest.php @@ -18,7 +18,7 @@ class UpdatePaymentLinkRequest extends ResourceHydratableRequest implements HasP /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = PaymentLink::class; + protected $hydratableResource = PaymentLink::class; private string $id; diff --git a/src/Http/Requests/UpdatePaymentRequest.php b/src/Http/Requests/UpdatePaymentRequest.php index 9797b001e..83b7e6091 100644 --- a/src/Http/Requests/UpdatePaymentRequest.php +++ b/src/Http/Requests/UpdatePaymentRequest.php @@ -18,7 +18,7 @@ class UpdatePaymentRequest extends ResourceHydratableRequest implements HasPaylo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Payment::class; + protected $hydratableResource = Payment::class; private string $id; diff --git a/src/Http/Requests/UpdatePaymentRouteRequest.php b/src/Http/Requests/UpdatePaymentRouteRequest.php index f1ac3d56d..9c282eee5 100644 --- a/src/Http/Requests/UpdatePaymentRouteRequest.php +++ b/src/Http/Requests/UpdatePaymentRouteRequest.php @@ -21,7 +21,7 @@ class UpdatePaymentRouteRequest extends ResourceHydratableRequest implements Has /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Route::class; + protected $hydratableResource = Route::class; private string $paymentId; diff --git a/src/Http/Requests/UpdateProfileRequest.php b/src/Http/Requests/UpdateProfileRequest.php index f3c07064a..63340b4a8 100644 --- a/src/Http/Requests/UpdateProfileRequest.php +++ b/src/Http/Requests/UpdateProfileRequest.php @@ -17,7 +17,7 @@ class UpdateProfileRequest extends ResourceHydratableRequest implements HasPaylo /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Profile::class; + protected $hydratableResource = Profile::class; private string $id; diff --git a/src/Http/Requests/UpdateSalesInvoiceRequest.php b/src/Http/Requests/UpdateSalesInvoiceRequest.php index 881f59b24..f03d8d1d1 100644 --- a/src/Http/Requests/UpdateSalesInvoiceRequest.php +++ b/src/Http/Requests/UpdateSalesInvoiceRequest.php @@ -14,7 +14,7 @@ class UpdateSalesInvoiceRequest extends ResourceHydratableRequest implements Has protected static string $method = Method::PATCH; - public static string $targetResourceClass = SalesInvoice::class; + protected $hydratableResource = SalesInvoice::class; private string $id; diff --git a/src/Http/Requests/UpdateSessionRequest.php b/src/Http/Requests/UpdateSessionRequest.php index 8e49e71d6..33ff0c075 100644 --- a/src/Http/Requests/UpdateSessionRequest.php +++ b/src/Http/Requests/UpdateSessionRequest.php @@ -14,7 +14,7 @@ class UpdateSessionRequest extends ResourceHydratableRequest implements HasPaylo protected static string $method = Method::PATCH; - public static string $targetResourceClass = Session::class; + protected $hydratableResource = Session::class; private string $sessionId; diff --git a/src/Http/Requests/UpdateSubscriptionRequest.php b/src/Http/Requests/UpdateSubscriptionRequest.php index fdcff799c..4c63bafa3 100644 --- a/src/Http/Requests/UpdateSubscriptionRequest.php +++ b/src/Http/Requests/UpdateSubscriptionRequest.php @@ -21,7 +21,7 @@ class UpdateSubscriptionRequest extends ResourceHydratableRequest implements Has /** * The resource class the request should be casted to. */ - public static string $targetResourceClass = Subscription::class; + protected $hydratableResource = Subscription::class; private string $customerId; diff --git a/src/Http/Response.php b/src/Http/Response.php index 276da8351..955cb34be 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -4,11 +4,6 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Http\Requests\ResourceHydratableRequest; -use Mollie\Api\Resources\BaseResource; -use Mollie\Api\Resources\ResourceCollection; -use Mollie\Api\Traits\DelegatesToResource; -use Mollie\Api\Traits\HandlesResourceHydration; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -17,9 +12,6 @@ class Response { - use DelegatesToResource; - use HandlesResourceHydration; - protected ResponseInterface $psrResponse; protected RequestInterface $psrRequest; @@ -28,11 +20,6 @@ class Response protected ?Throwable $senderException = null; - /** - * @var null|BaseResource|ResourceCollection - */ - protected $resource = null; - /** * The decoded JSON response. */ @@ -50,18 +37,6 @@ public function __construct( $this->senderException = $senderException; } - /** - * @return self|BaseResource|ResourceCollection|null - */ - public function toResource() - { - if (! $this->getRequest() instanceof ResourceHydratableRequest) { - return $this; - } - - return $this->resource ?: $this->resource = $this->hydrate($this->getRequest(), $this); - } - /** * Get the JSON decoded body of the response as an array or scalar value. */ diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index d95f0858c..cc4913140 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -46,9 +46,9 @@ use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Traits\HandlesAuthentication; -use Mollie\Api\Traits\HandlesAutoHydration; use Mollie\Api\Traits\HandlesDebugging; use Mollie\Api\Traits\HandlesIdempotency; +use Mollie\Api\Traits\HandlesResourceHydration; use Mollie\Api\Traits\HandlesTestmode; use Mollie\Api\Traits\HandlesVersions; use Mollie\Api\Traits\HasEndpoints; @@ -101,9 +101,9 @@ class MollieApiClient implements Connector { use HandlesAuthentication; - use HandlesAutoHydration; use HandlesDebugging; use HandlesIdempotency; + use HandlesResourceHydration; use HandlesTestmode; use HandlesVersions; use HasEndpoints; diff --git a/src/Repositories/JsonPayloadRepository.php b/src/Repositories/JsonPayloadRepository.php index 7405811c1..ff98caa39 100644 --- a/src/Repositories/JsonPayloadRepository.php +++ b/src/Repositories/JsonPayloadRepository.php @@ -37,6 +37,18 @@ public function add(string $key, $value): self return $this; } + public function get(string $key, $default = null): mixed + { + return $this->store[$key] ?? $default; + } + + public function merge(array ...$arrays): self + { + $this->store = array_merge($this->store, ...$arrays); + + return $this; + } + public function remove(string $key): self { unset($this->store[$key]); diff --git a/src/Resources/BaseCollection.php b/src/Resources/BaseCollection.php index 4f7a5875c..8d839fabf 100644 --- a/src/Resources/BaseCollection.php +++ b/src/Resources/BaseCollection.php @@ -11,7 +11,7 @@ abstract class BaseCollection extends ArrayObject implements HasResponse { protected Connector $connector; - protected ?Response $response = null; + protected Response $response; /** * The name of the collection resource in Mollie's API. @@ -23,7 +23,7 @@ abstract class BaseCollection extends ArrayObject implements HasResponse /** * @param array|object $items */ - public function __construct(Connector $connector, $items = [], ?\stdClass $_links = null, ?Response $response = null) + public function __construct(Connector $connector, Response $response, $items = [], ?\stdClass $_links = null) { parent::__construct($items); @@ -32,7 +32,7 @@ public function __construct(Connector $connector, $items = [], ?\stdClass $_link $this->response = $response; } - public function getResponse(): ?Response + public function getResponse(): Response { return $this->response; } @@ -53,7 +53,7 @@ public function filter(callable $callback) $filteredItems = array_filter($this->getArrayCopy(), $callback); /** @phpstan-ignore-next-line */ - return new static($this->connector, $filteredItems, $this->_links); + return new static($this->connector, $this->response, $filteredItems, $this->_links); } public static function getCollectionResourceName(): string diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 6108cebc4..d3a8c5dcd 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -12,32 +12,28 @@ abstract class BaseResource implements HasResponse { protected Connector $connector; - protected ?Response $response; + protected Response $response; /** * Indicates the type of resource. * - * @example payment - * * @var string */ public $resource; - public function __construct(Connector $connector, ?Response $response = null) + public function __construct(Connector $connector, Response $response) { $this->connector = $connector; $this->response = $response; } - public function getResponse(): ?Response + public function getResponse(): Response { return $this->response; } - public function getPendingRequest(): ?PendingRequest + public function getPendingRequest(): PendingRequest { - return $this->response - ? $this->response->getPendingRequest() - : null; + return $this->response->getPendingRequest(); } } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 498f9fc26..05432ae8a 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -47,7 +47,7 @@ private function fetchCollection(string $url) { return $this ->connector - ->send(new DynamicGetRequest($url, static::class)); + ->send((new DynamicGetRequest($url))->setHydratableResource(static::class)); } /** @@ -83,14 +83,10 @@ public function getAutoIterator(bool $iterateBackwards = false): LazyCollection break; } - $response = $iterateBackwards + $page = $iterateBackwards ? $page->previous() : $page->next(); - - $page = $response instanceof Response - ? $response->toResource() - : $response; } - }); + }, $this->response); } } diff --git a/src/Resources/LazyCollection.php b/src/Resources/LazyCollection.php index 2893e1e74..bfd26b293 100644 --- a/src/Resources/LazyCollection.php +++ b/src/Resources/LazyCollection.php @@ -4,7 +4,9 @@ use Iterator; use IteratorAggregate; +use Mollie\Api\Contracts\HasResponse; use Mollie\Api\Contracts\ViableResponse; +use Mollie\Api\Http\Response; /** * @template TKey of array-key @@ -12,19 +14,27 @@ * * @implements IteratorAggregate */ -class LazyCollection implements IteratorAggregate, ViableResponse +class LazyCollection implements HasResponse, IteratorAggregate, ViableResponse { /** * @var callable */ private $source; + private Response $response; + /** * @param callable $source */ - public function __construct($source) + public function __construct($source, Response $response) { $this->source = $source; + $this->response = $response; + } + + public function getResponse(): Response + { + return $this->response; } /** @@ -65,7 +75,7 @@ public function filter(callable $callback): self yield $key => $value; } } - }); + }, $this->response); } /** @@ -109,7 +119,7 @@ public function map(callable $callback): self foreach ($this as $key => $value) { yield $key => $callback($value, $key); } - }); + }, $this->response); } /** @@ -133,7 +143,7 @@ public function take(int $limit): self $iterator->next(); } } - }); + }, $this->response); } /** diff --git a/src/Resources/Method.php b/src/Resources/Method.php index 669eb66e9..6805fdaab 100644 --- a/src/Resources/Method.php +++ b/src/Resources/Method.php @@ -82,6 +82,7 @@ public function issuers(): IssuerCollection return ResourceFactory::createBaseResourceCollection( $this->connector, Issuer::class, + $this->response, $this->issuers ); } @@ -95,6 +96,7 @@ public function pricing(): MethodPriceCollection return ResourceFactory::createBaseResourceCollection( $this->connector, MethodPrice::class, + $this->response, $this->pricing ); } diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index dc1fad05b..7963264b8 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -20,9 +20,6 @@ class Payment extends BaseResource implements EmbeddedResourcesContract { use HasMode; - /** - * Resource id prefix. Used to validate resource id's. - */ /** * Id of the payment (on the Mollie platform). * @@ -598,15 +595,12 @@ public function hasSplitPayments(): bool public function refunds(): RefundCollection { if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->connector); + return new RefundCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->refunds->href, - RefundCollection::class - )); + ->send((new DynamicGetRequest($this->_links->refunds->href))->setHydratableResource(RefundCollection::class)); } /** @@ -643,15 +637,12 @@ public function listRefunds(array $parameters = []): RefundCollection public function captures(): CaptureCollection { if (! isset($this->_links->captures->href)) { - return new CaptureCollection($this->connector); + return new CaptureCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->captures->href, - CaptureCollection::class - )); + ->send((new DynamicGetRequest($this->_links->captures->href))->setHydratableResource(CaptureCollection::class)); } /** @@ -677,15 +668,12 @@ public function getCapture($captureId, array $parameters = []): Capture public function chargebacks(): ChargebackCollection { if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->connector); + return new ChargebackCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->chargebacks->href, - ChargebackCollection::class - )); + ->send((new DynamicGetRequest($this->_links->chargebacks->href))->setHydratableResource(ChargebackCollection::class)); } /** diff --git a/src/Resources/Profile.php b/src/Resources/Profile.php index d5973b284..e4ab49c54 100644 --- a/src/Resources/Profile.php +++ b/src/Resources/Profile.php @@ -124,15 +124,12 @@ public function update(): ?Profile public function chargebacks(): ChargebackCollection { if (! isset($this->_links->chargebacks->href)) { - return new ChargebackCollection($this->connector); + return new ChargebackCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->chargebacks->href, - ChargebackCollection::class - )); + ->send((new DynamicGetRequest($this->_links->chargebacks->href))->setHydratableResource(ChargebackCollection::class)); } /** @@ -143,15 +140,12 @@ public function chargebacks(): ChargebackCollection public function methods(): MethodCollection { if (! isset($this->_links->methods->href)) { - return new MethodCollection($this->connector); + return new MethodCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->methods->href, - MethodCollection::class - )); + ->send((new DynamicGetRequest($this->_links->methods->href))->setHydratableResource(MethodCollection::class)); } /** @@ -184,15 +178,12 @@ public function disableMethod(string $methodId): void public function payments(): PaymentCollection { if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->connector); + return new PaymentCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->payments->href, - PaymentCollection::class - )); + ->send((new DynamicGetRequest($this->_links->payments->href))->setHydratableResource(PaymentCollection::class)); } /** @@ -203,14 +194,11 @@ public function payments(): PaymentCollection public function refunds(): RefundCollection { if (! isset($this->_links->refunds->href)) { - return new RefundCollection($this->connector); + return new RefundCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->refunds->href, - RefundCollection::class - )); + ->send((new DynamicGetRequest($this->_links->refunds->href))->setHydratableResource(RefundCollection::class)); } } diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 108c764a2..8d837d630 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -7,7 +7,6 @@ use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\Http\Response; -#[\AllowDynamicProperties] class ResourceFactory { /** @@ -18,6 +17,8 @@ public static function createFromApiResult(Connector $connector, $data, string $ if ($data instanceof Response) { $response = $data; $data = $response->json(); + } else if ($response === null) { + throw new \InvalidArgumentException('Response is required'); } /** @var BaseResource $resource */ @@ -28,8 +29,8 @@ public static function createFromApiResult(Connector $connector, $data, string $ } else { foreach ($data as $property => $value) { $resource->{$property} = self::holdsEmbeddedResources($resource, $property, $value) - ? self::parseEmbeddedResources($connector, $resource, $value) - : $value; + ? self::parseEmbeddedResources($connector, $resource, $value, $response) + : $value; } } @@ -51,7 +52,7 @@ private static function holdsEmbeddedResources(object $resource, string $key, $v /** * Parses embedded resources into their respective resource objects or collections. */ - private static function parseEmbeddedResources(Connector $connector, object $resource, object $embedded): object + private static function parseEmbeddedResources(Connector $connector, object $resource, object $embedded, Response $response): object { $result = new \stdClass; @@ -60,7 +61,7 @@ private static function parseEmbeddedResources(Connector $connector, object $res if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - 'Resource '.get_class($resource)." does not have a mapping for embedded resource {$resourceKey}" + 'Resource ' . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" ); } @@ -68,12 +69,14 @@ private static function parseEmbeddedResources(Connector $connector, object $res ? self::createFromApiResult( $connector, $resourceData, - $collectionOrResourceClass + $collectionOrResourceClass, + $response ) : self::createEmbeddedResourceCollection( $connector, $collectionOrResourceClass, - $resourceData + $resourceData, + $response ); } @@ -86,7 +89,8 @@ private static function parseEmbeddedResources(Connector $connector, object $res private static function createEmbeddedResourceCollection( Connector $connector, string $collectionClass, - $data + $data, + Response $response ): BaseCollection { return self::instantiateBaseCollection( $connector, @@ -94,8 +98,10 @@ private static function createEmbeddedResourceCollection( self::mapToResourceObjects( $connector, $data, - $collectionClass::getResourceClass() + $collectionClass::getResourceClass(), + $response ), + $response ); } @@ -105,17 +111,17 @@ private static function createEmbeddedResourceCollection( public static function createBaseResourceCollection( Connector $connector, string $resourceClass, + Response $response, $data = null, ?object $_links = null, - ?string $resourceCollectionClass = null, - ?Response $response = null + ?string $resourceCollectionClass = null ): BaseCollection { return self::instantiateBaseCollection( $connector, self::determineCollectionClass($resourceClass, $resourceCollectionClass), self::mapToResourceObjects($connector, $data ?? [], $resourceClass, $response), - $_links, - $response + $response, + $_links ); } @@ -123,19 +129,19 @@ private static function instantiateBaseCollection( Connector $connector, string $collectionClass, array $items, - ?object $_links = null, - ?Response $response = null + Response $response, + ?object $_links = null ): BaseCollection { - return new $collectionClass($connector, $items, $_links, $response); + return new $collectionClass($connector, $response, $items, $_links); } /** * @param array|\ArrayObject $data */ - private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, ?Response $response = null): array + private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, Response $response): array { return array_map( - fn ($item) => static::createFromApiResult( + fn($item) => static::createFromApiResult( $connector, $item, $resourceClass, @@ -147,6 +153,6 @@ private static function mapToResourceObjects(Connector $connector, $data, string private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string { - return $resourceCollectionClass ?: $resourceClass.'Collection'; + return $resourceCollectionClass ?: $resourceClass . 'Collection'; } } diff --git a/src/Resources/ResourceHydrator.php b/src/Resources/ResourceHydrator.php new file mode 100644 index 000000000..3e4449084 --- /dev/null +++ b/src/Resources/ResourceHydrator.php @@ -0,0 +1,70 @@ +getHydratableResource(); + + if ($this->isCollectionTarget($targetResourceClass)) { + $collection = $this->buildResultCollection($response, $targetResourceClass); + + return $this->unwrapIterator($request, $collection); + } + + if ($this->isResourceTarget($targetResourceClass)) { + return ResourceFactory::createFromApiResult($response->getConnector(), $response, $targetResourceClass); + } + + return $response; + } + + /** + * @return BaseCollection|LazyCollection + */ + private function unwrapIterator(Request $request, BaseCollection $collection) + { + if ($request instanceof IsIteratable && $request->iteratorEnabled()) { + /** @var CursorCollection $collection */ + return $collection->getAutoIterator($request->iteratesBackwards()); + } + + return $collection; + } + + private function buildResultCollection(Response $response, string $targetCollectionClass): BaseCollection + { + $result = $response->json(); + + return ResourceFactory::createBaseResourceCollection( + $response->getConnector(), + ($targetCollectionClass)::getResourceClass(), + $response, + $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, + $result->_links, + $targetCollectionClass, + ); + } + + private function isCollectionTarget(string $targetResourceClass): bool + { + return is_subclass_of($targetResourceClass, BaseCollection::class); + } + + private function isResourceTarget(string $targetResourceClass): bool + { + return is_subclass_of($targetResourceClass, BaseResource::class); + } +} diff --git a/src/Resources/Subscription.php b/src/Resources/Subscription.php index a2dde239f..1066f97de 100644 --- a/src/Resources/Subscription.php +++ b/src/Resources/Subscription.php @@ -199,14 +199,11 @@ public function cancel(): ?Subscription public function payments(): PaymentCollection { if (! isset($this->_links->payments->href)) { - return new PaymentCollection($this->connector); + return new PaymentCollection($this->connector, $this->response); } return $this ->connector - ->send(new DynamicGetRequest( - $this->_links->payments->href, - PaymentCollection::class - )); + ->send((new DynamicGetRequest($this->_links->payments->href))->setHydratableResource(PaymentCollection::class)); } } diff --git a/src/Traits/DelegatesToResource.php b/src/Traits/DelegatesToResource.php deleted file mode 100644 index 1ef396d8d..000000000 --- a/src/Traits/DelegatesToResource.php +++ /dev/null @@ -1,91 +0,0 @@ -ensureResourceIsLoaded(); - - return isset($this->resource->{$key}); - } - - /** - * Unset an attribute on the resource. - * - * @param string $key - * @return void - */ - public function __unset($key) - { - $this->ensureResourceIsLoaded(); - - unset($this->resource->{$key}); - } - - /** - * Dynamically get properties from the underlying resource. - * - * @param string $key - * @return mixed - */ - public function __get($key) - { - $this->ensureResourceIsLoaded(); - - if (! property_exists($this->resource, $key)) { - throw new \InvalidArgumentException("Property {$key} does not exist on resource."); - } - - $reflectionProperty = new ReflectionProperty($this->resource, $key); - - return $reflectionProperty->getValue($this->resource); - } - - /** - * Dynamically pass method calls to the underlying resource. - * - * @param string $method - * @param array $parameters - * @return mixed - */ - public function __call($method, $parameters) - { - $this->ensureResourceIsLoaded(); - - if (method_exists($this->resource, $method)) { - return call_user_func_array([$this->resource, $method], $parameters); - } - - throw new \BadMethodCallException("Method {$method} does not exist on resource."); - } - - /** - * Ensure the resource is loaded. - */ - private function ensureResourceIsLoaded(): void - { - if ($this->resource) { - return; - } - - $this->toResource(); - } -} diff --git a/src/Traits/HandlesAutoHydration.php b/src/Traits/HandlesAutoHydration.php deleted file mode 100644 index 0c8685293..000000000 --- a/src/Traits/HandlesAutoHydration.php +++ /dev/null @@ -1,34 +0,0 @@ -getTargetResourceClass(); - - if ($this->isCollectionTarget($targetResourceClass)) { - $collection = $this->buildResultCollection($response, $targetResourceClass); - - return $this->unwrapIterator($request, $collection); - } + protected ResourceHydrator $resourceHydrator; - if ($this->isResourceTarget($targetResourceClass)) { - return ResourceFactory::createFromApiResult($response->getConnector(), $response, $targetResourceClass); - } - - return $response; + public function initializeHandlesResourceHydration() + { + $this->resourceHydrator = new ResourceHydrator; } /** - * @return BaseCollection|LazyCollection + * Hydrate the response if the request is a ResourceHydratableRequest. + * + * @return Response|BaseResource|BaseCollection|LazyCollection */ - private function unwrapIterator(Request $request, BaseCollection $collection) - { - if ($request instanceof IsIteratable && $request->iteratorEnabled()) { - /** @var CursorCollection $collection */ - return $collection->getAutoIterator($request->iteratesBackwards()); - } - - return $collection; - } - - private function buildResultCollection(Response $response, string $targetCollectionClass): BaseCollection + public function hydrateIfApplicable(Response $response) { - $result = $response->json(); - - return ResourceFactory::createBaseResourceCollection( - $response->getConnector(), - ($targetCollectionClass)::getResourceClass(), - $result->_embedded->{$targetCollectionClass::getCollectionResourceName()}, - $result->_links, - $targetCollectionClass, - $response, - ); - } + $request = $response->getRequest(); - private function isCollectionTarget(string $targetResourceClass): bool - { - return is_subclass_of($targetResourceClass, BaseCollection::class); - } + if ($request instanceof ResourceHydratableRequest && $request->isHydratable()) { + return $this->resourceHydrator->hydrate($request, $response); + } - private function isResourceTarget(string $targetResourceClass): bool - { - return is_subclass_of($targetResourceClass, BaseResource::class); + return $response; } } diff --git a/src/Traits/IsIteratableRequest.php b/src/Traits/IsIteratableRequest.php index 6a1f09c5e..01ebad43b 100644 --- a/src/Traits/IsIteratableRequest.php +++ b/src/Traits/IsIteratableRequest.php @@ -2,6 +2,11 @@ namespace Mollie\Api\Traits; +use Mollie\Api\Http\Requests\ResourceHydratableRequest; + +/** + * @mixin ResourceHydratableRequest + */ trait IsIteratableRequest { protected bool $iteratorEnabled = false; diff --git a/src/Traits/SendsRequests.php b/src/Traits/SendsRequests.php index d0de39c52..17ce9e9e0 100644 --- a/src/Traits/SendsRequests.php +++ b/src/Traits/SendsRequests.php @@ -17,8 +17,10 @@ public function send(Request $request): object $pendingRequest = $pendingRequest->executeRequestHandlers(); - $response = $this->httpClient->sendRequest($pendingRequest); + $response = $pendingRequest->executeResponseHandlers( + $this->httpClient->sendRequest($pendingRequest) + ); - return $pendingRequest->executeResponseHandlers($response); + return $this->hydrateIfApplicable($response); } } diff --git a/src/Types/SalesInvoiceStatus.php b/src/Types/SalesInvoiceStatus.php index 02dc13694..e97f883d5 100644 --- a/src/Types/SalesInvoiceStatus.php +++ b/src/Types/SalesInvoiceStatus.php @@ -7,15 +7,15 @@ class SalesInvoiceStatus /** * The sales invoice is in draft status and has not been sent or paid. */ - const DRAFT = 'draft'; + public const DRAFT = 'draft'; /** * The sales invoice has been issued to the customer but has not been paid yet. */ - const ISSUED = 'issued'; + public const ISSUED = 'issued'; /** * The sales invoice has been fully paid. */ - const PAID = 'paid'; + public const PAID = 'paid'; } diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index 78df81ab9..ce68a85f7 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -9,11 +9,11 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; -use Tests\TestCase; class BalanceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index 5878fa1ca..a9f812c00 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -7,11 +7,12 @@ use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; -use Tests\TestCase; +use Mollie\Api\Http\Response; class BalanceReportEndpointCollectionTest extends TestCase { @@ -42,7 +43,7 @@ public function get_for_balance() GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_gVMhHKqSSRYJyPsuoPNFH'), ]); - $balance = new Balance($client); + $balance = new Balance($client, $this->createMock(Response::class)); $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; /** @var BalanceReport $report */ diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 190c79eae..9107354d6 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -7,9 +7,10 @@ use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class BalanceTransactionEndpointCollectionTest extends TestCase { @@ -20,7 +21,10 @@ public function page_for() GetPaginatedBalanceTransactionRequest::class => new MockResponse(200, 'balance-transactions'), ]); - $balance = new Balance($client); + $balance = new Balance( + $client, + $this->createMock(Response::class) + ); $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; /** @var BalanceTransactionCollection $transactions */ @@ -42,7 +46,7 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'balance_transactions'), ]); - $balance = new Balance($client); + $balance = new Balance($client, $this->createMock(Response::class)); $balance->id = 'bal_gVMhHKqSSRYJyPsuoPNFH'; foreach ($client->balanceTransactions->iteratorFor($balance) as $transaction) { diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index a0ad4190c..e0bd131ce 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php index fa73c9db9..b6dc3c9a1 100644 --- a/tests/EndpointCollection/ClientEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ClientEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index 96ede1fc0..0b53dfbb7 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ClientLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php index 010b34ac6..3afcdc31c 100644 --- a/tests/EndpointCollection/CustomerEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -10,9 +10,9 @@ use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CustomerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 51b0e186b..370c3c59f 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -10,9 +10,10 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class CustomerPaymentsEndpointCollectionTest extends TestCase { @@ -23,7 +24,10 @@ public function create_for() CreateCustomerPaymentRequest::class => new MockResponse(201, 'payment'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_kEn1PlbGa'; /** @var Payment $payment */ @@ -43,7 +47,10 @@ public function page_for() GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_kEn1PlbGa'; /** @var PaymentCollection $payments */ @@ -65,7 +72,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_kEn1PlbGa'; foreach ($client->customerPayments->iteratorFor($customer) as $payment) { diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php index e2dfe10e4..ff041c269 100644 --- a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class InvoiceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 05e6a7275..c6298fc18 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -11,9 +11,10 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class MandateEndpointCollectionTest extends TestCase { @@ -24,7 +25,10 @@ public function create_for() CreateMandateRequest::class => new MockResponse(201, 'mandate'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_4qqhO89gsT'; /** @var Mandate $mandate */ @@ -48,7 +52,10 @@ public function get_for() GetMandateRequest::class => new MockResponse(200, 'mandate'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_4qqhO89gsT'; /** @var Mandate $mandate */ @@ -64,7 +71,10 @@ public function revoke_for() RevokeMandateRequest::class => new MockResponse(204), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_4qqhO89gsT'; $client->mandates->revokeFor($customer, 'mdt_h3gAaD5zP'); @@ -80,7 +90,10 @@ public function page_for() GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), ]); - $customer = new Customer($client); + $customer = new Customer( + $client, + $this->createMock(Response::class) + ); $customer->id = 'cst_4qqhO89gsT'; /** @var MandateCollection $mandates */ diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php index 4c0c2deef..d0967eacf 100644 --- a/tests/EndpointCollection/MethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class MethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php index db90e2a0e..33876aa7e 100644 --- a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class MethodIssuerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php index 04d588c17..af290fc3c 100644 --- a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\GetOnboardingRequest; use Mollie\Api\Resources\Onboarding; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class OnboardingEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php index 37478a9c9..d456c4f0f 100644 --- a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class OrganizationEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php index 789ef496a..9fd0b4f83 100644 --- a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class OrganizationPartnerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index e10985c37..816422bdf 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -10,9 +10,9 @@ use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentCaptureEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index a25cffb96..c94c5cbf8 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index b1b6de205..1d2a22b8c 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -16,9 +16,10 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; +use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentEndpointCollectionTest extends TestCase { @@ -88,7 +89,10 @@ public function refund() CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_WDqYK6vllg'; /** @var Refund $refund */ diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index d8ac444ce..2fe3a8b2a 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -14,9 +14,9 @@ use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php index 6edba93f3..86f7abd2d 100644 --- a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentLinkPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index 99673c57e..65a13736e 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -10,9 +10,10 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class PaymentRefundEndpointCollectionTest extends TestCase { @@ -23,7 +24,10 @@ public function create_for() CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_7UhSN1zuXS'; /** @var Refund $refund */ @@ -45,7 +49,10 @@ public function get_for() GetPaymentRefundRequest::class => new MockResponse(200, 'refund'), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_7UhSN1zuXS'; /** @var Refund $refund */ @@ -61,7 +68,10 @@ public function cancel_for() CancelPaymentRefundRequest::class => new MockResponse(204), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_7UhSN1zuXS'; $client->paymentRefunds->cancelForPayment($payment, 're_4qqhO89gsT'); @@ -77,7 +87,10 @@ public function page_for() GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_7UhSN1zuXS'; /** @var RefundCollection $refunds */ @@ -100,7 +113,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); - $payment = new Payment($client); + $payment = new Payment( + $client, + $this->createMock(Response::class) + ); $payment->id = 'tr_7UhSN1zuXS'; foreach ($client->paymentRefunds->iteratorFor($payment) as $refund) { diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php index 5842509a3..a8aea41bc 100644 --- a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PaymentRouteEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php index 96274fa37..a9b54f43a 100644 --- a/tests/EndpointCollection/PermissionEndpointCollectionTest.php +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class PermissionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index 879314c55..155b3eae8 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -12,9 +12,9 @@ use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ProfileEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php index 8d83d2104..90853bd6f 100644 --- a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php @@ -5,9 +5,9 @@ use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ProfileMethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php index aec800e13..d59b54412 100644 --- a/tests/EndpointCollection/RefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -6,9 +6,9 @@ use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class RefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index 2465fc529..6ff7abbb0 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -21,9 +21,9 @@ use Mollie\Api\Types\SalesInvoiceStatus; use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class SalesInvoiceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index f6b146495..741511523 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -12,9 +12,9 @@ use Mollie\Api\Http\Requests\UpdateSessionRequest; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class SessionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index 556d1bacd..edad76b82 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -7,9 +7,10 @@ use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class SettlementCaptureEndpointCollectionTest extends TestCase { @@ -20,7 +21,10 @@ public function page_for() GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; /** @var CaptureCollection $captures */ @@ -42,7 +46,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'captures'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; foreach ($client->settlementCaptures->iteratorFor($settlement) as $capture) { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 9d27b5861..8bdba3c24 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -7,9 +7,10 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class SettlementChargebackEndpointCollectionTest extends TestCase { @@ -20,7 +21,10 @@ public function page_for() GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; /** @var ChargebackCollection $chargebacks */ @@ -42,7 +46,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; foreach ($client->settlementChargebacks->iteratorFor($settlement) as $chargeback) { diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php index 2e6bc1062..9fdea5874 100644 --- a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -4,12 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class SettlementPaymentEndpointCollectionTest extends TestCase { @@ -20,7 +21,7 @@ public function page_for() GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement($client, $this->createMock(Response::class)); $settlement->id = 'stl_jDk30akdN'; /** @var PaymentCollection $payments */ @@ -42,7 +43,7 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement($client, $this->createMock(Response::class)); $settlement->id = 'stl_jDk30akdN'; foreach ($client->settlementPayments->iteratorFor($settlement) as $payment) { diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index b05034927..2b93e9b28 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -7,9 +7,10 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class SettlementRefundEndpointCollectionTest extends TestCase { @@ -20,7 +21,10 @@ public function page_for() GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; /** @var RefundCollection $refunds */ @@ -42,7 +46,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); - $settlement = new Settlement($client); + $settlement = new Settlement( + $client, + $this->createMock(Response::class) + ); $settlement->id = 'stl_jDk30akdN'; foreach ($client->settlementRefunds->iteratorFor($settlement) as $refund) { diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php index d95c13c74..15432d762 100644 --- a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class SettlementsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 21eb9f931..837306c8c 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -12,9 +12,10 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; +use Mollie\Api\Http\Response; class SubscriptionEndpointCollectionTest extends TestCase { @@ -25,7 +26,7 @@ public function create_for() CreateSubscriptionRequest::class => new MockResponse(201, 'subscription'), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; /** @var Subscription $subscription */ @@ -49,7 +50,7 @@ public function get_for() GetSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; /** @var Subscription $subscription */ @@ -65,7 +66,7 @@ public function update_for() UpdateSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; /** @var Subscription $subscription */ @@ -87,7 +88,7 @@ public function cancel_for() CancelSubscriptionRequest::class => new MockResponse(204), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; $client->subscriptions->cancelFor($customer, 'sub_rVKGtNd6s3'); @@ -103,7 +104,7 @@ public function page_for() GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; /** @var SubscriptionCollection $subscriptions */ @@ -126,7 +127,7 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), ]); - $customer = new Customer($client); + $customer = new Customer($client, $this->createMock(Response::class)); $customer->id = 'cst_kEn1PlbGa'; foreach ($client->subscriptions->iteratorFor($customer) as $subscription) { @@ -164,12 +165,14 @@ public function iterator_for_all() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), ]); - foreach ($client->subscriptions->iteratorForAll( - 'sub_123', - 50, - ['profile_id' => 'prf_123'], - true - ) as $subscription) { + foreach ( + $client->subscriptions->iteratorForAll( + 'sub_123', + 50, + ['profile_id' => 'prf_123'], + true + ) as $subscription + ) { $this->assertSubscription($subscription); } } diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php index c9e1e48ba..4eafcb13b 100644 --- a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -4,12 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class SubscriptionPaymentEndpointCollectionTest extends TestCase { @@ -20,7 +21,10 @@ public function page_for() GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); - $subscription = new Subscription($client); + $subscription = new Subscription( + $client, + $this->createMock(Response::class) + ); $subscription->id = 'sub_rVKGtNd6s3'; $subscription->customerId = 'cust_kEn1PlbGa'; @@ -43,7 +47,10 @@ public function iterator_for() DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); - $subscription = new Subscription($client); + $subscription = new Subscription( + $client, + $this->createMock(Response::class) + ); $subscription->id = 'sub_rVKGtNd6s3'; $subscription->customerId = 'cust_kEn1PlbGa'; diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index a3dcf54c9..a26497fca 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -7,9 +7,9 @@ use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class TerminalEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index eb9f5e11a..49c565582 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class WalletEndpointCollectionTest extends TestCase { diff --git a/tests/Fixtures/Requests/DynamicDeleteRequest.php b/tests/Fixtures/Requests/DynamicDeleteRequest.php index 18395e4d5..fde2f97e3 100644 --- a/tests/Fixtures/Requests/DynamicDeleteRequest.php +++ b/tests/Fixtures/Requests/DynamicDeleteRequest.php @@ -21,10 +21,9 @@ class DynamicDeleteRequest extends DynamicRequest implements HasPayload, Support public function __construct( string $url, - string $resourceClass = '', array $payload = [] ) { - parent::__construct($url, $resourceClass); + parent::__construct($url); $this->payload = $payload; } diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index a43226d3d..e79b4c895 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -9,9 +9,9 @@ use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; +use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; use Tests\Fixtures\MockClient; -use Tests\TestCase; class GuzzleMollieHttpAdapterTest extends TestCase { diff --git a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php index 3db57e47b..73ed55e79 100644 --- a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php +++ b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php @@ -6,7 +6,7 @@ use Mollie\Api\Exceptions\UnrecognizedClientException; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class MollieHttpAdapterPickerTest extends TestCase { diff --git a/tests/Http/Adapter/RetryMiddlewareFactoryTest.php b/tests/Http/Adapter/RetryMiddlewareFactoryTest.php index b20c36e09..084cf373f 100644 --- a/tests/Http/Adapter/RetryMiddlewareFactoryTest.php +++ b/tests/Http/Adapter/RetryMiddlewareFactoryTest.php @@ -9,7 +9,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Mollie\Api\Http\Adapter\GuzzleRetryMiddlewareFactory; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class RetryMiddlewareFactoryTest extends TestCase { diff --git a/tests/Http/Auth/BearetTokenAuthenticatorTest.php b/tests/Http/Auth/BearetTokenAuthenticatorTest.php index 2639b76f1..79027398d 100644 --- a/tests/Http/Auth/BearetTokenAuthenticatorTest.php +++ b/tests/Http/Auth/BearetTokenAuthenticatorTest.php @@ -5,7 +5,7 @@ use Mollie\Api\Http\Auth\BearerTokenAuthenticator; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Repositories\ArrayStore; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class BearetTokenAuthenticatorTest extends TestCase { diff --git a/tests/Http/Middleware/GuardResponseTest.php b/tests/Http/Middleware/GuardResponseTest.php index 148e45725..a583c4faf 100644 --- a/tests/Http/Middleware/GuardResponseTest.php +++ b/tests/Http/Middleware/GuardResponseTest.php @@ -6,7 +6,7 @@ use Mollie\Api\Http\Middleware\GuardResponse; use Mollie\Api\Http\Response; use Mollie\Api\Http\ResponseStatusCode; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class GuardResponseTest extends TestCase { diff --git a/tests/Http/Middleware/HandlersTest.php b/tests/Http/Middleware/HandlersTest.php index dd798e001..91e5ca1b7 100644 --- a/tests/Http/Middleware/HandlersTest.php +++ b/tests/Http/Middleware/HandlersTest.php @@ -6,7 +6,7 @@ use Mollie\Api\Contracts\ViableResponse; use Mollie\Api\Http\Middleware\Handlers; use Mollie\Api\Http\Middleware\MiddlewarePriority; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class HandlersTest extends TestCase { diff --git a/tests/Http/MiddlewareTest.php b/tests/Http/MiddlewareTest.php index 67bd5cb8e..2efc9d71d 100644 --- a/tests/Http/MiddlewareTest.php +++ b/tests/Http/MiddlewareTest.php @@ -6,8 +6,8 @@ use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; -use Tests\TestCase; class MiddlewareTest extends TestCase { diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php index bcc3875e0..8e04e4936 100644 --- a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\RequestApplePayPaymentSessionPayload; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\AnyResource; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ApplePayPaymentSessionRequestTest extends TestCase { @@ -27,11 +26,11 @@ public function it_can_create_apple_pay_session() $request = new ApplePayPaymentSessionRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var AnyResource */ + $appleSession = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(AnyResource::class, $response->toResource()); + $this->assertTrue($appleSession->getResponse()->successful()); + $this->assertInstanceOf(AnyResource::class, $appleSession); } /** @test */ diff --git a/tests/Http/Requests/CancelPaymentRefundRequestTest.php b/tests/Http/Requests/CancelPaymentRefundRequestTest.php index bf1d15d81..1efe5a71f 100644 --- a/tests/Http/Requests/CancelPaymentRefundRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRefundRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CancelPaymentRefundRequestTest extends TestCase { diff --git a/tests/Http/Requests/CancelPaymentRequestTest.php b/tests/Http/Requests/CancelPaymentRequestTest.php index e1fb1e951..912cf971d 100644 --- a/tests/Http/Requests/CancelPaymentRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\CancelPaymentRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CancelPaymentRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_cancel_payment() $paymentId = 'tr_WDqYK6vllg'; $request = new CancelPaymentRequest($paymentId); - /** @var Response */ - $response = $client->send($request); + /** @var Payment */ + $payment = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Payment::class, $response->toResource()); + $this->assertTrue($payment->getResponse()->successful()); + $this->assertInstanceOf(Payment::class, $payment); } /** @test */ diff --git a/tests/Http/Requests/CancelSessionRequestTest.php b/tests/Http/Requests/CancelSessionRequestTest.php index 1eb90c80d..99bd15e34 100644 --- a/tests/Http/Requests/CancelSessionRequestTest.php +++ b/tests/Http/Requests/CancelSessionRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\CancelSessionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CancelSessionRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_cancel_session() $sessionId = 'sess_pNxqdWEFws'; $request = new CancelSessionRequest($sessionId); - /** @var Response */ - $response = $client->send($request); + /** @var Session */ + $session = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Session::class, $response->toResource()); + $this->assertTrue($session->getResponse()->successful()); + $this->assertInstanceOf(Session::class, $session); } /** @test */ diff --git a/tests/Http/Requests/CancelSubscriptionRequestTest.php b/tests/Http/Requests/CancelSubscriptionRequestTest.php index b468e2f54..ff6e41274 100644 --- a/tests/Http/Requests/CancelSubscriptionRequestTest.php +++ b/tests/Http/Requests/CancelSubscriptionRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CancelSubscriptionRequestTest extends TestCase { @@ -22,11 +21,11 @@ public function it_can_cancel_subscription() $subscriptionId = 'sub_rVKGtNd6s3'; $request = new CancelSubscriptionRequest($customerId, $subscriptionId); - /** @var Response */ - $response = $client->send($request); + /** @var Subscription */ + $subscription = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Subscription::class, $response->toResource()); + $this->assertTrue($subscription->getResponse()->successful()); + $this->assertInstanceOf(Subscription::class, $subscription); } /** @test */ diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php index cbc9273c2..a19729c0f 100644 --- a/tests/Http/Requests/CreateClientLinkRequestTest.php +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -6,11 +6,10 @@ use Mollie\Api\Http\Data\Owner; use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\ClientLink; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateClientLinkRequestTest extends TestCase { @@ -29,10 +28,10 @@ public function it_can_create_client_link() $request = new CreateClientLinkRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var ClientLink */ + $clientLink = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(ClientLink::class, $response->toResource()); + $this->assertTrue($clientLink->getResponse()->successful()); + $this->assertInstanceOf(ClientLink::class, $clientLink); } } diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index d280436c3..fc9a22017 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -6,11 +6,10 @@ use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateCustomerPaymentRequestTest extends TestCase { @@ -33,11 +32,11 @@ public function it_can_create_customer_payment() new CreatePaymentQuery(true) ); - /** @var Response */ - $response = $client->send($request); + /** @var Payment */ + $payment = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Payment::class, $response->toResource()); + $this->assertTrue($payment->getResponse()->successful()); + $this->assertInstanceOf(Payment::class, $payment); } /** @test */ diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php index d9a3384b4..bebef48b9 100644 --- a/tests/Http/Requests/CreateCustomerRequestTest.php +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Http\Requests\CreateCustomerRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateCustomerRequestTest extends TestCase { @@ -26,11 +25,11 @@ public function it_can_create_customer() $request = new CreateCustomerRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var Customer */ + $customer = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Customer::class, $response->toResource()); + $this->assertTrue($customer->getResponse()->successful()); + $this->assertInstanceOf(Customer::class, $customer); } /** @test */ diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php index 91b1b9bbe..2f9541c73 100644 --- a/tests/Http/Requests/CreateMandateRequestTest.php +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Mandate; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateMandateRequestTest extends TestCase { @@ -28,11 +27,11 @@ public function it_can_create_mandate() $request = new CreateMandateRequest($customerId, $payload); - /** @var Response */ - $response = $client->send($request); + /** @var Mandate */ + $mandate = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Mandate::class, $response->toResource()); + $this->assertTrue($mandate->getResponse()->successful()); + $this->assertInstanceOf(Mandate::class, $mandate); } /** @test */ diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php index 7b8d6d1b0..191b36cf6 100644 --- a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreatePaymentCaptureRequestTest extends TestCase { @@ -27,11 +26,11 @@ public function it_can_create_payment_capture() $request = new CreatePaymentCaptureRequest('tr_123', $payload); - /** @var Response */ - $response = $client->send($request); + /** @var Capture */ + $capture = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Capture::class, $response->toResource()); + $this->assertTrue($capture->getResponse()->successful()); + $this->assertInstanceOf(Capture::class, $capture); } /** @test */ diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php index cefa3469d..94261ce9e 100644 --- a/tests/Http/Requests/CreatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentLink; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreatePaymentLinkRequestTest extends TestCase { @@ -27,11 +26,11 @@ public function it_can_create_payment_link() $request = new CreatePaymentLinkRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var PaymentLink */ + $paymentLink = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(PaymentLink::class, $response->toResource()); + $this->assertTrue($paymentLink->getResponse()->successful()); + $this->assertInstanceOf(PaymentLink::class, $paymentLink); } /** @test */ diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php index 133c64b18..701b455e4 100644 --- a/tests/Http/Requests/CreatePaymentRefundRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Refund; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreatePaymentRefundRequestTest extends TestCase { @@ -28,11 +27,11 @@ public function it_can_create_payment_refund() $request = new CreatePaymentRefundRequest($paymentId, $payload); - /** @var Response */ - $response = $client->send($request); + /** @var Refund */ + $refund = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Refund::class, $response->toResource()); + $this->assertTrue($refund->getResponse()->successful()); + $this->assertInstanceOf(Refund::class, $refund); } /** @test */ diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index f690492ac..dd1305b25 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreatePaymentRequestTest extends TestCase { @@ -29,11 +28,11 @@ public function it_can_create_payment() $request = new CreatePaymentRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var Payment */ + $payment = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Payment::class, $response->toResource()); + $this->assertTrue($payment->getResponse()->successful()); + $this->assertInstanceOf(Payment::class, $payment); } /** @test */ diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php index 5f0b9ecf8..104330147 100644 --- a/tests/Http/Requests/CreateProfileRequestTest.php +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Profile; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateProfileRequestTest extends TestCase { @@ -29,11 +28,11 @@ public function it_can_create_profile() $request = new CreateProfileRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var Profile */ + $profile = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Profile::class, $response->toResource()); + $this->assertTrue($profile->getResponse()->successful()); + $this->assertInstanceOf(Profile::class, $profile); } /** @test */ diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index 6aa974f7a..755713df1 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -8,16 +8,15 @@ use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\Recipient; use Mollie\Api\Http\Requests\CreateSalesInvoiceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\PaymentTerm; use Mollie\Api\Types\RecipientType; use Mollie\Api\Types\SalesInvoiceStatus; use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateSalesInvoiceRequestTest extends TestCase { @@ -58,11 +57,11 @@ public function it_creates_sales_invoice() ); $request = new CreateSalesInvoiceRequest($payload); - /** @var Response */ - $response = $client->send($request); + /** @var SalesInvoice */ + $salesInvoice = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + $this->assertTrue($salesInvoice->getResponse()->successful()); + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); } /** @test */ diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php index 345284fa4..f8f1c5a5d 100644 --- a/tests/Http/Requests/CreateSessionRequestTest.php +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\CreateSessionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateSessionRequestTest extends TestCase { @@ -24,11 +23,11 @@ public function it_can_create_session() new AnyData(['baz' => 'qux']) ); - /** @var Response */ - $response = $client->send($request); + /** @var Session */ + $session = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Session::class, $response->toResource()); + $this->assertTrue($session->getResponse()->successful()); + $this->assertInstanceOf(Session::class, $session); } /** @test */ diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php index e20b56502..f42f164e6 100644 --- a/tests/Http/Requests/CreateSubscriptionRequestTest.php +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\CreateSubscriptionPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateSubscriptionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class CreateSubscriptionRequestTest extends TestCase { @@ -26,11 +25,11 @@ public function it_can_create_subscription() 'Test subscription' )); - /** @var Response */ - $response = $client->send($request); + /** @var Subscription */ + $subscription = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Subscription::class, $response->toResource()); + $this->assertTrue($subscription->getResponse()->successful()); + $this->assertInstanceOf(Subscription::class, $subscription); } /** @test */ diff --git a/tests/Http/Requests/DeleteCustomerRequestTest.php b/tests/Http/Requests/DeleteCustomerRequestTest.php index 3fe352d80..6748636c1 100644 --- a/tests/Http/Requests/DeleteCustomerRequestTest.php +++ b/tests/Http/Requests/DeleteCustomerRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DeleteCustomerRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DeleteCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeletePaymentLinkRequestTest.php b/tests/Http/Requests/DeletePaymentLinkRequestTest.php index 0a112a243..fa2474fb3 100644 --- a/tests/Http/Requests/DeletePaymentLinkRequestTest.php +++ b/tests/Http/Requests/DeletePaymentLinkRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DeletePaymentLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeleteProfileRequestTest.php b/tests/Http/Requests/DeleteProfileRequestTest.php index 339fc2686..55f8c102d 100644 --- a/tests/Http/Requests/DeleteProfileRequestTest.php +++ b/tests/Http/Requests/DeleteProfileRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DeleteProfileRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php index eae213fc8..4a2daeca3 100644 --- a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DeleteSalesInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/DisableMethodIssuerRequestTest.php b/tests/Http/Requests/DisableMethodIssuerRequestTest.php index 60741dbb1..db4c04c11 100644 --- a/tests/Http/Requests/DisableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/DisableMethodIssuerRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DisableMethodIssuerRequestTest extends TestCase { diff --git a/tests/Http/Requests/DisableProfileMethodRequestTest.php b/tests/Http/Requests/DisableProfileMethodRequestTest.php index fbb39aea1..19b76231a 100644 --- a/tests/Http/Requests/DisableProfileMethodRequestTest.php +++ b/tests/Http/Requests/DisableProfileMethodRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DisableProfileMethodRequestTest extends TestCase { diff --git a/tests/Http/Requests/DynamicGetRequestTest.php b/tests/Http/Requests/DynamicGetRequestTest.php index 7db9ee1a4..88bb59b54 100644 --- a/tests/Http/Requests/DynamicGetRequestTest.php +++ b/tests/Http/Requests/DynamicGetRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\DynamicGetRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class DynamicGetRequestTest extends TestCase { @@ -20,22 +19,24 @@ public function it_can_make_dynamic_get_request() $request = new DynamicGetRequest( 'payments/tr_WDqYK6vllg', - Payment::class, ['testmode' => 'true'] ); - /** @var Response */ - $response = $client->send($request); + $request->setHydratableResource(Payment::class); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Payment::class, $response->toResource()); + /** @var Payment */ + $payment = $client->send($request); + + $this->assertTrue($payment->getResponse()->successful()); + $this->assertInstanceOf(Payment::class, $payment); } /** @test */ public function it_resolves_correct_resource_path() { $path = 'payments/tr_WDqYK6vllg'; - $request = new DynamicGetRequest($path, Payment::class); + $request = new DynamicGetRequest($path); + $request->setHydratableResource(Payment::class); $this->assertEquals($path, $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php index 77c389748..2a2ff7662 100644 --- a/tests/Http/Requests/DynamicRequestTest.php +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -6,7 +6,7 @@ use Mollie\Api\Http\Requests\DynamicRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\Method; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class DynamicRequestTest extends TestCase { @@ -16,33 +16,38 @@ public function it_throws_exception_for_invalid_resource_class() $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("The resource class 'NonExistentClass' does not exist."); - /** @phpstan-ignore-next-line */ - new class('some-url', 'NonExistentClass') extends DynamicRequest + $request = new class('some-url') extends DynamicRequest { protected static string $method = Method::GET; }; + + $request->setHydratableResource('NonExistentClass'); } /** @test */ public function it_accepts_valid_resource_class() { - $request = new class('some-url', Payment::class) extends DynamicRequest + $request = new class('some-url') extends DynamicRequest { protected static string $method = Method::GET; }; - $this->assertEquals(Payment::class, $request->getTargetResourceClass()); + $request->setHydratableResource(Payment::class); + + $this->assertEquals(Payment::class, $request->getHydratableResource()); } /** @test */ public function it_resolves_correct_resource_path() { $url = 'https://example.org'; - $request = new class($url, Payment::class) extends DynamicRequest + $request = new class($url) extends DynamicRequest { protected static string $method = Method::GET; }; + $request->setHydratableResource(Payment::class); + $this->assertEquals($url, $request->resolveResourcePath()); } } diff --git a/tests/Http/Requests/EnableMethodIssuerRequestTest.php b/tests/Http/Requests/EnableMethodIssuerRequestTest.php index a0a1939df..d78fc20cf 100644 --- a/tests/Http/Requests/EnableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/EnableMethodIssuerRequestTest.php @@ -3,10 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; -use Mollie\Api\Http\Response; +use Mollie\Api\Resources\Issuer; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class EnableMethodIssuerRequestTest extends TestCase { @@ -22,11 +22,11 @@ public function it_can_enable_method_issuer() $issuerId = 'INGBNL2A'; $request = new EnableMethodIssuerRequest($profileId, $methodId, $issuerId); - /** @var Response */ - $response = $client->send($request); + /** @var Issuer */ + $issuer = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertEquals(204, $response->status()); + $this->assertTrue($issuer->getResponse()->successful()); + $this->assertEquals(204, $issuer->getResponse()->status()); } /** @test */ diff --git a/tests/Http/Requests/EnableProfileMethodRequestTest.php b/tests/Http/Requests/EnableProfileMethodRequestTest.php index 95ab9c582..19c2d9e15 100644 --- a/tests/Http/Requests/EnableProfileMethodRequestTest.php +++ b/tests/Http/Requests/EnableProfileMethodRequestTest.php @@ -3,10 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\EnableProfileMethodRequest; -use Mollie\Api\Http\Response; +use Mollie\Api\Resources\Method; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class EnableProfileMethodRequestTest extends TestCase { @@ -21,11 +21,11 @@ public function it_can_enable_profile_method() $methodId = 'ideal'; $request = new EnableProfileMethodRequest($profileId, $methodId); - /** @var Response */ - $response = $client->send($request); + /** @var Method */ + $method = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertEquals(204, $response->status()); + $this->assertTrue($method->getResponse()->successful()); + $this->assertEquals(204, $method->getResponse()->status()); } /** @test */ diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php index d4fefdf7e..6756cee4a 100644 --- a/tests/Http/Requests/GetAllMethodsRequestTest.php +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetAllMethodsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\MethodCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetAllMethodsRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_all_methods() $request = new GetAllMethodsRequest; - /** @var Response */ - $response = $client->send($request); + /** @var MethodCollection */ + $methods = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + $this->assertTrue($methods->getResponse()->successful()); + $this->assertInstanceOf(MethodCollection::class, $methods); } /** @test */ diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php index 260a365b7..a0b995241 100644 --- a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\SubscriptionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetAllPaginatedSubscriptionsRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_subscriptions() $request = new GetAllPaginatedSubscriptionsRequest; - /** @var Response */ - $response = $client->send($request); + /** @var SubscriptionCollection */ + $subscriptions = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(SubscriptionCollection::class, $response->toResource()); + $this->assertTrue($subscriptions->getResponse()->successful()); + $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); } /** @test */ diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index 187b5a6d5..1affd6dd0 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -5,11 +5,10 @@ use DateTime; use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\BalanceReport; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetBalanceReportRequestTest extends TestCase { @@ -28,11 +27,11 @@ public function it_can_get_balance_report() ) ); - /** @var Response */ - $response = $client->send($request); + /** @var BalanceReport */ + $balanceReport = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(BalanceReport::class, $response->toResource()); + $this->assertTrue($balanceReport->getResponse()->successful()); + $this->assertInstanceOf(BalanceReport::class, $balanceReport); } /** @test */ diff --git a/tests/Http/Requests/GetBalanceRequestTest.php b/tests/Http/Requests/GetBalanceRequestTest.php index 602301636..3854ee50f 100644 --- a/tests/Http/Requests/GetBalanceRequestTest.php +++ b/tests/Http/Requests/GetBalanceRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetBalanceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Balance; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetBalanceRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_balance() $balanceId = 'bal_12345678'; $request = new GetBalanceRequest($balanceId); - /** @var Response */ - $response = $client->send($request); + /** @var Balance */ + $balance = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Balance::class, $response->toResource()); + $this->assertTrue($balance->getResponse()->successful()); + $this->assertInstanceOf(Balance::class, $balance); } /** @test */ diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php index 1684dddd2..26c8c431c 100644 --- a/tests/Http/Requests/GetClientRequestTest.php +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetClientRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Client; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetClientRequestTest extends TestCase { @@ -20,12 +19,12 @@ public function it_can_get_client() $request = new GetClientRequest('client_123'); - /** @var Response */ - $response = $client->send($request); + /** @var Client */ + $client = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Client::class, $response->toResource()); - $this->assertEquals('client', $response->resource); + $this->assertTrue($client->getResponse()->successful()); + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals('client', $client->resource); } /** @test */ diff --git a/tests/Http/Requests/GetCustomerRequestTest.php b/tests/Http/Requests/GetCustomerRequestTest.php index 4626f72c9..36c90e9f8 100644 --- a/tests/Http/Requests/GetCustomerRequestTest.php +++ b/tests/Http/Requests/GetCustomerRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetCustomerRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetCustomerRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_customer() $customerId = 'cst_kEn1PlbGa'; $request = new GetCustomerRequest($customerId); - /** @var Response */ - $response = $client->send($request); + /** @var Customer */ + $customer = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Customer::class, $response->toResource()); + $this->assertTrue($customer->getResponse()->successful()); + $this->assertInstanceOf(Customer::class, $customer); } /** @test */ diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php index 46dae1dd9..b2cb2ce25 100644 --- a/tests/Http/Requests/GetEnabledMethodsRequestTest.php +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetEnabledMethodsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\MethodCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetEnabledMethodsRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_enabled_methods() $request = new GetEnabledMethodsRequest; - /** @var Response */ - $response = $client->send($request); + /** @var MethodCollection */ + $methods = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(MethodCollection::class, $response->toResource()); + $this->assertTrue($methods->getResponse()->successful()); + $this->assertInstanceOf(MethodCollection::class, $methods); } /** @test */ diff --git a/tests/Http/Requests/GetInvoiceRequestTest.php b/tests/Http/Requests/GetInvoiceRequestTest.php index 4dda901b9..748ca5074 100644 --- a/tests/Http/Requests/GetInvoiceRequestTest.php +++ b/tests/Http/Requests/GetInvoiceRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetInvoiceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Invoice; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetInvoiceRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_invoice() $invoiceId = 'inv_xBEbP9rvAq'; $request = new GetInvoiceRequest($invoiceId); - /** @var Response */ - $response = $client->send($request); + /** @var Invoice */ + $invoice = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Invoice::class, $response->toResource()); + $this->assertTrue($invoice->getResponse()->successful()); + $this->assertInstanceOf(Invoice::class, $invoice); } /** @test */ diff --git a/tests/Http/Requests/GetMandateRequestTest.php b/tests/Http/Requests/GetMandateRequestTest.php index 2178d288d..1308d3ce8 100644 --- a/tests/Http/Requests/GetMandateRequestTest.php +++ b/tests/Http/Requests/GetMandateRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetMandateRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Mandate; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetMandateRequestTest extends TestCase { @@ -22,11 +21,11 @@ public function it_can_get_mandate() $mandateId = 'mdt_h3gAaD5zP'; $request = new GetMandateRequest($customerId, $mandateId); - /** @var Response */ - $response = $client->send($request); + /** @var Mandate */ + $mandate = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Mandate::class, $response->toResource()); + $this->assertTrue($mandate->getResponse()->successful()); + $this->assertInstanceOf(Mandate::class, $mandate); } /** @test */ diff --git a/tests/Http/Requests/GetOnboardingRequestTest.php b/tests/Http/Requests/GetOnboardingRequestTest.php index e621f0807..6acc57b41 100644 --- a/tests/Http/Requests/GetOnboardingRequestTest.php +++ b/tests/Http/Requests/GetOnboardingRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetOnboardingRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Onboarding; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetOnboardingRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_onboarding() $request = new GetOnboardingRequest; - /** @var Response */ - $response = $client->send($request); + /** @var Onboarding */ + $onboarding = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Onboarding::class, $response->toResource()); + $this->assertTrue($onboarding->getResponse()->successful()); + $this->assertInstanceOf(Onboarding::class, $onboarding); } /** @test */ diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php index a2dbde763..db2e0bc62 100644 --- a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Partner; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetOrganizationPartnerStatusRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_organization_partner_status() $request = new GetOrganizationPartnerStatusRequest; - /** @var Response */ - $response = $client->send($request); + /** @var Partner */ + $partner = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Partner::class, $response->toResource()); + $this->assertTrue($partner->getResponse()->successful()); + $this->assertInstanceOf(Partner::class, $partner); } /** @test */ diff --git a/tests/Http/Requests/GetOrganizationRequestTest.php b/tests/Http/Requests/GetOrganizationRequestTest.php index 97fb103e4..073a82efa 100644 --- a/tests/Http/Requests/GetOrganizationRequestTest.php +++ b/tests/Http/Requests/GetOrganizationRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetOrganizationRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Organization; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetOrganizationRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_organization() $organizationId = 'org_1337'; $request = new GetOrganizationRequest($organizationId); - /** @var Response */ - $response = $client->send($request); + /** @var Organization */ + $organization = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Organization::class, $response->toResource()); + $this->assertTrue($organization->getResponse()->successful()); + $this->assertInstanceOf(Organization::class, $organization); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php index 7fd73bee3..4d964dc49 100644 --- a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\BalanceCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedBalanceRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_balances() $request = new GetPaginatedBalanceRequest; - /** @var Response */ - $response = $client->send($request); + /** @var BalanceCollection */ + $balances = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(BalanceCollection::class, $response->toResource()); + $this->assertTrue($balances->getResponse()->successful()); + $this->assertInstanceOf(BalanceCollection::class, $balances); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php index c7b81b294..3e594c1d0 100644 --- a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\BalanceTransactionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedBalanceTransactionRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_paginated_balance_transactions() $balanceId = 'bal_gVMhHKqSSRYJyPsuoPNFH'; $request = new GetPaginatedBalanceTransactionRequest($balanceId); - /** @var Response */ - $response = $client->send($request); + /** @var BalanceTransactionCollection */ + $balanceTransactions = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(BalanceTransactionCollection::class, $response->toResource()); + $this->assertTrue($balanceTransactions->getResponse()->successful()); + $this->assertInstanceOf(BalanceTransactionCollection::class, $balanceTransactions); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php index 3fb260273..163b21299 100644 --- a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\ChargebackCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedChargebacksRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_chargebacks() $request = new GetPaginatedChargebacksRequest; - /** @var Response */ - $response = $client->send($request); + /** @var ChargebackCollection */ + $chargebacks = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(ChargebackCollection::class, $response->toResource()); + $this->assertTrue($chargebacks->getResponse()->successful()); + $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php index 6ba609150..89c57313c 100644 --- a/tests/Http/Requests/GetPaginatedClientRequestTest.php +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\ClientCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedClientRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_clients() $request = new GetPaginatedClientRequest; - /** @var Response */ - $response = $client->send($request); + /** @var ClientCollection */ + $clients = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(ClientCollection::class, $response->toResource()); + $this->assertTrue($clients->getResponse()->successful()); + $this->assertInstanceOf(ClientCollection::class, $clients); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php index 4118819bc..1c99adcb8 100644 --- a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedCustomerPaymentsRequestTest extends TestCase { @@ -21,11 +20,11 @@ public function it_can_get_paginated_customer_payments() $customerId = 'cst_kEn1PlbGa'; $request = new GetPaginatedCustomerPaymentsRequest($customerId); - /** @var Response */ - $response = $client->send($request); + /** @var PaymentCollection */ + $payments = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(PaymentCollection::class, $response->toResource()); + $this->assertTrue($payments->getResponse()->successful()); + $this->assertInstanceOf(PaymentCollection::class, $payments); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php index 306edf79d..b1ff7c0b1 100644 --- a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\CustomerCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedCustomerRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_customers() $request = new GetPaginatedCustomerRequest; - /** @var Response */ - $response = $client->send($request); + /** @var CustomerCollection */ + $customers = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(CustomerCollection::class, $response->toResource()); + $this->assertTrue($customers->getResponse()->successful()); + $this->assertInstanceOf(CustomerCollection::class, $customers); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php index aa9519502..8203bb32d 100644 --- a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\InvoiceCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaginatedInvoiceRequestTest extends TestCase { @@ -20,11 +19,11 @@ public function it_can_get_paginated_invoices() $request = new GetPaginatedInvoiceRequest; - /** @var Response */ - $response = $client->send($request); + /** @var InvoiceCollection */ + $invoices = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(InvoiceCollection::class, $response->toResource()); + $this->assertTrue($invoices->getResponse()->successful()); + $this->assertInstanceOf(InvoiceCollection::class, $invoices); } /** @test */ diff --git a/tests/Http/Requests/GetPaginatedMandateRequestTest.php b/tests/Http/Requests/GetPaginatedMandateRequestTest.php index 33f8155c6..b52583ade 100644 --- a/tests/Http/Requests/GetPaginatedMandateRequestTest.php +++ b/tests/Http/Requests/GetPaginatedMandateRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedMandateRequestTest extends TestCase { @@ -24,14 +22,10 @@ public function it_can_get_paginated_mandates() $request = new GetPaginatedMandateRequest('cst_kEn1PlbGa'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var MandateCollection */ - $mandates = $response->toResource(); - // Assert response was properly handled + $mandates = $client->send($request); + + $this->assertTrue($mandates->getResponse()->successful()); $this->assertInstanceOf(MandateCollection::class, $mandates); $this->assertGreaterThan(0, $mandates->count()); @@ -54,12 +48,9 @@ public function it_can_iterate_over_mandates() $request = (new GetPaginatedMandateRequest('cst_kEn1PlbGa'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $mandates = $response->toResource(); + /** @var MandateCollection */ + $mandates = $client->send($request); + $this->assertTrue($mandates->getResponse()->successful()); foreach ($mandates as $mandate) { $this->assertInstanceOf(Mandate::class, $mandate); diff --git a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php index 806af8489..f2908f542 100644 --- a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; -use Mollie\Api\Resources\LazyCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentCapturesRequestTest extends TestCase { @@ -24,14 +22,10 @@ public function it_can_get_paginated_captures() $request = new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var CaptureCollection */ - $captures = $response->toResource(); - // Assert response was properly handled + $captures = $client->send($request); + + $this->assertTrue($captures->getResponse()->successful()); $this->assertInstanceOf(CaptureCollection::class, $captures); $this->assertGreaterThan(0, $captures->count()); @@ -54,12 +48,9 @@ public function it_can_iterate_over_captures() $request = (new GetPaginatedPaymentCapturesRequest('tr_WDqYK6vllg'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $captures = $response->toResource(); + /** @var CaptureCollection */ + $captures = $client->send($request); + $this->assertTrue($captures->getResponse()->successful()); foreach ($captures as $capture) { $this->assertInstanceOf(Capture::class, $capture); diff --git a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php index 36b8cc131..cc1b4c76e 100644 --- a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; -use Mollie\Api\Resources\LazyCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentChargebacksRequestTest extends TestCase { @@ -24,14 +22,10 @@ public function it_can_get_paginated_chargebacks() $request = new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var ChargebackCollection */ - $chargebacks = $response->toResource(); - // Assert response was properly handled + $chargebacks = $client->send($request); + + $this->assertTrue($chargebacks->getResponse()->successful()); $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); $this->assertGreaterThan(0, $chargebacks->count()); @@ -54,12 +48,9 @@ public function it_can_iterate_over_chargebacks() $request = (new GetPaginatedPaymentChargebacksRequest('tr_WDqYK6vllg'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $chargebacks = $response->toResource(); + /** @var ChargebackCollection */ + $chargebacks = $client->send($request); + $this->assertTrue($chargebacks->getResponse()->successful()); foreach ($chargebacks as $chargeback) { $this->assertInstanceOf(Chargeback::class, $chargeback); diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php index 3473e1da9..d009fd469 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentLinkPaymentsRequestTest extends TestCase { @@ -24,14 +22,11 @@ public function it_can_get_paginated_payment_link_payments() $request = new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); - /** @var Response */ - $response = $client->send($request); + /** @var PaymentCollection */ + $payments = $client->send($request); - $this->assertTrue($response->successful()); + $this->assertTrue($payments->getResponse()->successful()); - /** @var PaymentCollection */ - $payments = $response->toResource(); - // Assert response was properly handled $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertGreaterThan(0, $payments->count()); @@ -54,12 +49,9 @@ public function it_can_iterate_over_payment_link_payments() $request = (new GetPaginatedPaymentLinkPaymentsRequest('pl_4Y0eZitmBnQ5jsBYZIBw'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $payments = $response->toResource(); + /** @var PaymentCollection */ + $payments = $client->send($request); + $this->assertTrue($payments->getResponse()->successful()); foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php index 8a5ff6bbf..893b614a2 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentLinksRequestTest extends TestCase { @@ -24,16 +22,10 @@ public function it_can_get_paginated_payment_links() $request = new GetPaginatedPaymentLinksRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var PaymentLinkCollection */ - $paymentLinks = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(PaymentLinkCollection::class, $paymentLinks); - $this->assertGreaterThan(0, $paymentLinks->count()); + $paymentLinks = $client->send($request); + + $this->assertTrue($paymentLinks->getResponse()->successful()); foreach ($paymentLinks as $paymentLink) { $this->assertInstanceOf(PaymentLink::class, $paymentLink); @@ -54,12 +46,10 @@ public function it_can_iterate_over_payment_links() $request = (new GetPaginatedPaymentLinksRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); + /** @var PaymentLinkCollection */ + $paymentLinks = $client->send($request); - /** @var LazyCollection */ - $paymentLinks = $response->toResource(); + $this->assertTrue($paymentLinks->getResponse()->successful()); foreach ($paymentLinks as $paymentLink) { $this->assertInstanceOf(PaymentLink::class, $paymentLink); diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php index 8666739d3..1e2ddec37 100644 --- a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentRefundsRequestTest extends TestCase { @@ -24,16 +22,9 @@ public function it_can_get_paginated_refunds() $request = new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var RefundCollection */ - $refunds = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertGreaterThan(0, $refunds->count()); + $refunds = $client->send($request); + $this->assertTrue($refunds->getResponse()->successful()); foreach ($refunds as $refund) { $this->assertInstanceOf(Refund::class, $refund); @@ -54,12 +45,9 @@ public function it_can_iterate_over_refunds() $request = (new GetPaginatedPaymentRefundsRequest('tr_WDqYK6vllg'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $refunds = $response->toResource(); + /** @var RefundCollection */ + $refunds = $client->send($request); + $this->assertTrue($refunds->getResponse()->successful()); foreach ($refunds as $refund) { $this->assertInstanceOf(Refund::class, $refund); diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index 35dfcd146..58c13ccd2 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -8,10 +8,10 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedPaymentsRequestTest extends TestCase { @@ -24,13 +24,11 @@ public function it_can_get_paginated_payments() $request = new GetPaginatedPaymentsRequest; - /** @var Response */ - $response = $client->send($request); + /** @var PaymentCollection */ + $payments = $client->send($request); - $this->assertTrue($response->successful()); + $this->assertTrue($payments->getResponse()->successful()); - /** @var PaymentCollection */ - $payments = $response->toResource(); // Assert response was properly handled $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertGreaterThan(0, $payments->count()); @@ -54,12 +52,9 @@ public function it_can_iterate_over_payments() $request = (new GetPaginatedPaymentsRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $payments = $response->toResource(); + $payments = $client->send($request); + $this->assertTrue($payments->getResponse()->successful()); foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php index 6551351f1..3b55d6d3c 100644 --- a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedProfilesRequestTest extends TestCase { @@ -24,16 +22,10 @@ public function it_can_get_paginated_profiles() $request = new GetPaginatedProfilesRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var ProfileCollection */ - $profiles = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(ProfileCollection::class, $profiles); - $this->assertGreaterThan(0, $profiles->count()); + $profiles = $client->send($request); + + $this->assertTrue($profiles->getResponse()->successful()); foreach ($profiles as $profile) { $this->assertInstanceOf(Profile::class, $profile); @@ -54,12 +46,9 @@ public function it_can_iterate_over_profiles() $request = (new GetPaginatedProfilesRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $profiles = $response->toResource(); + /** @var ProfileCollection */ + $profiles = $client->send($request); + $this->assertTrue($profiles->getResponse()->successful()); foreach ($profiles as $profile) { $this->assertInstanceOf(Profile::class, $profile); diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php index 63ae9abc1..5367fbc0c 100644 --- a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; -use Mollie\Api\Http\Response; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedRefundsRequestTest extends TestCase { @@ -24,16 +22,10 @@ public function it_can_get_paginated_refunds() $request = new GetPaginatedRefundsRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var RefundCollection */ - $refunds = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertGreaterThan(0, $refunds->count()); + $refunds = $client->send($request); + + $this->assertTrue($refunds->getResponse()->successful()); foreach ($refunds as $refund) { $this->assertInstanceOf(Refund::class, $refund); @@ -54,12 +46,9 @@ public function it_can_iterate_over_refunds() $request = (new GetPaginatedRefundsRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - - /** @var LazyCollection */ - $refunds = $response->toResource(); + /** @var RefundCollection */ + $refunds = $client->send($request); + $this->assertTrue($refunds->getResponse()->successful()); foreach ($refunds as $refund) { $this->assertInstanceOf(Refund::class, $refund); diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php index 4d2dc1818..662429f30 100644 --- a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -11,7 +11,7 @@ use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class GetPaginatedSalesInvoicesRequestTest extends TestCase { @@ -24,13 +24,11 @@ public function it_gets_paginated_sales_invoices() $request = new GetPaginatedSalesInvoicesRequest; - /** @var Response */ - $response = $client->send($request); + /** @var SalesInvoiceCollection */ + $salesInvoices = $client->send($request); - $this->assertTrue($response->successful()); + $this->assertTrue($salesInvoices->getResponse()->successful()); - /** @var SalesInvoiceCollection */ - $salesInvoices = $response->toResource(); $this->assertInstanceOf(SalesInvoiceCollection::class, $salesInvoices); $this->assertGreaterThan(0, $salesInvoices->count()); } @@ -48,12 +46,9 @@ public function it_can_iterate_over_sales_invoices() $request = (new GetPaginatedSalesInvoicesRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $salesInvoices = $response->toResource(); + $salesInvoices = $client->send($request); + $this->assertTrue($salesInvoices->getResponse()->successful()); foreach ($salesInvoices as $salesInvoice) { $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php index 3cb416129..4ac570edc 100644 --- a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSessionsRequestTest extends TestCase { @@ -24,16 +23,10 @@ public function it_can_get_paginated_sessions() $request = new GetPaginatedSessionsRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var SessionCollection */ - $sessions = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(SessionCollection::class, $sessions); - $this->assertGreaterThan(0, $sessions->count()); + $sessions = $client->send($request); + + $this->assertTrue($sessions->getResponse()->successful()); foreach ($sessions as $session) { $this->assertInstanceOf(Session::class, $session); @@ -54,12 +47,9 @@ public function it_can_iterate_over_sessions() $request = (new GetPaginatedSessionsRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $sessions = $response->toResource(); + $sessions = $client->send($request); + $this->assertTrue($sessions->getResponse()->successful()); foreach ($sessions as $session) { $this->assertInstanceOf(Session::class, $session); diff --git a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php index e8dbdde0e..cc5c8dda0 100644 --- a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSettlementCapturesRequestTest extends TestCase { @@ -24,16 +23,10 @@ public function it_can_get_paginated_settlement_captures() $request = new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var CaptureCollection */ - $captures = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(CaptureCollection::class, $captures); - $this->assertGreaterThan(0, $captures->count()); + $captures = $client->send($request); + + $this->assertTrue($captures->getResponse()->successful()); foreach ($captures as $capture) { $this->assertInstanceOf(Capture::class, $capture); @@ -54,12 +47,9 @@ public function it_can_iterate_over_settlement_captures() $request = (new GetPaginatedSettlementCapturesRequest('stl_jDk30akdN'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $captures = $response->toResource(); + $captures = $client->send($request); + $this->assertTrue($captures->getResponse()->successful()); foreach ($captures as $capture) { $this->assertInstanceOf(Capture::class, $capture); diff --git a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php index 87a0838e9..a1b34e160 100644 --- a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php @@ -4,14 +4,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Chargeback; -use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSettlementChargebacksRequestTest extends TestCase { @@ -24,16 +22,10 @@ public function it_can_get_paginated_settlement_chargebacks() $request = new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); + /** @var LazyCollection */ + $chargebacks = $client->send($request); - /** @var ChargebackCollection */ - $chargebacks = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(ChargebackCollection::class, $chargebacks); - $this->assertGreaterThan(0, $chargebacks->count()); + $this->assertTrue($chargebacks->getResponse()->successful()); foreach ($chargebacks as $chargeback) { $this->assertInstanceOf(Chargeback::class, $chargeback); @@ -54,12 +46,9 @@ public function it_can_iterate_over_settlement_chargebacks() $request = (new GetPaginatedSettlementChargebacksRequest('stl_jDk30akdN'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $chargebacks = $response->toResource(); + $chargebacks = $client->send($request); + $this->assertTrue($chargebacks->getResponse()->successful()); foreach ($chargebacks as $chargeback) { $this->assertInstanceOf(Chargeback::class, $chargeback); diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php index fa4145a01..eb95c4429 100644 --- a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSettlementPaymentsRequestTest extends TestCase { @@ -24,14 +23,11 @@ public function it_can_get_paginated_settlement_payments() $request = new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'); - /** @var Response */ - $response = $client->send($request); + /** @var PaymentCollection */ + $payments = $client->send($request); - $this->assertTrue($response->successful()); + $this->assertTrue($payments->getResponse()->successful()); - /** @var PaymentCollection */ - $payments = $response->toResource(); - // Assert response was properly handled $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertGreaterThan(0, $payments->count()); @@ -54,12 +50,9 @@ public function it_can_iterate_over_settlement_payments() $request = (new GetPaginatedSettlementPaymentsRequest('stl_jDk30akdN'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $payments = $response->toResource(); + $payments = $client->send($request); + $this->assertTrue($payments->getResponse()->successful()); foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php index d4659701d..ea4a795bb 100644 --- a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSettlementRefundsRequestTest extends TestCase { @@ -24,14 +23,11 @@ public function it_can_get_paginated_settlement_refunds() $request = new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'); - /** @var Response */ - $response = $client->send($request); + /** @var RefundCollection */ + $refunds = $client->send($request); - $this->assertTrue($response->successful()); + $this->assertTrue($refunds->getResponse()->successful()); - /** @var RefundCollection */ - $refunds = $response->toResource(); - // Assert response was properly handled $this->assertInstanceOf(RefundCollection::class, $refunds); $this->assertGreaterThan(0, $refunds->count()); @@ -54,12 +50,9 @@ public function it_can_iterate_over_settlement_refunds() $request = (new GetPaginatedSettlementRefundsRequest('stl_jDk30akdN'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $refunds = $response->toResource(); + $refunds = $client->send($request); + $this->assertTrue($refunds->getResponse()->successful()); foreach ($refunds as $refund) { $this->assertInstanceOf(Refund::class, $refund); diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php index 09f772510..6b17960c4 100644 --- a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSettlementsRequestTest extends TestCase { @@ -24,14 +23,10 @@ public function it_can_get_paginated_settlements() $request = new GetPaginatedSettlementsRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var SettlementCollection */ - $settlements = $response->toResource(); - // Assert response was properly handled + $settlements = $client->send($request); + + $this->assertTrue($settlements->getResponse()->successful()); $this->assertInstanceOf(SettlementCollection::class, $settlements); $this->assertGreaterThan(0, $settlements->count()); @@ -54,12 +49,9 @@ public function it_can_iterate_over_settlements() $request = (new GetPaginatedSettlementsRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $settlements = $response->toResource(); + $settlements = $client->send($request); + $this->assertTrue($settlements->getResponse()->successful()); foreach ($settlements as $settlement) { $this->assertInstanceOf(Settlement::class, $settlement); diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index 554675312..016fa8435 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -5,14 +5,13 @@ use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSubscriptionPaymentsRequestTest extends TestCase { @@ -25,14 +24,10 @@ public function it_can_get_paginated_subscription_payments() $request = new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var PaymentCollection */ - $payments = $response->toResource(); - // Assert response was properly handled + $payments = $client->send($request); + + $this->assertTrue($payments->getResponse()->successful()); $this->assertInstanceOf(PaymentCollection::class, $payments); $this->assertGreaterThan(0, $payments->count()); @@ -55,12 +50,9 @@ public function it_can_iterate_over_subscription_payments() $request = (new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $payments = $response->toResource(); + $payments = $client->send($request); + $this->assertTrue($payments->getResponse()->successful()); foreach ($payments as $payment) { $this->assertInstanceOf(Payment::class, $payment); diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php index d96f427e0..a550f36b8 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedSubscriptionsRequestTest extends TestCase { @@ -24,14 +23,10 @@ public function it_can_get_paginated_subscriptions() $request = new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var SubscriptionCollection */ - $subscriptions = $response->toResource(); - // Assert response was properly handled + $subscriptions = $client->send($request); + + $this->assertTrue($subscriptions->getResponse()->successful()); $this->assertInstanceOf(SubscriptionCollection::class, $subscriptions); $this->assertGreaterThan(0, $subscriptions->count()); @@ -54,12 +49,9 @@ public function it_can_iterate_over_subscriptions() $request = (new GetPaginatedSubscriptionsRequest('cst_kEn1PlbGa'))->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $subscriptions = $response->toResource(); + $subscriptions = $client->send($request); + $this->assertTrue($subscriptions->getResponse()->successful()); foreach ($subscriptions as $subscription) { $this->assertInstanceOf(Subscription::class, $subscription); diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php index fef5a9665..38b96d0ef 100644 --- a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class GetPaginatedTerminalsRequestTest extends TestCase { @@ -24,16 +23,10 @@ public function it_can_get_paginated_terminals() $request = new GetPaginatedTerminalsRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var TerminalCollection */ - $terminals = $response->toResource(); - // Assert response was properly handled - $this->assertInstanceOf(TerminalCollection::class, $terminals); - $this->assertGreaterThan(0, $terminals->count()); + $terminals = $client->send($request); + + $this->assertTrue($terminals->getResponse()->successful()); foreach ($terminals as $terminal) { $this->assertInstanceOf(Terminal::class, $terminal); @@ -54,12 +47,9 @@ public function it_can_iterate_over_terminals() $request = (new GetPaginatedTerminalsRequest)->useIterator(); - /** @var Response */ - $response = $client->send($request); - $this->assertTrue($response->successful()); - /** @var LazyCollection */ - $terminals = $response->toResource(); + $terminals = $client->send($request); + $this->assertTrue($terminals->getResponse()->successful()); foreach ($terminals as $terminal) { $this->assertInstanceOf(Terminal::class, $terminal); diff --git a/tests/Http/Requests/GetPaymentCaptureRequestTest.php b/tests/Http/Requests/GetPaymentCaptureRequestTest.php index 10c3d60a6..77cba3311 100644 --- a/tests/Http/Requests/GetPaymentCaptureRequestTest.php +++ b/tests/Http/Requests/GetPaymentCaptureRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentCaptureRequestTest extends TestCase { @@ -20,18 +19,14 @@ public function it_can_get_payment_capture() $request = new GetPaymentCaptureRequest('tr_WDqYK6vllg', 'cpt_4qqhO89gsT'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Capture */ - $capture = $response->toResource(); + $capture = $client->send($request); + $this->assertTrue($capture->getResponse()->successful()); $this->assertInstanceOf(Capture::class, $capture); - $this->assertEquals('capture', $capture->resource); } + /** @test */ /** @test */ public function it_resolves_correct_resource_path() { diff --git a/tests/Http/Requests/GetPaymentChargebackRequestTest.php b/tests/Http/Requests/GetPaymentChargebackRequestTest.php index 116a46e9d..4022cdab0 100644 --- a/tests/Http/Requests/GetPaymentChargebackRequestTest.php +++ b/tests/Http/Requests/GetPaymentChargebackRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Chargeback; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentChargebackRequestTest extends TestCase { @@ -20,18 +19,14 @@ public function it_can_get_payment_chargeback() $request = new GetPaymentChargebackRequest('tr_WDqYK6vllg', 'chb_n9z0tp'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Chargeback */ - $chargeback = $response->toResource(); + $chargeback = $client->send($request); + $this->assertTrue($chargeback->getResponse()->successful()); $this->assertInstanceOf(Chargeback::class, $chargeback); - $this->assertEquals('chargeback', $chargeback->resource); } + /** @test */ /** @test */ public function it_resolves_correct_resource_path() { diff --git a/tests/Http/Requests/GetPaymentLinkRequestTest.php b/tests/Http/Requests/GetPaymentLinkRequestTest.php index 8914a2b84..cfe937893 100644 --- a/tests/Http/Requests/GetPaymentLinkRequestTest.php +++ b/tests/Http/Requests/GetPaymentLinkRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentLinkRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentLink; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentLinkRequestTest extends TestCase { @@ -20,18 +19,14 @@ public function it_can_get_payment_link() $request = new GetPaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var PaymentLink */ - $paymentLink = $response->toResource(); + $paymentLink = $client->send($request); + $this->assertTrue($paymentLink->getResponse()->successful()); $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals('payment-link', $paymentLink->resource); } + /** @test */ /** @test */ public function it_resolves_correct_resource_path() { diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php index 27bf0e226..78941a3e7 100644 --- a/tests/Http/Requests/GetPaymentMethodRequestTest.php +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentMethodRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Method; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentMethodRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_payment_method() $request = new GetPaymentMethodRequest('ideal'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Method */ - $method = $response->toResource(); + $method = $client->send($request); + $this->assertTrue($method->getResponse()->successful()); $this->assertInstanceOf(Method::class, $method); - $this->assertEquals('method', $method->resource); } /** @test */ diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php index 0e7778ec9..c250225b0 100644 --- a/tests/Http/Requests/GetPaymentRefundRequestTest.php +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentRefundRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Refund; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentRefundRequestTest extends TestCase { @@ -22,16 +21,11 @@ public function it_can_get_payment_refund() $refundId = 're_4qqhO89gsT'; $request = new GetPaymentRefundRequest($paymentId, $refundId); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Refund */ - $refund = $response->toResource(); + $refund = $client->send($request); + $this->assertTrue($refund->getResponse()->successful()); $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals('refund', $refund->resource); } /** @test */ diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php index 67239067f..10767ac64 100644 --- a/tests/Http/Requests/GetPaymentRequestTest.php +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPaymentRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPaymentRequestTest extends TestCase { @@ -21,16 +20,11 @@ public function it_can_get_payment() $paymentId = 'tr_WDqYK6vllg'; $request = new GetPaymentRequest($paymentId); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Payment */ - $payment = $response->toResource(); + $payment = $client->send($request); + $this->assertTrue($payment->getResponse()->successful()); $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('payment', $payment->resource); } /** @test */ diff --git a/tests/Http/Requests/GetPermissionRequestTest.php b/tests/Http/Requests/GetPermissionRequestTest.php index dacdf72e0..0e295314f 100644 --- a/tests/Http/Requests/GetPermissionRequestTest.php +++ b/tests/Http/Requests/GetPermissionRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetPermissionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Permission; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetPermissionRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_permission() $request = new GetPermissionRequest('payments.read'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Permission */ - $permission = $response->toResource(); + $permission = $client->send($request); + $this->assertTrue($permission->getResponse()->successful()); $this->assertInstanceOf(Permission::class, $permission); - $this->assertEquals('permission', $permission->resource); } /** @test */ diff --git a/tests/Http/Requests/GetProfileRequestTest.php b/tests/Http/Requests/GetProfileRequestTest.php index 8637aff66..49f74a760 100644 --- a/tests/Http/Requests/GetProfileRequestTest.php +++ b/tests/Http/Requests/GetProfileRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetProfileRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Profile; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetProfileRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_profile() $request = new GetProfileRequest('pfl_v9hTwCvYqw'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Profile */ - $profile = $response->toResource(); + $profile = $client->send($request); + $this->assertTrue($profile->getResponse()->successful()); $this->assertInstanceOf(Profile::class, $profile); - $this->assertEquals('profile', $profile->resource); } /** @test */ diff --git a/tests/Http/Requests/GetSalesInvoiceRequestTest.php b/tests/Http/Requests/GetSalesInvoiceRequestTest.php index b38fc6553..830117779 100644 --- a/tests/Http/Requests/GetSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/GetSalesInvoiceRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\GetSalesInvoiceRequest; use Mollie\Api\Resources\SalesInvoice; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetSalesInvoiceRequestTest extends TestCase { @@ -18,9 +18,11 @@ public function it_fetches_sales_invoice() ]); $request = new GetSalesInvoiceRequest('invoice_123'); - $response = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + /** @var SalesInvoice */ + $salesInvoice = $client->send($request); + + $this->assertTrue($salesInvoice->getResponse()->successful()); + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); } } diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php index 280da3d38..4bd5ba655 100644 --- a/tests/Http/Requests/GetSessionRequestTest.php +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\GetSessionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetSessionRequestTest extends TestCase { @@ -25,16 +24,11 @@ public function it_can_get_session() $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Session */ - $session = $response->toResource(); + $session = $client->send($request); + $this->assertTrue($session->getResponse()->successful()); $this->assertInstanceOf(Session::class, $session); - $this->assertEquals('session', $session->resource); } /** @test */ diff --git a/tests/Http/Requests/GetSettlementRequestTest.php b/tests/Http/Requests/GetSettlementRequestTest.php index c48d15371..98512a221 100644 --- a/tests/Http/Requests/GetSettlementRequestTest.php +++ b/tests/Http/Requests/GetSettlementRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetSettlementRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Settlement; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetSettlementRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_settlement() $request = new GetSettlementRequest('stl_jDk30akdN'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Settlement */ - $settlement = $response->toResource(); + $settlement = $client->send($request); + $this->assertTrue($settlement->getResponse()->successful()); $this->assertInstanceOf(Settlement::class, $settlement); - $this->assertEquals('settlement', $settlement->resource); } /** @test */ diff --git a/tests/Http/Requests/GetSubscriptionRequestTest.php b/tests/Http/Requests/GetSubscriptionRequestTest.php index 5b2b93dec..e32efcac4 100644 --- a/tests/Http/Requests/GetSubscriptionRequestTest.php +++ b/tests/Http/Requests/GetSubscriptionRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetSubscriptionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetSubscriptionRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_subscription() $request = new GetSubscriptionRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Subscription */ - $subscription = $response->toResource(); + $subscription = $client->send($request); + $this->assertTrue($subscription->getResponse()->successful()); $this->assertInstanceOf(Subscription::class, $subscription); - $this->assertEquals('subscription', $subscription->resource); } /** @test */ diff --git a/tests/Http/Requests/GetTerminalRequestTest.php b/tests/Http/Requests/GetTerminalRequestTest.php index 537b80e92..353f0b310 100644 --- a/tests/Http/Requests/GetTerminalRequestTest.php +++ b/tests/Http/Requests/GetTerminalRequestTest.php @@ -3,11 +3,10 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\GetTerminalRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Terminal; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class GetTerminalRequestTest extends TestCase { @@ -20,16 +19,11 @@ public function it_can_get_terminal() $request = new GetTerminalRequest('term_7MgL4wea'); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Terminal */ - $terminal = $response->toResource(); + $terminal = $client->send($request); + $this->assertTrue($terminal->getResponse()->successful()); $this->assertInstanceOf(Terminal::class, $terminal); - $this->assertEquals('terminal', $terminal->resource); } /** @test */ diff --git a/tests/Http/Requests/ListPermissionsRequestTest.php b/tests/Http/Requests/ListPermissionsRequestTest.php index 7fb0630c6..265b50919 100644 --- a/tests/Http/Requests/ListPermissionsRequestTest.php +++ b/tests/Http/Requests/ListPermissionsRequestTest.php @@ -3,12 +3,11 @@ namespace Tests\Http\Requests; use Mollie\Api\Http\Requests\ListPermissionsRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class ListPermissionsRequestTest extends TestCase { @@ -21,14 +20,10 @@ public function it_can_list_permissions() $request = new ListPermissionsRequest; - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var PermissionCollection */ - $permissions = $response->toResource(); + $permissions = $client->send($request); + $this->assertTrue($permissions->getResponse()->successful()); $this->assertInstanceOf(PermissionCollection::class, $permissions); $this->assertGreaterThan(0, $permissions->count()); diff --git a/tests/Http/Requests/PaginatedRequestTest.php b/tests/Http/Requests/PaginatedRequestTest.php index 58d77e58b..d4d0307f6 100644 --- a/tests/Http/Requests/PaginatedRequestTest.php +++ b/tests/Http/Requests/PaginatedRequestTest.php @@ -5,7 +5,7 @@ use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Http\Requests\PaginatedRequest; use Mollie\Api\Resources\BaseCollection; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class PaginatedRequestTest extends TestCase { @@ -29,7 +29,7 @@ public function it_can_handle_query() class ConcretePaginatedRequest extends PaginatedRequest { - public static string $targetResourceClass = BaseCollection::class; + protected $hydratableResource = BaseCollection::class; public function resolveResourcePath(): string { diff --git a/tests/Http/Requests/ResourceHydratableRequestTest.php b/tests/Http/Requests/ResourceHydratableRequestTest.php index 5e650c7c8..41f641164 100644 --- a/tests/Http/Requests/ResourceHydratableRequestTest.php +++ b/tests/Http/Requests/ResourceHydratableRequestTest.php @@ -4,7 +4,7 @@ use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Resources\BaseResource; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class ResourceHydratableRequestTest extends TestCase { @@ -13,21 +13,7 @@ public function it_can_get_target_resource_class() { $request = new ConcreteResourceHydratableRequest; - $this->assertEquals(BaseResource::class, $request->getTargetResourceClass()); - } - - /** @test */ - public function it_can_toggle_auto_hydration() - { - $request = new ConcreteResourceHydratableRequest; - - $this->assertFalse($request->shouldAutoHydrate()); - - ConcreteResourceHydratableRequest::hydrate(true); - $this->assertTrue($request->shouldAutoHydrate()); - - ConcreteResourceHydratableRequest::hydrate(false); - $this->assertFalse($request->shouldAutoHydrate()); + $this->assertEquals(BaseResource::class, $request->getHydratableResource()); } /** @test */ @@ -38,13 +24,13 @@ public function it_throws_exception_when_target_resource_class_is_not_set() $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Resource class is not set.'); - $request->getTargetResourceClass(); + $request->getHydratableResource(); } } class ConcreteResourceHydratableRequest extends ResourceHydratableRequest { - public static string $targetResourceClass = BaseResource::class; + protected $hydratableResource = BaseResource::class; public function resolveResourcePath(): string { diff --git a/tests/Http/Requests/RevokeMandateRequestTest.php b/tests/Http/Requests/RevokeMandateRequestTest.php index f41e7d78f..4ce0b57ce 100644 --- a/tests/Http/Requests/RevokeMandateRequestTest.php +++ b/tests/Http/Requests/RevokeMandateRequestTest.php @@ -4,9 +4,9 @@ use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class RevokeMandateRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php index 895003fb8..2f5a931ec 100644 --- a/tests/Http/Requests/UpdateCustomerRequestTest.php +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Http\Requests\UpdateCustomerRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdateCustomerRequestTest extends TestCase { @@ -24,16 +23,11 @@ public function it_can_update_customer() 'updated@example.com', )); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Customer */ - $customer = $response->toResource(); + $customer = $client->send($request); + $this->assertTrue($customer->getResponse()->successful()); $this->assertInstanceOf(Customer::class, $customer); - $this->assertEquals('customer', $customer->resource); } /** @test */ diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php index 531964f9e..ec77806c3 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\PaymentLink; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdatePaymentLinkRequestTest extends TestCase { @@ -23,16 +22,11 @@ public function it_can_update_payment_link() 'Updated payment link', )); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var PaymentLink */ - $paymentLink = $response->toResource(); + $paymentLink = $client->send($request); + $this->assertTrue($paymentLink->getResponse()->successful()); $this->assertInstanceOf(PaymentLink::class, $paymentLink); - $this->assertEquals('payment-link', $paymentLink->resource); } /** @test */ diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php index 58503c36c..20886b492 100644 --- a/tests/Http/Requests/UpdatePaymentRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\UpdatePaymentRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdatePaymentRequestTest extends TestCase { @@ -24,16 +23,11 @@ public function it_can_update_payment() 'https://example.com/redirect', )); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Payment */ - $payment = $response->toResource(); + $payment = $client->send($request); + $this->assertTrue($payment->getResponse()->successful()); $this->assertInstanceOf(Payment::class, $payment); - $this->assertEquals('payment', $payment->resource); } /** @test */ diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php index 7484fca51..8abf047df 100644 --- a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -5,11 +5,10 @@ use DateTime; use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Route; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdatePaymentRouteRequestTest extends TestCase { @@ -24,16 +23,11 @@ public function it_can_update_payment_route() new DateTime('2024-01-01'), )); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Route */ - $route = $response->toResource(); + $route = $client->send($request); + $this->assertTrue($route->getResponse()->successful()); $this->assertInstanceOf(Route::class, $route); - $this->assertEquals('route', $route->resource); } /** @test */ diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php index 9767b603e..868b22a92 100644 --- a/tests/Http/Requests/UpdateProfileRequestTest.php +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\UpdateProfileRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Profile; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdateProfileRequestTest extends TestCase { @@ -23,16 +22,11 @@ public function it_can_update_profile() 'Updated Profile Name', )); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Profile */ - $profile = $response->toResource(); + $profile = $client->send($request); + $this->assertTrue($profile->getResponse()->successful()); $this->assertInstanceOf(Profile::class, $profile); - $this->assertEquals('profile', $profile->resource); } /** @test */ diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index 572e7f1e4..8ea9a01d1 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -4,12 +4,11 @@ use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; use Mollie\Api\Http\Requests\UpdateSalesInvoiceRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\SalesInvoiceStatus; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdateSalesInvoiceRequestTest extends TestCase { @@ -26,11 +25,11 @@ public function it_updates_sales_invoice() ); $request = new UpdateSalesInvoiceRequest('invoice_123', $payload); - /** @var Response */ - $response = $client->send($request); + /** @var SalesInvoice */ + $salesInvoice = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(SalesInvoice::class, $response->toResource()); + $this->assertTrue($salesInvoice->getResponse()->successful()); + $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); } /** @test */ diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index c8043cde6..c65fa81ba 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -4,11 +4,10 @@ use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\UpdateSessionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Session; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdateSessionRequestTest extends TestCase { @@ -28,13 +27,10 @@ public function it_can_update_session() $request = new UpdateSessionRequest('ses_LQNz4v4Qvk', $payload); - /** @var Response */ - $response = $client->send($request); - - $this->assertTrue($response->successful()); - /** @var Session */ - $session = $response->toResource(); + $session = $client->send($request); + + $this->assertTrue($session->getResponse()->successful()); $this->assertInstanceOf(Session::class, $session); $this->assertEquals('session', $session->resource); diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index b2c803b83..7daa11628 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -5,11 +5,10 @@ use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\Subscription; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Tests\TestCase; class UpdateSubscriptionRequestTest extends TestCase { @@ -37,11 +36,11 @@ public function it_can_update_subscription() $request->resolveResourcePath() ); - /** @var Response */ - $response = $client->send($request); + /** @var Subscription */ + $subscription = $client->send($request); - $this->assertTrue($response->successful()); - $this->assertInstanceOf(Subscription::class, $response->toResource()); + $this->assertTrue($subscription->getResponse()->successful()); + $this->assertInstanceOf(Subscription::class, $subscription); } /** @test */ diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index d41455e7a..7b3e548c4 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -16,6 +16,7 @@ use Mollie\Api\Http\Response as HttpResponse; use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\Requests\DynamicDeleteRequest; diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 848837f94..70e0ff42e 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -5,11 +5,12 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; +use PHPUnit\Framework\TestCase; use stdClass; use Tests\Fixtures\MockClient; +use Mollie\Api\Http\Response; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use Tests\TestCase; class CursorCollectionTest extends TestCase { @@ -22,6 +23,7 @@ public function can_get_next_collection_result_when_next_link_is_available() $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], $this->arrayToObject([ 'next' => [ @@ -43,6 +45,7 @@ public function test_will_return_null_if_no_next_result_is_available() $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], (object) [] ); @@ -59,6 +62,7 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], $this->arrayToObject([ 'previous' => [ @@ -80,6 +84,7 @@ public function test_will_return_null_if_no_previous_result_is_available() $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], (object) [] ); @@ -94,6 +99,7 @@ public function test_auto_paginator_returns_lazy_collection() $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], (object) [] ); @@ -113,6 +119,7 @@ public function test_auto_paginator_can_handle_consecutive_calls() $collection = new PaymentCollection( $client, + $this->createMock(Response::class), [], $this->arrayToObject([ 'next' => [ diff --git a/tests/Resources/InvoiceTest.php b/tests/Resources/InvoiceTest.php index 7c9126aeb..af6b844b9 100644 --- a/tests/Resources/InvoiceTest.php +++ b/tests/Resources/InvoiceTest.php @@ -5,7 +5,8 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Invoice; use Mollie\Api\Types\InvoiceStatus; -use Tests\TestCase; +use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; class InvoiceTest extends TestCase { @@ -18,7 +19,10 @@ class InvoiceTest extends TestCase */ public function test_invoice_statuses($status, $function, $expected_boolean) { - $invoice = new Invoice($this->createMock(MollieApiClient::class)); + $invoice = new Invoice( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $invoice->status = $status; $this->assertEquals($expected_boolean, $invoice->{$function}()); diff --git a/tests/Resources/LazyCollectionTest.php b/tests/Resources/LazyCollectionTest.php index a3e9b170b..5dd8755ea 100644 --- a/tests/Resources/LazyCollectionTest.php +++ b/tests/Resources/LazyCollectionTest.php @@ -3,7 +3,8 @@ namespace Tests\Resources; use Mollie\Api\Resources\LazyCollection; -use Tests\TestCase; +use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; class LazyCollectionTest extends TestCase { @@ -20,7 +21,7 @@ protected function setUp(): void yield 1; yield 2; yield 3; - }); + }, $this->createMock(Response::class)); } public function test_can_create_a_collection_from_generator_function() diff --git a/tests/Resources/MandateCollectionTest.php b/tests/Resources/MandateCollectionTest.php index 7838112f4..4e484dd0d 100644 --- a/tests/Resources/MandateCollectionTest.php +++ b/tests/Resources/MandateCollectionTest.php @@ -6,7 +6,8 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use Mollie\Api\Types\MandateStatus; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; +use Mollie\Api\Http\Response; class MandateCollectionTest extends TestCase { @@ -24,14 +25,14 @@ protected function setUp(): void public function test_where_status() { - $collection = new MandateCollection($this->client, [ + $collection = new MandateCollection($this->client, $this->createMock(Response::class), [ $this->getMandateWithStatus(MandateStatus::VALID), $this->getMandateWithStatus(MandateStatus::VALID), $this->getMandateWithStatus(MandateStatus::VALID), $this->getMandateWithStatus(MandateStatus::INVALID), $this->getMandateWithStatus(MandateStatus::INVALID), $this->getMandateWithStatus(MandateStatus::PENDING), - ], null); + ]); $valid = $collection->whereStatus(MandateStatus::VALID); $invalid = $collection->whereStatus(MandateStatus::INVALID); @@ -58,7 +59,10 @@ public function test_where_status() */ protected function getMandateWithStatus($status) { - $mandate = new Mandate($this->client); + $mandate = new Mandate( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $mandate->status = $status; return $mandate; diff --git a/tests/Resources/MethodTest.php b/tests/Resources/MethodTest.php index a443fb32c..921b0af2b 100644 --- a/tests/Resources/MethodTest.php +++ b/tests/Resources/MethodTest.php @@ -5,13 +5,17 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\IssuerCollection; use Mollie\Api\Resources\Method; -use Tests\TestCase; +use Mollie\Api\Http\Response; +use PHPUnit\Framework\TestCase; class MethodTest extends TestCase { public function test_issuers_null_works() { - $method = new Method($this->createMock(MollieApiClient::class)); + $method = new Method( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $this->assertNull($method->issuers); $issuers = $method->issuers(); diff --git a/tests/Resources/OnboardingTest.php b/tests/Resources/OnboardingTest.php index 1de306b81..e8eef5996 100644 --- a/tests/Resources/OnboardingTest.php +++ b/tests/Resources/OnboardingTest.php @@ -5,6 +5,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Types\OnboardingStatus; +use Mollie\Api\Http\Response; class OnboardingTest extends \PHPUnit\Framework\TestCase { @@ -17,10 +18,13 @@ class OnboardingTest extends \PHPUnit\Framework\TestCase */ public function test_onboarding_statuses($status, $function, $expected_boolean) { - $orderLine = new Onboarding($this->createMock(MollieApiClient::class)); - $orderLine->status = $status; + $onboarding = new Onboarding( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); + $onboarding->status = $status; - $this->assertEquals($expected_boolean, $orderLine->{$function}()); + $this->assertEquals($expected_boolean, $onboarding->{$function}()); } public function dpTestOnboardingStatuses() diff --git a/tests/Resources/PaymentTest.php b/tests/Resources/PaymentTest.php index b3a339556..dd08b6e1d 100644 --- a/tests/Resources/PaymentTest.php +++ b/tests/Resources/PaymentTest.php @@ -7,6 +7,7 @@ use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; use stdClass; +use Mollie\Api\Http\Response; class PaymentTest extends \PHPUnit\Framework\TestCase { @@ -19,7 +20,10 @@ class PaymentTest extends \PHPUnit\Framework\TestCase */ public function test_payment_statuses($status, $function, $expected_boolean) { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->status = $status; $this->assertEquals($expected_boolean, $payment->{$function}()); @@ -80,7 +84,10 @@ public function dpTestPaymentStatuses() public function test_is_paid_returns_true_when_paid_datetime_is_set() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->paidAt = '2016-10-24'; $this->assertTrue($payment->isPaid()); @@ -88,7 +95,10 @@ public function test_is_paid_returns_true_when_paid_datetime_is_set() public function test_has_refunds_returns_true_when_payment_has_refunds() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $payment->_links->refunds = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds', 'type' => 'application/hal+json']; @@ -98,7 +108,10 @@ public function test_has_refunds_returns_true_when_payment_has_refunds() public function test_has_refunds_returns_false_when_payment_has_no_refunds() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $this->assertFalse($payment->hasRefunds()); @@ -106,7 +119,10 @@ public function test_has_refunds_returns_false_when_payment_has_no_refunds() public function test_has_chargebacks_returns_true_when_payment_has_chargebacks() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $payment->_links->chargebacks = (object) ['href' => 'https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks', 'type' => 'application/hal+json']; @@ -116,7 +132,10 @@ public function test_has_chargebacks_returns_true_when_payment_has_chargebacks() public function test_has_chargebacks_returns_false_when_payment_has_no_chargebacks() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $this->assertFalse($payment->hasChargebacks()); @@ -124,7 +143,10 @@ public function test_has_chargebacks_returns_false_when_payment_has_no_chargebac public function test_has_recurring_type_returns_true_when_recurring_type_is_first() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->sequenceType = SequenceType::FIRST; $this->assertFalse($payment->hasSequenceTypeRecurring()); @@ -133,7 +155,10 @@ public function test_has_recurring_type_returns_true_when_recurring_type_is_firs public function test_has_recurring_type_returns_true_when_recurring_type_is_recurring() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->sequenceType = SequenceType::RECURRING; $this->assertTrue($payment->hasSequenceTypeRecurring()); @@ -142,7 +167,10 @@ public function test_has_recurring_type_returns_true_when_recurring_type_is_recu public function test_has_recurring_type_returns_false_when_recurring_type_is_none() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->sequenceType = SequenceType::ONEOFF; $this->assertFalse($payment->hasSequenceTypeFirst()); @@ -151,7 +179,10 @@ public function test_has_recurring_type_returns_false_when_recurring_type_is_non public function test_get_checkout_url_returns_payment_url_from_links_object() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $payment->_links->checkout = new stdClass; @@ -162,7 +193,10 @@ public function test_get_checkout_url_returns_payment_url_from_links_object() public function test_get_mobile_app_checkout_url_returns_payment_url_from_links_object() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $payment->_links->mobileAppCheckout = new stdClass; @@ -173,7 +207,10 @@ public function test_get_mobile_app_checkout_url_returns_payment_url_from_links_ public function test_can_be_refunded_returns_true_when_amount_remaining_is_set() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $amountRemaining = new Stdclass; $amountRemaining->value = '15.00'; @@ -186,7 +223,10 @@ public function test_can_be_refunded_returns_true_when_amount_remaining_is_set() public function test_can_be_refunded_returns_false_when_amount_remaining_is_null() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountRemaining = null; $this->assertFalse($payment->canBeRefunded()); @@ -195,7 +235,10 @@ public function test_can_be_refunded_returns_false_when_amount_remaining_is_null public function test_get_amount_refunded_returns_amount_refunded_as_float() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountRefunded = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountRefunded()); @@ -203,7 +246,10 @@ public function test_get_amount_refunded_returns_amount_refunded_as_float() public function test_get_amount_refunded_returns0_when_amount_refunded_is_set_to_null() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountRefunded = null; self::assertSame(0.0, $payment->getAmountRefunded()); @@ -211,7 +257,10 @@ public function test_get_amount_refunded_returns0_when_amount_refunded_is_set_to public function test_get_amount_remaining_returns_amount_remaining_as_float() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountRemaining = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountRemaining()); @@ -219,7 +268,10 @@ public function test_get_amount_remaining_returns_amount_remaining_as_float() public function test_get_amount_remaining_returns0_when_amount_remaining_is_set_to_null() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountRefunded = null; self::assertSame(0.0, $payment->getAmountRemaining()); @@ -227,7 +279,10 @@ public function test_get_amount_remaining_returns0_when_amount_remaining_is_set_ public function test_get_amount_charged_back_returns_amount_charged_back_as_float() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountChargedBack = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getAmountChargedBack()); @@ -235,7 +290,10 @@ public function test_get_amount_charged_back_returns_amount_charged_back_as_floa public function test_get_amount_charged_back_returns0_when_amount_charged_back_is_set_to_null() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->amountChargedBack = null; self::assertSame(0.0, $payment->getAmountChargedBack()); @@ -243,7 +301,10 @@ public function test_get_amount_charged_back_returns0_when_amount_charged_back_i public function test_get_settlement_amount_returns0_when_settlement_amount_is_set_to_null() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->settlementAmount = null; self::assertSame(0.0, $payment->getSettlementAmount()); @@ -251,7 +312,10 @@ public function test_get_settlement_amount_returns0_when_settlement_amount_is_se public function test_get_settlement_amount_returns_settlement_amount_as_float() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->settlementAmount = (object) ['value' => 22.0, 'currency' => 'EUR']; self::assertSame(22.0, $payment->getSettlementAmount()); @@ -259,7 +323,10 @@ public function test_get_settlement_amount_returns_settlement_amount_as_float() public function test_has_split_payments_returns_false_when_payment_has_no_split() { - $payment = new Payment($this->createMock(MollieApiClient::class)); + $payment = new Payment( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $payment->_links = new stdClass; $this->assertFalse($payment->hasSplitPayments()); diff --git a/tests/Resources/ProfileTest.php b/tests/Resources/ProfileTest.php index 9bbe48af3..1480e81f9 100644 --- a/tests/Resources/ProfileTest.php +++ b/tests/Resources/ProfileTest.php @@ -5,6 +5,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Profile; use Mollie\Api\Types\ProfileStatus; +use Mollie\Api\Http\Response; class ProfileTest extends \PHPUnit\Framework\TestCase { @@ -17,7 +18,10 @@ class ProfileTest extends \PHPUnit\Framework\TestCase */ public function test_profile_statusses($status, $function, $expected_boolean) { - $profile = new Profile($this->createMock(MollieApiClient::class)); + $profile = new Profile( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $profile->status = $status; $this->assertEquals($expected_boolean, $profile->{$function}()); diff --git a/tests/Resources/RefundTest.php b/tests/Resources/RefundTest.php index 2b9f31e85..586ab7a6a 100644 --- a/tests/Resources/RefundTest.php +++ b/tests/Resources/RefundTest.php @@ -5,6 +5,7 @@ use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Refund; use Mollie\Api\Types\RefundStatus; +use Mollie\Api\Http\Response; class RefundTest extends \PHPUnit\Framework\TestCase { @@ -17,7 +18,10 @@ class RefundTest extends \PHPUnit\Framework\TestCase */ public function test_refund_statuses($status, $function, $expected_boolean) { - $refund = new Refund($this->createMock(MollieApiClient::class)); + $refund = new Refund( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $refund->status = $status; $this->assertEquals($expected_boolean, $refund->{$function}()); @@ -31,7 +35,10 @@ public function test_refund_statuses($status, $function, $expected_boolean) */ public function test_refund_can_be_canceled($status, $expected_boolean) { - $refund = new Refund($this->createMock(MollieApiClient::class)); + $refund = new Refund( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $refund->status = $status; $this->assertEquals($expected_boolean, $refund->canBeCanceled()); diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 2b701ccb8..8609b4468 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -2,13 +2,14 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; -use Tests\TestCase; +use PHPUnit\Framework\TestCase; class ResourceFactoryTest extends TestCase { @@ -25,7 +26,12 @@ public function test_create_from_api_response_works() } }'); - $payment = ResourceFactory::createFromApiResult($this->createMock(MollieApiClient::class), $apiResult, Payment::class); + $payment = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Payment::class, + $this->createMock(Response::class) + ); $this->assertInstanceOf(Payment::class, $payment); $this->assertEquals('payment', $payment->resource); @@ -64,7 +70,8 @@ public function test_embedded_collections_are_type_casted() $payment = ResourceFactory::createFromApiResult( $this->createMock(MollieApiClient::class), $apiResult, - Payment::class + Payment::class, + $this->createMock(Response::class) ); $this->assertInstanceOf(Payment::class, $payment); @@ -102,7 +109,8 @@ public function test_embedded_resources_are_type_casted() $client = ResourceFactory::createFromApiResult( $this->createMock(MollieApiClient::class), $apiResult, - Client::class + Client::class, + $this->createMock(Response::class) ); $this->assertInstanceOf(Client::class, $client); diff --git a/tests/Resources/SettlementTest.php b/tests/Resources/SettlementTest.php index b99197ac9..1a11f7907 100644 --- a/tests/Resources/SettlementTest.php +++ b/tests/Resources/SettlementTest.php @@ -2,6 +2,7 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Settlement; use Mollie\Api\Types\SettlementStatus; @@ -17,7 +18,10 @@ class SettlementTest extends \PHPUnit\Framework\TestCase */ public function test_settlement_statuses($status, $function, $expected_boolean) { - $settlement = new Settlement($this->createMock(MollieApiClient::class)); + $settlement = new Settlement( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $settlement->status = $status; $this->assertEquals($expected_boolean, $settlement->{$function}()); diff --git a/tests/Resources/SubscriptionTest.php b/tests/Resources/SubscriptionTest.php index afa1b0c6b..112ddc9b5 100644 --- a/tests/Resources/SubscriptionTest.php +++ b/tests/Resources/SubscriptionTest.php @@ -2,6 +2,7 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Subscription; use Mollie\Api\Types\SubscriptionStatus; @@ -17,7 +18,10 @@ class SubscriptionTest extends \PHPUnit\Framework\TestCase */ public function test_subscription_statuses($status, $function, $expected_boolean) { - $subscription = new Subscription($this->createMock(MollieApiClient::class)); + $subscription = new Subscription( + $this->createMock(MollieApiClient::class), + $this->createMock(Response::class) + ); $subscription->status = $status; $this->assertEquals($expected_boolean, $subscription->{$function}()); diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index 3a0f5f903..000000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Tue, 17 Dec 2024 13:16:16 +0000 Subject: [PATCH 118/131] Fixes coding style --- src/Resources/ResourceFactory.php | 8 ++++---- .../BalanceReportEndpointCollectionTest.php | 2 +- .../BalanceTransactionEndpointCollectionTest.php | 2 +- .../CustomerPaymentsEndpointCollectionTest.php | 2 +- .../EndpointCollection/MandateEndpointCollectionTest.php | 2 +- .../EndpointCollection/PaymentEndpointCollectionTest.php | 2 +- .../PaymentRefundEndpointCollectionTest.php | 2 +- .../SettlementCaptureEndpointCollectionTest.php | 2 +- .../SettlementChargebackEndpointCollectionTest.php | 2 +- .../SettlementRefundEndpointCollectionTest.php | 2 +- .../SubscriptionEndpointCollectionTest.php | 2 +- .../Requests/GetPaginatedSalesInvoicesRequestTest.php | 3 +-- tests/Resources/CursorCollectionTest.php | 2 +- tests/Resources/InvoiceTest.php | 2 +- tests/Resources/LazyCollectionTest.php | 2 +- tests/Resources/MandateCollectionTest.php | 2 +- tests/Resources/MethodTest.php | 2 +- tests/Resources/OnboardingTest.php | 2 +- tests/Resources/PaymentTest.php | 2 +- tests/Resources/ProfileTest.php | 2 +- tests/Resources/RefundTest.php | 2 +- 21 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 8d837d630..c9fedcb1c 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -17,7 +17,7 @@ public static function createFromApiResult(Connector $connector, $data, string $ if ($data instanceof Response) { $response = $data; $data = $response->json(); - } else if ($response === null) { + } elseif ($response === null) { throw new \InvalidArgumentException('Response is required'); } @@ -61,7 +61,7 @@ private static function parseEmbeddedResources(Connector $connector, object $res if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - 'Resource ' . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" + 'Resource '.get_class($resource)." does not have a mapping for embedded resource {$resourceKey}" ); } @@ -141,7 +141,7 @@ private static function instantiateBaseCollection( private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, Response $response): array { return array_map( - fn($item) => static::createFromApiResult( + fn ($item) => static::createFromApiResult( $connector, $item, $resourceClass, @@ -153,6 +153,6 @@ private static function mapToResourceObjects(Connector $connector, $data, string private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string { - return $resourceCollectionClass ?: $resourceClass . 'Collection'; + return $resourceCollectionClass ?: $resourceClass.'Collection'; } } diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index a9f812c00..20a4edf35 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -5,6 +5,7 @@ namespace Tests\EndpointCollection; use Mollie\Api\Http\Requests\GetBalanceReportRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; use PHPUnit\Framework\TestCase; @@ -12,7 +13,6 @@ use Tests\Fixtures\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; -use Mollie\Api\Http\Response; class BalanceReportEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 9107354d6..8bb1d1d83 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -4,13 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class BalanceTransactionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 370c3c59f..7953e0280 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -7,13 +7,13 @@ use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class CustomerPaymentsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index c6298fc18..072b58016 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -8,13 +8,13 @@ use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; use Mollie\Api\Http\Requests\RevokeMandateRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class MandateEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index 1d2a22b8c..e48b626c5 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -13,10 +13,10 @@ use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest; use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Http\Requests\UpdatePaymentRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; -use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index 65a13736e..2c7653a91 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -7,13 +7,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Http\Requests\GetPaymentRefundRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class PaymentRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index edad76b82..b22d5c567 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -4,13 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class SettlementCaptureEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 8bdba3c24..f588baf6e 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -4,13 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class SettlementChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index 2b93e9b28..597bd94b1 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -4,13 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class SettlementRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 837306c8c..2fbe24f57 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -9,13 +9,13 @@ use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest; use Mollie\Api\Http\Requests\GetSubscriptionRequest; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; -use Mollie\Api\Http\Response; class SubscriptionEndpointCollectionTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php index 662429f30..7d4a61c5d 100644 --- a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -4,14 +4,13 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSalesInvoicesRequest; -use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Resources\SalesInvoiceCollection; +use PHPUnit\Framework\TestCase; use Tests\Fixtures\MockClient; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; -use PHPUnit\Framework\TestCase; class GetPaginatedSalesInvoicesRequestTest extends TestCase { diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 70e0ff42e..ba7d03b9d 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -3,12 +3,12 @@ namespace Tests\Resources; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; use stdClass; use Tests\Fixtures\MockClient; -use Mollie\Api\Http\Response; use Tests\Fixtures\MockResponse; use Tests\Fixtures\SequenceMockResponse; diff --git a/tests/Resources/InvoiceTest.php b/tests/Resources/InvoiceTest.php index af6b844b9..52943c7a7 100644 --- a/tests/Resources/InvoiceTest.php +++ b/tests/Resources/InvoiceTest.php @@ -2,10 +2,10 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Invoice; use Mollie\Api\Types\InvoiceStatus; -use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; class InvoiceTest extends TestCase diff --git a/tests/Resources/LazyCollectionTest.php b/tests/Resources/LazyCollectionTest.php index 5dd8755ea..c79e67330 100644 --- a/tests/Resources/LazyCollectionTest.php +++ b/tests/Resources/LazyCollectionTest.php @@ -2,8 +2,8 @@ namespace Tests\Resources; -use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Http\Response; +use Mollie\Api\Resources\LazyCollection; use PHPUnit\Framework\TestCase; class LazyCollectionTest extends TestCase diff --git a/tests/Resources/MandateCollectionTest.php b/tests/Resources/MandateCollectionTest.php index 4e484dd0d..426ade2b3 100644 --- a/tests/Resources/MandateCollectionTest.php +++ b/tests/Resources/MandateCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use Mollie\Api\Types\MandateStatus; use PHPUnit\Framework\TestCase; -use Mollie\Api\Http\Response; class MandateCollectionTest extends TestCase { diff --git a/tests/Resources/MethodTest.php b/tests/Resources/MethodTest.php index 921b0af2b..959e1b7d2 100644 --- a/tests/Resources/MethodTest.php +++ b/tests/Resources/MethodTest.php @@ -2,10 +2,10 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\IssuerCollection; use Mollie\Api\Resources\Method; -use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; class MethodTest extends TestCase diff --git a/tests/Resources/OnboardingTest.php b/tests/Resources/OnboardingTest.php index e8eef5996..84b70b86d 100644 --- a/tests/Resources/OnboardingTest.php +++ b/tests/Resources/OnboardingTest.php @@ -2,10 +2,10 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Types\OnboardingStatus; -use Mollie\Api\Http\Response; class OnboardingTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Resources/PaymentTest.php b/tests/Resources/PaymentTest.php index dd08b6e1d..ccf6fe53b 100644 --- a/tests/Resources/PaymentTest.php +++ b/tests/Resources/PaymentTest.php @@ -2,12 +2,12 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\PaymentStatus; use Mollie\Api\Types\SequenceType; use stdClass; -use Mollie\Api\Http\Response; class PaymentTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Resources/ProfileTest.php b/tests/Resources/ProfileTest.php index 1480e81f9..d58d70494 100644 --- a/tests/Resources/ProfileTest.php +++ b/tests/Resources/ProfileTest.php @@ -2,10 +2,10 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Profile; use Mollie\Api\Types\ProfileStatus; -use Mollie\Api\Http\Response; class ProfileTest extends \PHPUnit\Framework\TestCase { diff --git a/tests/Resources/RefundTest.php b/tests/Resources/RefundTest.php index 586ab7a6a..42b3a121f 100644 --- a/tests/Resources/RefundTest.php +++ b/tests/Resources/RefundTest.php @@ -2,10 +2,10 @@ namespace Tests\Resources; +use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\Refund; use Mollie\Api\Types\RefundStatus; -use Mollie\Api\Http\Response; class RefundTest extends \PHPUnit\Framework\TestCase { From 30ed85c40393f76855092eb54c275b6f2ad2d867 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:05:03 +0100 Subject: [PATCH 119/131] wip --- src/Contracts/ResourceDecorator.php | 16 ++ .../Requests/ResourceHydratableRequest.php | 39 +++- src/Resources/DecorateResource.php | 38 ++++ src/Resources/Onboarding.php | 2 +- src/Resources/ResourceCollection.php | 2 +- src/Resources/ResourceFactory.php | 57 +++-- src/Resources/ResourceHydrator.php | 10 + tests/Resources/OnboardingTest.php | 6 +- tests/Resources/ResourceFactoryTest.php | 204 +++++++++++++++++- tests/Resources/ResourceHydratorTest.php | 192 +++++++++++++++++ 10 files changed, 529 insertions(+), 37 deletions(-) create mode 100644 src/Contracts/ResourceDecorator.php create mode 100644 src/Resources/DecorateResource.php create mode 100644 tests/Resources/ResourceHydratorTest.php diff --git a/src/Contracts/ResourceDecorator.php b/src/Contracts/ResourceDecorator.php new file mode 100644 index 000000000..ae9669df4 --- /dev/null +++ b/src/Contracts/ResourceDecorator.php @@ -0,0 +1,16 @@ +hydratableResource !== null; + return $this->hydratableResource !== null || $this->customHydratableResource !== null; } - public function getHydratableResource(): string + /** + * @return string|DecorateResource + */ + public function getHydratableResource() { if (! $this->isHydratable()) { throw new \RuntimeException('Resource class is not set.'); } - return $this->hydratableResource; + return $this->customHydratableResource ?? $this->hydratableResource; } - public function setHydratableResource(string $hydratableResource): self + /** + * @param string|DecorateResource $hydratableResource + * @return self + */ + public function setHydratableResource($hydratableResource): self { if (! class_exists($hydratableResource)) { throw new \InvalidArgumentException("The resource class '{$hydratableResource}' does not exist."); } - /** @phpstan-ignore-next-line */ - if ($this->hydratableResource && ! is_subclass_of($hydratableResource, $this->hydratableResource)) { - throw new \InvalidArgumentException("The resource class '{$hydratableResource}' does not match the existing resource class '{$this->hydratableResource}'."); + if ($hydratableResource instanceof DecorateResource && ! $hydratableResource->getDecorator()) { + throw new \InvalidArgumentException("The decorator class is not set."); } - $this->hydratableResource = $hydratableResource; + $this->customHydratableResource = $hydratableResource; + + return $this; + } + + public function resetHydratableResource(): self + { + $this->customHydratableResource = null; return $this; } diff --git a/src/Resources/DecorateResource.php b/src/Resources/DecorateResource.php new file mode 100644 index 000000000..a8ec0da0d --- /dev/null +++ b/src/Resources/DecorateResource.php @@ -0,0 +1,38 @@ +decoratedResource = $decoratedResource; + } + + public function with(string $decorator): self + { + if (! is_subclass_of($decorator, ResourceDecorator::class)) { + throw new \InvalidArgumentException("The decorator class '{$decorator}' does not implement the DecoratedResource interface."); + } + + $this->decorator = $decorator; + + return $this; + } + + public function getDecoratedResource(): string + { + return $this->decoratedResource; + } + + public function getDecorator(): ?string + { + return $this->decorator; + } +} diff --git a/src/Resources/Onboarding.php b/src/Resources/Onboarding.php index 73d373cb9..4bb819560 100644 --- a/src/Resources/Onboarding.php +++ b/src/Resources/Onboarding.php @@ -47,7 +47,7 @@ public function needsData(): bool return $this->status === OnboardingStatus::NEEDS_DATA; } - public function isInReview(): bool + public function inReview(): bool { return $this->status === OnboardingStatus::IN_REVIEW; } diff --git a/src/Resources/ResourceCollection.php b/src/Resources/ResourceCollection.php index 1f1c48140..d7dba9a51 100644 --- a/src/Resources/ResourceCollection.php +++ b/src/Resources/ResourceCollection.php @@ -12,7 +12,7 @@ abstract class ResourceCollection extends BaseCollection public static function getResourceClass(): string { if (empty(static::$resource)) { - throw new \RuntimeException('Collection name not set'); + throw new \RuntimeException('Resource name not set'); } return static::$resource; diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index c9fedcb1c..e17d5b43e 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\Connector; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\Http\Response; @@ -37,6 +38,42 @@ public static function createFromApiResult(Connector $connector, $data, string $ return $resource; } + /** + * @param null|array|\ArrayObject $data + */ + public static function createBaseResourceCollection( + Connector $connector, + string $resourceClass, + Response $response, + $data = null, + ?object $_links = null, + ?string $resourceCollectionClass = null + ): BaseCollection { + return self::instantiateBaseCollection( + $connector, + self::determineCollectionClass($resourceClass, $resourceCollectionClass), + self::mapToResourceObjects($connector, $data ?? [], $resourceClass, $response), + $response, + $_links + ); + } + + /** + * Create a decorated resource from a response or existing resource. + * + * @param Response|BaseResource|BaseCollection|LazyCollection $response + * @param string $decorator + * @return ResourceDecorator + */ + public static function createDecoratedResource($response, string $decorator): ResourceDecorator + { + if (! is_subclass_of($decorator, ResourceDecorator::class)) { + throw new \InvalidArgumentException("The decorator class '{$decorator}' does not implement the ResourceDecorator interface."); + } + + return $decorator::fromResource($response); + } + /** * Check if the resource holds embedded resources * @@ -105,26 +142,6 @@ private static function createEmbeddedResourceCollection( ); } - /** - * @param null|array|\ArrayObject $data - */ - public static function createBaseResourceCollection( - Connector $connector, - string $resourceClass, - Response $response, - $data = null, - ?object $_links = null, - ?string $resourceCollectionClass = null - ): BaseCollection { - return self::instantiateBaseCollection( - $connector, - self::determineCollectionClass($resourceClass, $resourceCollectionClass), - self::mapToResourceObjects($connector, $data ?? [], $resourceClass, $response), - $response, - $_links - ); - } - private static function instantiateBaseCollection( Connector $connector, string $collectionClass, diff --git a/src/Resources/ResourceHydrator.php b/src/Resources/ResourceHydrator.php index 3e4449084..bbe9e9ab6 100644 --- a/src/Resources/ResourceHydrator.php +++ b/src/Resources/ResourceHydrator.php @@ -18,6 +18,16 @@ public function hydrate(ResourceHydratableRequest $request, Response $response) { $targetResourceClass = $request->getHydratableResource(); + if ($targetResourceClass instanceof DecorateResource) { + $response = $this->hydrate( + // Reset the hydratable resource to the original resource class. + $request->resetHydratableResource(), + $response, + ); + + return ResourceFactory::createDecoratedResource($response, $targetResourceClass->getDecorator()); + } + if ($this->isCollectionTarget($targetResourceClass)) { $collection = $this->buildResultCollection($response, $targetResourceClass); diff --git a/tests/Resources/OnboardingTest.php b/tests/Resources/OnboardingTest.php index 84b70b86d..2291fb1c3 100644 --- a/tests/Resources/OnboardingTest.php +++ b/tests/Resources/OnboardingTest.php @@ -31,15 +31,15 @@ public function dpTestOnboardingStatuses() { return [ [OnboardingStatus::NEEDS_DATA, 'needsData', true], - [OnboardingStatus::NEEDS_DATA, 'isInReview', false], + [OnboardingStatus::NEEDS_DATA, 'inReview', false], [OnboardingStatus::NEEDS_DATA, 'isCompleted', false], [OnboardingStatus::IN_REVIEW, 'needsData', false], - [OnboardingStatus::IN_REVIEW, 'isInReview', true], + [OnboardingStatus::IN_REVIEW, 'inReview', true], [OnboardingStatus::IN_REVIEW, 'isCompleted', false], [OnboardingStatus::COMPLETED, 'needsData', false], - [OnboardingStatus::COMPLETED, 'isInReview', false], + [OnboardingStatus::COMPLETED, 'inReview', false], [OnboardingStatus::COMPLETED, 'isCompleted', true], ]; } diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 8609b4468..879233443 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -4,16 +4,21 @@ use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; +use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Resources\Payment; +use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; +use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Resources\BaseCollection; use PHPUnit\Framework\TestCase; class ResourceFactoryTest extends TestCase { - public function test_create_from_api_response_works() + /** @test */ + public function create_from_api_result() { $apiResult = json_decode('{ "resource":"payment", @@ -41,7 +46,8 @@ public function test_create_from_api_response_works() $this->assertEquals((object) ['value' => '20.00', 'currency' => 'EUR'], $payment->amount); } - public function test_embedded_collections_are_type_casted() + /** @test */ + public function embedded_collections_are_type_casted() { $apiResult = json_decode('{ "resource":"payment", @@ -80,7 +86,8 @@ public function test_embedded_collections_are_type_casted() } /** @test */ - public function test_embedded_resources_are_type_casted() + /** @test */ + public function embedded_resources_are_type_casted() { $apiResult = json_decode('{ "resource": "client", @@ -117,4 +124,195 @@ public function test_embedded_resources_are_type_casted() /** @phpstan-ignore-next-line */ $this->assertInstanceOf(Onboarding::class, $client->_embedded->onboarding); } + + /** @test */ + public function it_throws_exception_when_response_is_missing() + { + $apiResult = new \stdClass(); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Response is required'); + + ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Payment::class + ); + } + + /** @test */ + public function response_param_is_optional_when_data_is_a_response() + { + $jsonData = '{ + "resource":"payment", + "id":"tr_44aKxzEbr8" + }'; + + $response = $this->createMock(Response::class); + $response->method('json')->willReturn(json_decode($jsonData)); + + $payment = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $response, + Payment::class + ); + + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals('tr_44aKxzEbr8', $payment->id); + } + + /** @test */ + public function it_throws_exception_for_unmapped_embedded_resources() + { + $apiResult = json_decode('{ + "resource":"payment", + "id":"tr_44aKxzEbr8", + "_embedded": { + "unknown_resource": { + "id": "test" + } + } + }'); + + $this->expectException(\Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException::class); + + ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Payment::class, + $this->createMock(Response::class) + ); + } + + /** @test */ + public function it_creates_base_resource_collection() + { + $response = $this->createMock(Response::class); + $data = [ + ['id' => 'payment-1', 'resource' => 'payment'], + ['id' => 'payment-2', 'resource' => 'payment'] + ]; + + $collection = ResourceFactory::createBaseResourceCollection( + $this->createMock(MollieApiClient::class), + Payment::class, + $response, + $data + ); + + $this->assertInstanceOf(PaymentCollection::class, $collection); + $this->assertCount(2, $collection); + $this->assertInstanceOf(Payment::class, $collection[0]); + $this->assertEquals('payment-1', $collection[0]->id); + } + + /** @test */ + public function it_creates_base_resource_collection_with_custom_collection_class() + { + $response = $this->createMock(Response::class); + $data = [ + ['id' => 'payment-1', 'resource' => 'payment'] + ]; + + $collection = ResourceFactory::createBaseResourceCollection( + $this->createMock(MollieApiClient::class), + Payment::class, + $response, + $data, + null, + CustomPaymentCollection::class + ); + + $this->assertInstanceOf(CustomPaymentCollection::class, $collection); + $this->assertCount(1, $collection); + } + + /** @test */ + public function it_handles_any_resource_type() + { + $apiResult = json_decode('{ + "resource":"custom", + "id":"custom_123", + "customField":"test" + }'); + + $resource = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + AnyResource::class, + $this->createMock(Response::class) + ); + + $this->assertInstanceOf(AnyResource::class, $resource); + $this->assertEquals('custom_123', $resource->id); + $this->assertEquals('test', $resource->customField); + } + + /** @test */ + public function it_creates_decorated_resource() + { + $apiResult = json_decode('{ + "resource":"onboarding", + "status":"pending", + "canReceivePayments":true, + "canReceiveSettlements":true, + "_links": { + "dashboard": { + "href": "https://my.mollie.com/dashboard/org_123" + } + } + }'); + + $resource = ResourceFactory::createFromApiResult( + $this->createMock(MollieApiClient::class), + $apiResult, + Onboarding::class, + $this->createMock(Response::class) + ); + + $decoratedResource = ResourceFactory::createDecoratedResource( + $resource, + CustomResourceDecorator::class + ); + + $this->assertInstanceOf(CustomResourceDecorator::class, $decoratedResource); + $this->assertEquals('pending', $decoratedResource->status); + $this->assertEquals('https://my.mollie.com/dashboard/org_123', $decoratedResource->dashboardUrl); + } +} + +class CustomPaymentCollection extends BaseCollection +{ + // +} + +class CustomResourceDecorator implements ResourceDecorator +{ + public string $status; + public bool $canReceivePayments; + public bool $canReceiveSettlements; + public string $dashboardUrl; + + public function __construct( + string $status, + bool $canReceivePayments, + bool $canReceiveSettlements, + string $dashboardUrl + ) { + $this->status = $status; + $this->canReceivePayments = $canReceivePayments; + $this->canReceiveSettlements = $canReceiveSettlements; + $this->dashboardUrl = $dashboardUrl; + } + + public static function fromResource($onboarding): ResourceDecorator + { + /** @var Onboarding $onboarding */ + return new self( + $onboarding->status, + $onboarding->canReceivePayments, + $onboarding->canReceiveSettlements, + $onboarding->_links->dashboard->href + ); + } } diff --git a/tests/Resources/ResourceHydratorTest.php b/tests/Resources/ResourceHydratorTest.php new file mode 100644 index 000000000..4c8116544 --- /dev/null +++ b/tests/Resources/ResourceHydratorTest.php @@ -0,0 +1,192 @@ +hydrator = new ResourceHydrator(); + $this->client = $this->createMock(MollieApiClient::class); + } + + /** @test */ + public function hydrate_simple_resource(): void + { + $request = $this->createMock(ResourceHydratableRequest::class); + $response = $this->createMock(Response::class); + + $mockResource = new class($this->client, $response) extends BaseResource {}; + + $request->expects($this->once()) + ->method('getHydratableResource') + ->willReturn(get_class($mockResource)); + + $response->expects($this->once()) + ->method('getConnector') + ->willReturn($this->client); + + $result = $this->hydrator->hydrate($request, $response); + + $this->assertInstanceOf(BaseResource::class, $result); + } + + /** @test */ + public function hydrate_collection(): void + { + $request = $this->createMock(ResourceHydratableRequest::class); + $response = $this->createMock(Response::class); + + $mockCollection = new class($this->client, $response) extends ResourceCollection { + public static string $resource = AnyResource::class; + + public static string $collectionName = 'items'; + }; + + $request->expects($this->once()) + ->method('getHydratableResource') + ->willReturn(get_class($mockCollection)); + + $response->expects($this->once()) + ->method('getConnector') + ->willReturn($this->client); + + $response->expects($this->once()) + ->method('json') + ->willReturn((object)[ + '_embedded' => (object)['items' => []], + '_links' => (object)[] + ]); + + $result = $this->hydrator->hydrate($request, $response); + + $this->assertInstanceOf(ResourceCollection::class, $result); + } + + /** @test */ + public function hydrate_iteratable_collection(): void + { + $request = $this->createMock(IteratableRequest::class); + $request->method('getHydratableResource') + ->willReturn(CustomCollection::class); + + $request->expects($this->once()) + ->method('iteratorEnabled') + ->willReturn(true); + + $request->expects($this->once()) + ->method('iteratesBackwards') + ->willReturn(false); + + $this->assertInstanceOf(IsIteratable::class, $request); + + $response = $this->createMock(Response::class); + $response->method('getConnector') + ->willReturn($this->client); + + $response->expects($this->once()) + ->method('json') + ->willReturn((object)[ + '_embedded' => (object)['items' => [ + (object)[ + 'id' => 'id', + 'foo' => 'bar', + ] + ]], + '_links' => (object)[] + ]); + + $result = $this->hydrator->hydrate($request, $response); + + $this->assertInstanceOf(LazyCollection::class, $result); + $this->assertInstanceOf(AnyResource::class, $result->first()); + } + + /** @test */ + public function hydrate_decorated_resource(): void + { + $request = $this->createMock(ResourceHydratableRequest::class); + $response = $this->createMock(Response::class); + + $decoratedResource = (new DecorateResource(AnyResource::class)) + ->with(CustomDecorator::class); + + $request->expects($this->exactly(2)) + ->method('getHydratableResource') + ->willReturnOnConsecutiveCalls($decoratedResource, AnyResource::class); + + $request->expects($this->once()) + ->method('resetHydratableResource') + ->willReturnSelf(); + + $response->expects($this->once()) + ->method('getConnector') + ->willReturn($this->client); + + $result = $this->hydrator->hydrate($request, $response); + + $this->assertInstanceOf(CustomDecorator::class, $result); + } + + /** @test */ + public function hydrate_returns_response_when_no_resource_target(): void + { + $request = $this->createMock(ResourceHydratableRequest::class); + $response = $this->createMock(Response::class); + + $request->expects($this->once()) + ->method('getHydratableResource') + ->willReturn('InvalidClass'); + + $result = $this->hydrator->hydrate($request, $response); + + $this->assertSame($response, $result); + } +} + +class IteratableRequest extends ResourceHydratableRequest implements IsIteratable +{ + use IsIteratableRequest; + + protected $hydratableResource = CustomCollection::class; + + public function resolveResourcePath(): string + { + return 'items'; + } +} + +class CustomCollection extends CursorCollection +{ + public static string $resource = AnyResource::class; + + public static string $collectionName = 'items'; +} + +class CustomDecorator implements ResourceDecorator +{ + public static function fromResource($resource): self + { + return new self(); + } +} From b5aac1125021cd61c30abd1cbc3708a57c0a354b Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 18 Dec 2024 11:05:34 +0000 Subject: [PATCH 120/131] Fixes coding style --- src/Contracts/ResourceDecorator.php | 2 +- .../Requests/ResourceHydratableRequest.php | 5 ++-- src/Resources/ResourceFactory.php | 6 ++-- tests/Resources/ResourceFactoryTest.php | 13 ++++---- tests/Resources/ResourceHydratorTest.php | 30 ++++++++++--------- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Contracts/ResourceDecorator.php b/src/Contracts/ResourceDecorator.php index ae9669df4..c74d3e652 100644 --- a/src/Contracts/ResourceDecorator.php +++ b/src/Contracts/ResourceDecorator.php @@ -10,7 +10,7 @@ interface ResourceDecorator { /** - * @param Response|BaseResource|BaseCollection|LazyCollection $resource + * @param Response|BaseResource|BaseCollection|LazyCollection $resource */ public static function fromResource($resource): self; } diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index d08b126e3..dd1d824bb 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -39,8 +39,7 @@ public function getHydratableResource() } /** - * @param string|DecorateResource $hydratableResource - * @return self + * @param string|DecorateResource $hydratableResource */ public function setHydratableResource($hydratableResource): self { @@ -49,7 +48,7 @@ public function setHydratableResource($hydratableResource): self } if ($hydratableResource instanceof DecorateResource && ! $hydratableResource->getDecorator()) { - throw new \InvalidArgumentException("The decorator class is not set."); + throw new \InvalidArgumentException('The decorator class is not set.'); } $this->customHydratableResource = $hydratableResource; diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index e17d5b43e..1c8e6e426 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -3,8 +3,8 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\Connector; -use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Contracts\EmbeddedResourcesContract; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\Http\Response; @@ -61,9 +61,7 @@ public static function createBaseResourceCollection( /** * Create a decorated resource from a response or existing resource. * - * @param Response|BaseResource|BaseCollection|LazyCollection $response - * @param string $decorator - * @return ResourceDecorator + * @param Response|BaseResource|BaseCollection|LazyCollection $response */ public static function createDecoratedResource($response, string $decorator): ResourceDecorator { diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 879233443..453bada34 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -2,17 +2,17 @@ namespace Tests\Resources; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\AnyResource; +use Mollie\Api\Resources\BaseCollection; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\Onboarding; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\ResourceFactory; -use Mollie\Api\Contracts\ResourceDecorator; -use Mollie\Api\Resources\BaseCollection; use PHPUnit\Framework\TestCase; class ResourceFactoryTest extends TestCase @@ -128,7 +128,7 @@ public function embedded_resources_are_type_casted() /** @test */ public function it_throws_exception_when_response_is_missing() { - $apiResult = new \stdClass(); + $apiResult = new \stdClass; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Response is required'); @@ -190,7 +190,7 @@ public function it_creates_base_resource_collection() $response = $this->createMock(Response::class); $data = [ ['id' => 'payment-1', 'resource' => 'payment'], - ['id' => 'payment-2', 'resource' => 'payment'] + ['id' => 'payment-2', 'resource' => 'payment'], ]; $collection = ResourceFactory::createBaseResourceCollection( @@ -211,7 +211,7 @@ public function it_creates_base_resource_collection_with_custom_collection_class { $response = $this->createMock(Response::class); $data = [ - ['id' => 'payment-1', 'resource' => 'payment'] + ['id' => 'payment-1', 'resource' => 'payment'], ]; $collection = ResourceFactory::createBaseResourceCollection( @@ -289,8 +289,11 @@ class CustomPaymentCollection extends BaseCollection class CustomResourceDecorator implements ResourceDecorator { public string $status; + public bool $canReceivePayments; + public bool $canReceiveSettlements; + public string $dashboardUrl; public function __construct( diff --git a/tests/Resources/ResourceHydratorTest.php b/tests/Resources/ResourceHydratorTest.php index 4c8116544..dc2072144 100644 --- a/tests/Resources/ResourceHydratorTest.php +++ b/tests/Resources/ResourceHydratorTest.php @@ -6,27 +6,28 @@ use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; +use Mollie\Api\MollieApiClient; +use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\CursorCollection; use Mollie\Api\Resources\DecorateResource; -use Mollie\Api\Resources\ResourceHydrator; -use Mollie\Api\MollieApiClient; -use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceCollection; +use Mollie\Api\Resources\ResourceHydrator; use Mollie\Api\Traits\IsIteratableRequest; use PHPUnit\Framework\TestCase; class ResourceHydratorTest extends TestCase { private ResourceHydrator $hydrator; + private MollieApiClient $client; protected function setUp(): void { parent::setUp(); - $this->hydrator = new ResourceHydrator(); + $this->hydrator = new ResourceHydrator; $this->client = $this->createMock(MollieApiClient::class); } @@ -57,7 +58,8 @@ public function hydrate_collection(): void $request = $this->createMock(ResourceHydratableRequest::class); $response = $this->createMock(Response::class); - $mockCollection = new class($this->client, $response) extends ResourceCollection { + $mockCollection = new class($this->client, $response) extends ResourceCollection + { public static string $resource = AnyResource::class; public static string $collectionName = 'items'; @@ -73,9 +75,9 @@ public function hydrate_collection(): void $response->expects($this->once()) ->method('json') - ->willReturn((object)[ - '_embedded' => (object)['items' => []], - '_links' => (object)[] + ->willReturn((object) [ + '_embedded' => (object) ['items' => []], + '_links' => (object) [], ]); $result = $this->hydrator->hydrate($request, $response); @@ -106,14 +108,14 @@ public function hydrate_iteratable_collection(): void $response->expects($this->once()) ->method('json') - ->willReturn((object)[ - '_embedded' => (object)['items' => [ - (object)[ + ->willReturn((object) [ + '_embedded' => (object) ['items' => [ + (object) [ 'id' => 'id', 'foo' => 'bar', - ] + ], ]], - '_links' => (object)[] + '_links' => (object) [], ]); $result = $this->hydrator->hydrate($request, $response); @@ -187,6 +189,6 @@ class CustomDecorator implements ResourceDecorator { public static function fromResource($resource): self { - return new self(); + return new self; } } From 109e989451fa0315085b1c6952ddc61c1fbd848f Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:06:08 +0100 Subject: [PATCH 121/131] wip --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index bb38e898d..fb2fce4e7 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,6 @@ "brianium/paratest": "^6.11", "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", - "laravel/pint": "^1.18", "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.6" }, From 55d3425487039419c20f2fcf57017fcb453969d3 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:08:45 +0100 Subject: [PATCH 122/131] wip --- .github/workflows/fix-codestyle.yml | 2 +- .github/workflows/tests.yml | 3 --- composer.json | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/fix-codestyle.yml b/.github/workflows/fix-codestyle.yml index 367de127c..66be903f0 100644 --- a/.github/workflows/fix-codestyle.yml +++ b/.github/workflows/fix-codestyle.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.3] + php: [8.4] steps: - name: Checkout code diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8f356a39a..fac5d3f5b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,9 +22,6 @@ jobs: extensions: dom, curl, libxml, mbstring, zip tools: composer:v2 coverage: none - - name: Remove PHP CS Fixer dependency to prevent unnecessary dependency collisions - run: | - composer remove --dev friendsofphp/php-cs-fixer - name: Install dependencies run: | composer update --prefer-dist --no-interaction --no-progress diff --git a/composer.json b/composer.json index fb2fce4e7..46cd65ccc 100644 --- a/composer.json +++ b/composer.json @@ -58,8 +58,8 @@ }, "require-dev": { "brianium/paratest": "^6.11", - "friendsofphp/php-cs-fixer": "^3.39", "guzzlehttp/guzzle": "^7.6", + "laravel/pint": "^1.18", "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.6" }, @@ -82,6 +82,6 @@ }, "scripts": { "test": "./vendor/bin/phpunit tests", - "format": "./vendor/bin/php-cs-fixer fix --allow-risky=yes" + "format": "./vendor/bin/pint" } } From 94918f1ef80631194cc6b4a49cb7b56fbef0acf8 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:20:23 +0100 Subject: [PATCH 123/131] wip --- phpstan-baseline.neon | 12 ++++++++++++ src/Http/Requests/ResourceHydratableRequest.php | 8 ++------ src/Resources/DecorateResource.php | 10 +++++++++- src/Resources/ResourceHydrator.php | 3 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 792c7ec6f..b2a24ffa8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -372,6 +372,18 @@ parameters: count: 1 path: tests/Http/Middleware/GuardResponseTest.php + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\AnyResource\:\:\$customField\.$#' + identifier: property.notFound + count: 1 + path: tests/Resources/ResourceFactoryTest.php + + - + message: '#^Access to an undefined property Mollie\\Api\\Resources\\AnyResource\:\:\$id\.$#' + identifier: property.notFound + count: 1 + path: tests/Resources/ResourceFactoryTest.php + - message: '#^Property Tests\\Utils\\TestPropertiesClass\:\:\$privateProp is unused\.$#' identifier: property.unused diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index dd1d824bb..701fc4b24 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -19,7 +19,7 @@ abstract class ResourceHydratableRequest extends Request * * @var string|null|DecorateResource */ - protected ?string $customHydratableResource = null; + protected $customHydratableResource = null; public function isHydratable(): bool { @@ -39,7 +39,7 @@ public function getHydratableResource() } /** - * @param string|DecorateResource $hydratableResource + * @param string|DecorateResource $hydratableResource */ public function setHydratableResource($hydratableResource): self { @@ -47,10 +47,6 @@ public function setHydratableResource($hydratableResource): self throw new \InvalidArgumentException("The resource class '{$hydratableResource}' does not exist."); } - if ($hydratableResource instanceof DecorateResource && ! $hydratableResource->getDecorator()) { - throw new \InvalidArgumentException('The decorator class is not set.'); - } - $this->customHydratableResource = $hydratableResource; return $this; diff --git a/src/Resources/DecorateResource.php b/src/Resources/DecorateResource.php index a8ec0da0d..97125ecaa 100644 --- a/src/Resources/DecorateResource.php +++ b/src/Resources/DecorateResource.php @@ -10,9 +10,13 @@ class DecorateResource protected ?string $decorator = null; - public function __construct(string $decoratedResource) + public function __construct(string $decoratedResource, ?string $decorator = null) { $this->decoratedResource = $decoratedResource; + + if ($decorator) { + $this->with($decorator); + } } public function with(string $decorator): self @@ -33,6 +37,10 @@ public function getDecoratedResource(): string public function getDecorator(): ?string { + if (! $this->decorator) { + throw new \InvalidArgumentException('The decorator class is not set.'); + } + return $this->decorator; } } diff --git a/src/Resources/ResourceHydrator.php b/src/Resources/ResourceHydrator.php index bbe9e9ab6..fa0851d81 100644 --- a/src/Resources/ResourceHydrator.php +++ b/src/Resources/ResourceHydrator.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\IsIteratable; +use Mollie\Api\Contracts\ResourceDecorator; use Mollie\Api\Http\Request; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; @@ -12,7 +13,7 @@ class ResourceHydrator /** * Hydrate a response into a resource or collection * - * @return Response|BaseResource|BaseCollection|LazyCollection + * @return Response|BaseResource|BaseCollection|LazyCollection|ResourceDecorator */ public function hydrate(ResourceHydratableRequest $request, Response $response) { From 9d3ed6781ef22b8fb9ead94a0aa06492b298e66f Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 18 Dec 2024 11:20:57 +0000 Subject: [PATCH 124/131] Fixes coding style --- src/Http/Requests/ResourceHydratableRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index 701fc4b24..51bbfb856 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -39,7 +39,7 @@ public function getHydratableResource() } /** - * @param string|DecorateResource $hydratableResource + * @param string|DecorateResource $hydratableResource */ public function setHydratableResource($hydratableResource): self { From 1fa13dd46ff46f4af733ccc1495f644a368d1c02 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:21:15 +0100 Subject: [PATCH 125/131] wip --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fac5d3f5b..c9b246124 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,9 @@ jobs: extensions: dom, curl, libxml, mbstring, zip tools: composer:v2 coverage: none + - name: Remove pint dependency to prevent unnecessary dependency collisions + run: | + composer remove --dev laravel/pint - name: Install dependencies run: | composer update --prefer-dist --no-interaction --no-progress From 539fa62216f994be215381a76acc6dd7c46a1fe9 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:25:22 +0100 Subject: [PATCH 126/131] wip --- src/Contracts/PayloadRepository.php | 5 ++++- src/Repositories/JsonPayloadRepository.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Contracts/PayloadRepository.php b/src/Contracts/PayloadRepository.php index 3ad024ee3..1964bc1a0 100644 --- a/src/Contracts/PayloadRepository.php +++ b/src/Contracts/PayloadRepository.php @@ -21,7 +21,10 @@ public function remove(string $key): self; public function add(string $key, $value): self; - public function get(string $key, $default = null): mixed; + /** + * @return mixed + */ + public function get(string $key, $default = null); public function merge(array ...$arrays): self; diff --git a/src/Repositories/JsonPayloadRepository.php b/src/Repositories/JsonPayloadRepository.php index ff98caa39..34d53f666 100644 --- a/src/Repositories/JsonPayloadRepository.php +++ b/src/Repositories/JsonPayloadRepository.php @@ -37,7 +37,10 @@ public function add(string $key, $value): self return $this; } - public function get(string $key, $default = null): mixed + /** + * @return mixed + */ + public function get(string $key, $default = null) { return $this->store[$key] ?? $default; } From 953ae1aace2b8a07b1e6826d1a79d7a6a525c3a4 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 12:42:50 +0100 Subject: [PATCH 127/131] wip --- .../{ResourceDecorator.php => IsWrapper.php} | 2 +- .../Requests/ResourceHydratableRequest.php | 8 ++-- src/Resources/DecorateResource.php | 16 +++---- src/Resources/ResourceFactory.php | 12 ++--- src/Resources/ResourceHydrator.php | 8 ++-- src/Resources/ResourceWrapper.php | 25 ++++++++++ src/Resources/WrapResource.php | 46 +++++++++++++++++++ src/Traits/ForwardsCalls.php | 44 ++++++++++++++++++ tests/Resources/ResourceFactoryTest.php | 6 +-- tests/Resources/ResourceHydratorTest.php | 8 ++-- 10 files changed, 145 insertions(+), 30 deletions(-) rename src/Contracts/{ResourceDecorator.php => IsWrapper.php} (92%) create mode 100644 src/Resources/ResourceWrapper.php create mode 100644 src/Resources/WrapResource.php create mode 100644 src/Traits/ForwardsCalls.php diff --git a/src/Contracts/ResourceDecorator.php b/src/Contracts/IsWrapper.php similarity index 92% rename from src/Contracts/ResourceDecorator.php rename to src/Contracts/IsWrapper.php index c74d3e652..0eef5d3ae 100644 --- a/src/Contracts/ResourceDecorator.php +++ b/src/Contracts/IsWrapper.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\LazyCollection; -interface ResourceDecorator +interface IsWrapper { /** * @param Response|BaseResource|BaseCollection|LazyCollection $resource diff --git a/src/Http/Requests/ResourceHydratableRequest.php b/src/Http/Requests/ResourceHydratableRequest.php index 51bbfb856..a62a7821a 100644 --- a/src/Http/Requests/ResourceHydratableRequest.php +++ b/src/Http/Requests/ResourceHydratableRequest.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Http\Request; -use Mollie\Api\Resources\DecorateResource; +use Mollie\Api\Resources\WrapResource; abstract class ResourceHydratableRequest extends Request { @@ -17,7 +17,7 @@ abstract class ResourceHydratableRequest extends Request /** * The custom resource class the request should be hydrated into. * - * @var string|null|DecorateResource + * @var string|null|WrapResource */ protected $customHydratableResource = null; @@ -27,7 +27,7 @@ public function isHydratable(): bool } /** - * @return string|DecorateResource + * @return string|WrapResource */ public function getHydratableResource() { @@ -39,7 +39,7 @@ public function getHydratableResource() } /** - * @param string|DecorateResource $hydratableResource + * @param string|WrapResource $hydratableResource */ public function setHydratableResource($hydratableResource): self { diff --git a/src/Resources/DecorateResource.php b/src/Resources/DecorateResource.php index 97125ecaa..2a3a53941 100644 --- a/src/Resources/DecorateResource.php +++ b/src/Resources/DecorateResource.php @@ -2,17 +2,17 @@ namespace Mollie\Api\Resources; -use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Contracts\IsWrapper; -class DecorateResource +class WrapResource { - protected string $decoratedResource; + protected string $wrappedResource; protected ?string $decorator = null; public function __construct(string $decoratedResource, ?string $decorator = null) { - $this->decoratedResource = $decoratedResource; + $this->wrappedResource = $decoratedResource; if ($decorator) { $this->with($decorator); @@ -21,7 +21,7 @@ public function __construct(string $decoratedResource, ?string $decorator = null public function with(string $decorator): self { - if (! is_subclass_of($decorator, ResourceDecorator::class)) { + if (! is_subclass_of($decorator, IsWrapper::class)) { throw new \InvalidArgumentException("The decorator class '{$decorator}' does not implement the DecoratedResource interface."); } @@ -30,12 +30,12 @@ public function with(string $decorator): self return $this; } - public function getDecoratedResource(): string + public function getWrappedResource(): string { - return $this->decoratedResource; + return $this->wrappedResource; } - public function getDecorator(): ?string + public function getWrapper(): ?string { if (! $this->decorator) { throw new \InvalidArgumentException('The decorator class is not set.'); diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 1c8e6e426..a10980974 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -4,7 +4,7 @@ use Mollie\Api\Contracts\Connector; use Mollie\Api\Contracts\EmbeddedResourcesContract; -use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Contracts\IsWrapper; use Mollie\Api\Exceptions\EmbeddedResourcesNotParseableException; use Mollie\Api\Http\Response; @@ -63,9 +63,9 @@ public static function createBaseResourceCollection( * * @param Response|BaseResource|BaseCollection|LazyCollection $response */ - public static function createDecoratedResource($response, string $decorator): ResourceDecorator + public static function createDecoratedResource($response, string $decorator): IsWrapper { - if (! is_subclass_of($decorator, ResourceDecorator::class)) { + if (! is_subclass_of($decorator, IsWrapper::class)) { throw new \InvalidArgumentException("The decorator class '{$decorator}' does not implement the ResourceDecorator interface."); } @@ -96,7 +96,7 @@ private static function parseEmbeddedResources(Connector $connector, object $res if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - 'Resource '.get_class($resource)." does not have a mapping for embedded resource {$resourceKey}" + 'Resource ' . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" ); } @@ -156,7 +156,7 @@ private static function instantiateBaseCollection( private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, Response $response): array { return array_map( - fn ($item) => static::createFromApiResult( + fn($item) => static::createFromApiResult( $connector, $item, $resourceClass, @@ -168,6 +168,6 @@ private static function mapToResourceObjects(Connector $connector, $data, string private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string { - return $resourceCollectionClass ?: $resourceClass.'Collection'; + return $resourceCollectionClass ?: $resourceClass . 'Collection'; } } diff --git a/src/Resources/ResourceHydrator.php b/src/Resources/ResourceHydrator.php index fa0851d81..29735edad 100644 --- a/src/Resources/ResourceHydrator.php +++ b/src/Resources/ResourceHydrator.php @@ -3,7 +3,7 @@ namespace Mollie\Api\Resources; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Contracts\IsWrapper; use Mollie\Api\Http\Request; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; @@ -13,20 +13,20 @@ class ResourceHydrator /** * Hydrate a response into a resource or collection * - * @return Response|BaseResource|BaseCollection|LazyCollection|ResourceDecorator + * @return Response|BaseResource|BaseCollection|LazyCollection|IsWrapper */ public function hydrate(ResourceHydratableRequest $request, Response $response) { $targetResourceClass = $request->getHydratableResource(); - if ($targetResourceClass instanceof DecorateResource) { + if ($targetResourceClass instanceof WrapResource) { $response = $this->hydrate( // Reset the hydratable resource to the original resource class. $request->resetHydratableResource(), $response, ); - return ResourceFactory::createDecoratedResource($response, $targetResourceClass->getDecorator()); + return ResourceFactory::createDecoratedResource($response, $targetResourceClass->getWrapper()); } if ($this->isCollectionTarget($targetResourceClass)) { diff --git a/src/Resources/ResourceWrapper.php b/src/Resources/ResourceWrapper.php new file mode 100644 index 000000000..0d78d9316 --- /dev/null +++ b/src/Resources/ResourceWrapper.php @@ -0,0 +1,25 @@ +resource = $resource; + + return $this; + } + + public function __call($name, $arguments) + { + return $this->forwardDecoratedCallTo($this->resource, $name, $arguments); + } +} diff --git a/src/Resources/WrapResource.php b/src/Resources/WrapResource.php new file mode 100644 index 000000000..5d1d1c61d --- /dev/null +++ b/src/Resources/WrapResource.php @@ -0,0 +1,46 @@ +wrappedResource = $decoratedResource; + + if ($wrapper) { + $this->with($wrapper); + } + } + + public function with(string $wrapper): self + { + if (! is_subclass_of($wrapper, IsWrapper::class)) { + throw new \InvalidArgumentException("The wrapper class '{$wrapper}' does not implement the IsWrapper interface."); + } + + $this->wrapper = $wrapper; + + return $this; + } + + public function getWrappedResource(): string + { + return $this->wrappedResource; + } + + public function getWrapper(): ?string + { + if (! $this->wrapper) { + throw new \InvalidArgumentException('The wrapper class is not set.'); + } + + return $this->wrapper; + } +} diff --git a/src/Traits/ForwardsCalls.php b/src/Traits/ForwardsCalls.php new file mode 100644 index 000000000..50f442290 --- /dev/null +++ b/src/Traits/ForwardsCalls.php @@ -0,0 +1,44 @@ +{$method}(...$parameters); + } + + /** + * Forward a method call to the given object, returning $this if the forwarded call returned itself. + * + * @param mixed $object + * @param string $method + * @param array $parameters + * @return mixed + * + * @throws \BadMethodCallException + */ + protected function forwardDecoratedCallTo($object, $method, $parameters) + { + $result = $this->forwardCallTo($object, $method, $parameters); + + return $result === $object ? $this : $result; + } +} diff --git a/tests/Resources/ResourceFactoryTest.php b/tests/Resources/ResourceFactoryTest.php index 453bada34..972799748 100644 --- a/tests/Resources/ResourceFactoryTest.php +++ b/tests/Resources/ResourceFactoryTest.php @@ -2,7 +2,7 @@ namespace Tests\Resources; -use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Contracts\IsWrapper; use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\AnyResource; @@ -286,7 +286,7 @@ class CustomPaymentCollection extends BaseCollection // } -class CustomResourceDecorator implements ResourceDecorator +class CustomResourceDecorator implements IsWrapper { public string $status; @@ -308,7 +308,7 @@ public function __construct( $this->dashboardUrl = $dashboardUrl; } - public static function fromResource($onboarding): ResourceDecorator + public static function fromResource($onboarding): IsWrapper { /** @var Onboarding $onboarding */ return new self( diff --git a/tests/Resources/ResourceHydratorTest.php b/tests/Resources/ResourceHydratorTest.php index dc2072144..7b38caea1 100644 --- a/tests/Resources/ResourceHydratorTest.php +++ b/tests/Resources/ResourceHydratorTest.php @@ -3,14 +3,14 @@ namespace Mollie\Api\Tests\Resources; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\Contracts\ResourceDecorator; +use Mollie\Api\Contracts\IsWrapper; use Mollie\Api\Http\Requests\ResourceHydratableRequest; use Mollie\Api\Http\Response; use Mollie\Api\MollieApiClient; use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\CursorCollection; -use Mollie\Api\Resources\DecorateResource; +use Mollie\Api\Resources\WrapResource; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceCollection; use Mollie\Api\Resources\ResourceHydrator; @@ -130,7 +130,7 @@ public function hydrate_decorated_resource(): void $request = $this->createMock(ResourceHydratableRequest::class); $response = $this->createMock(Response::class); - $decoratedResource = (new DecorateResource(AnyResource::class)) + $decoratedResource = (new WrapResource(AnyResource::class)) ->with(CustomDecorator::class); $request->expects($this->exactly(2)) @@ -185,7 +185,7 @@ class CustomCollection extends CursorCollection public static string $collectionName = 'items'; } -class CustomDecorator implements ResourceDecorator +class CustomDecorator implements IsWrapper { public static function fromResource($resource): self { From df1b4b5086b8347bb2ad36233906209c13f41e20 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 18 Dec 2024 11:43:30 +0000 Subject: [PATCH 128/131] Fixes coding style --- src/Resources/ResourceFactory.php | 6 +++--- tests/Resources/ResourceHydratorTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index a10980974..f1ec9b244 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -96,7 +96,7 @@ private static function parseEmbeddedResources(Connector $connector, object $res if (is_null($collectionOrResourceClass)) { throw new EmbeddedResourcesNotParseableException( - 'Resource ' . get_class($resource) . " does not have a mapping for embedded resource {$resourceKey}" + 'Resource '.get_class($resource)." does not have a mapping for embedded resource {$resourceKey}" ); } @@ -156,7 +156,7 @@ private static function instantiateBaseCollection( private static function mapToResourceObjects(Connector $connector, $data, string $resourceClass, Response $response): array { return array_map( - fn($item) => static::createFromApiResult( + fn ($item) => static::createFromApiResult( $connector, $item, $resourceClass, @@ -168,6 +168,6 @@ private static function mapToResourceObjects(Connector $connector, $data, string private static function determineCollectionClass(string $resourceClass, ?string $resourceCollectionClass): string { - return $resourceCollectionClass ?: $resourceClass . 'Collection'; + return $resourceCollectionClass ?: $resourceClass.'Collection'; } } diff --git a/tests/Resources/ResourceHydratorTest.php b/tests/Resources/ResourceHydratorTest.php index 7b38caea1..97475746d 100644 --- a/tests/Resources/ResourceHydratorTest.php +++ b/tests/Resources/ResourceHydratorTest.php @@ -10,10 +10,10 @@ use Mollie\Api\Resources\AnyResource; use Mollie\Api\Resources\BaseResource; use Mollie\Api\Resources\CursorCollection; -use Mollie\Api\Resources\WrapResource; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\ResourceCollection; use Mollie\Api\Resources\ResourceHydrator; +use Mollie\Api\Resources\WrapResource; use Mollie\Api\Traits\IsIteratableRequest; use PHPUnit\Framework\TestCase; From 1bf7ddeec180cb107b0531b296ca60348f8445ed Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 14:12:24 +0100 Subject: [PATCH 129/131] wip --- phpstan-baseline.neon | 34 ++++++++++++++----- .../OnboardingEndpointCollection.php | 2 +- .../Fake/MockMollieClient.php | 6 ++-- .../Fake}/MockMollieHttpAdapter.php | 12 +++---- {tests/Fixtures => src/Fake}/MockResponse.php | 8 ++--- .../Fake}/Responses/apple-pay-session.json | 0 .../Fake}/Responses/balance-list.json | 0 .../Fake}/Responses/balance-report.json | 0 .../Fake}/Responses/balance-transactions.json | 0 .../Fake}/Responses/balance.json | 0 .../Fake}/Responses/capture-list.json | 0 .../Fake}/Responses/capture.json | 0 .../Fake}/Responses/chargeback-list.json | 0 .../Fake}/Responses/chargeback.json | 0 .../Fake}/Responses/client-link.json | 0 .../Fake}/Responses/client-list.json | 0 .../Fake}/Responses/client.json | 0 .../Fake}/Responses/current-profile.json | 0 .../Responses/cursor-collection-next.json | 0 .../Fake}/Responses/cursor-collection.json | 0 .../Fake}/Responses/customer-list.json | 0 .../Fake}/Responses/customer.json | 0 .../Fake}/Responses/empty-list.json | 0 .../Fake}/Responses/invoice-list.json | 0 .../Fake}/Responses/invoice.json | 0 .../Fake}/Responses/issuer.json | 0 .../Fake}/Responses/mandate-list.json | 0 .../Fake}/Responses/mandate.json | 0 .../Fake}/Responses/method-list.json | 0 .../Fake}/Responses/method.json | 0 .../Fake}/Responses/onboarding.json | 0 .../Fake}/Responses/organization.json | 0 .../Fake}/Responses/partner-status.json | 0 .../Fake}/Responses/payment-link-list.json | 0 .../Fake}/Responses/payment-link.json | 0 .../Fake}/Responses/payment-list.json | 0 .../Fake}/Responses/payment-route.json | 0 .../Fake}/Responses/payment.json | 0 .../Fake}/Responses/permission-list.json | 0 .../Fake}/Responses/permission.json | 0 .../Fake}/Responses/profile-list.json | 0 .../Fake}/Responses/profile.json | 0 .../Fake}/Responses/refund-list.json | 0 .../Fake}/Responses/refund.json | 0 .../Fake}/Responses/route.json | 0 .../Fake}/Responses/sales-invoice-list.json | 0 .../Fake}/Responses/sales-invoice.json | 0 .../Fake}/Responses/session-list.json | 0 .../Fake}/Responses/session.json | 0 .../Fake}/Responses/settlement-list.json | 0 .../Fake}/Responses/settlement.json | 0 .../Fake}/Responses/subscription-list.json | 0 .../Fake}/Responses/subscription.json | 0 .../Fake}/Responses/terminal-list.json | 0 .../Fake}/Responses/terminal.json | 0 .../unprocessable-entity-with-field.json | 0 .../Fake}/Responses/unprocessable-entity.json | 0 .../Fake}/SequenceMockResponse.php | 2 +- ...est.php => GetOnboardingStatusRequest.php} | 2 +- .../Requests/ResourceHydratableRequest.php | 4 --- src/MollieApiClient.php | 6 ++++ src/Resources/ResourceWrapper.php | 5 +++ src/Resources/WrapResource.php | 4 +-- .../BalanceEndpointCollectionTest.php | 12 +++---- .../BalanceReportEndpointCollectionTest.php | 10 +++--- ...lanceTransactionEndpointCollectionTest.php | 8 ++--- .../ChargebackEndpointCollectionTest.php | 8 ++--- .../ClientEndpointCollectionTest.php | 10 +++--- .../ClientLinkEndpointCollectionTest.php | 6 ++-- .../CustomerEndpointCollectionTest.php | 16 ++++----- ...CustomerPaymentsEndpointCollectionTest.php | 10 +++--- .../InvoiceEndpointCollectionTest.php | 10 +++--- .../MandateEndpointCollectionTest.php | 12 +++---- .../MethodEndpointCollectionTest.php | 10 +++--- .../MethodIssuerEndpointCollectionTest.php | 8 ++--- .../OnboardingEndpointCollectionTest.php | 10 +++--- .../OrganizationEndpointCollectionTest.php | 10 +++--- ...anizationPartnerEndpointCollectionTest.php | 6 ++-- .../PaymentCaptureEndpointCollectionTest.php | 12 +++---- ...aymentChargebackEndpointCollectionTest.php | 10 +++--- .../PaymentEndpointCollectionTest.php | 18 +++++----- .../PaymentLinkEndpointCollectionTest.php | 16 ++++----- ...ymentLinkPaymentEndpointCollectionTest.php | 8 ++--- .../PaymentRefundEndpointCollectionTest.php | 14 ++++---- .../PaymentRouteEndpointCollectionTest.php | 6 ++-- .../PermissionEndpointCollectionTest.php | 8 ++--- .../ProfileEndpointCollectionTest.php | 18 +++++----- .../ProfileMethodEndpointCollectionTest.php | 12 +++---- .../RefundEndpointCollectionTest.php | 8 ++--- .../SalesInvoiceEndpointCollectionTest.php | 16 ++++----- .../SessionEndpointCollectionTest.php | 16 ++++----- ...ettlementCaptureEndpointCollectionTest.php | 8 ++--- ...lementChargebackEndpointCollectionTest.php | 8 ++--- ...ettlementPaymentEndpointCollectionTest.php | 8 ++--- ...SettlementRefundEndpointCollectionTest.php | 8 ++--- .../SettlementsEndpointCollectionTest.php | 14 ++++---- .../SubscriptionEndpointCollectionTest.php | 20 +++++------ ...scriptionPaymentEndpointCollectionTest.php | 8 ++--- .../TerminalEndpointCollectionTest.php | 10 +++--- .../WalletEndpointCollectionTest.php | 6 ++-- .../Adapter/GuzzleMollieHttpAdapterTest.php | 6 ++-- .../Adapter/MollieHttpAdapterPickerTest.php | 1 + tests/Http/MiddlewareTest.php | 6 ++-- .../ApplePayPaymentSessionRequestTest.php | 6 ++-- .../CancelPaymentRefundRequestTest.php | 6 ++-- .../Requests/CancelPaymentRequestTest.php | 6 ++-- .../Requests/CancelSessionRequestTest.php | 6 ++-- .../CancelSubscriptionRequestTest.php | 6 ++-- .../Requests/CreateClientLinkRequestTest.php | 6 ++-- .../CreateCustomerPaymentRequestTest.php | 6 ++-- .../Requests/CreateCustomerRequestTest.php | 6 ++-- .../Requests/CreateMandateRequestTest.php | 6 ++-- .../CreatePaymentCaptureRequestTest.php | 6 ++-- .../Requests/CreatePaymentLinkRequestTest.php | 6 ++-- .../CreatePaymentRefundRequestTest.php | 6 ++-- .../Requests/CreatePaymentRequestTest.php | 6 ++-- .../Requests/CreateProfileRequestTest.php | 6 ++-- .../CreateSalesInvoiceRequestTest.php | 6 ++-- .../Requests/CreateSessionRequestTest.php | 6 ++-- .../CreateSubscriptionRequestTest.php | 6 ++-- .../Requests/DeleteCustomerRequestTest.php | 6 ++-- .../Requests/DeletePaymentLinkRequestTest.php | 6 ++-- .../Requests/DeleteProfileRequestTest.php | 6 ++-- .../DeleteSalesInvoiceRequestTest.php | 6 ++-- .../DisableMethodIssuerRequestTest.php | 6 ++-- .../DisableProfileMethodRequestTest.php | 6 ++-- tests/Http/Requests/DynamicGetRequestTest.php | 6 ++-- .../EnableMethodIssuerRequestTest.php | 6 ++-- .../EnableProfileMethodRequestTest.php | 6 ++-- .../Requests/GetAllMethodsRequestTest.php | 6 ++-- ...etAllPaginatedSubscriptionsRequestTest.php | 6 ++-- .../Requests/GetBalanceReportRequestTest.php | 6 ++-- tests/Http/Requests/GetBalanceRequestTest.php | 6 ++-- tests/Http/Requests/GetClientRequestTest.php | 6 ++-- .../Http/Requests/GetCustomerRequestTest.php | 6 ++-- .../Requests/GetEnabledMethodsRequestTest.php | 6 ++-- tests/Http/Requests/GetInvoiceRequestTest.php | 6 ++-- tests/Http/Requests/GetMandateRequestTest.php | 6 ++-- ...php => GetOnboardingStatusRequestTest.php} | 18 +++++----- ...etOrganizationPartnerStatusRequestTest.php | 6 ++-- .../Requests/GetOrganizationRequestTest.php | 6 ++-- .../GetPaginatedBalanceRequestTest.php | 6 ++-- ...PaginatedBalanceTransactionRequestTest.php | 6 ++-- .../GetPaginatedChargebacksRequestTest.php | 6 ++-- .../GetPaginatedClientRequestTest.php | 6 ++-- ...etPaginatedCustomerPaymentsRequestTest.php | 6 ++-- .../GetPaginatedCustomerRequestTest.php | 6 ++-- .../GetPaginatedInvoiceRequestTest.php | 6 ++-- .../GetPaginatedMandateRequestTest.php | 10 +++--- ...GetPaginatedPaymentCapturesRequestTest.php | 10 +++--- ...PaginatedPaymentChargebacksRequestTest.php | 10 +++--- ...aginatedPaymentLinkPaymentsRequestTest.php | 10 +++--- .../GetPaginatedPaymentLinksRequestTest.php | 10 +++--- .../GetPaginatedPaymentRefundsRequestTest.php | 10 +++--- .../GetPaginatedPaymentsRequestTest.php | 10 +++--- .../GetPaginatedProfilesRequestTest.php | 10 +++--- .../GetPaginatedRefundsRequestTest.php | 10 +++--- .../GetPaginatedSalesInvoicesRequestTest.php | 10 +++--- .../GetPaginatedSessionsRequestTest.php | 10 +++--- ...PaginatedSettlementCapturesRequestTest.php | 10 +++--- ...inatedSettlementChargebacksRequestTest.php | 10 +++--- ...PaginatedSettlementPaymentsRequestTest.php | 10 +++--- ...tPaginatedSettlementRefundsRequestTest.php | 10 +++--- .../GetPaginatedSettlementsRequestTest.php | 10 +++--- ...ginatedSubscriptionPaymentsRequestTest.php | 10 +++--- .../GetPaginatedSubscriptionsRequestTest.php | 10 +++--- .../GetPaginatedTerminalsRequestTest.php | 10 +++--- .../Requests/GetPaymentCaptureRequestTest.php | 6 ++-- .../GetPaymentChargebackRequestTest.php | 6 ++-- .../Requests/GetPaymentLinkRequestTest.php | 6 ++-- .../Requests/GetPaymentMethodRequestTest.php | 6 ++-- .../Requests/GetPaymentRefundRequestTest.php | 6 ++-- tests/Http/Requests/GetPaymentRequestTest.php | 6 ++-- .../Requests/GetPermissionRequestTest.php | 6 ++-- tests/Http/Requests/GetProfileRequestTest.php | 6 ++-- .../Requests/GetSalesInvoiceRequestTest.php | 6 ++-- tests/Http/Requests/GetSessionRequestTest.php | 6 ++-- .../Requests/GetSettlementRequestTest.php | 6 ++-- .../Requests/GetSubscriptionRequestTest.php | 6 ++-- .../Http/Requests/GetTerminalRequestTest.php | 6 ++-- .../Requests/ListPermissionsRequestTest.php | 6 ++-- .../Requests/RevokeMandateRequestTest.php | 6 ++-- .../Requests/UpdateCustomerRequestTest.php | 6 ++-- .../Requests/UpdatePaymentLinkRequestTest.php | 6 ++-- .../Requests/UpdatePaymentRequestTest.php | 6 ++-- .../UpdatePaymentRouteRequestTest.php | 6 ++-- .../Requests/UpdateProfileRequestTest.php | 6 ++-- .../UpdateSalesInvoiceRequestTest.php | 6 ++-- .../Requests/UpdateSessionRequestTest.php | 6 ++-- .../UpdateSubscriptionRequestTest.php | 6 ++-- tests/MollieApiClientTest.php | 30 ++++++++-------- tests/Resources/CursorCollectionTest.php | 18 +++++----- 192 files changed, 590 insertions(+), 564 deletions(-) rename tests/Fixtures/MockClient.php => src/Fake/MockMollieClient.php (84%) rename {tests/Http/Adapter => src/Fake}/MockMollieHttpAdapter.php (87%) rename {tests/Fixtures => src/Fake}/MockResponse.php (93%) rename {tests/Fixtures => src/Fake}/Responses/apple-pay-session.json (100%) rename {tests/Fixtures => src/Fake}/Responses/balance-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/balance-report.json (100%) rename {tests/Fixtures => src/Fake}/Responses/balance-transactions.json (100%) rename {tests/Fixtures => src/Fake}/Responses/balance.json (100%) rename {tests/Fixtures => src/Fake}/Responses/capture-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/capture.json (100%) rename {tests/Fixtures => src/Fake}/Responses/chargeback-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/chargeback.json (100%) rename {tests/Fixtures => src/Fake}/Responses/client-link.json (100%) rename {tests/Fixtures => src/Fake}/Responses/client-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/client.json (100%) rename {tests/Fixtures => src/Fake}/Responses/current-profile.json (100%) rename {tests/Fixtures => src/Fake}/Responses/cursor-collection-next.json (100%) rename {tests/Fixtures => src/Fake}/Responses/cursor-collection.json (100%) rename {tests/Fixtures => src/Fake}/Responses/customer-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/customer.json (100%) rename {tests/Fixtures => src/Fake}/Responses/empty-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/invoice-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/invoice.json (100%) rename {tests/Fixtures => src/Fake}/Responses/issuer.json (100%) rename {tests/Fixtures => src/Fake}/Responses/mandate-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/mandate.json (100%) rename {tests/Fixtures => src/Fake}/Responses/method-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/method.json (100%) rename {tests/Fixtures => src/Fake}/Responses/onboarding.json (100%) rename {tests/Fixtures => src/Fake}/Responses/organization.json (100%) rename {tests/Fixtures => src/Fake}/Responses/partner-status.json (100%) rename {tests/Fixtures => src/Fake}/Responses/payment-link-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/payment-link.json (100%) rename {tests/Fixtures => src/Fake}/Responses/payment-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/payment-route.json (100%) rename {tests/Fixtures => src/Fake}/Responses/payment.json (100%) rename {tests/Fixtures => src/Fake}/Responses/permission-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/permission.json (100%) rename {tests/Fixtures => src/Fake}/Responses/profile-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/profile.json (100%) rename {tests/Fixtures => src/Fake}/Responses/refund-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/refund.json (100%) rename {tests/Fixtures => src/Fake}/Responses/route.json (100%) rename {tests/Fixtures => src/Fake}/Responses/sales-invoice-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/sales-invoice.json (100%) rename {tests/Fixtures => src/Fake}/Responses/session-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/session.json (100%) rename {tests/Fixtures => src/Fake}/Responses/settlement-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/settlement.json (100%) rename {tests/Fixtures => src/Fake}/Responses/subscription-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/subscription.json (100%) rename {tests/Fixtures => src/Fake}/Responses/terminal-list.json (100%) rename {tests/Fixtures => src/Fake}/Responses/terminal.json (100%) rename {tests/Fixtures => src/Fake}/Responses/unprocessable-entity-with-field.json (100%) rename {tests/Fixtures => src/Fake}/Responses/unprocessable-entity.json (100%) rename {tests/Fixtures => src/Fake}/SequenceMockResponse.php (96%) rename src/Http/Requests/{GetOnboardingRequest.php => GetOnboardingStatusRequest.php} (82%) rename tests/Http/Requests/{GetOnboardingRequestTest.php => GetOnboardingStatusRequestTest.php} (53%) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b2a24ffa8..38c1edf35 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -270,6 +270,18 @@ parameters: count: 1 path: examples/subscriptions/update-subscription.php + - + message: '#^Unsafe access to private property Mollie\\Api\\Fake\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 + path: src/Fake/MockMollieHttpAdapter.php + + - + message: '#^Unsafe access to private property Mollie\\Api\\Fake\\MockResponse\:\:\$factories through static\:\:\.$#' + identifier: staticClassAccess.privateProperty + count: 3 + path: src/Fake/MockResponse.php + - message: '#^Unsafe usage of new static\(\)\.$#' identifier: new.static @@ -355,16 +367,22 @@ parameters: path: tests/EndpointCollection/SubscriptionEndpointCollectionTest.php - - message: '#^Unsafe access to private property Tests\\Fixtures\\MockResponse\:\:\$factories through static\:\:\.$#' - identifier: staticClassAccess.privateProperty - count: 3 - path: tests/Fixtures/MockResponse.php + message: '#^Class Tests\\Http\\Adapter\\MockMollieHttpAdapter not found\.$#' + identifier: class.notFound + count: 1 + path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php - - message: '#^Unsafe access to private property Tests\\Http\\Adapter\\MockMollieHttpAdapter\:\:\$factories through static\:\:\.$#' - identifier: staticClassAccess.privateProperty - count: 3 - path: tests/Http/Adapter/MockMollieHttpAdapter.php + message: '#^Instantiated class Tests\\Http\\Adapter\\MockMollieHttpAdapter not found\.$#' + identifier: class.notFound + count: 1 + path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php + + - + message: '#^Parameter \#1 \$httpClient of method Mollie\\Api\\Http\\Adapter\\MollieHttpAdapterPicker\:\:pickHttpAdapter\(\) expects GuzzleHttp\\ClientInterface\|Mollie\\Api\\Contracts\\HttpAdapterContract\|stdClass\|null, Tests\\Http\\Adapter\\MockMollieHttpAdapter given\.$#' + identifier: argument.type + count: 1 + path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' diff --git a/src/EndpointCollection/OnboardingEndpointCollection.php b/src/EndpointCollection/OnboardingEndpointCollection.php index 2e799522c..eabee6cd3 100644 --- a/src/EndpointCollection/OnboardingEndpointCollection.php +++ b/src/EndpointCollection/OnboardingEndpointCollection.php @@ -2,7 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Http\Requests\GetOnboardingRequest as GetOnboardingStatusRequest; +use Mollie\Api\Http\Requests\GetOnboardingStatusRequest as GetOnboardingStatusRequest; use Mollie\Api\Resources\Onboarding; class OnboardingEndpointCollection extends EndpointCollection diff --git a/tests/Fixtures/MockClient.php b/src/Fake/MockMollieClient.php similarity index 84% rename from tests/Fixtures/MockClient.php rename to src/Fake/MockMollieClient.php index c5ce8e5bf..e9a8d6492 100644 --- a/tests/Fixtures/MockClient.php +++ b/src/Fake/MockMollieClient.php @@ -1,14 +1,14 @@ expected, $requestClass)) { - throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); + throw new \RuntimeException('The request class ' . $requestClass . ' is not expected.'); } } @@ -84,7 +84,7 @@ public function recorded(?callable $callback = null): array return $this->recorded; } - return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); + return array_filter($this->recorded, fn($recorded) => $callback($recorded[0], $recorded[1])); } /** @@ -93,7 +93,7 @@ public function recorded(?callable $callback = null): array public function assertSent($callback): void { if (is_string($callback)) { - $callback = fn ($request) => get_class($request) === $callback; + $callback = fn($request) => get_class($request) === $callback; } PHPUnit::assertTrue( diff --git a/tests/Fixtures/MockResponse.php b/src/Fake/MockResponse.php similarity index 93% rename from tests/Fixtures/MockResponse.php rename to src/Fake/MockResponse.php index 7d2bde886..0ee0ee15f 100644 --- a/tests/Fixtures/MockResponse.php +++ b/src/Fake/MockResponse.php @@ -1,10 +1,10 @@ getBody(); $body->rewind(); - Assert::assertEquals( + PHPUnit::assertEquals( $body->getContents(), $this->createPsrResponse()->getBody()->getContents(), 'Response does not match' diff --git a/tests/Fixtures/Responses/apple-pay-session.json b/src/Fake/Responses/apple-pay-session.json similarity index 100% rename from tests/Fixtures/Responses/apple-pay-session.json rename to src/Fake/Responses/apple-pay-session.json diff --git a/tests/Fixtures/Responses/balance-list.json b/src/Fake/Responses/balance-list.json similarity index 100% rename from tests/Fixtures/Responses/balance-list.json rename to src/Fake/Responses/balance-list.json diff --git a/tests/Fixtures/Responses/balance-report.json b/src/Fake/Responses/balance-report.json similarity index 100% rename from tests/Fixtures/Responses/balance-report.json rename to src/Fake/Responses/balance-report.json diff --git a/tests/Fixtures/Responses/balance-transactions.json b/src/Fake/Responses/balance-transactions.json similarity index 100% rename from tests/Fixtures/Responses/balance-transactions.json rename to src/Fake/Responses/balance-transactions.json diff --git a/tests/Fixtures/Responses/balance.json b/src/Fake/Responses/balance.json similarity index 100% rename from tests/Fixtures/Responses/balance.json rename to src/Fake/Responses/balance.json diff --git a/tests/Fixtures/Responses/capture-list.json b/src/Fake/Responses/capture-list.json similarity index 100% rename from tests/Fixtures/Responses/capture-list.json rename to src/Fake/Responses/capture-list.json diff --git a/tests/Fixtures/Responses/capture.json b/src/Fake/Responses/capture.json similarity index 100% rename from tests/Fixtures/Responses/capture.json rename to src/Fake/Responses/capture.json diff --git a/tests/Fixtures/Responses/chargeback-list.json b/src/Fake/Responses/chargeback-list.json similarity index 100% rename from tests/Fixtures/Responses/chargeback-list.json rename to src/Fake/Responses/chargeback-list.json diff --git a/tests/Fixtures/Responses/chargeback.json b/src/Fake/Responses/chargeback.json similarity index 100% rename from tests/Fixtures/Responses/chargeback.json rename to src/Fake/Responses/chargeback.json diff --git a/tests/Fixtures/Responses/client-link.json b/src/Fake/Responses/client-link.json similarity index 100% rename from tests/Fixtures/Responses/client-link.json rename to src/Fake/Responses/client-link.json diff --git a/tests/Fixtures/Responses/client-list.json b/src/Fake/Responses/client-list.json similarity index 100% rename from tests/Fixtures/Responses/client-list.json rename to src/Fake/Responses/client-list.json diff --git a/tests/Fixtures/Responses/client.json b/src/Fake/Responses/client.json similarity index 100% rename from tests/Fixtures/Responses/client.json rename to src/Fake/Responses/client.json diff --git a/tests/Fixtures/Responses/current-profile.json b/src/Fake/Responses/current-profile.json similarity index 100% rename from tests/Fixtures/Responses/current-profile.json rename to src/Fake/Responses/current-profile.json diff --git a/tests/Fixtures/Responses/cursor-collection-next.json b/src/Fake/Responses/cursor-collection-next.json similarity index 100% rename from tests/Fixtures/Responses/cursor-collection-next.json rename to src/Fake/Responses/cursor-collection-next.json diff --git a/tests/Fixtures/Responses/cursor-collection.json b/src/Fake/Responses/cursor-collection.json similarity index 100% rename from tests/Fixtures/Responses/cursor-collection.json rename to src/Fake/Responses/cursor-collection.json diff --git a/tests/Fixtures/Responses/customer-list.json b/src/Fake/Responses/customer-list.json similarity index 100% rename from tests/Fixtures/Responses/customer-list.json rename to src/Fake/Responses/customer-list.json diff --git a/tests/Fixtures/Responses/customer.json b/src/Fake/Responses/customer.json similarity index 100% rename from tests/Fixtures/Responses/customer.json rename to src/Fake/Responses/customer.json diff --git a/tests/Fixtures/Responses/empty-list.json b/src/Fake/Responses/empty-list.json similarity index 100% rename from tests/Fixtures/Responses/empty-list.json rename to src/Fake/Responses/empty-list.json diff --git a/tests/Fixtures/Responses/invoice-list.json b/src/Fake/Responses/invoice-list.json similarity index 100% rename from tests/Fixtures/Responses/invoice-list.json rename to src/Fake/Responses/invoice-list.json diff --git a/tests/Fixtures/Responses/invoice.json b/src/Fake/Responses/invoice.json similarity index 100% rename from tests/Fixtures/Responses/invoice.json rename to src/Fake/Responses/invoice.json diff --git a/tests/Fixtures/Responses/issuer.json b/src/Fake/Responses/issuer.json similarity index 100% rename from tests/Fixtures/Responses/issuer.json rename to src/Fake/Responses/issuer.json diff --git a/tests/Fixtures/Responses/mandate-list.json b/src/Fake/Responses/mandate-list.json similarity index 100% rename from tests/Fixtures/Responses/mandate-list.json rename to src/Fake/Responses/mandate-list.json diff --git a/tests/Fixtures/Responses/mandate.json b/src/Fake/Responses/mandate.json similarity index 100% rename from tests/Fixtures/Responses/mandate.json rename to src/Fake/Responses/mandate.json diff --git a/tests/Fixtures/Responses/method-list.json b/src/Fake/Responses/method-list.json similarity index 100% rename from tests/Fixtures/Responses/method-list.json rename to src/Fake/Responses/method-list.json diff --git a/tests/Fixtures/Responses/method.json b/src/Fake/Responses/method.json similarity index 100% rename from tests/Fixtures/Responses/method.json rename to src/Fake/Responses/method.json diff --git a/tests/Fixtures/Responses/onboarding.json b/src/Fake/Responses/onboarding.json similarity index 100% rename from tests/Fixtures/Responses/onboarding.json rename to src/Fake/Responses/onboarding.json diff --git a/tests/Fixtures/Responses/organization.json b/src/Fake/Responses/organization.json similarity index 100% rename from tests/Fixtures/Responses/organization.json rename to src/Fake/Responses/organization.json diff --git a/tests/Fixtures/Responses/partner-status.json b/src/Fake/Responses/partner-status.json similarity index 100% rename from tests/Fixtures/Responses/partner-status.json rename to src/Fake/Responses/partner-status.json diff --git a/tests/Fixtures/Responses/payment-link-list.json b/src/Fake/Responses/payment-link-list.json similarity index 100% rename from tests/Fixtures/Responses/payment-link-list.json rename to src/Fake/Responses/payment-link-list.json diff --git a/tests/Fixtures/Responses/payment-link.json b/src/Fake/Responses/payment-link.json similarity index 100% rename from tests/Fixtures/Responses/payment-link.json rename to src/Fake/Responses/payment-link.json diff --git a/tests/Fixtures/Responses/payment-list.json b/src/Fake/Responses/payment-list.json similarity index 100% rename from tests/Fixtures/Responses/payment-list.json rename to src/Fake/Responses/payment-list.json diff --git a/tests/Fixtures/Responses/payment-route.json b/src/Fake/Responses/payment-route.json similarity index 100% rename from tests/Fixtures/Responses/payment-route.json rename to src/Fake/Responses/payment-route.json diff --git a/tests/Fixtures/Responses/payment.json b/src/Fake/Responses/payment.json similarity index 100% rename from tests/Fixtures/Responses/payment.json rename to src/Fake/Responses/payment.json diff --git a/tests/Fixtures/Responses/permission-list.json b/src/Fake/Responses/permission-list.json similarity index 100% rename from tests/Fixtures/Responses/permission-list.json rename to src/Fake/Responses/permission-list.json diff --git a/tests/Fixtures/Responses/permission.json b/src/Fake/Responses/permission.json similarity index 100% rename from tests/Fixtures/Responses/permission.json rename to src/Fake/Responses/permission.json diff --git a/tests/Fixtures/Responses/profile-list.json b/src/Fake/Responses/profile-list.json similarity index 100% rename from tests/Fixtures/Responses/profile-list.json rename to src/Fake/Responses/profile-list.json diff --git a/tests/Fixtures/Responses/profile.json b/src/Fake/Responses/profile.json similarity index 100% rename from tests/Fixtures/Responses/profile.json rename to src/Fake/Responses/profile.json diff --git a/tests/Fixtures/Responses/refund-list.json b/src/Fake/Responses/refund-list.json similarity index 100% rename from tests/Fixtures/Responses/refund-list.json rename to src/Fake/Responses/refund-list.json diff --git a/tests/Fixtures/Responses/refund.json b/src/Fake/Responses/refund.json similarity index 100% rename from tests/Fixtures/Responses/refund.json rename to src/Fake/Responses/refund.json diff --git a/tests/Fixtures/Responses/route.json b/src/Fake/Responses/route.json similarity index 100% rename from tests/Fixtures/Responses/route.json rename to src/Fake/Responses/route.json diff --git a/tests/Fixtures/Responses/sales-invoice-list.json b/src/Fake/Responses/sales-invoice-list.json similarity index 100% rename from tests/Fixtures/Responses/sales-invoice-list.json rename to src/Fake/Responses/sales-invoice-list.json diff --git a/tests/Fixtures/Responses/sales-invoice.json b/src/Fake/Responses/sales-invoice.json similarity index 100% rename from tests/Fixtures/Responses/sales-invoice.json rename to src/Fake/Responses/sales-invoice.json diff --git a/tests/Fixtures/Responses/session-list.json b/src/Fake/Responses/session-list.json similarity index 100% rename from tests/Fixtures/Responses/session-list.json rename to src/Fake/Responses/session-list.json diff --git a/tests/Fixtures/Responses/session.json b/src/Fake/Responses/session.json similarity index 100% rename from tests/Fixtures/Responses/session.json rename to src/Fake/Responses/session.json diff --git a/tests/Fixtures/Responses/settlement-list.json b/src/Fake/Responses/settlement-list.json similarity index 100% rename from tests/Fixtures/Responses/settlement-list.json rename to src/Fake/Responses/settlement-list.json diff --git a/tests/Fixtures/Responses/settlement.json b/src/Fake/Responses/settlement.json similarity index 100% rename from tests/Fixtures/Responses/settlement.json rename to src/Fake/Responses/settlement.json diff --git a/tests/Fixtures/Responses/subscription-list.json b/src/Fake/Responses/subscription-list.json similarity index 100% rename from tests/Fixtures/Responses/subscription-list.json rename to src/Fake/Responses/subscription-list.json diff --git a/tests/Fixtures/Responses/subscription.json b/src/Fake/Responses/subscription.json similarity index 100% rename from tests/Fixtures/Responses/subscription.json rename to src/Fake/Responses/subscription.json diff --git a/tests/Fixtures/Responses/terminal-list.json b/src/Fake/Responses/terminal-list.json similarity index 100% rename from tests/Fixtures/Responses/terminal-list.json rename to src/Fake/Responses/terminal-list.json diff --git a/tests/Fixtures/Responses/terminal.json b/src/Fake/Responses/terminal.json similarity index 100% rename from tests/Fixtures/Responses/terminal.json rename to src/Fake/Responses/terminal.json diff --git a/tests/Fixtures/Responses/unprocessable-entity-with-field.json b/src/Fake/Responses/unprocessable-entity-with-field.json similarity index 100% rename from tests/Fixtures/Responses/unprocessable-entity-with-field.json rename to src/Fake/Responses/unprocessable-entity-with-field.json diff --git a/tests/Fixtures/Responses/unprocessable-entity.json b/src/Fake/Responses/unprocessable-entity.json similarity index 100% rename from tests/Fixtures/Responses/unprocessable-entity.json rename to src/Fake/Responses/unprocessable-entity.json diff --git a/tests/Fixtures/SequenceMockResponse.php b/src/Fake/SequenceMockResponse.php similarity index 96% rename from tests/Fixtures/SequenceMockResponse.php rename to src/Fake/SequenceMockResponse.php index 7e4fad96c..a6c0f16a1 100644 --- a/tests/Fixtures/SequenceMockResponse.php +++ b/src/Fake/SequenceMockResponse.php @@ -1,6 +1,6 @@ customHydratableResource = $hydratableResource; return $this; diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index cc4913140..cb71df6e8 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -43,6 +43,7 @@ use Mollie\Api\EndpointCollection\SubscriptionPaymentEndpointCollection; use Mollie\Api\EndpointCollection\TerminalEndpointCollection; use Mollie\Api\EndpointCollection\WalletEndpointCollection; +use Mollie\Api\Fake\MockMollieClient; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator; use Mollie\Api\Traits\HandlesAuthentication; @@ -170,6 +171,11 @@ public function resolveBaseUrl(): string return Url::join($this->apiEndpoint, self::API_VERSION); } + public static function fake(array $expectedResponses = []): MockMollieClient + { + return new MockMollieClient($expectedResponses); + } + public function __serialize(): array { return [ diff --git a/src/Resources/ResourceWrapper.php b/src/Resources/ResourceWrapper.php index 0d78d9316..3a1588325 100644 --- a/src/Resources/ResourceWrapper.php +++ b/src/Resources/ResourceWrapper.php @@ -18,6 +18,11 @@ public function setResource($resource): static return $this; } + public function __get($name) + { + return $this->resource->{$name}; + } + public function __call($name, $arguments) { return $this->forwardDecoratedCallTo($this->resource, $name, $arguments); diff --git a/src/Resources/WrapResource.php b/src/Resources/WrapResource.php index 5d1d1c61d..a3d659414 100644 --- a/src/Resources/WrapResource.php +++ b/src/Resources/WrapResource.php @@ -10,9 +10,9 @@ class WrapResource protected ?string $wrapper = null; - public function __construct(string $decoratedResource, ?string $wrapper = null) + public function __construct(string $wrappedResource, ?string $wrapper = null) { - $this->wrappedResource = $decoratedResource; + $this->wrappedResource = $wrappedResource; if ($wrapper) { $this->with($wrapper); diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index ce68a85f7..a3e141ae8 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -10,8 +10,8 @@ use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; @@ -23,7 +23,7 @@ class BalanceEndpointCollectionTest extends TestCase /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceRequest::class => new MockResponse(200, 'balance'), ]); @@ -39,7 +39,7 @@ public function get() /** @test */ public function primary() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceRequest::class => new MockResponse(200, 'balance'), ]); @@ -55,7 +55,7 @@ public function primary() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), ]); @@ -97,7 +97,7 @@ public function page() /** @test */ public function iterate() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'balances'), ]); diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index 20a4edf35..d1f6ca219 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -9,8 +9,8 @@ use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; @@ -22,7 +22,7 @@ class BalanceReportEndpointCollectionTest extends TestCase /** @test */ public function get_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_gVMhHKqSSRYJyPsuoPNFH'), ]); @@ -39,7 +39,7 @@ public function get_for_id() /** @test */ public function get_for_balance() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_gVMhHKqSSRYJyPsuoPNFH'), ]); @@ -59,7 +59,7 @@ public function get_for_balance() /** @test */ public function get_for_primary() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceReportRequest::class => new MockResponse(200, 'balance-report', 'bal_primary'), ]); diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 8bb1d1d83..808c43939 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class BalanceTransactionEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceTransactionRequest::class => new MockResponse(200, 'balance-transactions'), ]); @@ -41,7 +41,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceTransactionRequest::class => new MockResponse(200, 'balance-transactions'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'balance_transactions'), ]); diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index e0bd131ce..547579a85 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ChargebackEndpointCollectionTest extends TestCase { /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); @@ -33,7 +33,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php index b6dc3c9a1..53c78adbb 100644 --- a/tests/EndpointCollection/ClientEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ClientEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetClientRequest::class => new MockResponse(200, 'client'), ]); @@ -29,7 +29,7 @@ public function get() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), ]); @@ -47,7 +47,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'clients'), ]); diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index 0b53dfbb7..7d02fa4e6 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ClientLinkEndpointCollectionTest extends TestCase { /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateClientLinkRequest::class => new MockResponse(201, 'client-link'), ]); diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php index 3afcdc31c..57c777a9f 100644 --- a/tests/EndpointCollection/CustomerEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -11,15 +11,15 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CustomerEndpointCollectionTest extends TestCase { /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateCustomerRequest::class => new MockResponse(201, 'customer'), ]); @@ -35,7 +35,7 @@ public function create() /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetCustomerRequest::class => new MockResponse(200, 'customer'), ]); @@ -48,7 +48,7 @@ public function get() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateCustomerRequest::class => new MockResponse(200, 'customer'), ]); @@ -64,7 +64,7 @@ public function update() /** @test */ public function delete() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteCustomerRequest::class => new MockResponse(204), ]); @@ -77,7 +77,7 @@ public function delete() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), ]); @@ -95,7 +95,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'customers'), ]); diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 7953e0280..b70842d8f 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -12,15 +12,15 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CustomerPaymentsEndpointCollectionTest extends TestCase { /** @test */ public function create_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateCustomerPaymentRequest::class => new MockResponse(201, 'payment'), ]); @@ -43,7 +43,7 @@ public function create_for() /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -67,7 +67,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php index ff041c269..3bb5f485c 100644 --- a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class InvoiceEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetInvoiceRequest::class => new MockResponse(200, 'invoice'), ]); @@ -29,7 +29,7 @@ public function get() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), ]); @@ -46,7 +46,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'invoices'), ]); diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 072b58016..521383206 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -13,15 +13,15 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class MandateEndpointCollectionTest extends TestCase { /** @test */ public function create_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateMandateRequest::class => new MockResponse(201, 'mandate'), ]); @@ -48,7 +48,7 @@ public function create_for() /** @test */ public function get_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetMandateRequest::class => new MockResponse(200, 'mandate'), ]); @@ -67,7 +67,7 @@ public function get_for() /** @test */ public function revoke_for() { - $client = new MockClient([ + $client = new MockMollieClient([ RevokeMandateRequest::class => new MockResponse(204), ]); @@ -86,7 +86,7 @@ public function revoke_for() /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), ]); diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php index d0967eacf..24b3668f5 100644 --- a/tests/EndpointCollection/MethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class MethodEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentMethodRequest::class => new MockResponse(200, 'method', 'ideal'), ]); @@ -29,7 +29,7 @@ public function get() /** @test */ public function all() { - $client = new MockClient([ + $client = new MockMollieClient([ GetAllMethodsRequest::class => new MockResponse(200, 'method-list'), ]); @@ -51,7 +51,7 @@ public function all() /** @test */ public function all_enabled() { - $client = new MockClient([ + $client = new MockMollieClient([ GetEnabledMethodsRequest::class => new MockResponse(200, 'method-list'), ]); diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php index 33876aa7e..2e722441d 100644 --- a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class MethodIssuerEndpointCollectionTest extends TestCase { /** @test */ public function enable() { - $client = new MockClient([ + $client = new MockMollieClient([ EnableMethodIssuerRequest::class => new MockResponse(200, 'issuer'), ]); @@ -32,7 +32,7 @@ public function enable() /** @test */ public function disable() { - $client = new MockClient([ + $client = new MockMollieClient([ DisableMethodIssuerRequest::class => new MockResponse(204), ]); diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php index af290fc3c..ce340f967 100644 --- a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -2,19 +2,19 @@ namespace Tests\EndpointCollection; -use Mollie\Api\Http\Requests\GetOnboardingRequest; +use Mollie\Api\Http\Requests\GetOnboardingStatusRequest; use Mollie\Api\Resources\Onboarding; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class OnboardingEndpointCollectionTest extends TestCase { /** @test */ public function status() { - $client = new MockClient([ - GetOnboardingRequest::class => new MockResponse(200, 'onboarding'), + $client = new MockMollieClient([ + GetOnboardingStatusRequest::class => new MockResponse(200, 'onboarding'), ]); /** @var Onboarding $onboarding */ diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php index d456c4f0f..7a63f1e35 100644 --- a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class OrganizationEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationRequest::class => new MockResponse(200, 'organization', 'org_12345678'), ]); @@ -28,7 +28,7 @@ public function get() /** @test */ public function current() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationRequest::class => new MockResponse(200, 'organization'), ]); @@ -41,7 +41,7 @@ public function current() /** @test */ public function partner_status() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php index 9fd0b4f83..195fa0c33 100644 --- a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class OrganizationPartnerEndpointCollectionTest extends TestCase { /** @test */ public function status() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index 816422bdf..37b94a64e 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -11,15 +11,15 @@ use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentCaptureEndpointCollectionTest extends TestCase { /** @test */ public function create_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentCaptureRequest::class => new MockResponse(201, 'capture'), ]); @@ -35,7 +35,7 @@ public function create_for_id() /** @test */ public function get_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentCaptureRequest::class => new MockResponse(200, 'capture'), ]); @@ -48,7 +48,7 @@ public function get_for_id() /** @test */ public function page_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); @@ -65,7 +65,7 @@ public function page_for_id() /** @test */ public function iterator_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'captures'), ]); diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index c94c5cbf8..326ef1fe6 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentChargebackEndpointCollectionTest extends TestCase { /** @test */ public function get_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentChargebackRequest::class => new MockResponse(200, 'chargeback'), ]); @@ -29,7 +29,7 @@ public function get_for_id() /** @test */ public function page_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); @@ -48,7 +48,7 @@ public function page_for_id() /** @test */ public function iterator_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index e48b626c5..71d2a8a3d 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -18,15 +18,15 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentEndpointCollectionTest extends TestCase { /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRequest::class => new MockResponse(201, 'payment'), ]); @@ -44,7 +44,7 @@ public function create() /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentRequest::class => new MockResponse(200, 'payment'), ]); @@ -57,7 +57,7 @@ public function get() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentRequest::class => new MockResponse(200, 'payment'), ]); @@ -73,7 +73,7 @@ public function update() /** @test */ public function cancel() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelPaymentRequest::class => new MockResponse(204), ]); @@ -85,7 +85,7 @@ public function cancel() /** @test */ public function refund() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), ]); @@ -111,7 +111,7 @@ public function refund() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -130,7 +130,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index 2fe3a8b2a..52e41e592 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -15,15 +15,15 @@ use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentLinkEndpointCollectionTest extends TestCase { /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentLinkRequest::class => new MockResponse(201, 'payment-link'), ]); @@ -44,7 +44,7 @@ public function create() /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentLinkRequest::class => new MockResponse(200, 'payment-link'), ]); @@ -57,7 +57,7 @@ public function get() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentLinkRequest::class => new MockResponse(200, 'payment-link'), ]); @@ -72,7 +72,7 @@ public function update() /** @test */ public function delete() { - $client = new MockClient([ + $client = new MockMollieClient([ DeletePaymentLinkRequest::class => new MockResponse(204), ]); @@ -85,7 +85,7 @@ public function delete() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), ]); @@ -104,7 +104,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payment_links'), ]); diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php index 86f7abd2d..939196298 100644 --- a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentLinkPaymentEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -33,7 +33,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index 2c7653a91..caeec6265 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -12,15 +12,15 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentRefundEndpointCollectionTest extends TestCase { /** @test */ public function create_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), ]); @@ -45,7 +45,7 @@ public function create_for() /** @test */ public function get_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentRefundRequest::class => new MockResponse(200, 'refund'), ]); @@ -64,7 +64,7 @@ public function get_for() /** @test */ public function cancel_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelPaymentRefundRequest::class => new MockResponse(204), ]); @@ -83,7 +83,7 @@ public function cancel_for() /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -108,7 +108,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php index a8aea41bc..82971548e 100644 --- a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PaymentRouteEndpointCollectionTest extends TestCase { /** @test */ public function update_release_date_for() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentRouteRequest::class => new MockResponse(200, 'route'), ]); diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php index a9b54f43a..655dbbdd6 100644 --- a/tests/EndpointCollection/PermissionEndpointCollectionTest.php +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class PermissionEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPermissionRequest::class => new MockResponse(200, 'permission'), ]); @@ -28,7 +28,7 @@ public function get() /** @test */ public function list() { - $client = new MockClient([ + $client = new MockMollieClient([ ListPermissionsRequest::class => new MockResponse(200, 'permission-list'), ]); diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index 155b3eae8..223e7cff3 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -13,15 +13,15 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ProfileEndpointCollectionTest extends TestCase { /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateProfileRequest::class => new MockResponse(201, 'profile'), ]); @@ -40,7 +40,7 @@ public function create() /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetProfileRequest::class => new MockResponse(200, 'profile'), ]); @@ -53,7 +53,7 @@ public function get() /** @test */ public function get_current() { - $client = new MockClient([ + $client = new MockMollieClient([ GetProfileRequest::class => new MockResponse(200, 'current-profile'), ]); @@ -66,7 +66,7 @@ public function get_current() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateProfileRequest::class => new MockResponse(200, 'profile'), ]); @@ -82,7 +82,7 @@ public function update() /** @test */ public function delete() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteProfileRequest::class => new MockResponse(204), ]); @@ -95,7 +95,7 @@ public function delete() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), ]); @@ -114,7 +114,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'profiles'), ]); diff --git a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php index 90853bd6f..9d692a56b 100644 --- a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ProfileMethodEndpointCollectionTest extends TestCase { /** @test */ public function enable_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ EnableProfileMethodRequest::class => new MockResponse(200, 'method', 'ideal'), ]); @@ -27,7 +27,7 @@ public function enable_for_id() /** @test */ public function enable() { - $client = new MockClient([ + $client = new MockMollieClient([ EnableProfileMethodRequest::class => new MockResponse(200, 'method', 'ideal'), ]); @@ -40,7 +40,7 @@ public function enable() /** @test */ public function disable_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ DisableProfileMethodRequest::class => new MockResponse(204), ]); @@ -53,7 +53,7 @@ public function disable_for_id() /** @test */ public function disable() { - $client = new MockClient([ + $client = new MockMollieClient([ DisableProfileMethodRequest::class => new MockResponse(204), ]); diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php index d59b54412..6423d6d85 100644 --- a/tests/EndpointCollection/RefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class RefundEndpointCollectionTest extends TestCase { /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -33,7 +33,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index 6ff7abbb0..a5dcb03f4 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -22,15 +22,15 @@ use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SalesInvoiceEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSalesInvoiceRequest::class => new MockResponse(200, 'sales-invoice'), ]); @@ -42,7 +42,7 @@ public function get() /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSalesInvoiceRequest::class => new MockResponse(201, 'sales-invoice'), ]); @@ -83,7 +83,7 @@ public function create() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSalesInvoiceRequest::class => new MockResponse(200, 'sales-invoice'), ]); @@ -99,7 +99,7 @@ public function update() /** @test */ public function delete() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteSalesInvoiceRequest::class => new MockResponse(204), ]); @@ -111,7 +111,7 @@ public function delete() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), ]); @@ -123,7 +123,7 @@ public function page() /** @test */ public function iterate() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'sales_invoices'), ]); diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index 741511523..3b2f26c29 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -13,15 +13,15 @@ use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SessionEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSessionRequest::class => new MockResponse(200, 'session'), ]); @@ -34,7 +34,7 @@ public function get() /** @test */ public function create() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSessionRequest::class => new MockResponse(201, 'session'), ]); @@ -50,7 +50,7 @@ public function create() /** @test */ public function update() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSessionRequest::class => new MockResponse(200, 'session'), ]); @@ -65,7 +65,7 @@ public function update() /** @test */ public function cancel() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelSessionRequest::class => new MockResponse(204), ]); @@ -78,7 +78,7 @@ public function cancel() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), ]); @@ -96,7 +96,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'sessions'), ]); diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index b22d5c567..d2fcdd9d1 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SettlementCaptureEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); @@ -41,7 +41,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'captures'), ]); diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index f588baf6e..0dec42b2a 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SettlementChargebackEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); @@ -41,7 +41,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'chargebacks'), ]); diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php index 9fdea5874..1dfb36a29 100644 --- a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SettlementPaymentEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -38,7 +38,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index 597bd94b1..09513d896 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SettlementRefundEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -41,7 +41,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'refunds'), ]); diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php index 15432d762..173fb5b27 100644 --- a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SettlementsEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSettlementRequest::class => new MockResponse(200, 'settlement'), ]); @@ -29,7 +29,7 @@ public function get() /** @test */ public function next() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSettlementRequest::class => new MockResponse(200, 'settlement'), ]); @@ -42,7 +42,7 @@ public function next() /** @test */ public function open() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSettlementRequest::class => new MockResponse(200, 'settlement'), ]); @@ -55,7 +55,7 @@ public function open() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), ]); @@ -73,7 +73,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'settlements'), ]); diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 2fbe24f57..5c659e261 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -14,15 +14,15 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SubscriptionEndpointCollectionTest extends TestCase { /** @test */ public function create_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSubscriptionRequest::class => new MockResponse(201, 'subscription'), ]); @@ -46,7 +46,7 @@ public function create_for() /** @test */ public function get_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); @@ -62,7 +62,7 @@ public function get_for() /** @test */ public function update_for() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); @@ -84,7 +84,7 @@ public function update_for() /** @test */ public function cancel_for() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelSubscriptionRequest::class => new MockResponse(204), ]); @@ -100,7 +100,7 @@ public function cancel_for() /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); @@ -122,7 +122,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), ]); @@ -138,7 +138,7 @@ public function iterator_for() /** @test */ public function all_for_id() { - $client = new MockClient([ + $client = new MockMollieClient([ GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); @@ -160,7 +160,7 @@ public function all_for_id() /** @test */ public function iterator_for_all() { - $client = new MockClient([ + $client = new MockMollieClient([ GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'subscriptions'), ]); diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php index 4eafcb13b..53f6595b6 100644 --- a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -9,15 +9,15 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class SubscriptionPaymentEndpointCollectionTest extends TestCase { /** @test */ public function page_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -42,7 +42,7 @@ public function page_for() /** @test */ public function iterator_for() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'payments'), ]); diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index a26497fca..9f2b2b1e3 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class TerminalEndpointCollectionTest extends TestCase { /** @test */ public function get() { - $client = new MockClient([ + $client = new MockMollieClient([ GetTerminalRequest::class => new MockResponse(200, 'terminal'), ]); @@ -29,7 +29,7 @@ public function get() /** @test */ public function page() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'terminals'), ]); @@ -48,7 +48,7 @@ public function page() /** @test */ public function iterator() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), DynamicGetRequest::class => new MockResponse(200, 'empty-list', 'terminals'), ]); diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index 49c565582..426aef129 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class WalletEndpointCollectionTest extends TestCase { /** @test */ public function request_apple_pay_payment_session() { - $client = new MockClient([ + $client = new MockMollieClient([ ApplePayPaymentSessionRequest::class => new MockResponse(200, 'apple-pay-session'), ]); diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index e79b4c895..3f9b254bc 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -11,7 +11,7 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; -use Tests\Fixtures\MockClient; +use Mollie\Api\Fake\MockMollieClient; class GuzzleMollieHttpAdapterTest extends TestCase { @@ -47,7 +47,7 @@ public function when_debugging_an_api_exception_includes_the_request() $adapter->enableDebugging(); $request = new DynamicGetRequest('https://api.mollie.com/v2/payments'); - $pendingRequest = new PendingRequest(new MockClient, $request); + $pendingRequest = new PendingRequest(new MockMollieClient, $request); try { $adapter->sendRequest($pendingRequest); @@ -75,7 +75,7 @@ public function when_not_debugging_an_api_exception_is_excluded_from_the_request $this->assertFalse($adapter->debuggingIsActive()); $request = new DynamicGetRequest('https://api.mollie.com/v2/payments'); - $pendingRequest = new PendingRequest(new MockClient, $request); + $pendingRequest = new PendingRequest(new MockMollieClient, $request); try { $adapter->sendRequest($pendingRequest); diff --git a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php index 73ed55e79..672e75859 100644 --- a/tests/Http/Adapter/MollieHttpAdapterPickerTest.php +++ b/tests/Http/Adapter/MollieHttpAdapterPickerTest.php @@ -4,6 +4,7 @@ use GuzzleHttp\Client as GuzzleClient; use Mollie\Api\Exceptions\UnrecognizedClientException; +use Mollie\Api\Fake\MockMollieHttpAdapter; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\Adapter\MollieHttpAdapterPicker; use PHPUnit\Framework\TestCase; diff --git a/tests/Http/MiddlewareTest.php b/tests/Http/MiddlewareTest.php index 2efc9d71d..16d0d3fbd 100644 --- a/tests/Http/MiddlewareTest.php +++ b/tests/Http/MiddlewareTest.php @@ -7,7 +7,7 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; +use Mollie\Api\Fake\MockMollieClient; class MiddlewareTest extends TestCase { @@ -25,7 +25,7 @@ public function it_can_add_request_middleware_and_execute_it(): void }); $result = $middlewareHandlers->executeOnRequest( - new PendingRequest(new MockClient, new DynamicGetRequest('')) + new PendingRequest(new MockMollieClient, new DynamicGetRequest('')) ); $this->assertEquals('Bar', $result->headers()->get('Foo')); @@ -76,7 +76,7 @@ public function it_can_merge_middleware_handlers(): void $middlewareHandlers1->merge($middlewareHandlers2); $result = $middlewareHandlers1->executeOnRequest( - new PendingRequest(new MockClient, new DynamicGetRequest('')) + new PendingRequest(new MockMollieClient, new DynamicGetRequest('')) ); $this->assertEquals('One', $result->headers()->get('Request-One')); diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php index 8e04e4936..229b27e98 100644 --- a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ApplePayPaymentSessionRequestTest extends TestCase { /** @test */ public function it_can_create_apple_pay_session() { - $client = new MockClient([ + $client = new MockMollieClient([ ApplePayPaymentSessionRequest::class => new MockResponse(200, 'apple-pay-session'), ]); diff --git a/tests/Http/Requests/CancelPaymentRefundRequestTest.php b/tests/Http/Requests/CancelPaymentRefundRequestTest.php index 1efe5a71f..ef0c76fa9 100644 --- a/tests/Http/Requests/CancelPaymentRefundRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRefundRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CancelPaymentRefundRequestTest extends TestCase { /** @test */ public function it_can_cancel_payment_refund() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelPaymentRefundRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/CancelPaymentRequestTest.php b/tests/Http/Requests/CancelPaymentRequestTest.php index 912cf971d..dba207e5a 100644 --- a/tests/Http/Requests/CancelPaymentRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CancelPaymentRequestTest extends TestCase { /** @test */ public function it_can_cancel_payment() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelPaymentRequest::class => new MockResponse(200, 'payment'), ]); diff --git a/tests/Http/Requests/CancelSessionRequestTest.php b/tests/Http/Requests/CancelSessionRequestTest.php index 99bd15e34..d596cb1fb 100644 --- a/tests/Http/Requests/CancelSessionRequestTest.php +++ b/tests/Http/Requests/CancelSessionRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CancelSessionRequestTest extends TestCase { /** @test */ public function it_can_cancel_session() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelSessionRequest::class => new MockResponse(200, 'session'), ]); diff --git a/tests/Http/Requests/CancelSubscriptionRequestTest.php b/tests/Http/Requests/CancelSubscriptionRequestTest.php index ff6e41274..e55f3ee81 100644 --- a/tests/Http/Requests/CancelSubscriptionRequestTest.php +++ b/tests/Http/Requests/CancelSubscriptionRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CancelSubscriptionRequestTest extends TestCase { /** @test */ public function it_can_cancel_subscription() { - $client = new MockClient([ + $client = new MockMollieClient([ CancelSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php index a19729c0f..0cb62a122 100644 --- a/tests/Http/Requests/CreateClientLinkRequestTest.php +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateClientLinkRequestTest extends TestCase { /** @test */ public function it_can_create_client_link() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateClientLinkRequest::class => new MockResponse(201, 'client-link'), ]); diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index fc9a22017..241d36659 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -8,15 +8,15 @@ use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateCustomerPaymentRequestTest extends TestCase { /** @test */ public function it_can_create_customer_payment() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateCustomerPaymentRequest::class => new MockResponse(201, 'payment'), ]); diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php index bebef48b9..a3d04a4f8 100644 --- a/tests/Http/Requests/CreateCustomerRequestTest.php +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\CreateCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateCustomerRequestTest extends TestCase { /** @test */ public function it_can_create_customer() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateCustomerRequest::class => new MockResponse(201, 'customer'), ]); diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php index 2f9541c73..13f64f6cd 100644 --- a/tests/Http/Requests/CreateMandateRequestTest.php +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Resources\Mandate; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateMandateRequestTest extends TestCase { /** @test */ public function it_can_create_mandate() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateMandateRequest::class => new MockResponse(201, 'mandate'), ]); diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php index 191b36cf6..059adcc93 100644 --- a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; use Mollie\Api\Resources\Capture; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreatePaymentCaptureRequestTest extends TestCase { /** @test */ public function it_can_create_payment_capture() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentCaptureRequest::class => new MockResponse(201, 'capture'), ]); diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php index 94261ce9e..c5c4f1ed5 100644 --- a/tests/Http/Requests/CreatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreatePaymentLinkRequestTest extends TestCase { /** @test */ public function it_can_create_payment_link() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentLinkRequest::class => new MockResponse(201, 'payment-link'), ]); diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php index 701b455e4..b4f4b8341 100644 --- a/tests/Http/Requests/CreatePaymentRefundRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreatePaymentRefundRequestTest extends TestCase { /** @test */ public function it_can_create_payment_refund() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRefundRequest::class => new MockResponse(201, 'refund'), ]); diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index dd1305b25..cfbb03625 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreatePaymentRequestTest extends TestCase { /** @test */ public function it_can_create_payment() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRequest::class => new MockResponse(201, 'payment'), ]); diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php index 104330147..afc0d4989 100644 --- a/tests/Http/Requests/CreateProfileRequestTest.php +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateProfileRequestTest extends TestCase { /** @test */ public function it_can_create_profile() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateProfileRequest::class => new MockResponse(201, 'profile'), ]); diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index 755713df1..54d615a6f 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -15,15 +15,15 @@ use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateSalesInvoiceRequestTest extends TestCase { /** @test */ public function it_creates_sales_invoice() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSalesInvoiceRequest::class => new MockResponse(201, 'sales-invoice'), ]); diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php index f8f1c5a5d..d5437cb04 100644 --- a/tests/Http/Requests/CreateSessionRequestTest.php +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateSessionRequestTest extends TestCase { /** @test */ public function it_can_create_session() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSessionRequest::class => new MockResponse(201, 'session'), ]); diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php index f42f164e6..619051d7a 100644 --- a/tests/Http/Requests/CreateSubscriptionRequestTest.php +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\CreateSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class CreateSubscriptionRequestTest extends TestCase { /** @test */ public function it_can_create_subscription() { - $client = new MockClient([ + $client = new MockMollieClient([ CreateSubscriptionRequest::class => new MockResponse(201, 'subscription'), ]); diff --git a/tests/Http/Requests/DeleteCustomerRequestTest.php b/tests/Http/Requests/DeleteCustomerRequestTest.php index 6748636c1..2c91ccf0f 100644 --- a/tests/Http/Requests/DeleteCustomerRequestTest.php +++ b/tests/Http/Requests/DeleteCustomerRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DeleteCustomerRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DeleteCustomerRequestTest extends TestCase { /** @test */ public function it_can_delete_customer() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteCustomerRequest::class => new MockResponse(204), ]); diff --git a/tests/Http/Requests/DeletePaymentLinkRequestTest.php b/tests/Http/Requests/DeletePaymentLinkRequestTest.php index fa2474fb3..6716f2dee 100644 --- a/tests/Http/Requests/DeletePaymentLinkRequestTest.php +++ b/tests/Http/Requests/DeletePaymentLinkRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DeletePaymentLinkRequestTest extends TestCase { /** @test */ public function it_can_delete_payment_link() { - $client = new MockClient([ + $client = new MockMollieClient([ DeletePaymentLinkRequest::class => new MockResponse(204), ]); diff --git a/tests/Http/Requests/DeleteProfileRequestTest.php b/tests/Http/Requests/DeleteProfileRequestTest.php index 55f8c102d..28fa539b7 100644 --- a/tests/Http/Requests/DeleteProfileRequestTest.php +++ b/tests/Http/Requests/DeleteProfileRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DeleteProfileRequestTest extends TestCase { /** @test */ public function it_can_delete_profile() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteProfileRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php index 4a2daeca3..ec3f31c44 100644 --- a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DeleteSalesInvoiceRequestTest extends TestCase { /** @test */ public function it_deletes_sales_invoice() { - $client = new MockClient([ + $client = new MockMollieClient([ DeleteSalesInvoiceRequest::class => new MockResponse(204), ]); diff --git a/tests/Http/Requests/DisableMethodIssuerRequestTest.php b/tests/Http/Requests/DisableMethodIssuerRequestTest.php index db4c04c11..f7eccd890 100644 --- a/tests/Http/Requests/DisableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/DisableMethodIssuerRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DisableMethodIssuerRequestTest extends TestCase { /** @test */ public function it_can_disable_method_issuer() { - $client = new MockClient([ + $client = new MockMollieClient([ DisableMethodIssuerRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/DisableProfileMethodRequestTest.php b/tests/Http/Requests/DisableProfileMethodRequestTest.php index 19b76231a..3d70c7451 100644 --- a/tests/Http/Requests/DisableProfileMethodRequestTest.php +++ b/tests/Http/Requests/DisableProfileMethodRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DisableProfileMethodRequestTest extends TestCase { /** @test */ public function it_can_disable_profile_method() { - $client = new MockClient([ + $client = new MockMollieClient([ DisableProfileMethodRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/DynamicGetRequestTest.php b/tests/Http/Requests/DynamicGetRequestTest.php index 88bb59b54..a375c4b0f 100644 --- a/tests/Http/Requests/DynamicGetRequestTest.php +++ b/tests/Http/Requests/DynamicGetRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class DynamicGetRequestTest extends TestCase { /** @test */ public function it_can_make_dynamic_get_request() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, 'payment'), ]); diff --git a/tests/Http/Requests/EnableMethodIssuerRequestTest.php b/tests/Http/Requests/EnableMethodIssuerRequestTest.php index d78fc20cf..6f221b514 100644 --- a/tests/Http/Requests/EnableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/EnableMethodIssuerRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class EnableMethodIssuerRequestTest extends TestCase { /** @test */ public function it_can_enable_method_issuer() { - $client = new MockClient([ + $client = new MockMollieClient([ EnableMethodIssuerRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/EnableProfileMethodRequestTest.php b/tests/Http/Requests/EnableProfileMethodRequestTest.php index 19c2d9e15..920387351 100644 --- a/tests/Http/Requests/EnableProfileMethodRequestTest.php +++ b/tests/Http/Requests/EnableProfileMethodRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class EnableProfileMethodRequestTest extends TestCase { /** @test */ public function it_can_enable_profile_method() { - $client = new MockClient([ + $client = new MockMollieClient([ EnableProfileMethodRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php index 6756cee4a..7a381153d 100644 --- a/tests/Http/Requests/GetAllMethodsRequestTest.php +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetAllMethodsRequest; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetAllMethodsRequestTest extends TestCase { /** @test */ public function it_can_get_all_methods() { - $client = new MockClient([ + $client = new MockMollieClient([ GetAllMethodsRequest::class => new MockResponse(200, 'method-list'), ]); diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php index a0b995241..e8767bc29 100644 --- a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetAllPaginatedSubscriptionsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_subscriptions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetAllPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index 1affd6dd0..07f496646 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\BalanceReport; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetBalanceReportRequestTest extends TestCase { /** @test */ public function it_can_get_balance_report() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceReportRequest::class => new MockResponse(200, 'balance-report'), ]); diff --git a/tests/Http/Requests/GetBalanceRequestTest.php b/tests/Http/Requests/GetBalanceRequestTest.php index 3854ee50f..926ce4c9a 100644 --- a/tests/Http/Requests/GetBalanceRequestTest.php +++ b/tests/Http/Requests/GetBalanceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetBalanceRequest; use Mollie\Api\Resources\Balance; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetBalanceRequestTest extends TestCase { /** @test */ public function it_can_get_balance() { - $client = new MockClient([ + $client = new MockMollieClient([ GetBalanceRequest::class => new MockResponse(200, 'balance'), ]); diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php index 26c8c431c..6fbf19e3a 100644 --- a/tests/Http/Requests/GetClientRequestTest.php +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Resources\Client; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetClientRequestTest extends TestCase { /** @test */ public function it_can_get_client() { - $client = new MockClient([ + $client = new MockMollieClient([ GetClientRequest::class => new MockResponse(200, 'client'), ]); diff --git a/tests/Http/Requests/GetCustomerRequestTest.php b/tests/Http/Requests/GetCustomerRequestTest.php index 36c90e9f8..9061db918 100644 --- a/tests/Http/Requests/GetCustomerRequestTest.php +++ b/tests/Http/Requests/GetCustomerRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetCustomerRequestTest extends TestCase { /** @test */ public function it_can_get_customer() { - $client = new MockClient([ + $client = new MockMollieClient([ GetCustomerRequest::class => new MockResponse(200, 'customer'), ]); diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php index b2cb2ce25..ae38f6d9d 100644 --- a/tests/Http/Requests/GetEnabledMethodsRequestTest.php +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetEnabledMethodsRequest; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetEnabledMethodsRequestTest extends TestCase { /** @test */ public function it_can_get_enabled_methods() { - $client = new MockClient([ + $client = new MockMollieClient([ GetEnabledMethodsRequest::class => new MockResponse(200, 'method-list'), ]); diff --git a/tests/Http/Requests/GetInvoiceRequestTest.php b/tests/Http/Requests/GetInvoiceRequestTest.php index 748ca5074..772bc3e43 100644 --- a/tests/Http/Requests/GetInvoiceRequestTest.php +++ b/tests/Http/Requests/GetInvoiceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetInvoiceRequest; use Mollie\Api\Resources\Invoice; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetInvoiceRequestTest extends TestCase { /** @test */ public function it_can_get_invoice() { - $client = new MockClient([ + $client = new MockMollieClient([ GetInvoiceRequest::class => new MockResponse(200, 'invoice'), ]); diff --git a/tests/Http/Requests/GetMandateRequestTest.php b/tests/Http/Requests/GetMandateRequestTest.php index 1308d3ce8..6e1cb3d9d 100644 --- a/tests/Http/Requests/GetMandateRequestTest.php +++ b/tests/Http/Requests/GetMandateRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Resources\Mandate; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetMandateRequestTest extends TestCase { /** @test */ public function it_can_get_mandate() { - $client = new MockClient([ + $client = new MockMollieClient([ GetMandateRequest::class => new MockResponse(200, 'mandate'), ]); diff --git a/tests/Http/Requests/GetOnboardingRequestTest.php b/tests/Http/Requests/GetOnboardingStatusRequestTest.php similarity index 53% rename from tests/Http/Requests/GetOnboardingRequestTest.php rename to tests/Http/Requests/GetOnboardingStatusRequestTest.php index 6acc57b41..4bd1592dd 100644 --- a/tests/Http/Requests/GetOnboardingRequestTest.php +++ b/tests/Http/Requests/GetOnboardingStatusRequestTest.php @@ -2,22 +2,22 @@ namespace Tests\Http\Requests; -use Mollie\Api\Http\Requests\GetOnboardingRequest; +use Mollie\Api\Http\Requests\GetOnboardingStatusRequest; use Mollie\Api\Resources\Onboarding; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; -class GetOnboardingRequestTest extends TestCase +class GetOnboardingStatusRequestTest extends TestCase { /** @test */ - public function it_can_get_onboarding() + public function it_can_get_onboarding_status() { - $client = new MockClient([ - GetOnboardingRequest::class => new MockResponse(200, 'onboarding'), + $client = new MockMollieClient([ + GetOnboardingStatusRequest::class => new MockResponse(200, 'onboarding'), ]); - $request = new GetOnboardingRequest; + $request = new GetOnboardingStatusRequest; /** @var Onboarding */ $onboarding = $client->send($request); @@ -29,7 +29,7 @@ public function it_can_get_onboarding() /** @test */ public function it_resolves_correct_resource_path() { - $request = new GetOnboardingRequest; + $request = new GetOnboardingStatusRequest; $this->assertEquals('onboarding/me', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php index db2e0bc62..b4c05a5f0 100644 --- a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetOrganizationPartnerStatusRequestTest extends TestCase { /** @test */ public function it_can_get_organization_partner_status() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationPartnerStatusRequest::class => new MockResponse(200, 'partner-status'), ]); diff --git a/tests/Http/Requests/GetOrganizationRequestTest.php b/tests/Http/Requests/GetOrganizationRequestTest.php index 073a82efa..99ef109d9 100644 --- a/tests/Http/Requests/GetOrganizationRequestTest.php +++ b/tests/Http/Requests/GetOrganizationRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetOrganizationRequestTest extends TestCase { /** @test */ public function it_can_get_organization() { - $client = new MockClient([ + $client = new MockMollieClient([ GetOrganizationRequest::class => new MockResponse(200, 'organization'), ]); diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php index 4d964dc49..0175fb357 100644 --- a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\BalanceCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedBalanceRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_balances() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceRequest::class => new MockResponse(200, 'balance-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php index 3e594c1d0..89460d2a0 100644 --- a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; use Mollie\Api\Resources\BalanceTransactionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedBalanceTransactionRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_balance_transactions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedBalanceTransactionRequest::class => new MockResponse(200, 'balance-transactions'), ]); diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php index 163b21299..069bbf8cc 100644 --- a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedChargebacksRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_chargebacks() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php index 89c57313c..9e6bde68f 100644 --- a/tests/Http/Requests/GetPaginatedClientRequestTest.php +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\ClientCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedClientRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_clients() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedClientRequest::class => new MockResponse(200, 'client-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php index 1c99adcb8..9a5a50897 100644 --- a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedCustomerPaymentsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_customer_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php index b1ff7c0b1..a95354cd6 100644 --- a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Resources\CustomerCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedCustomerRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_customers() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedCustomerRequest::class => new MockResponse(200, 'customer-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php index 8203bb32d..3f9bce767 100644 --- a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\InvoiceCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaginatedInvoiceRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_invoices() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedInvoiceRequest::class => new MockResponse(200, 'invoice-list'), ]); diff --git a/tests/Http/Requests/GetPaginatedMandateRequestTest.php b/tests/Http/Requests/GetPaginatedMandateRequestTest.php index b52583ade..cae8e877c 100644 --- a/tests/Http/Requests/GetPaginatedMandateRequestTest.php +++ b/tests/Http/Requests/GetPaginatedMandateRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedMandateRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_mandates() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), ]); @@ -38,7 +38,7 @@ public function it_can_get_paginated_mandates() /** @test */ public function it_can_iterate_over_mandates() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedMandateRequest::class => new MockResponse(200, 'mandate-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'mandate-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php index f2908f542..1d1ade6c4 100644 --- a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentCapturesRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_captures() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); @@ -38,7 +38,7 @@ public function it_can_get_paginated_captures() /** @test */ public function it_can_iterate_over_captures() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentCapturesRequest::class => new MockResponse(200, 'capture-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'capture-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php index cc1b4c76e..c5be6fbfb 100644 --- a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentChargebacksRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_chargebacks() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); @@ -38,7 +38,7 @@ public function it_can_get_paginated_chargebacks() /** @test */ public function it_can_iterate_over_chargebacks() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'chargeback-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php index d009fd469..80430f092 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentLinkPaymentsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_payment_link_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -39,7 +39,7 @@ public function it_can_get_paginated_payment_link_payments() /** @test */ public function it_can_iterate_over_payment_link_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinkPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'payment-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php index 893b614a2..f03d32605 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentLinksRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_payment_links() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), ]); @@ -36,7 +36,7 @@ public function it_can_get_paginated_payment_links() /** @test */ public function it_can_iterate_over_payment_links() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentLinksRequest::class => new MockResponse(200, 'payment-link-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'payment-link-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php index 1e2ddec37..9be9a943e 100644 --- a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentRefundsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -35,7 +35,7 @@ public function it_can_get_paginated_refunds() /** @test */ public function it_can_iterate_over_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'refund-list'), diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index 58c13ccd2..f742c0a71 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -9,16 +9,16 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -42,7 +42,7 @@ public function it_can_get_paginated_payments() /** @test */ public function it_can_iterate_over_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'payment-list'), diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php index 3b55d6d3c..e46d91196 100644 --- a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedProfilesRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_profiles() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), ]); @@ -36,7 +36,7 @@ public function it_can_get_paginated_profiles() /** @test */ public function it_can_iterate_over_profiles() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedProfilesRequest::class => new MockResponse(200, 'profile-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'profile-list'), diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php index 5367fbc0c..7e875f6ab 100644 --- a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedRefundsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -36,7 +36,7 @@ public function it_can_get_paginated_refunds() /** @test */ public function it_can_iterate_over_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'refund-list'), diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php index 7d4a61c5d..7ffbd257f 100644 --- a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Resources\SalesInvoiceCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSalesInvoicesRequestTest extends TestCase { /** @test */ public function it_gets_paginated_sales_invoices() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), ]); @@ -35,7 +35,7 @@ public function it_gets_paginated_sales_invoices() /** @test */ public function it_can_iterate_over_sales_invoices() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSalesInvoicesRequest::class => new MockResponse(200, 'sales-invoice-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'sales-invoice-list'), diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php index 4ac570edc..47977f004 100644 --- a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSessionsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_sessions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), ]); @@ -37,7 +37,7 @@ public function it_can_get_paginated_sessions() /** @test */ public function it_can_iterate_over_sessions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSessionsRequest::class => new MockResponse(200, 'session-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'session-list'), diff --git a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php index cc5c8dda0..bbfb0fdf5 100644 --- a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementCapturesRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_settlement_captures() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), ]); @@ -37,7 +37,7 @@ public function it_can_get_paginated_settlement_captures() /** @test */ public function it_can_iterate_over_settlement_captures() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementCapturesRequest::class => new MockResponse(200, 'capture-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'capture-list'), diff --git a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php index a1b34e160..6a61f0300 100644 --- a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php @@ -7,16 +7,16 @@ use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\LazyCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementChargebacksRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_settlement_chargebacks() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), ]); @@ -36,7 +36,7 @@ public function it_can_get_paginated_settlement_chargebacks() /** @test */ public function it_can_iterate_over_settlement_chargebacks() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementChargebacksRequest::class => new MockResponse(200, 'chargeback-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'chargeback-list'), diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php index eb95c4429..352eebd1e 100644 --- a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementPaymentsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_settlement_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -40,7 +40,7 @@ public function it_can_get_paginated_settlement_payments() /** @test */ public function it_can_iterate_over_settlement_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'payment-list'), diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php index ea4a795bb..98879d744 100644 --- a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementRefundsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_settlement_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), ]); @@ -40,7 +40,7 @@ public function it_can_get_paginated_settlement_refunds() /** @test */ public function it_can_iterate_over_settlement_refunds() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementRefundsRequest::class => new MockResponse(200, 'refund-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'refund-list'), diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php index 6b17960c4..a135606d3 100644 --- a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_settlements() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), ]); @@ -39,7 +39,7 @@ public function it_can_get_paginated_settlements() /** @test */ public function it_can_iterate_over_settlements() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSettlementsRequest::class => new MockResponse(200, 'settlement-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'settlement-list'), diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index 016fa8435..05dc94c78 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -9,16 +9,16 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSubscriptionPaymentsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_subscription_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), ]); @@ -40,7 +40,7 @@ public function it_can_get_paginated_subscription_payments() /** @test */ public function it_can_iterate_over_subscription_payments() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionPaymentsRequest::class => new MockResponse(200, 'payment-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'payment-list'), diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php index a550f36b8..4cfa04fc0 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSubscriptionsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_subscriptions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), ]); @@ -39,7 +39,7 @@ public function it_can_get_paginated_subscriptions() /** @test */ public function it_can_iterate_over_subscriptions() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedSubscriptionsRequest::class => new MockResponse(200, 'subscription-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'subscription-list'), diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php index 38b96d0ef..a134baff8 100644 --- a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedTerminalsRequestTest extends TestCase { /** @test */ public function it_can_get_paginated_terminals() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), ]); @@ -37,7 +37,7 @@ public function it_can_get_paginated_terminals() /** @test */ public function it_can_iterate_over_terminals() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaginatedTerminalsRequest::class => new MockResponse(200, 'terminal-list'), DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'terminal-list'), diff --git a/tests/Http/Requests/GetPaymentCaptureRequestTest.php b/tests/Http/Requests/GetPaymentCaptureRequestTest.php index 77cba3311..ef45e7b60 100644 --- a/tests/Http/Requests/GetPaymentCaptureRequestTest.php +++ b/tests/Http/Requests/GetPaymentCaptureRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Resources\Capture; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentCaptureRequestTest extends TestCase { /** @test */ public function it_can_get_payment_capture() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentCaptureRequest::class => new MockResponse(200, 'capture'), ]); diff --git a/tests/Http/Requests/GetPaymentChargebackRequestTest.php b/tests/Http/Requests/GetPaymentChargebackRequestTest.php index 4022cdab0..4c61356ac 100644 --- a/tests/Http/Requests/GetPaymentChargebackRequestTest.php +++ b/tests/Http/Requests/GetPaymentChargebackRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentChargebackRequestTest extends TestCase { /** @test */ public function it_can_get_payment_chargeback() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentChargebackRequest::class => new MockResponse(200, 'chargeback'), ]); diff --git a/tests/Http/Requests/GetPaymentLinkRequestTest.php b/tests/Http/Requests/GetPaymentLinkRequestTest.php index cfe937893..c61daf4a3 100644 --- a/tests/Http/Requests/GetPaymentLinkRequestTest.php +++ b/tests/Http/Requests/GetPaymentLinkRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentLinkRequestTest extends TestCase { /** @test */ public function it_can_get_payment_link() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentLinkRequest::class => new MockResponse(200, 'payment-link'), ]); diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php index 78941a3e7..767db6377 100644 --- a/tests/Http/Requests/GetPaymentMethodRequestTest.php +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentMethodRequestTest extends TestCase { /** @test */ public function it_can_get_payment_method() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentMethodRequest::class => new MockResponse(200, 'method'), ]); diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php index c250225b0..4b7b3a681 100644 --- a/tests/Http/Requests/GetPaymentRefundRequestTest.php +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentRefundRequestTest extends TestCase { /** @test */ public function it_can_get_payment_refund() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentRefundRequest::class => new MockResponse(200, 'refund'), ]); diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php index 10767ac64..08de4b860 100644 --- a/tests/Http/Requests/GetPaymentRequestTest.php +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPaymentRequestTest extends TestCase { /** @test */ public function it_can_get_payment() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPaymentRequest::class => new MockResponse(200, 'payment'), ]); diff --git a/tests/Http/Requests/GetPermissionRequestTest.php b/tests/Http/Requests/GetPermissionRequestTest.php index 0e295314f..9b9614ab4 100644 --- a/tests/Http/Requests/GetPermissionRequestTest.php +++ b/tests/Http/Requests/GetPermissionRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Resources\Permission; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetPermissionRequestTest extends TestCase { /** @test */ public function it_can_get_permission() { - $client = new MockClient([ + $client = new MockMollieClient([ GetPermissionRequest::class => new MockResponse(200, 'permission'), ]); diff --git a/tests/Http/Requests/GetProfileRequestTest.php b/tests/Http/Requests/GetProfileRequestTest.php index 49f74a760..3db95ec43 100644 --- a/tests/Http/Requests/GetProfileRequestTest.php +++ b/tests/Http/Requests/GetProfileRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetProfileRequestTest extends TestCase { /** @test */ public function it_can_get_profile() { - $client = new MockClient([ + $client = new MockMollieClient([ GetProfileRequest::class => new MockResponse(200, 'profile'), ]); diff --git a/tests/Http/Requests/GetSalesInvoiceRequestTest.php b/tests/Http/Requests/GetSalesInvoiceRequestTest.php index 830117779..a48df8de4 100644 --- a/tests/Http/Requests/GetSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/GetSalesInvoiceRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetSalesInvoiceRequest; use Mollie\Api\Resources\SalesInvoice; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetSalesInvoiceRequestTest extends TestCase { /** @test */ public function it_fetches_sales_invoice() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSalesInvoiceRequest::class => new MockResponse(200, 'sales-invoice'), ]); diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php index 4bd5ba655..a075a6d56 100644 --- a/tests/Http/Requests/GetSessionRequestTest.php +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\GetSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetSessionRequestTest extends TestCase { /** @test */ public function it_can_get_session() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSessionRequest::class => new MockResponse(200, 'session'), ]); diff --git a/tests/Http/Requests/GetSettlementRequestTest.php b/tests/Http/Requests/GetSettlementRequestTest.php index 98512a221..a1b11f359 100644 --- a/tests/Http/Requests/GetSettlementRequestTest.php +++ b/tests/Http/Requests/GetSettlementRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetSettlementRequestTest extends TestCase { /** @test */ public function it_can_get_settlement() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSettlementRequest::class => new MockResponse(200, 'settlement'), ]); diff --git a/tests/Http/Requests/GetSubscriptionRequestTest.php b/tests/Http/Requests/GetSubscriptionRequestTest.php index e32efcac4..e23e3e626 100644 --- a/tests/Http/Requests/GetSubscriptionRequestTest.php +++ b/tests/Http/Requests/GetSubscriptionRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetSubscriptionRequestTest extends TestCase { /** @test */ public function it_can_get_subscription() { - $client = new MockClient([ + $client = new MockMollieClient([ GetSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); diff --git a/tests/Http/Requests/GetTerminalRequestTest.php b/tests/Http/Requests/GetTerminalRequestTest.php index 353f0b310..eb38fcd71 100644 --- a/tests/Http/Requests/GetTerminalRequestTest.php +++ b/tests/Http/Requests/GetTerminalRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\Terminal; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class GetTerminalRequestTest extends TestCase { /** @test */ public function it_can_get_terminal() { - $client = new MockClient([ + $client = new MockMollieClient([ GetTerminalRequest::class => new MockResponse(200, 'terminal'), ]); diff --git a/tests/Http/Requests/ListPermissionsRequestTest.php b/tests/Http/Requests/ListPermissionsRequestTest.php index 265b50919..1fe0db17d 100644 --- a/tests/Http/Requests/ListPermissionsRequestTest.php +++ b/tests/Http/Requests/ListPermissionsRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class ListPermissionsRequestTest extends TestCase { /** @test */ public function it_can_list_permissions() { - $client = new MockClient([ + $client = new MockMollieClient([ ListPermissionsRequest::class => new MockResponse(200, 'permission-list'), ]); diff --git a/tests/Http/Requests/RevokeMandateRequestTest.php b/tests/Http/Requests/RevokeMandateRequestTest.php index 4ce0b57ce..1e69cf4ec 100644 --- a/tests/Http/Requests/RevokeMandateRequestTest.php +++ b/tests/Http/Requests/RevokeMandateRequestTest.php @@ -5,15 +5,15 @@ use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class RevokeMandateRequestTest extends TestCase { /** @test */ public function it_can_revoke_mandate() { - $client = new MockClient([ + $client = new MockMollieClient([ RevokeMandateRequest::class => new MockResponse(204, ''), ]); diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php index 2f5a931ec..9e3ad9f2d 100644 --- a/tests/Http/Requests/UpdateCustomerRequestTest.php +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdateCustomerRequestTest extends TestCase { /** @test */ public function it_can_update_customer() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateCustomerRequest::class => new MockResponse(200, 'customer'), ]); diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php index ec77806c3..c80f77d3e 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdatePaymentLinkRequestTest extends TestCase { /** @test */ public function it_can_update_payment_link() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentLinkRequest::class => new MockResponse(200, 'payment-link'), ]); diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php index 20886b492..4c3530889 100644 --- a/tests/Http/Requests/UpdatePaymentRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdatePaymentRequestTest extends TestCase { /** @test */ public function it_can_update_payment() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentRequest::class => new MockResponse(200, 'payment'), ]); diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php index 8abf047df..1bc8f649a 100644 --- a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdatePaymentRouteRequestTest extends TestCase { /** @test */ public function it_can_update_payment_route() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdatePaymentRouteRequest::class => new MockResponse(200, 'route'), ]); diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php index 868b22a92..75be6f18c 100644 --- a/tests/Http/Requests/UpdateProfileRequestTest.php +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdateProfileRequestTest extends TestCase { /** @test */ public function it_can_update_profile() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateProfileRequest::class => new MockResponse(200, 'profile'), ]); diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index 8ea9a01d1..e288a3e1d 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\SalesInvoiceStatus; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdateSalesInvoiceRequestTest extends TestCase { /** @test */ public function it_updates_sales_invoice() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSalesInvoiceRequest::class => new MockResponse(200, 'sales-invoice'), ]); diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index c65fa81ba..aaf75e0d0 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -6,15 +6,15 @@ use Mollie\Api\Http\Requests\UpdateSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdateSessionRequestTest extends TestCase { /** @test */ public function it_can_update_session() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSessionRequest::class => new MockResponse(200, 'session'), ]); diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index 7daa11628..ee6aaabb4 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -7,15 +7,15 @@ use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; class UpdateSubscriptionRequestTest extends TestCase { /** @test */ public function it_can_update_subscription() { - $client = new MockClient([ + $client = new MockMollieClient([ UpdateSubscriptionRequest::class => new MockResponse(200, 'subscription'), ]); diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index 7b3e548c4..8b9f61bf0 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -17,8 +17,8 @@ use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; use PHPUnit\Framework\TestCase; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Requests\DynamicDeleteRequest; use Tests\Fixtures\Requests\DynamicGetRequest; @@ -27,7 +27,7 @@ class MollieApiClientTest extends TestCase /** @test */ public function send_returns_body_as_object() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), ]); @@ -46,7 +46,7 @@ public function send_creates_api_exception_correctly() $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); $this->expectExceptionCode(422); - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => $mockResponse = new MockResponse(422, 'unprocessable-entity-with-field'), ]); @@ -69,7 +69,7 @@ public function send_creates_api_exception_without_field_and_documentation_url() $this->expectExceptionMessage('Error executing API call (422: Unprocessable Entity): Non-existent parameter "recurringType" for this API call. Did you mean: "sequenceType"?'); $this->expectExceptionCode(422); - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => $mockResponse = new MockResponse(422, 'unprocessable-entity'), ]); @@ -135,7 +135,7 @@ public function disabling_debugging_throws_an_exception_if_http_adapter_does_not /** @test */ public function correct_request_headers() { - $client = new MockClient([ + $client = new MockMollieClient([ CreatePaymentRequest::class => new MockResponse(200, '{"resource": "payment"}'), ]); @@ -170,7 +170,7 @@ public function correct_request_headers() /** @test */ public function no_content_type_without_provided_body() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(204, ''), ]); @@ -183,7 +183,7 @@ public function no_content_type_without_provided_body() /** @test */ public function no_idempotency_is_set_if_no_key_nor_generator_are_set() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicDeleteRequest::class => new MockResponse(204, ''), ]); @@ -202,7 +202,7 @@ public function no_idempotency_is_set_if_no_key_nor_generator_are_set() */ public function idempotency_key_is_used_on_mutating_requests($request, $response) { - $client = new MockClient([ + $client = new MockMollieClient([ get_class($request) => $response, ]); @@ -240,7 +240,7 @@ public static function providesMutatingRequests(): array /** @test */ public function idempotency_key_is_not_used_on_get_requests() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(204), ]); @@ -254,7 +254,7 @@ public function idempotency_key_is_not_used_on_get_requests() /** @test */ public function idempotency_key_resets_after_each_request() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicDeleteRequest::class => new MockResponse(204), ]); @@ -270,7 +270,7 @@ public function idempotency_key_resets_after_each_request() /** @test */ public function it_uses_the_idempotency_key_generator() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicDeleteRequest::class => new MockResponse(204), ]); @@ -290,7 +290,7 @@ public function it_uses_the_idempotency_key_generator() /** @test */ public function testmode_is_added_to_request_when_enabled() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), ]); @@ -305,7 +305,7 @@ public function testmode_is_added_to_request_when_enabled() /** @test */ public function testmode_is_removed_when_using_api_key_authentication() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), ]); @@ -320,7 +320,7 @@ public function testmode_is_removed_when_using_api_key_authentication() /** @test */ public function testmode_is_not_removed_when_not_using_api_key_authentication() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, '{"resource": "payment"}'), ]); diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index ba7d03b9d..51320e430 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -8,16 +8,16 @@ use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; use stdClass; -use Tests\Fixtures\MockClient; -use Tests\Fixtures\MockResponse; -use Tests\Fixtures\SequenceMockResponse; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; class CursorCollectionTest extends TestCase { /** @test */ public function can_get_next_collection_result_when_next_link_is_available() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, 'cursor-collection'), ]); @@ -41,7 +41,7 @@ public function can_get_next_collection_result_when_next_link_is_available() public function test_will_return_null_if_no_next_result_is_available() { - $client = new MockClient; + $client = new MockMollieClient; $collection = new PaymentCollection( $client, @@ -56,7 +56,7 @@ public function test_will_return_null_if_no_next_result_is_available() public function test_can_get_previous_collection_result_when_previous_link_is_available() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new MockResponse(200, 'cursor-collection'), ]); @@ -80,7 +80,7 @@ public function test_can_get_previous_collection_result_when_previous_link_is_av public function test_will_return_null_if_no_previous_result_is_available() { - $client = new MockClient; + $client = new MockMollieClient; $collection = new PaymentCollection( $client, @@ -95,7 +95,7 @@ public function test_will_return_null_if_no_previous_result_is_available() public function test_auto_paginator_returns_lazy_collection() { - $client = new MockClient; + $client = new MockMollieClient; $collection = new PaymentCollection( $client, @@ -109,7 +109,7 @@ public function test_auto_paginator_returns_lazy_collection() public function test_auto_paginator_can_handle_consecutive_calls() { - $client = new MockClient([ + $client = new MockMollieClient([ DynamicGetRequest::class => new SequenceMockResponse( new MockResponse(200, 'cursor-collection-next', 'tr_stTC2WHAuF'), new MockResponse(200, 'cursor-collection-next', 'tr_stTC2WHAuS'), From db324c680ed6d877c3e4e9d9b60964989971050c Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 18 Dec 2024 14:13:17 +0100 Subject: [PATCH 130/131] wip --- phpstan-baseline.neon | 18 ------------------ tests/Http/Requests/DynamicRequestTest.php | 14 -------------- 2 files changed, 32 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 38c1edf35..3147f0c35 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -366,24 +366,6 @@ parameters: count: 1 path: tests/EndpointCollection/SubscriptionEndpointCollectionTest.php - - - message: '#^Class Tests\\Http\\Adapter\\MockMollieHttpAdapter not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php - - - - message: '#^Instantiated class Tests\\Http\\Adapter\\MockMollieHttpAdapter not found\.$#' - identifier: class.notFound - count: 1 - path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php - - - - message: '#^Parameter \#1 \$httpClient of method Mollie\\Api\\Http\\Adapter\\MollieHttpAdapterPicker\:\:pickHttpAdapter\(\) expects GuzzleHttp\\ClientInterface\|Mollie\\Api\\Contracts\\HttpAdapterContract\|stdClass\|null, Tests\\Http\\Adapter\\MockMollieHttpAdapter given\.$#' - identifier: argument.type - count: 1 - path: tests/Http/Adapter/MollieHttpAdapterPickerTest.php - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertTrue\(\) with true will always evaluate to true\.$#' identifier: method.alreadyNarrowedType diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php index 2a2ff7662..1d1327445 100644 --- a/tests/Http/Requests/DynamicRequestTest.php +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -10,20 +10,6 @@ class DynamicRequestTest extends TestCase { - /** @test */ - public function it_throws_exception_for_invalid_resource_class() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("The resource class 'NonExistentClass' does not exist."); - - $request = new class('some-url') extends DynamicRequest - { - protected static string $method = Method::GET; - }; - - $request->setHydratableResource('NonExistentClass'); - } - /** @test */ public function it_accepts_valid_resource_class() { From 529f6e5a65046b8e84a0bbf0d00e92485637f1e2 Mon Sep 17 00:00:00 2001 From: Naoray Date: Wed, 18 Dec 2024 13:14:07 +0000 Subject: [PATCH 131/131] Fixes coding style --- src/Fake/MockMollieClient.php | 1 - src/Fake/MockMollieHttpAdapter.php | 8 +++----- src/Fake/MockResponse.php | 2 +- .../EndpointCollection/BalanceEndpointCollectionTest.php | 4 ++-- .../BalanceReportEndpointCollectionTest.php | 4 ++-- .../BalanceTransactionEndpointCollectionTest.php | 4 ++-- .../ChargebackEndpointCollectionTest.php | 4 ++-- tests/EndpointCollection/ClientEndpointCollectionTest.php | 4 ++-- .../ClientLinkEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/CustomerEndpointCollectionTest.php | 4 ++-- .../CustomerPaymentsEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/InvoiceEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/MandateEndpointCollectionTest.php | 4 ++-- tests/EndpointCollection/MethodEndpointCollectionTest.php | 4 ++-- .../MethodIssuerEndpointCollectionTest.php | 4 ++-- .../OnboardingEndpointCollectionTest.php | 4 ++-- .../OrganizationEndpointCollectionTest.php | 4 ++-- .../OrganizationPartnerEndpointCollectionTest.php | 4 ++-- .../PaymentCaptureEndpointCollectionTest.php | 4 ++-- .../PaymentChargebackEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/PaymentEndpointCollectionTest.php | 4 ++-- .../PaymentLinkEndpointCollectionTest.php | 4 ++-- .../PaymentLinkPaymentEndpointCollectionTest.php | 4 ++-- .../PaymentRefundEndpointCollectionTest.php | 4 ++-- .../PaymentRouteEndpointCollectionTest.php | 4 ++-- .../PermissionEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/ProfileEndpointCollectionTest.php | 4 ++-- .../ProfileMethodEndpointCollectionTest.php | 4 ++-- tests/EndpointCollection/RefundEndpointCollectionTest.php | 4 ++-- .../SalesInvoiceEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/SessionEndpointCollectionTest.php | 4 ++-- .../SettlementCaptureEndpointCollectionTest.php | 4 ++-- .../SettlementChargebackEndpointCollectionTest.php | 4 ++-- .../SettlementPaymentEndpointCollectionTest.php | 4 ++-- .../SettlementRefundEndpointCollectionTest.php | 4 ++-- .../SettlementsEndpointCollectionTest.php | 4 ++-- .../SubscriptionEndpointCollectionTest.php | 4 ++-- .../SubscriptionPaymentEndpointCollectionTest.php | 4 ++-- .../EndpointCollection/TerminalEndpointCollectionTest.php | 4 ++-- tests/EndpointCollection/WalletEndpointCollectionTest.php | 4 ++-- tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php | 2 +- tests/Http/MiddlewareTest.php | 2 +- tests/Http/Requests/ApplePayPaymentSessionRequestTest.php | 4 ++-- tests/Http/Requests/CancelPaymentRefundRequestTest.php | 4 ++-- tests/Http/Requests/CancelPaymentRequestTest.php | 4 ++-- tests/Http/Requests/CancelSessionRequestTest.php | 4 ++-- tests/Http/Requests/CancelSubscriptionRequestTest.php | 4 ++-- tests/Http/Requests/CreateClientLinkRequestTest.php | 4 ++-- tests/Http/Requests/CreateCustomerPaymentRequestTest.php | 4 ++-- tests/Http/Requests/CreateCustomerRequestTest.php | 4 ++-- tests/Http/Requests/CreateMandateRequestTest.php | 4 ++-- tests/Http/Requests/CreatePaymentCaptureRequestTest.php | 4 ++-- tests/Http/Requests/CreatePaymentLinkRequestTest.php | 4 ++-- tests/Http/Requests/CreatePaymentRefundRequestTest.php | 4 ++-- tests/Http/Requests/CreatePaymentRequestTest.php | 4 ++-- tests/Http/Requests/CreateProfileRequestTest.php | 4 ++-- tests/Http/Requests/CreateSalesInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/CreateSessionRequestTest.php | 4 ++-- tests/Http/Requests/CreateSubscriptionRequestTest.php | 4 ++-- tests/Http/Requests/DeleteCustomerRequestTest.php | 4 ++-- tests/Http/Requests/DeletePaymentLinkRequestTest.php | 4 ++-- tests/Http/Requests/DeleteProfileRequestTest.php | 4 ++-- tests/Http/Requests/DeleteSalesInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/DisableMethodIssuerRequestTest.php | 4 ++-- tests/Http/Requests/DisableProfileMethodRequestTest.php | 4 ++-- tests/Http/Requests/DynamicGetRequestTest.php | 4 ++-- tests/Http/Requests/DynamicRequestTest.php | 1 - tests/Http/Requests/EnableMethodIssuerRequestTest.php | 4 ++-- tests/Http/Requests/EnableProfileMethodRequestTest.php | 4 ++-- tests/Http/Requests/GetAllMethodsRequestTest.php | 4 ++-- .../Requests/GetAllPaginatedSubscriptionsRequestTest.php | 4 ++-- tests/Http/Requests/GetBalanceReportRequestTest.php | 4 ++-- tests/Http/Requests/GetBalanceRequestTest.php | 4 ++-- tests/Http/Requests/GetClientRequestTest.php | 4 ++-- tests/Http/Requests/GetCustomerRequestTest.php | 4 ++-- tests/Http/Requests/GetEnabledMethodsRequestTest.php | 4 ++-- tests/Http/Requests/GetInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/GetMandateRequestTest.php | 4 ++-- tests/Http/Requests/GetOnboardingStatusRequestTest.php | 4 ++-- .../Requests/GetOrganizationPartnerStatusRequestTest.php | 4 ++-- tests/Http/Requests/GetOrganizationRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedBalanceRequestTest.php | 4 ++-- .../GetPaginatedBalanceTransactionRequestTest.php | 4 ++-- .../Http/Requests/GetPaginatedChargebacksRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedClientRequestTest.php | 4 ++-- .../Requests/GetPaginatedCustomerPaymentsRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedCustomerRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/GetPaginatedMandateRequestTest.php | 6 +++--- .../Requests/GetPaginatedPaymentCapturesRequestTest.php | 6 +++--- .../GetPaginatedPaymentChargebacksRequestTest.php | 6 +++--- .../GetPaginatedPaymentLinkPaymentsRequestTest.php | 6 +++--- .../Http/Requests/GetPaginatedPaymentLinksRequestTest.php | 6 +++--- .../Requests/GetPaginatedPaymentRefundsRequestTest.php | 6 +++--- tests/Http/Requests/GetPaginatedPaymentsRequestTest.php | 6 +++--- tests/Http/Requests/GetPaginatedProfilesRequestTest.php | 6 +++--- tests/Http/Requests/GetPaginatedRefundsRequestTest.php | 6 +++--- .../Requests/GetPaginatedSalesInvoicesRequestTest.php | 6 +++--- tests/Http/Requests/GetPaginatedSessionsRequestTest.php | 6 +++--- .../GetPaginatedSettlementCapturesRequestTest.php | 6 +++--- .../GetPaginatedSettlementChargebacksRequestTest.php | 6 +++--- .../GetPaginatedSettlementPaymentsRequestTest.php | 6 +++--- .../Requests/GetPaginatedSettlementRefundsRequestTest.php | 6 +++--- .../Http/Requests/GetPaginatedSettlementsRequestTest.php | 6 +++--- .../GetPaginatedSubscriptionPaymentsRequestTest.php | 6 +++--- .../Requests/GetPaginatedSubscriptionsRequestTest.php | 6 +++--- tests/Http/Requests/GetPaginatedTerminalsRequestTest.php | 6 +++--- tests/Http/Requests/GetPaymentCaptureRequestTest.php | 4 ++-- tests/Http/Requests/GetPaymentChargebackRequestTest.php | 4 ++-- tests/Http/Requests/GetPaymentLinkRequestTest.php | 4 ++-- tests/Http/Requests/GetPaymentMethodRequestTest.php | 4 ++-- tests/Http/Requests/GetPaymentRefundRequestTest.php | 4 ++-- tests/Http/Requests/GetPaymentRequestTest.php | 4 ++-- tests/Http/Requests/GetPermissionRequestTest.php | 4 ++-- tests/Http/Requests/GetProfileRequestTest.php | 4 ++-- tests/Http/Requests/GetSalesInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/GetSessionRequestTest.php | 4 ++-- tests/Http/Requests/GetSettlementRequestTest.php | 4 ++-- tests/Http/Requests/GetSubscriptionRequestTest.php | 4 ++-- tests/Http/Requests/GetTerminalRequestTest.php | 4 ++-- tests/Http/Requests/ListPermissionsRequestTest.php | 4 ++-- tests/Http/Requests/RevokeMandateRequestTest.php | 4 ++-- tests/Http/Requests/UpdateCustomerRequestTest.php | 4 ++-- tests/Http/Requests/UpdatePaymentLinkRequestTest.php | 4 ++-- tests/Http/Requests/UpdatePaymentRequestTest.php | 4 ++-- tests/Http/Requests/UpdatePaymentRouteRequestTest.php | 4 ++-- tests/Http/Requests/UpdateProfileRequestTest.php | 4 ++-- tests/Http/Requests/UpdateSalesInvoiceRequestTest.php | 4 ++-- tests/Http/Requests/UpdateSessionRequestTest.php | 4 ++-- tests/Http/Requests/UpdateSubscriptionRequestTest.php | 4 ++-- tests/MollieApiClientTest.php | 4 ++-- tests/Resources/CursorCollectionTest.php | 6 +++--- 132 files changed, 278 insertions(+), 282 deletions(-) diff --git a/src/Fake/MockMollieClient.php b/src/Fake/MockMollieClient.php index e9a8d6492..93fbf10dc 100644 --- a/src/Fake/MockMollieClient.php +++ b/src/Fake/MockMollieClient.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Fake; use Mollie\Api\MollieApiClient; -use Mollie\Api\Fake\MockMollieHttpAdapter; /** * @property MockMollieHttpAdapter $httpClient diff --git a/src/Fake/MockMollieHttpAdapter.php b/src/Fake/MockMollieHttpAdapter.php index a3c6be74d..337ef0e02 100644 --- a/src/Fake/MockMollieHttpAdapter.php +++ b/src/Fake/MockMollieHttpAdapter.php @@ -8,8 +8,6 @@ use Mollie\Api\Traits\HasDefaultFactories; use Mollie\Api\Utils\Arr; use PHPUnit\Framework\Assert as PHPUnit; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class MockMollieHttpAdapter implements HttpAdapterContract { @@ -52,7 +50,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response private function guardAgainstStrayRequests(string $requestClass): void { if (! Arr::has($this->expected, $requestClass)) { - throw new \RuntimeException('The request class ' . $requestClass . ' is not expected.'); + throw new \RuntimeException('The request class '.$requestClass.' is not expected.'); } } @@ -84,7 +82,7 @@ public function recorded(?callable $callback = null): array return $this->recorded; } - return array_filter($this->recorded, fn($recorded) => $callback($recorded[0], $recorded[1])); + return array_filter($this->recorded, fn ($recorded) => $callback($recorded[0], $recorded[1])); } /** @@ -93,7 +91,7 @@ public function recorded(?callable $callback = null): array public function assertSent($callback): void { if (is_string($callback)) { - $callback = fn($request) => get_class($request) === $callback; + $callback = fn ($request) => get_class($request) === $callback; } PHPUnit::assertTrue( diff --git a/src/Fake/MockResponse.php b/src/Fake/MockResponse.php index 0ee0ee15f..d9f568b9f 100644 --- a/src/Fake/MockResponse.php +++ b/src/Fake/MockResponse.php @@ -55,7 +55,7 @@ public function body(): string $path = Arr::join([ __DIR__, 'Responses', - $body . '.json', + $body.'.json', ], DIRECTORY_SEPARATOR); $contents = file_get_contents($path); diff --git a/tests/EndpointCollection/BalanceEndpointCollectionTest.php b/tests/EndpointCollection/BalanceEndpointCollectionTest.php index a3e141ae8..9998fb271 100644 --- a/tests/EndpointCollection/BalanceEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceEndpointCollectionTest.php @@ -4,14 +4,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetBalanceRequest; use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; diff --git a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php index d1f6ca219..e41d0d9ad 100644 --- a/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceReportEndpointCollectionTest.php @@ -4,13 +4,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Traits\AmountObjectTestHelpers; use Tests\Fixtures\Traits\LinkObjectTestHelpers; diff --git a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php index 808c43939..a5fb5fc3e 100644 --- a/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php +++ b/tests/EndpointCollection/BalanceTransactionEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class BalanceTransactionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php index 547579a85..88fb53b41 100644 --- a/tests/EndpointCollection/ChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/ChargebackEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientEndpointCollectionTest.php b/tests/EndpointCollection/ClientEndpointCollectionTest.php index 53c78adbb..10edcec47 100644 --- a/tests/EndpointCollection/ClientEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ClientEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index 7d02fa4e6..a5f6badff 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateClientLinkPayload; use Mollie\Api\Http\Data\Owner; use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ClientLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerEndpointCollectionTest.php b/tests/EndpointCollection/CustomerEndpointCollectionTest.php index 57c777a9f..8839cbb62 100644 --- a/tests/EndpointCollection/CustomerEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CreateCustomerRequest; use Mollie\Api\Http\Requests\DeleteCustomerRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -11,8 +13,6 @@ use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CustomerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index b70842d8f..726516a63 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; @@ -12,8 +14,6 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CustomerPaymentsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php index 3bb5f485c..8ea4a0b0a 100644 --- a/tests/EndpointCollection/InvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/InvoiceEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetInvoiceRequest; use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class InvoiceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 521383206..0d9cd6572 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -3,6 +3,8 @@ namespace Tests\EndpointCollection; use DateTimeImmutable; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Http\Requests\GetMandateRequest; @@ -13,8 +15,6 @@ use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class MandateEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MethodEndpointCollectionTest.php b/tests/EndpointCollection/MethodEndpointCollectionTest.php index 24b3668f5..43bebd309 100644 --- a/tests/EndpointCollection/MethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetAllMethodsRequest; use Mollie\Api\Http\Requests\GetEnabledMethodsRequest; use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class MethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php index 2e722441d..59044be94 100644 --- a/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php +++ b/tests/EndpointCollection/MethodIssuerEndpointCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class MethodIssuerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php index ce340f967..15b409878 100644 --- a/tests/EndpointCollection/OnboardingEndpointCollectionTest.php +++ b/tests/EndpointCollection/OnboardingEndpointCollectionTest.php @@ -2,11 +2,11 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOnboardingStatusRequest; use Mollie\Api\Resources\Onboarding; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class OnboardingEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php index 7a63f1e35..7c459e8fd 100644 --- a/tests/EndpointCollection/OrganizationEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class OrganizationEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php index 195fa0c33..6c71b2bb4 100644 --- a/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php +++ b/tests/EndpointCollection/OrganizationPartnerEndpointCollectionTest.php @@ -2,11 +2,11 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class OrganizationPartnerEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index 37b94a64e..f2ba07248 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; @@ -11,8 +13,6 @@ use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentCaptureEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php index 326ef1fe6..ea632faeb 100644 --- a/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentChargebackEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index 71d2a8a3d..12358ba5f 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\Money; @@ -18,8 +20,6 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index 52e41e592..a68de6e42 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -3,6 +3,8 @@ namespace Tests\EndpointCollection; use DateTimeImmutable; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; @@ -15,8 +17,6 @@ use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentLinkEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php index 939196298..bf1445b9b 100644 --- a/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkPaymentEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentLinkPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php index caeec6265..c7397e746 100644 --- a/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRefundEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -12,8 +14,6 @@ use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php index 82971548e..684f2c8c4 100644 --- a/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentRouteEndpointCollectionTest.php @@ -2,11 +2,11 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PaymentRouteEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/PermissionEndpointCollectionTest.php b/tests/EndpointCollection/PermissionEndpointCollectionTest.php index 655dbbdd6..ac9f33180 100644 --- a/tests/EndpointCollection/PermissionEndpointCollectionTest.php +++ b/tests/EndpointCollection/PermissionEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class PermissionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index 223e7cff3..05d542505 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; @@ -13,8 +15,6 @@ use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ProfileEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php index 9d692a56b..3a690e558 100644 --- a/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileMethodEndpointCollectionTest.php @@ -2,12 +2,12 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ProfileMethodEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/RefundEndpointCollectionTest.php b/tests/EndpointCollection/RefundEndpointCollectionTest.php index 6423d6d85..d0179a58a 100644 --- a/tests/EndpointCollection/RefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/RefundEndpointCollectionTest.php @@ -2,13 +2,13 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class RefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index a5dcb03f4..66b982653 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateSalesInvoicePayload; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\InvoiceLine; @@ -22,8 +24,6 @@ use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SalesInvoiceEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index 3b2f26c29..c757f5f10 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CancelSessionRequest; @@ -13,8 +15,6 @@ use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SessionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php index d2fcdd9d1..9ac70470b 100644 --- a/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementCaptureEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SettlementCaptureEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php index 0dec42b2a..14704a394 100644 --- a/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementChargebackEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SettlementChargebackEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php index 1dfb36a29..6a71107e8 100644 --- a/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementPaymentEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SettlementPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php index 09513d896..9f74eba26 100644 --- a/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementRefundEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SettlementRefundEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php index 173fb5b27..177980f95 100644 --- a/tests/EndpointCollection/SettlementsEndpointCollectionTest.php +++ b/tests/EndpointCollection/SettlementsEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SettlementsEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php index 5c659e261..c7721b8b4 100644 --- a/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Http\Requests\CreateSubscriptionRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -14,8 +16,6 @@ use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SubscriptionEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php index 53f6595b6..8e51d57c8 100644 --- a/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/SubscriptionPaymentEndpointCollectionTest.php @@ -2,6 +2,8 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Http\Response; @@ -9,8 +11,6 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class SubscriptionPaymentEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/TerminalEndpointCollectionTest.php b/tests/EndpointCollection/TerminalEndpointCollectionTest.php index 9f2b2b1e3..54ed931db 100644 --- a/tests/EndpointCollection/TerminalEndpointCollectionTest.php +++ b/tests/EndpointCollection/TerminalEndpointCollectionTest.php @@ -2,14 +2,14 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class TerminalEndpointCollectionTest extends TestCase { diff --git a/tests/EndpointCollection/WalletEndpointCollectionTest.php b/tests/EndpointCollection/WalletEndpointCollectionTest.php index 426aef129..b9859d03e 100644 --- a/tests/EndpointCollection/WalletEndpointCollectionTest.php +++ b/tests/EndpointCollection/WalletEndpointCollectionTest.php @@ -2,11 +2,11 @@ namespace Tests\EndpointCollection; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class WalletEndpointCollectionTest extends TestCase { diff --git a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php index 3f9b254bc..b5a3ea80f 100644 --- a/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php +++ b/tests/Http/Adapter/GuzzleMollieHttpAdapterTest.php @@ -6,12 +6,12 @@ use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Psr7\Request; use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Fake\MockMollieClient; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestInterface; -use Mollie\Api\Fake\MockMollieClient; class GuzzleMollieHttpAdapterTest extends TestCase { diff --git a/tests/Http/MiddlewareTest.php b/tests/Http/MiddlewareTest.php index 16d0d3fbd..3abadd9be 100644 --- a/tests/Http/MiddlewareTest.php +++ b/tests/Http/MiddlewareTest.php @@ -2,12 +2,12 @@ namespace Tests\Http; +use Mollie\Api\Fake\MockMollieClient; use Mollie\Api\Http\Middleware; use Mollie\Api\Http\PendingRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; class MiddlewareTest extends TestCase { diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php index 229b27e98..fa0b5f8f4 100644 --- a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\RequestApplePayPaymentSessionPayload; use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; use Mollie\Api\Resources\AnyResource; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ApplePayPaymentSessionRequestTest extends TestCase { diff --git a/tests/Http/Requests/CancelPaymentRefundRequestTest.php b/tests/Http/Requests/CancelPaymentRefundRequestTest.php index ef0c76fa9..64aaef022 100644 --- a/tests/Http/Requests/CancelPaymentRefundRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRefundRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CancelPaymentRefundRequestTest extends TestCase { diff --git a/tests/Http/Requests/CancelPaymentRequestTest.php b/tests/Http/Requests/CancelPaymentRequestTest.php index dba207e5a..5e8c64756 100644 --- a/tests/Http/Requests/CancelPaymentRequestTest.php +++ b/tests/Http/Requests/CancelPaymentRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CancelPaymentRequestTest extends TestCase { diff --git a/tests/Http/Requests/CancelSessionRequestTest.php b/tests/Http/Requests/CancelSessionRequestTest.php index d596cb1fb..b1a7a9b10 100644 --- a/tests/Http/Requests/CancelSessionRequestTest.php +++ b/tests/Http/Requests/CancelSessionRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CancelSessionRequestTest extends TestCase { diff --git a/tests/Http/Requests/CancelSubscriptionRequestTest.php b/tests/Http/Requests/CancelSubscriptionRequestTest.php index e55f3ee81..4811b81f1 100644 --- a/tests/Http/Requests/CancelSubscriptionRequestTest.php +++ b/tests/Http/Requests/CancelSubscriptionRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CancelSubscriptionRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php index 0cb62a122..5556bacb1 100644 --- a/tests/Http/Requests/CreateClientLinkRequestTest.php +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateClientLinkPayload; use Mollie\Api\Http\Data\Owner; use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; use Mollie\Api\Resources\ClientLink; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateClientLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index 241d36659..c45c70f12 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\CreatePaymentQuery; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateCustomerPaymentRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateCustomerRequestTest.php b/tests/Http/Requests/CreateCustomerRequestTest.php index a3d04a4f8..e0cc38486 100644 --- a/tests/Http/Requests/CreateCustomerRequestTest.php +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateCustomerPayload; use Mollie\Api\Http\Requests\CreateCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php index 13f64f6cd..12128468c 100644 --- a/tests/Http/Requests/CreateMandateRequestTest.php +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Http\Requests\CreateMandateRequest; use Mollie\Api\Resources\Mandate; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateMandateRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php index 059adcc93..f9eec6025 100644 --- a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; use Mollie\Api\Resources\Capture; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreatePaymentCaptureRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreatePaymentLinkRequestTest.php b/tests/Http/Requests/CreatePaymentLinkRequestTest.php index c5c4f1ed5..b87378a7b 100644 --- a/tests/Http/Requests/CreatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentLinkPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreatePaymentLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreatePaymentRefundRequestTest.php b/tests/Http/Requests/CreatePaymentRefundRequestTest.php index b4f4b8341..8355138aa 100644 --- a/tests/Http/Requests/CreatePaymentRefundRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateRefundPaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreatePaymentRefundRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreatePaymentRequestTest.php b/tests/Http/Requests/CreatePaymentRequestTest.php index cfbb03625..4fd37c92d 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreatePaymentPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreatePaymentRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateProfileRequestTest.php b/tests/Http/Requests/CreateProfileRequestTest.php index afc0d4989..8230d64b3 100644 --- a/tests/Http/Requests/CreateProfileRequestTest.php +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Http\Requests\CreateProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateProfileRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index 54d615a6f..63958193c 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -2,6 +2,8 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateSalesInvoicePayload; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\InvoiceLine; @@ -15,8 +17,6 @@ use Mollie\Api\Types\VatMode; use Mollie\Api\Types\VatScheme; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateSalesInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php index d5437cb04..c9ace7514 100644 --- a/tests/Http/Requests/CreateSessionRequestTest.php +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateSessionRequestTest extends TestCase { diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php index 619051d7a..4466257bc 100644 --- a/tests/Http/Requests/CreateSubscriptionRequestTest.php +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\CreateSubscriptionPayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreateSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class CreateSubscriptionRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeleteCustomerRequestTest.php b/tests/Http/Requests/DeleteCustomerRequestTest.php index 2c91ccf0f..f866ce527 100644 --- a/tests/Http/Requests/DeleteCustomerRequestTest.php +++ b/tests/Http/Requests/DeleteCustomerRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DeleteCustomerRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DeleteCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeletePaymentLinkRequestTest.php b/tests/Http/Requests/DeletePaymentLinkRequestTest.php index 6716f2dee..3193c896d 100644 --- a/tests/Http/Requests/DeletePaymentLinkRequestTest.php +++ b/tests/Http/Requests/DeletePaymentLinkRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DeletePaymentLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeleteProfileRequestTest.php b/tests/Http/Requests/DeleteProfileRequestTest.php index 28fa539b7..053f84662 100644 --- a/tests/Http/Requests/DeleteProfileRequestTest.php +++ b/tests/Http/Requests/DeleteProfileRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DeleteProfileRequestTest extends TestCase { diff --git a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php index ec3f31c44..e2988774e 100644 --- a/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/DeleteSalesInvoiceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DeleteSalesInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/DisableMethodIssuerRequestTest.php b/tests/Http/Requests/DisableMethodIssuerRequestTest.php index f7eccd890..dc2da205d 100644 --- a/tests/Http/Requests/DisableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/DisableMethodIssuerRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DisableMethodIssuerRequestTest extends TestCase { diff --git a/tests/Http/Requests/DisableProfileMethodRequestTest.php b/tests/Http/Requests/DisableProfileMethodRequestTest.php index 3d70c7451..5184c0f31 100644 --- a/tests/Http/Requests/DisableProfileMethodRequestTest.php +++ b/tests/Http/Requests/DisableProfileMethodRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DisableProfileMethodRequestTest extends TestCase { diff --git a/tests/Http/Requests/DynamicGetRequestTest.php b/tests/Http/Requests/DynamicGetRequestTest.php index a375c4b0f..e9fea6fdc 100644 --- a/tests/Http/Requests/DynamicGetRequestTest.php +++ b/tests/Http/Requests/DynamicGetRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class DynamicGetRequestTest extends TestCase { diff --git a/tests/Http/Requests/DynamicRequestTest.php b/tests/Http/Requests/DynamicRequestTest.php index 1d1327445..547a2f74e 100644 --- a/tests/Http/Requests/DynamicRequestTest.php +++ b/tests/Http/Requests/DynamicRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use InvalidArgumentException; use Mollie\Api\Http\Requests\DynamicRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\Method; diff --git a/tests/Http/Requests/EnableMethodIssuerRequestTest.php b/tests/Http/Requests/EnableMethodIssuerRequestTest.php index 6f221b514..b3834e46b 100644 --- a/tests/Http/Requests/EnableMethodIssuerRequestTest.php +++ b/tests/Http/Requests/EnableMethodIssuerRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class EnableMethodIssuerRequestTest extends TestCase { diff --git a/tests/Http/Requests/EnableProfileMethodRequestTest.php b/tests/Http/Requests/EnableProfileMethodRequestTest.php index 920387351..07a6d18bd 100644 --- a/tests/Http/Requests/EnableProfileMethodRequestTest.php +++ b/tests/Http/Requests/EnableProfileMethodRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class EnableProfileMethodRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetAllMethodsRequestTest.php b/tests/Http/Requests/GetAllMethodsRequestTest.php index 7a381153d..6d5955425 100644 --- a/tests/Http/Requests/GetAllMethodsRequestTest.php +++ b/tests/Http/Requests/GetAllMethodsRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetAllMethodsRequest; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetAllMethodsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php index e8767bc29..615861f71 100644 --- a/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetAllPaginatedSubscriptionsRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetAllPaginatedSubscriptionsRequest; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetAllPaginatedSubscriptionsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index 07f496646..8211a33ac 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -3,12 +3,12 @@ namespace Tests\Http\Requests; use DateTime; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Http\Requests\GetBalanceReportRequest; use Mollie\Api\Resources\BalanceReport; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetBalanceReportRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetBalanceRequestTest.php b/tests/Http/Requests/GetBalanceRequestTest.php index 926ce4c9a..2b3cbc203 100644 --- a/tests/Http/Requests/GetBalanceRequestTest.php +++ b/tests/Http/Requests/GetBalanceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetBalanceRequest; use Mollie\Api\Resources\Balance; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetBalanceRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetClientRequestTest.php b/tests/Http/Requests/GetClientRequestTest.php index 6fbf19e3a..04d21b11e 100644 --- a/tests/Http/Requests/GetClientRequestTest.php +++ b/tests/Http/Requests/GetClientRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetClientRequest; use Mollie\Api\Resources\Client; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetClientRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetCustomerRequestTest.php b/tests/Http/Requests/GetCustomerRequestTest.php index 9061db918..1249bb9b5 100644 --- a/tests/Http/Requests/GetCustomerRequestTest.php +++ b/tests/Http/Requests/GetCustomerRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetEnabledMethodsRequestTest.php b/tests/Http/Requests/GetEnabledMethodsRequestTest.php index ae38f6d9d..fd59e8b6f 100644 --- a/tests/Http/Requests/GetEnabledMethodsRequestTest.php +++ b/tests/Http/Requests/GetEnabledMethodsRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetEnabledMethodsRequest; use Mollie\Api\Resources\MethodCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetEnabledMethodsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetInvoiceRequestTest.php b/tests/Http/Requests/GetInvoiceRequestTest.php index 772bc3e43..fb0e644bf 100644 --- a/tests/Http/Requests/GetInvoiceRequestTest.php +++ b/tests/Http/Requests/GetInvoiceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetInvoiceRequest; use Mollie\Api\Resources\Invoice; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetMandateRequestTest.php b/tests/Http/Requests/GetMandateRequestTest.php index 6e1cb3d9d..3b2ccd2e8 100644 --- a/tests/Http/Requests/GetMandateRequestTest.php +++ b/tests/Http/Requests/GetMandateRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Resources\Mandate; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetMandateRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetOnboardingStatusRequestTest.php b/tests/Http/Requests/GetOnboardingStatusRequestTest.php index 4bd1592dd..66b182480 100644 --- a/tests/Http/Requests/GetOnboardingStatusRequestTest.php +++ b/tests/Http/Requests/GetOnboardingStatusRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOnboardingStatusRequest; use Mollie\Api\Resources\Onboarding; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetOnboardingStatusRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php index b4c05a5f0..3d095fbcc 100644 --- a/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php +++ b/tests/Http/Requests/GetOrganizationPartnerStatusRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Resources\Partner; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetOrganizationPartnerStatusRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetOrganizationRequestTest.php b/tests/Http/Requests/GetOrganizationRequestTest.php index 99ef109d9..59ac25b0a 100644 --- a/tests/Http/Requests/GetOrganizationRequestTest.php +++ b/tests/Http/Requests/GetOrganizationRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetOrganizationRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php index 0175fb357..63ba1c053 100644 --- a/tests/Http/Requests/GetPaginatedBalanceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest; use Mollie\Api\Resources\BalanceCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedBalanceRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php index 89460d2a0..2eed463af 100644 --- a/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php +++ b/tests/Http/Requests/GetPaginatedBalanceTransactionRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; use Mollie\Api\Resources\BalanceTransactionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedBalanceTransactionRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php index 069bbf8cc..a9ed7cbaf 100644 --- a/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedChargebacksRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedChargebacksRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedClientRequestTest.php b/tests/Http/Requests/GetPaginatedClientRequestTest.php index 9e6bde68f..8c189c476 100644 --- a/tests/Http/Requests/GetPaginatedClientRequestTest.php +++ b/tests/Http/Requests/GetPaginatedClientRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedClientRequest; use Mollie\Api\Resources\ClientCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedClientRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php index 9a5a50897..165496dda 100644 --- a/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerPaymentsRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedCustomerPaymentsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php index a95354cd6..0e4cbcf9d 100644 --- a/tests/Http/Requests/GetPaginatedCustomerRequestTest.php +++ b/tests/Http/Requests/GetPaginatedCustomerRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; use Mollie\Api\Resources\CustomerCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php index 3f9bce767..20477277e 100644 --- a/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php +++ b/tests/Http/Requests/GetPaginatedInvoiceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\InvoiceCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaginatedInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedMandateRequestTest.php b/tests/Http/Requests/GetPaginatedMandateRequestTest.php index cae8e877c..9376f89dc 100644 --- a/tests/Http/Requests/GetPaginatedMandateRequestTest.php +++ b/tests/Http/Requests/GetPaginatedMandateRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedMandateRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php index 1d1ade6c4..a77eb4b90 100644 --- a/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentCapturesRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentCapturesRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php index c5be6fbfb..dafe1631b 100644 --- a/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentChargebacksRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentChargebacksRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php index 80430f092..95306352a 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinkPaymentsRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentLinkPaymentsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php index f03d32605..492c051a8 100644 --- a/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentLinksRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentLinksRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php index 9be9a943e..3f022962c 100644 --- a/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentRefundsRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentRefundsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php index f742c0a71..d91094902 100644 --- a/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedPaymentsRequestTest.php @@ -2,6 +2,9 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest; use Mollie\Api\Http\Response; @@ -9,9 +12,6 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedPaymentsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php index e46d91196..871a443fb 100644 --- a/tests/Http/Requests/GetPaginatedProfilesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedProfilesRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; use Mollie\Api\Resources\Profile; use Mollie\Api\Resources\ProfileCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedProfilesRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php index 7e875f6ab..57c270397 100644 --- a/tests/Http/Requests/GetPaginatedRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedRefundsRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedRefundsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php index 7ffbd257f..c74ffbee2 100644 --- a/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSalesInvoicesRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSalesInvoicesRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Resources\SalesInvoiceCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSalesInvoicesRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php index 47977f004..eeaea5b30 100644 --- a/tests/Http/Requests/GetPaginatedSessionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSessionsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSessionsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php index bbfb0fdf5..a9bb0f2e9 100644 --- a/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementCapturesRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementCapturesRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php index 6a61f0300..9f8461124 100644 --- a/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementChargebacksRequestTest.php @@ -2,14 +2,14 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\LazyCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementChargebacksRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php index 352eebd1e..beffbf5fb 100644 --- a/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementPaymentsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementPaymentsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php index 98879d744..bd777c028 100644 --- a/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementRefundsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementRefundsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php index a135606d3..7c686370b 100644 --- a/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSettlementsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSettlementsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index 05dc94c78..abdd25a02 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -2,6 +2,9 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; @@ -9,9 +12,6 @@ use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSubscriptionPaymentsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php index 4cfa04fc0..44d5dff90 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Subscription; use Mollie\Api\Resources\SubscriptionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedSubscriptionsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php index a134baff8..215a2af3a 100644 --- a/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedTerminalsRequestTest.php @@ -2,15 +2,15 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class GetPaginatedTerminalsRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentCaptureRequestTest.php b/tests/Http/Requests/GetPaymentCaptureRequestTest.php index ef45e7b60..00ff2c538 100644 --- a/tests/Http/Requests/GetPaymentCaptureRequestTest.php +++ b/tests/Http/Requests/GetPaymentCaptureRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; use Mollie\Api\Resources\Capture; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentCaptureRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentChargebackRequestTest.php b/tests/Http/Requests/GetPaymentChargebackRequestTest.php index 4c61356ac..b6c68fedb 100644 --- a/tests/Http/Requests/GetPaymentChargebackRequestTest.php +++ b/tests/Http/Requests/GetPaymentChargebackRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; use Mollie\Api\Resources\Chargeback; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentChargebackRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentLinkRequestTest.php b/tests/Http/Requests/GetPaymentLinkRequestTest.php index c61daf4a3..c3a9f3a8f 100644 --- a/tests/Http/Requests/GetPaymentLinkRequestTest.php +++ b/tests/Http/Requests/GetPaymentLinkRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentMethodRequestTest.php b/tests/Http/Requests/GetPaymentMethodRequestTest.php index 767db6377..04f50aeb0 100644 --- a/tests/Http/Requests/GetPaymentMethodRequestTest.php +++ b/tests/Http/Requests/GetPaymentMethodRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentMethodRequest; use Mollie\Api\Resources\Method; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentMethodRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentRefundRequestTest.php b/tests/Http/Requests/GetPaymentRefundRequestTest.php index 4b7b3a681..0a331905a 100644 --- a/tests/Http/Requests/GetPaymentRefundRequestTest.php +++ b/tests/Http/Requests/GetPaymentRefundRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Resources\Refund; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentRefundRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPaymentRequestTest.php b/tests/Http/Requests/GetPaymentRequestTest.php index 08de4b860..93d38b623 100644 --- a/tests/Http/Requests/GetPaymentRequestTest.php +++ b/tests/Http/Requests/GetPaymentRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPaymentRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetPermissionRequestTest.php b/tests/Http/Requests/GetPermissionRequestTest.php index 9b9614ab4..6d2f9bc46 100644 --- a/tests/Http/Requests/GetPermissionRequestTest.php +++ b/tests/Http/Requests/GetPermissionRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Resources\Permission; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetPermissionRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetProfileRequestTest.php b/tests/Http/Requests/GetProfileRequestTest.php index 3db95ec43..920972b7d 100644 --- a/tests/Http/Requests/GetProfileRequestTest.php +++ b/tests/Http/Requests/GetProfileRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetProfileRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetSalesInvoiceRequestTest.php b/tests/Http/Requests/GetSalesInvoiceRequestTest.php index a48df8de4..b840c0723 100644 --- a/tests/Http/Requests/GetSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/GetSalesInvoiceRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetSalesInvoiceRequest; use Mollie\Api\Resources\SalesInvoice; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetSalesInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php index a075a6d56..aded7caed 100644 --- a/tests/Http/Requests/GetSessionRequestTest.php +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\GetSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetSessionRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetSettlementRequestTest.php b/tests/Http/Requests/GetSettlementRequestTest.php index a1b11f359..8944c4bfc 100644 --- a/tests/Http/Requests/GetSettlementRequestTest.php +++ b/tests/Http/Requests/GetSettlementRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\Settlement; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetSettlementRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetSubscriptionRequestTest.php b/tests/Http/Requests/GetSubscriptionRequestTest.php index e23e3e626..d93c616b5 100644 --- a/tests/Http/Requests/GetSubscriptionRequestTest.php +++ b/tests/Http/Requests/GetSubscriptionRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetSubscriptionRequestTest extends TestCase { diff --git a/tests/Http/Requests/GetTerminalRequestTest.php b/tests/Http/Requests/GetTerminalRequestTest.php index eb38fcd71..ec3b89a7e 100644 --- a/tests/Http/Requests/GetTerminalRequestTest.php +++ b/tests/Http/Requests/GetTerminalRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\Terminal; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class GetTerminalRequestTest extends TestCase { diff --git a/tests/Http/Requests/ListPermissionsRequestTest.php b/tests/Http/Requests/ListPermissionsRequestTest.php index 1fe0db17d..e79b2b205 100644 --- a/tests/Http/Requests/ListPermissionsRequestTest.php +++ b/tests/Http/Requests/ListPermissionsRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; use Mollie\Api\Resources\PermissionCollection; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class ListPermissionsRequestTest extends TestCase { diff --git a/tests/Http/Requests/RevokeMandateRequestTest.php b/tests/Http/Requests/RevokeMandateRequestTest.php index 1e69cf4ec..1c3cfd901 100644 --- a/tests/Http/Requests/RevokeMandateRequestTest.php +++ b/tests/Http/Requests/RevokeMandateRequestTest.php @@ -2,11 +2,11 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Requests\RevokeMandateRequest; use Mollie\Api\Http\Response; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class RevokeMandateRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php index 9e3ad9f2d..a40d33eed 100644 --- a/tests/Http/Requests/UpdateCustomerRequestTest.php +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdateCustomerPayload; use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Resources\Customer; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdateCustomerRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php index c80f77d3e..60b9e2136 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\PaymentLink; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdatePaymentLinkRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdatePaymentRequestTest.php b/tests/Http/Requests/UpdatePaymentRequestTest.php index 4c3530889..a6c983134 100644 --- a/tests/Http/Requests/UpdatePaymentRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\UpdatePaymentRequest; use Mollie\Api\Resources\Payment; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdatePaymentRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php index 1bc8f649a..c0df7f1e3 100644 --- a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -3,12 +3,12 @@ namespace Tests\Http\Requests; use DateTime; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; use Mollie\Api\Resources\Route; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdatePaymentRouteRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateProfileRequestTest.php b/tests/Http/Requests/UpdateProfileRequestTest.php index 75be6f18c..eed0025cf 100644 --- a/tests/Http/Requests/UpdateProfileRequestTest.php +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\Profile; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdateProfileRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index e288a3e1d..6e46a4c8a 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; use Mollie\Api\Http\Requests\UpdateSalesInvoiceRequest; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Types\SalesInvoiceStatus; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdateSalesInvoiceRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index aaf75e0d0..c8b272c69 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -2,12 +2,12 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\UpdateSessionRequest; use Mollie\Api\Resources\Session; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdateSessionRequestTest extends TestCase { diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index ee6aaabb4..c83cfcb28 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -2,13 +2,13 @@ namespace Tests\Http\Requests; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\UpdateSubscriptionPayload; use Mollie\Api\Http\Requests\UpdateSubscriptionRequest; use Mollie\Api\Resources\Subscription; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; class UpdateSubscriptionRequestTest extends TestCase { diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index 8b9f61bf0..820937b43 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -5,6 +5,8 @@ use GuzzleHttp\Client; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Adapter\CurlMollieHttpAdapter; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; use Mollie\Api\Http\Data\CreatePaymentPayload; @@ -17,8 +19,6 @@ use Mollie\Api\Idempotency\FakeIdempotencyKeyGenerator; use Mollie\Api\MollieApiClient; use PHPUnit\Framework\TestCase; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; use Tests\Fixtures\Requests\DynamicDeleteRequest; use Tests\Fixtures\Requests\DynamicGetRequest; diff --git a/tests/Resources/CursorCollectionTest.php b/tests/Resources/CursorCollectionTest.php index 51320e430..3726b72f2 100644 --- a/tests/Resources/CursorCollectionTest.php +++ b/tests/Resources/CursorCollectionTest.php @@ -2,15 +2,15 @@ namespace Tests\Resources; +use Mollie\Api\Fake\MockMollieClient; +use Mollie\Api\Fake\MockResponse; +use Mollie\Api\Fake\SequenceMockResponse; use Mollie\Api\Http\Requests\DynamicGetRequest; use Mollie\Api\Http\Response; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; use PHPUnit\Framework\TestCase; use stdClass; -use Mollie\Api\Fake\MockMollieClient; -use Mollie\Api\Fake\MockResponse; -use Mollie\Api\Fake\SequenceMockResponse; class CursorCollectionTest extends TestCase {