From b4d4f0b143f97cfe7badaa92b5e97c5f400d6459 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Wed, 25 Oct 2023 12:30:44 +0200 Subject: [PATCH 01/10] wip --- src/Endpoints/CollectionEndpointAbstract.php | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index b11ee985..6c8e77ec 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -2,8 +2,10 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\BaseCollection; +use Mollie\Api\Resources\CursorCollection; use Mollie\Api\Resources\ResourceFactory; abstract class CollectionEndpointAbstract extends EndpointAbstract @@ -36,6 +38,35 @@ protected function rest_list($from = null, $limit = null, array $filters = []) return $collection; } + /** + * Iterate over all objects from the REST API. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $filters + * @param boolean $iterateBackwards Whether to iterate backwards or forward. + * @return Generator + */ + protected function rest_iterator($from = null, $limit = null, array $filters = [], bool $iterateBackwards = false): Generator + { + /** @var CursorCollection $page */ + $page = $this->rest_list($from, $limit, $filters); + + while (true) { + foreach ($page as $item) { + yield $item; + } + + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + break; + } + + $page = $iterateBackwards + ? $page->previous() + : $page->next(); + } + } + /** * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. * From 645a31ef6d30d5edf45e337ab33ce75a766417fd Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 26 Oct 2023 11:01:57 +0200 Subject: [PATCH 02/10] move test to right location --- .../SettlementRefundEndpointTest.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php diff --git a/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php new file mode 100644 index 00000000..261432c5 --- /dev/null +++ b/tests/Mollie/API/Endpoints/SettlementRefundEndpointTest.php @@ -0,0 +1,92 @@ +mockApiCall( + new Request( + 'GET', + '/v2/settlements/stl_jDk30akdN/refunds?limit=5&foo=bar' + ), + new Response( + 200, + [], + '{ + "_embedded": { + "refunds": [ + { + "resource": "refund", + "id": "re_3aKhkUNigy", + "amount": { + "value": "10.00", + "currency": "EUR" + }, + "status": "refunded", + "createdAt": "2018-08-30T07:59:02+00:00", + "description": "Order #33", + "paymentId": "tr_maJaG2j8OM", + "settlementAmount": { + "value": "-10.00", + "currency": "EUR" + }, + "settlementId": "stl_jDk30akdN", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM/refunds/re_3aKhkUNigy", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM", + "type": "application/hal+json" + }, + "settlement": { + "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", + "type": "application/hal+json" + } + } + }, + { } + ] + }, + "count": 1, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-refunds", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/refunds?limit=50", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + $settlement = new Settlement($this->apiClient); + $settlement->id = 'stl_jDk30akdN'; + + $refunds = $settlement->refunds(5, ['foo' => 'bar']); + + $this->assertInstanceOf(RefundCollection::class, $refunds); + $this->assertCount(2, $refunds); + + $refund = $refunds[0]; + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals("re_3aKhkUNigy", $refund->id); + } +} From f558f5f0f616ac586e8c70b45eb14dcfa62ad5a1 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 26 Oct 2023 11:57:44 +0200 Subject: [PATCH 03/10] add iterator to all cursor collection compatible endpoints --- src/Endpoints/BalanceEndpoint.php | 18 +- src/Endpoints/BalanceTransactionEndpoint.php | 46 ++++ src/Endpoints/ChargebackEndpoint.php | 18 +- src/Endpoints/ClientEndpoint.php | 18 +- src/Endpoints/CollectionEndpointAbstract.php | 25 ++- src/Endpoints/CustomerEndpoint.php | 20 +- src/Endpoints/CustomerPaymentsEndpoint.php | 39 +++- src/Endpoints/InvoiceEndpoint.php | 16 ++ src/Endpoints/MandateEndpoint.php | 35 +++ src/Endpoints/OrderEndpoint.php | 22 +- src/Endpoints/PaymentCaptureEndpoint.php | 35 +++ src/Endpoints/PaymentChargebackEndpoint.php | 35 +++ src/Endpoints/PaymentEndpoint.php | 20 +- src/Endpoints/PaymentLinkEndpoint.php | 18 +- src/Endpoints/PaymentRefundEndpoint.php | 35 +++ src/Endpoints/ProfileEndpoint.php | 18 +- src/Endpoints/RefundEndpoint.php | 16 ++ src/Endpoints/SettlementCaptureEndpoint.php | 19 ++ .../SettlementChargebackEndpoint.php | 19 ++ src/Endpoints/SettlementPaymentEndpoint.php | 19 ++ src/Endpoints/SettlementRefundEndpoint.php | 19 ++ src/Endpoints/SettlementsEndpoint.php | 16 ++ src/Endpoints/ShipmentEndpoint.php | 2 +- src/Endpoints/SubscriptionEndpoint.php | 54 ++++- src/Endpoints/TerminalEndpoint.php | 16 ++ .../API/Endpoints/BalanceEndpointTest.php | 113 ++++++++++ .../BalanceTransactionEndpointTest.php | 158 ++++++++++++++ .../API/Endpoints/ChargebackEndpointTest.php | 98 +++++++++ .../API/Endpoints/CustomerEndpointTest.php | 47 ++++ .../Endpoints/CustomerPaymentEndpointTest.php | 14 +- .../API/Endpoints/InvoiceEndpointTest.php | 98 +++++++++ .../API/Endpoints/OrderEndpointTest.php | 115 ++++++---- .../API/Endpoints/PaymentEndpointTest.php | 167 ++++++++++++-- .../API/Endpoints/RefundEndpointTest.php | 66 ++++++ .../API/Endpoints/SettlementEndpointTest.php | 205 ++++++++++++++++++ .../API/Endpoints/TerminalEndpointTest.php | 109 ++++++++++ tests/SettlementRefundEndpointTest.php | 91 -------- 37 files changed, 1705 insertions(+), 174 deletions(-) delete mode 100644 tests/SettlementRefundEndpointTest.php diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index b1a9d69a..a0582c8b 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceCollection; @@ -45,7 +46,7 @@ protected function getResourceObject() public function get(string $balanceId, array $parameters = []) { if (empty($balanceId) || strpos($balanceId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid balance ID: '{$balanceId}'. A balance ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid balance ID: '{$balanceId}'. A balance ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_read($balanceId, $parameters); @@ -79,4 +80,19 @@ public function page(?string $from = null, ?int $limit = null, array $parameters { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over balances retrieved from Mollie. + * + * @param string $from The first Balance ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index ed0cbb09..5dcec331 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -4,6 +4,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Balance; use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; @@ -50,6 +51,20 @@ public function listFor(Balance $balance, array $parameters = []) return $this->listForId($balance->id, $parameters); } + /** + * Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie. + * + * @param Balance $balance + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($balance->id, $parameters, $iterateBackwards); + } + /** * List the transactions for a specific Balance ID. * @@ -66,6 +81,22 @@ public function listForId(string $balanceId, array $parameters = []) return parent::rest_list(null, null, $parameters); } + /** + * Create an iterator for iterating over balance transactions for the given balance id retrieved from Mollie. + * + * @param string $balanceId + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $balanceId, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $balanceId; + + return $this->rest_iterator(null, null, $parameters, $iterateBackwards); + } + /** * List the transactions for the primary Balance. * @@ -80,4 +111,19 @@ public function listForPrimary(array $parameters = []) return parent::rest_list(null, null, $parameters); } + + /** + * Create an iterator for iterating over transactions for the primary balance retrieved from Mollie. + * + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForPrimary(array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = "primary"; + + return $this->rest_iterator(null, null, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index dd5045ab..68efd372 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -43,8 +44,23 @@ protected function getResourceCollectionObject($count, $_links) * @return ChargebackCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over chargeback retrieved from Mollie. + * + * @param string $from The first chargevback ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 86891785..5e3efb94 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Client; use Mollie\Api\Resources\ClientCollection; @@ -62,8 +63,23 @@ public function get($clientId, array $parameters = []) * @return ClientCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over clients retrieved from Mollie. + * + * @param string $from The first client ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index 6c8e77ec..c36f54bc 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -20,7 +20,7 @@ abstract class CollectionEndpointAbstract extends EndpointAbstract * @return mixed * @throws ApiException */ - protected function rest_list($from = null, $limit = null, array $filters = []) + protected function rest_list(?string $from = null, ?int $limit = null, array $filters = []) { $filters = array_merge(["from" => $from, "limit" => $limit], $filters); @@ -39,19 +39,36 @@ protected function rest_list($from = null, $limit = null, array $filters = []) } /** - * Iterate over all objects from the REST API. + * Create a generator for iterating over a resource's collection using REST API calls. + * + * This function fetches paginated data from a RESTful resource endpoint and returns a generator + * that allows you to iterate through the items in the collection one by one. It supports forward + * and backward iteration, pagination, and filtering. * * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $filters - * @param boolean $iterateBackwards Whether to iterate backwards or forward. + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). * @return Generator */ - protected function rest_iterator($from = null, $limit = null, array $filters = [], bool $iterateBackwards = false): Generator + protected function rest_iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): Generator { /** @var CursorCollection $page */ $page = $this->rest_list($from, $limit, $filters); + return $this->iterate($page, $iterateBackwards); + } + + /** + * Iterate over a CursorCollection and yield its elements. + * + * @param CursorCollection $page + * @param boolean $iterateBackwards + * + * @return Generator + */ + protected function iterate(CursorCollection $page, bool $iterateBackwards = false): Generator + { while (true) { foreach ($page as $item) { yield $item; diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index ae04d8f4..5e48a1b4 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\CustomerCollection; @@ -81,7 +82,7 @@ public function get($customerId, array $parameters = []) public function update($customerId, array $data = []) { if (empty($customerId) || strpos($customerId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$customerId}'. An order ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid order ID: '{$customerId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_update($customerId, $data); @@ -114,8 +115,23 @@ public function delete($customerId, array $data = []) * @return CustomerCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over customers retrieved from Mollie. + * + * @param string $from The first customer ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index 3961ea6f..ea231b88 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; @@ -74,11 +75,27 @@ public function createForId($customerId, array $options = [], array $filters = [ * @return PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = []) + public function listFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = []) { return $this->listForId($customer->id, $from, $limit, $parameters); } + /** + * Create an iterator for iterating over payments for the given customer, retrieved from Mollie. + * + * @param Customer $customer + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $customerId * @param string $from The first resource ID you want to include in your list. @@ -88,10 +105,28 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ * @return \Mollie\Api\Resources\PaymentCollection * @throws \Mollie\Api\Exceptions\ApiException */ - public function listForId($customerId, $from = null, $limit = null, array $parameters = []) + public function listForId($customerId, ?string $from = null, ?int $limit = null, array $parameters = []) { $this->parentId = $customerId; return parent::rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over payments for the given customer id, retrieved from Mollie. + * + * @param string $customerId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $customerId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index a228fd28..afd7750d 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Invoice; use Mollie\Api\Resources\InvoiceCollection; @@ -76,4 +77,19 @@ public function all(array $parameters = []) { return $this->page(null, null, $parameters); } + + /** + * Create an iterator for iterating over invoices retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index 046eaf2e..160f4b74 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\Mandate; use Mollie\Api\Resources\MandateCollection; @@ -103,6 +104,22 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ return $this->listForId($customer->id, $from, $limit, $parameters); } + /** + * Create an iterator for iterating over mandates for the given customer, retrieved from Mollie. + * + * @param Customer $customer + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $customerId * @param null $from @@ -119,6 +136,24 @@ public function listForId($customerId, $from = null, $limit = null, array $param return parent::rest_list($from, $limit, $parameters); } + /** + * Create an iterator for iterating over mandates for the given customer id, retrieved from Mollie. + * + * @param string $customerId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $customerId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } + /** * @param Customer $customer * @param string $mandateId diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 605544a3..102b44ea 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Order; use Mollie\Api\Resources\OrderCollection; @@ -68,7 +69,7 @@ public function create(array $data = [], array $filters = []) public function update($orderId, array $data = []) { if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_update($orderId, $data); @@ -87,7 +88,7 @@ public function update($orderId, array $data = []) public function get($orderId, array $parameters = []) { if (empty($orderId) || strpos($orderId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid order ID: '{$orderId}'. An order ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_read($orderId, $parameters); @@ -123,8 +124,23 @@ public function cancel($orderId, $parameters = []) * @return OrderCollection * @throws ApiException */ - public function page($from = null, $limit = null, array $parameters = []) + public function page(?string $from = null, ?int $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over orders retrieved from Mollie. + * + * @param string $from The first order ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index 6766235a..d7bd6f4e 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; use Mollie\Api\Resources\Payment; @@ -105,6 +106,22 @@ public function listFor(Payment $payment, array $parameters = []) return $this->listForId($payment->id, $parameters); } + /** + * Create an iterator for iterating over captures for the given payment, retrieved from Mollie. + * + * @param Payment $payment + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $paymentId * @param array $parameters @@ -118,4 +135,22 @@ public function listForId($paymentId, array $parameters = []) return parent::rest_list(null, null, $parameters); } + + /** + * Create an iterator for iterating over captures for the given payment id, retrieved from Mollie. + * + * @param string $paymentId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $paymentId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index e27ddeb5..e2f1d33a 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; use Mollie\Api\Resources\Payment; @@ -73,6 +74,22 @@ public function listFor(Payment $payment, array $parameters = []) return $this->listForId($payment->id, $parameters); } + /** + * Create an iterator for iterating over chargebacks for the given payment, retrieved from Mollie. + * + * @param Payment $payment + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $paymentId * @param array $parameters @@ -86,4 +103,22 @@ public function listForId($paymentId, array $parameters = []) return parent::rest_list(null, null, $parameters); } + + /** + * Create an iterator for iterating over chargebacks for the given payment id, retrieved from Mollie. + * + * @param string $paymentId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $paymentId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index a840863e..a68032cc 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; @@ -66,7 +67,7 @@ public function create(array $data = [], array $filters = []) public function update($paymentId, array $data = []) { if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_update($paymentId, $data); @@ -85,7 +86,7 @@ public function update($paymentId, array $data = []) public function get($paymentId, array $parameters = []) { if (empty($paymentId) || strpos($paymentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid payment ID: '{$paymentId}'. A payment ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_read($paymentId, $parameters); @@ -140,6 +141,21 @@ public function page($from = null, $limit = null, array $parameters = []) return $this->rest_list($from, $limit, $parameters); } + /** + * Create an iterator for iterating over payments retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } + /** * Issue a refund for the given payment. * diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index 8f3f3bef..6e98c053 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentLink; @@ -64,7 +65,7 @@ public function create(array $data = [], array $filters = []) public function get($paymentLinkId, array $parameters = []) { if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid payment link ID: '{$paymentLinkId}'. A payment link ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid payment link ID: '{$paymentLinkId}'. A payment link ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_read($paymentLinkId, $parameters); @@ -84,4 +85,19 @@ public function page($from = null, $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over payment links retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 3dfa2469..28c2ee36 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; @@ -73,6 +74,22 @@ public function listFor(Payment $payment, array $parameters = []) return $this->listForId($payment->id, $parameters); } + /** + * Create an iterator for iterating over refunds for the given payment, retrieved from Mollie. + * + * @param Payment $payment + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $paymentId * @param array $parameters @@ -87,6 +104,24 @@ public function listForId($paymentId, array $parameters = []) return parent::rest_list(null, null, $parameters); } + /** + * Create an iterator for iterating over refunds for the given payment id, retrieved from Mollie. + * + * @param string $paymentId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $paymentId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } + /** * Creates a refund for a specific payment. diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index 498d442a..07647743 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\CurrentProfile; use Mollie\Api\Resources\Profile; @@ -88,7 +89,7 @@ public function get($profileId, array $parameters = []) public function update($profileId, array $data = []) { if (empty($profileId) || strpos($profileId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid profile id: '{$profileId}'. An profile id should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid profile id: '{$profileId}'. An profile id should start with '" . self::RESOURCE_ID_PREFIX . "'."); } return parent::rest_update($profileId, $data); @@ -140,4 +141,19 @@ public function page($from = null, $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over profiles retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 385e21c0..616f15af 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; @@ -47,4 +48,19 @@ public function page($from = null, $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over refunds retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 0c46d330..4c08136a 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -4,6 +4,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Capture; use Mollie\Api\Resources\CaptureCollection; @@ -41,4 +42,22 @@ public function pageForId(string $settlementId, string $from = null, int $limit return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over captures for the given settlement id, retrieved from Mollie. + * + * @param string $settlementId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $settlementId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 850d0256..2992c322 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -4,6 +4,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Chargeback; use Mollie\Api\Resources\ChargebackCollection; @@ -44,4 +45,22 @@ public function pageForId(string $settlementId, string $from = null, int $limit return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over chargeback for the given settlement id, retrieved from Mollie. + * + * @param string $settlementId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $settlementId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index 6ac8304e..9766bd1d 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Payment; use Mollie\Api\Resources\PaymentCollection; @@ -42,4 +43,22 @@ public function pageForId($settlementId, $from = null, $limit = null, array $par return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over payments for the given settlement id, retrieved from Mollie. + * + * @param string $settlementId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $settlementId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 31e9c1d1..4984fe23 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -4,6 +4,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Resources\Refund; use Mollie\Api\Resources\RefundCollection; @@ -44,4 +45,22 @@ public function pageForId(string $settlementId, string $from = null, int $limit return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over refunds for the given settlement id, retrieved from Mollie. + * + * @param string $settlementId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $settlementId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index a4d49e85..6fc4c570 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Settlement; use Mollie\Api\Resources\SettlementCollection; @@ -84,4 +85,19 @@ public function page($from = null, $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over settlements retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/src/Endpoints/ShipmentEndpoint.php b/src/Endpoints/ShipmentEndpoint.php index 6456ab7c..c62bcb36 100644 --- a/src/Endpoints/ShipmentEndpoint.php +++ b/src/Endpoints/ShipmentEndpoint.php @@ -121,7 +121,7 @@ public function getForId($orderId, $shipmentId, array $parameters = []) public function update($orderId, $shipmentId, array $data = []) { if (empty($shipmentId) || strpos($shipmentId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid subscription ID: '{$shipmentId}'. An subscription ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid subscription ID: '{$shipmentId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } $this->parentId = $orderId; diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index d9b919af..b0975049 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Customer; use Mollie\Api\Resources\ResourceFactory; @@ -88,7 +89,7 @@ public function createForId($customerId, array $options = [], array $filters = [ public function update($customerId, $subscriptionId, array $data = []) { if (empty($subscriptionId) || strpos($subscriptionId, self::RESOURCE_ID_PREFIX) !== 0) { - throw new ApiException("Invalid subscription ID: '{$subscriptionId}'. An subscription ID should start with '".self::RESOURCE_ID_PREFIX."'."); + throw new ApiException("Invalid subscription ID: '{$subscriptionId}'. An subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); } $this->parentId = $customerId; @@ -138,6 +139,22 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ return $this->listForId($customer->id, $from, $limit, $parameters); } + /** + * Create an iterator for iterating over subscriptions for the given customer, retrieved from Mollie. + * + * @param Customer $customer + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards); + } + /** * @param string $customerId * @param string $from The first resource ID you want to include in your list. @@ -154,6 +171,24 @@ public function listForId($customerId, $from = null, $limit = null, array $param return parent::rest_list($from, $limit, $parameters); } + /** + * Create an iterator for iterating over subscriptions for the given customer id, retrieved from Mollie. + * + * @param string $customerId + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $this->parentId = $customerId; + + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } + /** * @param Customer $customer * @param string $subscriptionId @@ -209,4 +244,21 @@ public function page($from = null, $limit = null, array $parameters = []) return $collection; } + + /** + * Create an iterator for iterating over subscriptions retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + $page = $this->page($from, $limit, $parameters); + + return $this->iterate($page, $iterateBackwards); + } } diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 4b100b56..9b1d90a3 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Endpoints; +use Generator; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Terminal; use Mollie\Api\Resources\TerminalCollection; @@ -69,4 +70,19 @@ public function page($from = null, $limit = null, array $parameters = []) { return $this->rest_list($from, $limit, $parameters); } + + /** + * Create an iterator for iterating over terminals retrieved from Mollie. + * + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param array $parameters + * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return Generator + */ + public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): Generator + { + return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards); + } } diff --git a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php index 5f1a2ad8..c2b14129 100644 --- a/tests/Mollie/API/Endpoints/BalanceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceEndpointTest.php @@ -187,6 +187,119 @@ public function testListBalances() ); } + public function testIterateBalances() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/balances" + ), + new Response( + 200, + [], + '{ + "count": 2, + "_embedded": { + "balances": [ + { + "resource": "balance", + "id": "bal_gVMhHKqSSRYJyPsuoPNFH", + "mode": "live", + "createdAt": "2019-01-10T12:06:28+00:00", + "currency": "EUR", + "status": "active", + "availableAmount": { + "value": "0.00", + "currency": "EUR" + }, + "incomingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "outgoingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "transferFrequency": "daily", + "transferThreshold": { + "value": "40.00", + "currency": "EUR" + }, + "transferReference": "Mollie payout", + "transferDestination": { + "type": "bank-account", + "beneficiaryName": "Jack Bauer", + "bankAccount": "NL53INGB0654422370", + "bankAccountId": "bnk_jrty3f" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", + "type": "application/hal+json" + } + } + }, + { + "resource": "balance", + "id": "bal_gVMhHKqSSRYJyPsuoPABC", + "mode": "live", + "createdAt": "2019-01-10T10:23:41+00:00", + "status": "active", + "currency": "EUR", + "availableAmount": { + "value": "0.00", + "currency": "EUR" + }, + "incomingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "outgoingAmount": { + "value": "0.00", + "currency": "EUR" + }, + "transferFrequency": "twice-a-month", + "transferThreshold": { + "value": "5.00", + "currency": "EUR" + }, + "transferReference": "Mollie payout", + "transferDestination": { + "type": "bank-account", + "beneficiaryName": "Jack Bauer", + "bankAccount": "NL97MOLL6351480700", + "bankAccountId": "bnk_jrty3e" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPABC", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/balances?limit=5", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + foreach ($this->apiClient->balances->iterator() as $balance) { + $this->assertInstanceOf(Balance::class, $balance); + } + } + public function testGetBalance() { $this->mockApiCall( diff --git a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php index 6e9aefe0..55237ae8 100644 --- a/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php +++ b/tests/Mollie/API/Endpoints/BalanceTransactionEndpointTest.php @@ -7,6 +7,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Mollie\Api\Resources\Balance; +use Mollie\Api\Resources\BalanceTransaction; use Mollie\Api\Resources\BalanceTransactionCollection; use Mollie\Api\Resources\BaseCollection; use Tests\Mollie\TestHelpers\AmountObjectTestHelpers; @@ -97,6 +98,86 @@ public function testGetBalanceTransactionsThroughEndpoint() $this->assertTransactions($transactions); } + public function testIteratorForBalanceTransactionsThroughEndpoint() + { + $this->mockApiCall( + new Request("GET", "/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions"), + new Response( + 200, + [], + '{ + "count": 2, + "_embedded": { + "balance_transactions": [ + { + "resource": "balance_transaction", + "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", + "type": "refund", + "resultAmount": { + "value": "-10.25", + "currency": "EUR" + }, + "initialAmount": { + "value": "-10.00", + "currency": "EUR" + }, + "deductions": { + "value": "-0.25", + "currency": "EUR" + }, + "createdAt": "2021-01-10T12:06:28+00:00", + "context": { + "paymentId": "tr_7UhSN1zuXS", + "refundId": "re_4qqhO89gsT" + } + }, + { + "resource": "balance_transaction", + "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", + "type": "payment", + "resultAmount": { + "value": "9.71", + "currency": "EUR" + }, + "initialAmount": { + "value": "10.00", + "currency": "EUR" + }, + "deductions": { + "value": "-0.29", + "currency": "EUR" + }, + "createdAt": "2021-01-10T12:06:28+00:00", + "context": { + "paymentId": "tr_7UhSN1zuXS" + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + $balance = new Balance($this->apiClient); + $balance->id = "bal_gVMhHKqSSRYJyPsuoPNFH"; + + foreach ($this->apiClient->balanceTransactions->iteratorFor($balance) as $balanceTransactions) { + $this->assertInstanceOf(BalanceTransaction::class, $balanceTransactions); + } + } + public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() { $this->mockApiCall( @@ -174,6 +255,83 @@ public function testGetPrimaryBalanceTransactionsThroughBalanceTransactionEndpoi $this->assertTransactions($transactions); } + public function testIteratorForPrimaryBalanceTransactionsThroughBalanceTransactionEndpoint() + { + $this->mockApiCall( + new Request("GET", "/v2/balances/primary/transactions"), + new Response( + 200, + [], + '{ + "count": 2, + "_embedded": { + "balance_transactions": [ + { + "resource": "balance_transaction", + "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", + "type": "refund", + "resultAmount": { + "value": "-10.25", + "currency": "EUR" + }, + "initialAmount": { + "value": "-10.00", + "currency": "EUR" + }, + "deductions": { + "value": "-0.25", + "currency": "EUR" + }, + "createdAt": "2021-01-10T12:06:28+00:00", + "context": { + "paymentId": "tr_7UhSN1zuXS", + "refundId": "re_4qqhO89gsT" + } + }, + { + "resource": "balance_transaction", + "id": "baltr_QM24QwzUWR4ev4Xfgyt29B", + "type": "payment", + "resultAmount": { + "value": "9.71", + "currency": "EUR" + }, + "initialAmount": { + "value": "10.00", + "currency": "EUR" + }, + "deductions": { + "value": "-0.29", + "currency": "EUR" + }, + "createdAt": "2021-01-10T12:06:28+00:00", + "context": { + "paymentId": "tr_7UhSN1zuXS" + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/balances-api/list-balance-transactions", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?limit=5", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + foreach ($this->apiClient->balanceTransactions->iteratorForPrimary() as $balanceTransactions) { + $this->assertInstanceOf(BalanceTransaction::class, $balanceTransactions); + } + } + private function assertTransactions(BaseCollection $transactions) { $this->assertInstanceOf(BalanceTransactionCollection::class, $transactions); diff --git a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php index 38ad17ef..44fb3b56 100644 --- a/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php +++ b/tests/Mollie/API/Endpoints/ChargebackEndpointTest.php @@ -129,6 +129,104 @@ public function testListChargebacks() $this->assertChargeback($chargebacks[1], 'tr_nQKWJbDj7j', 'chb_6cqlwf', "-0.37", null); } + public function testIterateChargebacks() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/chargebacks" + ), + new Response( + 200, + [], + '{ + "_embedded":{ + "chargebacks":[ + { + "resource":"chargeback", + "id":"chb_n9z0tp", + "amount":{ + "value":"-13.00", + "currency":"EUR" + }, + "createdAt":"2018-03-28T11:44:32+00:00", + "paymentId":"tr_44aKxzEbr8", + "settlementAmount":{ + "value":"-13.00", + "currency":"EUR" + }, + "reversedAt": null, + "reason":{ + "code":"AC01", + "description":"" + }, + "_links":{ + "self":{ + "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8/chargebacks/chb_n9z0tp", + "type":"application/hal+json" + }, + "payment":{ + "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", + "type":"application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", + "type": "text/html" + } + } + }, + { + "resource":"chargeback", + "id":"chb_6cqlwf", + "amount":{ + "value":"-0.37", + "currency":"EUR" + }, + "createdAt":"2018-03-28T11:44:32+00:00", + "paymentId":"tr_nQKWJbDj7j", + "settlementAmount":{ + "value":"-0.37", + "currency":"EUR" + }, + "reversedAt": null, + "reason": null, + "_links":{ + "self":{ + "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j/chargebacks/chb_6cqlwf", + "type":"application/hal+json" + }, + "payment":{ + "href":"https://api.mollie.com/v2/payments/tr_nQKWJbDj7j", + "type":"application/hal+json" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback", + "type": "text/html" + } + } + } + ] + }, + "_links":{ + "documentation":{ + "href":"https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks", + "type":"text/html" + }, + "self":{ + "href":"https://api.mollie.com/v2/chargebacks", + "type":"application/hal+json" + } + }, + "count": 2 + }' + ) + ); + + foreach ($this->apiClient->chargebacks->iterator() as $chargeback) { + $this->assertInstanceOf(Chargeback::class, $chargeback); + } + } + protected function assertChargeback($chargeback, $paymentId, $chargebackId, $amount, $reasonCode) { $this->assertInstanceOf(Chargeback::class, $chargeback); diff --git a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php index e3a5eae3..20e939ba 100644 --- a/tests/Mollie/API/Endpoints/CustomerEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerEndpointTest.php @@ -157,6 +157,53 @@ public function testListWorks() } } + public function testIteratorWorks() + { + $this->mockApiCall( + new Request('GET', '/v2/customers'), + new Response( + 200, + [], + '{ + "_embedded": { + "customers": [ + { + "resource": "customer", + "id": "cst_FhQJRw4s2n", + "mode": "test", + "name": "John Doe", + "email": "johndoe@example.org", + "locale": null, + "metadata": null, + "recentlyUsedMethods": [], + "createdAt": "2018-04-19T08:49:01+00:00" + } + ] + }, + "count": 1, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/customers-api/list-customers", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.com/v2/customers?limit=50", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + foreach ($this->apiClient->customers->iterator() as $customer) { + $this->assertInstanceOf(Customer::class, $customer); + $this->assertEquals("customer", $customer->resource); + $this->assertNotEmpty($customer->createdAt); + } + } + public function testUpdateWorks() { $expectedName = 'Kaas Broodje'; diff --git a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php index 2dcb1d75..2de0d4b7 100644 --- a/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/CustomerPaymentEndpointTest.php @@ -21,7 +21,7 @@ public function testCreateCustomerPayment() "/v2/customers/cst_FhQJRw4s2n/payments", [], '{ - "amount":{ + "amount":{ "value":"20.00", "currency":"EUR" }, @@ -41,13 +41,13 @@ public function testCreateCustomerPayment() "id":"tr_44aKxzEbr8", "mode":"test", "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ + "amount":{ "value":"20.00", "currency":"EUR" }, "description":"My first API payment", "method":null, - "metadata":{ + "metadata":{ "order_id":"1234" }, "status":"open", @@ -58,12 +58,12 @@ public function testCreateCustomerPayment() "sequenceType":"oneoff", "redirectUrl":"https://example.org/redirect", "webhookUrl":"https://example.org/webhook", - "_links":{ - "self":{ + "_links":{ + "self":{ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type":"application/hal+json" }, - "checkout":{ + "checkout":{ "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type":"text/html" }, @@ -71,7 +71,7 @@ public function testCreateCustomerPayment() "href": "https://api.mollie.com/v2/customers/cst_FhQJRw4s2n", "type": "application/hal+json" }, - "documentation":{ + "documentation":{ "href":"https://docs.mollie.com/reference/v2/customers-api/create-payment", "type":"text/html" } diff --git a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php index cc25b24f..3e251fd4 100644 --- a/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php +++ b/tests/Mollie/API/Endpoints/InvoiceEndpointTest.php @@ -218,4 +218,102 @@ public function testListInvoices() $this->assertNotEmpty($invoice->lines); } } + + public function testIterateInvoices() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/invoices", + [], + '' + ), + new Response( + 200, + [], + '{ + "_embedded": { + "invoices": [ + { + "resource": "invoice", + "id": "inv_bsa6PvAwaK", + "reference": "2018.190241", + "vatNumber": "123456789B01", + "status": "paid", + "issuedAt": "2018-05-02", + "paidAt": "2018-05-02", + "netAmount": { + "value": "100.00", + "currency": "EUR" + }, + "vatAmount": { + "value": "0.00", + "currency": "EUR" + }, + "grossAmount": { + "value": "100.00", + "currency": "EUR" + }, + "lines": [ + { + "period": "2018-04", + "description": "iDEAL transaction costs: april 2018", + "count": 1337, + "vatPercentage": 0, + "amount": { + "value": "50.00", + "currency": "EUR" + } + }, + { + "period": "2018-04", + "description": "Refunds iDEAL: april 2018", + "count": 1337, + "vatPercentage": 0, + "amount": { + "value": "50.00", + "currency": "EUR" + } + } + ], + "_links": { + "self": { + "href": "https://api.mollie.com/v2/invoices/inv_bsa6PvAwaK", + "type": "application/hal+json" + }, + "pdf": { + "href": "https://www.mollie.com/merchant/download/invoice/bsa6PvAwaK/79aa10f49132b7844c0243648ade6985", + "type": "application/pdf" + }, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/invoices-api/get-invoice", + "type": "text/html" + } + } + } + ] + }, + "count": 1, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/invoices-api/list-invoices", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.nl/v2/invoices?limit=50", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + foreach ($this->apiClient->invoices->iterator() as $invoice) { + $this->assertInstanceOf(Invoice::class, $invoice); + $this->assertEquals("invoice", $invoice->resource); + $this->assertNotEmpty($invoice->lines); + } + } } diff --git a/tests/Mollie/API/Endpoints/OrderEndpointTest.php b/tests/Mollie/API/Endpoints/OrderEndpointTest.php index a1985a63..998d7f28 100644 --- a/tests/Mollie/API/Endpoints/OrderEndpointTest.php +++ b/tests/Mollie/API/Endpoints/OrderEndpointTest.php @@ -122,32 +122,32 @@ public function testCreateOrder() $order = $this->apiClient->orders->create([ "amount" => [ - "value" => "1027.99", - "currency" => "EUR", + "value" => "1027.99", + "currency" => "EUR", ], "billingAddress" => [ - "organizationName" => "Organization Name LTD.", - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", + "organizationName" => "Organization Name LTD.", + "streetAndNumber" => "Keizersgracht 313", + "postalCode" => "1016 EE", + "city" => "Amsterdam", + "country" => "nl", + "givenName" => "Luke", + "familyName" => "Skywalker", + "email" => "luke@skywalker.com", ], "shippingAddress" => [ - "organizationName" => "Organization Name LTD.", - "streetAndNumber" => "Keizersgracht 313", - "postalCode" => "1016 EE", - "city" => "Amsterdam", - "country" => "nl", - "givenName" => "Luke", - "familyName" => "Skywalker", - "email" => "luke@skywalker.com", + "organizationName" => "Organization Name LTD.", + "streetAndNumber" => "Keizersgracht 313", + "postalCode" => "1016 EE", + "city" => "Amsterdam", + "country" => "nl", + "givenName" => "Luke", + "familyName" => "Skywalker", + "email" => "luke@skywalker.com", ], "metadata" => [ - "order_id" => "1337", - "description" => "Lego cars", + "order_id" => "1337", + "description" => "Lego cars", ], "consumerDateOfBirth" => "1958-01-31", "locale" => "nl_NL", @@ -569,6 +569,43 @@ public function testListOrders() $this->assertOrder($orders[2], 'ord_pbjz3z'); } + public function testIterateOrders() + { + $this->mockApiCall( + new Request("GET", "/v2/orders"), + new Response( + 200, + [], + '{ + "count": 3, + "_embedded": { + "orders": [ + ' . $this->getOrderResponseFixture("ord_pbjz1x") . ', + ' . $this->getOrderResponseFixture("ord_pbjz2y") . ', + ' . $this->getOrderResponseFixture("ord_pbjz3z") . ' + ] + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/orders", + "type": "application/hal+json" + }, + "previous": null, + "next": null, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/orders-api/list-orders", + "type": "text/html" + } + } + }' + ) + ); + + foreach ($this->apiClient->orders->iterator() as $order) { + $this->assertInstanceOf(Order::class, $order); + } + } + public function testCancelOrderDirectly() { $this->mockApiCall( @@ -780,10 +817,10 @@ public function testUpdateOrderLine() $orderLine->sku = '5702016116977'; $orderLine->quantity = 2; $orderLine->vatRate = '21.00'; - $orderLine->unitPrice = (object) ['currency' => 'EUR','value' => '349.00']; - $orderLine->totalAmount = (object) ['currency' => 'EUR','value' => '598.00']; - $orderLine->discountAmount = (object) ['currency' => 'EUR','value' => '100.00']; - $orderLine->vatAmount = (object) ['currency' => 'EUR','value' => '103.79']; + $orderLine->unitPrice = (object) ['currency' => 'EUR', 'value' => '349.00']; + $orderLine->totalAmount = (object) ['currency' => 'EUR', 'value' => '598.00']; + $orderLine->discountAmount = (object) ['currency' => 'EUR', 'value' => '100.00']; + $orderLine->vatAmount = (object) ['currency' => 'EUR', 'value' => '103.79']; $orderLine->metadata = (object) ['foo' => 'bar']; $result = $orderLine->update(); @@ -807,8 +844,8 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::S $this->assertAmountObject('0.00', 'EUR', $order->amountRefunded); $this->assertEquals((object) [ - 'order_id' => '1337', - 'description' => 'Lego cars', + 'order_id' => '1337', + 'description' => 'Lego cars', ], $order->metadata); $this->assertEquals($order_status, $order->status); @@ -841,19 +878,19 @@ protected function assertOrder($order, $order_id, $order_status = OrderStatus::S $this->assertEquals("https://example.org/redirect", $order->redirectUrl); $this->assertEquals("https://example.org/webhook", $order->webhookUrl); - $links = (object )[ - 'self' => $this->createLinkObject( - 'https://api.mollie.com/v2/orders/' . $order_id, - 'application/hal+json' - ), - 'checkout' => $this->createLinkObject( - 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', - 'text/html' - ), - 'documentation' => $this->createLinkObject( - 'https://docs.mollie.com/reference/v2/orders-api/get-order', - 'text/html' - ), + $links = (object)[ + 'self' => $this->createLinkObject( + 'https://api.mollie.com/v2/orders/' . $order_id, + 'application/hal+json' + ), + 'checkout' => $this->createLinkObject( + 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', + 'text/html' + ), + 'documentation' => $this->createLinkObject( + 'https://docs.mollie.com/reference/v2/orders-api/get-order', + 'text/html' + ), ]; $this->assertEquals($links, $order->_links); diff --git a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php index fca9112a..f742501d 100644 --- a/tests/Mollie/API/Endpoints/PaymentEndpointTest.php +++ b/tests/Mollie/API/Endpoints/PaymentEndpointTest.php @@ -23,7 +23,7 @@ public function testCreatePayment() "/v2/payments", [], '{ - "amount":{ + "amount":{ "value":"20.00", "currency":"EUR" }, @@ -43,13 +43,13 @@ public function testCreatePayment() "id":"tr_44aKxzEbr8", "mode":"test", "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ + "amount":{ "value":"20.00", "currency":"EUR" }, "description":"My first API payment", "method":null, - "metadata":{ + "metadata":{ "order_id":"1234" }, "status":"open", @@ -60,16 +60,16 @@ public function testCreatePayment() "sequenceType":"oneoff", "redirectUrl":"https://example.org/redirect", "webhookUrl":"https://example.org/webhook", - "_links":{ - "self":{ + "_links":{ + "self":{ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type":"application/hal+json" }, - "checkout":{ + "checkout":{ "href":"https://www.mollie.com/payscreen/select-method/44aKxzEbr8", "type":"text/html" }, - "documentation":{ + "documentation":{ "href":"https://docs.mollie.com/reference/v2/payments-api/create-payment", "type":"text/html" } @@ -246,31 +246,31 @@ public function testGetPayment() new Response( 200, [], - '{ + '{ "resource":"payment", "id":"tr_44aKxzEbr8", "mode":"test", "createdAt":"2018-03-13T14:02:29+00:00", - "amount":{ + "amount":{ "value":"20.00", "currency":"EUR" }, "description":"My first API payment", "method":"ideal", - "metadata":{ + "metadata":{ "order_id":"1234" }, "status":"paid", "paidAt":"2018-03-19T12:18:35+00:00", - "amountRefunded":{ + "amountRefunded":{ "value":"0.00", "currency":"EUR" }, - "amountRemaining":{ + "amountRemaining":{ "value":"20.00", "currency":"EUR" }, - "details":{ + "details":{ "consumerName":"T. TEST", "consumerAccount":"NL17RABO0213698412", "consumerBic":"TESTNL99" @@ -281,16 +281,16 @@ public function testGetPayment() "sequenceType":"oneoff", "redirectUrl":"https://example.org/redirect", "webhookUrl":"https://example.org/webhook", - "settlementAmount":{ + "settlementAmount":{ "value":"20.00", "currency":"EUR" }, - "_links":{ - "self":{ + "_links":{ + "self":{ "href":"https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type":"application/hal+json" }, - "documentation":{ + "documentation":{ "href":"https://docs.mollie.com/reference/v2/payments-api/get-payment", "type":"text/html" } @@ -492,4 +492,137 @@ public function testListPayment() $nextLink = (object)["href" => "http://api.mollie.com/v2/payments?from=tr_eW8f5kzUkF&limit=3", "type" => "application/hal+json"]; $this->assertEquals($nextLink, $payments->_links->next); } + + public function testIteratePayment() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/payments", + [], + '' + ), + new Response( + 200, + [], + '{ + "_embedded": { + "payments": [ + { + "resource": "payment", + "id": "tr_admNa2tFfa", + "mode": "test", + "createdAt": "2018-03-19T15:00:50+00:00", + "amount": { + "value": "100.00", + "currency": "EUR" + }, + "description": "Payment no 1", + "method": null, + "metadata": null, + "status": "open", + "isCancelable": false, + "expiresAt": "2018-03-19T15:15:50+00:00", + "details": null, + "locale": "nl_NL", + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://www.example.org/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_admNa2tFfa", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/admNa2tFfa", + "type": "text/html" + } + } + }, + { + "resource": "payment", + "id": "tr_bcaLc7hFfa", + "mode": "test", + "createdAt": "2018-03-19T15:00:50+00:00", + "amount": { + "value": "100.00", + "currency": "EUR" + }, + "description": "Payment no 2", + "method": null, + "metadata": null, + "status": "open", + "isCancelable": false, + "expiresAt": "2018-03-19T15:15:50+00:00", + "details": null, + "locale": "nl_NL", + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://www.example.org/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_bcaLc7hFfa", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/bcaLc7hFfa", + "type": "text/html" + } + } + }, + { + "resource": "payment", + "id": "tr_pslHy1tFfa", + "mode": "test", + "createdAt": "2018-03-19T15:00:50+00:00", + "amount": { + "value": "100.00", + "currency": "EUR" + }, + "description": "Payment no 3", + "method": null, + "metadata": null, + "status": "open", + "isCancelable": false, + "expiresAt": "2018-03-19T15:15:50+00:00", + "details": null, + "locale": "nl_NL", + "profileId": "pfl_7N5qjbu42V", + "sequenceType": "oneoff", + "redirectUrl": "https://www.example.org/", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_pslHy1tFfa", + "type": "application/hal+json" + }, + "checkout": { + "href": "https://www.mollie.com/payscreen/select-method/pslHy1tFfa", + "type": "text/html" + } + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/payments-api/list-payments", + "type": "text/html" + }, + "self": { + "href": "http://api.mollie.com/v2/payments?limit=3", + "type": "application/hal+json" + }, + "previous": null, + "next": null + }, + "count": 3 + }' + ) + ); + + foreach ($this->apiClient->payments->iterator() as $payment) { + $this->assertInstanceOf(Payment::class, $payment); + $this->assertEquals("payment", $payment->resource); + } + } } diff --git a/tests/Mollie/API/Endpoints/RefundEndpointTest.php b/tests/Mollie/API/Endpoints/RefundEndpointTest.php index 2bc80483..351e2b46 100644 --- a/tests/Mollie/API/Endpoints/RefundEndpointTest.php +++ b/tests/Mollie/API/Endpoints/RefundEndpointTest.php @@ -94,4 +94,70 @@ public function testListRefunds() $paymentLink = (object)["href" => "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", "type" => "application/hal+json"]; $this->assertEquals($paymentLink, $refund->_links->payment); } + + public function testIterateRefunds() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/refunds", + [], + '' + ), + new Response( + 200, + [], + '{ + "_embedded": { + "refunds": [ + { + "resource": "refund", + "id": "re_haCsig5aru", + "amount": { + "value": "2.00", + "currency": "EUR" + }, + "status": "pending", + "createdAt": "2018-03-28T10:56:10+00:00", + "description": "My first API payment", + "paymentId": "tr_44aKxzEbr8", + "settlementAmount": { + "value": "-2.00", + "currency": "EUR" + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8/refunds/re_haCsig5aru", + "type": "application/hal+json" + }, + "payment": { + "href": "https://api.mollie.com/v2/payments/tr_44aKxzEbr8", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/refunds-api/list-refunds", + "type": "text/html" + }, + "self": { + "href": "http://api.mollie.nl/v2/refunds?limit=10", + "type": "application/hal+json" + }, + "previous": null, + "next": null + }, + "count": 1 + }' + ) + ); + + foreach ($this->apiClient->refunds->iterator() as $refund) { + $this->assertInstanceOf(Refund::class, $refund); + $this->assertEquals("refund", $refund->resource); + } + } } diff --git a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php index 592020aa..a0e8ae31 100644 --- a/tests/Mollie/API/Endpoints/SettlementEndpointTest.php +++ b/tests/Mollie/API/Endpoints/SettlementEndpointTest.php @@ -446,4 +446,209 @@ public function testListSettlement() $this->assertNotEmpty($settlement->periods); } } + + public function testIterateSettlement() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/settlements", + [], + '' + ), + new Response( + 200, + [], + '{ + "_embedded": { + "settlements": [ + { + "resource": "settlement", + "id": "stl_xcaSGAHuRt", + "reference": "1234567.1234.12", + "createdAt": "2018-04-30T04:00:02+00:00", + "settledAt": "2018-05-01T04:00:02+00:00", + "status": "pending", + "amount": { + "value": "1980.98", + "currency": "EUR" + }, + "periods": { + "2018": { + "04": { + "revenue": [ + { + "description": "Creditcard", + "method": "creditcard", + "count": 2, + "amountNet": { + "value": "790.00", + "currency": "EUR" + }, + "amountVat": null, + "amountGross": { + "value": "1000.00", + "currency": "EUR" + } + }, + { + "description": "iDEAL", + "method": "ideal", + "count": 2, + "amountNet": { + "value": "790.00", + "currency": "EUR" + }, + "amountVat": null, + "amountGross": { + "value": "1000.00", + "currency": "EUR" + } + } + ], + "costs": [ + { + "description": "Creditcard", + "method": "creditcard", + "count": 2, + "rate": { + "fixed": { + "value": "0.00", + "currency": "EUR" + }, + "percentage": "1.80" + }, + "amountNet": { + "value": "14.22", + "currency": "EUR" + }, + "amountVat": { + "value": "2.9862", + "currency": "EUR" + }, + "amountGross": { + "value": "17.2062", + "currency": "EUR" + } + }, + { + "description": "Fixed creditcard costs", + "method": "creditcard", + "count": 2, + "rate": { + "fixed": { + "value": "0.25", + "currency": "EUR" + }, + "percentage": "0" + }, + "amountNet": { + "value": "0.50", + "currency": "EUR" + }, + "amountVat": { + "value": "0.105", + "currency": "EUR" + }, + "amountGross": { + "value": "0.605", + "currency": "EUR" + } + }, + { + "description": "Fixed iDEAL costs", + "method": "ideal", + "count": 2, + "rate": { + "fixed": { + "value": "0.25", + "currency": "EUR" + }, + "percentage": "0" + }, + "amountNet": { + "value": "0.50", + "currency": "EUR" + }, + "amountVat": { + "value": "0.105", + "currency": "EUR" + }, + "amountGross": { + "value": "0.605", + "currency": "EUR" + } + }, + { + "description": "Refunds iDEAL", + "method": "refund", + "count": 2, + "rate": { + "fixed": { + "value": "0.25", + "currency": "EUR" + }, + "percentage": "0" + }, + "amountNet": { + "value": "0.50", + "currency": "EUR" + }, + "amountVat": { + "value": "0.105", + "currency": "EUR" + }, + "amountGross": { + "value": "0.605", + "currency": "EUR" + } + } + ] + } + } + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt", + "type": "application/hal+json" + }, + "payments": { + "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/payments", + "type": "application/hal+json" + }, + "refunds": { + "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/refunds", + "type": "application/hal+json" + }, + "chargebacks": { + "href": "https://api.mollie.com/v2/settlements/stl_xcaSGAHuRt/chargebacks", + "type": "application/hal+json" + } + } + } + ] + }, + "count": 1, + "_links": { + "documentation": { + "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlements", + "type": "text/html" + }, + "self": { + "href": "https://api.mollie.nl/v2/settlements", + "type": "application/hal+json" + }, + "previous": null, + "next": null + } + }' + ) + ); + + foreach ($this->apiClient->settlements->iterator() as $settlement) { + $this->assertInstanceOf(Settlement::class, $settlement); + $this->assertEquals("settlement", $settlement->resource); + $this->assertNotEmpty($settlement->periods); + } + } } diff --git a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php index 3a9bfccc..e3e0d146 100644 --- a/tests/Mollie/API/Endpoints/TerminalEndpointTest.php +++ b/tests/Mollie/API/Endpoints/TerminalEndpointTest.php @@ -92,6 +92,7 @@ public function testListTerminal() "terminals": [ { "id": "term_7MgL4wea46qkRcoTZjWEH", + "resource": "terminal", "profileId": "pfl_QkEhN94Ba", "status": "active", "brand": "PAX", @@ -113,6 +114,7 @@ public function testListTerminal() }, { "id": "term_7MgL4wea46qkRcoTZjWEG", + "resource": "terminal", "profileId": "pfl_QkEhN94Bb", "status": "pending", "brand": "PAX", @@ -134,6 +136,7 @@ public function testListTerminal() }, { "id": "term_7MgL4wea46qkRcoTZjWEI", + "resource": "terminal", "profileId": "pfl_QkEhN94Bc", "status": "inactive", "brand": "PAX", @@ -186,4 +189,110 @@ public function testListTerminal() $this->assertNull($terminals->_links->previous); } + + public function testIterateTerminal() + { + $this->mockApiCall( + new Request( + "GET", + "/v2/terminals", + [], + '' + ), + new Response( + 200, + [], + '{ + "count": 3, + "_embedded": { + "terminals": [ + { + "id": "term_7MgL4wea46qkRcoTZjWEH", + "resource": "terminal", + "profileId": "pfl_QkEhN94Ba", + "status": "active", + "brand": "PAX", + "model": "A920", + "serialNumber": "1234567890", + "currency": "EUR", + "description": "Terminal #12345", + "timezone": "GMT +08:00", + "locale": "nl_NL", + "createdAt": "2022-02-12T11:58:35.0Z", + "updatedAt": "2022-11-15T13:32:11+00:00", + "activatedAt": "2022-02-12T12:13:35.0Z", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", + "type": "application/hal+json" + } + } + }, + { + "id": "term_7MgL4wea46qkRcoTZjWEG", + "resource": "terminal", + "profileId": "pfl_QkEhN94Bb", + "status": "pending", + "brand": "PAX", + "model": "A920", + "serialNumber": "1234567891", + "currency": "EUR", + "description": "Terminal #12346", + "timezone": "GMT +08:00", + "locale": "nl_NL", + "createdAt": "2022-02-13T11:58:35.0Z", + "updatedAt": "2022-11-16T13:32:11+00:00", + "activatedAt": "2022-02-13T12:13:35.0Z", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEG", + "type": "application/hal+json" + } + } + }, + { + "id": "term_7MgL4wea46qkRcoTZjWEI", + "resource": "terminal", + "profileId": "pfl_QkEhN94Bc", + "status": "inactive", + "brand": "PAX", + "model": "A920", + "serialNumber": "1234567892", + "currency": "EUR", + "description": "Terminal #12347", + "timezone": "GMT +08:00", + "locale": "nl_NL", + "createdAt": "2022-02-14T11:58:35.0Z", + "updatedAt": "2022-11-17T13:32:11+00:00", + "activatedAt": "2022-02-14T12:13:35.0Z", + "_links": { + "self": { + "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEI", + "type": "application/hal+json" + } + } + } + ] + }, + "_links": { + "self": { + "href": "https://api.mollie.com/v2/terminals", + "type": "application/hal+json" + }, + "previous": null, + "next": null, + "documentation": { + "href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals", + "type": "text/html" + } + } + }' + ) + ); + + foreach ($this->apiClient->terminals->iterator() as $terminal) { + $this->assertInstanceOf(Terminal::class, $terminal); + $this->assertEquals("terminal", $terminal->resource); + } + } } diff --git a/tests/SettlementRefundEndpointTest.php b/tests/SettlementRefundEndpointTest.php deleted file mode 100644 index 14df7f53..00000000 --- a/tests/SettlementRefundEndpointTest.php +++ /dev/null @@ -1,91 +0,0 @@ -mockApiCall( - new Request( - 'GET', - '/v2/settlements/stl_jDk30akdN/refunds?limit=5&foo=bar' - ), - new Response( - 200, - [], - '{ - "_embedded": { - "refunds": [ - { - "resource": "refund", - "id": "re_3aKhkUNigy", - "amount": { - "value": "10.00", - "currency": "EUR" - }, - "status": "refunded", - "createdAt": "2018-08-30T07:59:02+00:00", - "description": "Order #33", - "paymentId": "tr_maJaG2j8OM", - "settlementAmount": { - "value": "-10.00", - "currency": "EUR" - }, - "settlementId": "stl_jDk30akdN", - "_links": { - "self": { - "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM/refunds/re_3aKhkUNigy", - "type": "application/hal+json" - }, - "payment": { - "href": "https://api.mollie.com/v2/payments/tr_maJaG2j8OM", - "type": "application/hal+json" - }, - "settlement": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", - "type": "application/hal+json" - } - } - }, - { } - ] - }, - "count": 1, - "_links": { - "documentation": { - "href": "https://docs.mollie.com/reference/v2/settlements-api/list-settlement-refunds", - "type": "text/html" - }, - "self": { - "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN/refunds?limit=50", - "type": "application/hal+json" - }, - "previous": null, - "next": null - } - }' - ) - ); - - $settlement = new Settlement($this->apiClient); - $settlement->id = 'stl_jDk30akdN'; - - $refunds = $settlement->refunds(5, ['foo' => 'bar']); - - $this->assertInstanceOf(RefundCollection::class, $refunds); - $this->assertCount(2, $refunds); - - $refund = $refunds[0]; - $this->assertInstanceOf(Refund::class, $refund); - $this->assertEquals("re_3aKhkUNigy", $refund->id); - } -} From 4a8760976ecf9cd8b8e819dd56bd033a4ae1e4f1 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 26 Oct 2023 09:58:13 +0000 Subject: [PATCH 04/10] Fix styling --- src/Endpoints/BalanceEndpoint.php | 2 +- src/Endpoints/BalanceTransactionEndpoint.php | 6 +++--- src/Endpoints/ChargebackEndpoint.php | 2 +- src/Endpoints/ClientEndpoint.php | 2 +- src/Endpoints/CollectionEndpointAbstract.php | 6 +++--- src/Endpoints/CustomerEndpoint.php | 2 +- src/Endpoints/CustomerPaymentsEndpoint.php | 4 ++-- src/Endpoints/InvoiceEndpoint.php | 2 +- src/Endpoints/MandateEndpoint.php | 4 ++-- src/Endpoints/OrderEndpoint.php | 2 +- src/Endpoints/PaymentCaptureEndpoint.php | 4 ++-- src/Endpoints/PaymentChargebackEndpoint.php | 4 ++-- src/Endpoints/PaymentEndpoint.php | 2 +- src/Endpoints/PaymentLinkEndpoint.php | 2 +- src/Endpoints/PaymentRefundEndpoint.php | 4 ++-- src/Endpoints/ProfileEndpoint.php | 2 +- src/Endpoints/RefundEndpoint.php | 2 +- src/Endpoints/SettlementCaptureEndpoint.php | 2 +- src/Endpoints/SettlementChargebackEndpoint.php | 2 +- src/Endpoints/SettlementPaymentEndpoint.php | 2 +- src/Endpoints/SettlementRefundEndpoint.php | 2 +- src/Endpoints/SettlementsEndpoint.php | 2 +- src/Endpoints/SubscriptionEndpoint.php | 6 +++--- src/Endpoints/TerminalEndpoint.php | 2 +- 24 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Endpoints/BalanceEndpoint.php b/src/Endpoints/BalanceEndpoint.php index a0582c8b..50dcbf42 100644 --- a/src/Endpoints/BalanceEndpoint.php +++ b/src/Endpoints/BalanceEndpoint.php @@ -87,7 +87,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters * @param string $from The first Balance ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/BalanceTransactionEndpoint.php b/src/Endpoints/BalanceTransactionEndpoint.php index 5dcec331..e0238007 100644 --- a/src/Endpoints/BalanceTransactionEndpoint.php +++ b/src/Endpoints/BalanceTransactionEndpoint.php @@ -56,7 +56,7 @@ public function listFor(Balance $balance, array $parameters = []) * * @param Balance $balance * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -86,7 +86,7 @@ public function listForId(string $balanceId, array $parameters = []) * * @param string $balanceId * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -116,7 +116,7 @@ public function listForPrimary(array $parameters = []) * Create an iterator for iterating over transactions for the primary balance retrieved from Mollie. * * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/ChargebackEndpoint.php b/src/Endpoints/ChargebackEndpoint.php index 68efd372..d02d08ae 100644 --- a/src/Endpoints/ChargebackEndpoint.php +++ b/src/Endpoints/ChargebackEndpoint.php @@ -55,7 +55,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters * @param string $from The first chargevback ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/ClientEndpoint.php b/src/Endpoints/ClientEndpoint.php index 5e3efb94..cdad8b50 100644 --- a/src/Endpoints/ClientEndpoint.php +++ b/src/Endpoints/ClientEndpoint.php @@ -74,7 +74,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters * @param string $from The first client ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index c36f54bc..81e05787 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -48,7 +48,7 @@ protected function rest_list(?string $from = null, ?int $limit = null, array $fi * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $filters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * @return Generator */ protected function rest_iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): Generator @@ -63,7 +63,7 @@ protected function rest_iterator(?string $from = null, ?int $limit = null, array * Iterate over a CursorCollection and yield its elements. * * @param CursorCollection $page - * @param boolean $iterateBackwards + * @param bool $iterateBackwards * * @return Generator */ @@ -74,7 +74,7 @@ protected function iterate(CursorCollection $page, bool $iterateBackwards = fals yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } diff --git a/src/Endpoints/CustomerEndpoint.php b/src/Endpoints/CustomerEndpoint.php index 5e48a1b4..603ba1eb 100644 --- a/src/Endpoints/CustomerEndpoint.php +++ b/src/Endpoints/CustomerEndpoint.php @@ -126,7 +126,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters * @param string $from The first customer ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/CustomerPaymentsEndpoint.php b/src/Endpoints/CustomerPaymentsEndpoint.php index ea231b88..0738dd65 100644 --- a/src/Endpoints/CustomerPaymentsEndpoint.php +++ b/src/Endpoints/CustomerPaymentsEndpoint.php @@ -87,7 +87,7 @@ public function listFor(Customer $customer, ?string $from = null, ?int $limit = * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -119,7 +119,7 @@ public function listForId($customerId, ?string $from = null, ?int $limit = null, * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/InvoiceEndpoint.php b/src/Endpoints/InvoiceEndpoint.php index afd7750d..3f5af151 100644 --- a/src/Endpoints/InvoiceEndpoint.php +++ b/src/Endpoints/InvoiceEndpoint.php @@ -84,7 +84,7 @@ public function all(array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/MandateEndpoint.php b/src/Endpoints/MandateEndpoint.php index 160f4b74..75302515 100644 --- a/src/Endpoints/MandateEndpoint.php +++ b/src/Endpoints/MandateEndpoint.php @@ -111,7 +111,7 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -143,7 +143,7 @@ public function listForId($customerId, $from = null, $limit = null, array $param * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/OrderEndpoint.php b/src/Endpoints/OrderEndpoint.php index 102b44ea..ee1eaaee 100644 --- a/src/Endpoints/OrderEndpoint.php +++ b/src/Endpoints/OrderEndpoint.php @@ -135,7 +135,7 @@ public function page(?string $from = null, ?int $limit = null, array $parameters * @param string $from The first order ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/PaymentCaptureEndpoint.php b/src/Endpoints/PaymentCaptureEndpoint.php index d7bd6f4e..1671f095 100644 --- a/src/Endpoints/PaymentCaptureEndpoint.php +++ b/src/Endpoints/PaymentCaptureEndpoint.php @@ -113,7 +113,7 @@ public function listFor(Payment $payment, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -143,7 +143,7 @@ public function listForId($paymentId, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/PaymentChargebackEndpoint.php b/src/Endpoints/PaymentChargebackEndpoint.php index e2f1d33a..42da9b03 100644 --- a/src/Endpoints/PaymentChargebackEndpoint.php +++ b/src/Endpoints/PaymentChargebackEndpoint.php @@ -81,7 +81,7 @@ public function listFor(Payment $payment, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -111,7 +111,7 @@ public function listForId($paymentId, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/PaymentEndpoint.php b/src/Endpoints/PaymentEndpoint.php index a68032cc..10ad9d34 100644 --- a/src/Endpoints/PaymentEndpoint.php +++ b/src/Endpoints/PaymentEndpoint.php @@ -147,7 +147,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/PaymentLinkEndpoint.php b/src/Endpoints/PaymentLinkEndpoint.php index 6e98c053..22adf5cd 100644 --- a/src/Endpoints/PaymentLinkEndpoint.php +++ b/src/Endpoints/PaymentLinkEndpoint.php @@ -92,7 +92,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/PaymentRefundEndpoint.php b/src/Endpoints/PaymentRefundEndpoint.php index 28c2ee36..9ea4a168 100644 --- a/src/Endpoints/PaymentRefundEndpoint.php +++ b/src/Endpoints/PaymentRefundEndpoint.php @@ -81,7 +81,7 @@ public function listFor(Payment $payment, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -111,7 +111,7 @@ public function listForId($paymentId, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/ProfileEndpoint.php b/src/Endpoints/ProfileEndpoint.php index 07647743..45d382df 100644 --- a/src/Endpoints/ProfileEndpoint.php +++ b/src/Endpoints/ProfileEndpoint.php @@ -148,7 +148,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/RefundEndpoint.php b/src/Endpoints/RefundEndpoint.php index 616f15af..720d14c5 100644 --- a/src/Endpoints/RefundEndpoint.php +++ b/src/Endpoints/RefundEndpoint.php @@ -55,7 +55,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SettlementCaptureEndpoint.php b/src/Endpoints/SettlementCaptureEndpoint.php index 4c08136a..03786563 100644 --- a/src/Endpoints/SettlementCaptureEndpoint.php +++ b/src/Endpoints/SettlementCaptureEndpoint.php @@ -50,7 +50,7 @@ public function pageForId(string $settlementId, string $from = null, int $limit * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SettlementChargebackEndpoint.php b/src/Endpoints/SettlementChargebackEndpoint.php index 2992c322..6dc5a735 100644 --- a/src/Endpoints/SettlementChargebackEndpoint.php +++ b/src/Endpoints/SettlementChargebackEndpoint.php @@ -53,7 +53,7 @@ public function pageForId(string $settlementId, string $from = null, int $limit * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SettlementPaymentEndpoint.php b/src/Endpoints/SettlementPaymentEndpoint.php index 9766bd1d..5dc6b4e4 100644 --- a/src/Endpoints/SettlementPaymentEndpoint.php +++ b/src/Endpoints/SettlementPaymentEndpoint.php @@ -51,7 +51,7 @@ public function pageForId($settlementId, $from = null, $limit = null, array $par * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SettlementRefundEndpoint.php b/src/Endpoints/SettlementRefundEndpoint.php index 4984fe23..dc11f782 100644 --- a/src/Endpoints/SettlementRefundEndpoint.php +++ b/src/Endpoints/SettlementRefundEndpoint.php @@ -53,7 +53,7 @@ public function pageForId(string $settlementId, string $from = null, int $limit * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SettlementsEndpoint.php b/src/Endpoints/SettlementsEndpoint.php index 6fc4c570..2de54067 100644 --- a/src/Endpoints/SettlementsEndpoint.php +++ b/src/Endpoints/SettlementsEndpoint.php @@ -92,7 +92,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index b0975049..690992fb 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -146,7 +146,7 @@ public function listFor(Customer $customer, $from = null, $limit = null, array $ * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -178,7 +178,7 @@ public function listForId($customerId, $from = null, $limit = null, array $param * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ @@ -251,7 +251,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ diff --git a/src/Endpoints/TerminalEndpoint.php b/src/Endpoints/TerminalEndpoint.php index 9b1d90a3..dbd9ff12 100644 --- a/src/Endpoints/TerminalEndpoint.php +++ b/src/Endpoints/TerminalEndpoint.php @@ -77,7 +77,7 @@ public function page($from = null, $limit = null, array $parameters = []) * @param string $from The first resource ID you want to include in your list. * @param int $limit * @param array $parameters - * @param boolean $iterateBackwards Set to true for reverse order iteration (default is false). + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). * * @return Generator */ From eafd22e004fad1e239e9edafe488f33d94e06b96 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Thu, 26 Oct 2023 12:20:26 +0200 Subject: [PATCH 05/10] wip --- src/Endpoints/CollectionEndpointAbstract.php | 27 +---------------- src/Endpoints/SubscriptionEndpoint.php | 2 +- src/Resources/CursorCollection.php | 31 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Endpoints/CollectionEndpointAbstract.php b/src/Endpoints/CollectionEndpointAbstract.php index 81e05787..65987623 100644 --- a/src/Endpoints/CollectionEndpointAbstract.php +++ b/src/Endpoints/CollectionEndpointAbstract.php @@ -56,32 +56,7 @@ protected function rest_iterator(?string $from = null, ?int $limit = null, array /** @var CursorCollection $page */ $page = $this->rest_list($from, $limit, $filters); - return $this->iterate($page, $iterateBackwards); - } - - /** - * Iterate over a CursorCollection and yield its elements. - * - * @param CursorCollection $page - * @param bool $iterateBackwards - * - * @return Generator - */ - protected function iterate(CursorCollection $page, bool $iterateBackwards = false): Generator - { - while (true) { - foreach ($page as $item) { - yield $item; - } - - if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { - break; - } - - $page = $iterateBackwards - ? $page->previous() - : $page->next(); - } + return $page->getAutoIterator($iterateBackwards); } /** diff --git a/src/Endpoints/SubscriptionEndpoint.php b/src/Endpoints/SubscriptionEndpoint.php index 690992fb..06930027 100644 --- a/src/Endpoints/SubscriptionEndpoint.php +++ b/src/Endpoints/SubscriptionEndpoint.php @@ -259,6 +259,6 @@ public function iterator(?string $from = null, ?int $limit = null, array $parame { $page = $this->page($from, $limit, $parameters); - return $this->iterate($page, $iterateBackwards); + return $page->getAutoIterator($iterateBackwards); } } diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index e3265335..36e4d40d 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -2,6 +2,7 @@ namespace Mollie\Api\Resources; +use Generator; use Mollie\Api\MollieApiClient; abstract class CursorCollection extends BaseCollection @@ -36,7 +37,7 @@ abstract protected function createResourceObject(); */ final public function next() { - if (! $this->hasNext()) { + if (!$this->hasNext()) { return null; } @@ -59,7 +60,7 @@ final public function next() */ final public function previous() { - if (! $this->hasPrevious()) { + if (!$this->hasPrevious()) { return null; } @@ -93,4 +94,30 @@ public function hasPrevious() { return isset($this->_links->previous->href); } + + /** + * Iterate over a CursorCollection and yield its elements. + * + * @param boolean $iterateBackwards + * + * @return Generator + */ + public function getAutoIterator(bool $iterateBackwards = false): Generator + { + $page = $this; + + while (true) { + foreach ($page as $item) { + yield $item; + } + + if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + break; + } + + $page = $iterateBackwards + ? $page->previous() + : $page->next(); + } + } } From f3322f3788e4008540211bcc7eb25f8479e8e715 Mon Sep 17 00:00:00 2001 From: Naoray Date: Thu, 26 Oct 2023 10:20:54 +0000 Subject: [PATCH 06/10] Fix styling --- src/Resources/CursorCollection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resources/CursorCollection.php b/src/Resources/CursorCollection.php index 36e4d40d..2a20e54e 100644 --- a/src/Resources/CursorCollection.php +++ b/src/Resources/CursorCollection.php @@ -37,7 +37,7 @@ abstract protected function createResourceObject(); */ final public function next() { - if (!$this->hasNext()) { + if (! $this->hasNext()) { return null; } @@ -60,7 +60,7 @@ final public function next() */ final public function previous() { - if (!$this->hasPrevious()) { + if (! $this->hasPrevious()) { return null; } @@ -98,7 +98,7 @@ public function hasPrevious() /** * Iterate over a CursorCollection and yield its elements. * - * @param boolean $iterateBackwards + * @param bool $iterateBackwards * * @return Generator */ @@ -111,7 +111,7 @@ public function getAutoIterator(bool $iterateBackwards = false): Generator yield $item; } - if (($iterateBackwards && !$page->hasPrevious()) || !$page->hasNext()) { + if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) { break; } From 396230a0a51c7a1ab832c2085c70db3e21216761 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 27 Oct 2023 09:59:35 +0200 Subject: [PATCH 07/10] add pagination examples --- examples/pagination/backwards.php | 57 +++++++++++++++++++++++++++++ examples/pagination/basic_usage.php | 56 ++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 examples/pagination/backwards.php create mode 100644 examples/pagination/basic_usage.php diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php new file mode 100644 index 00000000..910ced84 --- /dev/null +++ b/examples/pagination/backwards.php @@ -0,0 +1,57 @@ +orders->page($orderId); + + while ($page->hasPrevious()) { + foreach ($page as $order) { + echo ($order->id); + } + + $page = $page->previous(); + } + + // iterating backwards using the iterator by passing iterateBackwards = true + // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) + foreach ($client->orders->iterator(null, null, [], true) as $order) { + echo ($order->id); + } +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php new file mode 100644 index 00000000..26194844 --- /dev/null +++ b/examples/pagination/basic_usage.php @@ -0,0 +1,56 @@ +orders->page(); + + while ($page->hasNext()) { + foreach ($page as $order) { + echo ($order->id); + } + + $page = $page->next(); + } + + + // using the iterator we can iterate over all orders directly + foreach ($client->orders->iterator() as $order) { + echo ($order->id); + } +} catch (\Mollie\Api\Exceptions\ApiException $e) { + echo "API call failed: " . htmlspecialchars($e->getMessage()); +} From bc69d2f77a0b76f5b6c91ee99bbd8927ed3f74e3 Mon Sep 17 00:00:00 2001 From: Naoray Date: Fri, 27 Oct 2023 07:59:59 +0000 Subject: [PATCH 08/10] Fix styling --- examples/pagination/backwards.php | 4 ++-- examples/pagination/basic_usage.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index 910ced84..5eeb6b53 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -41,7 +41,7 @@ while ($page->hasPrevious()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->previous(); @@ -50,7 +50,7 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) foreach ($client->orders->iterator(null, null, [], true) as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index 26194844..38f4d53f 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -40,7 +40,7 @@ while ($page->hasNext()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->next(); @@ -49,7 +49,7 @@ // using the iterator we can iterate over all orders directly foreach ($client->orders->iterator() as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); From 01b313f5ea8aaf6db5b94f37c4c857ec8cb02d5e Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Fri, 27 Oct 2023 10:16:46 +0200 Subject: [PATCH 09/10] fix example --- examples/pagination/backwards.php | 8 ++++---- examples/pagination/basic_usage.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index 5eeb6b53..d14823dc 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -37,11 +37,11 @@ $orderId = 'ord_8wmqcHMN4U'; // cursor paginating backwards through all orders - $page = $client->orders->page($orderId); + $page = $mollie->orders->page($orderId); while ($page->hasPrevious()) { foreach ($page as $order) { - echo($order->id); + echo ($order->id); } $page = $page->previous(); @@ -49,8 +49,8 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) - foreach ($client->orders->iterator(null, null, [], true) as $order) { - echo($order->id); + foreach ($mollie->orders->iterator(null, null, [], true) as $order) { + echo ($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index 38f4d53f..658da245 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -36,11 +36,11 @@ // cursor paginating through all orders - $page = $client->orders->page(); + $page = $mollie->orders->page(); while ($page->hasNext()) { foreach ($page as $order) { - echo($order->id); + echo ($order->id); } $page = $page->next(); @@ -48,8 +48,8 @@ // using the iterator we can iterate over all orders directly - foreach ($client->orders->iterator() as $order) { - echo($order->id); + foreach ($mollie->orders->iterator() as $order) { + echo ($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); From 1e54ac4806a003a6ffe6ea6dae24fa9aae60fb2f Mon Sep 17 00:00:00 2001 From: Naoray Date: Fri, 27 Oct 2023 08:17:10 +0000 Subject: [PATCH 10/10] Fix styling --- examples/pagination/backwards.php | 4 ++-- examples/pagination/basic_usage.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/pagination/backwards.php b/examples/pagination/backwards.php index d14823dc..35aa6363 100644 --- a/examples/pagination/backwards.php +++ b/examples/pagination/backwards.php @@ -41,7 +41,7 @@ while ($page->hasPrevious()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->previous(); @@ -50,7 +50,7 @@ // iterating backwards using the iterator by passing iterateBackwards = true // in php 8.0+ you could also use the named parameter syntax iterator(iterateBackwards: true) foreach ($mollie->orders->iterator(null, null, [], true) as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage()); diff --git a/examples/pagination/basic_usage.php b/examples/pagination/basic_usage.php index 658da245..3e927ca8 100644 --- a/examples/pagination/basic_usage.php +++ b/examples/pagination/basic_usage.php @@ -40,7 +40,7 @@ while ($page->hasNext()) { foreach ($page as $order) { - echo ($order->id); + echo($order->id); } $page = $page->next(); @@ -49,7 +49,7 @@ // using the iterator we can iterate over all orders directly foreach ($mollie->orders->iterator() as $order) { - echo ($order->id); + echo($order->id); } } catch (\Mollie\Api\Exceptions\ApiException $e) { echo "API call failed: " . htmlspecialchars($e->getMessage());