diff --git a/UPGRADING.md b/UPGRADING.md index 4b936349..581a22a6 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -160,7 +160,7 @@ $client->payments->page(); Two new collection methods were added which can be used to simplify interacting with collection resources. - `contains(callable $callback): bool` -- `filter(callable $callback): static` +- `filter(callable $callback): self` ### Testmode is automatically removed.. ..If an API key is used as authentication. diff --git a/examples/captures/create-capture.php b/examples/captures/create-capture.php index 65d37440..33dc17f3 100644 --- a/examples/captures/create-capture.php +++ b/examples/captures/create-capture.php @@ -4,7 +4,6 @@ * How to prepare a new payment with the Mollie API. */ -use Mollie\Api\Http\Data\CreatePaymentCapturePayload; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; @@ -22,10 +21,11 @@ * description Description of the capture. * metadata Custom metadata that is stored with the payment. */ - $response = $mollie->send(new CreatePaymentCaptureRequest('tr_WDqYK6vllg', new CreatePaymentCapturePayload( + $response = $mollie->send(new CreatePaymentCaptureRequest( + 'tr_WDqYK6vllg', 'Order #12345', new Money('EUR', '5.00') - ))); + )); $capture = $response->toResource(); diff --git a/examples/client-links/create-client-link.php b/examples/client-links/create-client-link.php index cfbfcd95..82f69cae 100644 --- a/examples/client-links/create-client-link.php +++ b/examples/client-links/create-client-link.php @@ -3,8 +3,6 @@ /* * How to create a new client link in the Mollie API. */ - -use Mollie\Api\Http\Data\CreateClientLinkPayload; use Mollie\Api\Http\Data\Owner; use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Http\Requests\CreateClientLinkRequest; @@ -29,13 +27,13 @@ */ $response = $mollie ->send( - new CreateClientLinkRequest(new CreateClientLinkPayload( + new CreateClientLinkRequest( new Owner('foo@test.com', 'foo', 'bar', 'nl_NL'), 'Foo Company', new OwnerAddress('NL', 'Keizersgracht 313', '1016 EE', 'Amsterdam'), '30204462', 'NL123456789B01', - )) + ) ); $clientLink = $response->toResource(); diff --git a/examples/customers/create-customer-first-payment.php b/examples/customers/create-customer-first-payment.php index 96761e31..75ce0aa9 100644 --- a/examples/customers/create-customer-first-payment.php +++ b/examples/customers/create-customer-first-payment.php @@ -4,12 +4,10 @@ * How to create a first payment to allow recurring payments later. */ -use Mollie\Api\Factories\CreatePaymentPayloadFactory; 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; try { /* @@ -40,19 +38,17 @@ * * @See: https://docs.mollie.com/reference/v2/customers-api/create-customer-payment */ - $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' => new Metadata([ - 'order_id' => $orderId, - ]), - 'sequenceType' => SequenceType::FIRST, - ])->create(); - $payment = $mollie->send( - new CreateCustomerPaymentRequest($customer->id, $payload) + new CreateCustomerPaymentRequest( + $customer->id, + "First payment - Order #{$orderId}", + new Money('EUR', '10.00'), + "{$protocol}://{$hostname}/payments/return.php?order_id={$orderId}", + "{$protocol}://{$hostname}/payments/webhook.php", + new Metadata([ + 'order_id' => $orderId, + ]) + ) ); /* diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 754d4f04..01e3d5c1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -273,7 +273,13 @@ parameters: - message: '#^Unsafe usage of new static\(\)\.$#' identifier: new.static - count: 4 + count: 1 + path: src/Factories/Factory.php + + - + message: '#^Unsafe usage of new static\(\)\.$#' + identifier: new.static + count: 5 path: src/Http/Data/DataCollection.php - diff --git a/phpunit.xml b/phpunit.xml index f566b1d9..164ede99 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,26 @@ - - - - src/ - - - - - - - - tests/ - + + + + tests + + + + + src + + + vendor + tests + + + + + + + diff --git a/src/CompatibilityChecker.php b/src/CompatibilityChecker.php index dbfb9a7a..313f5522 100644 --- a/src/CompatibilityChecker.php +++ b/src/CompatibilityChecker.php @@ -25,7 +25,7 @@ public function checkCompatibility() { if (! $this->satisfiesPhpVersion()) { throw new IncompatiblePlatformException( - '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.'.', IncompatiblePlatformException::INCOMPATIBLE_PHP_VERSION ); } diff --git a/src/Contracts/Connector.php b/src/Contracts/Connector.php index c316cb6d..92ae74aa 100644 --- a/src/Contracts/Connector.php +++ b/src/Contracts/Connector.php @@ -7,7 +7,10 @@ interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract, Testable { - public function send(Request $request): ?object; + /** + * @return mixed + */ + public function send(Request $request); public function resolveBaseUrl(): string; diff --git a/src/Contracts/Factory.php b/src/Contracts/Factory.php deleted file mode 100644 index c47d9e48..00000000 --- a/src/Contracts/Factory.php +++ /dev/null @@ -1,13 +0,0 @@ -send((new GetBalanceRequest($id))->test($testmode)); } @@ -37,7 +36,7 @@ public function get(string $id, $testmode = false): Balance * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function primary($testmode = false): Balance { @@ -52,13 +51,19 @@ public function page(?string $from = null, ?int $limit = null, array $filters = { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedBalanceQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $query = SortablePaginatedQueryFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); - return $this->send((new GetPaginatedBalanceRequest($query))->test($testmode)); + return $this->send((new GetPaginatedBalanceRequest( + $query->from, + $query->limit, + $query->sort, + ))->test($testmode)); } /** @@ -71,14 +76,20 @@ public function iterator(?string $from = null, ?int $limit = null, array $filter { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedBalanceQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $query = SortablePaginatedQueryFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedBalanceRequest($query)) + (new GetPaginatedBalanceRequest( + $query->from, + $query->limit, + $query->sort, + )) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/BalanceReportEndpointCollection.php b/src/EndpointCollection/BalanceReportEndpointCollection.php index 7abe127e..2e946508 100644 --- a/src/EndpointCollection/BalanceReportEndpointCollection.php +++ b/src/EndpointCollection/BalanceReportEndpointCollection.php @@ -2,9 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Factories\GetBalanceReportQueryFactory; -use Mollie\Api\Http\Data\GetBalanceReportQuery; -use Mollie\Api\Http\Requests\GetBalanceReportRequest; +use Mollie\Api\Factories\GetBalanceReportRequestFactory; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceReport; use Mollie\Api\Utils\Utility; @@ -14,30 +12,27 @@ class BalanceReportEndpointCollection extends EndpointCollection /** * Retrieve a balance report for the provided balance id and parameters. * - * @param array|GetBalanceReportQuery $query - * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function getForId(string $balanceId, $query = []): ?BalanceReport + public function getForId(string $balanceId, array $query = []): ?BalanceReport { $testmode = Utility::extractBool($query, 'testmode', false); - $query = GetBalanceReportQueryFactory::new($query) + $request = GetBalanceReportRequestFactory::new($balanceId) + ->withQuery($query) ->create(); /** @var BalanceReport */ - return $this->send((new GetBalanceReportRequest($balanceId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** * 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 + * @throws \Mollie\Api\Exceptions\RequestException */ - public function getForPrimary($query = []): BalanceReport + public function getForPrimary(array $query = []): ?BalanceReport { return $this->getForId('primary', $query); } @@ -45,10 +40,10 @@ public function getForPrimary($query = []): BalanceReport /** * Retrieve a balance report for the provided balance resource and parameters. * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function getFor(Balance $balance, array $parameters = []): BalanceReport + public function getFor(Balance $balance, array $query = []): ?BalanceReport { - return $this->getForId($balance->id, $parameters); + return $this->getForId($balance->id, $query); } } diff --git a/src/EndpointCollection/BalanceTransactionEndpointCollection.php b/src/EndpointCollection/BalanceTransactionEndpointCollection.php index bb6ff863..8635d7b1 100644 --- a/src/EndpointCollection/BalanceTransactionEndpointCollection.php +++ b/src/EndpointCollection/BalanceTransactionEndpointCollection.php @@ -5,56 +5,51 @@ namespace Mollie\Api\EndpointCollection; use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Resources\LazyCollection; +use Mollie\Api\Utils\Utility; class BalanceTransactionEndpointCollection extends EndpointCollection { /** * List the transactions for a specific Balance. * - * @param array|PaginatedQuery $query - * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function pageFor(Balance $balance, $query = [], bool $testmode = false): BalanceTransactionCollection + public function pageFor(Balance $balance, array $query = [], bool $testmode = false): BalanceTransactionCollection { return $this->pageForId($balance->id, $query, $testmode); } /** - * Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie. + * List the transactions for the primary Balance. * - * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * @throws \Mollie\Api\Exceptions\RequestException */ - public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection + public function pageForPrimary(array $query = [], bool $testmode = false): BalanceTransactionCollection { - return $this->iteratorForId($balance->id, $parameters, $iterateBackwards, $testmode); + /** @var BalanceTransactionCollection */ + return $this->pageForId('primary', $query, $testmode); } /** - * List the transactions for the primary Balance. - * - * @param array|PaginatedQuery $query + * Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie. * - * @throws \Mollie\Api\Exceptions\ApiException + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ - public function pageForPrimary($query = [], bool $testmode = false): BalanceTransactionCollection + public function iteratorFor(Balance $balance, array $query = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection { - /** @var BalanceTransactionCollection */ - return $this->pageForId('primary', $query, $testmode); + return $this->iteratorForId($balance->id, $query, $iterateBackwards, $testmode); } /** * 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, ?bool $testmode = null): LazyCollection + public function iteratorForPrimary(array $query = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection { return $this->iteratorForId('primary', $query, $iterateBackwards); } @@ -62,36 +57,43 @@ public function iteratorForPrimary($query = [], bool $iterateBackwards = false, /** * List the transactions for a specific Balance ID. * - * @param array|PaginatedQuery $query - * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function pageForId(string $balanceId, $query = [], bool $testmode = false): BalanceTransactionCollection + public function pageForId(string $balanceId, array $query = [], bool $testmode = false): BalanceTransactionCollection { - if (! $query instanceof PaginatedQuery) { - $query = PaginatedQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $query = PaginatedQueryFactory::new() + ->withQuery($query) + ->create(); /** @var BalanceTransactionCollection */ - return $this->send((new GetPaginatedBalanceTransactionRequest($balanceId, $query))->test($testmode)); + return $this->send((new GetPaginatedBalanceTransactionRequest( + $balanceId, + $query->from, + $query->limit, + ))->test($testmode)); } /** * 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, bool $testmode = false): LazyCollection + public function iteratorForId(string $balanceId, array $query = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection { - if (! $query instanceof PaginatedQuery) { - $query = PaginatedQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $query = PaginatedQueryFactory::new() + ->withQuery($query) + ->create(); return $this->send( - (new GetPaginatedBalanceTransactionRequest($balanceId, $query)) + (new GetPaginatedBalanceTransactionRequest( + $balanceId, + $query->from, + $query->limit, + )) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/ChargebackEndpointCollection.php b/src/EndpointCollection/ChargebackEndpointCollection.php index 4db3798b..90b06a94 100644 --- a/src/EndpointCollection/ChargebackEndpointCollection.php +++ b/src/EndpointCollection/ChargebackEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedChargebackQueryFactory; -use Mollie\Api\Http\Requests\GetPaginatedChargebacksRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedChargebacksRequestFactory; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Utils\Utility; @@ -16,20 +15,22 @@ class ChargebackEndpointCollection extends EndpointCollection * * @param string $from The first chargeback ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): ChargebackCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedChargebackQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedChargebacksRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); /** @var ChargebackCollection */ - return $this->send((new GetPaginatedChargebacksRequest($query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -43,14 +44,16 @@ public function iterator(?string $from = null, ?int $limit = null, $filters = [] { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedChargebackQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedChargebacksRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedChargebacksRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/ClientEndpointCollection.php b/src/EndpointCollection/ClientEndpointCollection.php index 6664e4b1..c7cda045 100644 --- a/src/EndpointCollection/ClientEndpointCollection.php +++ b/src/EndpointCollection/ClientEndpointCollection.php @@ -2,12 +2,9 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetClientQueryFactory; -use Mollie\Api\Factories\GetPaginatedClientQueryFactory; -use Mollie\Api\Http\Data\GetClientQuery; -use Mollie\Api\Http\Requests\GetClientRequest; -use Mollie\Api\Http\Requests\GetPaginatedClientRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetClientRequestFactory; +use Mollie\Api\Factories\GetPaginatedClientRequestFactory; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; use Mollie\Api\Resources\LazyCollection; @@ -21,18 +18,17 @@ class ClientEndpointCollection extends EndpointCollection * 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 + * @throws RequestException */ - public function get(string $id, $query = []): Client + public function get(string $id, array $query = []): Client { - if (! $query instanceof GetClientQuery) { - $query = GetClientQueryFactory::new($query)->create(); - } + $request = GetClientRequestFactory::new($id) + ->withQuery($query) + ->create(); /** @var Client */ - return $this->send(new GetClientRequest($id, $query)); + return $this->send($request); } /** @@ -40,18 +36,20 @@ public function get(string $id, $query = []): Client * * @param string $from The first client ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): ClientCollection { - $query = GetPaginatedClientQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedClientRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); /** @var ClientCollection */ - return $this->send(new GetPaginatedClientRequest($query)); + return $this->send($request); } /** @@ -62,14 +60,16 @@ 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 { - $query = GetPaginatedClientQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedClientRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedClientRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/ClientLinkEndpointCollection.php b/src/EndpointCollection/ClientLinkEndpointCollection.php index 389f45a6..7cfa014c 100644 --- a/src/EndpointCollection/ClientLinkEndpointCollection.php +++ b/src/EndpointCollection/ClientLinkEndpointCollection.php @@ -2,10 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateClientLinkPayloadFactory; -use Mollie\Api\Http\Data\CreateClientLinkPayload; -use Mollie\Api\Http\Requests\CreateClientLinkRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateClientLinkRequestFactory; use Mollie\Api\Resources\ClientLink; class ClientLinkEndpointCollection extends EndpointCollection @@ -13,18 +11,17 @@ class ClientLinkEndpointCollection extends EndpointCollection /** * Creates a client link in Mollie. * - * @param array|CreateClientLinkPayload $payload An array containing details on the client link. + * @param array $payload An array containing details on the client link. * - * @throws ApiException + * @throws RequestException */ - public function create($payload = []): ClientLink + public function create(array $payload = []): ClientLink { - if (! $payload instanceof CreateClientLinkPayload) { - $payload = CreateClientLinkPayloadFactory::new($payload) - ->create(); - } + $request = CreateClientLinkRequestFactory::new() + ->withPayload($payload) + ->create(); /** @var ClientLink */ - return $this->send(new CreateClientLinkRequest($payload)); + return $this->send($request); } } diff --git a/src/EndpointCollection/CustomerEndpointCollection.php b/src/EndpointCollection/CustomerEndpointCollection.php index a9af25b2..4989f674 100644 --- a/src/EndpointCollection/CustomerEndpointCollection.php +++ b/src/EndpointCollection/CustomerEndpointCollection.php @@ -2,17 +2,12 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateCustomerPayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdateCustomerPayloadFactory; -use Mollie\Api\Http\Data\CreateCustomerPayload; -use Mollie\Api\Http\Data\UpdateCustomerPayload; -use Mollie\Api\Http\Requests\CreateCustomerRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateCustomerRequestFactory; +use Mollie\Api\Factories\UpdateCustomerRequestFactory; use Mollie\Api\Http\Requests\DeleteCustomerRequest; use Mollie\Api\Http\Requests\GetCustomerRequest; use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest; -use Mollie\Api\Http\Requests\UpdateCustomerRequest; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; use Mollie\Api\Resources\LazyCollection; @@ -23,21 +18,20 @@ 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 + * @throws RequestException */ public function create($data = [], $testmode = false): Customer { $testmode = Utility::extractBool($testmode, 'testmode', false); - if (! $data instanceof CreateCustomerPayload) { - $data = CreateCustomerPayloadFactory::new($data)->create(); - } + $request = CreateCustomerRequestFactory::new() + ->withPayload($data) + ->create(); /** @var Customer */ - return $this->send((new CreateCustomerRequest($data))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -47,7 +41,7 @@ public function create($data = [], $testmode = false): Customer * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function get(string $id, $testmode = false): Customer { @@ -62,16 +56,16 @@ public function get(string $id, $testmode = false): Customer * * Will throw an ApiException if the customer id is invalid or the resource cannot be found. * - * @throws ApiException + * @throws RequestException */ - public function update(string $id, $data = []): ?Customer + public function update(string $id, array $data = []): ?Customer { - if (! $data instanceof UpdateCustomerPayload) { - $data = UpdateCustomerPayloadFactory::new($data)->create(); - } + $request = UpdateCustomerRequestFactory::new($id) + ->withPayload($data) + ->create(); /** @var null|Customer */ - return $this->send(new UpdateCustomerRequest($id, $data)); + return $this->send($request); } /** @@ -82,7 +76,7 @@ public function update(string $id, $data = []): ?Customer * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function delete(string $id, $testmode = false): void { @@ -95,41 +89,31 @@ public function delete(string $id, $testmode = false): void * Retrieves a collection of Customers from Mollie. * * @param string $from The first customer ID you want to include in your list. + * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ - public function page(?string $from = null, ?int $limit = null, array $filters = []): CustomerCollection + public function page(?string $from = null, ?int $limit = null, $testmode = false): CustomerCollection { - $testmode = Utility::extractBool($filters, 'testmode', false); - - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var CustomerCollection */ - return $this->send((new GetPaginatedCustomerRequest($query))->test($testmode)); + return $this->send((new GetPaginatedCustomerRequest($from, $limit))->test($testmode)); } /** * 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|array $testmode * @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 + public function iterator(?string $from = null, ?int $limit = null, $testmode = false, bool $iterateBackwards = false): LazyCollection { - $testmode = Utility::extractBool($filters, 'testmode', false); - - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $testmode = Utility::extractBool($testmode, 'testmode', false); return $this->send( - (new GetPaginatedCustomerRequest($query)) + (new GetPaginatedCustomerRequest($from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php index a602c29e..28f5b0e1 100644 --- a/src/EndpointCollection/CustomerPaymentsEndpointCollection.php +++ b/src/EndpointCollection/CustomerPaymentsEndpointCollection.php @@ -2,18 +2,13 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreatePaymentPayloadFactory; -use Mollie\Api\Factories\GetPaginatedCustomerPaymentsQueryFactory; -use Mollie\Api\Http\Data\CreatePaymentPayload; -use Mollie\Api\Http\Data\CreatePaymentQuery; -use Mollie\Api\Http\Requests\CreateCustomerPaymentRequest; -use Mollie\Api\Http\Requests\GetPaginatedCustomerPaymentsRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateCustomerPaymentRequestFactory; +use Mollie\Api\Factories\GetPaginatedCustomerPaymentsRequestFactory; use Mollie\Api\Resources\Customer; 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 @@ -21,12 +16,9 @@ class CustomerPaymentsEndpointCollection extends EndpointCollection /** * Create a subscription for a Customer * - * @param array|CreatePaymentPayload $payload - * @param array|CreatePaymentQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function createFor(Customer $customer, $payload = [], $query = [], bool $testmode = false): Payment + public function createFor(Customer $customer, array $payload = [], array $query = [], bool $testmode = false): Payment { return $this->createForId($customer->id, $payload, $query, $testmode); } @@ -34,32 +26,25 @@ public function createFor(Customer $customer, $payload = [], $query = [], bool $ /** * Create a subscription for a Customer ID * - * @param string $customerId - * @param array|CreatePaymentPayload $payload - * @param array|CreatePaymentQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function createForId($customerId, $payload = [], $query = [], bool $testmode = false): Payment + public function createForId(string $customerId, array $payload = [], array $query = [], bool $testmode = false): Payment { - if (! $payload instanceof CreatePaymentPayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreatePaymentPayloadFactory::new($payload) - ->create(); - } + $testmode = Utility::extractBool($payload, 'testmode', $testmode); - if (! $query instanceof CreatePaymentQuery) { - $query = CreatePaymentQuery::fromArray(Arr::wrap($query)); - } + $request = CreateCustomerPaymentRequestFactory::new($customerId) + ->withPayload($payload) + ->withQuery($query) + ->create(); /** @var Payment */ - return $this->send((new CreateCustomerPaymentRequest($customerId, $payload, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** * @param string $from The first resource ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { @@ -69,21 +54,21 @@ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = /** * @param string $from The first resource ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedCustomerPaymentsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - return $this->send((new GetPaginatedCustomerPaymentsRequest( - $customerId, - $query - ))->test($testmode)); + $request = GetPaginatedCustomerPaymentsRequestFactory::new($customerId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); + + return $this->send($request->test($testmode)); } /** @@ -116,14 +101,16 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedCustomerPaymentsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedCustomerPaymentsRequestFactory::new($customerId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedCustomerPaymentsRequest($customerId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/InvoiceEndpointCollection.php b/src/EndpointCollection/InvoiceEndpointCollection.php index b20cb61a..1f946ffd 100644 --- a/src/EndpointCollection/InvoiceEndpointCollection.php +++ b/src/EndpointCollection/InvoiceEndpointCollection.php @@ -2,11 +2,9 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedInvoiceQueryFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedInvoiceRequestFactory; use Mollie\Api\Http\Requests\GetInvoiceRequest; -use Mollie\Api\Http\Requests\GetPaginatedInvoiceRequest; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; use Mollie\Api\Resources\LazyCollection; @@ -18,7 +16,7 @@ class InvoiceEndpointCollection extends EndpointCollection * * Will throw a ApiException if the invoice id is invalid or the resource cannot be found. * - * @throws ApiException + * @throws RequestException */ public function get(string $invoiceId): Invoice { @@ -31,18 +29,20 @@ public function get(string $invoiceId): Invoice * * @param string|null $from The first invoice ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): InvoiceCollection { - $query = GetPaginatedInvoiceQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedInvoiceRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); /** @var InvoiceCollection */ - return $this->send(new GetPaginatedInvoiceRequest($query)); + return $this->send($request); } /** @@ -51,16 +51,18 @@ public function page(?string $from = null, ?int $limit = null, array $filters = * @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 + public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection { - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $parameters, - ])->create(); + $request = GetPaginatedInvoiceRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedInvoiceRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/MandateEndpointCollection.php b/src/EndpointCollection/MandateEndpointCollection.php index d272f4d2..bfc3d202 100644 --- a/src/EndpointCollection/MandateEndpointCollection.php +++ b/src/EndpointCollection/MandateEndpointCollection.php @@ -2,11 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateMandatePayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Http\Data\CreateMandatePayload; -use Mollie\Api\Http\Requests\CreateMandateRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateMandateRequestFactory; use Mollie\Api\Http\Requests\GetMandateRequest; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; use Mollie\Api\Http\Requests\RevokeMandateRequest; @@ -21,11 +18,10 @@ class MandateEndpointCollection extends EndpointCollection /** * Creates a mandate for a specific customer. * - * @param array|CreateMandatePayload $payload * - * @throws ApiException + * @throws RequestException */ - public function createForCustomer(Customer $customer, $payload = [], bool $testmode = false): Mandate + public function createForCustomer(Customer $customer, array $payload = [], bool $testmode = false): Mandate { return $this->createForCustomerId($customer->id, $payload, $testmode); } @@ -33,26 +29,26 @@ public function createForCustomer(Customer $customer, $payload = [], bool $testm /** * Creates a mandate for a specific customer ID. * - * @param array $payload * - * @throws ApiException + * @throws RequestException */ - public function createForCustomerId(string $customerId, $payload = [], bool $testmode = false): Mandate + public function createForCustomerId(string $customerId, array $payload = [], bool $testmode = false): Mandate { - if (! $payload instanceof CreateMandatePayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreateMandatePayloadFactory::new($payload)->create(); - } + $testmode = Utility::extractBool($payload, 'testmode', $testmode); + + $request = CreateMandateRequestFactory::new($customerId) + ->withPayload($payload) + ->create(); /** @var Mandate */ - return $this->send((new CreateMandateRequest($customerId, $payload))->test($testmode)); + return $this->send($request->test($testmode)); } /** * Retrieve a specific mandate for a customer. * * - * @throws ApiException + * @throws RequestException */ public function getForCustomer(Customer $customer, string $mandateId, array $parameters = []): Mandate { @@ -64,7 +60,7 @@ public function getForCustomer(Customer $customer, string $mandateId, array $par * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function getForCustomerId(string $customerId, string $mandateId, $testmode = false): Mandate { @@ -78,7 +74,7 @@ public function getForCustomerId(string $customerId, string $mandateId, $testmod * Revoke a mandate for a specific customer. * * - * @throws ApiException + * @throws RequestException */ public function revokeForCustomer(Customer $customer, string $mandateId, $data = []): void { @@ -90,7 +86,7 @@ public function revokeForCustomer(Customer $customer, string $mandateId, $data = * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function revokeForCustomerId(string $customerId, string $mandateId, $testmode = false): void { @@ -103,72 +99,68 @@ public function revokeForCustomerId(string $customerId, string $mandateId, $test * Retrieves a collection of mandates for the given customer. * * @param string $from The first mandate ID you want to include in your list. + * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ - public function pageForCustomer(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []): MandateCollection + public function pageForCustomer(Customer $customer, ?string $from = null, ?int $limit = null, $testmode = false): MandateCollection { - return $this->pageForCustomerId($customer->id, $from, $limit, $parameters); + return $this->pageForCustomerId($customer->id, $from, $limit, $testmode); } /** * Retrieves a collection of mandates for the given customer ID. * * @param string $from The first mandate ID you want to include in your list. + * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ - public function pageForCustomerId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): MandateCollection + public function pageForCustomerId(string $customerId, ?string $from = null, ?int $limit = null, $testmode = false): MandateCollection { - $testmode = Utility::extractBool($filters, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var MandateCollection */ - return $this->send((new GetPaginatedMandateRequest($customerId, $query))->test($testmode)); + return $this->send( + (new GetPaginatedMandateRequest($customerId, $from, $limit))->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|array $testmode * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorForCustomer( Customer $customer, ?string $from = null, ?int $limit = null, - array $parameters = [], + $testmode = false, bool $iterateBackwards = false ): LazyCollection { - return $this->iteratorForCustomerId($customer->id, $from, $limit, $parameters, $iterateBackwards); + return $this->iteratorForCustomerId($customer->id, $from, $limit, $testmode, $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|array $testmode * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). */ public function iteratorForCustomerId( string $customerId, ?string $from = null, ?int $limit = null, - array $filters = [], + $testmode = false, bool $iterateBackwards = false ): LazyCollection { - $testmode = Utility::extractBool($filters, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $testmode = Utility::extractBool($testmode, 'testmode', false); return $this->send( - (new GetPaginatedMandateRequest($customerId, $query)) + (new GetPaginatedMandateRequest($customerId, $from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/MethodEndpointCollection.php b/src/EndpointCollection/MethodEndpointCollection.php index 359cd1a8..873370d8 100644 --- a/src/EndpointCollection/MethodEndpointCollection.php +++ b/src/EndpointCollection/MethodEndpointCollection.php @@ -2,16 +2,10 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetAllPaymentMethodsQueryFactory; -use Mollie\Api\Factories\GetEnabledPaymentMethodsQueryFactory; -use Mollie\Api\Factories\GetPaymentMethodQueryFactory; -use Mollie\Api\Http\Data\GetAllMethodsQuery as GetAllPaymentMethodsQuery; -use Mollie\Api\Http\Data\GetEnabledPaymentMethodsQuery; -use Mollie\Api\Http\Data\GetPaymentMethodQuery; -use Mollie\Api\Http\Requests\GetAllMethodsRequest as GetAllPaymentMethodsRequest; -use Mollie\Api\Http\Requests\GetEnabledMethodsRequest as GetEnabledPaymentMethodsRequest; -use Mollie\Api\Http\Requests\GetPaymentMethodRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetAllPaymentMethodsRequestFactory; +use Mollie\Api\Factories\GetEnabledMethodsRequestFactory; +use Mollie\Api\Factories\GetPaymentMethodRequestFactory; use Mollie\Api\Resources\Method; use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Utils\Utility; @@ -22,19 +16,18 @@ class MethodEndpointCollection extends EndpointCollection * Retrieve all methods from Mollie. * Will return all available methods, both enabled and disabled. * - * @param array|GetAllPaymentMethodsQuery $query Query string parameters + * @param array $query Query string parameters * - * @throws ApiException + * @throws RequestException */ - public function all($query = []): MethodCollection + public function all(array $query = []): MethodCollection { - if (! $query instanceof GetAllPaymentMethodsQuery) { - $query = GetAllPaymentMethodsQueryFactory::new($query) - ->create(); - } + $request = GetAllPaymentMethodsRequestFactory::new() + ->withQuery($query) + ->create(); /** @var MethodCollection */ - return $this->send(new GetAllPaymentMethodsRequest($query)); + return $this->send($request); } /** @@ -42,24 +35,24 @@ public function all($query = []): MethodCollection * In test mode, this includes pending methods. * The results are not paginated. * - * @throws ApiException + * @throws RequestException */ - public function allEnabled($query = [], bool $testmode = false): MethodCollection + public function allEnabled(array $query = [], bool $testmode = false): MethodCollection { - if (! $query instanceof GetEnabledPaymentMethodsQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetEnabledPaymentMethodsQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetEnabledMethodsRequestFactory::new() + ->withQuery($query) + ->create(); /** @var MethodCollection */ - return $this->send((new GetEnabledPaymentMethodsRequest($query))->test($testmode)); + return $this->send($request->test($testmode)); } /** * @deprecated Use allEnabled() instead * - * @throws ApiException + * @throws RequestException */ public function allActive($query = [], bool $testmode = false): MethodCollection { @@ -71,17 +64,17 @@ public function allActive($query = [], bool $testmode = false): MethodCollection * * Will throw an ApiException if the method id is invalid or the resource cannot be found. * - * @throws ApiException + * @throws RequestException */ public function get(string $methodId, $query = [], bool $testmode = false): Method { - if (! $query instanceof GetPaymentMethodQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaymentMethodQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaymentMethodRequestFactory::new($methodId) + ->withQuery($query) + ->create(); /** @var Method */ - return $this->send((new GetPaymentMethodRequest($methodId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } } diff --git a/src/EndpointCollection/MethodIssuerEndpointCollection.php b/src/EndpointCollection/MethodIssuerEndpointCollection.php index ee28f3bd..a5e0398f 100644 --- a/src/EndpointCollection/MethodIssuerEndpointCollection.php +++ b/src/EndpointCollection/MethodIssuerEndpointCollection.php @@ -2,7 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\DisableMethodIssuerRequest; use Mollie\Api\Http\Requests\EnableMethodIssuerRequest; use Mollie\Api\Resources\Issuer; @@ -12,7 +12,7 @@ class MethodIssuerEndpointCollection extends EndpointCollection /** * Enable an issuer for a specific payment method. * - * @throws ApiException + * @throws RequestException */ public function enable(string $profileId, string $methodId, string $issuerId, ?string $contractId = null): Issuer { @@ -22,7 +22,7 @@ public function enable(string $profileId, string $methodId, string $issuerId, ?s /** * Disable an issuer for a specific payment method. * - * @throws ApiException + * @throws RequestException */ public function disable(string $profileId, string $methodId, string $issuerId): void { diff --git a/src/EndpointCollection/OrganizationEndpointCollection.php b/src/EndpointCollection/OrganizationEndpointCollection.php index 37e2404b..2aa0c571 100644 --- a/src/EndpointCollection/OrganizationEndpointCollection.php +++ b/src/EndpointCollection/OrganizationEndpointCollection.php @@ -2,7 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest; use Mollie\Api\Http\Requests\GetOrganizationRequest; use Mollie\Api\Resources\Organization; @@ -18,7 +18,7 @@ class OrganizationEndpointCollection extends EndpointCollection * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function get(string $id, $testmode = false): Organization { @@ -33,7 +33,7 @@ public function get(string $id, $testmode = false): Organization * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function current($testmode = false): Organization { @@ -44,7 +44,7 @@ public function current($testmode = false): Organization /** * Retrieve the partner status of the current organization. * - * @throws ApiException + * @throws RequestException */ public function partnerStatus(): Partner { diff --git a/src/EndpointCollection/PaymentCaptureEndpointCollection.php b/src/EndpointCollection/PaymentCaptureEndpointCollection.php index a59c04ac..fc96e1ad 100644 --- a/src/EndpointCollection/PaymentCaptureEndpointCollection.php +++ b/src/EndpointCollection/PaymentCaptureEndpointCollection.php @@ -2,16 +2,10 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreatePaymentCapturePayloadFactory; -use Mollie\Api\Factories\GetPaginatedPaymentCapturesQueryFactory; -use Mollie\Api\Factories\GetPaymentCaptureQueryFactory; -use Mollie\Api\Http\Data\CreatePaymentCapturePayload; -use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; -use Mollie\Api\Http\Data\GetPaymentCaptureQuery; -use Mollie\Api\Http\Requests\CreatePaymentCaptureRequest; -use Mollie\Api\Http\Requests\GetPaginatedPaymentCapturesRequest; -use Mollie\Api\Http\Requests\GetPaymentCaptureRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreatePaymentCaptureRequestFactory; +use Mollie\Api\Factories\GetPaginatedPaymentCapturesRequestFactory; +use Mollie\Api\Factories\GetPaymentCaptureRequestFactory; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; @@ -23,11 +17,9 @@ class PaymentCaptureEndpointCollection extends EndpointCollection /** * Creates a payment capture in Mollie. * - * @param array|CreatePaymentCapturePayload $payload An array containing details on the capture. - * - * @throws ApiException + * @throws RequestException */ - public function createFor(Payment $payment, $payload = [], bool $testmode = false): Capture + public function createFor(Payment $payment, array $payload = [], bool $testmode = false): Capture { return $this->createForId($payment->id, $payload, $testmode); } @@ -35,71 +27,64 @@ public function createFor(Payment $payment, $payload = [], bool $testmode = fals /** * Creates a payment capture in Mollie. * - * @param array|CreatePaymentCapturePayload $payload An array containing details on the capture. - * - * @throws ApiException + * @throws RequestException */ - public function createForId(string $paymentId, $payload = [], bool $testmode = false): Capture + public function createForId(string $paymentId, array $payload = [], bool $testmode = false): Capture { - if (! $payload instanceof CreatePaymentCapturePayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreatePaymentCapturePayloadFactory::new($payload)->create(); - } + $testmode = Utility::extractBool($payload, 'testmode', $testmode); + + $request = CreatePaymentCaptureRequestFactory::new($paymentId) + ->withPayload($payload) + ->create(); /** @var Capture */ - return $this->send((new CreatePaymentCaptureRequest($paymentId, $payload))->test($testmode)); + return $this->send($request->test($testmode)); } /** - * @param array|GetPaymentCaptureQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function getFor(Payment $payment, string $captureId, $query = [], bool $testmode = false): Capture + public function getFor(Payment $payment, string $captureId, array $query = [], bool $testmode = false): Capture { return $this->getForId($payment->id, $captureId, $query, $testmode); } /** - * @param array|GetPaymentCaptureQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function getForId(string $paymentId, string $captureId, $query = [], bool $testmode = false): Capture + public function getForId(string $paymentId, string $captureId, array $query = [], bool $testmode = false): Capture { - if (! $query instanceof GetPaymentCaptureQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaymentCaptureQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaymentCaptureRequestFactory::new($paymentId, $captureId) + ->withQuery($query) + ->create(); /** @var Capture */ - return $this->send((new GetPaymentCaptureRequest($paymentId, $captureId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** - * @param array|GetPaginatedPaymentCapturesQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Payment $payment, $query = [], bool $testmode = false): CaptureCollection + public function pageFor(Payment $payment, array $query = [], bool $testmode = false): CaptureCollection { return $this->pageForId($payment->id, $query, $testmode); } /** - * @param array|GetPaginatedPaymentCapturesQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $paymentId, $query = [], bool $testmode = false): CaptureCollection + public function pageForId(string $paymentId, array $query = [], bool $testmode = false): CaptureCollection { - if (! $query instanceof GetPaginatedPaymentCapturesQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaginatedPaymentCapturesQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaginatedPaymentCapturesRequestFactory::new($paymentId) + ->withQuery($query) + ->create(); /** @var CaptureCollection */ - return $this->send((new GetPaginatedPaymentCapturesRequest($paymentId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -132,14 +117,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedPaymentCapturesQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedPaymentCapturesRequestFactory::new($paymentId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedPaymentCapturesRequest($paymentId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentChargebackEndpointCollection.php b/src/EndpointCollection/PaymentChargebackEndpointCollection.php index fd6bbcd9..37144766 100644 --- a/src/EndpointCollection/PaymentChargebackEndpointCollection.php +++ b/src/EndpointCollection/PaymentChargebackEndpointCollection.php @@ -2,13 +2,9 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedPaymentChargebacksQueryFactory; -use Mollie\Api\Factories\GetPaymentChargebackQueryFactory; -use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; -use Mollie\Api\Http\Data\GetPaymentChargebackQuery; -use Mollie\Api\Http\Requests\GetPaginatedPaymentChargebacksRequest; -use Mollie\Api\Http\Requests\GetPaymentChargebackRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedPaymentChargebacksRequestFactory; +use Mollie\Api\Factories\GetPaymentChargebackRequestFactory; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; @@ -18,55 +14,49 @@ class PaymentChargebackEndpointCollection extends EndpointCollection { /** - * @param array|GetPaymentChargebackQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function getFor(Payment $payment, string $chargebackId, $query = [], ?bool $testmode = null): Chargeback + public function getFor(Payment $payment, string $chargebackId, array $query = [], bool $testmode = false): Chargeback { return $this->getForId($payment->id, $chargebackId, $query, $testmode); } /** - * @param array|GetPaymentChargebackQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function getForId(string $paymentId, string $chargebackId, $query = [], bool $testmode = false): Chargeback + public function getForId(string $paymentId, string $chargebackId, array $query = [], bool $testmode = false): Chargeback { - if (! $query instanceof GetPaymentChargebackQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaymentChargebackQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaymentChargebackRequestFactory::new($paymentId, $chargebackId) + ->withQuery($query) + ->create(); /** @var Chargeback */ - return $this->send((new GetPaymentChargebackRequest($paymentId, $chargebackId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** - * @param array|GetPaginatedPaymentChargebacksQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Payment $payment, $query = []): ChargebackCollection + public function pageFor(Payment $payment, array $query = []): ChargebackCollection { return $this->pageForId($payment->id, $query); } /** - * @param array|GetPaginatedPaymentChargebacksQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $paymentId, $query = [], bool $testmode = false): ChargebackCollection + public function pageForId(string $paymentId, array $query = [], bool $testmode = false): ChargebackCollection { - if (! $query instanceof GetPaginatedPaymentChargebacksQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaginatedPaymentChargebacksQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaginatedPaymentChargebacksRequestFactory::new($paymentId) + ->withQuery($query) + ->create(); /** @var ChargebackCollection */ - return $this->send((new GetPaginatedPaymentChargebacksRequest($paymentId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -99,14 +89,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedPaymentChargebacksQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedPaymentChargebacksRequestFactory::new($paymentId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedPaymentChargebacksRequest($paymentId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentEndpointCollection.php b/src/EndpointCollection/PaymentEndpointCollection.php index 326737e8..01b0e9b3 100644 --- a/src/EndpointCollection/PaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentEndpointCollection.php @@ -2,28 +2,18 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreatePaymentPayloadFactory; -use Mollie\Api\Factories\CreateRefundPaymentPayloadFactory; -use Mollie\Api\Factories\GetPaymentQueryFactory; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreatePaymentRefundRequestFactory; +use Mollie\Api\Factories\CreatePaymentRequestFactory; +use Mollie\Api\Factories\GetPaymentRequestFactory; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Factories\UpdatePaymentPayloadFactory; -use Mollie\Api\Http\Data\CreatePaymentPayload; -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\Factories\UpdatePaymentRequestFactory; use Mollie\Api\Http\Requests\CancelPaymentRequest; -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; use Mollie\Api\Resources\LazyCollection; 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 @@ -33,43 +23,38 @@ class PaymentEndpointCollection extends EndpointCollection * * Will throw a ApiException if the payment id is invalid or the resource cannot be found. * - * @param array|GetPaymentQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function get(string $id, $query = [], bool $testmode = false): Payment + public function get(string $id, array $query = [], bool $testmode = false): Payment { - if (! $query instanceof GetPaymentQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaymentQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaymentRequestFactory::new($id) + ->withQuery($query) + ->create(); - return $this->send((new GetPaymentRequest($id, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** * Creates a payment in Mollie. * - * @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. + * @param array $payload An array containing details on the payment. + * @param array $query An array of strings or a single string containing the details to include. * - * @throws ApiException + * @throws RequestException */ - public function create($payload = [], $query = [], bool $testmode = false): Payment + public function create(array $payload = [], array $query = [], bool $testmode = false): Payment { - if (! $payload instanceof CreatePaymentPayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreatePaymentPayloadFactory::new($payload) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); - if (! $query instanceof CreatePaymentQuery) { - $query = CreatePaymentQuery::fromArray(Arr::wrap($query)); - } + $request = CreatePaymentRequestFactory::new() + ->withPayload($payload) + ->withQuery($query) + ->create(); /** @var Payment */ - return $this->send((new CreatePaymentRequest($payload, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -77,21 +62,18 @@ public function create($payload = [], $query = [], bool $testmode = false): Paym * * Will throw a ApiException if the payment id is invalid or the resource cannot be found. * - * @param string $id - * @param array|UpdatePaymentPayload $data - * - * @throws ApiException + * @throws RequestException */ - public function update($id, $data = [], bool $testmode = false): ?Payment + public function update(string $id, array $data = [], bool $testmode = false): ?Payment { - if (! $data instanceof UpdatePaymentPayload) { - $testmode = Utility::extractBool($data, 'testmode', $testmode); - $data = UpdatePaymentPayloadFactory::new($data) - ->create(); - } + $testmode = Utility::extractBool($data, 'testmode', $testmode); + + $request = UpdatePaymentRequestFactory::new($id) + ->withPayload($data) + ->create(); /** @var null|Payment */ - return $this->send((new UpdatePaymentRequest($id, $data))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -100,8 +82,7 @@ public function update($id, $data = [], bool $testmode = false): ?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 + * @throws RequestException */ public function delete(string $id, $data = []): ?Payment { @@ -116,7 +97,7 @@ public function delete(string $id, $data = []): ?Payment * * @param array|bool $testmode * - * @throws ApiException + * @throws RequestException */ public function cancel(string $id, $testmode = false): ?Payment { @@ -132,22 +113,18 @@ public function cancel(string $id, $testmode = false): ?Payment * The $data parameter may either be an array of endpoint * parameters, or an instance of CreateRefundPaymentData. * - * @param array|CreateRefundPaymentPayload $payload * - * @throws ApiException + * @throws RequestException */ - public function refund(Payment $payment, $payload = [], bool $testmode = false): Refund + public function refund(Payment $payment, array $payload = [], bool $testmode = false): Refund { - if (! $payload instanceof CreateRefundPaymentPayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreateRefundPaymentPayloadFactory::new($payload) - ->create(); - } - - return $this->send((new CreatePaymentRefundRequest( - $payment->id, - $payload - ))->test($testmode)); + $testmode = Utility::extractBool($payload, 'testmode', $testmode); + + $request = CreatePaymentRefundRequestFactory::new($payment->id) + ->withPayload($payload) + ->create(); + + return $this->send($request->test($testmode)); } /** @@ -156,13 +133,20 @@ public function refund(Payment $payment, $payload = [], bool $testmode = false): public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = SortablePaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - return $this->send((new GetPaginatedPaymentsRequest($query))->test($testmode)); + $query = SortablePaginatedQueryFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); + + return $this->send((new GetPaginatedPaymentsRequest( + $query->from, + $query->limit, + $query->sort, + ))->test($testmode)); } /** @@ -174,14 +158,21 @@ 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 = Utility::extractBool($filters, 'testmode', false); - $query = SortablePaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $query = SortablePaginatedQueryFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedPaymentsRequest($query)) + (new GetPaginatedPaymentsRequest( + $query->from, + $query->limit, + $query->sort, + )) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentLinkEndpointCollection.php b/src/EndpointCollection/PaymentLinkEndpointCollection.php index c609f79a..2bf09076 100644 --- a/src/EndpointCollection/PaymentLinkEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkEndpointCollection.php @@ -2,17 +2,12 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreatePaymentLinkPayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdatePaymentLinkPayloadFactory; -use Mollie\Api\Http\Data\CreatePaymentLinkPayload; -use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; -use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreatePaymentLinkRequestFactory; +use Mollie\Api\Factories\UpdatePaymentLinkRequestFactory; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest; use Mollie\Api\Http\Requests\GetPaymentLinkRequest; -use Mollie\Api\Http\Requests\UpdatePaymentLinkRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Resources\PaymentLinkCollection; @@ -23,18 +18,16 @@ class PaymentLinkEndpointCollection extends EndpointCollection /** * Creates a payment link in Mollie. * - * @param array|CreatePaymentLinkPayload $payload An array containing details on the payment link. - * - * @throws ApiException + * @throws RequestException */ - public function create($payload = []): PaymentLink + public function create(array $payload = []): PaymentLink { - if (! $payload instanceof CreatePaymentLinkPayload) { - $payload = CreatePaymentLinkPayloadFactory::new($payload)->create(); - } + $request = CreatePaymentLinkRequestFactory::new() + ->withPayload($payload) + ->create(); /** @var PaymentLink */ - return $this->send(new CreatePaymentLinkRequest($payload)); + return $this->send($request); } /** @@ -44,7 +37,7 @@ public function create($payload = []): PaymentLink * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function get(string $paymentLinkId, $testmode = false): PaymentLink { @@ -57,25 +50,22 @@ public function get(string $paymentLinkId, $testmode = false): PaymentLink /** * Update a Payment Link. * - * @param array|UpdatePaymentLinkPayload $payload - * - * @throws ApiException + * @throws RequestException */ - public function update(string $paymentLinkId, $payload = [], bool $testmode = false): PaymentLink + public function update(string $paymentLinkId, array $payload = [], bool $testmode = false): PaymentLink { - if (! $payload instanceof UpdatePaymentLinkPayload) { - $payload = UpdatePaymentLinkPayloadFactory::new($payload)->create(); - } + $request = UpdatePaymentLinkRequestFactory::new($paymentLinkId) + ->withPayload($payload) + ->create(); /** @var PaymentLink */ - return $this->send((new UpdatePaymentLinkRequest($paymentLinkId, $payload))->test($testmode)); + return $this->send($request->test($testmode)); } /** * Delete a Payment Link. * - * - * @throws ApiException + * @throws RequestException */ public function delete(string $paymentLinkId, bool $testmode = false): void { @@ -88,19 +78,17 @@ public function delete(string $paymentLinkId, bool $testmode = false): void * @param string|null $from The first payment link ID you want to include in your list. * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, $testmode = false): PaymentLinkCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - /** @var PaymentLinkCollection */ - return $this->send((new GetPaginatedPaymentLinksRequest($query))->test($testmode)); + return $this->send( + (new GetPaginatedPaymentLinksRequest($from, $limit)) + ->test($testmode) + ); } /** @@ -116,13 +104,9 @@ public function iterator( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); return $this->send( - (new GetPaginatedPaymentLinksRequest($query)) + (new GetPaginatedPaymentLinksRequest($from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php index dbe1c4c7..d147b3a4 100644 --- a/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php +++ b/src/EndpointCollection/PaymentLinkPaymentEndpointCollection.php @@ -2,11 +2,10 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; 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; @@ -18,7 +17,7 @@ class PaymentLinkPaymentEndpointCollection extends EndpointCollection * * @param string|null $from The first payment ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { @@ -30,11 +29,12 @@ public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $li * * @param string|null $from The first payment ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection { $testmode = Utility::extractBool($filters, 'testmode', false); + $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -42,7 +42,10 @@ public function pageForId(string $paymentLinkId, ?string $from = null, ?int $lim ])->create(); /** @var PaymentCollection */ - return $this->send((new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query))->test($testmode)); + return $this->send( + (new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $from, $limit, $query->sort)) + ->test($testmode) + ); } /** @@ -81,6 +84,7 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); + $query = SortablePaginatedQueryFactory::new([ 'from' => $from, 'limit' => $limit, @@ -88,7 +92,7 @@ public function iteratorForId( ])->create(); return $this->send( - (new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query)) + (new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $from, $limit, $query->sort)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentRefundEndpointCollection.php b/src/EndpointCollection/PaymentRefundEndpointCollection.php index 44952206..953b4df1 100644 --- a/src/EndpointCollection/PaymentRefundEndpointCollection.php +++ b/src/EndpointCollection/PaymentRefundEndpointCollection.php @@ -2,15 +2,10 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Factories\CreateRefundPaymentPayloadFactory; -use Mollie\Api\Factories\GetPaginatedPaymentRefundQueryFactory; -use Mollie\Api\Factories\GetPaymentRefundQueryFactory; -use Mollie\Api\Http\Data\CreateRefundPaymentPayload; -use Mollie\Api\Http\Data\GetPaymentRefundQuery; +use Mollie\Api\Factories\CreatePaymentRefundRequestFactory; +use Mollie\Api\Factories\GetPaginatedPaymentRefundsRequestFactory; +use Mollie\Api\Factories\GetPaymentRefundRequestFactory; use Mollie\Api\Http\Requests\CancelPaymentRefundRequest; -use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; -use Mollie\Api\Http\Requests\GetPaginatedPaymentRefundsRequest; -use Mollie\Api\Http\Requests\GetPaymentRefundRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; @@ -24,7 +19,7 @@ class PaymentRefundEndpointCollection extends EndpointCollection * * @param bool|array $testmode * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function createFor(Payment $payment, array $data, $testmode = false): Refund { @@ -34,27 +29,24 @@ public function createFor(Payment $payment, array $data, $testmode = false): Ref /** * Creates a refund for a specific payment. * - * @param array|CreateRefundPaymentPayload $payload * @param bool|array $testmode * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function createForId(string $paymentId, $payload = [], $testmode = false): Refund + public function createForId(string $paymentId, array $payload = [], $testmode = false): Refund { - $testmode = Utility::extractBool($testmode, 'testmode', false); + $testmode = Utility::extractBool($payload, 'testmode', false) ?: + Utility::extractBool($testmode, 'testmode', false); - if (! $payload instanceof CreateRefundPaymentPayload) { - $testmode = Utility::extractBool($payload, 'testmode', $testmode); - $payload = CreateRefundPaymentPayloadFactory::new($payload) - ->create(); - } + $request = CreatePaymentRefundRequestFactory::new($paymentId) + ->withPayload($payload) + ->create(); - /** @var Refund */ - return $this->send((new CreatePaymentRefundRequest($paymentId, $payload))->test($testmode)); + return $this->send($request->test($testmode)); } /** - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function getFor(Payment $payment, string $refundId, array $parameters = [], bool $testmode = false): Refund { @@ -62,27 +54,25 @@ public function getFor(Payment $payment, string $refundId, array $parameters = [ } /** - * @param array|GetPaymentRefundQuery $query - * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ - public function getForId(string $paymentId, string $refundId, $query = [], bool $testmode = false): Refund + public function getForId(string $paymentId, string $refundId, array $query = [], bool $testmode = false): Refund { - if (! $query instanceof GetPaymentRefundQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaymentRefundQueryFactory::new($query) - ->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaymentRefundRequestFactory::new($paymentId, $refundId) + ->withQuery($query) + ->create(); /** @var Refund */ - return $this->send((new GetPaymentRefundRequest($paymentId, $refundId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** * @param array|bool $testmode * @return null * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function cancelForPayment(Payment $payment, string $refundId, $testmode = false) { @@ -93,7 +83,7 @@ public function cancelForPayment(Payment $payment, string $refundId, $testmode = * @param array|bool $testmode * @return null * - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function cancelForId(string $paymentId, string $refundId, $testmode = false) { @@ -103,22 +93,25 @@ public function cancelForId(string $paymentId, string $refundId, $testmode = fal } /** - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedPaymentRefundQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - return $this->send((new GetPaginatedPaymentRefundsRequest($paymentId, $query))->test($testmode)); + $request = GetPaginatedPaymentRefundsRequestFactory::new($paymentId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); + + return $this->send($request->test($testmode)); } /** - * @throws \Mollie\Api\Exceptions\ApiException + * @throws \Mollie\Api\Exceptions\RequestException */ public function pageFor(Payment $payment, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection { @@ -155,14 +148,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedPaymentRefundQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedPaymentRefundsRequestFactory::new($paymentId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedPaymentRefundsRequest($paymentId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/PaymentRouteEndpointCollection.php b/src/EndpointCollection/PaymentRouteEndpointCollection.php index 20522e3f..e683da61 100644 --- a/src/EndpointCollection/PaymentRouteEndpointCollection.php +++ b/src/EndpointCollection/PaymentRouteEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\UpdatePaymentRoutePayloadFactory; -use Mollie\Api\Http\Requests\UpdatePaymentRouteRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\UpdatePaymentRouteRequestFactory; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Route; @@ -15,7 +14,7 @@ class PaymentRouteEndpointCollection extends EndpointCollection * * @param string $releaseDate UTC datetime in ISO-8601 format when the funds will become available * - * @throws ApiException + * @throws RequestException */ public function updateReleaseDateFor(Payment $payment, string $routeId, string $releaseDate, bool $testmode = false): Route { @@ -27,15 +26,17 @@ public function updateReleaseDateFor(Payment $payment, string $routeId, string $ * * @param string $releaseDate UTC datetime when the funds will become available * - * @throws ApiException + * @throws RequestException */ public function updateReleaseDateForId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): Route { - $payload = UpdatePaymentRoutePayloadFactory::new([ - 'releaseDate' => $releaseDate, - ])->create(); + $request = UpdatePaymentRouteRequestFactory::new($paymentId, $routeId) + ->withPayload([ + 'releaseDate' => $releaseDate, + ]) + ->create(); /** @var Route */ - return $this->send((new UpdatePaymentRouteRequest($paymentId, $routeId, $payload))->test($testmode)); + return $this->send($request->test($testmode)); } } diff --git a/src/EndpointCollection/PermissionEndpointCollection.php b/src/EndpointCollection/PermissionEndpointCollection.php index f5b0eba0..366347f2 100644 --- a/src/EndpointCollection/PermissionEndpointCollection.php +++ b/src/EndpointCollection/PermissionEndpointCollection.php @@ -2,7 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\GetPermissionRequest; use Mollie\Api\Http\Requests\ListPermissionsRequest; use Mollie\Api\Resources\Permission; @@ -18,7 +18,7 @@ class PermissionEndpointCollection extends EndpointCollection * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function get(string $permissionId, $testmode = false): Permission { @@ -31,7 +31,7 @@ public function get(string $permissionId, $testmode = false): Permission /** * Retrieve all permissions from Mollie. * - * @throws ApiException + * @throws RequestException */ public function list(): PermissionCollection { diff --git a/src/EndpointCollection/ProfileEndpointCollection.php b/src/EndpointCollection/ProfileEndpointCollection.php index 5c1d2f08..2fb31ef0 100644 --- a/src/EndpointCollection/ProfileEndpointCollection.php +++ b/src/EndpointCollection/ProfileEndpointCollection.php @@ -2,17 +2,13 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateProfilePayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdateProfilePayloadFactory; -use Mollie\Api\Http\Data\CreateProfilePayload; -use Mollie\Api\Http\Data\UpdateProfilePayload; -use Mollie\Api\Http\Requests\CreateProfileRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateProfileRequestFactory; +use Mollie\Api\Factories\UpdateProfileRequestFactory; use Mollie\Api\Http\Requests\DeleteProfileRequest; +use Mollie\Api\Http\Requests\GetCurrentProfileRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; use Mollie\Api\Http\Requests\GetProfileRequest; -use Mollie\Api\Http\Requests\UpdateProfileRequest; use Mollie\Api\Resources\CurrentProfile; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Profile; @@ -24,19 +20,16 @@ class ProfileEndpointCollection extends EndpointCollection /** * Creates a Profile in Mollie. * - * @param array|CreateProfilePayload $payload An array containing details on the profile. - * - * @throws ApiException + * @throws RequestException */ - public function create($payload = []): Profile + public function create(array $payload = []): Profile { - if (! $payload instanceof CreateProfilePayload) { - $payload = CreateProfilePayloadFactory::new($payload) - ->create(); - } + $request = CreateProfileRequestFactory::new() + ->withPayload($payload) + ->create(); /** @var Profile */ - return $this->send(new CreateProfileRequest($payload)); + return $this->send($request); } /** @@ -47,7 +40,7 @@ public function create($payload = []): Profile * @param bool|array $testmode * @return Profile|CurrentProfile * - * @throws ApiException + * @throws RequestException */ public function get(string $profileId, $testmode = false): Profile { @@ -62,38 +55,29 @@ public function get(string $profileId, $testmode = false): Profile * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function getCurrent($testmode = false): CurrentProfile { $testmode = Utility::extractBool($testmode, 'testmode', false); /** @var CurrentProfile */ - return $this->send( - (new GetProfileRequest('me')) - ->setHydratableResource(CurrentProfile::class) - ->test($testmode) - ); + return $this->send((new GetCurrentProfileRequest)->test($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 $payload - * - * @throws ApiException + * @throws RequestException */ - public function update(string $profileId, $payload = []): ?Profile + public function update(string $profileId, array $payload = []): ?Profile { - if (! $payload instanceof UpdateProfilePayload) { - $payload = UpdateProfilePayloadFactory::new($payload) - ->create(); - } + $request = UpdateProfileRequestFactory::new($profileId) + ->withPayload($payload) + ->create(); /** @var Profile|null */ - return $this->send(new UpdateProfileRequest($profileId, $payload)); + return $this->send($request); } /** @@ -102,7 +86,7 @@ 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 + * @throws RequestException */ public function delete(string $profileId): void { @@ -114,17 +98,12 @@ public function delete(string $profileId): void * * @param string|null $from The first profile ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ 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)); + return $this->send(new GetPaginatedProfilesRequest($from, $limit)); } /** @@ -138,13 +117,8 @@ public function iterator( ?int $limit = null, bool $iterateBackwards = false ): LazyCollection { - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - return $this->send( - (new GetPaginatedProfilesRequest($query)) + (new GetPaginatedProfilesRequest($from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/ProfileMethodEndpointCollection.php b/src/EndpointCollection/ProfileMethodEndpointCollection.php index bf27872d..86c3b1c0 100644 --- a/src/EndpointCollection/ProfileMethodEndpointCollection.php +++ b/src/EndpointCollection/ProfileMethodEndpointCollection.php @@ -2,7 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\DisableProfileMethodRequest; use Mollie\Api\Http\Requests\EnableProfileMethodRequest; use Mollie\Api\Resources\Method; @@ -14,7 +14,7 @@ class ProfileMethodEndpointCollection extends EndpointCollection * Enable a method for the provided Profile ID. * Alias of enableForId for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function createForId(string $profileId, string $id): Method { @@ -25,7 +25,7 @@ public function createForId(string $profileId, string $id): Method * Enable a method for the provided Profile object. * Alias of enableFor for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function createFor(Profile $profile, string $id): Method { @@ -36,7 +36,7 @@ public function createFor(Profile $profile, string $id): Method * Enable a method for the current profile. * Alias of enable for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function createForCurrentProfile(string $id): Method { @@ -49,7 +49,7 @@ public function createForCurrentProfile(string $id): Method * @param string $profileId The profile's ID or 'me' for the current profile * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function enableForId(string $profileId, string $id): Method { @@ -62,7 +62,7 @@ public function enableForId(string $profileId, string $id): Method * * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function enableFor(Profile $profile, string $id): Method { @@ -74,7 +74,7 @@ public function enableFor(Profile $profile, string $id): Method * * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function enable(string $id): Method { @@ -85,7 +85,7 @@ public function enable(string $id): Method * Disable a method for the provided Profile ID. * Alias of disableForId for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function deleteForId(string $profileId, string $id): void { @@ -96,7 +96,7 @@ public function deleteForId(string $profileId, string $id): void * Disable a method for the provided Profile object. * Alias of disableFor for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function deleteFor(Profile $profile, string $id): void { @@ -107,7 +107,7 @@ public function deleteFor(Profile $profile, string $id): void * Disable a method for the current profile. * Alias of disable for backwards compatibility. * - * @throws ApiException + * @throws RequestException */ public function deleteForCurrentProfile(string $id): void { @@ -120,7 +120,7 @@ public function deleteForCurrentProfile(string $id): void * @param string $profileId The profile's ID or 'me' for the current profile * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function disableForId(string $profileId, string $id): void { @@ -132,7 +132,7 @@ public function disableForId(string $profileId, string $id): void * * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function disableFor(Profile $profile, string $id): void { @@ -144,7 +144,7 @@ public function disableFor(Profile $profile, string $id): void * * @param string $id The payment method ID * - * @throws ApiException + * @throws RequestException */ public function disable(string $id): void { diff --git a/src/EndpointCollection/RefundEndpointCollection.php b/src/EndpointCollection/RefundEndpointCollection.php index 2cfa43a2..03a7ce1b 100644 --- a/src/EndpointCollection/RefundEndpointCollection.php +++ b/src/EndpointCollection/RefundEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedRefundsQueryFactory; -use Mollie\Api\Http\Requests\GetPaginatedRefundsRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedRefundsRequestFactory; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Utils\Utility; @@ -16,19 +15,22 @@ class RefundEndpointCollection extends EndpointCollection * * @param string|null $from The first refund ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): RefundCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedRefundsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedRefundsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); /** @var RefundCollection */ - return $this->send((new GetPaginatedRefundsRequest($query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -44,14 +46,17 @@ public function iterator( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedRefundsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedRefundsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedRefundsRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SalesInvoiceEndpointCollection.php b/src/EndpointCollection/SalesInvoiceEndpointCollection.php index d2e12134..db41431d 100644 --- a/src/EndpointCollection/SalesInvoiceEndpointCollection.php +++ b/src/EndpointCollection/SalesInvoiceEndpointCollection.php @@ -2,17 +2,12 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateSalesInvoicePayloadFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdateSalesInvoicePayloadFactory; -use Mollie\Api\Http\Data\CreateSalesInvoicePayload; -use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; -use Mollie\Api\Http\Requests\CreateSalesInvoiceRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateSalesInvoiceRequestFactory; +use Mollie\Api\Factories\UpdateSalesInvoiceRequestFactory; use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest; use Mollie\Api\Http\Requests\GetPaginatedSalesInvoicesRequest; use Mollie\Api\Http\Requests\GetSalesInvoiceRequest; -use Mollie\Api\Http\Requests\UpdateSalesInvoiceRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Resources\SalesInvoiceCollection; @@ -22,7 +17,7 @@ class SalesInvoiceEndpointCollection extends EndpointCollection /** * Retrieve a SalesInvoice from Mollie. * - * @throws ApiException + * @throws RequestException */ public function get(string $id): SalesInvoice { @@ -32,37 +27,35 @@ public function get(string $id): SalesInvoice /** * Creates a SalesInvoice in Mollie. * - * @param array|CreateSalesInvoicePayload $payload - * - * @throws ApiException + * @throws RequestException */ - public function create($payload = []): SalesInvoice + public function create(array $payload = []): SalesInvoice { - if (! $payload instanceof CreateSalesInvoicePayload) { - $payload = CreateSalesInvoicePayloadFactory::new($payload)->create(); - } + $request = CreateSalesInvoiceRequestFactory::new() + ->withPayload($payload) + ->create(); - return $this->send(new CreateSalesInvoiceRequest($payload)); + return $this->send($request); } /** * Update a specific SalesInvoice resource. * - * @throws ApiException + * @throws RequestException */ - public function update(string $id, $payload = []): ?SalesInvoice + public function update(string $id, array $payload = []): ?SalesInvoice { - if (! $payload instanceof UpdateSalesInvoicePayload) { - $payload = UpdateSalesInvoicePayloadFactory::new($payload)->create(); - } + $request = UpdateSalesInvoiceRequestFactory::new($id) + ->withPayload($payload) + ->create(); - return $this->send(new UpdateSalesInvoiceRequest($id, $payload)); + return $this->send($request); } /** * Delete a SalesInvoice from Mollie. * - * @throws ApiException + * @throws RequestException */ public function delete(string $id): void { @@ -72,16 +65,11 @@ public function delete(string $id): void /** * Retrieves a collection of SalesInvoices from Mollie. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null): SalesInvoiceCollection { - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - - return $this->send(new GetPaginatedSalesInvoicesRequest($query)); + return $this->send(new GetPaginatedSalesInvoicesRequest($from, $limit)); } /** @@ -95,13 +83,8 @@ public function iterator( ?int $limit = null, bool $iterateBackwards = false ): LazyCollection { - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - return $this->send( - (new GetPaginatedSalesInvoicesRequest($query)) + (new GetPaginatedSalesInvoicesRequest($from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/SessionEndpointCollection.php b/src/EndpointCollection/SessionEndpointCollection.php index 1dd47cf1..5a5e2caf 100644 --- a/src/EndpointCollection/SessionEndpointCollection.php +++ b/src/EndpointCollection/SessionEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Requests\CancelSessionRequest; use Mollie\Api\Http\Requests\CreateSessionRequest; use Mollie\Api\Http\Requests\GetPaginatedSessionsRequest; @@ -13,48 +12,39 @@ use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Session; use Mollie\Api\Resources\SessionCollection; +use Mollie\Api\Utils\Arr; class SessionEndpointCollection extends EndpointCollection { /** * Retrieve a single session from Mollie. * - * Will throw a ApiException if the session id is invalid or the resource cannot be found. - * - * @param array|AnyData $query - * - * @throws ApiException + * @throws RequestException */ - public function get(string $sessionId, $query = []): Session + public function get(string $sessionId, array $query = []): Session { - if (! $query instanceof AnyData) { - $query = AnyData::fromArray($query); - } + $request = new GetSessionRequest($sessionId); + + $request->query()->set($query); /** @var Session */ - return $this->send(new GetSessionRequest($sessionId, $query)); + return $this->send($request); } /** * Creates a session in Mollie. * - * @param array|AnyData $payload - * @param array|AnyData $query - * - * @throws ApiException + * @throws RequestException */ - public function create($payload = [], $query = []): Session + public function create(array $payload = [], array $query = []): Session { - if (! $payload instanceof AnyData) { - $payload = AnyData::fromArray($payload); - } + $request = new CreateSessionRequest; - if (! $query instanceof AnyData) { - $query = AnyData::fromArray($query); - } + $request->payload()->set($payload); + $request->query()->set($query); /** @var Session */ - return $this->send(new CreateSessionRequest($payload, $query)); + return $this->send($request); } /** @@ -62,18 +52,18 @@ public function create($payload = [], $query = []): Session * * Will throw a ApiException if the session id is invalid or the resource cannot be found. * - * @param array|AnyData $payload + * @param array $payload * - * @throws ApiException + * @throws RequestException */ - public function update(string $id, $payload = []): Session + public function update(string $id, array $payload = []): Session { - if (! $payload instanceof AnyData) { - $payload = AnyData::fromArray($payload); - } + $request = new UpdateSessionRequest($id); + + $request->payload()->set($payload); /** @var Session */ - return $this->send(new UpdateSessionRequest($id, $payload)); + return $this->send($request); } /** @@ -81,7 +71,7 @@ public function update(string $id, $payload = []): Session * * Will throw a ApiException if the session id is invalid or the resource cannot be found. * - * @throws ApiException + * @throws RequestException */ public function cancel(string $id): void { @@ -93,7 +83,7 @@ public function cancel(string $id): void * * @param string|null $from The first session ID you want to include in your list. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): SessionCollection { @@ -103,8 +93,14 @@ public function page(?string $from = null, ?int $limit = null, array $filters = 'filters' => $filters, ])->create(); + $request = new GetPaginatedSessionsRequest($query->from, $query->limit, $query->sort); + + foreach (Arr::except($filters, 'sort') as $key => $value) { + $request->query()->add($key, $value); + } + /** @var SessionCollection */ - return $this->send(new GetPaginatedSessionsRequest($query)); + return $this->send($request); } /** @@ -125,8 +121,14 @@ public function iterator( 'filters' => $filters, ])->create(); + $request = new GetPaginatedSessionsRequest($query->from, $query->limit, $query->sort); + + foreach (Arr::except($filters, 'sort') as $key => $value) { + $request->query()->add($key, $value); + } + return $this->send( - (new GetPaginatedSessionsRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/SettlementCaptureEndpointCollection.php b/src/EndpointCollection/SettlementCaptureEndpointCollection.php index aea502db..28dcd9fa 100644 --- a/src/EndpointCollection/SettlementCaptureEndpointCollection.php +++ b/src/EndpointCollection/SettlementCaptureEndpointCollection.php @@ -2,10 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedSettlementCapturesQueryFactory; -use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; -use Mollie\Api\Http\Requests\GetPaginatedSettlementCapturesRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedSettlementCapturesRequestFactory; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; @@ -16,11 +14,9 @@ class SettlementCaptureEndpointCollection extends EndpointCollection /** * Retrieves a collection of Settlement Captures from Mollie. * - * @param array|GetPaginatedSettlementCapturesQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Settlement $settlement, $query = [], bool $testmode = false): CaptureCollection + public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): CaptureCollection { return $this->pageForId($settlement->id, $query, $testmode); } @@ -28,19 +24,18 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa /** * Retrieves a collection of Settlement Captures from Mollie. * - * @param array|GetPaginatedSettlementCapturesQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $settlementId, $query = [], bool $testmode = false): CaptureCollection + public function pageForId(string $settlementId, array $query = [], bool $testmode = false): CaptureCollection { - if (! $query instanceof GetPaginatedSettlementCapturesQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaginatedSettlementCapturesQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaginatedSettlementCapturesRequestFactory::new($settlementId) + ->withQuery($query) + ->create(); /** @var CaptureCollection */ - return $this->send((new GetPaginatedSettlementCapturesRequest($settlementId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -73,14 +68,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedSettlementCapturesQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedSettlementCapturesRequestFactory::new($settlementId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedSettlementCapturesRequest($settlementId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SettlementChargebackEndpointCollection.php b/src/EndpointCollection/SettlementChargebackEndpointCollection.php index 78651f22..90c66ce1 100644 --- a/src/EndpointCollection/SettlementChargebackEndpointCollection.php +++ b/src/EndpointCollection/SettlementChargebackEndpointCollection.php @@ -2,10 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedSettlementChargebacksQueryFactory; -use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; -use Mollie\Api\Http\Requests\GetPaginatedSettlementChargebacksRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedSettlementChargebacksRequestFactory; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; @@ -16,11 +14,9 @@ class SettlementChargebackEndpointCollection extends EndpointCollection /** * Retrieves a collection of Settlement Chargebacks from Mollie. * - * @param array|GetPaginatedSettlementChargebacksQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Settlement $settlement, $query = [], bool $testmode = false): ChargebackCollection + public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): ChargebackCollection { return $this->pageForId($settlement->id, $query, $testmode); } @@ -28,19 +24,18 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa /** * Retrieves a collection of Settlement Chargebacks from Mollie. * - * @param array|GetPaginatedSettlementChargebacksQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $settlementId, $query = [], bool $testmode = false): ChargebackCollection + public function pageForId(string $settlementId, array $query = [], bool $testmode = false): ChargebackCollection { - if (! $query instanceof GetPaginatedSettlementChargebacksQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaginatedSettlementChargebacksQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + + $request = GetPaginatedSettlementChargebacksRequestFactory::new($settlementId) + ->withQuery($query) + ->create(); /** @var ChargebackCollection */ - return $this->send((new GetPaginatedSettlementChargebacksRequest($settlementId, $query))->test($testmode)); + return $this->send($request->test($testmode)); } /** @@ -73,14 +68,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedSettlementChargebacksQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedSettlementChargebacksRequestFactory::new($settlementId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedSettlementChargebacksRequest($settlementId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SettlementEndpointCollection.php b/src/EndpointCollection/SettlementEndpointCollection.php index c24f96e6..5ce1dcdd 100644 --- a/src/EndpointCollection/SettlementEndpointCollection.php +++ b/src/EndpointCollection/SettlementEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\GetPaginatedSettlementsQueryFactory; -use Mollie\Api\Http\Requests\GetPaginatedSettlementsRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\GetPaginatedSettlementsRequestFactory; use Mollie\Api\Http\Requests\GetSettlementRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Settlement; @@ -17,7 +16,7 @@ class SettlementEndpointCollection extends EndpointCollection * * Will throw a ApiException if the settlement id is invalid or the resource cannot be found. * - * @throws ApiException + * @throws RequestException */ public function get(string $settlementId): Settlement { @@ -27,7 +26,7 @@ public function get(string $settlementId): Settlement /** * Retrieve the details of the current settlement that has not yet been paid out. * - * @throws ApiException + * @throws RequestException */ public function next(): Settlement { @@ -37,7 +36,7 @@ public function next(): Settlement /** * Retrieve the details of the open balance of the organization. * - * @throws ApiException + * @throws RequestException */ public function open(): Settlement { @@ -47,17 +46,19 @@ public function open(): Settlement /** * Retrieves a collection of Settlements from Mollie. * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection { - $query = GetPaginatedSettlementsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedSettlementsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); - return $this->send(new GetPaginatedSettlementsRequest($query)); + return $this->send($request); } /** @@ -65,14 +66,16 @@ 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 { - $query = GetPaginatedSettlementsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + $request = GetPaginatedSettlementsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedSettlementsRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ); diff --git a/src/EndpointCollection/SettlementPaymentEndpointCollection.php b/src/EndpointCollection/SettlementPaymentEndpointCollection.php index f5866b2f..78f9eeb0 100644 --- a/src/EndpointCollection/SettlementPaymentEndpointCollection.php +++ b/src/EndpointCollection/SettlementPaymentEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Factories\SortablePaginatedQueryFactory; -use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; @@ -16,11 +15,9 @@ class SettlementPaymentEndpointCollection extends EndpointCollection /** * Retrieves a collection of Settlement Payments from Mollie. * - * @param array|SortablePaginatedQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Settlement $settlement, $query = [], bool $testmode = false): PaymentCollection + public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): PaymentCollection { return $this->pageForId($settlement->id, $query, $testmode); } @@ -28,18 +25,22 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa /** * Retrieves a collection of Settlement Payments from Mollie. * - * @param array|SortablePaginatedQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $settlementId, $query = [], bool $testmode = false): PaymentCollection + public function pageForId(string $settlementId, array $query = [], bool $testmode = false): PaymentCollection { - if (! $query instanceof SortablePaginatedQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = SortablePaginatedQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); + $query = SortablePaginatedQueryFactory::new($query)->create(); - return $this->send((new GetPaginatedSettlementPaymentsRequest($settlementId, $query))->test($testmode)); + return $this->send( + (new GetPaginatedSettlementPaymentsRequest( + $settlementId, + $query->from, + $query->limit, + $query->sort + )) + ->test($testmode) + ); } /** @@ -70,7 +71,12 @@ public function iteratorForId( ])->create(); return $this->send( - (new GetPaginatedSettlementPaymentsRequest($settlementId, $query)) + (new GetPaginatedSettlementPaymentsRequest( + $settlementId, + $query->from, + $query->limit, + $query->sort + )) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SettlementRefundEndpointCollection.php b/src/EndpointCollection/SettlementRefundEndpointCollection.php index 26368fa8..0e7ccbd2 100644 --- a/src/EndpointCollection/SettlementRefundEndpointCollection.php +++ b/src/EndpointCollection/SettlementRefundEndpointCollection.php @@ -2,10 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Factories\GetPaginatedSettlementRefundsQueryFactory; -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; @@ -16,11 +14,9 @@ class SettlementRefundEndpointCollection extends EndpointCollection /** * Retrieves a collection of Settlement Refunds from Mollie. * - * @param array|GetPaginatedSettlementRefundsQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageFor(Settlement $settlement, $query = [], bool $testmode = false): RefundCollection + public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): RefundCollection { return $this->pageForId($settlement->id, $query, $testmode); } @@ -28,18 +24,17 @@ public function pageFor(Settlement $settlement, $query = [], bool $testmode = fa /** * Retrieves a collection of Settlement Refunds from Mollie. * - * @param array|GetPaginatedSettlementRefundsQuery $query - * - * @throws ApiException + * @throws RequestException */ - public function pageForId(string $settlementId, $query = [], bool $testmode = false): RefundCollection + public function pageForId(string $settlementId, array $query = [], bool $testmode = false): RefundCollection { - if (! $query instanceof GetPaginatedSettlementRefundsQuery) { - $testmode = Utility::extractBool($query, 'testmode', $testmode); - $query = GetPaginatedSettlementRefundsQueryFactory::new($query)->create(); - } + $testmode = Utility::extractBool($query, 'testmode', $testmode); - return $this->send((new GetPaginatedSettlementRefundsRequest($settlementId, $query))->test($testmode)); + $request = GetPaginatedSettlementRefundsQueryFactory::new($settlementId) + ->withQuery($query) + ->create(); + + return $this->send($request->test($testmode)); } /** @@ -66,14 +61,17 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetPaginatedSettlementRefundsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetPaginatedSettlementRefundsQueryFactory::new($settlementId) + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetPaginatedSettlementRefundsRequest($settlementId, $query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SubscriptionEndpointCollection.php b/src/EndpointCollection/SubscriptionEndpointCollection.php index 355e645d..eceec0c7 100644 --- a/src/EndpointCollection/SubscriptionEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionEndpointCollection.php @@ -2,19 +2,13 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\CreateSubscriptionPayloadFactory; -use Mollie\Api\Factories\GetAllPaginatedSubscriptionsQueryFactory; -use Mollie\Api\Factories\PaginatedQueryFactory; -use Mollie\Api\Factories\UpdateSubscriptionPayloadFactory; -use Mollie\Api\Http\Data\CreateSubscriptionPayload; -use Mollie\Api\Http\Data\UpdateSubscriptionPayload; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\CreateSubscriptionRequestFactory; +use Mollie\Api\Factories\GetAllPaginatedSubscriptionsRequestFactory; +use Mollie\Api\Factories\UpdateSubscriptionRequestFactory; use Mollie\Api\Http\Requests\CancelSubscriptionRequest; -use Mollie\Api\Http\Requests\CreateSubscriptionRequest; -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\Resources\Customer; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\Subscription; @@ -28,7 +22,7 @@ class SubscriptionEndpointCollection extends EndpointCollection * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function getFor(Customer $customer, string $subscriptionId, $testmode = false): Subscription { @@ -40,7 +34,7 @@ public function getFor(Customer $customer, string $subscriptionId, $testmode = f * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function getForId(string $customerId, string $subscriptionId, $testmode = false): Subscription { @@ -52,53 +46,49 @@ public function getForId(string $customerId, string $subscriptionId, $testmode = /** * Creates a subscription for a Customer in Mollie. * - * @param array|CreateSubscriptionPayload $data An array containing details on the subscription. - * - * @throws ApiException + * @throws RequestException */ - public function createFor(Customer $customer, $data = [], bool $testmode = false): Subscription + public function createFor(Customer $customer, array $payload = [], bool $testmode = false): Subscription { - return $this->createForId($customer->id, $data, $testmode); + return $this->createForId($customer->id, $payload, $testmode); } /** * Creates a subscription for a Customer in Mollie. * - * @param array|CreateSubscriptionPayload $data An array containing details on the subscription. - * - * @throws ApiException + * @throws RequestException */ - public function createForId(string $customerId, $data = [], bool $testmode = false): Subscription + public function createForId(string $customerId, array $payload = [], bool $testmode = false): Subscription { - if (! $data instanceof CreateSubscriptionPayload) { - $testmode = Utility::extractBool($data, 'testmode', $testmode); - $data = CreateSubscriptionPayloadFactory::new($data)->create(); - } + $testmode = Utility::extractBool($payload, 'testmode', $testmode); - return $this->send((new CreateSubscriptionRequest($customerId, $data))->test($testmode)); + $request = CreateSubscriptionRequestFactory::new($customerId) + ->withPayload($payload) + ->create(); + + return $this->send($request->test($testmode)); } /** * Update the given Subscription. * - * @param array|UpdateSubscriptionPayload $data - * - * @throws ApiException + * @throws RequestException */ - public function update(string $customerId, string $subscriptionId, $data = [], bool $testmode = false): ?Subscription + public function update(string $customerId, string $subscriptionId, array $payload = [], bool $testmode = false): ?Subscription { - if (! $data instanceof UpdateSubscriptionPayload) { - $testmode = Utility::extractBool($data, 'testmode', $testmode); - $data = UpdateSubscriptionPayloadFactory::new($data)->create(); - } + $testmode = Utility::extractBool($payload, 'testmode', $testmode); - return $this->send((new UpdateSubscriptionRequest($customerId, $subscriptionId, $data))->test($testmode)); + $request = UpdateSubscriptionRequestFactory::new($customerId, $subscriptionId) + ->withPayload($payload) + ->create(); + + return $this->send($request->test($testmode)); } /** * Cancel the given Subscription. * - * @throws ApiException + * @throws RequestException */ public function cancelFor(Customer $customer, string $subscriptionId, bool $testmode = false): ?Subscription { @@ -108,7 +98,7 @@ public function cancelFor(Customer $customer, string $subscriptionId, bool $test /** * Cancel the given Subscription. * - * @throws ApiException + * @throws RequestException */ public function cancelForId(string $customerId, string $subscriptionId, bool $testmode = false): ?Subscription { @@ -118,7 +108,7 @@ public function cancelForId(string $customerId, string $subscriptionId, bool $te /** * Retrieve a page of subscriptions from Mollie. * - * @throws ApiException + * @throws RequestException */ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection { @@ -128,17 +118,13 @@ public function pageFor(Customer $customer, ?string $from = null, ?int $limit = /** * Retrieve a page of subscriptions from Mollie. * - * @throws ApiException + * @throws RequestException */ public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - return $this->send((new GetPaginatedSubscriptionsRequest($customerId, $query))->test($testmode)); + return $this->send((new GetPaginatedSubscriptionsRequest($customerId, $from, $limit))->test($testmode)); } /** @@ -165,13 +151,9 @@ public function iteratorForId( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); return $this->send( - (new GetPaginatedSubscriptionsRequest($customerId, $query)) + (new GetPaginatedSubscriptionsRequest($customerId, $from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) @@ -189,13 +171,16 @@ public function allForId( array $filters = [] ): SubscriptionCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetAllPaginatedSubscriptionsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); - return $this->send((new GetAllPaginatedSubscriptionsRequest($query))->test($testmode)); + $request = GetAllPaginatedSubscriptionsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); + + return $this->send($request->test($testmode)); } public function iteratorForAll( @@ -205,14 +190,17 @@ public function iteratorForAll( bool $iterateBackwards = true ): LazyCollection { $testmode = Utility::extractBool($filters, 'testmode', false); - $query = GetAllPaginatedSubscriptionsQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - 'filters' => $filters, - ])->create(); + + $request = GetAllPaginatedSubscriptionsRequestFactory::new() + ->withQuery([ + 'from' => $from, + 'limit' => $limit, + 'filters' => $filters, + ]) + ->create(); return $this->send( - (new GetAllPaginatedSubscriptionsRequest($query)) + $request ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php index a1a51f89..fc2846d7 100644 --- a/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php +++ b/src/EndpointCollection/SubscriptionPaymentEndpointCollection.php @@ -2,8 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\PaginatedQueryFactory; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest; use Mollie\Api\Resources\LazyCollection; use Mollie\Api\Resources\PaymentCollection; @@ -19,7 +18,7 @@ class SubscriptionPaymentEndpointCollection extends EndpointCollection * @param int|null $limit The maximum amount of results you want to retrieve per page. * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function pageFor(Subscription $subscription, ?string $from = null, ?int $limit = null, $testmode = false): PaymentCollection { @@ -33,7 +32,7 @@ public function pageFor(Subscription $subscription, ?string $from = null, ?int $ * @param int|null $limit The maximum amount of results you want to retrieve per page. * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function pageForIds( string $customerId, @@ -43,12 +42,11 @@ public function pageForIds( $testmode = false ): PaymentCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); - return $this->send((new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $query))->test($testmode)); + return $this->send( + (new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $from, $limit)) + ->test($testmode) + ); } /** @@ -80,13 +78,9 @@ public function iteratorForIds( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); return $this->send( - (new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $query)) + (new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/TerminalEndpointCollection.php b/src/EndpointCollection/TerminalEndpointCollection.php index ea396b1b..9bf0ab81 100644 --- a/src/EndpointCollection/TerminalEndpointCollection.php +++ b/src/EndpointCollection/TerminalEndpointCollection.php @@ -2,8 +2,7 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\PaginatedQueryFactory; +use Mollie\Api\Exceptions\RequestException; use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest; use Mollie\Api\Http\Requests\GetTerminalRequest; use Mollie\Api\Resources\LazyCollection; @@ -20,7 +19,7 @@ class TerminalEndpointCollection extends EndpointCollection * * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function get(string $id, $testmode = false): Terminal { @@ -36,18 +35,14 @@ public function get(string $id, $testmode = false): Terminal * @param string|null $from The first terminal ID you want to include in your list. * @param bool|array $testmode * - * @throws ApiException + * @throws RequestException */ public function page(?string $from = null, ?int $limit = null, $testmode = false): TerminalCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); /** @var TerminalCollection */ - return $this->send((new GetPaginatedTerminalsRequest($query))->test($testmode)); + return $this->send((new GetPaginatedTerminalsRequest($from, $limit))->test($testmode)); } /** @@ -64,13 +59,9 @@ public function iterator( bool $iterateBackwards = false ): LazyCollection { $testmode = Utility::extractBool($testmode, 'testmode', false); - $query = PaginatedQueryFactory::new([ - 'from' => $from, - 'limit' => $limit, - ])->create(); return $this->send( - (new GetPaginatedTerminalsRequest($query)) + (new GetPaginatedTerminalsRequest($from, $limit)) ->useIterator() ->setIterationDirection($iterateBackwards) ->test($testmode) diff --git a/src/EndpointCollection/WalletEndpointCollection.php b/src/EndpointCollection/WalletEndpointCollection.php index 32f064dd..4b11582b 100644 --- a/src/EndpointCollection/WalletEndpointCollection.php +++ b/src/EndpointCollection/WalletEndpointCollection.php @@ -2,9 +2,8 @@ namespace Mollie\Api\EndpointCollection; -use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Factories\ApplePayPaymentSessionPayloadFactory; -use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest; +use Mollie\Api\Exceptions\RequestException; +use Mollie\Api\Factories\ApplePayPaymentSessionRequestFactory; use Mollie\Api\Resources\AnyResource; class WalletEndpointCollection extends EndpointCollection @@ -15,15 +14,17 @@ class WalletEndpointCollection extends EndpointCollection * @param array $parameters Additional parameters * @return AnyResource The payment session data * - * @throws ApiException + * @throws RequestException */ public function requestApplePayPaymentSession(string $domain, string $validationUrl, array $parameters = []): AnyResource { - $payload = ApplePayPaymentSessionPayloadFactory::new(array_merge([ - 'domain' => $domain, - 'validationUrl' => $validationUrl, - ], $parameters))->create(); + $request = ApplePayPaymentSessionRequestFactory::new() + ->withPayload(array_merge([ + 'domain' => $domain, + 'validationUrl' => $validationUrl, + ], $parameters)) + ->create(); - return $this->send(new ApplePayPaymentSessionRequest($payload)); + return $this->send($request); } } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index 46a0aa7a..226281ca 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -14,15 +14,18 @@ class ApiException extends RequestException { protected string $plainMessage; + protected \DateTimeImmutable $raisedAt; + /** @var array */ protected array $links = []; /** - * @param Response $response The response that caused this exception - * @param string $message The error message - * @param int $code The error code - * @param Throwable|null $previous Previous exception if any + * @param Response $response The response that caused this exception + * @param string $message The error message + * @param int $code The error code + * @param Throwable|null $previous Previous exception if any + * * @throws ApiException */ public function __construct( @@ -35,7 +38,7 @@ public function __construct( $this->raisedAt = new DateTimeImmutable; $formattedRaisedAt = $this->raisedAt->format(DateTimeImmutable::ATOM); - $message = "[{$formattedRaisedAt}] " . $message; + $message = "[{$formattedRaisedAt}] ".$message; $object = $response->json(); if (isset($object->_links)) { diff --git a/src/Exceptions/CurlInitializationException.php b/src/Exceptions/CurlInitializationException.php index bfbcb441..6d9521ca 100644 --- a/src/Exceptions/CurlInitializationException.php +++ b/src/Exceptions/CurlInitializationException.php @@ -13,6 +13,7 @@ class CurlInitializationException extends MollieException { protected PendingRequest $pendingRequest; + protected string $plainMessage; public function __construct( diff --git a/src/Exceptions/ForbiddenException.php b/src/Exceptions/ForbiddenException.php index 1d88de85..f559d172 100644 --- a/src/Exceptions/ForbiddenException.php +++ b/src/Exceptions/ForbiddenException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'Your request was understood but not allowed. ' . + 'Your request was understood but not allowed. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_FORBIDDEN, $body->title, $body->detail), ResponseStatusCode::HTTP_FORBIDDEN ); diff --git a/src/Exceptions/MethodNotAllowedException.php b/src/Exceptions/MethodNotAllowedException.php index 9d9aceea..6848d942 100644 --- a/src/Exceptions/MethodNotAllowedException.php +++ b/src/Exceptions/MethodNotAllowedException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'The HTTP method is not supported. ' . + 'The HTTP method is not supported. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_METHOD_NOT_ALLOWED, $body->title, $body->detail), ResponseStatusCode::HTTP_METHOD_NOT_ALLOWED ); diff --git a/src/Exceptions/NetworkRequestException.php b/src/Exceptions/NetworkRequestException.php index 00e2f430..12b122b6 100644 --- a/src/Exceptions/NetworkRequestException.php +++ b/src/Exceptions/NetworkRequestException.php @@ -15,6 +15,7 @@ class NetworkRequestException extends MollieException implements NetworkExceptionInterface { protected PendingRequest $pendingRequest; + protected string $plainMessage; public function __construct( diff --git a/src/Exceptions/NotFoundException.php b/src/Exceptions/NotFoundException.php index 4367abd2..0f6d4d81 100644 --- a/src/Exceptions/NotFoundException.php +++ b/src/Exceptions/NotFoundException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'The object referenced by your API request does not exist. ' . + 'The object referenced by your API request does not exist. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_NOT_FOUND, $body->title, $body->detail), ResponseStatusCode::HTTP_NOT_FOUND ); diff --git a/src/Exceptions/RequestTimeoutException.php b/src/Exceptions/RequestTimeoutException.php index 98f37eac..3b5e2389 100644 --- a/src/Exceptions/RequestTimeoutException.php +++ b/src/Exceptions/RequestTimeoutException.php @@ -16,7 +16,7 @@ public static function fromResponse(Response $response): self return new self( $response->getPendingRequest(), null, - 'The request took too long to complete. ' . + 'The request took too long to complete. '. sprintf('Error executing API call (%d: %s): %s', 408, $body->title, $body->detail) ); } diff --git a/src/Exceptions/ServiceUnavailableException.php b/src/Exceptions/ServiceUnavailableException.php index 0c885aaa..cc4f92a7 100644 --- a/src/Exceptions/ServiceUnavailableException.php +++ b/src/Exceptions/ServiceUnavailableException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'The service is temporarily unavailable. ' . + 'The service is temporarily unavailable. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_SERVICE_UNAVAILABLE, $body->title, $body->detail), ResponseStatusCode::HTTP_SERVICE_UNAVAILABLE ); diff --git a/src/Exceptions/TooManyRequestsException.php b/src/Exceptions/TooManyRequestsException.php index 5d3f5113..55e43d7b 100644 --- a/src/Exceptions/TooManyRequestsException.php +++ b/src/Exceptions/TooManyRequestsException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'Your request exceeded the rate limit. ' . + 'Your request exceeded the rate limit. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_TOO_MANY_REQUESTS, $body->title, $body->detail), ResponseStatusCode::HTTP_TOO_MANY_REQUESTS ); diff --git a/src/Exceptions/UnauthorizedException.php b/src/Exceptions/UnauthorizedException.php index 68069e5e..b48cc69c 100644 --- a/src/Exceptions/UnauthorizedException.php +++ b/src/Exceptions/UnauthorizedException.php @@ -13,7 +13,7 @@ public static function fromResponse(Response $response): self return new self( $response, - 'Your request wasn\'t executed due to failed authentication. Check your API key. ' . + 'Your request wasn\'t executed due to failed authentication. Check your API key. '. sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_UNAUTHORIZED, $body->title, $body->detail), ResponseStatusCode::HTTP_UNAUTHORIZED ); diff --git a/src/Exceptions/ValidationException.php b/src/Exceptions/ValidationException.php index 66dca401..cb21b083 100644 --- a/src/Exceptions/ValidationException.php +++ b/src/Exceptions/ValidationException.php @@ -35,7 +35,7 @@ public static function fromResponse(Response $response): self return new self( $response, $field, - 'We could not process your request due to validation errors. ' . + 'We could not process your request due to validation errors. '. sprintf('Error executing API call (%d: %s): %s', 422, $body->title, $body->detail), ResponseStatusCode::HTTP_UNPROCESSABLE_ENTITY ); diff --git a/src/Factories/ApplePayPaymentSessionPayloadFactory.php b/src/Factories/ApplePayPaymentSessionPayloadFactory.php deleted file mode 100644 index d7af8a2e..00000000 --- a/src/Factories/ApplePayPaymentSessionPayloadFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -get('domain'), - $this->get('validationUrl'), - $this->get('profileId'), - ); - } -} diff --git a/src/Factories/ApplePayPaymentSessionRequestFactory.php b/src/Factories/ApplePayPaymentSessionRequestFactory.php new file mode 100644 index 00000000..12209ec5 --- /dev/null +++ b/src/Factories/ApplePayPaymentSessionRequestFactory.php @@ -0,0 +1,17 @@ +payload('domain'), + $this->payload('validationUrl'), + $this->payload('profileId'), + ); + } +} diff --git a/src/Factories/ApplicationFeeFactory.php b/src/Factories/ApplicationFeeFactory.php index 2abf7b9f..5d83c911 100644 --- a/src/Factories/ApplicationFeeFactory.php +++ b/src/Factories/ApplicationFeeFactory.php @@ -9,8 +9,8 @@ class ApplicationFeeFactory extends Factory public function create(): ApplicationFee { return new ApplicationFee( - MoneyFactory::new($this->data['amount'])->create(), - $this->data['description'], + MoneyFactory::new($this->get('amount'))->create(), + $this->get('description'), ); } } diff --git a/src/Factories/CreateClientLinkPayloadFactory.php b/src/Factories/CreateClientLinkPayloadFactory.php deleted file mode 100644 index c8058b45..00000000 --- a/src/Factories/CreateClientLinkPayloadFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -get('owner')), - $this->get('name'), - OwnerAddress::fromArray($this->get('address')), - $this->get('registrationNumber'), - $this->get('vatNumber') - ); - } -} diff --git a/src/Factories/CreateClientLinkRequestFactory.php b/src/Factories/CreateClientLinkRequestFactory.php new file mode 100644 index 00000000..91fe268d --- /dev/null +++ b/src/Factories/CreateClientLinkRequestFactory.php @@ -0,0 +1,21 @@ +payload('owner')), + $this->payload('name'), + OwnerAddress::fromArray($this->payload('address')), + $this->payload('registrationNumber'), + $this->payload('vatNumber') + ); + } +} diff --git a/src/Factories/CreateCustomerPayloadFactory.php b/src/Factories/CreateCustomerPayloadFactory.php deleted file mode 100644 index 6390452b..00000000 --- a/src/Factories/CreateCustomerPayloadFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -get('name'), - $this->get('email'), - $this->get('locale'), - $this->mapIfNotNull('metadata', Metadata::class), - ); - } -} diff --git a/src/Factories/CreateCustomerPaymentRequestFactory.php b/src/Factories/CreateCustomerPaymentRequestFactory.php new file mode 100644 index 00000000..55d5600c --- /dev/null +++ b/src/Factories/CreateCustomerPaymentRequestFactory.php @@ -0,0 +1,57 @@ +customerId = $customerId; + } + + public function create(): CreateCustomerPaymentRequest + { + return new CreateCustomerPaymentRequest( + $this->customerId, + $this->payload('description'), + MoneyFactory::new($this->payload('amount'))->create(), + $this->payload('redirectUrl'), + $this->payload('cancelUrl'), + $this->payload('webhookUrl'), + $this + ->transformFromPayload( + 'lines', + fn ($items) => OrderLineCollectionFactory::new($items)->create() + ), + $this->transformFromPayload('billingAddress', fn ($item) => Address::fromArray($item)), + $this->transformFromPayload('shippingAddress', fn ($item) => Address::fromArray($item)), + $this->payload('locale'), + $this->payload('method'), + $this->payload('issuer'), + $this->payload('restrictPaymentMethodsToCountry'), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('captureMode'), + $this->payload('captureDelay'), + $this->transformFromPayload( + 'applicationFee', + fn ($item) => ApplicationFeeFactory::new($item)->create() + ), + $this->transformFromPayload( + 'routing', + fn ($items) => PaymentRouteCollectionFactory::new($items)->create() + ), + $this->payload('sequenceType'), + $this->payload('mandateId'), + $this->payload('profileId'), + $this->payload('additional') ?: Utility::filterByProperties(CreateCustomerPaymentRequest::class, $this->payload()) ?: [], + $this->query('includeQrCode', false) + ); + } +} diff --git a/src/Factories/CreateCustomerRequestFactory.php b/src/Factories/CreateCustomerRequestFactory.php new file mode 100644 index 00000000..d2e71ebd --- /dev/null +++ b/src/Factories/CreateCustomerRequestFactory.php @@ -0,0 +1,19 @@ +payload('name'), + $this->payload('email'), + $this->payload('locale'), + $this->transformFromPayload('metadata', Metadata::class), + ); + } +} diff --git a/src/Factories/CreateMandatePayloadFactory.php b/src/Factories/CreateMandatePayloadFactory.php deleted file mode 100644 index b339b6cd..00000000 --- a/src/Factories/CreateMandatePayloadFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -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'), - ); - } -} diff --git a/src/Factories/CreateMandateRequestFactory.php b/src/Factories/CreateMandateRequestFactory.php new file mode 100644 index 00000000..59d2f9db --- /dev/null +++ b/src/Factories/CreateMandateRequestFactory.php @@ -0,0 +1,36 @@ +customerId = $customerId; + } + + public function create(): CreateMandateRequest + { + if (! $this->payloadHas(['method', 'consumerName'])) { + throw new LogicException('Method and consumerName are required for creating a mandate'); + } + + return new CreateMandateRequest( + $this->customerId, + $this->payload('method'), + $this->payload('consumerName'), + $this->payload('consumerAccount'), + $this->payload('consumerBic'), + $this->payload('consumerEmail'), + $this->transformFromPayload('signatureDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date), DateTimeImmutable::class), + $this->payload('mandateReference'), + $this->payload('paypalBillingAgreementId'), + ); + } +} diff --git a/src/Factories/CreatePaymentCapturePayloadFactory.php b/src/Factories/CreatePaymentCapturePayloadFactory.php deleted file mode 100644 index 2e207dcc..00000000 --- a/src/Factories/CreatePaymentCapturePayloadFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -get('description'), - $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), - $this->mapIfNotNull('metadata', Metadata::class) - ); - } -} diff --git a/src/Factories/CreatePaymentCaptureRequestFactory.php b/src/Factories/CreatePaymentCaptureRequestFactory.php new file mode 100644 index 00000000..57f0ea6b --- /dev/null +++ b/src/Factories/CreatePaymentCaptureRequestFactory.php @@ -0,0 +1,26 @@ +paymentId = $paymentId; + } + + public function create(): CreatePaymentCaptureRequest + { + return new CreatePaymentCaptureRequest( + $this->paymentId, + $this->payload('description'), + $this->transformFromPayload('amount', fn ($item) => MoneyFactory::new($item)->create()), + $this->transformFromPayload('metadata', Metadata::class) + ); + } +} diff --git a/src/Factories/CreatePaymentLinkPayloadFactory.php b/src/Factories/CreatePaymentLinkPayloadFactory.php deleted file mode 100644 index 9c6eed9c..00000000 --- a/src/Factories/CreatePaymentLinkPayloadFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -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/CreatePaymentLinkRequestFactory.php b/src/Factories/CreatePaymentLinkRequestFactory.php new file mode 100644 index 00000000..3556d498 --- /dev/null +++ b/src/Factories/CreatePaymentLinkRequestFactory.php @@ -0,0 +1,23 @@ +payload('description'), + $this->transformFromPayload('amount', fn ($amount) => MoneyFactory::new($amount)->create()), + $this->payload('redirectUrl'), + $this->payload('webhookUrl'), + $this->payload('profileId'), + $this->payload('reusable'), + $this->transformFromPayload('expiresAt', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date), DateTimeImmutable::class), + $this->payload('allowedMethods'), + ); + } +} diff --git a/src/Factories/CreatePaymentPayloadFactory.php b/src/Factories/CreatePaymentPayloadFactory.php deleted file mode 100644 index c9aeaeca..00000000 --- a/src/Factories/CreatePaymentPayloadFactory.php +++ /dev/null @@ -1,49 +0,0 @@ -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') ?? Utility::filterByProperties(CreatePaymentPayload::class, $this->data), - ); - } -} diff --git a/src/Factories/CreatePaymentRefundRequestFactory.php b/src/Factories/CreatePaymentRefundRequestFactory.php new file mode 100644 index 00000000..e78283d9 --- /dev/null +++ b/src/Factories/CreatePaymentRefundRequestFactory.php @@ -0,0 +1,32 @@ +paymentId = $paymentId; + } + + public function create(): CreatePaymentRefundRequest + { + return new CreatePaymentRefundRequest( + $this->paymentId, + $this->payload('description'), + MoneyFactory::new($this->payload('amount'))->create(), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('reverseRouting'), + $this + ->transformFromPayload( + 'routingReversals', + fn ($items) => RefundRouteCollectionFactory::new($items)->create() + ), + ); + } +} diff --git a/src/Factories/CreatePaymentRequestFactory.php b/src/Factories/CreatePaymentRequestFactory.php new file mode 100644 index 00000000..4de8a8a1 --- /dev/null +++ b/src/Factories/CreatePaymentRequestFactory.php @@ -0,0 +1,50 @@ +payload('description'), + MoneyFactory::new($this->payload('amount'))->create(), + $this->payload('redirectUrl'), + $this->payload('cancelUrl'), + $this->payload('webhookUrl'), + $this + ->transformFromPayload( + 'lines', + fn ($items) => OrderLineCollectionFactory::new($items)->create() + ), + $this->transformFromPayload('billingAddress', fn ($item) => Address::fromArray($item)), + $this->transformFromPayload('shippingAddress', fn ($item) => Address::fromArray($item)), + $this->payload('locale'), + $this->payload('method'), + $this->payload('issuer'), + $this->payload('restrictPaymentMethodsToCountry'), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('captureMode'), + $this->payload('captureDelay'), + $this->transformFromPayload( + 'applicationFee', + fn ($item) => ApplicationFeeFactory::new($item)->create() + ), + $this->transformFromPayload( + 'routing', + fn ($items) => PaymentRouteCollectionFactory::new($items)->create() + ), + $this->payload('sequenceType'), + $this->payload('mandateId'), + $this->payload('customerId'), + $this->payload('profileId'), + $this->payload('additional') ?: Utility::filterByProperties(CreatePaymentRequest::class, $this->payload()) ?: [], + $this->query('includeQrCode', false) + ); + } +} diff --git a/src/Factories/CreateProfilePayloadFactory.php b/src/Factories/CreateProfilePayloadFactory.php deleted file mode 100644 index c0357b5f..00000000 --- a/src/Factories/CreateProfilePayloadFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -get('name'), - $this->get('website'), - $this->get('email'), - $this->get('phone'), - $this->get('description'), - $this->get('countriesOfActivity'), - $this->get('businessCategory') - ); - } -} diff --git a/src/Factories/CreateProfileRequestFactory.php b/src/Factories/CreateProfileRequestFactory.php new file mode 100644 index 00000000..f04ff9a7 --- /dev/null +++ b/src/Factories/CreateProfileRequestFactory.php @@ -0,0 +1,21 @@ +payload('name'), + $this->payload('website'), + $this->payload('email'), + $this->payload('phone'), + $this->payload('description'), + $this->payload('countriesOfActivity'), + $this->payload('businessCategory') + ); + } +} diff --git a/src/Factories/CreateRefundPaymentPayloadFactory.php b/src/Factories/CreateRefundPaymentPayloadFactory.php deleted file mode 100644 index 42e56184..00000000 --- a/src/Factories/CreateRefundPaymentPayloadFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -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() - ), - ); - } -} diff --git a/src/Factories/CreateSalesInvoicePayloadFactory.php b/src/Factories/CreateSalesInvoicePayloadFactory.php deleted file mode 100644 index 3d7eeb85..00000000 --- a/src/Factories/CreateSalesInvoicePayloadFactory.php +++ /dev/null @@ -1,38 +0,0 @@ -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/CreateSalesInvoiceRequestFactory.php b/src/Factories/CreateSalesInvoiceRequestFactory.php new file mode 100644 index 00000000..455b4e27 --- /dev/null +++ b/src/Factories/CreateSalesInvoiceRequestFactory.php @@ -0,0 +1,38 @@ +payload('currency'), + $this->payload('status'), + $this->payload('vatScheme'), + $this->payload('vatMode'), + $this->payload('paymentTerm'), + $this->payload('recipientIdentifier'), + RecipientFactory::new($this->payload('recipient'))->create(), + $this + ->transformFromPayload( + 'lines', + fn ($items) => InvoiceLineCollectionFactory::new($items)->create() + ), + $this->payload('profileId'), + $this->payload('memo'), + $this->transformFromPayload('paymentDetails', fn ($data) => PaymentDetails::fromArray($data)), + $this->transformFromPayload('emailDetails', fn ($data) => EmailDetails::fromArray($data)), + $this->payload('webhookUrl'), + $this->transformFromPayload('discount', fn ($data) => Discount::fromArray($data)) + ); + } +} diff --git a/src/Factories/CreateSubscriptionPayloadFactory.php b/src/Factories/CreateSubscriptionPayloadFactory.php deleted file mode 100644 index 27e7a372..00000000 --- a/src/Factories/CreateSubscriptionPayloadFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -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/CreateSubscriptionRequestFactory.php b/src/Factories/CreateSubscriptionRequestFactory.php new file mode 100644 index 00000000..cbe3f8d2 --- /dev/null +++ b/src/Factories/CreateSubscriptionRequestFactory.php @@ -0,0 +1,36 @@ +customerId = $customerId; + } + + public function create(): CreateSubscriptionRequest + { + return new CreateSubscriptionRequest( + $this->customerId, + MoneyFactory::new($this->payload('amount'))->create(), + $this->payload('interval'), + $this->payload('description'), + $this->payload('status'), + $this->payload('times'), + $this->transformFromPayload('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date), DateTimeImmutable::class), + $this->payload('method'), + $this->transformFromPayload('applicationFee', fn ($fee) => ApplicationFeeFactory::new($fee)->create()), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('webhookUrl'), + $this->payload('mandateId'), + $this->payload('profileId'), + ); + } +} diff --git a/src/Factories/Factory.php b/src/Factories/Factory.php index 0ac9262d..38903ca1 100644 --- a/src/Factories/Factory.php +++ b/src/Factories/Factory.php @@ -3,27 +3,28 @@ namespace Mollie\Api\Factories; use Mollie\Api\Contracts\Arrayable; -use Mollie\Api\Contracts\Factory as FactoryContract; use Mollie\Api\Utils\Arr; use Mollie\Api\Utils\Utility; -abstract class Factory implements FactoryContract +abstract class Factory { - protected array $data; + private array $data; - public function __construct($data) + public function __construct($data = null) { if ($data instanceof Arrayable) { $this->data = $data->toArray(); } else { - $this->data = $data; + $this->data = $data ?: []; } } - public static function new($data): self + /** + * @return static + */ + public static function new(...$args) { - /** @phpstan-ignore-next-line */ - return new static($data); + return new static(...$args); } /** @@ -32,16 +33,22 @@ public static function new($data): self * @param string|array $key * @param mixed $default */ - protected function get($key, $default = null, $backupKey = 'filters.') + protected function get($key = null, $default = null, $data = null, $backupKey = 'filters.') { + $data = $data ?? $this->data; + $keys = (array) $key; + if (empty($keys)) { + return $data; + } + if ($backupKey !== null) { $keys[] = $backupKey.$key; } foreach ($keys as $key) { - if ($value = Arr::get($this->data, $key, $default)) { + if ($value = Arr::get($data, $key, $default)) { return $value; } } @@ -49,30 +56,30 @@ protected function get($key, $default = null, $backupKey = 'filters.') return $default; } - protected function has($keys): bool + protected function has($keys, $data = null): bool { - return Arr::has($this->data, $keys); + return Arr::has($data ?? $this->data, $keys); } /** * @param string|array $key * @param mixed $value */ - protected function includes($key, $value, $backupKey = 'filters.'): bool + protected function includes($key, $value, $data = null, $backupKey = 'filters.'): bool { - return Arr::includes($this->data, [$backupKey.$key, $key], $value); + return Arr::includes($data ?? $this->data, [$backupKey.$key, $key], $value); } /** * Map a value to a new form if it is not null. * * @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. + * @param callable|string $resolver A callable function to transform the value, or the name of a class to instantiate. + * @param string $composableClass The class to instantiate if the resolver is a string. * @return mixed The transformed value, a new class instance, or null if the value is null. */ - protected function mapIfNotNull($key, $composable, $backupKey = 'filters.') + protected function transformIfNotNull($key, $resolver, $composableClass = null) { - return Utility::compose($this->get($key, null, $backupKey), $composable); + return Utility::compose($this->get($key), $resolver, $composableClass); } } diff --git a/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php b/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php deleted file mode 100644 index 23837a33..00000000 --- a/src/Factories/GetAllPaginatedSubscriptionsQueryFactory.php +++ /dev/null @@ -1,19 +0,0 @@ - $this->get('from'), - 'limit' => $this->get('limit'), - ])->create(), - $this->get('profileId') - ); - } -} diff --git a/src/Factories/GetAllPaginatedSubscriptionsRequestFactory.php b/src/Factories/GetAllPaginatedSubscriptionsRequestFactory.php new file mode 100644 index 00000000..8045f29d --- /dev/null +++ b/src/Factories/GetAllPaginatedSubscriptionsRequestFactory.php @@ -0,0 +1,17 @@ +query('limit'), + $this->query('from'), + $this->query('profileId') + ); + } +} diff --git a/src/Factories/GetAllPaymentMethodsQueryFactory.php b/src/Factories/GetAllPaymentMethodsQueryFactory.php deleted file mode 100644 index eba8e55f..00000000 --- a/src/Factories/GetAllPaymentMethodsQueryFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -includes('include', MethodQuery::INCLUDE_ISSUERS); - $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); - - return new GetAllMethodsQuery( - $this->get('includeIssuers', $includeIssuers), - $this->get('includePricing', $includePricing), - $this->get('locale'), - $this->mapIfNotNull('amount', MoneyFactory::class) - ); - } -} diff --git a/src/Factories/GetAllPaymentMethodsRequestFactory.php b/src/Factories/GetAllPaymentMethodsRequestFactory.php new file mode 100644 index 00000000..c1c9c534 --- /dev/null +++ b/src/Factories/GetAllPaymentMethodsRequestFactory.php @@ -0,0 +1,22 @@ +queryIncludes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->queryIncludes('include', MethodQuery::INCLUDE_PRICING); + + return new GetAllMethodsRequest( + $this->query('includeIssuers', $includeIssuers), + $this->query('includePricing', $includePricing), + $this->query('locale'), + $this->transformFromQuery('amount', fn ($item) => MoneyFactory::new($item)->create()) + ); + } +} diff --git a/src/Factories/GetBalanceReportQueryFactory.php b/src/Factories/GetBalanceReportQueryFactory.php deleted file mode 100644 index f0da2001..00000000 --- a/src/Factories/GetBalanceReportQueryFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -has(['from', 'until'])) { - throw new \InvalidArgumentException('The "from" and "until" fields are required.'); - } - - return new GetBalanceReportQuery( - DateTimeImmutable::createFromFormat('Y-m-d', $this->get('from')), - DateTimeImmutable::createFromFormat('Y-m-d', $this->get('until')), - $this->get('grouping'), - ); - } -} diff --git a/src/Factories/GetBalanceReportRequestFactory.php b/src/Factories/GetBalanceReportRequestFactory.php new file mode 100644 index 00000000..61b3cea3 --- /dev/null +++ b/src/Factories/GetBalanceReportRequestFactory.php @@ -0,0 +1,36 @@ +balanceId = $balanceId; + } + + public function create(): GetBalanceReportRequest + { + if (! $this->queryHas(['from', 'until'])) { + throw new \LogicException('The "from" and "until" fields are required.'); + } + + /** @var DateTimeImmutable $from */ + $from = DateTimeImmutable::createFromFormat('Y-m-d', $this->query('from')); + + /** @var DateTimeImmutable $until */ + $until = DateTimeImmutable::createFromFormat('Y-m-d', $this->query('until')); + + return new GetBalanceReportRequest( + $this->balanceId, + $from, + $until, + $this->query('grouping'), + ); + } +} diff --git a/src/Factories/GetClientQueryFactory.php b/src/Factories/GetClientQueryFactory.php deleted file mode 100644 index 7e8e47c4..00000000 --- a/src/Factories/GetClientQueryFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -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/GetClientRequestFactory.php b/src/Factories/GetClientRequestFactory.php new file mode 100644 index 00000000..3df94549 --- /dev/null +++ b/src/Factories/GetClientRequestFactory.php @@ -0,0 +1,28 @@ +id = $id; + } + + public function create(): GetClientRequest + { + $embedOrganization = $this->queryIncludes('embed', ClientQuery::EMBED_ORGANIZATION); + $embedOnboarding = $this->queryIncludes('embed', ClientQuery::EMBED_ONBOARDING); + + return new GetClientRequest( + $this->id, + $this->query('embedOrganization', $embedOrganization), + $this->query('embedOnboarding', $embedOnboarding), + ); + } +} diff --git a/src/Factories/GetEnabledMethodsRequestFactory.php b/src/Factories/GetEnabledMethodsRequestFactory.php new file mode 100644 index 00000000..9d88a902 --- /dev/null +++ b/src/Factories/GetEnabledMethodsRequestFactory.php @@ -0,0 +1,29 @@ +queryIncludes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->queryIncludes('include', MethodQuery::INCLUDE_PRICING); + + return new GetEnabledMethodsRequest( + $this->query('sequenceType', SequenceType::ONEOFF), + $this->query('resource', MethodQuery::RESOURCE_PAYMENTS), + $this->query('locale'), + $this->transformFromQuery('amount', fn ($item) => MoneyFactory::new($item)->create()), + $this->query('billingCountry'), + $this->query('includeWallets'), + $this->query('orderLineCategories', []), + $this->query('profileId'), + $this->query('includeIssuers', $includeIssuers), + $this->query('includePricing', $includePricing), + ); + } +} diff --git a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php b/src/Factories/GetEnabledPaymentMethodsQueryFactory.php deleted file mode 100644 index 073ba299..00000000 --- a/src/Factories/GetEnabledPaymentMethodsQueryFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -includes('include', MethodQuery::INCLUDE_ISSUERS); - $includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING); - - return new GetEnabledPaymentMethodsQuery( - $this->get('sequenceType', SequenceType::ONEOFF), - $this->get('resource', MethodQuery::RESOURCE_PAYMENTS), - $this->get('locale'), - $this->mapIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), - $this->get('billingCountry'), - $this->get('includeWallets'), - $this->get('orderLineCategories', []), - $this->get('profileId'), - $this->get('includeIssuers', $includeIssuers), - $this->get('includePricing', $includePricing), - ); - } -} diff --git a/src/Factories/GetPaginatedBalanceQueryFactory.php b/src/Factories/GetPaginatedBalanceQueryFactory.php deleted file mode 100644 index 438e0e8f..00000000 --- a/src/Factories/GetPaginatedBalanceQueryFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -data)->create(), - $this->get('currency') - ); - } -} diff --git a/src/Factories/GetPaginatedChargebackQueryFactory.php b/src/Factories/GetPaginatedChargebackQueryFactory.php deleted file mode 100644 index 9823d81a..00000000 --- a/src/Factories/GetPaginatedChargebackQueryFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -data)->create(), - $this->get('includePayment', false), - $this->get('profileId') - ); - } -} diff --git a/src/Factories/GetPaginatedChargebacksRequestFactory.php b/src/Factories/GetPaginatedChargebacksRequestFactory.php new file mode 100644 index 00000000..7b499c6f --- /dev/null +++ b/src/Factories/GetPaginatedChargebacksRequestFactory.php @@ -0,0 +1,21 @@ +queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedChargebacksRequest( + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment), + $this->query('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedClientQueryFactory.php b/src/Factories/GetPaginatedClientQueryFactory.php deleted file mode 100644 index 214b3262..00000000 --- a/src/Factories/GetPaginatedClientQueryFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -includes('embed', ClientQuery::EMBED_ORGANIZATION); - $embedOnboarding = $this->includes('embed', ClientQuery::EMBED_ONBOARDING); - - return new GetPaginatedClientQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('embedOrganization', $embedOrganization), - $this->get('embedOnboarding', $embedOnboarding), - ); - } -} diff --git a/src/Factories/GetPaginatedClientRequestFactory.php b/src/Factories/GetPaginatedClientRequestFactory.php new file mode 100644 index 00000000..110455d2 --- /dev/null +++ b/src/Factories/GetPaginatedClientRequestFactory.php @@ -0,0 +1,22 @@ +queryIncludes('embed', ClientQuery::EMBED_ORGANIZATION); + $embedOnboarding = $this->queryIncludes('embed', ClientQuery::EMBED_ONBOARDING); + + return new GetPaginatedClientRequest( + $this->query('from'), + $this->query('limit'), + $this->query('embedOrganization', $embedOrganization), + $this->query('embedOnboarding', $embedOnboarding), + ); + } +} diff --git a/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php b/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php deleted file mode 100644 index 1317452e..00000000 --- a/src/Factories/GetPaginatedCustomerPaymentsQueryFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -data)->create(), - $this->get('profileId') - ); - } -} diff --git a/src/Factories/GetPaginatedCustomerPaymentsRequestFactory.php b/src/Factories/GetPaginatedCustomerPaymentsRequestFactory.php new file mode 100644 index 00000000..679c4f31 --- /dev/null +++ b/src/Factories/GetPaginatedCustomerPaymentsRequestFactory.php @@ -0,0 +1,26 @@ +customerId = $customerId; + } + + public function create(): GetPaginatedCustomerPaymentsRequest + { + return new GetPaginatedCustomerPaymentsRequest( + $this->customerId, + $this->query('from'), + $this->query('limit'), + $this->query('sort'), + $this->query('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedInvoiceQueryFactory.php b/src/Factories/GetPaginatedInvoiceQueryFactory.php deleted file mode 100644 index c7cb9748..00000000 --- a/src/Factories/GetPaginatedInvoiceQueryFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -get('filters.reference'); - $year = $this->get('filters.year'); - - return new GetPaginatedInvoiceQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('reference', $reference), - $this->get('year', $year) - ); - } -} diff --git a/src/Factories/GetPaginatedInvoiceRequestFactory.php b/src/Factories/GetPaginatedInvoiceRequestFactory.php new file mode 100644 index 00000000..c936b695 --- /dev/null +++ b/src/Factories/GetPaginatedInvoiceRequestFactory.php @@ -0,0 +1,18 @@ +query('from'), + $this->query('limit'), + $this->query('reference'), + $this->query('year') + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php b/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php deleted file mode 100644 index eff146b1..00000000 --- a/src/Factories/GetPaginatedPaymentCapturesQueryFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaginatedPaymentCapturesQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('includePayments', $includePayments) - ); - } -} diff --git a/src/Factories/GetPaginatedPaymentCapturesRequestFactory.php b/src/Factories/GetPaginatedPaymentCapturesRequestFactory.php new file mode 100644 index 00000000..bd420ce3 --- /dev/null +++ b/src/Factories/GetPaginatedPaymentCapturesRequestFactory.php @@ -0,0 +1,28 @@ +paymentId = $paymentId; + } + + public function create(): GetPaginatedPaymentCapturesRequest + { + $includePayments = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedPaymentCapturesRequest( + $this->paymentId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayments', $includePayments) + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php b/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php deleted file mode 100644 index 47998792..00000000 --- a/src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaginatedPaymentChargebacksQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('includePayment', $includePayment), - ); - } -} diff --git a/src/Factories/GetPaginatedPaymentChargebacksRequestFactory.php b/src/Factories/GetPaginatedPaymentChargebacksRequestFactory.php new file mode 100644 index 00000000..fef969e6 --- /dev/null +++ b/src/Factories/GetPaginatedPaymentChargebacksRequestFactory.php @@ -0,0 +1,28 @@ +paymentId = $paymentId; + } + + public function create(): GetPaginatedPaymentChargebacksRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedPaymentChargebacksRequest( + $this->paymentId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment), + ); + } +} diff --git a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php b/src/Factories/GetPaginatedPaymentRefundQueryFactory.php deleted file mode 100644 index ecc44959..00000000 --- a/src/Factories/GetPaginatedPaymentRefundQueryFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -data)->create(), - $this->get('includePayment', false) - ); - } -} diff --git a/src/Factories/GetPaginatedPaymentRefundsRequestFactory.php b/src/Factories/GetPaginatedPaymentRefundsRequestFactory.php new file mode 100644 index 00000000..a589f4ce --- /dev/null +++ b/src/Factories/GetPaginatedPaymentRefundsRequestFactory.php @@ -0,0 +1,28 @@ +paymentId = $paymentId; + } + + public function create(): GetPaginatedPaymentRefundsRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedPaymentRefundsRequest( + $this->paymentId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment), + ); + } +} diff --git a/src/Factories/GetPaginatedRefundsQueryFactory.php b/src/Factories/GetPaginatedRefundsQueryFactory.php deleted file mode 100644 index 780ca39a..00000000 --- a/src/Factories/GetPaginatedRefundsQueryFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -includes('embed', PaymentIncludesQuery::PAYMENT); - - return new GetPaginatedRefundsQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('embedPayment', $embedPayment), - $this->get('profileId') - ); - } -} diff --git a/src/Factories/GetPaginatedRefundsRequestFactory.php b/src/Factories/GetPaginatedRefundsRequestFactory.php new file mode 100644 index 00000000..2d07abeb --- /dev/null +++ b/src/Factories/GetPaginatedRefundsRequestFactory.php @@ -0,0 +1,21 @@ +queryIncludes('embed', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedRefundsRequest( + $this->query('from'), + $this->query('limit'), + $this->query('embedPayment', $embedPayment), + $this->query('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php b/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php deleted file mode 100644 index 27e769c7..00000000 --- a/src/Factories/GetPaginatedSettlementCapturesQueryFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaginatedSettlementCapturesQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('includePayment', $includePayment) - ); - } -} diff --git a/src/Factories/GetPaginatedSettlementCapturesRequestFactory.php b/src/Factories/GetPaginatedSettlementCapturesRequestFactory.php new file mode 100644 index 00000000..6bc0c87c --- /dev/null +++ b/src/Factories/GetPaginatedSettlementCapturesRequestFactory.php @@ -0,0 +1,28 @@ +settlementId = $settlementId; + } + + public function create(): GetPaginatedSettlementCapturesRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedSettlementCapturesRequest( + $this->settlementId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment) + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php b/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php deleted file mode 100644 index 196f236e..00000000 --- a/src/Factories/GetPaginatedSettlementChargebacksQueryFactory.php +++ /dev/null @@ -1,20 +0,0 @@ -data)->create(), - $this->get('includePayment', false), - $this->get('profileId') - ); - } -} diff --git a/src/Factories/GetPaginatedSettlementChargebacksRequestFactory.php b/src/Factories/GetPaginatedSettlementChargebacksRequestFactory.php new file mode 100644 index 00000000..df05a4b0 --- /dev/null +++ b/src/Factories/GetPaginatedSettlementChargebacksRequestFactory.php @@ -0,0 +1,29 @@ +settlementId = $settlementId; + } + + public function create(): GetPaginatedSettlementChargebacksRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaginatedSettlementChargebacksRequest( + $this->settlementId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment), + $this->query('profileId') + ); + } +} diff --git a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php index 50b42c5e..ce8d9426 100644 --- a/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php +++ b/src/Factories/GetPaginatedSettlementRefundsQueryFactory.php @@ -2,18 +2,27 @@ namespace Mollie\Api\Factories; -use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; +use Mollie\Api\Http\Requests\GetPaginatedSettlementRefundsRequest; use Mollie\Api\Types\PaymentIncludesQuery; -class GetPaginatedSettlementRefundsQueryFactory extends Factory +class GetPaginatedSettlementRefundsQueryFactory extends RequestFactory { - public function create(): GetPaginatedSettlementRefundsQuery + private string $settlementId; + + public function __construct(string $settlementId) + { + $this->settlementId = $settlementId; + } + + public function create(): GetPaginatedSettlementRefundsRequest { - $includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT); + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); - return new GetPaginatedSettlementRefundsQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('includePayment', $includePayment) + return new GetPaginatedSettlementRefundsRequest( + $this->settlementId, + $this->query('from'), + $this->query('limit'), + $this->query('includePayment', $includePayment) ); } } diff --git a/src/Factories/GetPaginatedSettlementsQueryFactory.php b/src/Factories/GetPaginatedSettlementsQueryFactory.php deleted file mode 100644 index e31c6e43..00000000 --- a/src/Factories/GetPaginatedSettlementsQueryFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -get('balanceId'); - - return new GetPaginatedSettlementsQuery( - PaginatedQueryFactory::new($this->data)->create(), - $this->get('filters.balanceId', $balanceId), - ); - } -} diff --git a/src/Factories/GetPaginatedSettlementsRequestFactory.php b/src/Factories/GetPaginatedSettlementsRequestFactory.php new file mode 100644 index 00000000..4c18bc0b --- /dev/null +++ b/src/Factories/GetPaginatedSettlementsRequestFactory.php @@ -0,0 +1,17 @@ +query('from'), + $this->query('limit'), + $this->query('balanceId'), + ); + } +} diff --git a/src/Factories/GetPaymentCaptureQueryFactory.php b/src/Factories/GetPaymentCaptureQueryFactory.php deleted file mode 100644 index cd8c538e..00000000 --- a/src/Factories/GetPaymentCaptureQueryFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaymentCaptureQuery( - $this->get('includePayment', $includePayment), - ); - } -} diff --git a/src/Factories/GetPaymentCaptureRequestFactory.php b/src/Factories/GetPaymentCaptureRequestFactory.php new file mode 100644 index 00000000..c5ce9b2e --- /dev/null +++ b/src/Factories/GetPaymentCaptureRequestFactory.php @@ -0,0 +1,30 @@ +paymentId = $paymentId; + $this->captureId = $captureId; + } + + public function create(): GetPaymentCaptureRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaymentCaptureRequest( + $this->paymentId, + $this->captureId, + $this->query('includePayment', $includePayment), + ); + } +} diff --git a/src/Factories/GetPaymentChargebackQueryFactory.php b/src/Factories/GetPaymentChargebackQueryFactory.php deleted file mode 100644 index b1bf16a2..00000000 --- a/src/Factories/GetPaymentChargebackQueryFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaymentChargebackQuery( - $this->get('includePayment', $includePayment), - ); - } -} diff --git a/src/Factories/GetPaymentChargebackRequestFactory.php b/src/Factories/GetPaymentChargebackRequestFactory.php new file mode 100644 index 00000000..a6d8a90e --- /dev/null +++ b/src/Factories/GetPaymentChargebackRequestFactory.php @@ -0,0 +1,30 @@ +paymentId = $paymentId; + $this->chargebackId = $chargebackId; + } + + public function create(): GetPaymentChargebackRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaymentChargebackRequest( + $this->paymentId, + $this->chargebackId, + $this->query('includePayment', $includePayment), + ); + } +} diff --git a/src/Factories/GetPaymentMethodQueryFactory.php b/src/Factories/GetPaymentMethodQueryFactory.php deleted file mode 100644 index 330d50c4..00000000 --- a/src/Factories/GetPaymentMethodQueryFactory.php +++ /dev/null @@ -1,23 +0,0 @@ -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('includeIssuers', $includeIssuers), - $this->get('includePricing', $includePricing), - ); - } -} diff --git a/src/Factories/GetPaymentMethodRequestFactory.php b/src/Factories/GetPaymentMethodRequestFactory.php new file mode 100644 index 00000000..f25517a5 --- /dev/null +++ b/src/Factories/GetPaymentMethodRequestFactory.php @@ -0,0 +1,31 @@ +id = $id; + } + + public function create(): GetPaymentMethodRequest + { + $includeIssuers = $this->queryIncludes('include', MethodQuery::INCLUDE_ISSUERS); + $includePricing = $this->queryIncludes('include', MethodQuery::INCLUDE_PRICING); + + return new GetPaymentMethodRequest( + $this->id, + $this->query('locale'), + $this->query('currency'), + $this->query('profileId'), + $this->query('includeIssuers', $includeIssuers), + $this->query('includePricing', $includePricing), + ); + } +} diff --git a/src/Factories/GetPaymentQueryFactory.php b/src/Factories/GetPaymentQueryFactory.php deleted file mode 100644 index 4740ab13..00000000 --- a/src/Factories/GetPaymentQueryFactory.php +++ /dev/null @@ -1,26 +0,0 @@ -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('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 deleted file mode 100644 index 62662783..00000000 --- a/src/Factories/GetPaymentRefundQueryFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -includes('include', PaymentIncludesQuery::PAYMENT); - - return new GetPaymentRefundQuery( - $this->get('includePayment', $includePayment), - ); - } -} diff --git a/src/Factories/GetPaymentRefundRequestFactory.php b/src/Factories/GetPaymentRefundRequestFactory.php new file mode 100644 index 00000000..823cdb7a --- /dev/null +++ b/src/Factories/GetPaymentRefundRequestFactory.php @@ -0,0 +1,30 @@ +paymentId = $paymentId; + $this->refundId = $refundId; + } + + public function create(): GetPaymentRefundRequest + { + $includePayment = $this->queryIncludes('include', PaymentIncludesQuery::PAYMENT); + + return new GetPaymentRefundRequest( + $this->paymentId, + $this->refundId, + $this->query('includePayment', $includePayment), + ); + } +} diff --git a/src/Factories/GetPaymentRequestFactory.php b/src/Factories/GetPaymentRequestFactory.php new file mode 100644 index 00000000..26a0075e --- /dev/null +++ b/src/Factories/GetPaymentRequestFactory.php @@ -0,0 +1,34 @@ +id = $id; + } + + public function create(): GetPaymentRequest + { + $embedCaptures = $this->queryIncludes('embed', PaymentQuery::EMBED_CAPTURES); + $embedRefunds = $this->queryIncludes('embed', PaymentQuery::EMBED_REFUNDS); + $embedChargebacks = $this->queryIncludes('embed', PaymentQuery::EMBED_CHARGEBACKS); + $includeQrCode = $this->queryIncludes('include', PaymentQuery::INCLUDE_QR_CODE); + $includeRemainderDetails = $this->queryIncludes('include', PaymentQuery::INCLUDE_REMAINDER_DETAILS); + + return new GetPaymentRequest( + $this->id, + $this->query('embedCaptures', $embedCaptures), + $this->query('embedRefunds', $embedRefunds), + $this->query('embedChargebacks', $embedChargebacks), + $this->query('includeQrCode', $includeQrCode), + $this->query('includeRemainderDetails', $includeRemainderDetails), + ); + } +} diff --git a/src/Factories/InvoiceLineCollectionFactory.php b/src/Factories/InvoiceLineCollectionFactory.php index 920f4cd3..0d470b3e 100644 --- a/src/Factories/InvoiceLineCollectionFactory.php +++ b/src/Factories/InvoiceLineCollectionFactory.php @@ -9,8 +9,8 @@ class InvoiceLineCollectionFactory extends Factory public function create(): DataCollection { return new DataCollection(array_map( - fn (array $item) => InvoiceLineFactory::new($item)->create(), - $this->data + fn ($item) => InvoiceLineFactory::new($item)->create(), + $this->get() )); } } diff --git a/src/Factories/InvoiceLineFactory.php b/src/Factories/InvoiceLineFactory.php index 560bf271..ce64112c 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->transformIfNotNull('discount', fn (array $data) => Discount::fromArray($data)) ); } } diff --git a/src/Factories/OrderLineCollectionFactory.php b/src/Factories/OrderLineCollectionFactory.php index f41d15ae..572c1486 100644 --- a/src/Factories/OrderLineCollectionFactory.php +++ b/src/Factories/OrderLineCollectionFactory.php @@ -9,8 +9,8 @@ class OrderLineCollectionFactory extends Factory public function create(): DataCollection { return new DataCollection(array_map( - fn (array $item) => OrderLineFactory::new($item)->create(), - $this->data + fn ($item) => OrderLineFactory::new($item)->create(), + $this->get() )); } } diff --git a/src/Factories/OrderLineFactory.php b/src/Factories/OrderLineFactory.php index 99b4d0ec..457065ac 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->transformIfNotNull('discountAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->transformIfNotNull('recurring', fn (array $item) => RecurringBillingCycleFactory::new($item)->create()), $this->get('vatRate'), - $this->mapIfNotNull('vatAmount', fn (array $item) => MoneyFactory::new($item)->create()), + $this->transformIfNotNull('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 98498c45..93b91b39 100644 --- a/src/Factories/PaginatedQueryFactory.php +++ b/src/Factories/PaginatedQueryFactory.php @@ -4,13 +4,13 @@ use Mollie\Api\Http\Data\PaginatedQuery; -class PaginatedQueryFactory extends Factory +class PaginatedQueryFactory extends RequestFactory { public function create(): PaginatedQuery { return new PaginatedQuery( - $this->get('from'), - $this->get('limit'), + $this->query('from'), + $this->query('limit'), ); } } diff --git a/src/Factories/PaymentRouteCollectionFactory.php b/src/Factories/PaymentRouteCollectionFactory.php index a430ae22..b5e6b223 100644 --- a/src/Factories/PaymentRouteCollectionFactory.php +++ b/src/Factories/PaymentRouteCollectionFactory.php @@ -3,6 +3,7 @@ namespace Mollie\Api\Factories; use DateTimeImmutable; +use Mollie\Api\Exceptions\LogicException; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\PaymentRoute; use Mollie\Api\Utils\Arr; @@ -12,9 +13,13 @@ class PaymentRouteCollectionFactory extends Factory { public function create(): DataCollection { - $paymentRoutes = array_map(function (array $item) { - if (! $this->has(['amount', 'destination.organizationId'])) { - throw new \InvalidArgumentException('Invalid PaymentRoute data provided'); + $paymentRoutes = array_map(function ($item) { + if ($item instanceof PaymentRoute) { + return $item; + } + + if (! $this->has(['amount', 'destination.organizationId'], $item)) { + throw new LogicException('Invalid PaymentRoute data provided'); } return new PaymentRoute( @@ -22,10 +27,11 @@ public function create(): DataCollection Arr::get($item, 'destination.organizationId'), Utility::compose( Arr::get($item, 'delayUntil'), - fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value) + fn ($value) => DateTimeImmutable::createFromFormat('Y-m-d', $value), + DateTimeImmutable::class ) ); - }, $this->data); + }, $this->get()); return new DataCollection($paymentRoutes); } diff --git a/src/Factories/RecurringBillingCycleFactory.php b/src/Factories/RecurringBillingCycleFactory.php index c55a8d7c..290df49c 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->transformIfNotNull('amount', fn (array $item) => MoneyFactory::new($item)->create()), $this->get('times'), - $this->mapIfNotNull('startDate', fn (string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), + $this->transformIfNotNull('startDate', fn (string $item) => DateTimeImmutable::createFromFormat('Y-m-d', $item)), ); } } diff --git a/src/Factories/RefundRouteCollectionFactory.php b/src/Factories/RefundRouteCollectionFactory.php index 788cfa64..0eb1529a 100644 --- a/src/Factories/RefundRouteCollectionFactory.php +++ b/src/Factories/RefundRouteCollectionFactory.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Factories; +use Mollie\Api\Exceptions\LogicException; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\RefundRoute; use Mollie\Api\Utils\Arr; @@ -10,16 +11,20 @@ class RefundRouteCollectionFactory extends Factory { public function create(): DataCollection { - $refundRoutes = array_map(function (array $item) { - if (! $this->has(['amount', 'source.organizationId'])) { - throw new \InvalidArgumentException('Invalid RefundRoute data provided'); + $refundRoutes = array_map(function ($item) { + if ($item instanceof RefundRoute) { + return $item; + } + + if (! $this->has(['amount', 'source.organizationId'], $item)) { + throw new LogicException('Invalid RefundRoute data provided'); } return new RefundRoute( MoneyFactory::new(Arr::get($item, 'amount'))->create(), Arr::get($item, 'source.organizationId') ); - }, $this->data); + }, $this->get()); return new DataCollection($refundRoutes); } diff --git a/src/Factories/RequestFactory.php b/src/Factories/RequestFactory.php new file mode 100644 index 00000000..b01ebd85 --- /dev/null +++ b/src/Factories/RequestFactory.php @@ -0,0 +1,83 @@ +payload = $payload; + + return $this; + } + + /** + * @return static + */ + public function withQuery(array $query) + { + $this->query = $query; + + return $this; + } + + protected function payload(?string $key = null, $default = null) + { + return $this->get($key, $default, $this->payload); + } + + protected function query(?string $key = null, $default = null) + { + return $this->get($key, $default, $this->query); + } + + protected function payloadIncludes(string $key, $value) + { + return $this->includes($key, $value, $this->payload); + } + + protected function queryIncludes(string $key, $value) + { + return $this->includes($key, $value, $this->query); + } + + protected function payloadHas($key): bool + { + return $this->has($key, $this->payload); + } + + /** + * @param string|array $key + */ + protected function queryHas($key): bool + { + return $this->has($key, $this->query); + } + + protected function transformFromPayload($key, $resolver, $composableClass = null) + { + return $this->transformFromResolved($this->payload($key), $resolver, $composableClass); + } + + protected function transformFromQuery($key, $resolver, $composableClass = null) + { + return $this->transformFromResolved($this->query($key), $resolver, $composableClass); + } + + /** + * Map a value to a new form if it is not null. + */ + protected function transformFromResolved($resolvedValue, $composable, $resolver = null) + { + return Utility::compose($resolvedValue, $composable, $resolver); + } +} diff --git a/src/Factories/SortablePaginatedQueryFactory.php b/src/Factories/SortablePaginatedQueryFactory.php index 37dad387..5eba1a36 100644 --- a/src/Factories/SortablePaginatedQueryFactory.php +++ b/src/Factories/SortablePaginatedQueryFactory.php @@ -4,14 +4,14 @@ use Mollie\Api\Http\Data\SortablePaginatedQuery; -class SortablePaginatedQueryFactory extends Factory +class SortablePaginatedQueryFactory extends RequestFactory { public function create(): SortablePaginatedQuery { return new SortablePaginatedQuery( - $this->get('from'), - $this->get('limit'), - $this->get('sort'), + $this->query('from'), + $this->query('limit'), + $this->query('sort'), ); } } diff --git a/src/Factories/UpdateCustomerPayloadFactory.php b/src/Factories/UpdateCustomerPayloadFactory.php deleted file mode 100644 index 53105dcc..00000000 --- a/src/Factories/UpdateCustomerPayloadFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -get('name'), - $this->get('email'), - $this->get('locale'), - $this->mapIfNotNull('metadata', Metadata::class), - ); - } -} diff --git a/src/Factories/UpdateCustomerRequestFactory.php b/src/Factories/UpdateCustomerRequestFactory.php new file mode 100644 index 00000000..771af47b --- /dev/null +++ b/src/Factories/UpdateCustomerRequestFactory.php @@ -0,0 +1,27 @@ +id = $id; + } + + public function create(): UpdateCustomerRequest + { + return new UpdateCustomerRequest( + $this->id, + $this->payload('name'), + $this->payload('email'), + $this->payload('locale'), + $this->transformFromPayload('metadata', Metadata::class), + ); + } +} diff --git a/src/Factories/UpdatePaymentLinkPayloadFactory.php b/src/Factories/UpdatePaymentLinkPayloadFactory.php deleted file mode 100644 index 5203b660..00000000 --- a/src/Factories/UpdatePaymentLinkPayloadFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -get('description'), - $this->get('archived'), - ); - } -} diff --git a/src/Factories/UpdatePaymentLinkRequestFactory.php b/src/Factories/UpdatePaymentLinkRequestFactory.php new file mode 100644 index 00000000..5de69fcd --- /dev/null +++ b/src/Factories/UpdatePaymentLinkRequestFactory.php @@ -0,0 +1,25 @@ +paymentLinkId = $paymentLinkId; + } + + public function create(): UpdatePaymentLinkRequest + { + return new UpdatePaymentLinkRequest( + $this->paymentLinkId, + $this->payload('description'), + $this->payload('archived', false), + $this->payload('allowedMethods'), + ); + } +} diff --git a/src/Factories/UpdatePaymentPayloadFactory.php b/src/Factories/UpdatePaymentPayloadFactory.php deleted file mode 100644 index 7c3b2992..00000000 --- a/src/Factories/UpdatePaymentPayloadFactory.php +++ /dev/null @@ -1,25 +0,0 @@ -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') ?? Utility::filterByProperties(UpdatePaymentPayload::class, $this->data), - ); - } -} diff --git a/src/Factories/UpdatePaymentRequestFactory.php b/src/Factories/UpdatePaymentRequestFactory.php new file mode 100644 index 00000000..2826d4ca --- /dev/null +++ b/src/Factories/UpdatePaymentRequestFactory.php @@ -0,0 +1,33 @@ +id = $id; + } + + public function create(): UpdatePaymentRequest + { + return new UpdatePaymentRequest( + $this->id, + $this->payload('description'), + $this->payload('redirectUrl'), + $this->payload('cancelUrl'), + $this->payload('webhookUrl'), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('method'), + $this->payload('locale'), + $this->payload('restrictPaymentMethodsToCountry'), + $this->payload('additional') ?? Utility::filterByProperties(UpdatePaymentRequest::class, $this->payload()), + ); + } +} diff --git a/src/Factories/UpdatePaymentRoutePayloadFactory.php b/src/Factories/UpdatePaymentRoutePayloadFactory.php deleted file mode 100644 index f657aa8b..00000000 --- a/src/Factories/UpdatePaymentRoutePayloadFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -get('releaseDate')), - ); - } -} diff --git a/src/Factories/UpdatePaymentRouteRequestFactory.php b/src/Factories/UpdatePaymentRouteRequestFactory.php new file mode 100644 index 00000000..5d2fbd8e --- /dev/null +++ b/src/Factories/UpdatePaymentRouteRequestFactory.php @@ -0,0 +1,33 @@ +paymentId = $paymentId; + $this->routeId = $routeId; + } + + public function create(): UpdatePaymentRouteRequest + { + if (! $releaseDate = $this->payload('releaseDate')) { + throw new LogicException('Release date is required'); + } + + return new UpdatePaymentRouteRequest( + $this->paymentId, + $this->routeId, + DateTimeImmutable::createFromFormat('Y-m-d', $releaseDate), + ); + } +} diff --git a/src/Factories/UpdateProfilePayloadFactory.php b/src/Factories/UpdateProfilePayloadFactory.php deleted file mode 100644 index 1c23baed..00000000 --- a/src/Factories/UpdateProfilePayloadFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -get('name'), - $this->get('website'), - $this->get('email'), - $this->get('phone'), - $this->get('description'), - $this->get('countriesOfActivity'), - $this->get('businessCategory'), - $this->get('mode') - ); - } -} diff --git a/src/Factories/UpdateProfileRequestFactory.php b/src/Factories/UpdateProfileRequestFactory.php new file mode 100644 index 00000000..cffe455d --- /dev/null +++ b/src/Factories/UpdateProfileRequestFactory.php @@ -0,0 +1,30 @@ +id = $id; + } + + public function create(): UpdateProfileRequest + { + return new UpdateProfileRequest( + $this->id, + $this->payload('name'), + $this->payload('website'), + $this->payload('email'), + $this->payload('phone'), + $this->payload('description'), + $this->payload('countriesOfActivity'), + $this->payload('businessCategory'), + $this->payload('mode') + ); + } +} diff --git a/src/Factories/UpdateSalesInvoicePayloadFactory.php b/src/Factories/UpdateSalesInvoicePayloadFactory.php deleted file mode 100644 index 8023d83f..00000000 --- a/src/Factories/UpdateSalesInvoicePayloadFactory.php +++ /dev/null @@ -1,34 +0,0 @@ -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/Factories/UpdateSalesInvoiceRequestFactory.php b/src/Factories/UpdateSalesInvoiceRequestFactory.php new file mode 100644 index 00000000..20b2b54f --- /dev/null +++ b/src/Factories/UpdateSalesInvoiceRequestFactory.php @@ -0,0 +1,39 @@ +id = $id; + } + + public function create(): UpdateSalesInvoiceRequest + { + return new UpdateSalesInvoiceRequest( + $this->id, + $this->payload('status'), + $this->payload('recipientIdentifier'), + $this->payload('paymentTerm'), + $this->payload('memo'), + $this->transformFromPayload('paymentDetails', fn ($data) => PaymentDetails::fromArray($data)), + $this->transformFromPayload('emailDetails', fn ($data) => EmailDetails::fromArray($data)), + $this->transformFromPayload('recipient', fn ($data) => RecipientFactory::new($data)->create()), + $this + ->transformFromPayload( + 'lines', + fn (array $items) => InvoiceLineCollectionFactory::new($items)->create() + ), + $this->payload('webhookUrl'), + $this->transformFromPayload('discount', fn ($data) => Discount::fromArray($data)) + ); + } +} diff --git a/src/Factories/UpdateSubscriptionPayloadFactory.php b/src/Factories/UpdateSubscriptionPayloadFactory.php deleted file mode 100644 index c833394f..00000000 --- a/src/Factories/UpdateSubscriptionPayloadFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -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/Factories/UpdateSubscriptionRequestFactory.php b/src/Factories/UpdateSubscriptionRequestFactory.php new file mode 100644 index 00000000..00a6ac6a --- /dev/null +++ b/src/Factories/UpdateSubscriptionRequestFactory.php @@ -0,0 +1,36 @@ +customerId = $customerId; + $this->subscriptionId = $subscriptionId; + } + + public function create(): UpdateSubscriptionRequest + { + return new UpdateSubscriptionRequest( + $this->customerId, + $this->subscriptionId, + $this->transformFromPayload('amount', fn ($amount) => MoneyFactory::new($amount)->create()), + $this->payload('description'), + $this->payload('interval'), + $this->transformFromPayload('startDate', fn (string $date) => DateTimeImmutable::createFromFormat('Y-m-d', $date), DateTimeImmutable::class), + $this->payload('times'), + $this->transformFromPayload('metadata', Metadata::class), + $this->payload('webhookUrl'), + $this->payload('mandateId') + ); + } +} diff --git a/src/Fake/MockMollieHttpAdapter.php b/src/Fake/MockMollieHttpAdapter.php index 56e5df6c..9358e6fd 100644 --- a/src/Fake/MockMollieHttpAdapter.php +++ b/src/Fake/MockMollieHttpAdapter.php @@ -51,7 +51,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.'); } } diff --git a/src/Fake/MockResponse.php b/src/Fake/MockResponse.php index a9b35bd2..dedcfb2c 100644 --- a/src/Fake/MockResponse.php +++ b/src/Fake/MockResponse.php @@ -108,7 +108,7 @@ public function body(): string $path = Arr::join([ __DIR__, 'Responses', - $body . '.json', + $body.'.json', ], DIRECTORY_SEPARATOR); $contents = file_get_contents($path); diff --git a/src/Http/Adapter/CurlErrorMapper.php b/src/Http/Adapter/CurlErrorMapper.php index e8ed16d3..bd614932 100644 --- a/src/Http/Adapter/CurlErrorMapper.php +++ b/src/Http/Adapter/CurlErrorMapper.php @@ -10,6 +10,7 @@ class CurlErrorMapper { /** * Maps CURL error codes to their root causes for better error messages. + * * @var array */ private const ERROR_CATEGORIES = [ @@ -40,6 +41,7 @@ class CurlErrorMapper /** * Errors that are likely temporary and should be retried. + * * @var array */ private const RETRYABLE_ERRORS = [ diff --git a/src/Http/Adapter/CurlFactory.php b/src/Http/Adapter/CurlFactory.php index 069082dd..6e9005f0 100644 --- a/src/Http/Adapter/CurlFactory.php +++ b/src/Http/Adapter/CurlFactory.php @@ -9,9 +9,11 @@ class CurlFactory { public const DEFAULT_TIMEOUT = 10; + public const DEFAULT_CONNECT_TIMEOUT = 2; private $handle; + private PendingRequest $pendingRequest; private function __construct($handle, PendingRequest $pendingRequest) @@ -75,7 +77,7 @@ public function withMethod(string $method, ?string $body): self case Method::GET: default: if ($method !== Method::GET) { - throw new \InvalidArgumentException('Invalid HTTP method: ' . $method); + throw new \InvalidArgumentException('Invalid HTTP method: '.$method); } break; @@ -90,8 +92,7 @@ public function create() } /** - * @param int $option - * @param mixed $value + * @param mixed $value */ private function setOption(int $option, $value): void { @@ -107,7 +108,7 @@ private function parseHeaders(array $headers): array { $result = []; foreach ($headers as $key => $value) { - $result[] = $key . ': ' . $value; + $result[] = $key.': '.$value; } return $result; diff --git a/src/Http/Adapter/CurlInitializationException.php b/src/Http/Adapter/CurlInitializationException.php index bfbcb441..6d9521ca 100644 --- a/src/Http/Adapter/CurlInitializationException.php +++ b/src/Http/Adapter/CurlInitializationException.php @@ -13,6 +13,7 @@ class CurlInitializationException extends MollieException { protected PendingRequest $pendingRequest; + protected string $plainMessage; public function __construct( diff --git a/src/Http/Adapter/CurlMollieHttpAdapter.php b/src/Http/Adapter/CurlMollieHttpAdapter.php index 9be28e13..4d0a4912 100644 --- a/src/Http/Adapter/CurlMollieHttpAdapter.php +++ b/src/Http/Adapter/CurlMollieHttpAdapter.php @@ -49,8 +49,9 @@ public function sendRequest(PendingRequest $pendingRequest): Response } /** - * @throws NetworkRequestException * @return array{0: array, 1: string, 2: int} + * + * @throws NetworkRequestException */ protected function send(PendingRequest $pendingRequest): array { @@ -67,7 +68,7 @@ protected function send(PendingRequest $pendingRequest): array if ($response === false) { $curlErrorNumber = curl_errno($curl); - $curlErrorMessage = 'Curl error: ' . curl_error($curl); + $curlErrorMessage = 'Curl error: '.curl_error($curl); throw CurlErrorMapper::toException($curlErrorNumber, $curlErrorMessage, $pendingRequest); } @@ -101,7 +102,6 @@ protected function createResponse(PendingRequest $pendingRequest, int $statusCod } /** - * @param string $response * @return array{0: array, 1: string, 2: int} */ private function extractResponseDetails($curl, string $response): array diff --git a/src/Http/Adapter/GuzzleMollieHttpAdapter.php b/src/Http/Adapter/GuzzleMollieHttpAdapter.php index bdc9c687..4e83ad4b 100644 --- a/src/Http/Adapter/GuzzleMollieHttpAdapter.php +++ b/src/Http/Adapter/GuzzleMollieHttpAdapter.php @@ -62,7 +62,7 @@ public function factories(): Factories */ public static function createClient(): self { - $retryMiddlewareFactory = new GuzzleRetryMiddlewareFactory(); + $retryMiddlewareFactory = new GuzzleRetryMiddlewareFactory; $handlerStack = HandlerStack::create(); $handlerStack->push($retryMiddlewareFactory->retry()); @@ -114,6 +114,6 @@ protected function createResponse( 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 1b2f3b6c..387c5eed 100644 --- a/src/Http/Adapter/MollieHttpAdapterPicker.php +++ b/src/Http/Adapter/MollieHttpAdapterPicker.php @@ -41,6 +41,6 @@ private function createDefaultAdapter(): HttpAdapterContract private function guzzleIsDetected(): bool { - return interface_exists('\\' . \GuzzleHttp\ClientInterface::class); + return interface_exists('\\'.\GuzzleHttp\ClientInterface::class); } } diff --git a/src/Http/Adapter/PSR18MollieHttpAdapter.php b/src/Http/Adapter/PSR18MollieHttpAdapter.php index 4dfee103..d7058c1b 100644 --- a/src/Http/Adapter/PSR18MollieHttpAdapter.php +++ b/src/Http/Adapter/PSR18MollieHttpAdapter.php @@ -23,10 +23,15 @@ final class PSR18MollieHttpAdapter implements HttpAdapterContract { private ClientInterface $httpClient; + private RequestFactoryInterface $requestFactory; + private ResponseFactoryInterface $responseFactory; + private StreamFactoryInterface $streamFactory; + private UriFactoryInterface $uriFactory; + private ?Factories $factories = null; public function __construct( @@ -72,7 +77,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response // PSR-18 NetworkExceptionInterface indicates network errors, which are retryable throw new RetryableNetworkRequestException( $pendingRequest, - 'Network error: ' . $e->getMessage() + 'Network error: '.$e->getMessage() ); } catch (RequestExceptionInterface $e) { if (method_exists($e, 'getResponse') && $response = $e->getResponse()) { @@ -81,7 +86,7 @@ public function sendRequest(PendingRequest $pendingRequest): Response throw new RetryableNetworkRequestException( $pendingRequest, - 'Network error: ' . $e->getMessage() + 'Network error: '.$e->getMessage() ); } } @@ -109,6 +114,6 @@ public function version(): string $clientClass = get_class($this->httpClient); $clientName = substr($clientClass, strrpos($clientClass, '\\') + 1); - return 'PSR18/' . $clientName; + return 'PSR18/'.$clientName; } } diff --git a/src/Http/Data/AnyData.php b/src/Http/Data/AnyData.php deleted file mode 100644 index b47be321..00000000 --- a/src/Http/Data/AnyData.php +++ /dev/null @@ -1,23 +0,0 @@ -data = $data; - } - - public function toArray(): array - { - return $this->data ?? []; - } -} diff --git a/src/Http/Data/CreateClientLinkPayload.php b/src/Http/Data/CreateClientLinkPayload.php deleted file mode 100644 index 6c3efdaa..00000000 --- a/src/Http/Data/CreateClientLinkPayload.php +++ /dev/null @@ -1,43 +0,0 @@ -owner = $owner; - $this->name = $name; - $this->address = $address; - $this->registrationNumber = $registrationNumber; - $this->vatNumber = $vatNumber; - } - - public function toArray(): array - { - return [ - 'owner' => $this->owner, - 'name' => $this->name, - 'address' => $this->address, - 'registrationNumber' => $this->registrationNumber, - 'vatNumber' => $this->vatNumber, - ]; - } -} diff --git a/src/Http/Data/CreateCustomerPayload.php b/src/Http/Data/CreateCustomerPayload.php deleted file mode 100644 index ca457730..00000000 --- a/src/Http/Data/CreateCustomerPayload.php +++ /dev/null @@ -1,38 +0,0 @@ -name = $name; - $this->email = $email; - $this->locale = $locale; - $this->metadata = $metadata; - } - - public function toArray(): array - { - return [ - 'name' => $this->name, - 'email' => $this->email, - 'locale' => $this->locale, - 'metadata' => $this->metadata, - ]; - } -} diff --git a/src/Http/Data/CreateMandatePayload.php b/src/Http/Data/CreateMandatePayload.php deleted file mode 100644 index 06a212f9..00000000 --- a/src/Http/Data/CreateMandatePayload.php +++ /dev/null @@ -1,59 +0,0 @@ -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 toArray(): array - { - return [ - 'method' => $this->method, - 'consumerName' => $this->consumerName, - 'consumerAccount' => $this->consumerAccount, - 'consumerBic' => $this->consumerBic, - 'consumerEmail' => $this->consumerEmail, - 'signatureDate' => $this->signatureDate ? $this->signatureDate->format('Y-m-d') : null, - 'mandateReference' => $this->mandateReference, - 'paypalBillingAgreementId' => $this->paypalBillingAgreementId, - ]; - } -} diff --git a/src/Http/Data/CreatePaymentCapturePayload.php b/src/Http/Data/CreatePaymentCapturePayload.php deleted file mode 100644 index 898cc0f9..00000000 --- a/src/Http/Data/CreatePaymentCapturePayload.php +++ /dev/null @@ -1,33 +0,0 @@ -amount = $amount; - $this->description = $description; - $this->metadata = $metadata; - } - - public function toArray(): array - { - return [ - 'description' => $this->description, - 'amount' => $this->amount, - 'metadata' => $this->metadata, - ]; - } -} diff --git a/src/Http/Data/CreatePaymentLinkPayload.php b/src/Http/Data/CreatePaymentLinkPayload.php deleted file mode 100644 index 3cd53928..00000000 --- a/src/Http/Data/CreatePaymentLinkPayload.php +++ /dev/null @@ -1,54 +0,0 @@ -description = $description; - $this->amount = $amount; - $this->redirectUrl = $redirectUrl; - $this->webhookUrl = $webhookUrl; - $this->profileId = $profileId; - $this->reusable = $reusable; - $this->expiresAt = $expiresAt; - } - - public function toArray(): array - { - return [ - 'description' => $this->description, - 'amount' => $this->amount, - 'redirectUrl' => $this->redirectUrl, - 'webhookUrl' => $this->webhookUrl, - 'profileId' => $this->profileId, - 'reusable' => $this->reusable, - 'expiresAt' => $this->expiresAt ? $this->expiresAt->format('Y-m-d') : null, - ]; - } -} diff --git a/src/Http/Data/CreatePaymentPayload.php b/src/Http/Data/CreatePaymentPayload.php deleted file mode 100644 index 9a0cbd5e..00000000 --- a/src/Http/Data/CreatePaymentPayload.php +++ /dev/null @@ -1,138 +0,0 @@ -|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; - - /** - * 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, - 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; - } - - public function toArray(): array - { - 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/Data/CreatePaymentQuery.php b/src/Http/Data/CreatePaymentQuery.php deleted file mode 100644 index d40c81fa..00000000 --- a/src/Http/Data/CreatePaymentQuery.php +++ /dev/null @@ -1,27 +0,0 @@ -includeQrCode = $includeQrCode; - } - - public function toArray(): array - { - return [ - 'include' => $this->includeQrCode ? PaymentQuery::INCLUDE_QR_CODE : null, - ]; - } -} diff --git a/src/Http/Data/CreateProfilePayload.php b/src/Http/Data/CreateProfilePayload.php deleted file mode 100644 index 2d3a3e17..00000000 --- a/src/Http/Data/CreateProfilePayload.php +++ /dev/null @@ -1,53 +0,0 @@ -name = $name; - $this->website = $website; - $this->email = $email; - $this->phone = $phone; - $this->description = $description; - $this->countriesOfActivity = $countriesOfActivity; - $this->businessCategory = $businessCategory; - } - - public function toArray(): 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/Data/CreateRefundPaymentPayload.php b/src/Http/Data/CreateRefundPaymentPayload.php deleted file mode 100644 index e1212fd7..00000000 --- a/src/Http/Data/CreateRefundPaymentPayload.php +++ /dev/null @@ -1,46 +0,0 @@ - - */ - public ?DataCollection $routingReversals = null; - - public function __construct( - string $description, - Money $amount, - ?Metadata $metadata = null, - ?bool $reverseRouting = null, - ?DataCollection $routingReversals = null - ) { - $this->description = $description; - $this->amount = $amount; - $this->metadata = $metadata; - $this->reverseRouting = $reverseRouting; - $this->routingReversals = $routingReversals; - } - - public function toArray(): array - { - return [ - 'description' => $this->description, - 'amount' => $this->amount, - 'metadata' => $this->metadata, - 'reverseRouting' => $this->reverseRouting, - 'routingReversals' => $this->routingReversals, - ]; - } -} diff --git a/src/Http/Data/CreateSalesInvoicePayload.php b/src/Http/Data/CreateSalesInvoicePayload.php deleted file mode 100644 index 104b1281..00000000 --- a/src/Http/Data/CreateSalesInvoicePayload.php +++ /dev/null @@ -1,94 +0,0 @@ - - */ - 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 toArray(): 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/Data/CreateSubscriptionPayload.php b/src/Http/Data/CreateSubscriptionPayload.php deleted file mode 100644 index bf28405d..00000000 --- a/src/Http/Data/CreateSubscriptionPayload.php +++ /dev/null @@ -1,79 +0,0 @@ -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 toArray(): array - { - return [ - 'amount' => $this->amount, - 'interval' => $this->interval, - 'description' => $this->description, - 'status' => $this->status, - 'times' => $this->times, - 'startDate' => $this->startDate ? $this->startDate->format('Y-m-d') : null, - 'method' => $this->method, - 'applicationFee' => $this->applicationFee, - 'metadata' => $this->metadata, - 'webhookUrl' => $this->webhookUrl, - 'mandateId' => $this->mandateId, - 'profileId' => $this->profileId, - ]; - } -} diff --git a/src/Http/Data/DataCollection.php b/src/Http/Data/DataCollection.php index 69d0f38b..443ccb6e 100644 --- a/src/Http/Data/DataCollection.php +++ b/src/Http/Data/DataCollection.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Http\Data; +use Countable; use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Contracts\Resolvable; use Mollie\Api\Utils\Arr; @@ -9,7 +10,7 @@ /** * @template T of mixed */ -class DataCollection implements Resolvable +class DataCollection implements Countable, Resolvable { /** * @var array @@ -24,6 +25,11 @@ public function __construct(array $items) $this->items = $items; } + public function count(): int + { + return count($this->items); + } + /** * @param mixed $subject */ @@ -40,6 +46,11 @@ public static function wrap($subject): self return new static(Arr::wrap($subject)); } + public function values(): self + { + return new static(array_values($this->items)); + } + public function toArray(): array { return $this->items; diff --git a/src/Http/Data/GetAllMethodsQuery.php b/src/Http/Data/GetAllMethodsQuery.php deleted file mode 100644 index 5c16ef2d..00000000 --- a/src/Http/Data/GetAllMethodsQuery.php +++ /dev/null @@ -1,41 +0,0 @@ -locale = $locale; - $this->includeIssuers = $includeIssuers; - $this->includePricing = $includePricing; - $this->amount = $amount; - } - - public function toArray(): array - { - return [ - 'include' => array_filter([ - $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, - $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, - ]), - 'locale' => $this->locale, - 'amount' => $this->amount, - ]; - } -} diff --git a/src/Http/Data/GetAllPaginatedSubscriptionsQuery.php b/src/Http/Data/GetAllPaginatedSubscriptionsQuery.php deleted file mode 100644 index 2efec758..00000000 --- a/src/Http/Data/GetAllPaginatedSubscriptionsQuery.php +++ /dev/null @@ -1,25 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->profileId = $profileId; - } - - public function toArray(): array - { - return array_merge($this->paginatedQuery->toArray(), [ - 'profileId' => $this->profileId, - ]); - } -} diff --git a/src/Http/Data/GetBalanceReportQuery.php b/src/Http/Data/GetBalanceReportQuery.php deleted file mode 100644 index 26f7bdaa..00000000 --- a/src/Http/Data/GetBalanceReportQuery.php +++ /dev/null @@ -1,34 +0,0 @@ -from = $from; - $this->until = $until; - $this->grouping = $grouping; - } - - public function toArray(): array - { - return [ - 'from' => $this->from, - 'until' => $this->until, - 'grouping' => $this->grouping, - ]; - } -} diff --git a/src/Http/Data/GetClientQuery.php b/src/Http/Data/GetClientQuery.php deleted file mode 100644 index 75177bb0..00000000 --- a/src/Http/Data/GetClientQuery.php +++ /dev/null @@ -1,32 +0,0 @@ -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/Data/GetEnabledPaymentMethodsQuery.php b/src/Http/Data/GetEnabledPaymentMethodsQuery.php deleted file mode 100644 index a979224b..00000000 --- a/src/Http/Data/GetEnabledPaymentMethodsQuery.php +++ /dev/null @@ -1,78 +0,0 @@ -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 - { - return [ - 'sequenceType' => $this->sequenceType, - 'locale' => $this->locale, - 'amount' => $this->amount, - 'resource' => $this->resource, - 'billingCountry' => $this->billingCountry, - 'includeWallets' => Arr::join($this->includeWallets ?? []), - 'orderLineCategories' => Arr::join($this->orderLineCategories ?? []), - 'profileId' => $this->profileId, - 'include' => array_filter([ - $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, - $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, - ]), - ]; - } -} diff --git a/src/Http/Data/GetPaginatedBalanceQuery.php b/src/Http/Data/GetPaginatedBalanceQuery.php deleted file mode 100644 index 90de853c..00000000 --- a/src/Http/Data/GetPaginatedBalanceQuery.php +++ /dev/null @@ -1,30 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->currency = $currency; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'currency' => $this->currency, - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedChargebackQuery.php b/src/Http/Data/GetPaginatedChargebackQuery.php deleted file mode 100644 index 5e6333b2..00000000 --- a/src/Http/Data/GetPaginatedChargebackQuery.php +++ /dev/null @@ -1,36 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->includePayment = $includePayment; - $this->profileId = $profileId; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, - 'profileId' => $this->profileId, - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedClientQuery.php b/src/Http/Data/GetPaginatedClientQuery.php deleted file mode 100644 index e36276f4..00000000 --- a/src/Http/Data/GetPaginatedClientQuery.php +++ /dev/null @@ -1,39 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->embedOrganization = $embedOrganization; - $this->embedOnboarding = $embedOnboarding; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'embed' => Arr::join([ - $this->embedOrganization ? ClientQuery::EMBED_ORGANIZATION : null, - $this->embedOnboarding ? ClientQuery::EMBED_ONBOARDING : null, - ]), - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedCustomerPaymentsQuery.php b/src/Http/Data/GetPaginatedCustomerPaymentsQuery.php deleted file mode 100644 index b417065d..00000000 --- a/src/Http/Data/GetPaginatedCustomerPaymentsQuery.php +++ /dev/null @@ -1,30 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->profileId = $profileId; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'profileId' => $this->profileId, - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedInvoiceQuery.php b/src/Http/Data/GetPaginatedInvoiceQuery.php deleted file mode 100644 index 129ffa15..00000000 --- a/src/Http/Data/GetPaginatedInvoiceQuery.php +++ /dev/null @@ -1,35 +0,0 @@ -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/Data/GetPaginatedPaymentCapturesQuery.php b/src/Http/Data/GetPaginatedPaymentCapturesQuery.php deleted file mode 100644 index 8f1ee269..00000000 --- a/src/Http/Data/GetPaginatedPaymentCapturesQuery.php +++ /dev/null @@ -1,32 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->includePayment = $includePayment; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'include' => Arr::join($this->includePayment ? [PaymentIncludesQuery::PAYMENT] : []), - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedPaymentChargebacksQuery.php b/src/Http/Data/GetPaginatedPaymentChargebacksQuery.php deleted file mode 100644 index 76ada52a..00000000 --- a/src/Http/Data/GetPaginatedPaymentChargebacksQuery.php +++ /dev/null @@ -1,31 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->includePayment = $includePayment; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : [], - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedPaymentRefundQuery.php b/src/Http/Data/GetPaginatedPaymentRefundQuery.php deleted file mode 100644 index 20e51da4..00000000 --- a/src/Http/Data/GetPaginatedPaymentRefundQuery.php +++ /dev/null @@ -1,31 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->includePayment = $includePayment; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedRefundsQuery.php b/src/Http/Data/GetPaginatedRefundsQuery.php deleted file mode 100644 index c2f363dd..00000000 --- a/src/Http/Data/GetPaginatedRefundsQuery.php +++ /dev/null @@ -1,36 +0,0 @@ -paginatedQuery = $paginatedQuery; - $this->embedPayment = $embedPayment; - $this->profileId = $profileId; - } - - public function toArray(): array - { - return array_merge( - $this->paginatedQuery->toArray(), - [ - 'embed' => $this->embedPayment ? PaymentIncludesQuery::PAYMENT : null, - 'profileId' => $this->profileId, - ] - ); - } -} diff --git a/src/Http/Data/GetPaginatedSettlementCapturesQuery.php b/src/Http/Data/GetPaginatedSettlementCapturesQuery.php deleted file mode 100644 index 729a27c0..00000000 --- a/src/Http/Data/GetPaginatedSettlementCapturesQuery.php +++ /dev/null @@ -1,7 +0,0 @@ -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/Data/GetPaymentCaptureQuery.php b/src/Http/Data/GetPaymentCaptureQuery.php deleted file mode 100644 index 617d7c1a..00000000 --- a/src/Http/Data/GetPaymentCaptureQuery.php +++ /dev/null @@ -1,25 +0,0 @@ -includePayment = $includePayment; - } - - public function toArray(): array - { - return [ - 'include' => Arr::join($this->includePayment ? [PaymentIncludesQuery::PAYMENT] : []), - ]; - } -} diff --git a/src/Http/Data/GetPaymentChargebackQuery.php b/src/Http/Data/GetPaymentChargebackQuery.php deleted file mode 100644 index fad91877..00000000 --- a/src/Http/Data/GetPaymentChargebackQuery.php +++ /dev/null @@ -1,24 +0,0 @@ -includePayment = $includePayment; - } - - public function toArray(): array - { - return [ - 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, - ]; - } -} diff --git a/src/Http/Data/GetPaymentMethodQuery.php b/src/Http/Data/GetPaymentMethodQuery.php deleted file mode 100644 index bd0c4731..00000000 --- a/src/Http/Data/GetPaymentMethodQuery.php +++ /dev/null @@ -1,47 +0,0 @@ -locale = $locale; - $this->currency = $currency; - $this->profileId = $profileId; - $this->includeIssuers = $includeIssuers; - $this->includePricing = $includePricing; - } - - public function toArray(): array - { - return [ - 'locale' => $this->locale, - 'currency' => $this->currency, - 'profileId' => $this->profileId, - 'include' => Arr::join([ - $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, - $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, - ]), - ]; - } -} diff --git a/src/Http/Data/GetPaymentQuery.php b/src/Http/Data/GetPaymentQuery.php deleted file mode 100644 index 35a561e6..00000000 --- a/src/Http/Data/GetPaymentQuery.php +++ /dev/null @@ -1,49 +0,0 @@ -embedCaptures = $embedCaptures; - $this->embedRefunds = $embedRefunds; - $this->embedChargebacks = $embedChargebacks; - $this->includeQrCode = $includeQrCode; - $this->includeRemainderDetails = $includeRemainderDetails; - } - - public function toArray(): array - { - return [ - '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/Data/GetPaymentRefundQuery.php b/src/Http/Data/GetPaymentRefundQuery.php deleted file mode 100644 index cf4bae72..00000000 --- a/src/Http/Data/GetPaymentRefundQuery.php +++ /dev/null @@ -1,24 +0,0 @@ -includePayment = $includePayment; - } - - public function toArray(): array - { - return [ - 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, - ]; - } -} diff --git a/src/Http/Data/OwnerAddress.php b/src/Http/Data/OwnerAddress.php index d3c547c7..03c27908 100644 --- a/src/Http/Data/OwnerAddress.php +++ b/src/Http/Data/OwnerAddress.php @@ -36,11 +36,11 @@ public function __construct( public function toArray(): array { return [ + 'country' => $this->country, 'streetAndNumber' => $this->streetAndNumber, 'postalCode' => $this->postalCode, 'city' => $this->city, 'region' => $this->region, - 'country' => $this->country, ]; } } diff --git a/src/Http/Data/RequestApplePayPaymentSessionPayload.php b/src/Http/Data/RequestApplePayPaymentSessionPayload.php deleted file mode 100644 index f3ed782d..00000000 --- a/src/Http/Data/RequestApplePayPaymentSessionPayload.php +++ /dev/null @@ -1,33 +0,0 @@ -domain = $domain; - $this->validationUrl = $validationUrl; - $this->profileId = $profileId; - } - - public function toArray(): array - { - return [ - 'domain' => $this->domain, - 'validationUrl' => $this->validationUrl, - 'profileId' => $this->profileId, - ]; - } -} diff --git a/src/Http/Data/UpdateCustomerPayload.php b/src/Http/Data/UpdateCustomerPayload.php deleted file mode 100644 index ef64bb7b..00000000 --- a/src/Http/Data/UpdateCustomerPayload.php +++ /dev/null @@ -1,8 +0,0 @@ -description = $description; - $this->archived = $archived; - } - - public function toArray(): array - { - return [ - 'description' => $this->description, - 'archived' => $this->archived, - ]; - } -} diff --git a/src/Http/Data/UpdatePaymentPayload.php b/src/Http/Data/UpdatePaymentPayload.php deleted file mode 100644 index e5dc0f07..00000000 --- a/src/Http/Data/UpdatePaymentPayload.php +++ /dev/null @@ -1,67 +0,0 @@ -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; - } - - public function toArray(): 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, - ], $this->additional); - } -} diff --git a/src/Http/Data/UpdatePaymentRoutePayload.php b/src/Http/Data/UpdatePaymentRoutePayload.php deleted file mode 100644 index 443d8de4..00000000 --- a/src/Http/Data/UpdatePaymentRoutePayload.php +++ /dev/null @@ -1,24 +0,0 @@ -releaseDate = $releaseDate; - } - - public function toArray(): array - { - return [ - 'releaseDate' => $this->releaseDate, - ]; - } -} diff --git a/src/Http/Data/UpdateProfilePayload.php b/src/Http/Data/UpdateProfilePayload.php deleted file mode 100644 index 3b3e140e..00000000 --- a/src/Http/Data/UpdateProfilePayload.php +++ /dev/null @@ -1,58 +0,0 @@ -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 toArray(): 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/Data/UpdateSalesInvoicePayload.php b/src/Http/Data/UpdateSalesInvoicePayload.php deleted file mode 100644 index 215e2142..00000000 --- a/src/Http/Data/UpdateSalesInvoicePayload.php +++ /dev/null @@ -1,71 +0,0 @@ - - */ - 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 toArray(): 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/Data/UpdateSubscriptionPayload.php b/src/Http/Data/UpdateSubscriptionPayload.php deleted file mode 100644 index 599d7529..00000000 --- a/src/Http/Data/UpdateSubscriptionPayload.php +++ /dev/null @@ -1,59 +0,0 @@ -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 toArray(): array - { - return [ - 'amount' => $this->amount, - 'description' => $this->description, - 'interval' => $this->interval, - 'startDate' => $this->startDate, - 'times' => $this->times, - 'metadata' => $this->metadata, - 'webhookUrl' => $this->webhookUrl, - 'mandateId' => $this->mandateId, - ]; - } -} diff --git a/src/Http/PendingRequest/AuthenticateRequest.php b/src/Http/PendingRequest/AuthenticateRequest.php index 7bec05a2..8b571982 100644 --- a/src/Http/PendingRequest/AuthenticateRequest.php +++ b/src/Http/PendingRequest/AuthenticateRequest.php @@ -12,7 +12,7 @@ public function __invoke(PendingRequest $pendingRequest): PendingRequest $authenticator = $pendingRequest->getConnector()->getAuthenticator(); if (! $authenticator) { - throw new MissingAuthenticationException(); + throw new MissingAuthenticationException; } $authenticator->authenticate($pendingRequest); diff --git a/src/Http/Request.php b/src/Http/Request.php index 55faf5e9..62cd920c 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -10,9 +10,9 @@ abstract class Request { + use HandlesDebugging; use HandlesTestmode; use HasMiddleware; - use HandlesDebugging; use HasRequestProperties; /** diff --git a/src/Http/RequestSanitizer.php b/src/Http/RequestSanitizer.php index 82eb5a59..4c905b62 100644 --- a/src/Http/RequestSanitizer.php +++ b/src/Http/RequestSanitizer.php @@ -29,7 +29,7 @@ public function sanitize(RequestException $exception): RequestException $request = $response->getPsrRequest(); // Clear any sensitive payload data - $pendingRequest->setPayload(new JsonPayloadRepository()); + $pendingRequest->setPayload(new JsonPayloadRepository); // Remove sensitive headers and create a new sanitized request foreach ($this->sensitiveHeaders as $header) { diff --git a/src/Http/Requests/ApplePayPaymentSessionRequest.php b/src/Http/Requests/ApplePayPaymentSessionRequest.php index a42e49af..93f791a4 100644 --- a/src/Http/Requests/ApplePayPaymentSessionRequest.php +++ b/src/Http/Requests/ApplePayPaymentSessionRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\RequestApplePayPaymentSessionPayload; use Mollie\Api\Resources\AnyResource; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -16,20 +15,30 @@ class ApplePayPaymentSessionRequest extends ResourceHydratableRequest implements protected $hydratableResource = AnyResource::class; - private RequestApplePayPaymentSessionPayload $payload; + private string $domain; - public function __construct(RequestApplePayPaymentSessionPayload $payload) + private string $validationUrl; + + private ?string $profileId; + + public function __construct(string $domain, string $validationUrl, ?string $profileId = null) { - $this->payload = $payload; + $this->domain = $domain; + $this->validationUrl = $validationUrl; + $this->profileId = $profileId; } - public function resolveResourcePath(): string + public function defaultPayload(): array { - return 'wallets/applepay/sessions'; + return [ + 'domain' => $this->domain, + 'validationUrl' => $this->validationUrl, + 'profileId' => $this->profileId, + ]; } - public function defaultPayload(): array + public function resolveResourcePath(): string { - return $this->payload->toArray(); + return 'wallets/applepay/sessions'; } } diff --git a/src/Http/Requests/CreateClientLinkRequest.php b/src/Http/Requests/CreateClientLinkRequest.php index 70c77be0..ad92a398 100644 --- a/src/Http/Requests/CreateClientLinkRequest.php +++ b/src/Http/Requests/CreateClientLinkRequest.php @@ -3,7 +3,8 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\CreateClientLinkPayload; +use Mollie\Api\Http\Data\Owner; +use Mollie\Api\Http\Data\OwnerAddress; use Mollie\Api\Resources\ClientLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -22,16 +23,39 @@ class CreateClientLinkRequest extends ResourceHydratableRequest implements HasPa */ protected $hydratableResource = ClientLink::class; - private CreateClientLinkPayload $payload; + private Owner $owner; - public function __construct(CreateClientLinkPayload $payload) - { - $this->payload = $payload; + private string $name; + + private OwnerAddress $address; + + private ?string $registrationNumber; + + private ?string $vatNumber; + + public function __construct( + Owner $owner, + string $name, + OwnerAddress $address, + ?string $registrationNumber = null, + ?string $vatNumber = null + ) { + $this->owner = $owner; + $this->name = $name; + $this->address = $address; + $this->registrationNumber = $registrationNumber; + $this->vatNumber = $vatNumber; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'owner' => $this->owner, + 'name' => $this->name, + 'address' => $this->address, + 'registrationNumber' => $this->registrationNumber, + 'vatNumber' => $this->vatNumber, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreateCustomerPaymentRequest.php b/src/Http/Requests/CreateCustomerPaymentRequest.php index 146353ce..6a18ac86 100644 --- a/src/Http/Requests/CreateCustomerPaymentRequest.php +++ b/src/Http/Requests/CreateCustomerPaymentRequest.php @@ -4,8 +4,11 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\CreatePaymentPayload; -use Mollie\Api\Http\Data\CreatePaymentQuery; +use Mollie\Api\Http\Data\Address; +use Mollie\Api\Http\Data\ApplicationFee; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; class CreateCustomerPaymentRequest extends CreatePaymentRequest implements HasPayload, SupportsTestmodeInPayload { @@ -13,10 +16,54 @@ class CreateCustomerPaymentRequest extends CreatePaymentRequest implements HasPa public function __construct( string $customerId, - CreatePaymentPayload $payload, - ?CreatePaymentQuery $query = null + 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 $paymentMethod = 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 $profileId = null, + array $additional = [], + bool $includeQrCode = false ) { - parent::__construct($payload, $query); + parent::__construct( + $description, + $amount, + $redirectUrl, + $cancelUrl, + $webhookUrl, + $lines, + $billingAddress, + $shippingAddress, + $locale, + $paymentMethod, + $issuer, + $restrictPaymentMethodsToCountry, + $metadata, + $captureMode, + $captureDelay, + $applicationFee, + $routing, + $sequenceType, + $mandateId, + null, // customerId is already defined through path + $profileId, + $additional, + $includeQrCode + ); $this->customerId = $customerId; } diff --git a/src/Http/Requests/CreateCustomerRequest.php b/src/Http/Requests/CreateCustomerRequest.php index 8ad7cbc4..0b467959 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\Data\CreateCustomerPayload; +use Mollie\Api\Http\Data\Metadata; use Mollie\Api\Resources\Customer; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -17,16 +17,34 @@ class CreateCustomerRequest extends ResourceHydratableRequest implements HasPayl protected $hydratableResource = Customer::class; - private CreateCustomerPayload $payload; + private ?string $name; - public function __construct(CreateCustomerPayload $payload) - { - $this->payload = $payload; + private ?string $email; + + private ?string $locale; + + private ?Metadata $metadata; + + public function __construct( + ?string $name = null, + ?string $email = null, + ?string $locale = null, + ?Metadata $metadata = null + ) { + $this->name = $name; + $this->email = $email; + $this->locale = $locale; + $this->metadata = $metadata; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'name' => $this->name, + 'email' => $this->email, + 'locale' => $this->locale, + 'metadata' => $this->metadata, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreateMandateRequest.php b/src/Http/Requests/CreateMandateRequest.php index 6167de57..c42a510a 100644 --- a/src/Http/Requests/CreateMandateRequest.php +++ b/src/Http/Requests/CreateMandateRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\CreateMandatePayload; use Mollie\Api\Resources\Mandate; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -25,17 +25,56 @@ class CreateMandateRequest extends ResourceHydratableRequest implements HasPaylo private string $customerId; - private CreateMandatePayload $payload; + private string $paymentMethod; - public function __construct(string $customerId, CreateMandatePayload $payload) - { + private string $consumerName; + + private ?string $consumerAccount; + + private ?string $consumerBic; + + private ?string $consumerEmail; + + private ?DateTimeInterface $signatureDate; + + private ?string $mandateReference; + + private ?string $paypalBillingAgreementId; + + public function __construct( + string $customerId, + string $paymentMethod, + string $consumerName, + ?string $consumerAccount = null, + ?string $consumerBic = null, + ?string $consumerEmail = null, + ?DateTimeInterface $signatureDate = null, + ?string $mandateReference = null, + ?string $paypalBillingAgreementId = null + ) { $this->customerId = $customerId; - $this->payload = $payload; + $this->paymentMethod = $paymentMethod; + $this->consumerName = $consumerName; + $this->consumerAccount = $consumerAccount; + $this->consumerBic = $consumerBic; + $this->consumerEmail = $consumerEmail; + $this->signatureDate = $signatureDate; + $this->mandateReference = $mandateReference; + $this->paypalBillingAgreementId = $paypalBillingAgreementId; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'method' => $this->paymentMethod, + 'consumerName' => $this->consumerName, + 'consumerAccount' => $this->consumerAccount, + 'consumerBic' => $this->consumerBic, + 'consumerEmail' => $this->consumerEmail, + 'signatureDate' => $this->signatureDate, + 'mandateReference' => $this->mandateReference, + 'paypalBillingAgreementId' => $this->paypalBillingAgreementId, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreatePaymentCaptureRequest.php b/src/Http/Requests/CreatePaymentCaptureRequest.php index 38389959..b0aafbb8 100644 --- a/src/Http/Requests/CreatePaymentCaptureRequest.php +++ b/src/Http/Requests/CreatePaymentCaptureRequest.php @@ -4,7 +4,8 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\CreatePaymentCapturePayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\Capture; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -25,17 +26,31 @@ class CreatePaymentCaptureRequest extends ResourceHydratableRequest implements H private string $paymentId; - private CreatePaymentCapturePayload $payload; + private string $description; - public function __construct(string $paymentId, CreatePaymentCapturePayload $payload) - { + private ?Money $amount; + + private ?Metadata $metadata; + + public function __construct( + string $paymentId, + string $description, + ?Money $amount = null, + ?Metadata $metadata = null + ) { $this->paymentId = $paymentId; - $this->payload = $payload; + $this->description = $description; + $this->amount = $amount; + $this->metadata = $metadata; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'metadata' => $this->metadata, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreatePaymentLinkRequest.php b/src/Http/Requests/CreatePaymentLinkRequest.php index cea9aa42..821bfcdf 100644 --- a/src/Http/Requests/CreatePaymentLinkRequest.php +++ b/src/Http/Requests/CreatePaymentLinkRequest.php @@ -2,8 +2,9 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\CreatePaymentLinkPayload; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -22,16 +23,54 @@ class CreatePaymentLinkRequest extends ResourceHydratableRequest implements HasP */ protected $hydratableResource = PaymentLink::class; - private CreatePaymentLinkPayload $payload; + private string $description; - public function __construct(CreatePaymentLinkPayload $payload) - { - $this->payload = $payload; + private ?Money $amount; + + private ?string $redirectUrl; + + private ?string $webhookUrl; + + private ?string $profileId; + + private ?bool $reusable; + + private ?DateTimeInterface $expiresAt; + + private ?array $allowedMethods; + + public function __construct( + string $description, + ?Money $amount = null, + ?string $redirectUrl = null, + ?string $webhookUrl = null, + ?string $profileId = null, + ?bool $reusable = null, + ?DateTimeInterface $expiresAt = null, + ?array $allowedMethods = null + ) { + $this->description = $description; + $this->amount = $amount; + $this->redirectUrl = $redirectUrl; + $this->webhookUrl = $webhookUrl; + $this->profileId = $profileId; + $this->reusable = $reusable; + $this->expiresAt = $expiresAt; + $this->allowedMethods = $allowedMethods; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'redirectUrl' => $this->redirectUrl, + 'webhookUrl' => $this->webhookUrl, + 'profileId' => $this->profileId, + 'reusable' => $this->reusable, + 'expiresAt' => $this->expiresAt, + 'allowedMethods' => $this->allowedMethods, + ]; } /** diff --git a/src/Http/Requests/CreatePaymentRefundRequest.php b/src/Http/Requests/CreatePaymentRefundRequest.php index eca3d8a3..11c0f583 100644 --- a/src/Http/Requests/CreatePaymentRefundRequest.php +++ b/src/Http/Requests/CreatePaymentRefundRequest.php @@ -4,7 +4,9 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\CreateRefundPaymentPayload; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\Refund; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -25,19 +27,41 @@ class CreatePaymentRefundRequest extends ResourceHydratableRequest implements Ha private string $paymentId; - private CreateRefundPaymentPayload $payload; + private string $description; + + private Money $amount; + + private ?Metadata $metadata; + + private ?bool $reverseRouting; + + private ?DataCollection $routingReversals; public function __construct( - string $identifier, - CreateRefundPaymentPayload $payload + string $paymentId, + string $description, + Money $amount, + ?Metadata $metadata = null, + ?bool $reverseRouting = null, + ?DataCollection $routingReversals = null ) { - $this->paymentId = $identifier; - $this->payload = $payload; + $this->paymentId = $paymentId; + $this->description = $description; + $this->amount = $amount; + $this->metadata = $metadata; + $this->reverseRouting = $reverseRouting; + $this->routingReversals = $routingReversals; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'description' => $this->description, + 'amount' => $this->amount, + 'metadata' => $this->metadata, + 'reverseRouting' => $this->reverseRouting, + 'routingReversals' => $this->routingReversals, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/CreatePaymentRequest.php b/src/Http/Requests/CreatePaymentRequest.php index 186fd774..9e271e2f 100644 --- a/src/Http/Requests/CreatePaymentRequest.php +++ b/src/Http/Requests/CreatePaymentRequest.php @@ -3,14 +3,20 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\CreatePaymentPayload; -use Mollie\Api\Http\Data\CreatePaymentQuery; +use Mollie\Api\Contracts\SupportsTestmodeInPayload; +use Mollie\Api\Http\Data\Address; +use Mollie\Api\Http\Data\ApplicationFee; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; +use Mollie\Api\Http\Data\OrderLine; +use Mollie\Api\Http\Data\PaymentRoute; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentQuery; -class CreatePaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInQuery +class CreatePaymentRequest extends ResourceHydratableRequest implements HasPayload, SupportsTestmodeInPayload { use HasJsonPayload; @@ -24,24 +30,145 @@ class CreatePaymentRequest extends ResourceHydratableRequest implements HasPaylo */ protected $hydratableResource = Payment::class; - private CreatePaymentPayload $payload; + private string $description; - private ?CreatePaymentQuery $query = null; + private Money $amount; - public function __construct(CreatePaymentPayload $payload, ?CreatePaymentQuery $query = null) - { - $this->payload = $payload; - $this->query = $query; + private ?string $redirectUrl; + + private ?string $cancelUrl; + + private ?string $webhookUrl; + + /** + * @var DataCollection|null + */ + private ?DataCollection $lines; + + private ?Address $billingAddress; + + private ?Address $shippingAddress; + + private ?string $locale; + + private ?string $paymentMethod; + + private ?string $issuer; + + private ?string $restrictPaymentMethodsToCountry; + + private ?Metadata $metadata; + + private ?string $captureMode; + + private ?string $captureDelay; + + private ?ApplicationFee $applicationFee; + + /** + * @var DataCollection|null + */ + private ?DataCollection $routing; + + private ?string $sequenceType; + + private ?string $mandateId; + + private ?string $customerId; + + private ?string $profileId; + + /** + * Method specific data. + * + * s. https://docs.mollie.com/reference/extra-payment-parameters#payment-creation-request-parameters + */ + private array $additional = []; + + private bool $includeQrCode; + + 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 $paymentMethod = 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, + array $additional = [], + bool $includeQrCode = false + ) { + $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->paymentMethod = $paymentMethod; + $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->includeQrCode = $includeQrCode; } protected function defaultPayload(): array { - return $this->payload->toArray(); + 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->paymentMethod, + '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); } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'include' => $this->includeQrCode ? PaymentQuery::INCLUDE_QR_CODE : null, + ]; } /** diff --git a/src/Http/Requests/CreateProfileRequest.php b/src/Http/Requests/CreateProfileRequest.php index 2984c25c..29f42f91 100644 --- a/src/Http/Requests/CreateProfileRequest.php +++ b/src/Http/Requests/CreateProfileRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\CreateProfilePayload; use Mollie\Api\Resources\Profile; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -22,16 +21,49 @@ class CreateProfileRequest extends ResourceHydratableRequest implements HasPaylo */ protected $hydratableResource = Profile::class; - private CreateProfilePayload $payload; + private string $name; - public function __construct(CreateProfilePayload $payload) - { - $this->payload = $payload; + private string $website; + + private string $email; + + private string $phone; + + private ?string $description; + + private ?array $countriesOfActivity; + + private ?string $businessCategory; + + public function __construct( + string $name, + string $website, + string $email, + string $phone, + ?string $description = null, + ?array $countriesOfActivity = null, + ?string $businessCategory = null + ) { + $this->name = $name; + $this->website = $website; + $this->email = $email; + $this->phone = $phone; + $this->description = $description; + $this->countriesOfActivity = $countriesOfActivity; + $this->businessCategory = $businessCategory; } protected function defaultPayload(): array { - return $this->payload->toArray(); + 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/Requests/CreateSalesInvoiceRequest.php b/src/Http/Requests/CreateSalesInvoiceRequest.php index 31f69606..e4b89c8b 100644 --- a/src/Http/Requests/CreateSalesInvoiceRequest.php +++ b/src/Http/Requests/CreateSalesInvoiceRequest.php @@ -3,10 +3,18 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\CreateSalesInvoicePayload; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\Discount; +use Mollie\Api\Http\Data\EmailDetails; +use Mollie\Api\Http\Data\InvoiceLine; +use Mollie\Api\Http\Data\PaymentDetails; +use Mollie\Api\Http\Data\Recipient; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentTerm; +use Mollie\Api\Types\VatMode; +use Mollie\Api\Types\VatScheme; class CreateSalesInvoiceRequest extends ResourceHydratableRequest implements HasPayload { @@ -16,20 +24,91 @@ class CreateSalesInvoiceRequest extends ResourceHydratableRequest implements Has protected $hydratableResource = SalesInvoice::class; - private CreateSalesInvoicePayload $payload; + private string $currency; - public function __construct(CreateSalesInvoicePayload $payload) - { - $this->payload = $payload; + private string $status; + + private string $vatScheme = VatScheme::STANDARD; + + private string $vatMode = VatMode::EXCLUSIVE; + + private string $paymentTerm = PaymentTerm::DAYS_30; + + public string $recipientIdentifier; + + public Recipient $recipient; + + /** + * @var DataCollection + */ + public DataCollection $lines; + + public ?string $profileId; + + public ?string $memo; + + public ?PaymentDetails $paymentDetails; + + public ?EmailDetails $emailDetails; + + 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->currency = $currency; + $this->status = $status; + $this->vatScheme = $vatScheme; + $this->vatMode = $vatMode; + $this->paymentTerm = $paymentTerm; + $this->recipientIdentifier = $recipientIdentifier; + $this->recipient = $recipient; + $this->lines = $lines; + $this->profileId = $profileId; + $this->memo = $memo; + $this->paymentDetails = $paymentDetails; + $this->emailDetails = $emailDetails; + $this->webhookUrl = $webhookUrl; + $this->discount = $discount; } - public function resolveResourcePath(): string + public function defaultPayload(): array { - return 'sales-invoices'; + return [ + 'currency' => $this->currency, + 'status' => $this->status, + 'vatScheme' => $this->vatScheme, + 'vatMode' => $this->vatMode, + 'paymentTerm' => $this->paymentTerm, + 'recipientIdentifier' => $this->recipientIdentifier, + 'recipient' => $this->recipient, + 'lines' => $this->lines, + 'profileId' => $this->profileId, + 'memo' => $this->memo, + 'paymentDetails' => $this->paymentDetails, + 'emailDetails' => $this->emailDetails, + 'webhookUrl' => $this->webhookUrl, + 'discount' => $this->discount, + ]; } - public function defaultPayload(): array + public function resolveResourcePath(): string { - return $this->payload->toArray(); + return 'sales-invoices'; } } diff --git a/src/Http/Requests/CreateSessionRequest.php b/src/Http/Requests/CreateSessionRequest.php index 94be5ebb..0d92e124 100644 --- a/src/Http/Requests/CreateSessionRequest.php +++ b/src/Http/Requests/CreateSessionRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -16,26 +15,6 @@ class CreateSessionRequest extends ResourceHydratableRequest implements HasPaylo protected $hydratableResource = Session::class; - private AnyData $payload; - - private AnyData $query; - - public function __construct(AnyData $payload, AnyData $query) - { - $this->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/CreateSubscriptionRequest.php b/src/Http/Requests/CreateSubscriptionRequest.php index 9030a9a9..7579389a 100644 --- a/src/Http/Requests/CreateSubscriptionRequest.php +++ b/src/Http/Requests/CreateSubscriptionRequest.php @@ -2,9 +2,12 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\CreateSubscriptionPayload; +use Mollie\Api\Http\Data\ApplicationFee; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\Subscription; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -25,17 +28,76 @@ class CreateSubscriptionRequest extends ResourceHydratableRequest implements Has private string $customerId; - private CreateSubscriptionPayload $payload; + private Money $amount; - public function __construct(string $customerId, CreateSubscriptionPayload $payload) - { + private string $interval; + + private string $description; + + private ?string $status; + + private ?int $times; + + private ?DateTimeInterface $startDate; + + private ?string $paymentMethod; + + private ?ApplicationFee $applicationFee; + + private ?Metadata $metadata; + + private ?string $webhookUrl; + + private ?string $mandateId; + + private ?string $profileId; + + public function __construct( + string $customerId, + Money $amount, + string $interval, + string $description, + ?string $status = null, + ?int $times = null, + ?DateTimeInterface $startDate = null, + ?string $paymentMethod = null, + ?ApplicationFee $applicationFee = null, + ?Metadata $metadata = null, + ?string $webhookUrl = null, + ?string $mandateId = null, + ?string $profileId = null + ) { $this->customerId = $customerId; - $this->payload = $payload; + $this->amount = $amount; + $this->interval = $interval; + $this->description = $description; + $this->status = $status; + $this->times = $times; + $this->startDate = $startDate; + $this->paymentMethod = $paymentMethod; + $this->applicationFee = $applicationFee; + $this->metadata = $metadata; + $this->webhookUrl = $webhookUrl; + $this->mandateId = $mandateId; + $this->profileId = $profileId; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'amount' => $this->amount, + 'interval' => $this->interval, + 'description' => $this->description, + 'status' => $this->status, + 'times' => $this->times, + 'startDate' => $this->startDate, + 'method' => $this->paymentMethod, + 'applicationFee' => $this->applicationFee, + 'metadata' => $this->metadata, + 'webhookUrl' => $this->webhookUrl, + 'mandateId' => $this->mandateId, + 'profileId' => $this->profileId, + ]; } /** diff --git a/src/Http/Requests/GetAllMethodsRequest.php b/src/Http/Requests/GetAllMethodsRequest.php index 5ddab946..0b3b0e08 100644 --- a/src/Http/Requests/GetAllMethodsRequest.php +++ b/src/Http/Requests/GetAllMethodsRequest.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Data\GetAllMethodsQuery; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\MethodCollection; use Mollie\Api\Types\Method as HttpMethod; +use Mollie\Api\Types\MethodQuery; class GetAllMethodsRequest extends ResourceHydratableRequest { @@ -18,16 +19,32 @@ class GetAllMethodsRequest extends ResourceHydratableRequest */ protected $hydratableResource = MethodCollection::class; - private GetAllMethodsQuery $query; + private bool $includeIssuers; - public function __construct(?GetAllMethodsQuery $query = null) + private bool $includePricing; + + private ?string $locale; + + private ?Money $amount; + + public function __construct(bool $includeIssuers = false, bool $includePricing = false, ?string $locale = null, ?Money $amount = null) { - $this->query = $query ?: new GetAllMethodsQuery; + $this->includeIssuers = $includeIssuers; + $this->includePricing = $includePricing; + $this->locale = $locale; + $this->amount = $amount; } protected function defaultQuery(): array { - return $this->query->toArray(); + return [ + 'include' => array_filter([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), + 'locale' => $this->locale, + 'amount' => $this->amount, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php index ca69d815..0dcf847a 100644 --- a/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetAllPaginatedSubscriptionsRequest.php @@ -6,16 +6,41 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\SubscriptionCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\Method; -class GetAllPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetAllPaginatedSubscriptionsRequest extends ResourceHydratableRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; + protected static string $method = Method::GET; + /** * The resource class the request should be casted to. */ protected $hydratableResource = SubscriptionCollection::class; + private ?string $profileId; + + private ?string $from; + + private ?string $limit; + + public function __construct(?string $from = null, ?string $limit = null, ?string $profileId = null) + { + $this->from = $from; + $this->limit = $limit; + $this->profileId = $profileId; + } + + public function defaultQuery(): array + { + return [ + 'from' => $this->from, + 'limit' => $this->limit, + 'profileId' => $this->profileId, + ]; + } + /** * The resource path. */ diff --git a/src/Http/Requests/GetBalanceReportRequest.php b/src/Http/Requests/GetBalanceReportRequest.php index 8d833874..f37cd81b 100644 --- a/src/Http/Requests/GetBalanceReportRequest.php +++ b/src/Http/Requests/GetBalanceReportRequest.php @@ -2,8 +2,8 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetBalanceReportQuery; use Mollie\Api\Resources\BalanceReport; use Mollie\Api\Types\Method; @@ -21,17 +21,27 @@ class GetBalanceReportRequest extends ResourceHydratableRequest implements Suppo private string $balanceId; - private GetBalanceReportQuery $query; + private DateTimeInterface $from; - public function __construct(string $balanceId, GetBalanceReportQuery $query) + private DateTimeInterface $until; + + private ?string $grouping; + + public function __construct(string $balanceId, DateTimeInterface $from, DateTimeInterface $until, ?string $grouping = null) { $this->balanceId = $balanceId; - $this->query = $query; + $this->from = $from; + $this->until = $until; + $this->grouping = $grouping; } protected function defaultQuery(): array { - return $this->query->toArray(); + return [ + 'from' => $this->from, + 'until' => $this->until, + 'grouping' => $this->grouping, + ]; } /** diff --git a/src/Http/Requests/GetClientRequest.php b/src/Http/Requests/GetClientRequest.php index 5f707ce4..10c904bb 100644 --- a/src/Http/Requests/GetClientRequest.php +++ b/src/Http/Requests/GetClientRequest.php @@ -2,9 +2,10 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Data\GetClientQuery; use Mollie\Api\Resources\Client; +use Mollie\Api\Types\ClientQuery; use Mollie\Api\Types\Method; +use Mollie\Api\Utils\Arr; class GetClientRequest extends ResourceHydratableRequest { @@ -20,17 +21,25 @@ class GetClientRequest extends ResourceHydratableRequest private string $id; - private ?GetClientQuery $query; + private ?bool $embedOrganization; - public function __construct(string $id, ?GetClientQuery $query = null) + private ?bool $embedOnboarding; + + public function __construct(string $id, ?bool $embedOrganization = null, ?bool $embedOnboarding = null) { $this->id = $id; - $this->query = $query; + $this->embedOrganization = $embedOrganization; + $this->embedOnboarding = $embedOnboarding; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'embed' => Arr::join([ + $this->embedOrganization ? ClientQuery::EMBED_ORGANIZATION : null, + $this->embedOnboarding ? ClientQuery::EMBED_ONBOARDING : null, + ]), + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetCurrentProfileRequest.php b/src/Http/Requests/GetCurrentProfileRequest.php new file mode 100644 index 00000000..f084c90e --- /dev/null +++ b/src/Http/Requests/GetCurrentProfileRequest.php @@ -0,0 +1,22 @@ +query = $query; + 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( + string $sequenceType = SequenceType::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; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'sequenceType' => $this->sequenceType, + 'resource' => $this->resource, + 'locale' => $this->locale, + 'amount' => $this->amount, + 'billingCountry' => $this->billingCountry, + 'includeWallets' => Arr::join($this->includeWallets ?? []), + 'orderLineCategories' => Arr::join($this->orderLineCategories ?? []), + 'profileId' => $this->profileId, + 'include' => array_filter([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedBalanceRequest.php b/src/Http/Requests/GetPaginatedBalanceRequest.php index 4b7b6394..574beba5 100644 --- a/src/Http/Requests/GetPaginatedBalanceRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceRequest.php @@ -7,18 +7,12 @@ use Mollie\Api\Resources\BalanceCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedBalanceRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedBalanceRequest extends SortablePaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; - /** - * The resource class the request should be casted to. - */ protected $hydratableResource = BalanceCollection::class; - /** - * Resolve the resource path. - */ public function resolveResourcePath(): string { return 'balances'; diff --git a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php index b61140f5..7d23b1f5 100644 --- a/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php +++ b/src/Http/Requests/GetPaginatedBalanceTransactionRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\IsIteratable; -use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Traits\IsIteratableRequest; @@ -20,11 +19,12 @@ class GetPaginatedBalanceTransactionRequest extends PaginatedRequest implements public function __construct( string $balanceId, - ?PaginatedQuery $query = null + ?string $from = null, + ?int $limit = null ) { - parent::__construct($query); - $this->balanceId = $balanceId; + + parent::__construct($from, $limit); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedChargebacksRequest.php b/src/Http/Requests/GetPaginatedChargebacksRequest.php index 488a3bda..83f8dc64 100644 --- a/src/Http/Requests/GetPaginatedChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedChargebacksRequest.php @@ -6,6 +6,7 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedChargebacksRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { @@ -16,6 +17,19 @@ class GetPaginatedChargebacksRequest extends PaginatedRequest implements IsItera */ protected $hydratableResource = ChargebackCollection::class; + public function __construct( + ?string $from = null, + ?int $limit = null, + ?bool $includePayment = null, + ?string $profileId = null + ) { + parent::__construct($from, $limit); + + $this->query() + ->add('include', $includePayment ? PaymentIncludesQuery::PAYMENT : null) + ->add('profileId', $profileId); + } + public function resolveResourcePath(): string { return 'chargebacks'; diff --git a/src/Http/Requests/GetPaginatedClientRequest.php b/src/Http/Requests/GetPaginatedClientRequest.php index 0ade79a3..898c5e4b 100644 --- a/src/Http/Requests/GetPaginatedClientRequest.php +++ b/src/Http/Requests/GetPaginatedClientRequest.php @@ -5,6 +5,8 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Resources\ClientCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\ClientQuery; +use Mollie\Api\Utils\Arr; class GetPaginatedClientRequest extends PaginatedRequest implements IsIteratable { @@ -15,6 +17,21 @@ class GetPaginatedClientRequest extends PaginatedRequest implements IsIteratable */ protected $hydratableResource = ClientCollection::class; + public function __construct( + ?string $from = null, + ?int $limit = null, + ?bool $embedOrganization = null, + ?bool $embedOnboarding = null + ) { + parent::__construct($from, $limit); + + $this->query() + ->add('embed', Arr::join([ + $embedOrganization ? ClientQuery::EMBED_ORGANIZATION : null, + $embedOnboarding ? ClientQuery::EMBED_ONBOARDING : null, + ])); + } + public function resolveResourcePath(): string { return 'clients'; diff --git a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php index aa50501b..942db718 100644 --- a/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedCustomerPaymentsRequest.php @@ -4,11 +4,10 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedCustomerPaymentsQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedCustomerPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedCustomerPaymentsRequest extends SortablePaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; @@ -21,11 +20,17 @@ class GetPaginatedCustomerPaymentsRequest extends PaginatedRequest implements Is public function __construct( string $customerId, - ?GetPaginatedCustomerPaymentsQuery $query = null + ?string $from = null, + ?int $limit = null, + ?string $sort = null, + ?string $profileId = null ) { - parent::__construct($query); - $this->customerId = $customerId; + + parent::__construct($from, $limit, $sort); + + $this->query() + ->add('profileId', $profileId); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedInvoiceRequest.php b/src/Http/Requests/GetPaginatedInvoiceRequest.php index f6689599..34e4fc24 100644 --- a/src/Http/Requests/GetPaginatedInvoiceRequest.php +++ b/src/Http/Requests/GetPaginatedInvoiceRequest.php @@ -15,6 +15,19 @@ class GetPaginatedInvoiceRequest extends PaginatedRequest implements IsIteratabl */ protected $hydratableResource = InvoiceCollection::class; + public function __construct( + ?string $from = null, + ?int $limit = null, + ?string $reference = null, + ?string $year = null + ) { + parent::__construct($from, $limit); + + $this->query() + ->add('reference', $reference) + ->add('year', $year); + } + public function resolveResourcePath(): string { return 'invoices'; diff --git a/src/Http/Requests/GetPaginatedMandateRequest.php b/src/Http/Requests/GetPaginatedMandateRequest.php index f2f3f90a..c56bb5b5 100644 --- a/src/Http/Requests/GetPaginatedMandateRequest.php +++ b/src/Http/Requests/GetPaginatedMandateRequest.php @@ -4,7 +4,6 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\MandateCollection; use Mollie\Api\Traits\IsIteratableRequest; @@ -19,11 +18,11 @@ class GetPaginatedMandateRequest extends PaginatedRequest implements IsIteratabl private string $customerId; - public function __construct(string $customerId, ?PaginatedQuery $query = null) + public function __construct(string $customerId, ?string $from = null, ?int $limit = null) { - parent::__construct($query); - $this->customerId = $customerId; + + parent::__construct($from, $limit); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php index 6cbbd818..29bd793f 100644 --- a/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentCapturesRequest.php @@ -4,20 +4,15 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedPaymentCapturesQuery; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Utils\Arr; class GetPaginatedPaymentCapturesRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected static string $method = Method::GET; - /** * The resource class the request should be casted to. */ @@ -25,17 +20,14 @@ class GetPaginatedPaymentCapturesRequest extends PaginatedRequest implements IsI private string $paymentId; - private ?GetPaginatedPaymentCapturesQuery $query; - - public function __construct(string $paymentId, ?GetPaginatedPaymentCapturesQuery $query = null) + public function __construct(string $paymentId, ?string $from = null, ?int $limit = null, bool $includePayment = false) { $this->paymentId = $paymentId; - $this->query = $query; - } - protected function defaultQuery(): array - { - return $this->query ? $this->query->toArray() : []; + parent::__construct($from, $limit); + + $this->query() + ->add('include', Arr::join($includePayment ? [PaymentIncludesQuery::PAYMENT] : [])); } /** diff --git a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php index ed51d048..aab66e63 100644 --- a/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentChargebacksRequest.php @@ -4,20 +4,14 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedPaymentChargebacksQuery; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentChargebacksRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected static string $method = Method::GET; - /** * The resource class the request should be casted to. */ @@ -25,11 +19,14 @@ class GetPaginatedPaymentChargebacksRequest extends PaginatedRequest implements private string $paymentId; - public function __construct(string $paymentId, ?GetPaginatedPaymentChargebacksQuery $query = null) + public function __construct(string $paymentId, ?string $from = null, ?int $limit = null, bool $includePayment = false) { - parent::__construct($query); - $this->paymentId = $paymentId; + + parent::__construct($from, $limit); + + $this->query() + ->add('include', $includePayment ? PaymentIncludesQuery::PAYMENT : null); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php index d23914a2..3b52fafa 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinkPaymentsRequest.php @@ -4,11 +4,10 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedPaymentLinkPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedPaymentLinkPaymentsRequest extends SortablePaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; @@ -19,10 +18,11 @@ class GetPaginatedPaymentLinkPaymentsRequest extends PaginatedRequest implements private string $paymentLinkId; - public function __construct(string $paymentLinkId, ?SortablePaginatedQuery $query = null) + public function __construct(string $paymentLinkId, ?string $from = null, ?int $limit = null, ?string $sort = null) { - parent::__construct($query); $this->paymentLinkId = $paymentLinkId; + + parent::__construct($from, $limit, $sort); } /** diff --git a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php index 5c05b218..4f867dfd 100644 --- a/src/Http/Requests/GetPaginatedPaymentLinksRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentLinksRequest.php @@ -6,17 +6,11 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\PaymentLinkCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Types\Method; class GetPaginatedPaymentLinksRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected static string $method = Method::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 82040b67..5d1c4ce8 100644 --- a/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentRefundsRequest.php @@ -4,9 +4,9 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedPaymentRefundQuery; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedPaymentRefundsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { @@ -21,11 +21,16 @@ class GetPaginatedPaymentRefundsRequest extends PaginatedRequest implements IsIt public function __construct( string $paymentId, - ?GetPaginatedPaymentRefundQuery $query = null + ?string $from = null, + ?int $limit = null, + bool $includePayment = false ) { - parent::__construct($query); - $this->paymentId = $paymentId; + + parent::__construct($from, $limit); + + $this->query() + ->add('include', $includePayment ? PaymentIncludesQuery::PAYMENT : null); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaginatedPaymentsRequest.php b/src/Http/Requests/GetPaginatedPaymentsRequest.php index 18c7f0f6..793106f6 100644 --- a/src/Http/Requests/GetPaginatedPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedPaymentsRequest.php @@ -7,7 +7,7 @@ use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedPaymentsRequest extends SortablePaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedProfilesRequest.php b/src/Http/Requests/GetPaginatedProfilesRequest.php index 1a9113b9..b90a5a4d 100644 --- a/src/Http/Requests/GetPaginatedProfilesRequest.php +++ b/src/Http/Requests/GetPaginatedProfilesRequest.php @@ -3,31 +3,18 @@ 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; class GetPaginatedProfilesRequest extends PaginatedRequest implements IsIteratable { use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected static string $method = Method::GET; - /** * The resource class the request should be casted to. */ 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 69723cdf..1411d27f 100644 --- a/src/Http/Requests/GetPaginatedRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedRefundsRequest.php @@ -6,22 +6,30 @@ use Mollie\Api\Contracts\SupportsTestmodeInQuery; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Traits\IsIteratableRequest; -use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedRefundsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; - /** - * Define the HTTP method. - */ - protected static string $method = Method::GET; - /** * The resource class the request should be casted to. */ protected $hydratableResource = RefundCollection::class; + public function __construct( + ?string $from = null, + ?int $limit = null, + bool $embedPayment = false, + ?string $profileId = null + ) { + parent::__construct($from, $limit); + + $this->query() + ->add('embed', $embedPayment ? PaymentIncludesQuery::PAYMENT : null) + ->add('profileId', $profileId); + } + public function resolveResourcePath(): string { return 'refunds'; diff --git a/src/Http/Requests/GetPaginatedSessionsRequest.php b/src/Http/Requests/GetPaginatedSessionsRequest.php index 2c010cf0..d80dd651 100644 --- a/src/Http/Requests/GetPaginatedSessionsRequest.php +++ b/src/Http/Requests/GetPaginatedSessionsRequest.php @@ -6,7 +6,7 @@ use Mollie\Api\Resources\SessionCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedSessionsRequest extends PaginatedRequest implements IsIteratable +class GetPaginatedSessionsRequest extends SortablePaginatedRequest implements IsIteratable { use IsIteratableRequest; diff --git a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php index b1ecd232..e8622ad4 100644 --- a/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementCapturesRequest.php @@ -4,9 +4,10 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedSettlementCapturesQuery; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Utils\Arr; class GetPaginatedSettlementCapturesRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { @@ -19,11 +20,18 @@ class GetPaginatedSettlementCapturesRequest extends PaginatedRequest implements private string $settlementId; - public function __construct(string $settlementId, ?GetPaginatedSettlementCapturesQuery $query = null) - { + public function __construct( + string $settlementId, + ?string $from = null, + ?int $limit = null, + bool $includePayment = false + ) { $this->settlementId = $settlementId; - parent::__construct($query); + parent::__construct($from, $limit); + + $this->query() + ->add('include', Arr::join($includePayment ? [PaymentIncludesQuery::PAYMENT] : [])); } /** diff --git a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php index b846929a..4bd06f9c 100644 --- a/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementChargebacksRequest.php @@ -4,26 +4,21 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedSettlementChargebacksQuery; -use Mollie\Api\Resources\ChargebackCollection; -use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedSettlementChargebacksRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedSettlementChargebacksRequest extends GetPaginatedChargebacksRequest implements IsIteratable, SupportsTestmodeInQuery { - use IsIteratableRequest; - - /** - * The resource class the request should be casted to. - */ - protected $hydratableResource = ChargebackCollection::class; - private string $settlementId; - public function __construct(string $settlementId, ?GetPaginatedSettlementChargebacksQuery $query = null) - { + public function __construct( + string $settlementId, + ?string $from = null, + ?int $limit = null, + ?bool $includePayment = null, + ?string $profileId = null + ) { $this->settlementId = $settlementId; - parent::__construct($query); + parent::__construct($from, $limit, $includePayment, $profileId); } /** diff --git a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php index 20770a80..033583c7 100644 --- a/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementPaymentsRequest.php @@ -4,11 +4,10 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\SortablePaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; -class GetPaginatedSettlementPaymentsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery +class GetPaginatedSettlementPaymentsRequest extends SortablePaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { use IsIteratableRequest; @@ -19,11 +18,11 @@ class GetPaginatedSettlementPaymentsRequest extends PaginatedRequest implements private string $settlementId; - public function __construct(string $settlementId, ?SortablePaginatedQuery $query = null) + public function __construct(string $settlementId, ?string $from = null, ?int $limit = null, ?string $sort = null) { $this->settlementId = $settlementId; - parent::__construct($query); + parent::__construct($from, $limit, $sort); } /** diff --git a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php index 4d33a662..9c787420 100644 --- a/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementRefundsRequest.php @@ -4,9 +4,9 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaginatedSettlementRefundsQuery; use Mollie\Api\Resources\RefundCollection; use Mollie\Api\Traits\IsIteratableRequest; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaginatedSettlementRefundsRequest extends PaginatedRequest implements IsIteratable, SupportsTestmodeInQuery { @@ -19,11 +19,18 @@ class GetPaginatedSettlementRefundsRequest extends PaginatedRequest implements I private string $settlementId; - public function __construct(string $settlementId, ?GetPaginatedSettlementRefundsQuery $query = null) - { + public function __construct( + string $settlementId, + ?string $from = null, + ?int $limit = null, + bool $includePayment = false + ) { $this->settlementId = $settlementId; - parent::__construct($query); + parent::__construct($from, $limit); + + $this->query() + ->add('include', $includePayment ? PaymentIncludesQuery::PAYMENT : null); } /** diff --git a/src/Http/Requests/GetPaginatedSettlementsRequest.php b/src/Http/Requests/GetPaginatedSettlementsRequest.php index 427d59c1..b3ca7524 100644 --- a/src/Http/Requests/GetPaginatedSettlementsRequest.php +++ b/src/Http/Requests/GetPaginatedSettlementsRequest.php @@ -15,6 +15,17 @@ class GetPaginatedSettlementsRequest extends PaginatedRequest implements IsItera */ protected $hydratableResource = SettlementCollection::class; + public function __construct( + ?string $from = null, + ?int $limit = null, + ?string $balanceId = null + ) { + parent::__construct($from, $limit); + + $this->query() + ->add('balanceId', $balanceId); + } + /** * Resolve the resource path. */ diff --git a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php index 073e1e8c..01f36bcb 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionPaymentsRequest.php @@ -4,7 +4,6 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\PaymentCollection; use Mollie\Api\Traits\IsIteratableRequest; @@ -21,12 +20,12 @@ class GetPaginatedSubscriptionPaymentsRequest extends PaginatedRequest implement private string $subscriptionId; - public function __construct(string $customerId, string $subscriptionId, ?PaginatedQuery $query = null) + public function __construct(string $customerId, string $subscriptionId, ?string $from = null, ?int $limit = null) { $this->customerId = $customerId; $this->subscriptionId = $subscriptionId; - parent::__construct($query); + parent::__construct($from, $limit); } /** diff --git a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php index aa7bfedc..66da3c48 100644 --- a/src/Http/Requests/GetPaginatedSubscriptionsRequest.php +++ b/src/Http/Requests/GetPaginatedSubscriptionsRequest.php @@ -4,7 +4,6 @@ use Mollie\Api\Contracts\IsIteratable; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\PaginatedQuery; use Mollie\Api\Resources\SubscriptionCollection; use Mollie\Api\Traits\IsIteratableRequest; @@ -19,11 +18,11 @@ class GetPaginatedSubscriptionsRequest extends PaginatedRequest implements IsIte private string $customerId; - public function __construct(string $customerId, ?PaginatedQuery $query = null) + public function __construct(string $customerId, ?string $from = null, ?int $limit = null) { $this->customerId = $customerId; - parent::__construct($query); + parent::__construct($from, $limit); } /** diff --git a/src/Http/Requests/GetPaginatedTerminalsRequest.php b/src/Http/Requests/GetPaginatedTerminalsRequest.php index d85d0f96..503bee5b 100644 --- a/src/Http/Requests/GetPaginatedTerminalsRequest.php +++ b/src/Http/Requests/GetPaginatedTerminalsRequest.php @@ -16,9 +16,6 @@ class GetPaginatedTerminalsRequest extends PaginatedRequest implements IsIterata */ protected $hydratableResource = TerminalCollection::class; - /** - * The resource path. - */ public function resolveResourcePath(): string { return 'terminals'; diff --git a/src/Http/Requests/GetPaymentCaptureRequest.php b/src/Http/Requests/GetPaymentCaptureRequest.php index e29ac88d..fea25a1b 100644 --- a/src/Http/Requests/GetPaymentCaptureRequest.php +++ b/src/Http/Requests/GetPaymentCaptureRequest.php @@ -3,9 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaymentCaptureQuery; use Mollie\Api\Resources\Capture; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; +use Mollie\Api\Utils\Arr; class GetPaymentCaptureRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { @@ -23,18 +24,20 @@ class GetPaymentCaptureRequest extends ResourceHydratableRequest implements Supp private string $captureId; - private ?GetPaymentCaptureQuery $query; + private bool $includePayment; - public function __construct(string $paymentId, string $captureId, ?GetPaymentCaptureQuery $query = null) + public function __construct(string $paymentId, string $captureId, bool $includePayment = false) { $this->paymentId = $paymentId; $this->captureId = $captureId; - $this->query = $query; + $this->includePayment = $includePayment; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'include' => Arr::join($this->includePayment ? [PaymentIncludesQuery::PAYMENT] : []), + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentChargebackRequest.php b/src/Http/Requests/GetPaymentChargebackRequest.php index a1ac1690..c09b0b45 100644 --- a/src/Http/Requests/GetPaymentChargebackRequest.php +++ b/src/Http/Requests/GetPaymentChargebackRequest.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaymentChargebackQuery; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentChargebackRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { @@ -23,18 +23,20 @@ class GetPaymentChargebackRequest extends ResourceHydratableRequest implements S private string $chargebackId; - private ?GetPaymentChargebackQuery $query; + private bool $includePayment; - public function __construct(string $paymentId, string $chargebackId, ?GetPaymentChargebackQuery $query = null) + public function __construct(string $paymentId, string $chargebackId, bool $includePayment = false) { $this->paymentId = $paymentId; $this->chargebackId = $chargebackId; - $this->query = $query; + $this->includePayment = $includePayment; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentMethodRequest.php b/src/Http/Requests/GetPaymentMethodRequest.php index 882a2c4f..0673ec37 100644 --- a/src/Http/Requests/GetPaymentMethodRequest.php +++ b/src/Http/Requests/GetPaymentMethodRequest.php @@ -3,9 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaymentMethodQuery; use Mollie\Api\Resources\Method; use Mollie\Api\Types\Method as HttpMethod; +use Mollie\Api\Types\MethodQuery; +use Mollie\Api\Utils\Arr; class GetPaymentMethodRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { @@ -13,19 +14,45 @@ class GetPaymentMethodRequest extends ResourceHydratableRequest implements Suppo protected $hydratableResource = Method::class; - private ?GetPaymentMethodQuery $query = null; - private string $methodId; - public function __construct(string $methodId, ?GetPaymentMethodQuery $query = null) - { + private ?string $locale; + + private ?string $currency; + + private ?string $profileId; + + private ?bool $includeIssuers; + + private ?bool $includePricing; + + public function __construct( + string $methodId, + ?string $locale = null, + ?string $currency = null, + ?string $profileId = null, + ?bool $includeIssuers = null, + ?bool $includePricing = null + ) { $this->methodId = $methodId; - $this->query = $query; + $this->locale = $locale; + $this->currency = $currency; + $this->profileId = $profileId; + $this->includeIssuers = $includeIssuers; + $this->includePricing = $includePricing; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'locale' => $this->locale, + 'currency' => $this->currency, + 'profileId' => $this->profileId, + 'include' => Arr::join([ + $this->includeIssuers ? MethodQuery::INCLUDE_ISSUERS : null, + $this->includePricing ? MethodQuery::INCLUDE_PRICING : null, + ]), + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/GetPaymentRefundRequest.php b/src/Http/Requests/GetPaymentRefundRequest.php index ebdfed5d..dafbbaa5 100644 --- a/src/Http/Requests/GetPaymentRefundRequest.php +++ b/src/Http/Requests/GetPaymentRefundRequest.php @@ -3,9 +3,9 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaymentRefundQuery; use Mollie\Api\Resources\Refund; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentIncludesQuery; class GetPaymentRefundRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { @@ -23,18 +23,20 @@ class GetPaymentRefundRequest extends ResourceHydratableRequest implements Suppo private string $refundId; - private ?GetPaymentRefundQuery $query = null; + private bool $includePayment; - public function __construct(string $paymentId, string $refundId, ?GetPaymentRefundQuery $query = null) + public function __construct(string $paymentId, string $refundId, bool $includePayment = false) { $this->paymentId = $paymentId; $this->refundId = $refundId; - $this->query = $query; + $this->includePayment = $includePayment; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + 'include' => $this->includePayment ? PaymentIncludesQuery::PAYMENT : null, + ]; } /** diff --git a/src/Http/Requests/GetPaymentRequest.php b/src/Http/Requests/GetPaymentRequest.php index 683e9dfa..7f4d560a 100644 --- a/src/Http/Requests/GetPaymentRequest.php +++ b/src/Http/Requests/GetPaymentRequest.php @@ -3,9 +3,10 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\GetPaymentQuery; use Mollie\Api\Resources\Payment; use Mollie\Api\Types\Method; +use Mollie\Api\Types\PaymentQuery; +use Mollie\Api\Utils\Arr; class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTestmodeInQuery { @@ -21,19 +22,48 @@ class GetPaymentRequest extends ResourceHydratableRequest implements SupportsTes private string $id; - private ?GetPaymentQuery $query = null; + /** + * Query parameters. + */ + private bool $embedCaptures = false; + + private bool $embedRefunds = false; + + private bool $embedChargebacks = false; + + private bool $includeQrCode = false; + + private bool $includeRemainderDetails = false; public function __construct( string $id, - ?GetPaymentQuery $query = null + bool $embedCaptures = false, + bool $embedRefunds = false, + bool $embedChargebacks = false, + bool $includeQrCode = false, + bool $includeRemainderDetails = false ) { $this->id = $id; - $this->query = $query; + $this->embedCaptures = $embedCaptures; + $this->embedRefunds = $embedRefunds; + $this->embedChargebacks = $embedChargebacks; + $this->includeQrCode = $includeQrCode; + $this->includeRemainderDetails = $includeRemainderDetails; } protected function defaultQuery(): array { - return $this->query ? $this->query->toArray() : []; + return [ + '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/Requests/GetSessionRequest.php b/src/Http/Requests/GetSessionRequest.php index 4bf471fb..0bf78378 100644 --- a/src/Http/Requests/GetSessionRequest.php +++ b/src/Http/Requests/GetSessionRequest.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Types\Method; @@ -14,17 +13,9 @@ class GetSessionRequest extends ResourceHydratableRequest private string $sessionId; - private AnyData $query; - - public function __construct(string $sessionId, AnyData $query) + public function __construct(string $sessionId) { $this->sessionId = $sessionId; - $this->query = $query; - } - - protected function defaultQuery(): array - { - return $this->query->toArray(); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/PaginatedRequest.php b/src/Http/Requests/PaginatedRequest.php index 223aa0d6..5c6ac2ec 100644 --- a/src/Http/Requests/PaginatedRequest.php +++ b/src/Http/Requests/PaginatedRequest.php @@ -2,7 +2,6 @@ namespace Mollie\Api\Http\Requests; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Types\Method; abstract class PaginatedRequest extends ResourceHydratableRequest @@ -12,18 +11,23 @@ abstract class PaginatedRequest extends ResourceHydratableRequest */ protected static string $method = Method::GET; - private ?Arrayable $query = null; + private ?string $from; + + private ?int $limit; public function __construct( - ?Arrayable $query = null + ?string $from = null, + ?int $limit = null ) { - $this->query = $query; + $this->from = $from; + $this->limit = $limit; } protected function defaultQuery(): array { - return $this->query - ? $this->query->toArray() - : []; + return [ + 'from' => $this->from, + 'limit' => $this->limit, + ]; } } diff --git a/src/Http/Requests/SortablePaginatedRequest.php b/src/Http/Requests/SortablePaginatedRequest.php new file mode 100644 index 00000000..661db105 --- /dev/null +++ b/src/Http/Requests/SortablePaginatedRequest.php @@ -0,0 +1,16 @@ +query()->add('sort', $sort); + } +} diff --git a/src/Http/Requests/UpdateCustomerRequest.php b/src/Http/Requests/UpdateCustomerRequest.php index 3059034b..0165862e 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\Data\UpdateCustomerPayload; +use Mollie\Api\Http\Data\Metadata; use Mollie\Api\Resources\Customer; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -21,17 +21,36 @@ class UpdateCustomerRequest extends ResourceHydratableRequest implements HasPayl private string $id; - private UpdateCustomerPayload $payload; + private ?string $name; - public function __construct(string $id, UpdateCustomerPayload $payload) - { + private ?string $email; + + private ?string $locale; + + private ?Metadata $metadata; + + public function __construct( + string $id, + ?string $name = null, + ?string $email = null, + ?string $locale = null, + ?Metadata $metadata = null + ) { $this->id = $id; - $this->payload = $payload; + $this->name = $name; + $this->email = $email; + $this->locale = $locale; + $this->metadata = $metadata; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'name' => $this->name, + 'email' => $this->email, + 'locale' => $this->locale, + 'metadata' => $this->metadata, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdatePaymentLinkRequest.php b/src/Http/Requests/UpdatePaymentLinkRequest.php index ee312fba..5dc743c5 100644 --- a/src/Http/Requests/UpdatePaymentLinkRequest.php +++ b/src/Http/Requests/UpdatePaymentLinkRequest.php @@ -4,7 +4,6 @@ use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\UpdatePaymentLinkPayload; use Mollie\Api\Resources\PaymentLink; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -22,17 +21,27 @@ class UpdatePaymentLinkRequest extends ResourceHydratableRequest implements HasP private string $id; - private UpdatePaymentLinkPayload $payload; + private string $description; - public function __construct(string $id, UpdatePaymentLinkPayload $payload) + private bool $archived; + + private ?array $allowedMethods; + + public function __construct(string $id, string $description, bool $archived = false, ?array $allowedMethods = null) { $this->id = $id; - $this->payload = $payload; + $this->description = $description; + $this->archived = $archived; + $this->allowedMethods = $allowedMethods; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'description' => $this->description, + 'archived' => $this->archived, + 'allowedMethods' => $this->allowedMethods, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdatePaymentRequest.php b/src/Http/Requests/UpdatePaymentRequest.php index 83b7e609..93936758 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\Data\UpdatePaymentPayload; +use Mollie\Api\Http\Data\Metadata; use Mollie\Api\Resources\Payment; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -22,17 +22,65 @@ class UpdatePaymentRequest extends ResourceHydratableRequest implements HasPaylo private string $id; - private UpdatePaymentPayload $payload; + private ?string $description; - public function __construct(string $id, UpdatePaymentPayload $payload) - { + private ?string $redirectUrl; + + private ?string $cancelUrl; + + private ?string $webhookUrl; + + private ?Metadata $metadata; + + private ?string $paymentMethod; + + private ?string $locale; + + private ?string $restrictPaymentMethodsToCountry; + + /** + * Method specific data. + * + * s. https://docs.mollie.com/reference/extra-payment-parameters#bank-transfer + */ + private array $additional = []; + + public function __construct( + string $id, + ?string $description = null, + ?string $redirectUrl = null, + ?string $cancelUrl = null, + ?string $webhookUrl = null, + ?Metadata $metadata = null, + ?string $paymentMethod = null, + ?string $locale = null, + ?string $restrictPaymentMethodsToCountry = null, + array $additional = [] + ) { $this->id = $id; - $this->payload = $payload; + $this->description = $description; + $this->redirectUrl = $redirectUrl; + $this->cancelUrl = $cancelUrl; + $this->webhookUrl = $webhookUrl; + $this->metadata = $metadata; + $this->paymentMethod = $paymentMethod; + $this->locale = $locale; + $this->restrictPaymentMethodsToCountry = $restrictPaymentMethodsToCountry; + $this->additional = $additional; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return array_merge([ + 'description' => $this->description, + 'redirectUrl' => $this->redirectUrl, + 'cancelUrl' => $this->cancelUrl, + 'webhookUrl' => $this->webhookUrl, + 'metadata' => $this->metadata, + 'paymentMethod' => $this->paymentMethod, + 'locale' => $this->locale, + 'restrictPaymentMethodsToCountry' => $this->restrictPaymentMethodsToCountry, + ], $this->additional); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdatePaymentRouteRequest.php b/src/Http/Requests/UpdatePaymentRouteRequest.php index 9c282eee..0ce7d77e 100644 --- a/src/Http/Requests/UpdatePaymentRouteRequest.php +++ b/src/Http/Requests/UpdatePaymentRouteRequest.php @@ -2,9 +2,9 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInPayload; -use Mollie\Api\Http\Data\UpdatePaymentRoutePayload; use Mollie\Api\Resources\Route; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -27,18 +27,20 @@ class UpdatePaymentRouteRequest extends ResourceHydratableRequest implements Has private string $routeId; - private UpdatePaymentRoutePayload $payload; + private DateTimeInterface $releaseDate; - public function __construct(string $paymentId, string $routeId, UpdatePaymentRoutePayload $payload) + public function __construct(string $paymentId, string $routeId, DateTimeInterface $releaseDate) { $this->paymentId = $paymentId; $this->routeId = $routeId; - $this->payload = $payload; + $this->releaseDate = $releaseDate; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'releaseDate' => $this->releaseDate, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdateProfileRequest.php b/src/Http/Requests/UpdateProfileRequest.php index 63340b4a..16ff8133 100644 --- a/src/Http/Requests/UpdateProfileRequest.php +++ b/src/Http/Requests/UpdateProfileRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\UpdateProfilePayload; use Mollie\Api\Resources\Profile; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -21,17 +20,56 @@ class UpdateProfileRequest extends ResourceHydratableRequest implements HasPaylo private string $id; - private UpdateProfilePayload $payload; + private ?string $name; - public function __construct(string $id, UpdateProfilePayload $payload) - { + private ?string $website; + + private ?string $email; + + private ?string $phone; + + private ?string $description; + + private ?array $countriesOfActivity; + + private ?string $businessCategory; + + private ?string $mode; + + public function __construct( + string $id, + ?string $name = null, + ?string $website = null, + ?string $email = null, + ?string $phone = null, + ?string $description = null, + ?array $countriesOfActivity = null, + ?string $businessCategory = null, + ?string $mode = null + ) { $this->id = $id; - $this->payload = $payload; + $this->name = $name; + $this->website = $website; + $this->email = $email; + $this->phone = $phone; + $this->description = $description; + $this->countriesOfActivity = $countriesOfActivity; + $this->businessCategory = $businessCategory; + $this->mode = $mode; } protected function defaultPayload(): array { - return $this->payload->toArray(); + 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, + ]; } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdateSalesInvoiceRequest.php b/src/Http/Requests/UpdateSalesInvoiceRequest.php index f03d8d1d..087b3b39 100644 --- a/src/Http/Requests/UpdateSalesInvoiceRequest.php +++ b/src/Http/Requests/UpdateSalesInvoiceRequest.php @@ -3,7 +3,12 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\UpdateSalesInvoicePayload; +use Mollie\Api\Http\Data\DataCollection; +use Mollie\Api\Http\Data\Discount; +use Mollie\Api\Http\Data\EmailDetails; +use Mollie\Api\Http\Data\InvoiceLine; +use Mollie\Api\Http\Data\PaymentDetails; +use Mollie\Api\Http\Data\Recipient; use Mollie\Api\Resources\SalesInvoice; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -18,21 +23,73 @@ class UpdateSalesInvoiceRequest extends ResourceHydratableRequest implements Has private string $id; - private UpdateSalesInvoicePayload $payload; + private string $status; - public function __construct(string $id, UpdateSalesInvoicePayload $payload) - { + private string $recipientIdentifier; + + private ?string $memo; + + private ?string $paymentTerm; + + private ?PaymentDetails $paymentDetails; + + private ?EmailDetails $emailDetails; + + private ?Recipient $recipient; + + /** + * @var DataCollection + */ + private ?DataCollection $lines; + + private ?string $webhookUrl; + + private ?Discount $discount; + + public function __construct( + string $id, + string $status, + string $recipientIdentifier, + ?string $memo = null, + ?string $paymentTerm = null, + ?PaymentDetails $paymentDetails = null, + ?EmailDetails $emailDetails = null, + ?Recipient $recipient = null, + ?DataCollection $lines = null, + ?string $webhookUrl = null, + ?Discount $discount = null + ) { $this->id = $id; - $this->payload = $payload; + $this->status = $status; + $this->recipientIdentifier = $recipientIdentifier; + $this->memo = $memo; + $this->paymentTerm = $paymentTerm; + $this->paymentDetails = $paymentDetails; + $this->emailDetails = $emailDetails; + $this->recipient = $recipient; + $this->lines = $lines; + $this->webhookUrl = $webhookUrl; + $this->discount = $discount; } - public function resolveResourcePath(): string + public function defaultPayload(): array { - return "sales-invoices/{$this->id}"; + return [ + 'status' => $this->status, + 'recipientIdentifier' => $this->recipientIdentifier, + 'memo' => $this->memo, + 'paymentTerm' => $this->paymentTerm, + 'paymentDetails' => $this->paymentDetails, + 'emailDetails' => $this->emailDetails, + 'recipient' => $this->recipient, + 'lines' => $this->lines, + 'webhookUrl' => $this->webhookUrl, + 'discount' => $this->discount, + ]; } - public function defaultPayload(): array + public function resolveResourcePath(): string { - return $this->payload->toArray(); + return "sales-invoices/{$this->id}"; } } diff --git a/src/Http/Requests/UpdateSessionRequest.php b/src/Http/Requests/UpdateSessionRequest.php index 33ff0c07..124a3ea7 100644 --- a/src/Http/Requests/UpdateSessionRequest.php +++ b/src/Http/Requests/UpdateSessionRequest.php @@ -3,7 +3,6 @@ namespace Mollie\Api\Http\Requests; use Mollie\Api\Contracts\HasPayload; -use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Resources\Session; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -18,17 +17,9 @@ class UpdateSessionRequest extends ResourceHydratableRequest implements HasPaylo private string $sessionId; - private AnyData $payload; - - public function __construct(string $sessionId, AnyData $payload) + public function __construct(string $sessionId) { $this->sessionId = $sessionId; - $this->payload = $payload; - } - - protected function defaultPayload(): array - { - return $this->payload->toArray(); } public function resolveResourcePath(): string diff --git a/src/Http/Requests/UpdateSubscriptionRequest.php b/src/Http/Requests/UpdateSubscriptionRequest.php index 4c63bafa..a54b5b7d 100644 --- a/src/Http/Requests/UpdateSubscriptionRequest.php +++ b/src/Http/Requests/UpdateSubscriptionRequest.php @@ -2,9 +2,11 @@ namespace Mollie\Api\Http\Requests; +use DateTimeInterface; use Mollie\Api\Contracts\HasPayload; use Mollie\Api\Contracts\SupportsTestmodeInQuery; -use Mollie\Api\Http\Data\UpdateSubscriptionPayload; +use Mollie\Api\Http\Data\Metadata; +use Mollie\Api\Http\Data\Money; use Mollie\Api\Resources\Subscription; use Mollie\Api\Traits\HasJsonPayload; use Mollie\Api\Types\Method; @@ -27,21 +29,58 @@ class UpdateSubscriptionRequest extends ResourceHydratableRequest implements Has private string $subscriptionId; - private UpdateSubscriptionPayload $payload; + private ?Money $amount; + + private ?string $description; + + private ?string $interval; + + private ?DateTimeInterface $startDate; + + private ?int $times; + + private ?Metadata $metadata; + + private ?string $webhookUrl; + + private ?string $mandateId; public function __construct( string $customerId, string $subscriptionId, - UpdateSubscriptionPayload $payload + ?Money $amount = null, + ?string $description = null, + ?string $interval = null, + ?DateTimeInterface $startDate = null, + ?int $times = null, + ?Metadata $metadata = null, + ?string $webhookUrl = null, + ?string $mandateId = null ) { $this->customerId = $customerId; $this->subscriptionId = $subscriptionId; - $this->payload = $payload; + $this->amount = $amount; + $this->description = $description; + $this->interval = $interval; + $this->startDate = $startDate; + $this->times = $times; + $this->metadata = $metadata; + $this->webhookUrl = $webhookUrl; + $this->mandateId = $mandateId; } protected function defaultPayload(): array { - return $this->payload->toArray(); + return [ + 'amount' => $this->amount, + 'description' => $this->description, + 'interval' => $this->interval, + 'startDate' => $this->startDate, + 'times' => $this->times, + 'metadata' => $this->metadata, + 'webhookUrl' => $this->webhookUrl, + 'mandateId' => $this->mandateId, + ]; } /** diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 7963264b..92eab836 100644 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -5,7 +5,6 @@ use Mollie\Api\Contracts\EmbeddedResourcesContract; use Mollie\Api\Exceptions\ApiException; 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; @@ -708,14 +707,15 @@ public function refund($data): Refund /** * @throws \Mollie\Api\Exceptions\ApiException */ - public function update(): ?Payment + public function update(): Payment { $additional = []; if ($this->method === PaymentMethod::BANKTRANSFER) { $additional['dueDate'] = $this->dueDate; } - $payload = new UpdatePaymentPayload( + $updateRequest = (new UpdatePaymentRequest( + $this->id, $this->description, $this->redirectUrl, $this->cancelUrl, @@ -725,11 +725,12 @@ public function update(): ?Payment $this->locale, $this->restrictPaymentMethodsToCountry, $additional - ); + ))->test($this->isInTestmode()); + /** @var null|Payment */ return $this ->connector - ->send((new UpdatePaymentRequest($this->id, $payload))->test($this->isInTestmode())); + ->send($updateRequest); } /** diff --git a/src/Traits/ComposableFromArray.php b/src/Traits/ComposableFromArray.php index 6ddad919..efab0ee1 100644 --- a/src/Traits/ComposableFromArray.php +++ b/src/Traits/ComposableFromArray.php @@ -2,10 +2,16 @@ namespace Mollie\Api\Traits; +use Mollie\Api\Http\Data\DataCollection; + trait ComposableFromArray { - public static function fromArray(array $data = []): self + public static function fromArray($data = []): self { + $data = DataCollection::wrap($data) + ->values() + ->toArray(); + /** @phpstan-ignore-next-line */ return new static(...$data); } diff --git a/src/Traits/HandlesDebugging.php b/src/Traits/HandlesDebugging.php index 08d39365..16d9d729 100644 --- a/src/Traits/HandlesDebugging.php +++ b/src/Traits/HandlesDebugging.php @@ -15,16 +15,13 @@ */ trait HandlesDebugging { - /** - * @var bool - */ private bool $hasSanitizerMiddleware = false; /** * Enable request debugging with an optional custom debugger. * - * @param callable|null $debugger Custom request debugger function - * @param bool $die Whether to die after dumping + * @param callable|null $debugger Custom request debugger function + * @param bool $die Whether to die after dumping * @return $this */ public function debugRequest(?callable $debugger = null, bool $die = false): self @@ -49,8 +46,8 @@ public function debugRequest(?callable $debugger = null, bool $die = false): sel /** * Enable response debugging with an optional custom debugger. * - * @param callable|null $debugger Custom response debugger function - * @param bool $die Whether to die after dumping + * @param callable|null $debugger Custom response debugger function + * @param bool $die Whether to die after dumping * @return $this */ public function debugResponse(?callable $debugger = null, bool $die = false): self @@ -84,7 +81,7 @@ protected function removeSensitiveData(): self } $this->hasSanitizerMiddleware = true; - $sanitizer = new RequestSanitizer(); + $sanitizer = new RequestSanitizer; $this->middleware()->onFatal(function (MollieException $exception) use ($sanitizer) { if ($exception instanceof RequestException) { @@ -100,7 +97,7 @@ protected function removeSensitiveData(): self /** * Enable both request and response debugging. * - * @param bool $die Whether to die after dumping + * @param bool $die Whether to die after dumping * @return $this */ public function debug(bool $die = false): self diff --git a/src/Utils/Arr.php b/src/Utils/Arr.php index d6d776d8..85a7e6c9 100644 --- a/src/Utils/Arr.php +++ b/src/Utils/Arr.php @@ -47,6 +47,18 @@ public static function pull(array &$array, string $key, $default = null) return $value; } + /** + * Remove the given keys from the array. + */ + public static function except(array $array, $keys): array + { + foreach ((array) $keys as $key) { + static::forget($array, $key); + } + + return $array; + } + /** * Remove an item from an array using "dot" notation. */ diff --git a/src/Utils/Utility.php b/src/Utils/Utility.php index 9176b5cb..75bb6c44 100644 --- a/src/Utils/Utility.php +++ b/src/Utils/Utility.php @@ -83,22 +83,33 @@ public static function filterByProperties($class, array $array): array * Compose a value to a new form if it is truthy. * * @param mixed $value - * @param string|callable $composable + * @param string|callable $resolver + * @param string|null $composableClass * @param mixed $default * @return mixed */ - public static function compose($value, $composable, $default = null) + public static function compose($value, $resolver, $composableClass = null, $default = null) { - // If the value is an instance of the composable class, return it. - if (is_string($composable) && $value instanceof $composable) { - return $value; + /** + * If the third argument is a string and the class does not exist, + * it is assumed that the third argument is the default value. + */ + if (func_num_args() === 3 && is_string($composableClass) && ! class_exists($composableClass)) { + $default = $composableClass; + $composableClass = null; + } + + if (is_string($resolver)) { + $composableClass = $resolver; + $resolver = fn ($value) => new $resolver($value); } - $composable = is_string($composable) - ? fn ($value) => new $composable($value) - : $composable; + // If the value is an instance of the target class, return it. + if (is_object($value) && $composableClass && $value instanceof $composableClass) { + return $value; + } - return (bool) $value ? $composable($value) : $default; + return (bool) $value ? $resolver($value) : $default; } /** diff --git a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php index 5ee8aec3..680434fd 100644 --- a/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/ClientLinkEndpointCollectionTest.php @@ -4,7 +4,6 @@ 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; @@ -21,11 +20,11 @@ public function create() ]); /** @var ClientLink $clientLink */ - $clientLink = $client->clientLinks->create(new CreateClientLinkPayload( - new Owner('test@example.com', 'John', 'Doe'), - 'Test Client Link', - new OwnerAddress('NL'), - )); + $clientLink = $client->clientLinks->create([ + 'owner' => new Owner('test@example.com', 'John', 'Doe'), + 'name' => 'Test Client Link', + 'address' => new OwnerAddress('NL'), + ]); $this->assertInstanceOf(ClientLink::class, $clientLink); $this->assertEquals('client-link', $clientLink->resource); diff --git a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php index 36cfb9c3..d46cfa7f 100644 --- a/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php +++ b/tests/EndpointCollection/CustomerPaymentsEndpointCollectionTest.php @@ -4,7 +4,6 @@ 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; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -27,11 +26,11 @@ public function create_for() $customer->id = 'cst_kEn1PlbGa'; /** @var Payment $payment */ - $payment = $client->customerPayments->createFor($customer, new CreatePaymentPayload( - 'Test payment', - new Money('10.00', 'EUR'), - 'https://example.org/redirect', - )); + $payment = $client->customerPayments->createFor($customer, [ + 'description' => 'Test payment', + 'amount' => new Money('10.00', 'EUR'), + 'redirectUrl' => 'https://example.org/redirect', + ]); $this->assertPayment($payment); } diff --git a/tests/EndpointCollection/MandateEndpointCollectionTest.php b/tests/EndpointCollection/MandateEndpointCollectionTest.php index 8fd43858..e5649a8a 100644 --- a/tests/EndpointCollection/MandateEndpointCollectionTest.php +++ b/tests/EndpointCollection/MandateEndpointCollectionTest.php @@ -5,7 +5,6 @@ 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; use Mollie\Api\Http\Requests\GetPaginatedMandateRequest; @@ -28,15 +27,15 @@ public function create_for() $customer->id = 'cst_4qqhO89gsT'; /** @var Mandate $mandate */ - $mandate = $client->mandates->createForCustomer($customer, new CreateMandatePayload( - 'directdebit', - 'John Doe', - 'NL55INGB0000000000', - 'INGBNL2A', - 'john.doe@example.com', - new DateTimeImmutable('2023-05-07'), - 'EXAMPLE-CORP-MD13804', - )); + $mandate = $client->mandates->createForCustomer($customer, [ + 'method' => 'directdebit', + 'consumerName' => 'John Doe', + 'iban' => 'NL55INGB0000000000', + 'bic' => 'INGBNL2A', + 'email' => 'john.doe@example.com', + 'signatureDate' => new DateTimeImmutable('2023-05-07'), + 'mandateReference' => 'EXAMPLE-CORP-MD13804', + ]); $this->assertMandate($mandate); } diff --git a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php index f3386a33..33f873d6 100644 --- a/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentCaptureEndpointCollectionTest.php @@ -4,7 +4,6 @@ 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\Http\Requests\DynamicGetRequest; @@ -24,10 +23,10 @@ public function create_for_id() ]); /** @var Capture $capture */ - $capture = $client->paymentCaptures->createForId('tr_7UhSN1zuXS', new CreatePaymentCapturePayload( - 'Capture for cart #12345', - new Money('EUR', '35.95') - )); + $capture = $client->paymentCaptures->createForId('tr_7UhSN1zuXS', [ + 'description' => 'Capture for cart #12345', + 'amount' => new Money('EUR', '35.95'), + ]); $this->assertCapture($capture); } diff --git a/tests/EndpointCollection/PaymentEndpointCollectionTest.php b/tests/EndpointCollection/PaymentEndpointCollectionTest.php index c6b9e0c5..3e6c52c5 100644 --- a/tests/EndpointCollection/PaymentEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentEndpointCollectionTest.php @@ -4,10 +4,7 @@ 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; -use Mollie\Api\Http\Data\UpdatePaymentPayload; use Mollie\Api\Http\Requests\CancelPaymentRequest; use Mollie\Api\Http\Requests\CreatePaymentRefundRequest; use Mollie\Api\Http\Requests\CreatePaymentRequest; @@ -30,12 +27,12 @@ public function create() ]); /** @var Payment $payment */ - $payment = $client->payments->create(new CreatePaymentPayload( - 'Test payment', - new Money('10.00', 'EUR'), - 'https://example.org/redirect', - 'https://example.org/webhook', - )); + $payment = $client->payments->create([ + 'description' => 'Test payment', + 'amount' => new Money('10.00', 'EUR'), + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + ]); $this->assertPayment($payment); } @@ -61,10 +58,10 @@ public function update() ]); /** @var Payment $payment */ - $payment = $client->payments->update('tr_WDqYK6vllg', new UpdatePaymentPayload( - 'Updated description', - 'https://example.org/updated-redirect', - )); + $payment = $client->payments->update('tr_WDqYK6vllg', [ + 'description' => 'Updated description', + 'redirectUrl' => 'https://example.org/updated-redirect', + ]); $this->assertPayment($payment); } @@ -92,10 +89,10 @@ public function refund() $payment->id = 'tr_WDqYK6vllg'; /** @var Refund $refund */ - $refund = $client->payments->refund($payment, new CreateRefundPaymentPayload( - 'Test refund', - new Money('5.95', 'EUR'), - )); + $refund = $client->payments->refund($payment, [ + 'description' => 'Test refund', + 'amount' => new Money('5.95', 'EUR'), + ]); $this->assertInstanceOf(Refund::class, $refund); $this->assertEquals('refund', $refund->resource); diff --git a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php index 0ea51dc7..e70d0947 100644 --- a/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php +++ b/tests/EndpointCollection/PaymentLinkEndpointCollectionTest.php @@ -2,12 +2,9 @@ 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; use Mollie\Api\Http\Requests\CreatePaymentLinkRequest; use Mollie\Api\Http\Requests\DeletePaymentLinkRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; @@ -28,15 +25,12 @@ public function create() ]); /** @var PaymentLink $paymentLink */ - $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'), - )); + $paymentLink = $client->paymentLinks->create([ + 'description' => 'Test payment link', + 'amount' => new Money('10.00', 'EUR'), + 'redirectUrl' => 'https://example.org/redirect', + 'webhookUrl' => 'https://example.org/webhook', + ]); $this->assertPaymentLink($paymentLink); } @@ -62,9 +56,9 @@ public function update() ]); /** @var PaymentLink $paymentLink */ - $paymentLink = $client->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', new UpdatePaymentLinkPayload( - 'Updated description', - )); + $paymentLink = $client->paymentLinks->update('pl_4Y0eZitmBnQ6IDoMqZQKh', [ + 'description' => 'Updated description', + ]); $this->assertPaymentLink($paymentLink); } diff --git a/tests/EndpointCollection/ProfileEndpointCollectionTest.php b/tests/EndpointCollection/ProfileEndpointCollectionTest.php index 64b0c930..c2ca1099 100644 --- a/tests/EndpointCollection/ProfileEndpointCollectionTest.php +++ b/tests/EndpointCollection/ProfileEndpointCollectionTest.php @@ -4,11 +4,10 @@ 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; use Mollie\Api\Http\Requests\DeleteProfileRequest; use Mollie\Api\Http\Requests\DynamicGetRequest; +use Mollie\Api\Http\Requests\GetCurrentProfileRequest; use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest; use Mollie\Api\Http\Requests\GetProfileRequest; use Mollie\Api\Http\Requests\UpdateProfileRequest; @@ -26,13 +25,13 @@ public function create() ]); /** @var Profile $profile */ - $profile = $client->profiles->create(new CreateProfilePayload( - 'My Test Profile', - 'https://example.org', - 'info@example.org', - '+31612345678', - 'test', - )); + $profile = $client->profiles->create([ + 'name' => 'My Test Profile', + 'website' => 'https://example.org', + 'email' => 'info@example.org', + 'phone' => '+31612345678', + 'businessCategory' => 'test', + ]); $this->assertProfile($profile); } @@ -54,7 +53,7 @@ public function get() public function get_current() { $client = new MockMollieClient([ - GetProfileRequest::class => MockResponse::ok('current-profile'), + GetCurrentProfileRequest::class => MockResponse::ok('current-profile'), ]); /** @var Profile $profile */ @@ -71,10 +70,10 @@ public function update() ]); /** @var Profile $profile */ - $profile = $client->profiles->update('pfl_v9hTwCvYqw', new UpdateProfilePayload( - 'Updated Profile Name', - 'https://updated-example.org', - )); + $profile = $client->profiles->update('pfl_v9hTwCvYqw', [ + 'name' => 'Updated Profile Name', + 'website' => 'https://updated-example.org', + ]); $this->assertProfile($profile); } diff --git a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php index 4ff831d3..a073e986 100644 --- a/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php +++ b/tests/EndpointCollection/SalesInvoiceEndpointCollectionTest.php @@ -4,12 +4,10 @@ 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; 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; @@ -56,14 +54,14 @@ public function create() ]; // Create a sales invoice - $payload = new CreateSalesInvoicePayload( - 'EUR', - SalesInvoiceStatus::DRAFT, - VatScheme::STANDARD, - VatMode::INCLUSIVE, - PaymentTerm::DAYS_30, - 'XXXXX', - new Recipient( + $payload = [ + 'currency' => 'EUR', + 'status' => SalesInvoiceStatus::DRAFT, + 'vatScheme' => VatScheme::STANDARD, + 'vatMode' => VatMode::INCLUSIVE, + 'paymentTerm' => PaymentTerm::DAYS_30, + 'recipientIdentifier' => 'XXXXX', + 'recipient' => new Recipient( RecipientType::CONSUMER, 'darth@vader.deathstar', 'Sample Street 12b', @@ -72,8 +70,8 @@ public function create() 'NL', 'nl_NL' ), - new DataCollection($invoiceLines) - ); + 'lines' => new DataCollection($invoiceLines), + ]; $salesInvoice = $client->salesInvoices->create($payload); @@ -87,10 +85,10 @@ public function update() UpdateSalesInvoiceRequest::class => MockResponse::ok('sales-invoice'), ]); - $payload = new UpdateSalesInvoicePayload( - SalesInvoiceStatus::PAID, - 'XXXXX', - ); + $payload = [ + 'status' => SalesInvoiceStatus::PAID, + 'recipientIdentifier' => 'XXXXX', + ]; $salesInvoice = $client->salesInvoices->update('invoice_123', $payload); $this->assertInstanceOf(SalesInvoice::class, $salesInvoice); diff --git a/tests/EndpointCollection/SessionEndpointCollectionTest.php b/tests/EndpointCollection/SessionEndpointCollectionTest.php index 3d6b149b..adb2b5e3 100644 --- a/tests/EndpointCollection/SessionEndpointCollectionTest.php +++ b/tests/EndpointCollection/SessionEndpointCollectionTest.php @@ -4,7 +4,6 @@ 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; use Mollie\Api\Http\Requests\CreateSessionRequest; @@ -26,7 +25,7 @@ public function get() ]); /** @var Session $session */ - $session = $client->sessions->get('ses_123', new AnyData(['include' => 'details'])); + $session = $client->sessions->get('ses_123', ['include' => 'details']); $this->assertSession($session); } @@ -39,10 +38,10 @@ public function create() ]); /** @var Session $session */ - $session = $client->sessions->create(new AnyData([ + $session = $client->sessions->create([ 'amount' => new Money('EUR', '10.00'), 'description' => 'Test Session', - ])); + ]); $this->assertSession($session); } @@ -55,9 +54,9 @@ public function update() ]); /** @var Session $session */ - $session = $client->sessions->update('ses_123', new AnyData([ + $session = $client->sessions->update('ses_123', [ 'description' => 'Updated Session', - ])); + ]); $this->assertSession($session); } diff --git a/tests/Factories/ApplePayPaymentSessionRequestFactoryTest.php b/tests/Factories/ApplePayPaymentSessionRequestFactoryTest.php new file mode 100644 index 00000000..f81a71f9 --- /dev/null +++ b/tests/Factories/ApplePayPaymentSessionRequestFactoryTest.php @@ -0,0 +1,24 @@ +withPayload([ + 'domain' => 'example.com', + 'validationUrl' => 'https://example.com/validation', + 'profileId' => '1234567890', + ]) + ->create(); + + $this->assertInstanceOf(ApplePayPaymentSessionRequest::class, $factory); + } +} diff --git a/tests/Factories/ApplicationFeeFactoryTest.php b/tests/Factories/ApplicationFeeFactoryTest.php new file mode 100644 index 00000000..4738ba23 --- /dev/null +++ b/tests/Factories/ApplicationFeeFactoryTest.php @@ -0,0 +1,28 @@ + [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'description' => 'Test application fee', + ])->create(); + + $this->assertInstanceOf(ApplicationFee::class, $fee); + + $this->assertEquals('EUR', $fee->amount->currency); + $this->assertEquals('10.00', $fee->amount->value); + $this->assertEquals('Test application fee', $fee->description); + } +} diff --git a/tests/Factories/CreateClientLinkRequestFactoryTest.php b/tests/Factories/CreateClientLinkRequestFactoryTest.php new file mode 100644 index 00000000..33ab1eca --- /dev/null +++ b/tests/Factories/CreateClientLinkRequestFactoryTest.php @@ -0,0 +1,59 @@ +withPayload([ + 'owner' => [ + 'givenName' => 'John', + 'familyName' => 'Doe', + 'email' => 'john@example.com', + 'locale' => 'nl_NL', + ], + 'name' => 'Example Company', + 'address' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + 'registrationNumber' => '12345678', + 'vatNumber' => 'NL123456789B01', + ]) + ->create(); + + $this->assertInstanceOf(CreateClientLinkRequest::class, $request); + } + + /** @test */ + public function create_returns_client_link_request_object_with_minimal_data() + { + $request = CreateClientLinkRequestFactory::new() + ->withPayload([ + 'owner' => [ + 'givenName' => 'John', + 'familyName' => 'Doe', + 'email' => 'john@example.com', + ], + 'name' => 'Example Company', + 'address' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreateClientLinkRequest::class, $request); + } +} diff --git a/tests/Factories/CreateCustomerPaymentRequestFactoryTest.php b/tests/Factories/CreateCustomerPaymentRequestFactoryTest.php new file mode 100644 index 00000000..c93d6897 --- /dev/null +++ b/tests/Factories/CreateCustomerPaymentRequestFactoryTest.php @@ -0,0 +1,135 @@ +withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + 'cancelUrl' => 'https://example.com/cancel', + 'webhookUrl' => 'https://example.com/webhook', + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '50.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + 'billingAddress' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + 'shippingAddress' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + 'locale' => 'nl_NL', + 'method' => 'ideal', + 'issuer' => 'ideal_INGBNL2A', + 'restrictPaymentMethodsToCountry' => 'NL', + 'metadata' => [ + 'order_id' => '12345', + ], + 'captureMode' => 'manual', + 'captureDelay' => 'P3D', + 'applicationFee' => [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '1.00', + ], + 'description' => 'Application fee', + ], + 'routing' => [ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '50.00', + ], + 'destination' => [ + 'type' => 'organization', + 'organizationId' => 'org_12345', + ], + ], + ], + 'sequenceType' => 'first', + 'mandateId' => 'mdt_12345', + 'profileId' => 'pfl_12345', + 'additional' => [ + 'customField' => 'customValue', + ], + ]) + ->withQuery([ + 'includeQrCode' => true, + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerPaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_customer_payment_request_object_with_minimal_data() + { + $request = CreateCustomerPaymentRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerPaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_customer_payment_request_object_with_partial_data() + { + $request = CreateCustomerPaymentRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + 'webhookUrl' => 'https://example.com/webhook', + 'metadata' => [ + 'order_id' => '12345', + ], + 'method' => 'ideal', + 'sequenceType' => 'first', + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerPaymentRequest::class, $request); + } +} diff --git a/tests/Factories/CreateCustomerRequestFactoryTest.php b/tests/Factories/CreateCustomerRequestFactoryTest.php new file mode 100644 index 00000000..1895a777 --- /dev/null +++ b/tests/Factories/CreateCustomerRequestFactoryTest.php @@ -0,0 +1,55 @@ +withPayload([ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'locale' => 'nl_NL', + 'metadata' => [ + 'order_id' => '12345', + 'customer_type' => 'premium', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerRequest::class, $request); + } + + /** @test */ + public function create_returns_customer_request_object_with_minimal_data() + { + $request = CreateCustomerRequestFactory::new() + ->withPayload([ + 'name' => 'John Doe', + 'email' => 'john@example.com', + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerRequest::class, $request); + } + + /** @test */ + public function create_returns_customer_request_object_with_partial_data() + { + $request = CreateCustomerRequestFactory::new() + ->withPayload([ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'locale' => 'nl_NL', + ]) + ->create(); + + $this->assertInstanceOf(CreateCustomerRequest::class, $request); + } +} diff --git a/tests/Factories/CreateMandateRequestFactoryTest.php b/tests/Factories/CreateMandateRequestFactoryTest.php new file mode 100644 index 00000000..b555099f --- /dev/null +++ b/tests/Factories/CreateMandateRequestFactoryTest.php @@ -0,0 +1,95 @@ +withPayload([ + 'method' => 'directdebit', + 'consumerName' => 'John Doe', + 'consumerAccount' => 'NL55INGB0000000000', + 'consumerBic' => 'INGBNL2A', + 'consumerEmail' => 'john@example.com', + 'signatureDate' => '2024-01-01', + 'mandateReference' => 'MANDATE-12345', + 'paypalBillingAgreementId' => null, + ]) + ->create(); + + $this->assertInstanceOf(CreateMandateRequest::class, $request); + } + + /** @test */ + public function create_returns_mandate_request_object_with_minimal_data() + { + $request = CreateMandateRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'method' => 'directdebit', + 'consumerName' => 'John Doe', + ]) + ->create(); + + $this->assertInstanceOf(CreateMandateRequest::class, $request); + } + + /** @test */ + public function create_returns_mandate_request_object_with_partial_data() + { + $request = CreateMandateRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'method' => 'directdebit', + 'consumerName' => 'John Doe', + 'consumerAccount' => 'NL55INGB0000000000', + 'consumerBic' => 'INGBNL2A', + ]) + ->create(); + + $this->assertInstanceOf(CreateMandateRequest::class, $request); + } + + /** @test */ + public function create_throws_exception_when_required_fields_are_missing() + { + $this->expectException(\Mollie\Api\Exceptions\LogicException::class); + $this->expectExceptionMessage('Method and consumerName are required for creating a mandate'); + + CreateMandateRequestFactory::new(self::CUSTOMER_ID) + ->create(); + } + + /** @test */ + public function create_throws_exception_when_method_is_missing() + { + $this->expectException(\Mollie\Api\Exceptions\LogicException::class); + $this->expectExceptionMessage('Method and consumerName are required for creating a mandate'); + + CreateMandateRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'consumerName' => 'John Doe', + ]) + ->create(); + } + + /** @test */ + public function create_throws_exception_when_consumer_name_is_missing() + { + $this->expectException(\Mollie\Api\Exceptions\LogicException::class); + $this->expectExceptionMessage('Method and consumerName are required for creating a mandate'); + + CreateMandateRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'method' => 'directdebit', + ]) + ->create(); + } +} diff --git a/tests/Factories/CreatePaymentCaptureRequestFactoryTest.php b/tests/Factories/CreatePaymentCaptureRequestFactoryTest.php new file mode 100644 index 00000000..7777bc10 --- /dev/null +++ b/tests/Factories/CreatePaymentCaptureRequestFactoryTest.php @@ -0,0 +1,64 @@ +withPayload([ + 'description' => 'Capture for order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'metadata' => [ + 'order_id' => '12345', + 'description' => 'Manual capture for order', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentCaptureRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_capture_request_object_with_minimal_data() + { + $request = CreatePaymentCaptureRequestFactory::new(self::PAYMENT_ID) + ->withPayload([ + 'description' => 'Capture for order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentCaptureRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_capture_request_object_with_partial_data() + { + $request = CreatePaymentCaptureRequestFactory::new(self::PAYMENT_ID) + ->withPayload([ + 'description' => 'Capture for order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentCaptureRequest::class, $request); + } +} diff --git a/tests/Factories/CreatePaymentLinkRequestFactoryTest.php b/tests/Factories/CreatePaymentLinkRequestFactoryTest.php new file mode 100644 index 00000000..108b236b --- /dev/null +++ b/tests/Factories/CreatePaymentLinkRequestFactoryTest.php @@ -0,0 +1,68 @@ +withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + 'webhookUrl' => 'https://example.com/webhook', + 'profileId' => 'pfl_12345', + 'reusable' => true, + 'expiresAt' => '2024-12-31', + 'allowedMethods' => ['ideal', 'creditcard'], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentLinkRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_link_request_object_with_minimal_data() + { + $request = CreatePaymentLinkRequestFactory::new() + ->withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentLinkRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_link_request_object_with_partial_data() + { + $request = CreatePaymentLinkRequestFactory::new() + ->withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + 'webhookUrl' => 'https://example.com/webhook', + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentLinkRequest::class, $request); + } +} diff --git a/tests/Factories/CreatePaymentRefundRequestFactoryTest.php b/tests/Factories/CreatePaymentRefundRequestFactoryTest.php new file mode 100644 index 00000000..29ef7872 --- /dev/null +++ b/tests/Factories/CreatePaymentRefundRequestFactoryTest.php @@ -0,0 +1,64 @@ +withPayload([ + 'description' => 'Order refund', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'metadata' => [ + 'order_id' => '12345', + 'reason' => 'customer_request', + ], + 'reverseRouting' => true, + 'routingReversals' => [ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '50.00', + ], + 'source' => [ + 'organizationId' => 'org_12345', + ], + ], + ], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentRefundRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_refund_request_object_with_minimal_data() + { + $request = CreatePaymentRefundRequestFactory::new(self::PAYMENT_ID) + ->withPayload([ + 'description' => 'Refund for order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'metadata' => [ + 'order_id' => '12345', + 'reason' => 'customer_request', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentRefundRequest::class, $request); + } +} diff --git a/tests/Factories/CreatePaymentRequestFactoryTest.php b/tests/Factories/CreatePaymentRequestFactoryTest.php new file mode 100644 index 00000000..6b80a6da --- /dev/null +++ b/tests/Factories/CreatePaymentRequestFactoryTest.php @@ -0,0 +1,111 @@ +withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + 'cancelUrl' => 'https://example.com/cancel', + 'webhookUrl' => 'https://example.com/webhook', + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '50.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + 'billingAddress' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + 'shippingAddress' => [ + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + ], + 'locale' => 'nl_NL', + 'method' => 'ideal', + 'issuer' => 'ideal_INGBNL2A', + 'restrictPaymentMethodsToCountry' => 'NL', + 'metadata' => [ + 'order_id' => '12345', + ], + 'captureMode' => 'manual', + 'captureDelay' => 'P3D', + 'applicationFee' => [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '1.00', + ], + 'description' => 'Application fee', + ], + 'routing' => [ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '50.00', + ], + 'destination' => [ + 'type' => 'organization', + 'organizationId' => 'org_12345', + ], + ], + ], + 'sequenceType' => 'oneoff', + 'mandateId' => 'mdt_12345', + 'customerId' => 'cst_12345', + 'profileId' => 'pfl_12345', + 'additional' => [ + 'customField' => 'customValue', + ], + ]) + ->withQuery([ + 'includeQrCode' => true, + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_request_object_with_minimal_data() + { + $request = CreatePaymentRequestFactory::new() + ->withPayload([ + 'description' => 'Order #12345', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'redirectUrl' => 'https://example.com/redirect', + ]) + ->create(); + + $this->assertInstanceOf(CreatePaymentRequest::class, $request); + } +} diff --git a/tests/Factories/CreateProfileRequestFactoryTest.php b/tests/Factories/CreateProfileRequestFactoryTest.php new file mode 100644 index 00000000..6a6fea8a --- /dev/null +++ b/tests/Factories/CreateProfileRequestFactoryTest.php @@ -0,0 +1,59 @@ +withPayload([ + 'name' => 'My Webshop', + 'website' => 'https://www.mywebshop.com', + 'email' => 'info@mywebshop.com', + 'phone' => '+31612345678', + 'description' => 'Online store selling premium products', + 'countriesOfActivity' => ['NL', 'BE', 'DE'], + 'businessCategory' => 'RETAIL', + ]) + ->create(); + + $this->assertInstanceOf(CreateProfileRequest::class, $request); + } + + /** @test */ + public function create_returns_profile_request_object_with_minimal_data() + { + $request = CreateProfileRequestFactory::new() + ->withPayload([ + 'name' => 'My Webshop', + 'website' => 'https://www.mywebshop.com', + 'email' => 'info@mywebshop.com', + 'phone' => '+31612345678', + ]) + ->create(); + + $this->assertInstanceOf(CreateProfileRequest::class, $request); + } + + /** @test */ + public function create_returns_profile_request_object_with_partial_data() + { + $request = CreateProfileRequestFactory::new() + ->withPayload([ + 'name' => 'My Webshop', + 'website' => 'https://www.mywebshop.com', + 'email' => 'info@mywebshop.com', + 'phone' => '+31612345678', + 'description' => 'Online store selling premium products', + ]) + ->create(); + + $this->assertInstanceOf(CreateProfileRequest::class, $request); + } +} diff --git a/tests/Factories/CreateSalesInvoiceRequestFactoryTest.php b/tests/Factories/CreateSalesInvoiceRequestFactoryTest.php new file mode 100644 index 00000000..74a6ece6 --- /dev/null +++ b/tests/Factories/CreateSalesInvoiceRequestFactoryTest.php @@ -0,0 +1,139 @@ +withPayload([ + 'currency' => 'EUR', + 'status' => 'draft', + 'vatScheme' => 'standard', + 'vatMode' => 'inclusive', + 'paymentTerm' => 30, + 'recipientIdentifier' => 'cst_12345', + 'recipient' => [ + 'type' => 'organization', + 'email' => 'org@example.com', + 'streetAndNumber' => 'Business Ave 42', + 'postalCode' => '5678CD', + 'city' => 'Rotterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + ], + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + 'profileId' => 'pfl_12345', + 'memo' => 'Please pay within 30 days', + 'paymentDetails' => [ + 'source' => 'NL55INGB0000000000', + 'sourceDescription' => 'ING Bank', + ], + 'emailDetails' => [ + 'subject' => 'Invoice from Example Company', + 'body' => 'Please find attached the invoice for your recent purchase.', + ], + 'webhookUrl' => 'https://example.com/webhook', + 'discount' => [ + 'type' => 'percentage', + 'value' => '10', + ], + ]) + ->create(); + + $this->assertInstanceOf(CreateSalesInvoiceRequest::class, $request); + } + + /** @test */ + public function create_returns_sales_invoice_request_object_with_minimal_data() + { + $request = CreateSalesInvoiceRequestFactory::new() + ->withPayload([ + 'currency' => 'EUR', + 'status' => 'draft', + 'vatScheme' => 'standard', + 'vatMode' => 'inclusive', + 'recipientIdentifier' => 'cst_12345', + 'paymentTerm' => PaymentTerm::DAYS_30, + 'recipient' => [ + 'type' => 'organization', + 'email' => 'org@example.com', + 'streetAndNumber' => 'Business Ave 42', + 'postalCode' => '5678CD', + 'city' => 'Rotterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + ], + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + ]) + ->create(); + + $this->assertInstanceOf(CreateSalesInvoiceRequest::class, $request); + } + + /** @test */ + public function create_returns_sales_invoice_request_object_with_partial_data() + { + $request = CreateSalesInvoiceRequestFactory::new() + ->withPayload([ + 'currency' => 'EUR', + 'status' => 'draft', + 'vatScheme' => 'standard', + 'vatMode' => 'inclusive', + 'paymentTerm' => 30, + 'recipientIdentifier' => 'cst_12345', + 'recipient' => [ + 'type' => 'organization', + 'email' => 'org@example.com', + 'streetAndNumber' => 'Business Ave 42', + 'postalCode' => '5678CD', + 'city' => 'Rotterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + ], + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + 'memo' => 'Please pay within 30 days', + 'webhookUrl' => 'https://example.com/webhook', + ]) + ->create(); + + $this->assertInstanceOf(CreateSalesInvoiceRequest::class, $request); + } +} diff --git a/tests/Factories/CreateSubscriptionRequestFactoryTest.php b/tests/Factories/CreateSubscriptionRequestFactoryTest.php new file mode 100644 index 00000000..083f1045 --- /dev/null +++ b/tests/Factories/CreateSubscriptionRequestFactoryTest.php @@ -0,0 +1,84 @@ +withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription', + 'status' => 'active', + 'times' => 12, + 'startDate' => '2024-01-01', + 'method' => 'directdebit', + 'applicationFee' => [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '1.00', + ], + 'description' => 'Application fee', + ], + 'metadata' => [ + 'subscription_id' => '12345', + 'plan' => 'premium', + ], + 'webhookUrl' => 'https://example.com/webhook', + 'mandateId' => 'mdt_12345', + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(CreateSubscriptionRequest::class, $request); + } + + /** @test */ + public function create_returns_subscription_request_object_with_minimal_data() + { + $request = CreateSubscriptionRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription', + ]) + ->create(); + + $this->assertInstanceOf(CreateSubscriptionRequest::class, $request); + } + + /** @test */ + public function create_returns_subscription_request_object_with_partial_data() + { + $request = CreateSubscriptionRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + 'interval' => '1 month', + 'description' => 'Monthly subscription', + 'status' => 'active', + 'times' => 12, + 'startDate' => '2024-01-01', + ]) + ->create(); + + $this->assertInstanceOf(CreateSubscriptionRequest::class, $request); + } +} diff --git a/tests/Factories/GetAllPaginatedSubscriptionsRequestFactoryTest.php b/tests/Factories/GetAllPaginatedSubscriptionsRequestFactoryTest.php new file mode 100644 index 00000000..d4d1bca3 --- /dev/null +++ b/tests/Factories/GetAllPaginatedSubscriptionsRequestFactoryTest.php @@ -0,0 +1,46 @@ +withQuery([ + 'limit' => 50, + 'from' => 'sub_12345', + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetAllPaginatedSubscriptionsRequest::class, $request); + } + + /** @test */ + public function create_returns_all_paginated_subscriptions_request_object_with_minimal_data() + { + $request = GetAllPaginatedSubscriptionsRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetAllPaginatedSubscriptionsRequest::class, $request); + } + + /** @test */ + public function create_returns_all_paginated_subscriptions_request_object_with_partial_data() + { + $request = GetAllPaginatedSubscriptionsRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'from' => 'sub_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetAllPaginatedSubscriptionsRequest::class, $request); + } +} diff --git a/tests/Factories/GetAllPaymentMethodsRequestFactoryTest.php b/tests/Factories/GetAllPaymentMethodsRequestFactoryTest.php new file mode 100644 index 00000000..de55953d --- /dev/null +++ b/tests/Factories/GetAllPaymentMethodsRequestFactoryTest.php @@ -0,0 +1,49 @@ +withQuery([ + 'include' => ['issuers', 'pricing'], + 'locale' => 'nl_NL', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ]) + ->create(); + + $this->assertInstanceOf(GetAllMethodsRequest::class, $request); + } + + /** @test */ + public function create_returns_all_methods_request_object_with_minimal_data() + { + $request = GetAllPaymentMethodsRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetAllMethodsRequest::class, $request); + } + + /** @test */ + public function create_returns_all_methods_request_object_with_partial_data() + { + $request = GetAllPaymentMethodsRequestFactory::new() + ->withQuery([ + 'include' => ['issuers'], + 'locale' => 'nl_NL', + ]) + ->create(); + + $this->assertInstanceOf(GetAllMethodsRequest::class, $request); + } +} diff --git a/tests/Factories/GetBalanceReportRequestFactoryTest.php b/tests/Factories/GetBalanceReportRequestFactoryTest.php new file mode 100644 index 00000000..e1b3c312 --- /dev/null +++ b/tests/Factories/GetBalanceReportRequestFactoryTest.php @@ -0,0 +1,75 @@ +withQuery([ + 'from' => '2024-01-01', + 'until' => '2024-03-31', + 'grouping' => 'transaction-categories', + ]) + ->create(); + + $this->assertInstanceOf(GetBalanceReportRequest::class, $request); + } + + /** @test */ + public function create_returns_balance_report_request_object_with_minimal_data() + { + $request = GetBalanceReportRequestFactory::new(self::BALANCE_ID) + ->withQuery([ + 'from' => '2024-01-01', + 'until' => '2024-03-31', + ]) + ->create(); + + $this->assertInstanceOf(GetBalanceReportRequest::class, $request); + } + + /** @test */ + public function create_throws_exception_when_required_fields_are_missing() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The "from" and "until" fields are required.'); + + GetBalanceReportRequestFactory::new(self::BALANCE_ID) + ->create(); + } + + /** @test */ + public function create_throws_exception_when_from_field_is_missing() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The "from" and "until" fields are required.'); + + GetBalanceReportRequestFactory::new(self::BALANCE_ID) + ->withQuery([ + 'until' => '2024-03-31', + ]) + ->create(); + } + + /** @test */ + public function create_throws_exception_when_until_field_is_missing() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The "from" and "until" fields are required.'); + + GetBalanceReportRequestFactory::new(self::BALANCE_ID) + ->withQuery([ + 'from' => '2024-01-01', + ]) + ->create(); + } +} diff --git a/tests/Factories/GetClientRequestFactoryTest.php b/tests/Factories/GetClientRequestFactoryTest.php new file mode 100644 index 00000000..b89bdfe5 --- /dev/null +++ b/tests/Factories/GetClientRequestFactoryTest.php @@ -0,0 +1,45 @@ +withQuery([ + 'embed' => ['organization', 'onboarding'], + ]) + ->create(); + + $this->assertInstanceOf(GetClientRequest::class, $request); + } + + /** @test */ + public function create_returns_client_request_object_with_minimal_data() + { + $request = GetClientRequestFactory::new(self::CLIENT_ID) + ->create(); + + $this->assertInstanceOf(GetClientRequest::class, $request); + } + + /** @test */ + public function create_returns_client_request_object_with_partial_data() + { + $request = GetClientRequestFactory::new(self::CLIENT_ID) + ->withQuery([ + 'embed' => ['organization'], + ]) + ->create(); + + $this->assertInstanceOf(GetClientRequest::class, $request); + } +} diff --git a/tests/Factories/GetEnabledMethodsRequestFactoryTest.php b/tests/Factories/GetEnabledMethodsRequestFactoryTest.php new file mode 100644 index 00000000..fa60e307 --- /dev/null +++ b/tests/Factories/GetEnabledMethodsRequestFactoryTest.php @@ -0,0 +1,59 @@ +withQuery([ + 'sequenceType' => 'oneoff', + 'resource' => 'payments', + 'locale' => 'nl_NL', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'billingCountry' => 'NL', + 'includeWallets' => ['applepay'], + 'orderLineCategories' => ['digital-goods', 'physical-goods'], + 'profileId' => 'pfl_12345', + 'include' => ['issuers', 'pricing'], + ]) + ->create(); + + $this->assertInstanceOf(GetEnabledMethodsRequest::class, $request); + } + + /** @test */ + public function create_returns_enabled_methods_request_object_with_minimal_data() + { + $request = GetEnabledMethodsRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetEnabledMethodsRequest::class, $request); + } + + /** @test */ + public function create_returns_enabled_methods_request_object_with_partial_data() + { + $request = GetEnabledMethodsRequestFactory::new() + ->withQuery([ + 'locale' => 'nl_NL', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + 'billingCountry' => 'NL', + ]) + ->create(); + + $this->assertInstanceOf(GetEnabledMethodsRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedChargebacksRequestFactoryTest.php b/tests/Factories/GetPaginatedChargebacksRequestFactoryTest.php new file mode 100644 index 00000000..f0d860f4 --- /dev/null +++ b/tests/Factories/GetPaginatedChargebacksRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'chb_12345', + 'limit' => 50, + 'include' => ['payment'], + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_chargebacks_request_object_with_minimal_data() + { + $request = GetPaginatedChargebacksRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetPaginatedChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_chargebacks_request_object_with_partial_data() + { + $request = GetPaginatedChargebacksRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedChargebacksRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedClientRequestFactoryTest.php b/tests/Factories/GetPaginatedClientRequestFactoryTest.php new file mode 100644 index 00000000..d58fee61 --- /dev/null +++ b/tests/Factories/GetPaginatedClientRequestFactoryTest.php @@ -0,0 +1,46 @@ +withQuery([ + 'from' => 'org_12345', + 'limit' => 50, + 'embed' => ['organization', 'onboarding'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedClientRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_client_request_object_with_minimal_data() + { + $request = GetPaginatedClientRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetPaginatedClientRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_client_request_object_with_partial_data() + { + $request = GetPaginatedClientRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'embed' => ['organization'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedClientRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedCustomerPaymentsRequestFactoryTest.php b/tests/Factories/GetPaginatedCustomerPaymentsRequestFactoryTest.php new file mode 100644 index 00000000..1fb13690 --- /dev/null +++ b/tests/Factories/GetPaginatedCustomerPaymentsRequestFactoryTest.php @@ -0,0 +1,49 @@ +withQuery([ + 'from' => 'tr_12345', + 'limit' => 50, + 'sort' => 'created_at', + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedCustomerPaymentsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_customer_payments_request_object_with_minimal_data() + { + $request = GetPaginatedCustomerPaymentsRequestFactory::new(self::CUSTOMER_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedCustomerPaymentsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_customer_payments_request_object_with_partial_data() + { + $request = GetPaginatedCustomerPaymentsRequestFactory::new(self::CUSTOMER_ID) + ->withQuery([ + 'limit' => 25, + 'sort' => 'created_at', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedCustomerPaymentsRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedInvoiceRequestFactoryTest.php b/tests/Factories/GetPaginatedInvoiceRequestFactoryTest.php new file mode 100644 index 00000000..2e73df7d --- /dev/null +++ b/tests/Factories/GetPaginatedInvoiceRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'inv_12345', + 'limit' => 50, + 'reference' => 'INV2024-001', + 'year' => '2024', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedInvoiceRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_invoice_request_object_with_minimal_data() + { + $request = GetPaginatedInvoiceRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetPaginatedInvoiceRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_invoice_request_object_with_partial_data() + { + $request = GetPaginatedInvoiceRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'year' => '2024', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedInvoiceRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedPaymentCapturesRequestFactoryTest.php b/tests/Factories/GetPaginatedPaymentCapturesRequestFactoryTest.php new file mode 100644 index 00000000..d4870e00 --- /dev/null +++ b/tests/Factories/GetPaginatedPaymentCapturesRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'cap_12345', + 'limit' => 50, + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentCapturesRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_payment_captures_request_object_with_minimal_data() + { + $request = GetPaginatedPaymentCapturesRequestFactory::new(self::PAYMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentCapturesRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_payment_captures_request_object_with_partial_data() + { + $request = GetPaginatedPaymentCapturesRequestFactory::new(self::PAYMENT_ID) + ->withQuery([ + 'limit' => 25, + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentCapturesRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedPaymentChargebacksRequestFactoryTest.php b/tests/Factories/GetPaginatedPaymentChargebacksRequestFactoryTest.php new file mode 100644 index 00000000..c1a96f3b --- /dev/null +++ b/tests/Factories/GetPaginatedPaymentChargebacksRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'chb_12345', + 'limit' => 50, + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_payment_chargebacks_request_object_with_minimal_data() + { + $request = GetPaginatedPaymentChargebacksRequestFactory::new(self::PAYMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_payment_chargebacks_request_object_with_partial_data() + { + $request = GetPaginatedPaymentChargebacksRequestFactory::new(self::PAYMENT_ID) + ->withQuery([ + 'limit' => 25, + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedPaymentChargebacksRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedRefundsRequestFactoryTest.php b/tests/Factories/GetPaginatedRefundsRequestFactoryTest.php new file mode 100644 index 00000000..91c79d93 --- /dev/null +++ b/tests/Factories/GetPaginatedRefundsRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'ref_12345', + 'limit' => 50, + 'embed' => ['payment'], + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedRefundsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_refunds_request_object_with_minimal_data() + { + $request = GetPaginatedRefundsRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetPaginatedRefundsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_refunds_request_object_with_partial_data() + { + $request = GetPaginatedRefundsRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedRefundsRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedSettlementCapturesRequestFactoryTest.php b/tests/Factories/GetPaginatedSettlementCapturesRequestFactoryTest.php new file mode 100644 index 00000000..ec6f48da --- /dev/null +++ b/tests/Factories/GetPaginatedSettlementCapturesRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'cap_12345', + 'limit' => 50, + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementCapturesRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_captures_request_object_with_minimal_data() + { + $request = GetPaginatedSettlementCapturesRequestFactory::new(self::SETTLEMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementCapturesRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_captures_request_object_with_partial_data() + { + $request = GetPaginatedSettlementCapturesRequestFactory::new(self::SETTLEMENT_ID) + ->withQuery([ + 'limit' => 25, + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementCapturesRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedSettlementChargebacksRequestFactoryTest.php b/tests/Factories/GetPaginatedSettlementChargebacksRequestFactoryTest.php new file mode 100644 index 00000000..22e2e5ca --- /dev/null +++ b/tests/Factories/GetPaginatedSettlementChargebacksRequestFactoryTest.php @@ -0,0 +1,49 @@ +withQuery([ + 'from' => 'chb_12345', + 'limit' => 50, + 'include' => ['payment'], + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_chargebacks_request_object_with_minimal_data() + { + $request = GetPaginatedSettlementChargebacksRequestFactory::new(self::SETTLEMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementChargebacksRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_chargebacks_request_object_with_partial_data() + { + $request = GetPaginatedSettlementChargebacksRequestFactory::new(self::SETTLEMENT_ID) + ->withQuery([ + 'limit' => 25, + 'profileId' => 'pfl_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementChargebacksRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedSettlementRefundsQueryFactoryTest.php b/tests/Factories/GetPaginatedSettlementRefundsQueryFactoryTest.php new file mode 100644 index 00000000..aa2a04a4 --- /dev/null +++ b/tests/Factories/GetPaginatedSettlementRefundsQueryFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'from' => 'ref_12345', + 'limit' => 50, + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementRefundsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_refunds_request_object_with_minimal_data() + { + $request = GetPaginatedSettlementRefundsQueryFactory::new(self::SETTLEMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementRefundsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlement_refunds_request_object_with_partial_data() + { + $request = GetPaginatedSettlementRefundsQueryFactory::new(self::SETTLEMENT_ID) + ->withQuery([ + 'limit' => 25, + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementRefundsRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaginatedSettlementsRequestFactoryTest.php b/tests/Factories/GetPaginatedSettlementsRequestFactoryTest.php new file mode 100644 index 00000000..5b9938ad --- /dev/null +++ b/tests/Factories/GetPaginatedSettlementsRequestFactoryTest.php @@ -0,0 +1,46 @@ +withQuery([ + 'from' => 'stl_12345', + 'limit' => 50, + 'balanceId' => 'bal_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlements_request_object_with_minimal_data() + { + $request = GetPaginatedSettlementsRequestFactory::new() + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementsRequest::class, $request); + } + + /** @test */ + public function create_returns_paginated_settlements_request_object_with_partial_data() + { + $request = GetPaginatedSettlementsRequestFactory::new() + ->withQuery([ + 'limit' => 25, + 'balanceId' => 'bal_12345', + ]) + ->create(); + + $this->assertInstanceOf(GetPaginatedSettlementsRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaymentCaptureRequestFactoryTest.php b/tests/Factories/GetPaymentCaptureRequestFactoryTest.php new file mode 100644 index 00000000..6d6d615e --- /dev/null +++ b/tests/Factories/GetPaymentCaptureRequestFactoryTest.php @@ -0,0 +1,35 @@ +withQuery([ + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentCaptureRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_capture_request_object_with_minimal_data() + { + $request = GetPaymentCaptureRequestFactory::new(self::PAYMENT_ID, self::CAPTURE_ID) + ->create(); + + $this->assertInstanceOf(GetPaymentCaptureRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaymentChargebackRequestFactoryTest.php b/tests/Factories/GetPaymentChargebackRequestFactoryTest.php new file mode 100644 index 00000000..208aaa3f --- /dev/null +++ b/tests/Factories/GetPaymentChargebackRequestFactoryTest.php @@ -0,0 +1,35 @@ +withQuery([ + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentChargebackRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_chargeback_request_object_with_minimal_data() + { + $request = GetPaymentChargebackRequestFactory::new(self::PAYMENT_ID, self::CHARGEBACK_ID) + ->create(); + + $this->assertInstanceOf(GetPaymentChargebackRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaymentMethodRequestFactoryTest.php b/tests/Factories/GetPaymentMethodRequestFactoryTest.php new file mode 100644 index 00000000..ffabc6d2 --- /dev/null +++ b/tests/Factories/GetPaymentMethodRequestFactoryTest.php @@ -0,0 +1,49 @@ +withQuery([ + 'locale' => 'nl_NL', + 'currency' => 'EUR', + 'profileId' => 'pfl_12345', + 'include' => ['issuers', 'pricing'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentMethodRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_method_request_object_with_minimal_data() + { + $request = GetPaymentMethodRequestFactory::new(self::METHOD_ID) + ->create(); + + $this->assertInstanceOf(GetPaymentMethodRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_method_request_object_with_partial_data() + { + $request = GetPaymentMethodRequestFactory::new(self::METHOD_ID) + ->withQuery([ + 'locale' => 'nl_NL', + 'currency' => 'EUR', + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentMethodRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaymentRefundRequestFactoryTest.php b/tests/Factories/GetPaymentRefundRequestFactoryTest.php new file mode 100644 index 00000000..2300837b --- /dev/null +++ b/tests/Factories/GetPaymentRefundRequestFactoryTest.php @@ -0,0 +1,35 @@ +withQuery([ + 'include' => ['payment'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentRefundRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_refund_request_object_with_minimal_data() + { + $request = GetPaymentRefundRequestFactory::new(self::PAYMENT_ID, self::REFUND_ID) + ->create(); + + $this->assertInstanceOf(GetPaymentRefundRequest::class, $request); + } +} diff --git a/tests/Factories/GetPaymentRequestFactoryTest.php b/tests/Factories/GetPaymentRequestFactoryTest.php new file mode 100644 index 00000000..d8ae74a6 --- /dev/null +++ b/tests/Factories/GetPaymentRequestFactoryTest.php @@ -0,0 +1,47 @@ +withQuery([ + 'embed' => ['captures', 'refunds', 'chargebacks'], + 'include' => ['qrCode', 'remainderDetails'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_request_object_with_minimal_data() + { + $request = GetPaymentRequestFactory::new(self::PAYMENT_ID) + ->create(); + + $this->assertInstanceOf(GetPaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_payment_request_object_with_partial_data() + { + $request = GetPaymentRequestFactory::new(self::PAYMENT_ID) + ->withQuery([ + 'embed' => ['captures'], + 'include' => ['qrCode'], + ]) + ->create(); + + $this->assertInstanceOf(GetPaymentRequest::class, $request); + } +} diff --git a/tests/Factories/InvoiceLineCollectionFactoryTest.php b/tests/Factories/InvoiceLineCollectionFactoryTest.php new file mode 100644 index 00000000..8859fec3 --- /dev/null +++ b/tests/Factories/InvoiceLineCollectionFactoryTest.php @@ -0,0 +1,50 @@ + 'First Invoice Line', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'discount' => [ + 'type' => 'percentage', + 'value' => '10', + ], + ], + [ + 'description' => 'Second Invoice Line', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '15.00', + ], + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + } + + /** @test */ + public function create_returns_empty_collection_for_empty_input() + { + $collection = InvoiceLineCollectionFactory::new([])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(0, $collection); + } +} diff --git a/tests/Factories/InvoiceLineFactoryTest.php b/tests/Factories/InvoiceLineFactoryTest.php new file mode 100644 index 00000000..17c97266 --- /dev/null +++ b/tests/Factories/InvoiceLineFactoryTest.php @@ -0,0 +1,46 @@ + 'Test Invoice Line', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'discount' => [ + 'type' => 'percentage', + 'value' => '10', + ], + ])->create(); + + $this->assertInstanceOf(InvoiceLine::class, $invoiceLine); + } + + /** @test */ + public function create_returns_invoice_line_object_with_minimal_data() + { + $invoiceLine = InvoiceLineFactory::new([ + 'description' => 'Test Invoice Line', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + ])->create(); + + $this->assertInstanceOf(InvoiceLine::class, $invoiceLine); + } +} diff --git a/tests/Factories/MoneyFactoryTest.php b/tests/Factories/MoneyFactoryTest.php new file mode 100644 index 00000000..8995be56 --- /dev/null +++ b/tests/Factories/MoneyFactoryTest.php @@ -0,0 +1,35 @@ + 'EUR', + 'value' => '10.00', + ])->create(); + + $this->assertInstanceOf(Money::class, $money); + $this->assertEquals('EUR', $money->currency); + $this->assertEquals('10.00', $money->value); + } + + /** @test */ + public function create_throws_exception_for_invalid_data() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid Money data provided'); + + MoneyFactory::new([ + 'currency' => 'EUR', + // missing value + ])->create(); + } +} diff --git a/tests/Factories/OrderLineCollectionFactoryTest.php b/tests/Factories/OrderLineCollectionFactoryTest.php new file mode 100644 index 00000000..f840ae9d --- /dev/null +++ b/tests/Factories/OrderLineCollectionFactoryTest.php @@ -0,0 +1,57 @@ + 'First Product', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '20.00', + ], + 'type' => 'physical', + ], + [ + 'description' => 'Second Product', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '15.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '15.00', + ], + 'type' => 'digital', + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(2, $collection); + } + + /** @test */ + public function create_returns_empty_collection_for_empty_input() + { + $collection = OrderLineCollectionFactory::new([])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(0, $collection); + } +} diff --git a/tests/Factories/OrderLineFactoryTest.php b/tests/Factories/OrderLineFactoryTest.php new file mode 100644 index 00000000..2799853c --- /dev/null +++ b/tests/Factories/OrderLineFactoryTest.php @@ -0,0 +1,68 @@ + 'Test Product', + 'quantity' => 2, + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '20.00', + ], + 'type' => 'physical', + 'quantityUnit' => 'pcs', + 'discountAmount' => [ + 'currency' => 'EUR', + 'value' => '5.00', + ], + 'recurring' => [ + 'times' => 12, + 'interval' => '1 month', + ], + 'vatRate' => '21.00', + 'vatAmount' => [ + 'currency' => 'EUR', + 'value' => '4.20', + ], + 'sku' => 'PROD-123', + 'imageUrl' => 'https://example.com/image.jpg', + 'productUrl' => 'https://example.com/product', + ])->create(); + + $this->assertInstanceOf(OrderLine::class, $orderLine); + } + + /** @test */ + public function create_returns_order_line_object_with_minimal_data() + { + $orderLine = OrderLineFactory::new([ + 'description' => 'Test Product', + 'quantity' => 1, + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'totalAmount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'type' => 'digital', + 'vatRate' => '21.00', + ])->create(); + + $this->assertInstanceOf(OrderLine::class, $orderLine); + } +} diff --git a/tests/Factories/PaymentRouteCollectionFactoryTest.php b/tests/Factories/PaymentRouteCollectionFactoryTest.php new file mode 100644 index 00000000..429d1dd4 --- /dev/null +++ b/tests/Factories/PaymentRouteCollectionFactoryTest.php @@ -0,0 +1,77 @@ + [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'destination' => [ + 'organizationId' => 'org_123456', + ], + 'delayUntil' => '2024-12-31', + ], + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', + ], + 'destination' => [ + 'organizationId' => 'org_789012', + ], + 'delayUntil' => '2025-01-15', + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(2, $collection); + } + + /** @test */ + public function create_returns_payment_route_collection_with_minimal_data() + { + $collection = PaymentRouteCollectionFactory::new([ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'destination' => [ + 'organizationId' => 'org_123456', + ], + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(1, $collection); + } + + /** @test */ + public function create_throws_exception_for_invalid_data() + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Invalid PaymentRoute data provided'); + + PaymentRouteCollectionFactory::new([ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + // missing destination.organizationId + ], + ])->create(); + } +} diff --git a/tests/Factories/RecipientFactoryTest.php b/tests/Factories/RecipientFactoryTest.php new file mode 100644 index 00000000..7e307d73 --- /dev/null +++ b/tests/Factories/RecipientFactoryTest.php @@ -0,0 +1,51 @@ + 'individual', + 'email' => 'john@example.com', + 'streetAndNumber' => 'Main Street 1', + 'postalCode' => '1234AB', + 'city' => 'Amsterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + 'title' => 'Mr', + 'givenName' => 'John', + 'familyName' => 'Doe', + 'organizationName' => null, + 'organizationNumber' => null, + 'vatNumber' => null, + 'phone' => '+31612345678', + 'streetAdditional' => 'Floor 3', + 'region' => 'Noord-Holland', + ])->create(); + + $this->assertInstanceOf(Recipient::class, $recipient); + } + + /** @test */ + public function create_returns_recipient_object_with_minimal_data() + { + $recipient = RecipientFactory::new([ + 'type' => 'organization', + 'email' => 'org@example.com', + 'streetAndNumber' => 'Business Ave 42', + 'postalCode' => '5678CD', + 'city' => 'Rotterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + ])->create(); + + $this->assertInstanceOf(Recipient::class, $recipient); + } +} diff --git a/tests/Factories/RecurringBillingCycleFactoryTest.php b/tests/Factories/RecurringBillingCycleFactoryTest.php new file mode 100644 index 00000000..ddc43427 --- /dev/null +++ b/tests/Factories/RecurringBillingCycleFactoryTest.php @@ -0,0 +1,38 @@ + '1 month', + 'descriptipn' => 'Monthly subscription', + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.99', + ], + 'times' => 12, + 'startDate' => '2024-03-01', + ])->create(); + + $this->assertInstanceOf(RecurringBillingCycle::class, $cycle); + } + + /** @test */ + public function create_returns_recurring_billing_cycle_with_minimal_data() + { + $cycle = RecurringBillingCycleFactory::new([ + 'interval' => '1 month', + 'descriptipn' => 'Monthly subscription', + ])->create(); + + $this->assertInstanceOf(RecurringBillingCycle::class, $cycle); + } +} diff --git a/tests/Factories/RefundRouteCollectionFactoryTest.php b/tests/Factories/RefundRouteCollectionFactoryTest.php new file mode 100644 index 00000000..311e0451 --- /dev/null +++ b/tests/Factories/RefundRouteCollectionFactoryTest.php @@ -0,0 +1,75 @@ + [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'source' => [ + 'organizationId' => 'org_123456', + ], + ], + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '20.00', + ], + 'source' => [ + 'organizationId' => 'org_789012', + ], + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(2, $collection); + } + + /** @test */ + public function create_returns_refund_route_collection_with_single_route() + { + $collection = RefundRouteCollectionFactory::new([ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + 'source' => [ + 'organizationId' => 'org_123456', + ], + ], + ])->create(); + + $this->assertInstanceOf(DataCollection::class, $collection); + $this->assertCount(1, $collection); + } + + /** @test */ + public function create_throws_exception_for_invalid_data() + { + $this->expectException(LogicException::class); + $this->expectExceptionMessage('Invalid RefundRoute data provided'); + + RefundRouteCollectionFactory::new([ + [ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '10.00', + ], + // missing source.organizationId + ], + ])->create(); + } +} diff --git a/tests/Factories/UpdateCustomerRequestFactoryTest.php b/tests/Factories/UpdateCustomerRequestFactoryTest.php new file mode 100644 index 00000000..9a6a8f88 --- /dev/null +++ b/tests/Factories/UpdateCustomerRequestFactoryTest.php @@ -0,0 +1,56 @@ +withPayload([ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'locale' => 'nl_NL', + 'metadata' => [ + 'order_id' => '12345', + 'customer_type' => 'premium', + ], + ]) + ->create(); + + $this->assertInstanceOf(UpdateCustomerRequest::class, $request); + } + + /** @test */ + public function create_returns_update_customer_request_object_with_minimal_data() + { + $request = UpdateCustomerRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'name' => 'John Doe', + ]) + ->create(); + + $this->assertInstanceOf(UpdateCustomerRequest::class, $request); + } + + /** @test */ + public function create_returns_update_customer_request_object_with_partial_data() + { + $request = UpdateCustomerRequestFactory::new(self::CUSTOMER_ID) + ->withPayload([ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'locale' => 'nl_NL', + ]) + ->create(); + + $this->assertInstanceOf(UpdateCustomerRequest::class, $request); + } +} diff --git a/tests/Factories/UpdatePaymentLinkRequestFactoryTest.php b/tests/Factories/UpdatePaymentLinkRequestFactoryTest.php new file mode 100644 index 00000000..c6e32dc9 --- /dev/null +++ b/tests/Factories/UpdatePaymentLinkRequestFactoryTest.php @@ -0,0 +1,51 @@ +withPayload([ + 'description' => 'Updated payment link description', + 'archived' => true, + 'allowedMethods' => ['ideal', 'creditcard'], + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentLinkRequest::class, $request); + } + + /** @test */ + public function create_returns_update_payment_link_request_object_with_minimal_data() + { + $request = UpdatePaymentLinkRequestFactory::new(self::PAYMENT_LINK_ID) + ->withPayload([ + 'description' => 'Updated payment link description', + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentLinkRequest::class, $request); + } + + /** @test */ + public function create_returns_update_payment_link_request_object_with_partial_data() + { + $request = UpdatePaymentLinkRequestFactory::new(self::PAYMENT_LINK_ID) + ->withPayload([ + 'description' => 'Updated payment link description', + 'archived' => true, + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentLinkRequest::class, $request); + } +} diff --git a/tests/Factories/UpdatePaymentRequestFactoryTest.php b/tests/Factories/UpdatePaymentRequestFactoryTest.php new file mode 100644 index 00000000..05e783f3 --- /dev/null +++ b/tests/Factories/UpdatePaymentRequestFactoryTest.php @@ -0,0 +1,65 @@ +withPayload([ + 'description' => 'Updated payment description', + 'redirectUrl' => 'https://example.com/redirect', + 'cancelUrl' => 'https://example.com/cancel', + 'webhookUrl' => 'https://example.com/webhook', + 'metadata' => [ + 'order_id' => '12345', + 'customer_id' => '67890', + ], + 'method' => 'ideal', + 'locale' => 'nl_NL', + 'restrictPaymentMethodsToCountry' => 'NL', + 'additional' => [ + 'customField' => 'customValue', + ], + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_update_payment_request_object_with_minimal_data() + { + $request = UpdatePaymentRequestFactory::new(self::PAYMENT_ID) + ->withPayload([ + 'description' => 'Updated payment description', + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentRequest::class, $request); + } + + /** @test */ + public function create_returns_update_payment_request_object_with_filtered_properties() + { + $request = UpdatePaymentRequestFactory::new(self::PAYMENT_ID) + ->withPayload([ + 'description' => 'Updated payment description', + 'metadata' => [ + 'order_id' => '12345', + ], + 'invalidField' => 'This should be filtered out', + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentRequest::class, $request); + } +} diff --git a/tests/Factories/UpdatePaymentRouteRequestFactoryTest.php b/tests/Factories/UpdatePaymentRouteRequestFactoryTest.php new file mode 100644 index 00000000..676d57ed --- /dev/null +++ b/tests/Factories/UpdatePaymentRouteRequestFactoryTest.php @@ -0,0 +1,36 @@ +withPayload([ + 'releaseDate' => '2024-01-01', + ]) + ->create(); + + $this->assertInstanceOf(UpdatePaymentRouteRequest::class, $request); + } + + /** @test */ + public function create_throws_exception_when_release_date_is_missing() + { + $this->expectException(\Mollie\Api\Exceptions\LogicException::class); + $this->expectExceptionMessage('Release date is required'); + + UpdatePaymentRouteRequestFactory::new(self::PAYMENT_ID, self::ROUTE_ID) + ->create(); + } +} diff --git a/tests/Factories/UpdateProfileRequestFactoryTest.php b/tests/Factories/UpdateProfileRequestFactoryTest.php new file mode 100644 index 00000000..928bd170 --- /dev/null +++ b/tests/Factories/UpdateProfileRequestFactoryTest.php @@ -0,0 +1,59 @@ +withPayload([ + 'name' => 'My Updated Webshop', + 'website' => 'https://www.mywebshop.com', + 'email' => 'info@mywebshop.com', + 'phone' => '+31612345678', + 'description' => 'Online store selling premium products', + 'countriesOfActivity' => ['NL', 'BE', 'DE'], + 'businessCategory' => 'RETAIL', + 'mode' => 'live', + ]) + ->create(); + + $this->assertInstanceOf(UpdateProfileRequest::class, $request); + } + + /** @test */ + public function create_returns_update_profile_request_object_with_minimal_data() + { + $request = UpdateProfileRequestFactory::new(self::PROFILE_ID) + ->withPayload([ + 'name' => 'My Updated Webshop', + ]) + ->create(); + + $this->assertInstanceOf(UpdateProfileRequest::class, $request); + } + + /** @test */ + public function create_returns_update_profile_request_object_with_partial_data() + { + $request = UpdateProfileRequestFactory::new(self::PROFILE_ID) + ->withPayload([ + 'name' => 'My Updated Webshop', + 'website' => 'https://www.mywebshop.com', + 'email' => 'info@mywebshop.com', + 'phone' => '+31612345678', + 'description' => 'Online store selling premium products', + ]) + ->create(); + + $this->assertInstanceOf(UpdateProfileRequest::class, $request); + } +} diff --git a/tests/Factories/UpdateSalesInvoiceRequestFactoryTest.php b/tests/Factories/UpdateSalesInvoiceRequestFactoryTest.php new file mode 100644 index 00000000..fbf5b280 --- /dev/null +++ b/tests/Factories/UpdateSalesInvoiceRequestFactoryTest.php @@ -0,0 +1,84 @@ +withPayload([ + 'status' => 'draft', + 'recipientIdentifier' => 'cst_12345', + 'paymentTerm' => 30, + 'memo' => 'Please pay within 30 days', + 'paymentDetails' => [ + 'source' => 'NL55INGB0000000000', + 'sourceDescription' => 'ING Bank', + ], + 'emailDetails' => [ + 'subject' => 'Invoice from Example Company', + 'body' => 'Please find attached the invoice for your recent purchase.', + ], + 'recipient' => [ + 'type' => 'organization', + 'email' => 'org@example.com', + 'streetAndNumber' => 'Business Ave 42', + 'postalCode' => '5678CD', + 'city' => 'Rotterdam', + 'country' => 'NL', + 'locale' => 'nl_NL', + ], + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 2, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + 'webhookUrl' => 'https://example.com/webhook', + 'discount' => [ + 'type' => 'percentage', + 'value' => '10', + ], + ]) + ->create(); + + $this->assertInstanceOf(UpdateSalesInvoiceRequest::class, $request); + } + + /** @test */ + public function create_returns_update_sales_invoice_request_object_with_minimal_data() + { + $request = UpdateSalesInvoiceRequestFactory::new(self::INVOICE_ID) + ->withPayload([ + 'status' => 'draft', + 'recipientIdentifier' => 'cst_12345', + 'lines' => [ + [ + 'description' => 'Product A', + 'quantity' => 1, + 'vatRate' => '21.00', + 'unitPrice' => [ + 'currency' => 'EUR', + 'value' => '100.00', + ], + ], + ], + ]) + ->create(); + + $this->assertInstanceOf(UpdateSalesInvoiceRequest::class, $request); + } +} diff --git a/tests/Factories/UpdateSubscriptionRequestFactoryTest.php b/tests/Factories/UpdateSubscriptionRequestFactoryTest.php new file mode 100644 index 00000000..08e6c746 --- /dev/null +++ b/tests/Factories/UpdateSubscriptionRequestFactoryTest.php @@ -0,0 +1,72 @@ +withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + 'description' => 'Updated monthly subscription', + 'interval' => '1 month', + 'startDate' => '2024-01-01', + 'times' => 12, + 'metadata' => [ + 'subscription_id' => '12345', + 'plan' => 'premium', + ], + 'webhookUrl' => 'https://example.com/webhook', + 'mandateId' => 'mdt_12345', + ]) + ->create(); + + $this->assertInstanceOf(UpdateSubscriptionRequest::class, $request); + } + + /** @test */ + public function create_returns_update_subscription_request_object_with_minimal_data() + { + $request = UpdateSubscriptionRequestFactory::new(self::CUSTOMER_ID, self::SUBSCRIPTION_ID) + ->withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + ]) + ->create(); + + $this->assertInstanceOf(UpdateSubscriptionRequest::class, $request); + } + + /** @test */ + public function create_returns_update_subscription_request_object_with_partial_data() + { + $request = UpdateSubscriptionRequestFactory::new(self::CUSTOMER_ID, self::SUBSCRIPTION_ID) + ->withPayload([ + 'amount' => [ + 'currency' => 'EUR', + 'value' => '29.95', + ], + 'description' => 'Updated monthly subscription', + 'interval' => '1 month', + 'times' => 12, + ]) + ->create(); + + $this->assertInstanceOf(UpdateSubscriptionRequest::class, $request); + } +} diff --git a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php index b0620d52..4bdc4655 100644 --- a/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php +++ b/tests/Http/Requests/ApplePayPaymentSessionRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,14 +17,12 @@ public function it_can_create_apple_pay_session() ApplePayPaymentSessionRequest::class => MockResponse::ok('apple-pay-session'), ]); - $payload = new RequestApplePayPaymentSessionPayload( + $request = new ApplePayPaymentSessionRequest( 'https://example.com', 'Example Domain', - 'EUR' + '1234567890' ); - $request = new ApplePayPaymentSessionRequest($payload); - /** @var AnyResource */ $appleSession = $client->send($request); @@ -36,14 +33,12 @@ public function it_can_create_apple_pay_session() /** @test */ public function it_resolves_correct_resource_path() { - $payload = new RequestApplePayPaymentSessionPayload( + $request = new ApplePayPaymentSessionRequest( 'https://example.com', 'Example Domain', - 'EUR' + '1234567890' ); - $request = new ApplePayPaymentSessionRequest($payload); - $this->assertEquals( 'wallets/applepay/sessions', $request->resolveResourcePath() diff --git a/tests/Http/Requests/CreateClientLinkRequestTest.php b/tests/Http/Requests/CreateClientLinkRequestTest.php index 9a6991d9..925f9bd6 100644 --- a/tests/Http/Requests/CreateClientLinkRequestTest.php +++ b/tests/Http/Requests/CreateClientLinkRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -20,14 +19,12 @@ public function it_can_create_client_link() CreateClientLinkRequest::class => MockResponse::created('client-link'), ]); - $payload = new CreateClientLinkPayload( + $request = new CreateClientLinkRequest( new Owner('test@example.org', 'John', 'Doe'), 'Test', new OwnerAddress('NL') ); - $request = new CreateClientLinkRequest($payload); - /** @var ClientLink */ $clientLink = $client->send($request); diff --git a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php index cd31c992..9155b3ec 100644 --- a/tests/Http/Requests/CreateCustomerPaymentRequestTest.php +++ b/tests/Http/Requests/CreateCustomerPaymentRequestTest.php @@ -4,8 +4,6 @@ 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; @@ -20,16 +18,11 @@ public function it_can_create_customer_payment() CreateCustomerPaymentRequest::class => MockResponse::created('payment'), ]); - $payload = new CreatePaymentPayload( - 'Test payment', - new Money('EUR', '10.00'), - 'https://example.org/redirect' - ); - $request = new CreateCustomerPaymentRequest( 'cst_123', - $payload, - new CreatePaymentQuery(true) + 'Test payment', + new Money('EUR', '10.00'), + 'https://example.org/redirect', ); /** @var Payment */ @@ -43,11 +36,12 @@ public function it_can_create_customer_payment() public function it_resolves_correct_resource_path() { $customerId = 'cst_123'; - $request = new CreateCustomerPaymentRequest($customerId, new CreatePaymentPayload( + $request = new CreateCustomerPaymentRequest( + $customerId, '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 index 698b46d5..c20e2ba9 100644 --- a/tests/Http/Requests/CreateCustomerRequestTest.php +++ b/tests/Http/Requests/CreateCustomerRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,13 +17,11 @@ public function it_can_create_customer() CreateCustomerRequest::class => MockResponse::created('customer'), ]); - $payload = new CreateCustomerPayload( + $request = new CreateCustomerRequest( 'John Doe', 'john@example.org' ); - $request = new CreateCustomerRequest($payload); - /** @var Customer */ $customer = $client->send($request); @@ -35,10 +32,10 @@ public function it_can_create_customer() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateCustomerRequest(new CreateCustomerPayload( + $request = new CreateCustomerRequest( 'John Doe', 'john@example.org' - )); + ); $this->assertEquals('customers', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/CreateMandateRequestTest.php b/tests/Http/Requests/CreateMandateRequestTest.php index 28954df8..2d003c32 100644 --- a/tests/Http/Requests/CreateMandateRequestTest.php +++ b/tests/Http/Requests/CreateMandateRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,14 +18,13 @@ public function it_can_create_mandate() ]); $customerId = 'cst_kEn1PlbGa'; - $payload = new CreateMandatePayload( + $request = new CreateMandateRequest( + $customerId, 'directdebit', 'John Doe', 'NL55INGB0000000000' ); - $request = new CreateMandateRequest($customerId, $payload); - /** @var Mandate */ $mandate = $client->send($request); @@ -38,14 +36,13 @@ public function it_can_create_mandate() public function it_resolves_correct_resource_path() { $customerId = 'cst_kEn1PlbGa'; - $payload = new CreateMandatePayload( + $request = new CreateMandateRequest( + $customerId, '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 index 7cc23702..bde0d3c9 100644 --- a/tests/Http/Requests/CreatePaymentCaptureRequestTest.php +++ b/tests/Http/Requests/CreatePaymentCaptureRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,13 +18,12 @@ public function it_can_create_payment_capture() CreatePaymentCaptureRequest::class => MockResponse::created('capture'), ]); - $payload = new CreatePaymentCapturePayload( + $request = new CreatePaymentCaptureRequest( + 'tr_123', 'Test capture', new Money('EUR', '10.00') ); - $request = new CreatePaymentCaptureRequest('tr_123', $payload); - /** @var Capture */ $capture = $client->send($request); @@ -36,10 +34,11 @@ public function it_can_create_payment_capture() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreatePaymentCaptureRequest('tr_123', new CreatePaymentCapturePayload( + $request = new CreatePaymentCaptureRequest( + 'tr_123', '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 index 92f3230c..09304714 100644 --- a/tests/Http/Requests/CreatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/CreatePaymentLinkRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,13 +18,11 @@ public function it_can_create_payment_link() CreatePaymentLinkRequest::class => MockResponse::created('payment-link'), ]); - $payload = new CreatePaymentLinkPayload( + $request = new CreatePaymentLinkRequest( 'Test payment link', new Money('EUR', '10.00') ); - $request = new CreatePaymentLinkRequest($payload); - /** @var PaymentLink */ $paymentLink = $client->send($request); @@ -36,10 +33,10 @@ public function it_can_create_payment_link() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreatePaymentLinkRequest(new CreatePaymentLinkPayload( + $request = new CreatePaymentLinkRequest( '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 index f5e5d6c3..1d67ceb6 100644 --- a/tests/Http/Requests/CreatePaymentRefundRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRefundRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,14 +18,12 @@ public function it_can_create_payment_refund() CreatePaymentRefundRequest::class => MockResponse::created('refund'), ]); - $paymentId = 'tr_WDqYK6vllg'; - $payload = new CreateRefundPaymentPayload( + $request = new CreatePaymentRefundRequest( + 'tr_WDqYK6vllg', 'Order cancellation', new Money('EUR', '10.00') ); - $request = new CreatePaymentRefundRequest($paymentId, $payload); - /** @var Refund */ $refund = $client->send($request); @@ -38,13 +35,13 @@ public function it_can_create_payment_refund() public function it_resolves_correct_resource_path() { $paymentId = 'tr_WDqYK6vllg'; - $payload = new CreateRefundPaymentPayload( + + $request = new CreatePaymentRefundRequest( + $paymentId, '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 2bf148f2..6eb60811 100644 --- a/tests/Http/Requests/CreatePaymentRequestTest.php +++ b/tests/Http/Requests/CreatePaymentRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,15 +18,13 @@ public function it_can_create_payment() CreatePaymentRequest::class => MockResponse::created('payment'), ]); - $payload = new CreatePaymentPayload( + $request = new CreatePaymentRequest( 'Test payment', new Money('EUR', '10.00'), 'https://example.org/redirect', 'https://example.org/webhook', ); - $request = new CreatePaymentRequest($payload); - /** @var Payment */ $payment = $client->send($request); @@ -38,12 +35,12 @@ public function it_can_create_payment() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreatePaymentRequest(new CreatePaymentPayload( + $request = new CreatePaymentRequest( '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 index 83ef3b6d..e5fb6b54 100644 --- a/tests/Http/Requests/CreateProfileRequestTest.php +++ b/tests/Http/Requests/CreateProfileRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,15 +17,7 @@ public function it_can_create_profile() CreateProfileRequest::class => MockResponse::created('profile'), ]); - $payload = new CreateProfilePayload( - 'Test profile', - 'https://example.org', - 'test@example.org', - 'en_US', - '+31612345678' - ); - - $request = new CreateProfileRequest($payload); + $request = new CreateProfileRequest('Test profile', 'https://example.org', 'test@example.org', 'en_US', '+31612345678'); /** @var Profile */ $profile = $client->send($request); @@ -38,13 +29,7 @@ public function it_can_create_profile() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateProfileRequest(new CreateProfilePayload( - 'Test profile', - 'https://example.org', - 'test@example.org', - 'en_US', - '+31612345678' - )); + $request = new CreateProfileRequest('Test profile', 'https://example.org', 'test@example.org', 'en_US', '+31612345678'); $this->assertEquals('profiles', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php index d6a8f555..703b7700 100644 --- a/tests/Http/Requests/CreateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/CreateSalesInvoiceRequestTest.php @@ -4,7 +4,6 @@ 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; use Mollie\Api\Http\Data\Money; @@ -37,7 +36,7 @@ public function it_creates_sales_invoice() ]; // Create a sales invoice - $payload = new CreateSalesInvoicePayload( + $request = new CreateSalesInvoiceRequest( 'EUR', SalesInvoiceStatus::DRAFT, VatScheme::STANDARD, @@ -55,7 +54,6 @@ public function it_creates_sales_invoice() ), new DataCollection($invoiceLines) ); - $request = new CreateSalesInvoiceRequest($payload); /** @var SalesInvoice */ $salesInvoice = $client->send($request); @@ -67,31 +65,16 @@ public function it_creates_sales_invoice() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateSalesInvoiceRequest(new CreateSalesInvoicePayload( + $request = new CreateSalesInvoiceRequest( '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'), - ), - ]) - )); + 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/CreateSessionRequestTest.php b/tests/Http/Requests/CreateSessionRequestTest.php index 5eea86b9..fd599e0f 100644 --- a/tests/Http/Requests/CreateSessionRequestTest.php +++ b/tests/Http/Requests/CreateSessionRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,10 +17,7 @@ public function it_can_create_session() CreateSessionRequest::class => MockResponse::created('session'), ]); - $request = new CreateSessionRequest( - new AnyData(['foo' => 'bar']), - new AnyData(['baz' => 'qux']) - ); + $request = new CreateSessionRequest; /** @var Session */ $session = $client->send($request); @@ -33,7 +29,7 @@ public function it_can_create_session() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateSessionRequest(new AnyData(['foo' => 'bar']), new AnyData(['baz' => 'qux'])); + $request = new CreateSessionRequest; $this->assertEquals('sessions', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/CreateSubscriptionRequestTest.php b/tests/Http/Requests/CreateSubscriptionRequestTest.php index 4cf56145..9780db54 100644 --- a/tests/Http/Requests/CreateSubscriptionRequestTest.php +++ b/tests/Http/Requests/CreateSubscriptionRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,11 +18,7 @@ public function it_can_create_subscription() CreateSubscriptionRequest::class => MockResponse::created('subscription'), ]); - $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( - new Money('EUR', '10.00'), - '1 month', - 'Test subscription' - )); + $request = new CreateSubscriptionRequest('cst_123', new Money('EUR', '10.00'), '1 month', 'Test subscription'); /** @var Subscription */ $subscription = $client->send($request); @@ -35,11 +30,7 @@ public function it_can_create_subscription() /** @test */ public function it_resolves_correct_resource_path() { - $request = new CreateSubscriptionRequest('cst_123', new CreateSubscriptionPayload( - new Money('EUR', '10.00'), - '1 month', - 'Test subscription' - )); + $request = new CreateSubscriptionRequest('cst_123', new Money('EUR', '10.00'), '1 month', 'Test subscription'); $this->assertEquals('customers/cst_123/subscriptions', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetBalanceReportRequestTest.php b/tests/Http/Requests/GetBalanceReportRequestTest.php index ae9ddab3..c675bbce 100644 --- a/tests/Http/Requests/GetBalanceReportRequestTest.php +++ b/tests/Http/Requests/GetBalanceReportRequestTest.php @@ -5,7 +5,6 @@ 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; @@ -19,13 +18,7 @@ public function it_can_get_balance_report() GetBalanceReportRequest::class => MockResponse::ok('balance-report'), ]); - $request = new GetBalanceReportRequest( - 'bal_12345', - new GetBalanceReportQuery( - new DateTime('2024-01-01'), - new DateTime('2024-01-31'), - ) - ); + $request = new GetBalanceReportRequest('bal_12345', new DateTime('2024-01-01'), new DateTime('2024-01-31')); /** @var BalanceReport */ $balanceReport = $client->send($request); @@ -37,10 +30,7 @@ public function it_can_get_balance_report() /** @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'), - )); + $request = new GetBalanceReportRequest('bal_12345', new DateTime('2024-01-01'), new DateTime('2024-01-31')); $this->assertEquals('balances/bal_12345/report', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php index e3712566..4f647da4 100644 --- a/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php +++ b/tests/Http/Requests/GetPaginatedSubscriptionPaymentsRequestTest.php @@ -5,7 +5,6 @@ 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; use Mollie\Api\Resources\LazyCollection; @@ -22,7 +21,7 @@ public function it_can_get_paginated_subscription_payments() GetPaginatedSubscriptionPaymentsRequest::class => MockResponse::ok('payment-list'), ]); - $request = new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery); + $request = new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'); /** @var PaymentCollection */ $payments = $client->send($request); @@ -48,7 +47,7 @@ public function it_can_iterate_over_subscription_payments() ), ]); - $request = (new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3', new PaginatedQuery))->useIterator(); + $request = (new GetPaginatedSubscriptionPaymentsRequest('cst_kEn1PlbGa', 'sub_rVKGtNd6s3'))->useIterator(); /** @var LazyCollection */ $payments = $client->send($request); diff --git a/tests/Http/Requests/GetSessionRequestTest.php b/tests/Http/Requests/GetSessionRequestTest.php index d24a0edc..cee9edc4 100644 --- a/tests/Http/Requests/GetSessionRequestTest.php +++ b/tests/Http/Requests/GetSessionRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,11 +17,7 @@ public function it_can_get_session() GetSessionRequest::class => MockResponse::ok('session'), ]); - $query = new AnyData([ - 'testmode' => true, - ]); - - $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + $request = new GetSessionRequest('ses_LQNz4v4Qvk'); /** @var Session */ $session = $client->send($request); @@ -34,11 +29,7 @@ public function it_can_get_session() /** @test */ public function it_resolves_correct_resource_path() { - $query = new AnyData([ - 'testmode' => true, - ]); - - $request = new GetSessionRequest('ses_LQNz4v4Qvk', $query); + $request = new GetSessionRequest('ses_LQNz4v4Qvk'); $this->assertEquals( 'sessions/ses_LQNz4v4Qvk', diff --git a/tests/Http/Requests/PaginatedRequestTest.php b/tests/Http/Requests/PaginatedRequestTest.php index d4d0307f..49c9fbb3 100644 --- a/tests/Http/Requests/PaginatedRequestTest.php +++ b/tests/Http/Requests/PaginatedRequestTest.php @@ -2,7 +2,6 @@ namespace Tests\Http\Requests; -use Mollie\Api\Contracts\Arrayable; use Mollie\Api\Http\Requests\PaginatedRequest; use Mollie\Api\Resources\BaseCollection; use PHPUnit\Framework\TestCase; @@ -14,16 +13,15 @@ public function it_can_handle_null_query() { $request = new ConcretePaginatedRequest; - $this->assertEquals([], $request->query()->all()); + $this->assertEquals([], $request->query()->resolve()->all()); } /** @test */ public function it_can_handle_query() { - $query = new ConcreteQuery(['limit' => 10]); - $request = new ConcretePaginatedRequest($query); + $request = new ConcretePaginatedRequest(null, 10); - $this->assertEquals(['limit' => 10], $request->query()->all()); + $this->assertEquals(['limit' => 10], $request->query()->resolve()->all()); } } @@ -36,18 +34,3 @@ public function resolveResourcePath(): string return 'test'; } } - -class ConcreteQuery implements Arrayable -{ - private array $parameters; - - public function __construct(array $parameters) - { - $this->parameters = $parameters; - } - - public function toArray(): array - { - return $this->parameters; - } -} diff --git a/tests/Http/Requests/UpdateCustomerRequestTest.php b/tests/Http/Requests/UpdateCustomerRequestTest.php index eb519ab7..a9917f50 100644 --- a/tests/Http/Requests/UpdateCustomerRequestTest.php +++ b/tests/Http/Requests/UpdateCustomerRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,10 +17,7 @@ public function it_can_update_customer() UpdateCustomerRequest::class => MockResponse::ok('customer'), ]); - $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( - 'Updated Customer Name', - 'updated@example.com', - )); + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', 'Updated Customer Name', 'updated@example.com'); /** @var Customer */ $customer = $client->send($request); @@ -33,10 +29,7 @@ public function it_can_update_customer() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdateCustomerRequest('cst_kEn1PlbGa', new UpdateCustomerPayload( - 'Updated Customer Name', - 'updated@example.com', - )); + $request = new UpdateCustomerRequest('cst_kEn1PlbGa', '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 index 4f2c89ba..3c54a27a 100644 --- a/tests/Http/Requests/UpdatePaymentLinkRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentLinkRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,9 +17,7 @@ public function it_can_update_payment_link() UpdatePaymentLinkRequest::class => MockResponse::ok('payment-link'), ]); - $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( - 'Updated payment link', - )); + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', 'Updated payment link'); /** @var PaymentLink */ $paymentLink = $client->send($request); @@ -32,9 +29,7 @@ public function it_can_update_payment_link() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', new UpdatePaymentLinkPayload( - 'Updated payment link', - )); + $request = new UpdatePaymentLinkRequest('pl_4Y0eZitmBnQ5jsBYZIBw', '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 index a8d88100..01aa0d46 100644 --- a/tests/Http/Requests/UpdatePaymentRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,10 +17,11 @@ public function it_can_update_payment() UpdatePaymentRequest::class => MockResponse::ok('payment'), ]); - $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + $request = new UpdatePaymentRequest( + 'tr_WDqYK6vllg', 'Updated payment description', 'https://example.com/redirect', - )); + ); /** @var Payment */ $payment = $client->send($request); @@ -33,10 +33,11 @@ public function it_can_update_payment() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdatePaymentRequest('tr_WDqYK6vllg', new UpdatePaymentPayload( + $request = new UpdatePaymentRequest( + 'tr_WDqYK6vllg', '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 index e7d969cc..7ac92e26 100644 --- a/tests/Http/Requests/UpdatePaymentRouteRequestTest.php +++ b/tests/Http/Requests/UpdatePaymentRouteRequestTest.php @@ -5,7 +5,6 @@ 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; @@ -19,9 +18,7 @@ public function it_can_update_payment_route() UpdatePaymentRouteRequest::class => MockResponse::ok('route'), ]); - $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( - new DateTime('2024-01-01'), - )); + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new DateTime('2024-01-01')); /** @var Route */ $route = $client->send($request); @@ -33,9 +30,7 @@ public function it_can_update_payment_route() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', new UpdatePaymentRoutePayload( - new DateTime('2024-01-01'), - )); + $request = new UpdatePaymentRouteRequest('tr_WDqYK6vllg', 'rt_H2wvxEyQcP', 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 index 516daf96..18ae6cc1 100644 --- a/tests/Http/Requests/UpdateProfileRequestTest.php +++ b/tests/Http/Requests/UpdateProfileRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,9 +17,7 @@ public function it_can_update_profile() UpdateProfileRequest::class => MockResponse::ok('profile'), ]); - $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( - 'Updated Profile Name', - )); + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', 'Updated Profile Name'); /** @var Profile */ $profile = $client->send($request); @@ -32,9 +29,7 @@ public function it_can_update_profile() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', new UpdateProfilePayload( - 'Updated Profile Name', - )); + $request = new UpdateProfileRequest('pfl_v9hTwCvYqw', 'Updated Profile Name'); $this->assertEquals('profiles/pfl_v9hTwCvYqw', $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php index 2fa61bf0..ce176865 100644 --- a/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php +++ b/tests/Http/Requests/UpdateSalesInvoiceRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -19,11 +18,7 @@ public function it_updates_sales_invoice() UpdateSalesInvoiceRequest::class => MockResponse::ok('sales-invoice'), ]); - $payload = new UpdateSalesInvoicePayload( - SalesInvoiceStatus::PAID, - 'XXXXX', - ); - $request = new UpdateSalesInvoiceRequest('invoice_123', $payload); + $request = new UpdateSalesInvoiceRequest('invoice_123', SalesInvoiceStatus::PAID, 'XXXXX'); /** @var SalesInvoice */ $salesInvoice = $client->send($request); @@ -35,10 +30,8 @@ public function it_updates_sales_invoice() /** @test */ public function it_resolves_correct_resource_path() { - $request = new UpdateSalesInvoiceRequest('invoice_123', new UpdateSalesInvoicePayload( - SalesInvoiceStatus::PAID, - 'XXXXX', - )); + $request = new UpdateSalesInvoiceRequest('invoice_123', SalesInvoiceStatus::PAID, 'XXXXX'); + $this->assertEquals('sales-invoices/invoice_123', $request->resolveResourcePath()); } } diff --git a/tests/Http/Requests/UpdateSessionRequestTest.php b/tests/Http/Requests/UpdateSessionRequestTest.php index 6bf9737d..a4213a97 100644 --- a/tests/Http/Requests/UpdateSessionRequestTest.php +++ b/tests/Http/Requests/UpdateSessionRequestTest.php @@ -4,7 +4,6 @@ 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; @@ -18,15 +17,15 @@ public function it_can_update_session() UpdateSessionRequest::class => MockResponse::ok('session'), ]); - $payload = new AnyData([ + $request = new UpdateSessionRequest('ses_LQNz4v4Qvk'); + + $request->payload()->set([ 'status' => 'completed', 'metadata' => [ 'order_id' => '12345', ], ]); - $request = new UpdateSessionRequest('ses_LQNz4v4Qvk', $payload); - /** @var Session */ $session = $client->send($request); @@ -39,8 +38,7 @@ public function it_can_update_session() /** @test */ public function it_resolves_correct_resource_path() { - $sessionId = 'ses_LQNz4v4Qvk'; - $request = new UpdateSessionRequest($sessionId, new AnyData); + $request = new UpdateSessionRequest($sessionId = 'ses_LQNz4v4Qvk'); $this->assertEquals("sessions/{$sessionId}", $request->resolveResourcePath()); } diff --git a/tests/Http/Requests/UpdateSubscriptionRequestTest.php b/tests/Http/Requests/UpdateSubscriptionRequestTest.php index 7d7a6257..adc5e4e7 100644 --- a/tests/Http/Requests/UpdateSubscriptionRequestTest.php +++ b/tests/Http/Requests/UpdateSubscriptionRequestTest.php @@ -5,7 +5,6 @@ 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; @@ -22,15 +21,14 @@ public function it_can_update_subscription() $customerId = 'cst_kEn1PlbGa'; $subscriptionId = 'sub_rVKGtNd6s3'; - $money = new Money('EUR', '20.00'); - $payload = new UpdateSubscriptionPayload( - $money, + $request = new UpdateSubscriptionRequest( + $customerId, + $subscriptionId, + new Money('EUR', '20.00'), 'Updated subscription', '1 month' ); - $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, $payload); - $this->assertEquals( "customers/{$customerId}/subscriptions/{$subscriptionId}", $request->resolveResourcePath() @@ -48,11 +46,13 @@ public function it_resolves_correct_resource_path() { $customerId = 'cst_kEn1PlbGa'; $subscriptionId = 'sub_rVKGtNd6s3'; - $request = new UpdateSubscriptionRequest($customerId, $subscriptionId, new UpdateSubscriptionPayload( + $request = new UpdateSubscriptionRequest( + $customerId, + $subscriptionId, new Money('EUR', '20.00'), 'Updated subscription', '1 month' - )); + ); $this->assertEquals("customers/{$customerId}/subscriptions/{$subscriptionId}", $request->resolveResourcePath()); } diff --git a/tests/MollieApiClientTest.php b/tests/MollieApiClientTest.php index 70023fac..dc061bb5 100644 --- a/tests/MollieApiClientTest.php +++ b/tests/MollieApiClientTest.php @@ -10,9 +10,7 @@ use Mollie\Api\Fake\MockMollieClient; use Mollie\Api\Fake\MockResponse; use Mollie\Api\Http\Adapter\GuzzleMollieHttpAdapter; -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\PendingRequest; use Mollie\Api\Http\Request; @@ -126,10 +124,10 @@ public function correct_request_headers() $client->setApiKey('test_foobarfoobarfoobarfoobarfoobar'); - $response = $client->send(new CreatePaymentRequest(new CreatePaymentPayload( + $response = $client->send(new CreatePaymentRequest( 'test', new Money('EUR', '100.00'), - ))); + )); $usedHeaders = $response->getPendingRequest()->headers()->all(); @@ -207,16 +205,17 @@ public static function providesMutatingRequests(): array MockResponse::noContent(), ], 'post' => [ - new CreatePaymentRequest(new CreatePaymentPayload( + new CreatePaymentRequest( 'test', new Money('EUR', '100.00'), - )), + ), MockResponse::ok('payment'), ], 'patch' => [ - new UpdatePaymentRequest('tr_payment-id', new UpdatePaymentPayload( + new UpdatePaymentRequest( + 'tr_payment-id', 'test', - )), + ), MockResponse::ok('payment'), ], ]; diff --git a/tests/Utils/ArrTest.php b/tests/Utils/ArrTest.php index 6d8af09c..a07b6dd3 100644 --- a/tests/Utils/ArrTest.php +++ b/tests/Utils/ArrTest.php @@ -4,7 +4,6 @@ use DateTimeImmutable; use Mollie\Api\Contracts\Resolvable; -use Mollie\Api\Http\Data\AnyData; use Mollie\Api\Http\Data\DataCollection; use Mollie\Api\Http\Data\Money; use Mollie\Api\Http\Data\PaymentRoute; @@ -33,6 +32,14 @@ public function pull(): void $this->assertEquals(['foo' => []], $array); } + /** @test */ + public function except(): void + { + $array = ['foo' => 'bar', 'baz' => 'qux']; + + $this->assertEquals(['foo' => 'bar'], Arr::except($array, ['baz'])); + } + /** @test */ public function forget(): void { @@ -96,11 +103,6 @@ public function includes(): void /** @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); diff --git a/tests/Utils/UtilityTest.php b/tests/Utils/UtilityTest.php index 74c2ebd6..61a322d4 100644 --- a/tests/Utils/UtilityTest.php +++ b/tests/Utils/UtilityTest.php @@ -61,10 +61,11 @@ public function filter_by_properties() /** @test */ public function compose() { - // Test with callable + // Test with primitive value and callable resolver $composedWithCallable = Utility::compose(5, fn ($x) => $x * 2); $this->assertEquals(10, $composedWithCallable); + // Test with primitive value and class resolver $composedWithClass = Utility::compose('test', TestComposable::class); $this->assertInstanceOf(TestComposable::class, $composedWithClass); $this->assertEquals('test', $composedWithClass->value); @@ -73,9 +74,27 @@ public function compose() $composedWithDefault = Utility::compose(false, fn ($x) => $x * 2, 'default'); $this->assertEquals('default', $composedWithDefault); - $existingValueIsNotOverriden = Utility::compose(new Metadata(['key' => 'value']), Metadata::class); - $this->assertInstanceOf(Metadata::class, $existingValueIsNotOverriden); + // Test with matching instance - should return as is + $metadata = new Metadata(['key' => 'value']); + $existingValueIsNotOverriden = Utility::compose($metadata, Metadata::class); + $this->assertSame($metadata, $existingValueIsNotOverriden); $this->assertEquals(['key' => 'value'], $existingValueIsNotOverriden->data); + + // Test when third argument is a non-existent class (should be treated as default) + $nonExistentClass = Utility::compose(false, fn ($x) => $x * 2, 'NonExistentClass'); + $this->assertEquals('NonExistentClass', $nonExistentClass); + + // Test with null value and default + $nullWithDefault = Utility::compose(null, TestComposable::class, 'default_value'); + $this->assertEquals('default_value', $nullWithDefault); + + // Test with empty string value + $emptyStringValue = Utility::compose('', TestComposable::class, 'default_value'); + $this->assertEquals('default_value', $emptyStringValue); + + // Test with zero value (should be considered falsy) + $zeroValue = Utility::compose(0, TestComposable::class, 'default_value'); + $this->assertEquals('default_value', $zeroValue); } /** @test */ @@ -154,3 +173,13 @@ public function __construct($value) $this->value = $value; } } + +class TestSourceClass +{ + public $value; + + public function __construct($value) + { + $this->value = $value; + } +}