allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s

This commit is contained in:
2026-03-30 14:54:57 +07:00
parent 66aed7c4e8
commit b5e3a778ce
21316 changed files with 2777892 additions and 13 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceCollection;
use Mollie\Api\Resources\BaseCollection;
use Mollie\Api\Resources\LazyCollection;
class BalanceEndpoint extends CollectionEndpointAbstract
{
/**
* @var string
*/
const RESOURCE_ID_PREFIX = 'bal_';
protected $resourcePath = "balances";
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new BalanceCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Balance($this->client);
}
/**
* Retrieve a single balance from Mollie.
*
* Will throw an ApiException if the balance id is invalid or the resource cannot be found.
*
* @param string $balanceId
* @param array $parameters
* @return \Mollie\Api\Resources\Balance|\Mollie\Api\Resources\BaseResource
* @throws ApiException
*/
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 . "'.");
}
return parent::rest_read($balanceId, $parameters);
}
/**
* Retrieve the primary balance from Mollie.
*
* Will throw an ApiException if the balance id is invalid or the resource cannot be found.
*
* @param array $parameters
* @return \Mollie\Api\Resources\Balance|\Mollie\Api\Resources\BaseResource
* @throws ApiException
*/
public function primary(array $parameters = [])
{
return parent::rest_read("primary", $parameters);
}
/**
* Retrieves a collection of Balances from Mollie.
*
* @param string|null $from The first Balance ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return BaseCollection|BalanceCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
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);
}
}

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceReport;
use Mollie\Api\Resources\ResourceFactory;
class BalanceReportEndpoint extends EndpointAbstract
{
protected $resourcePath = "balances_report";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new BalanceReport($this->client);
}
/**
* Retrieve a balance report for the provided balance id and parameters.
*
* @param string $balanceId
* @param array $parameters
* @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId(string $balanceId, array $parameters = [])
{
$this->parentId = $balanceId;
$result = $this->client->performHttpCall(
self::REST_READ,
$this->getResourcePath() . $this->buildQueryString($parameters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Retrieve the primary balance.
* This is the balance of your accounts primary currency, where all payments are settled to by default.
*
* @param array $parameters
* @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForPrimary(array $parameters = [])
{
return $this->getForId("primary", $parameters);
}
/**
* Retrieve a balance report for the provided balance resource and parameters.
*
* @param \Mollie\Api\Resources\Balance $balance
* @param array $parameters
* @return \Mollie\Api\Resources\BalanceReport|\Mollie\Api\Resources\BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Balance $balance, array $parameters = [])
{
return $this->getForId($balance->id, $parameters);
}
}

View File

@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceTransaction;
use Mollie\Api\Resources\BalanceTransactionCollection;
use Mollie\Api\Resources\LazyCollection;
class BalanceTransactionEndpoint extends CollectionEndpointAbstract
{
/**
* @var string
*/
const RESOURCE_ID_PREFIX = 'baltr_';
/**
* @var string
*/
protected $resourcePath = "balances_transactions";
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new BalanceTransactionCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new BalanceTransaction($this->client);
}
/**
* List the transactions for a specific Balance.
*
* @param Balance $balance
* @param array $parameters
* @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
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.
*
* @param string $balanceId
* @param array $parameters
* @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId(string $balanceId, array $parameters = [])
{
$this->parentId = $balanceId;
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.
*
* @param array $parameters
* @return BalanceTransactionCollection|\Mollie\Api\Resources\BaseCollection
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForPrimary(array $parameters = [])
{
$this->parentId = "primary";
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);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Capability;
use Mollie\Api\Resources\CapabilityCollection;
class CapabilityEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "capabilities";
protected function getResourceCollectionObject($count, $_links)
{
return new CapabilityCollection($count, $_links);
}
protected function getResourceObject()
{
return new Capability($this->client);
}
/**
* Retrieve a single capability from Mollie.
*
* @param string $name
* @param array $parameters
* @return \Mollie\Api\Resources\Capability|\Mollie\Api\Resources\BaseResource
* @throws ApiException
*/
public function get(string $name, array $parameters = [])
{
return parent::rest_read($name, $parameters);
}
/**
* Retrieve all capabilities.
*
* @param array $parameters
*
* @return CapabilityCollection
* @throws ApiException
*/
public function all(array $parameters = [])
{
return parent::rest_list(null, null, $parameters);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
class ChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "chargebacks";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Chargeback
*/
protected function getResourceObject()
{
return new Chargeback($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return ChargebackCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ChargebackCollection($this->client, $count, $_links);
}
/**
* Retrieves a collection of Chargebacks from Mollie.
*
* @param string $from The first chargeback ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return ChargebackCollection
* @throws ApiException
*/
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);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Client;
use Mollie\Api\Resources\ClientCollection;
use Mollie\Api\Resources\LazyCollection;
class ClientEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "clients";
/**
* @return Client
*/
protected function getResourceObject()
{
return new Client($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return ClientCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ClientCollection($this->client, $count, $_links);
}
/**
* Retrieve a client from Mollie.
*
* Will throw an ApiException if the client id is invalid or the resource cannot be found.
* The client id corresponds to the organization id, for example "org_1337".
*
* @param string $clientId
* @param array $parameters
*
* @return Client
* @throws ApiException
*/
public function get($clientId, array $parameters = [])
{
if (empty($clientId)) {
throw new ApiException("Client ID is empty.");
}
return parent::rest_read($clientId, $parameters);
}
/**
* Retrieves a page of clients from Mollie.
*
* @param string $from The first client ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return ClientCollection
* @throws ApiException
*/
public function page(?string $from = null, ?int $limit = null, array $parameters = [])
{
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);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\ClientLink;
class ClientLinkEndpoint extends EndpointAbstract
{
protected $resourcePath = "client-links";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'cl_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return ClientLink
*/
protected function getResourceObject(): ClientLink
{
return new ClientLink($this->client);
}
/**
* Creates a client link in Mollie.
*
* @param array $data An array containing details on the client link.
*
* @return ClientLink
* @throws ApiException
*/
public function create(array $data = []): ClientLink
{
return $this->rest_create($data, []);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Mollie\Api\Endpoints;
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
{
/**
* Get a collection of objects from the REST API.
*
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $filters
*
* @return mixed
* @throws ApiException
*/
protected function rest_list(?string $from = null, ?int $limit = null, array $filters = [])
{
$filters = array_merge(["from" => $from, "limit" => $limit], $filters);
$apiPath = $this->getResourcePath() . $this->buildQueryString($filters);
$result = $this->client->performHttpCall(self::REST_LIST, $apiPath);
/** @var BaseCollection $collection */
$collection = $this->getResourceCollectionObject($result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
return $collection;
}
/**
* 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.
*
* @param int $count
* @param \stdClass $_links
*
* @return BaseCollection
*/
abstract protected function getResourceCollectionObject($count, $_links);
}

View File

@@ -0,0 +1,137 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\CustomerCollection;
use Mollie\Api\Resources\LazyCollection;
class CustomerEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'cst_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Customer
*/
protected function getResourceObject()
{
return new Customer($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return CustomerCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new CustomerCollection($this->client, $count, $_links);
}
/**
* Creates a customer in Mollie.
*
* @param array $data An array containing details on the customer.
* @param array $filters
*
* @return Customer
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Retrieve a single customer from Mollie.
*
* Will throw a ApiException if the customer id is invalid or the resource cannot be found.
*
* @param string $customerId
* @param array $parameters
* @return Customer
* @throws ApiException
*/
public function get($customerId, array $parameters = [])
{
return $this->rest_read($customerId, $parameters);
}
/**
* Update a specific Customer resource.
*
* Will throw an ApiException if the customer id is invalid or the resource cannot be found.
*
* @param string $customerId
*
* @param array $data
* @return Customer
* @throws ApiException
*/
public function update($customerId, array $data = [])
{
if (empty($customerId) || strpos($customerId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid customer ID: '{$customerId}'. A customer ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_update($customerId, $data);
}
/**
* Deletes the given Customer.
*
* Will throw a ApiException if the customer id is invalid or the resource cannot be found.
* Returns with HTTP status No Content (204) if successful.
*
* @param string $customerId
*
* @param array $data
* @return null
* @throws ApiException
*/
public function delete($customerId, array $data = [])
{
return $this->rest_delete($customerId, $data);
}
/**
* Retrieves a collection of Customers from Mollie.
*
* @param string $from The first customer ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return CustomerCollection
* @throws ApiException
*/
public function page(?string $from = null, ?int $limit = null, array $parameters = [])
{
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);
}
}

View File

@@ -0,0 +1,132 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class CustomerPaymentsEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_payments";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Payment
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PaymentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
/**
* Create a subscription for a Customer
*
* @param Customer $customer
* @param array $options
* @param array $filters
*
* @return Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Customer $customer, array $options = [], array $filters = [])
{
return $this->createForId($customer->id, $options, $filters);
}
/**
* Create a subscription for a Customer ID
*
* @param string $customerId
* @param array $options
* @param array $filters
*
* @return \Mollie\Api\Resources\Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($customerId, array $options = [], array $filters = [])
{
$this->parentId = $customerId;
return parent::rest_create($options, $filters);
}
/**
* @param Customer $customer
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return PaymentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
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.
* @param int $limit
* @param array $parameters
*
* @return \Mollie\Api\Resources\PaymentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
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);
}
}

View File

@@ -0,0 +1,210 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\BaseResource;
use Mollie\Api\Resources\ResourceFactory;
abstract class EndpointAbstract
{
public const REST_CREATE = MollieApiClient::HTTP_POST;
public const REST_UPDATE = MollieApiClient::HTTP_PATCH;
public const REST_READ = MollieApiClient::HTTP_GET;
public const REST_LIST = MollieApiClient::HTTP_GET;
public const REST_DELETE = MollieApiClient::HTTP_DELETE;
/**
* @var MollieApiClient
*/
protected $client;
/**
* @var string
*/
protected $resourcePath;
/**
* @var string|null
*/
protected $parentId;
/**
* @param MollieApiClient $api
*/
public function __construct(MollieApiClient $api)
{
$this->client = $api;
}
/**
* @param array $filters
* @return string
*/
protected function buildQueryString(array $filters)
{
if (empty($filters)) {
return "";
}
foreach ($filters as $key => $value) {
if ($value === true) {
$filters[$key] = "true";
}
if ($value === false) {
$filters[$key] = "false";
}
}
return "?" . http_build_query($filters, "", "&");
}
/**
* @param array $body
* @param array $filters
* @return mixed
* @throws ApiException
*/
protected function rest_create(array $body, array $filters)
{
$result = $this->client->performHttpCall(
self::REST_CREATE,
$this->getResourcePath() . $this->buildQueryString($filters),
$this->parseRequestBody($body)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Sends a PATCH request to a single Mollie API object.
*
* @param string $id
* @param array $body
*
* @return mixed
* @throws ApiException
*/
protected function rest_update($id, array $body = [])
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_UPDATE,
"{$this->getResourcePath()}/{$id}",
$this->parseRequestBody($body)
);
if ($result == null) {
return null;
}
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Retrieves a single object from the REST API.
*
* @param string $id Id of the object to retrieve.
* @param array $filters
* @return mixed
* @throws ApiException
*/
protected function rest_read($id, array $filters)
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_READ,
"{$this->getResourcePath()}/{$id}" . $this->buildQueryString($filters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Sends a DELETE request to a single Mollie API object.
*
* @param string $id
* @param array $body
*
* @return mixed
* @throws ApiException
*/
protected function rest_delete($id, array $body = [])
{
if (empty($id)) {
throw new ApiException("Invalid resource id.");
}
$id = urlencode($id);
$result = $this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}/{$id}",
$this->parseRequestBody($body)
);
if ($result == null) {
return null;
}
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return BaseResource
*/
abstract protected function getResourceObject();
/**
* @param string $resourcePath
*/
public function setResourcePath($resourcePath)
{
$this->resourcePath = strtolower($resourcePath);
}
/**
* @return string
* @throws ApiException
*/
public function getResourcePath()
{
if (strpos($this->resourcePath, "_") !== false) {
[$parentResource, $childResource] = explode("_", $this->resourcePath, 2);
if (empty($this->parentId)) {
throw new ApiException("Subresource '{$this->resourcePath}' used without parent '$parentResource' ID.");
}
return "$parentResource/{$this->parentId}/$childResource";
}
return $this->resourcePath;
}
/**
* @param array $body
* @return null|string
*/
protected function parseRequestBody(array $body)
{
if (empty($body)) {
return null;
}
return @json_encode($body);
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Invoice;
use Mollie\Api\Resources\InvoiceCollection;
use Mollie\Api\Resources\LazyCollection;
class InvoiceEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "invoices";
/**
* Get the object that is used by this API. Every API uses one type of object.
*
* @return \Mollie\Api\Resources\BaseResource
*/
protected function getResourceObject()
{
return new Invoice($this->client);
}
/**
* Get the collection object that is used by this API. Every API uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return \Mollie\Api\Resources\BaseCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new InvoiceCollection($this->client, $count, $_links);
}
/**
* Retrieve an Invoice from Mollie.
*
* Will throw a ApiException if the invoice id is invalid or the resource cannot be found.
*
* @param string $invoiceId
* @param array $parameters
*
* @return Invoice
* @throws ApiException
*/
public function get($invoiceId, array $parameters = [])
{
return $this->rest_read($invoiceId, $parameters);
}
/**
* Retrieves a collection of Invoices from Mollie.
*
* @param string $from The first invoice ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return InvoiceCollection
* @throws ApiException
*/
public function page($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
/**
* This is a wrapper method for page
*
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection
* @throws ApiException
*/
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);
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Mandate;
use Mollie\Api\Resources\MandateCollection;
class MandateEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_mandates";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Mandate
*/
protected function getResourceObject()
{
return new Mandate($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return MandateCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new MandateCollection($this->client, $count, $_links);
}
/**
* @param Customer $customer
* @param array $options
* @param array $filters
*
* @return \Mollie\Api\Resources\Mandate
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Customer $customer, array $options = [], array $filters = [])
{
return $this->createForId($customer->id, $options, $filters);
}
/**
* @param string $customerId
* @param array $options
* @param array $filters
*
* @return \Mollie\Api\Resources\Mandate
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($customerId, array $options = [], array $filters = [])
{
$this->parentId = $customerId;
return parent::rest_create($options, $filters);
}
/**
* @param Customer $customer
* @param string $mandateId
* @param array $parameters
*
* @return \Mollie\Api\Resources\Mandate
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Customer $customer, $mandateId, array $parameters = [])
{
return $this->getForId($customer->id, $mandateId, $parameters);
}
/**
* @param string $customerId
* @param string $mandateId
* @param array $parameters
*
* @return \Mollie\Api\Resources\Mandate
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId($customerId, $mandateId, array $parameters = [])
{
$this->parentId = $customerId;
return parent::rest_read($mandateId, $parameters);
}
/**
* @param Customer $customer
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return \Mollie\Api\Resources\MandateCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = [])
{
return $this->listForId($customer->id, $from, $limit, $parameters);
}
/**
* Create an iterator for iterating over mandates for the given customer, retrieved from Mollie.
*
* @param Customer $customer
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* @param string $customerId
* @param string|null $from
* @param int|null $limit
* @param array $parameters
*
* @return \Mollie\Api\Resources\MandateCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId($customerId, $from = null, $limit = null, array $parameters = [])
{
$this->parentId = $customerId;
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 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);
}
/**
* @param Customer $customer
* @param string $mandateId
* @param array $data
*
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function revokeFor(Customer $customer, $mandateId, $data = [])
{
return $this->revokeForId($customer->id, $mandateId, $data);
}
/**
* @param string $customerId
* @param string $mandateId
* @param array $data
*
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function revokeForId($customerId, $mandateId, $data = [])
{
$this->parentId = $customerId;
return parent::rest_delete($mandateId, $data);
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\MethodCollection;
use Mollie\Api\Resources\ResourceFactory;
class MethodEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "methods";
/**
* @return Method
*/
protected function getResourceObject()
{
return new Method($this->client);
}
/**
* Retrieve all active methods. In test mode, this includes pending methods. The results are not paginated.
*
* @deprecated Use allActive() instead
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection
* @throws ApiException
*/
public function all(array $parameters = [])
{
return $this->allActive($parameters);
}
/**
* Retrieve all active methods for the organization. In test mode, this includes pending methods.
* The results are not paginated.
*
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection
* @throws ApiException
*/
public function allActive(array $parameters = [])
{
return parent::rest_list(null, null, $parameters);
}
/**
* Retrieve all available methods for the organization, including activated and not yet activated methods. The
* results are not paginated. Make sure to include the profileId parameter if using an OAuth Access Token.
*
* @param array $parameters Query string parameters.
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\MethodCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function allAvailable(array $parameters = [])
{
$url = 'methods/all' . $this->buildQueryString($parameters);
$result = $this->client->performHttpCall('GET', $url);
return ResourceFactory::createBaseResourceCollection(
$this->client,
Method::class,
$result->_embedded->methods,
$result->_links
);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return MethodCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new MethodCollection($count, $_links);
}
/**
* Retrieve a payment method from Mollie.
*
* Will throw a ApiException if the method id is invalid or the resource cannot be found.
*
* @param string $methodId
* @param array $parameters
* @return \Mollie\Api\Resources\Method
* @throws ApiException
*/
public function get($methodId, array $parameters = [])
{
if (empty($methodId)) {
throw new ApiException("Method ID is empty.");
}
return parent::rest_read($methodId, $parameters);
}
}

View File

@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Issuer;
class MethodIssuerEndpoint extends EndpointAbstract
{
protected $resourcePath = 'profiles_methods_issuers';
protected $profileId = null;
protected $methodId = null;
protected $issuerId = null;
/**
* @param string $profileId
* @param string $methodId
* @param string $issuerId
* @return Issuer
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function enable(string $profileId, string $methodId, string $issuerId)
{
$this->profileId = $profileId;
$this->methodId = $methodId;
$this->issuerId = $issuerId;
$response = $this->rest_create([], []);
$this->resetResourceIds();
return $response;
}
public function disable(string $profileId, string $methodId, string $issuerId)
{
$this->profileId = $profileId;
$this->methodId = $methodId;
return $this->rest_delete($issuerId);
}
protected function resetResourceIds()
{
$this->profileId = null;
$this->methodId = null;
$this->issuerId = null;
}
/**
* @return string
* @throws ApiException
*/
public function getResourcePath()
{
if (! $this->profileId) {
throw new ApiException("No profileId provided.");
}
if (! $this->methodId) {
throw new ApiException("No methodId provided.");
}
$path = "profiles/{$this->profileId}/methods/{$this->methodId}/issuers";
if ($this->issuerId) {
$path .= "/$this->issuerId";
}
return $path;
}
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Issuer
*/
protected function getResourceObject()
{
return new Issuer($this->client);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\BaseResource;
use Mollie\Api\Resources\Onboarding;
use Mollie\Api\Resources\ResourceFactory;
class OnboardingEndpoint extends EndpointAbstract
{
protected $resourcePath = "onboarding/me";
protected function getResourceCollectionObject($count, $links)
{
throw new \BadMethodCallException('not implemented');
}
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return BaseResource
*/
protected function getResourceObject()
{
return new Onboarding($this->client);
}
/**
* Retrieve the organization's onboarding status from Mollie.
*
* Will throw a ApiException if the resource cannot be found.
*
* @return Onboarding
* @throws ApiException
*/
public function get()
{
return $this->rest_read('', []);
}
/**
* @deprecated 2023-05-01 For an alternative, see https://docs.mollie.com/reference/create-client-link .
* Submit data that will be prefilled in the merchants onboarding.
* Please note that the data you submit will only be processed when the onboarding status is needs-data.
*
* Information that the merchant has entered in their dashboard will not be overwritten.
*
* Will throw an ApiException if the resource cannot be found.
* @throws ApiException
*/
public function submit(array $parameters = [])
{
return $this->rest_create($parameters, []);
}
/**
* @param string $id
* @param array $filters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected function rest_read($id, array $filters)
{
$result = $this->client->performHttpCall(
self::REST_READ,
$this->getResourcePath() . $this->buildQueryString($filters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* @param array $body
* @param array $filters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected function rest_create(array $body, array $filters)
{
$this->client->performHttpCall(
self::REST_CREATE,
$this->getResourcePath() . $this->buildQueryString($filters),
$this->parseRequestBody($body)
);
}
}

View File

@@ -0,0 +1,146 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\OrderCollection;
class OrderEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'ord_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return Order
*/
protected function getResourceObject()
{
return new Order($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return OrderCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new OrderCollection($this->client, $count, $_links);
}
/**
* Creates a order in Mollie.
*
* @param array $data An array containing details on the order.
* @param array $filters
*
* @return Order
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Update a specific Order resource
*
* Will throw a ApiException if the order id is invalid or the resource cannot be found.
*
* @param string $orderId
*
* @param array $data
* @return Order
* @throws ApiException
*/
public function update($orderId, array $data = [])
{
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 . "'.");
}
return parent::rest_update($orderId, $data);
}
/**
* Retrieve a single order from Mollie.
*
* Will throw a ApiException if the order id is invalid or the resource cannot
* be found.
*
* @param array $parameters
* @return Order
* @throws ApiException
*/
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 . "'.");
}
return parent::rest_read($orderId, $parameters);
}
/**
* Cancel the given Order.
*
* If the order was partially shipped, the status will be "completed" instead of
* "canceled".
* Will throw a ApiException if the order id is invalid or the resource cannot
* be found.
* Returns the canceled order with HTTP status 200.
*
* @param string $orderId
*
* @param array $parameters
* @return Order
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancel($orderId, $parameters = [])
{
return $this->rest_delete($orderId, $parameters);
}
/**
* Retrieves a collection of Orders from Mollie.
*
* @param string $from The first order ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return OrderCollection
* @throws ApiException
*/
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 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);
}
}

View File

@@ -0,0 +1,139 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\OrderLine;
use Mollie\Api\Resources\OrderLineCollection;
use Mollie\Api\Resources\ResourceFactory;
class OrderLineEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_lines";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'odl_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return OrderLine
*/
protected function getResourceObject()
{
return new OrderLine($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return OrderLineCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new OrderLineCollection($count, $_links);
}
/**
* Update a specific OrderLine resource.
*
* Will throw an ApiException if the order line id is invalid or the resource cannot be found.
*
* @param string|null $orderId
* @param string $orderlineId
*
* @param array $data
*
* @return \Mollie\Api\Resources\BaseResource|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update($orderId, $orderlineId, array $data = [])
{
$this->parentId = $orderId;
if (empty($orderlineId) || strpos($orderlineId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid order line ID: '{$orderlineId}'. An order line ID should start with '".self::RESOURCE_ID_PREFIX."'.");
}
return parent::rest_update($orderlineId, $data);
}
/**
* @param string $orderId
* @param array $operations
* @param array $parameters
* @return Order|\Mollie\Api\Resources\BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function updateMultiple(string $orderId, array $operations, array $parameters = [])
{
if (empty($orderId)) {
throw new ApiException("Invalid resource id.");
}
$this->parentId = $orderId;
$parameters['operations'] = $operations;
$result = $this->client->performHttpCall(
self::REST_UPDATE,
"{$this->getResourcePath()}",
$this->parseRequestBody($parameters)
);
return ResourceFactory::createFromApiResult($result, new Order($this->client));
}
/**
* Cancel lines for the provided order.
* The data array must contain a lines array.
* You can pass an empty lines array if you want to cancel all eligible lines.
* Returns null if successful.
*
* @param Order $order
* @param array $data
*
* @return null
* @throws ApiException
*/
public function cancelFor(Order $order, array $data)
{
return $this->cancelForId($order->id, $data);
}
/**
* Cancel lines for the provided order id.
* The data array must contain a lines array.
* You can pass an empty lines array if you want to cancel all eligible lines.
* Returns null if successful.
*
* @param string $orderId
* @param array $data
*
* @return null
* @throws ApiException
*/
public function cancelForId($orderId, array $data)
{
if (! isset($data['lines']) || ! is_array($data['lines'])) {
throw new ApiException("A lines array is required.");
}
$this->parentId = $orderId;
$this->client->performHttpCall(
self::REST_DELETE,
"{$this->getResourcePath()}",
$this->parseRequestBody($data)
);
return null;
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class OrderPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_payments";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'tr_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return \Mollie\Api\Resources\Payment
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return \Mollie\Api\Resources\PaymentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
/**
* Creates a payment in Mollie for a specific order.
*
* @param \Mollie\Api\Resources\Order $order
* @param array $data An array containing details on the order payment.
* @param array $filters
*
* @return \Mollie\Api\Resources\Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Order $order, array $data, array $filters = [])
{
return $this->createForId($order->id, $data, $filters);
}
/**
* Creates a payment in Mollie for a specific order ID.
*
* @param string $orderId
* @param array $data An array containing details on the order payment.
* @param array $filters
*
* @return \Mollie\Api\Resources\Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($orderId, array $data, array $filters = [])
{
$this->parentId = $orderId;
return $this->rest_create($data, $filters);
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class OrderRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_refunds";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Refund
*/
protected function getResourceObject()
{
return new Refund($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return RefundCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RefundCollection($this->client, $count, $_links);
}
/**
* Refund some order lines. You can provide an empty array for the
* "lines" data to refund all eligible lines for this order.
*
* @param Order $order
* @param array $data
* @param array $filters
*
* @return Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Order $order, array $data, array $filters = [])
{
return $this->createForId($order->id, $data, $filters);
}
/**
* Refund some order lines. You can provide an empty array for the
* "lines" data to refund all eligible lines for this order.
*
* @param string $orderId
* @param array $data
* @param array $filters
*
* @return \Mollie\Api\Resources\Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($orderId, array $data, array $filters = [])
{
$this->parentId = $orderId;
return parent::rest_create($data, $filters);
}
/**
* @param $orderId
* @param array $parameters
* @return RefundCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId($orderId, array $parameters = [])
{
$this->parentId = $orderId;
return parent::rest_list(null, null, $parameters);
}
/**
* @param \Mollie\Api\Resources\Order $order
* @param array $parameters
* @return \Mollie\Api\Resources\RefundCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageFor(Order $order, array $parameters = [])
{
return $this->pageForId($order->id, $parameters);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Organization;
use Mollie\Api\Resources\OrganizationCollection;
class OrganizationEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "organizations";
/**
* @return Organization
*/
protected function getResourceObject()
{
return new Organization($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return OrganizationCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new OrganizationCollection($this->client, $count, $_links);
}
/**
* Retrieve an organization from Mollie.
*
* Will throw a ApiException if the organization id is invalid or the resource cannot be found.
*
* @param string $organizationId
* @param array $parameters
* @return Organization
* @throws ApiException
*/
public function get($organizationId, array $parameters = [])
{
if (empty($organizationId)) {
throw new ApiException("Organization ID is empty.");
}
return parent::rest_read($organizationId, $parameters);
}
/**
* Retrieve the current organization from Mollie.
*
* @param array $parameters
* @return Organization
* @throws ApiException
*/
public function current(array $parameters = [])
{
return parent::rest_read('me', $parameters);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\BaseResource;
use Mollie\Api\Resources\Partner;
use Mollie\Api\Resources\ResourceFactory;
class OrganizationPartnerEndpoint extends EndpointAbstract
{
protected $resourcePath = "organizations/me/partner";
protected function getResourceCollectionObject($count, $links)
{
throw new \BadMethodCallException('not implemented');
}
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return BaseResource
*/
protected function getResourceObject()
{
return new Partner($this->client);
}
/**
* Retrieve details about the partner status of the currently authenticated organization.
*
* Will throw an ApiException if the resource cannot be found.
*
* @return Partner
* @throws ApiException
*/
public function get()
{
return $this->rest_read('', []);
}
/**
* @param string $id
* @param array $filters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected function rest_read($id, array $filters)
{
$result = $this->client->performHttpCall(
self::REST_READ,
$this->getResourcePath() . $this->buildQueryString($filters)
);
return ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Capture;
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
class PaymentCaptureEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_captures";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Capture
*/
protected function getResourceObject()
{
return new Capture($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return \Mollie\Api\Resources\CaptureCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new CaptureCollection($this->client, $count, $_links);
}
/**
* Creates a payment capture in Mollie.
*
* @param Payment $payment.
* @param array $data An array containing details on the capture.
* @param array $filters
*
* @return Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Payment $payment, array $data = [], array $filters = [])
{
return $this->createForId($payment->id, $data, $filters);
}
/**
* Creates a payment capture in Mollie.
*
* @param string $paymentId The payment's ID.
* @param array $data An array containing details on the capture.
* @param array $filters
*
* @return Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($paymentId, array $data = [], array $filters = [])
{
$this->parentId = $paymentId;
return $this->rest_create($data, $filters);
}
/**
* @param Payment $payment
* @param string $captureId
* @param array $parameters
*
* @return Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Payment $payment, $captureId, array $parameters = [])
{
return $this->getForId($payment->id, $captureId, $parameters);
}
/**
* @param string $paymentId
* @param string $captureId
* @param array $parameters
*
* @return \Mollie\Api\Resources\Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId($paymentId, $captureId, array $parameters = [])
{
$this->parentId = $paymentId;
return parent::rest_read($captureId, $parameters);
}
/**
* @param Payment $payment
* @param array $parameters
*
* @return Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* @param string $paymentId
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Capture
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId($paymentId, array $parameters = [])
{
$this->parentId = $paymentId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $paymentId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
class PaymentChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_chargebacks";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Chargeback
*/
protected function getResourceObject()
{
return new Chargeback($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return ChargebackCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ChargebackCollection($this->client, $count, $_links);
}
/**
* @param Payment $payment
* @param string $chargebackId
* @param array $parameters
*
* @return Chargeback
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Payment $payment, $chargebackId, array $parameters = [])
{
return $this->getForId($payment->id, $chargebackId, $parameters);
}
/**
* @param string $paymentId
* @param string $chargebackId
* @param array $parameters
*
* @return Chargeback
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId($paymentId, $chargebackId, array $parameters = [])
{
$this->parentId = $paymentId;
return parent::rest_read($chargebackId, $parameters);
}
/**
* @param Payment $payment
* @param array $parameters
*
* @return Chargeback
* @throws \Mollie\Api\Exceptions\ApiException
*/
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* @param string $paymentId
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Chargeback
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId($paymentId, array $parameters = [])
{
$this->parentId = $paymentId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $paymentId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,201 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\ResourceFactory;
class PaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'tr_';
/**
* @return Payment
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PaymentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
/**
* Creates a payment in Mollie.
*
* @param array $data An array containing details on the payment.
* @param array $filters
*
* @return Payment
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Update the given Payment.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
*
* @param string $paymentId
*
* @param array $data
* @return Payment
* @throws ApiException
*/
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 . "'.");
}
return parent::rest_update($paymentId, $data);
}
/**
* Retrieve a single payment from Mollie.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
*
* @param string $paymentId
* @param array $parameters
* @return Payment
* @throws ApiException
*/
public function get($paymentId, array $parameters = [])
{
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 . "'.");
}
return parent::rest_read($paymentId, $parameters);
}
/**
* Deletes the given Payment.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
* Returns with HTTP status No Content (204) if successful.
*
* @param string $paymentId
*
* @param array $data
* @return Payment
* @throws ApiException
*/
public function delete($paymentId, array $data = [])
{
return $this->rest_delete($paymentId, $data);
}
/**
* Cancel the given Payment. This is just an alias of the 'delete' method.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
* Returns with HTTP status No Content (204) if successful.
*
* @param string $paymentId
*
* @param array $data
* @return Payment
* @throws ApiException
*/
public function cancel($paymentId, array $data = [])
{
return $this->rest_delete($paymentId, $data);
}
/**
* Retrieves a collection of Payments from Mollie.
*
* @param string $from The first payment ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return PaymentCollection
* @throws ApiException
*/
public function page($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 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);
}
/**
* Issue a refund for the given payment.
*
* The $data parameter may either be an array of endpoint parameters, a float value to
* initiate a partial refund, or empty to do a full refund.
*
* @param Payment $payment
* @param array|float|null $data
*
* @return Refund
* @throws ApiException
*/
public function refund(Payment $payment, $data = [])
{
$resource = "{$this->getResourcePath()}/" . urlencode($payment->id) . "/refunds";
$body = null;
if (($data === null ? 0 : count($data)) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Refund($this->client));
}
/**
* Release the authorization for the given payment.
*
* @param Payment|string $paymentId
*
* @return void
* @throws ApiException
*/
public function releaseAuthorization($paymentId): void
{
$paymentId = $paymentId instanceof Payment ? $paymentId->id : $paymentId;
$resource = "{$this->getResourcePath()}/" . urlencode($paymentId) . "/release-authorization";
$this->client->performHttpCall(self::REST_CREATE, $resource);
}
}

View File

@@ -0,0 +1,136 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\PaymentLink;
use Mollie\Api\Resources\PaymentLinkCollection;
class PaymentLinkEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payment-links";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'pl_';
/**
* Update a Payment Link.
*
* @param string $paymentLinkId
* @param array $data
* @return PaymentLink
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update(string $paymentLinkId, array $data)
{
if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentLinkId}'. A Payment Link ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return $this->rest_update($paymentLinkId, $data);
}
/**
* Delete a Payment Link.
*
* @param string $paymentLinkId
* @param array $data
* @return void
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function delete(string $paymentLinkId, array $data = [])
{
if (empty($paymentLinkId) || strpos($paymentLinkId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid payment ID: '{$paymentLinkId}'. A Payment Link ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
$this->rest_delete($paymentLinkId, $data);
}
/**
* @return PaymentLink
*/
protected function getResourceObject()
{
return new PaymentLink($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PaymentLinkCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentLinkCollection($this->client, $count, $_links);
}
/**
* Creates a payment link in Mollie.
*
* @param array $data An array containing details on the payment link.
* @param array $filters
*
* @return PaymentLink
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Retrieve payment link from Mollie.
*
* Will throw a ApiException if the payment link id is invalid or the resource cannot be found.
*
* @param string $paymentLinkId
* @param array $parameters
* @return PaymentLink
* @throws ApiException
*/
public function get($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 . "'.");
}
return parent::rest_read($paymentLinkId, $parameters);
}
/**
* Retrieves a collection of Payment Links from Mollie.
*
* @param string $from The first payment link ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return PaymentLinkCollection
* @throws ApiException
*/
public function page($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 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);
}
}

View File

@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\PaymentLink;
class PaymentLinkPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = 'payment-links_payments';
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, array $filters = [])
{
$this->parentId = $paymentLinkId;
return $this->rest_list($from, $limit, $filters);
}
public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, array $filters = [])
{
return $this->pageForId($paymentLink->id, $from, $limit, $filters);
}
/**
* Create an iterator for iterating over payments associated with the provided Payment Link id, retrieved from Mollie.
*
* @param string $paymentLinkId
* @param string|null $from The first resource ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(
string $paymentLinkId,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
$this->parentId = $paymentLinkId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over payments associated with the provided Payment Link object, retrieved from Mollie.
*
* @param PaymentLink $paymentLink
* @param string|null $from The first resource ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(
PaymentLink $paymentLink,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId(
$paymentLink->id,
$from,
$limit,
$parameters,
$iterateBackwards
);
}
}

View File

@@ -0,0 +1,200 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class PaymentRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_refunds";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Refund
*/
protected function getResourceObject()
{
return new Refund($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return RefundCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RefundCollection($this->client, $count, $_links);
}
/**
* @param Payment $payment
* @param string $refundId
* @param array $parameters
*
* @return Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Payment $payment, $refundId, array $parameters = [])
{
return $this->getForId($payment->id, $refundId, $parameters);
}
/**
* @param string $paymentId
* @param string $refundId
* @param array $parameters
*
* @return \Mollie\Api\Resources\Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId($paymentId, $refundId, array $parameters = [])
{
$this->parentId = $paymentId;
return parent::rest_read($refundId, $parameters);
}
/**
* @param Payment $payment
* @param array $parameters
*
* @return Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
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|null $from The first resource ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Payment $payment, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* @param string $paymentId
* @param array $parameters
*
* @return \Mollie\Api\Resources\BaseCollection|\Mollie\Api\Resources\Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId($paymentId, array $parameters = [])
{
$this->parentId = $paymentId;
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|null $from The first resource ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $paymentId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $paymentId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
/**
* Creates a refund for a specific payment.
*
* @param Payment $payment
* @param array $data
* @param array $filters
*
* @return Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Payment $payment, array $data, array $filters = [])
{
return $this->createForId($payment->id, $data, $filters);
}
/**
* Creates a refund for a specific payment.
*
* @param string $paymentId
* @param array $data
* @param array $filters
*
* @return \Mollie\Api\Resources\Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId(string $paymentId, array $data, array $filters = [])
{
$this->parentId = $paymentId;
return parent::rest_create($data, $filters);
}
/**
* @param \Mollie\Api\Resources\Payment $payment
* @param string $refundId
* @param array $parameters
* @return null
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancelForPayment(Payment $payment, string $refundId, array $parameters = [])
{
$this->parentId = $payment->id;
return $this->cancelForId($payment->id, $refundId, $parameters);
}
/**
* @param string $paymentId
* @param string $refundId
* @param array $parameters
* @return null
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancelForId(string $paymentId, string $refundId, array $parameters = [])
{
$this->parentId = $paymentId;
$body = null;
if (count($parameters) > 0) {
$body = json_encode($parameters);
}
$this->client->performHttpCall(
EndpointAbstract::REST_DELETE,
$this->getResourcePath() . '/' . $refundId,
$body
);
$this->getResourcePath();
return null;
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Route;
use Mollie\Api\Resources\RouteCollection;
class PaymentRouteEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "payments_routes";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return \Mollie\Api\Resources\Route
*/
protected function getResourceObject()
{
return new Route($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return \Mollie\Api\Resources\RouteCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RouteCollection($this->client, $count, $_links);
}
/**
* @param Payment $payment
* @param string $routeId
* @param string $releaseDate - UTC datetime in ISO-8601 format when the funds for the following payment will become available on
* the balance of the connected account
*
* @return Route
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function updateReleaseDateFor(Payment $payment, $routeId, $releaseDate)
{
return $this->updateReleaseDateForPaymentId($payment->id, $routeId, $releaseDate);
}
/**
* @param string $paymentId
* @param string $routeId
* @param string $releaseDate - UTC datetime in ISO-8601 format when the funds for the following payment will become available on
* the balance of the connected account
*
* @return \Mollie\Api\Resources\Route
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function updateReleaseDateForPaymentId($paymentId, $routeId, $releaseDate, $testmode = false)
{
$this->parentId = $paymentId;
$params = [
'releaseDate' => $releaseDate,
'testmode' => $testmode,
];
return parent::rest_update($routeId, $params);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Permission;
use Mollie\Api\Resources\PermissionCollection;
class PermissionEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "permissions";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return Permission
*/
protected function getResourceObject()
{
return new Permission($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PermissionCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PermissionCollection($count, $_links);
}
/**
* Retrieve a single Permission from Mollie.
*
* Will throw an ApiException if the permission id is invalid.
*
* @param string $permissionId
* @param array $parameters
* @return Permission
* @throws ApiException
*/
public function get($permissionId, array $parameters = [])
{
return $this->rest_read($permissionId, $parameters);
}
/**
* Retrieve all permissions.
*
* @param array $parameters
*
* @return PermissionCollection
* @throws ApiException
*/
public function all(array $parameters = [])
{
return parent::rest_list(null, null, $parameters);
}
}

View File

@@ -0,0 +1,159 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\CurrentProfile;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ProfileCollection;
class ProfileEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "profiles";
protected $resourceClass = Profile::class;
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'pfl_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Profile
*/
protected function getResourceObject()
{
return new $this->resourceClass($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return ProfileCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ProfileCollection($this->client, $count, $_links);
}
/**
* Creates a Profile in Mollie.
*
* @param array $data An array containing details on the profile.
* @param array $filters
*
* @return Profile
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Retrieve a Profile from Mollie.
*
* Will throw an ApiException if the profile id is invalid or the resource cannot be found.
*
* @param string $profileId
* @param array $parameters
*
* @return Profile
* @throws ApiException
*/
public function get($profileId, array $parameters = [])
{
if ($profileId === 'me') {
return $this->getCurrent($parameters);
}
return $this->rest_read($profileId, $parameters);
}
/**
* Update a specific Profile resource.
*
* Will throw an ApiException if the profile id is invalid or the resource cannot be found.
*
* @param string $profileId
*
* @param array $data
* @return Profile
* @throws ApiException
*/
public function update($profileId, array $data = [])
{
if (empty($profileId) || strpos($profileId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid profile ID: '{$profileId}'. A profile ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_update($profileId, $data);
}
/**
* Retrieve the current Profile from Mollie.
*
* @param array $parameters
*
* @return CurrentProfile
* @throws ApiException
*/
public function getCurrent(array $parameters = [])
{
$this->resourceClass = CurrentProfile::class;
return $this->rest_read('me', $parameters);
}
/**
* Delete a Profile from Mollie.
*
* Will throw a ApiException if the profile id is invalid or the resource cannot be found.
* Returns with HTTP status No Content (204) if successful.
*
* @param string $profileId
*
* @param array $data
* @return Profile
* @throws ApiException
*/
public function delete($profileId, array $data = [])
{
return $this->rest_delete($profileId, $data);
}
/**
* Retrieves a collection of Profiles from Mollie.
*
* @param string $from The first profile ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return ProfileCollection
* @throws ApiException
*/
public function page($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 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);
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\MethodCollection;
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ResourceFactory;
class ProfileMethodEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "profiles_methods";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Method
*/
protected function getResourceObject()
{
return new Method($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return MethodCollection()
*/
protected function getResourceCollectionObject($count, $_links)
{
return new MethodCollection($count, $_links);
}
/**
* Enable a method for the provided Profile ID.
*
* @param string $profileId
* @param string $methodId
* @param array $data
* @return \Mollie\Api\Resources\Method
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
$resource = $this->getResourcePath() . '/' . urlencode($methodId);
$body = null;
if (count($data) > 0) {
$body = json_encode($data);
}
$result = $this->client->performHttpCall(self::REST_CREATE, $resource, $body);
return ResourceFactory::createFromApiResult($result, new Method($this->client));
}
/**
* Enable a method for the provided Profile object.
*
* @param Profile $profile
* @param string $methodId
* @param array $data
* @return Method
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor($profile, $methodId, array $data = [])
{
return $this->createForId($profile->id, $methodId, $data);
}
/**
* Enable a method for the current profile.
*
* @param string $methodId
* @param array $data
* @return \Mollie\Api\Resources\Method
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForCurrentProfile($methodId, array $data = [])
{
return $this->createForId('me', $methodId, $data);
}
/**
* Disable a method for the provided Profile ID.
*
* @param string $profileId
* @param string $methodId
* @param array $data
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function deleteForId($profileId, $methodId, array $data = [])
{
$this->parentId = $profileId;
return $this->rest_delete($methodId, $data);
}
/**
* Disable a method for the provided Profile object.
*
* @param Profile $profile
* @param string $methodId
* @param array $data
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function deleteFor($profile, $methodId, array $data = [])
{
return $this->deleteForId($profile->id, $methodId, $data);
}
/**
* Disable a method for the current profile.
*
* @param string $methodId
* @param array $data
* @return \Mollie\Api\Resources\Method
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function deleteForCurrentProfile($methodId, array $data)
{
return $this->deleteForId('me', $methodId, $data);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class RefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "refunds";
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Refund
*/
protected function getResourceObject()
{
return new Refund($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return RefundCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RefundCollection($this->client, $count, $_links);
}
/**
* Retrieves a collection of Refunds from Mollie.
*
* @param string $from The first refund ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return RefundCollection
* @throws ApiException
*/
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 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);
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\SalesInvoice;
use Mollie\Api\Resources\SalesInvoiceCollection;
class SalesInvoiceEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "sales-invoices";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'invoice_';
/**
* @return SalesInvoice
*/
protected function getResourceObject(): SalesInvoice
{
return new SalesInvoice($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return SalesInvoiceCollection
*/
protected function getResourceCollectionObject($count, $_links): SalesInvoiceCollection
{
return new SalesInvoiceCollection($this->client, $count, $_links);
}
/**
* Creates a payment in Mollie.
*
* @param array $data An array containing details on the payment.
*
* @return SalesInvoice
* @throws ApiException
*/
public function create(array $data = []): SalesInvoice
{
return $this->rest_create($data, []);
}
/**
* Update the given Payment.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
*
* @param string $salesInvoiceId
*
* @param array $data
* @return SalesInvoice
* @throws ApiException
*/
public function update($salesInvoiceId, array $data = []): SalesInvoice
{
if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_update($salesInvoiceId, $data);
}
/**
* @param string $salesInvoiceId
* @param array $parameters
* @return SalesInvoice
* @throws ApiException
*/
public function get($salesInvoiceId, array $parameters = []): SalesInvoice
{
if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_read($salesInvoiceId, $parameters);
}
/**
* @param string $salesInvoiceId
*
* @param array $data
* @throws ApiException
*/
public function delete($salesInvoiceId, array $data = []): void
{
$this->rest_delete($salesInvoiceId, $data);
}
/**
* @param string $from The first payment ID you want to include in your list.
* @param int $limit
*
* @return SalesInvoiceCollection
* @throws ApiException
*/
public function page($from = null, $limit = null)
{
return $this->rest_list($from, $limit, []);
}
/**
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, [], $iterateBackwards);
}
}

View File

@@ -0,0 +1,139 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Session;
use Mollie\Api\Resources\SessionCollection;
class SessionEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "sessions";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'sess_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one
* type of object.
*
* @return Session
*/
protected function getResourceObject()
{
return new Session($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return SessionCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new SessionCollection($this->client, $count, $_links);
}
/**
* Creates a session in Mollie.
*
* @param array $data An array containing details on the session.
* @param array $filters
*
* @return Session
* @throws ApiException
*/
public function create(array $data = [], array $filters = [])
{
return $this->rest_create($data, $filters);
}
/**
* Update a specific Session resource
*
* Will throw a ApiException if the resource id is invalid or the resource cannot be found.
*
* @param string $resourceId
*
* @param array $data
* @return Session
* @throws ApiException
*/
public function update($resourceId, array $data = [])
{
if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_update($resourceId, $data);
}
/**
* Retrieve a single session from Mollie.
*
* Will throw a ApiException if the resource id is invalid or the resource cannot
* be found.
*
* @param array $parameters
* @return Session
* @throws ApiException
*/
public function get($resourceId, array $parameters = [])
{
if (empty($resourceId) || strpos($resourceId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid session ID: '{$resourceId}'. A session ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_read($resourceId, $parameters);
}
/**
* Cancel the given Session.
*
* @param string $resourceId
* @param array $parameters
* @return Session
* @throws ApiException
*/
public function cancel($resourceId, $parameters = [])
{
return $this->rest_delete($resourceId, $parameters);
}
/**
* Retrieves a collection of Sessions from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return SessionCollection
* @throws ApiException
*/
public function page(?string $from = null, ?int $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
/**
* Create an iterator for iterating over sessions retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
* @param bool $iterateBackwards Set to true for reverse resource iteration (default is false).
*
* @return LazyCollection
*/
public function iterator(?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Capture;
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\LazyCollection;
class SettlementCaptureEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_captures";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Capture($this->client);
}
protected function getResourceCollectionObject($count, $_links)
{
return new CaptureCollection($this->client, $count, $_links);
}
/**
* Retrieves a collection of Settlement Captures from Mollie.
*
* @param string $settlementId
* @param string|null $from The first capture ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $settlementId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
class SettlementChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_chargebacks";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Chargeback($this->client);
}
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ChargebackCollection($this->client, $count, $_links);
}
/**
* Retrieves a collection of Settlement Chargebacks from Mollie.
*
* @param string $settlementId
* @param string|null $from The first chargeback ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $settlementId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class SettlementPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_payments";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
/**
* Retrieves a collection of Payments from Mollie.
*
* @param string $settlementId
* @param string $from The first payment ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId($settlementId, $from = null, $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $settlementId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class SettlementRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_refunds";
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RefundCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Refund($this->client);
}
/**
* Retrieves a collection of Settlement Refunds from Mollie.
*
* @param string $settlementId
* @param string|null $from The first refund ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorForId(string $settlementId, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
$this->parentId = $settlementId;
return $this->rest_iterator($from, $limit, $parameters, $iterateBackwards);
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Resources\SettlementCollection;
class SettlementsEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements";
/**
* Get the object that is used by this API. Every API uses one type of object.
*
* @return \Mollie\Api\Resources\BaseResource
*/
protected function getResourceObject()
{
return new Settlement($this->client);
}
/**
* Get the collection object that is used by this API. Every API uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return \Mollie\Api\Resources\BaseCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new SettlementCollection($this->client, $count, $_links);
}
/**
* Retrieve a single settlement from Mollie.
*
* Will throw a ApiException if the settlement id is invalid or the resource cannot be found.
*
* @param string $settlementId
* @param array $parameters
* @return Settlement
* @throws ApiException
*/
public function get($settlementId, array $parameters = [])
{
return parent::rest_read($settlementId, $parameters);
}
/**
* Retrieve the details of the current settlement that has not yet been paid out.
*
* @return Settlement
* @throws ApiException
*/
public function next()
{
return parent::rest_read("next", []);
}
/**
* Retrieve the details of the open balance of the organization.
*
* @return Settlement
* @throws ApiException
*/
public function open()
{
return parent::rest_read("open", []);
}
/**
* Retrieves a collection of Settlements from Mollie.
*
* @param string $from The first settlement ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return SettlementCollection
* @throws ApiException
*/
public function page($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 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);
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Shipment;
use Mollie\Api\Resources\ShipmentCollection;
class ShipmentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "orders_shipments";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'shp_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Shipment
*/
protected function getResourceObject()
{
return new Shipment($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API
* endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return ShipmentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ShipmentCollection($count, $_links);
}
/**
* Create a shipment for some order lines. You can provide an empty array for the
* "lines" option to include all unshipped lines for this order.
*
* @param Order $order
* @param array $options
* @param array $filters
*
* @return Shipment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createFor(Order $order, array $options = [], array $filters = [])
{
return $this->createForId($order->id, $options, $filters);
}
/**
* Create a shipment for some order lines. You can provide an empty array for the
* "lines" option to include all unshipped lines for this order.
*
* @param string $orderId
* @param array $options
* @param array $filters
*
* @return Shipment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createForId($orderId, array $options = [], array $filters = [])
{
$this->parentId = $orderId;
return parent::rest_create($options, $filters);
}
/**
* Retrieve a single shipment and the order lines shipped by a shipments ID.
*
* @param Order $order
* @param string $shipmentId
* @param array $parameters
*
* @return Shipment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(Order $order, $shipmentId, array $parameters = [])
{
return $this->getForId($order->id, $shipmentId, $parameters);
}
/**
* Retrieve a single shipment and the order lines shipped by a shipments ID.
*
* @param string $orderId
* @param string $shipmentId
* @param array $parameters
*
* @return \Mollie\Api\Resources\Shipment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getForId($orderId, $shipmentId, array $parameters = [])
{
$this->parentId = $orderId;
return parent::rest_read($shipmentId, $parameters);
}
/**
* Update a specific Order Shipment resource.
*
* Will throw an ApiException if the shipment id is invalid or the resource cannot be found.
*
* @param string $shipmentId
* @param string $orderId
*
* @param array $data
* @return Shipment
* @throws ApiException
*/
public function update($orderId, $shipmentId, array $data = [])
{
if (empty($shipmentId) || strpos($shipmentId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid shipment ID: '{$shipmentId}'. A shipment ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
$this->parentId = $orderId;
return parent::rest_update($shipmentId, $data);
}
/**
* Return all shipments for the Order provided.
*
* @param Order $order
* @param array $parameters
*
* @return ShipmentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listFor(Order $order, array $parameters = [])
{
return $this->listForId($order->id, $parameters);
}
/**
* Return all shipments for the provided Order id.
*
* @param string $orderId
* @param array $parameters
*
* @return \Mollie\Api\Resources\ShipmentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function listForId($orderId, array $parameters = [])
{
$this->parentId = $orderId;
return parent::rest_list(null, null, $parameters);
}
}

View File

@@ -0,0 +1,264 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\ResourceFactory;
use Mollie\Api\Resources\Subscription;
use Mollie\Api\Resources\SubscriptionCollection;
class SubscriptionEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_subscriptions";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'sub_';
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Subscription
*/
protected function getResourceObject()
{
return new Subscription($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return SubscriptionCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new SubscriptionCollection($this->client, $count, $_links);
}
/**
* Create a subscription for a Customer
*
* @param Customer $customer
* @param array $options
* @param array $filters
*
* @return Subscription
* @throws ApiException
*/
public function createFor(Customer $customer, array $options = [], array $filters = [])
{
return $this->createForId($customer->id, $options, $filters);
}
/**
* Create a subscription for a Customer
*
* @param string $customerId
* @param array $options
* @param array $filters
*
* @return Subscription
* @throws ApiException
*/
public function createForId($customerId, array $options = [], array $filters = [])
{
$this->parentId = $customerId;
return parent::rest_create($options, $filters);
}
/**
* Update a specific Subscription resource.
*
* Will throw an ApiException if the subscription id is invalid or the resource cannot be found.
*
* @param string $subscriptionId
* @param string $customerId
*
* @param array $data
*
* @return Subscription
* @throws ApiException
*/
public function update($customerId, $subscriptionId, array $data = [])
{
if (empty($subscriptionId) || strpos($subscriptionId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid subscription ID: '{$subscriptionId}'. A subscription ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
$this->parentId = $customerId;
return parent::rest_update($subscriptionId, $data);
}
/**
* @param Customer $customer
* @param string $subscriptionId
* @param array $parameters
*
* @return Subscription
* @throws ApiException
*/
public function getFor(Customer $customer, $subscriptionId, array $parameters = [])
{
return $this->getForId($customer->id, $subscriptionId, $parameters);
}
/**
* @param string $customerId
* @param string $subscriptionId
* @param array $parameters
*
* @return Subscription
* @throws ApiException
*/
public function getForId($customerId, $subscriptionId, array $parameters = [])
{
$this->parentId = $customerId;
return parent::rest_read($subscriptionId, $parameters);
}
/**
* @param Customer $customer
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return SubscriptionCollection
* @throws ApiException
*/
public function listFor(Customer $customer, $from = null, $limit = null, array $parameters = [])
{
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 bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @return LazyCollection
*/
public function iteratorFor(Customer $customer, ?string $from = null, ?int $limit = null, array $parameters = [], bool $iterateBackwards = false): LazyCollection
{
return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* @param string $customerId
* @param string $from The first resource ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return SubscriptionCollection
* @throws ApiException
*/
public function listForId($customerId, $from = null, $limit = null, array $parameters = [])
{
$this->parentId = $customerId;
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 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);
}
/**
* @param Customer $customer
* @param string $subscriptionId
* @param array $data
*
* @return Subscription
* @throws ApiException
*/
public function cancelFor(Customer $customer, $subscriptionId, array $data = [])
{
return $this->cancelForId($customer->id, $subscriptionId, $data);
}
/**
* @param string $customerId
* @param string $subscriptionId
* @param array $data
*
* @return Subscription
* @throws ApiException
*/
public function cancelForId($customerId, $subscriptionId, array $data = [])
{
$this->parentId = $customerId;
return parent::rest_delete($subscriptionId, $data);
}
/**
* Retrieves a collection of Subscriptions from Mollie.
*
* @param string $from The first payment ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return SubscriptionCollection
* @throws ApiException
*/
public function page($from = null, $limit = null, array $parameters = [])
{
$filters = array_merge(["from" => $from, "limit" => $limit], $parameters);
$apiPath = 'subscriptions' . $this->buildQueryString($filters);
$result = $this->client->performHttpCall(self::REST_LIST, $apiPath);
/** @var SubscriptionCollection $collection */
$collection = $this->getResourceCollectionObject($result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
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 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
{
$page = $this->page($from, $limit, $parameters);
return $page->getAutoIterator($iterateBackwards);
}
}

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class SubscriptionPaymentEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "customers_subscriptions_payments";
protected $customerId = null;
protected $subscriptionId = null;
/**
* Retrieves a paginated collection of Subscription Payments from Mollie.
*
* @param string $customerId
* @param string $subscriptionId
* @param string|null $from The first payment ID you want to include in your list.
* @param int|null $limit The maximum amount of results you want to retrieve per page.
* @param array $parameters
*
* @return PaymentCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForIds(
string $customerId,
string $subscriptionId,
?string $from = null,
?int $limit = null,
array $parameters = []
) {
$this->customerId = $customerId;
$this->subscriptionId = $subscriptionId;
return $this->rest_list($from, $limit, $parameters);
}
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return Payment
*/
protected function getResourceObject()
{
return new Payment($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return PaymentCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new PaymentCollection($this->client, $count, $_links);
}
public function getResourcePath()
{
if (is_null($this->customerId)) {
throw new ApiException('No customerId provided.');
}
if (is_null($this->subscriptionId)) {
throw new ApiException('No subscriptionId provided.');
}
return "customers/{$this->customerId}/subscriptions/{$this->subscriptionId}/payments";
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Terminal;
use Mollie\Api\Resources\TerminalCollection;
class TerminalEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "terminals";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'term_';
/**
* @return Terminal
*/
protected function getResourceObject()
{
return new Terminal($this->client);
}
/**
* Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object.
*
* @param int $count
* @param \stdClass $_links
*
* @return TerminalCollection
*/
protected function getResourceCollectionObject($count, $_links)
{
return new TerminalCollection($this->client, $count, $_links);
}
/**
* Retrieve terminal from Mollie.
*
* Will throw a ApiException if the terminal id is invalid or the resource cannot be found.
*
* @param string $terminalId
* @param array $parameters
* @return Terminal
* @throws ApiException
*/
public function get($terminalId, array $parameters = [])
{
if (empty($terminalId) || strpos($terminalId, self::RESOURCE_ID_PREFIX) !== 0) {
throw new ApiException("Invalid terminal ID: '{$terminalId}'. A terminal ID should start with '" . self::RESOURCE_ID_PREFIX . "'.");
}
return parent::rest_read($terminalId, $parameters);
}
/**
* Retrieves a collection of Terminals from Mollie for the current organization / profile, ordered from newest to oldest.
*
* @param string $from The first terminal ID you want to include in your list.
* @param int $limit
* @param array $parameters
*
* @return TerminalCollection
* @throws ApiException
*/
public function page($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 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);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\BaseResource;
class WalletEndpoint extends EndpointAbstract
{
/**
* Get the object that is used by this API endpoint. Every API endpoint uses one type of object.
*
* @return void|BaseResource
*/
protected function getResourceObject()
{
// Not used
}
/**
* Obtain a new ApplePay payment session.
*
* @param string $domain
* @param string $validationUrl
* @param array $parameters
*
* @return false|string
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function requestApplePayPaymentSession($domain, $validationUrl, $parameters = [])
{
$body = $this->parseRequestBody(array_merge([
'domain' => $domain,
'validationUrl' => $validationUrl,
], $parameters));
$response = $this->client->performHttpCall(
self::REST_CREATE,
'wallets/applepay/sessions',
$body
);
return json_encode($response);
}
}