Skip to content

Commit

Permalink
NTR: update mollie lbirary (#723)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitalij Mik <[email protected]>
  • Loading branch information
BlackScorp and Vitalij Mik authored Mar 18, 2024
1 parent 7a18c81 commit 70fe37e
Show file tree
Hide file tree
Showing 31 changed files with 1,292 additions and 143 deletions.
337 changes: 258 additions & 79 deletions vendor_manual/mollie/mollie-api-php/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceCollection;
use Mollie\Api\Resources\BaseCollection;
use Mollie\Api\Resources\LazyCollection;

class BalanceEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceTransaction;
use Mollie\Api\Resources\BalanceTransactionCollection;
use Mollie\Api\Resources\LazyCollection;

class BalanceTransactionEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($balance->id, $parameters, $iterateBackwards);
}

/**
* List the transactions for a specific Balance ID.
*
Expand All @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $balanceId, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $balanceId;

return $this->rest_iterator(null, null, $parameters, $iterateBackwards);
}

/**
* List the transactions for the primary Balance.
*
Expand All @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForPrimary(array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = "primary";

return $this->rest_iterator(null, null, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;

class ChargebackEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Client;
use Mollie\Api\Resources\ClientCollection;
use Mollie\Api\Resources\LazyCollection;

class ClientEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\BaseCollection;
use Mollie\Api\Resources\CursorCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\ResourceFactory;

abstract class CollectionEndpointAbstract extends EndpointAbstract
Expand All @@ -18,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);

Expand All @@ -36,6 +38,27 @@ protected function rest_list($from = null, $limit = null, array $filters = [])
return $collection;
}

/**
* Create a generator for iterating over a resource's collection using REST API calls.
*
* This function fetches paginated data from a RESTful resource endpoint and returns a generator
* that allows you to iterate through the items in the collection one by one. It supports forward
* and backward iteration, pagination, and filtering.
*
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $filters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
* @return LazyCollection
*/
protected function rest_iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
/** @var CursorCollection $page */
$page = $this->rest_list($from, $limit, $filters);

return $page->getAutoIterator($iterateBackwards);
}

/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\CustomerCollection;
use Mollie\Api\Resources\LazyCollection;

class CustomerEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mollie\Api\Endpoints;

use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;

Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards);
}

/**
* @param string $customerId
* @param string $from The first resource ID you want to include in your list.
Expand All @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $customerId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $customerId;

return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Invoice;
use Mollie\Api\Resources\InvoiceCollection;
use Mollie\Api\Resources\LazyCollection;

class InvoiceEndpoint extends CollectionEndpointAbstract
{
Expand Down Expand Up @@ -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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}
Loading

0 comments on commit 70fe37e

Please sign in to comment.