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,59 @@
<?php
namespace Mollie\Api;
use Mollie\Api\Exceptions\IncompatiblePlatform;
class CompatibilityChecker
{
/**
* @var string
*/
public const MIN_PHP_VERSION = "7.2";
/**
* @throws IncompatiblePlatform
* @return void
*/
public function checkCompatibility()
{
if (! $this->satisfiesPhpVersion()) {
throw new IncompatiblePlatform(
"The client requires PHP version >= " . self::MIN_PHP_VERSION . ", you have " . PHP_VERSION . ".",
IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION
);
}
if (! $this->satisfiesJsonExtension()) {
throw new IncompatiblePlatform(
"PHP extension json is not enabled. Please make sure to enable 'json' in your PHP configuration.",
IncompatiblePlatform::INCOMPATIBLE_JSON_EXTENSION
);
}
}
/**
* @return bool
* @codeCoverageIgnore
*/
public function satisfiesPhpVersion()
{
return (bool)version_compare(PHP_VERSION, self::MIN_PHP_VERSION, ">=");
}
/**
* @return bool
* @codeCoverageIgnore
*/
public function satisfiesJsonExtension()
{
// Check by extension_loaded
if (function_exists('extension_loaded') && extension_loaded('json')) {
return true;
} elseif (function_exists('json_encode')) {
return true;
}
return false;
}
}

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);
}
}

View File

@@ -0,0 +1,244 @@
<?php
namespace Mollie\Api\Exceptions;
use DateTime;
class ApiException extends \Exception
{
/**
* @var string
*/
protected $field;
/**
* @var string
*/
protected $plainMessage;
/**
* @var \Psr\Http\Message\RequestInterface|null
*/
protected $request;
/**
* @var \Psr\Http\Message\ResponseInterface|null
*/
protected $response;
/**
* ISO8601 representation of the moment this exception was thrown
*
* @var \DateTimeImmutable
*/
protected $raisedAt;
/**
* @var array
*/
protected $links = [];
/**
* @param string $message
* @param int $code
* @param string|null $field
* @param \Psr\Http\Message\RequestInterface|null $request
* @param \Psr\Http\Message\ResponseInterface|null $response
* @param \Throwable|null $previous
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function __construct(
$message = "",
$code = 0,
$field = null,
$request = null,
$response = null,
$previous = null
) {
$this->plainMessage = $message;
$this->raisedAt = new \DateTimeImmutable();
$formattedRaisedAt = $this->raisedAt->format(DateTime::ISO8601);
$message = "[{$formattedRaisedAt}] " . $message;
if (! empty($field)) {
$this->field = (string)$field;
$message .= ". Field: {$this->field}";
}
if (! empty($response)) {
$this->response = $response;
$object = static::parseResponseBody($this->response);
if (isset($object->_links)) {
foreach ($object->_links as $key => $value) {
$this->links[$key] = $value;
}
}
}
if ($this->hasLink('documentation')) {
$message .= ". Documentation: {$this->getDocumentationUrl()}";
}
$this->request = $request;
if ($request) {
$requestBody = $request->getBody()->__toString();
if ($requestBody) {
$message .= ". Request body: {$requestBody}";
}
}
parent::__construct($message, $code, $previous);
}
/**
* @param \Psr\Http\Message\ResponseInterface $response
* @param \Psr\Http\Message\RequestInterface $request
* @param \Throwable|null $previous
* @return \Mollie\Api\Exceptions\ApiException
* @throws \Mollie\Api\Exceptions\ApiException
*/
public static function createFromResponse($response, $request = null, $previous = null)
{
$object = static::parseResponseBody($response);
$field = null;
if (! empty($object->field)) {
$field = $object->field;
}
return new self(
"Error executing API call ({$object->status}: {$object->title}): {$object->detail}",
$response->getStatusCode(),
$field,
$request,
$response,
$previous
);
}
/**
* @return string|null
*/
public function getField()
{
return $this->field;
}
/**
* @return string|null
*/
public function getDocumentationUrl()
{
return $this->getUrl('documentation');
}
/**
* @return string|null
*/
public function getDashboardUrl()
{
return $this->getUrl('dashboard');
}
/**
* @return \Psr\Http\Message\ResponseInterface|null
*/
public function getResponse()
{
return $this->response;
}
/**
* @return bool
*/
public function hasResponse()
{
return $this->response !== null;
}
/**
* @param string $key
* @return bool
*/
public function hasLink($key)
{
return array_key_exists($key, $this->links);
}
/**
* @param string $key
* @return mixed|null
*/
public function getLink($key)
{
if ($this->hasLink($key)) {
return $this->links[$key];
}
return null;
}
/**
* @param string $key
* @return null
*/
public function getUrl($key)
{
if ($this->hasLink($key)) {
return $this->getLink($key)->href;
}
return null;
}
/**
* @return \Psr\Http\Message\RequestInterface
*/
public function getRequest()
{
return $this->request;
}
/**
* Get the ISO8601 representation of the moment this exception was thrown
*
* @return \DateTimeImmutable
*/
public function getRaisedAt()
{
return $this->raisedAt;
}
/**
* @param \Psr\Http\Message\ResponseInterface $response
* @return \stdClass
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected static function parseResponseBody($response)
{
$body = (string) $response->getBody();
$object = @json_decode($body);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new self("Unable to decode Mollie response: '{$body}'.");
}
return $object;
}
/**
* Retrieve the plain exception message.
*
* @return string
*/
public function getPlainMessage()
{
return $this->plainMessage;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Mollie\Api\Exceptions;
class CurlConnectTimeoutException extends ApiException
{
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Mollie\Api\Exceptions;
class HttpAdapterDoesNotSupportDebuggingException extends ApiException
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Mollie\Api\Exceptions;
class IncompatiblePlatform extends ApiException
{
public const INCOMPATIBLE_PHP_VERSION = 1000;
public const INCOMPATIBLE_CURL_EXTENSION = 2000;
public const INCOMPATIBLE_CURL_FUNCTION = 2500;
public const INCOMPATIBLE_JSON_EXTENSION = 3000;
public const INCOMPATIBLE_RANDOM_BYTES_FUNCTION = 4000;
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Mollie\Api\Exceptions;
class UnrecognizedClientException extends ApiException
{
}

View File

@@ -0,0 +1,230 @@
<?php
namespace Mollie\Api\HttpAdapter;
use Composer\CaBundle\CaBundle;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Exceptions\CurlConnectTimeoutException;
use Mollie\Api\MollieApiClient;
final class CurlMollieHttpAdapter implements MollieHttpAdapterInterface
{
/**
* Default response timeout (in seconds).
*/
public const DEFAULT_TIMEOUT = 10;
/**
* Default connect timeout (in seconds).
*/
public const DEFAULT_CONNECT_TIMEOUT = 2;
/**
* The maximum number of retries
*/
public const MAX_RETRIES = 5;
/**
* The amount of milliseconds the delay is being increased with on each retry.
*/
public const DELAY_INCREASE_MS = 1000;
/**
* @param string $httpMethod
* @param string $url
* @param array $headers
* @param string $httpBody
* @return \stdClass|void|null
* @throws \Mollie\Api\Exceptions\ApiException
* @throws \Mollie\Api\Exceptions\CurlConnectTimeoutException
*/
public function send($httpMethod, $url, $headers, $httpBody)
{
for ($i = 0; $i <= self::MAX_RETRIES; $i++) {
usleep($i * self::DELAY_INCREASE_MS);
try {
return $this->attemptRequest($httpMethod, $url, $headers, $httpBody);
} catch (CurlConnectTimeoutException $e) {
// Nothing
}
}
throw new CurlConnectTimeoutException(
"Unable to connect to Mollie. Maximum number of retries (". self::MAX_RETRIES .") reached."
);
}
/**
* @param string $httpMethod
* @param string $url
* @param array $headers
* @param string $httpBody
* @return \stdClass|void|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected function attemptRequest($httpMethod, $url, $headers, $httpBody)
{
$curl = curl_init($url);
$headers["Content-Type"] = "application/json";
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->parseHeaders($headers));
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::DEFAULT_CONNECT_TIMEOUT);
curl_setopt($curl, CURLOPT_TIMEOUT, self::DEFAULT_TIMEOUT);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_CAINFO, CaBundle::getBundledCaBundlePath());
switch ($httpMethod) {
case MollieApiClient::HTTP_POST:
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody);
break;
case MollieApiClient::HTTP_GET:
break;
case MollieApiClient::HTTP_PATCH:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody);
break;
case MollieApiClient::HTTP_DELETE:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($curl, CURLOPT_POSTFIELDS, $httpBody);
break;
default:
throw new \InvalidArgumentException("Invalid http method: ". $httpMethod);
}
$startTime = microtime(true);
$response = curl_exec($curl);
$endTime = microtime(true);
if ($response === false) {
$executionTime = $endTime - $startTime;
$curlErrorNumber = curl_errno($curl);
$curlErrorMessage = "Curl error: " . curl_error($curl);
if ($this->isConnectTimeoutError($curlErrorNumber, $executionTime)) {
throw new CurlConnectTimeoutException("Unable to connect to Mollie. " . $curlErrorMessage);
}
throw new ApiException($curlErrorMessage);
}
$statusCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
return $this->parseResponseBody($response, $statusCode, $httpBody);
}
/**
* The version number for the underlying http client, if available.
* @example Guzzle/6.3
*
* @return string|null
*/
public function versionString()
{
return 'Curl/*';
}
/**
* Whether this http adapter provides a debugging mode. If debugging mode is enabled, the
* request will be included in the ApiException.
*
* @return false
*/
public function supportsDebugging()
{
return false;
}
/**
* @param int $curlErrorNumber
* @param string|float $executionTime
* @return bool
*/
protected function isConnectTimeoutError($curlErrorNumber, $executionTime)
{
$connectErrors = [
\CURLE_COULDNT_RESOLVE_HOST => true,
\CURLE_COULDNT_CONNECT => true,
\CURLE_SSL_CONNECT_ERROR => true,
\CURLE_GOT_NOTHING => true,
];
if (isset($connectErrors[$curlErrorNumber])) {
return true;
};
if ($curlErrorNumber === \CURLE_OPERATION_TIMEOUTED) {
if ($executionTime > self::DEFAULT_TIMEOUT) {
return false;
}
return true;
}
return false;
}
/**
* @param string $response
* @param int $statusCode
* @param string $httpBody
* @return \stdClass|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
protected function parseResponseBody($response, $statusCode, $httpBody)
{
if (empty($response) && $statusCode >= 200 && $statusCode < 300) {
return null;
}
$body = @json_decode($response);
// GUARDS
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ApiException("Unable to decode Mollie response: '{$response}'.");
}
if (isset($body->error)) {
throw new ApiException($body->error->message);
}
if ($statusCode >= 400) {
$message = "Error executing API call ({$body->status}: {$body->title}): {$body->detail}";
$field = null;
if (! empty($body->field)) {
$field = $body->field;
}
if (isset($body->_links, $body->_links->documentation)) {
$message .= ". Documentation: {$body->_links->documentation->href}";
}
if ($httpBody) {
$message .= ". Request body: {$httpBody}";
}
throw new ApiException($message, $statusCode, $field);
}
return $body;
}
protected function parseHeaders($headers)
{
$result = [];
foreach ($headers as $key => $value) {
$result[] = $key .': ' . $value;
}
return $result;
}
}

View File

@@ -0,0 +1,190 @@
<?php
namespace Mollie\Api\HttpAdapter;
use Composer\CaBundle\CaBundle;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions as GuzzleRequestOptions;
use Mollie\Api\Exceptions\ApiException;
use Psr\Http\Message\ResponseInterface;
final class Guzzle6And7MollieHttpAdapter implements MollieHttpAdapterInterface
{
/**
* Default response timeout (in seconds).
*/
public const DEFAULT_TIMEOUT = 10;
/**
* Default connect timeout (in seconds).
*/
public const DEFAULT_CONNECT_TIMEOUT = 2;
/**
* @var \GuzzleHttp\ClientInterface
*/
protected $httpClient;
/**
* Whether debugging is enabled. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*
* @var bool
*/
protected $debugging = false;
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}
/**
* Instantiate a default adapter with sane configuration for Guzzle 6 or 7.
*
* @return static
*/
public static function createDefault()
{
$retryMiddlewareFactory = new Guzzle6And7RetryMiddlewareFactory;
$handlerStack = HandlerStack::create();
$handlerStack->push($retryMiddlewareFactory->retry());
$client = new Client([
GuzzleRequestOptions::VERIFY => CaBundle::getBundledCaBundlePath(),
GuzzleRequestOptions::TIMEOUT => self::DEFAULT_TIMEOUT,
GuzzleRequestOptions::CONNECT_TIMEOUT => self::DEFAULT_CONNECT_TIMEOUT,
'handler' => $handlerStack,
]);
return new Guzzle6And7MollieHttpAdapter($client);
}
/**
* Send a request to the specified Mollie api url.
*
* @param string $httpMethod
* @param string $url
* @param array $headers
* @param string $httpBody
* @return \stdClass|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function send($httpMethod, $url, $headers, $httpBody)
{
$request = new Request($httpMethod, $url, $headers, $httpBody);
try {
$response = $this->httpClient->send($request, ['http_errors' => false]);
} catch (GuzzleException $e) {
// Prevent sensitive request data from ending up in exception logs unintended
if (! $this->debugging) {
$request = null;
}
// Not all Guzzle Exceptions implement hasResponse() / getResponse()
if (method_exists($e, 'hasResponse') && method_exists($e, 'getResponse')) {
if ($e->hasResponse()) {
throw ApiException::createFromResponse($e->getResponse(), $request);
}
}
throw new ApiException($e->getMessage(), $e->getCode(), null, $request, null);
}
return $this->parseResponseBody($response);
}
/**
* Whether this http adapter provides a debugging mode. If debugging mode is enabled, the
* request will be included in the ApiException.
*
* @return true
*/
public function supportsDebugging()
{
return true;
}
/**
* Whether debugging is enabled. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*
* @return bool
*/
public function debugging()
{
return $this->debugging;
}
/**
* Enable debugging. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*/
public function enableDebugging()
{
$this->debugging = true;
}
/**
* Disable debugging. If debugging mode is enabled, the request will
* be included in the ApiException. By default, debugging is disabled to prevent
* sensitive request data from leaking into exception logs.
*/
public function disableDebugging()
{
$this->debugging = false;
}
/**
* Parse the PSR-7 Response body
*
* @param ResponseInterface $response
* @return \stdClass|null
* @throws ApiException
*/
private function parseResponseBody(ResponseInterface $response)
{
$body = (string) $response->getBody();
if (empty($body) && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return null;
}
$object = @json_decode($body);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new ApiException("Unable to decode Mollie response: '{$body}'.");
}
if ($response->getStatusCode() >= 400) {
throw ApiException::createFromResponse($response, null);
}
return $object;
}
/**
* The version number for the underlying http client, if available. This is used to report the UserAgent to Mollie,
* for convenient support.
* @example Guzzle/6.3
*
* @return string|null
*/
public function versionString()
{
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) { // Guzzle 7
return "Guzzle/" . ClientInterface::MAJOR_VERSION;
} elseif (defined('\GuzzleHttp\ClientInterface::VERSION')) { // Before Guzzle 7
return "Guzzle/" . ClientInterface::VERSION;
}
return null;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Mollie\Api\HttpAdapter;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
class Guzzle6And7RetryMiddlewareFactory
{
/**
* The maximum number of retries
*/
public const MAX_RETRIES = 5;
/**
* The amount of milliseconds the delay is being increased with on each retry.
*/
public const DELAY_INCREASE_MS = 1000;
/**
* @param bool $delay default to true, can be false to speed up tests
*
* @return callable
*/
public function retry($delay = true)
{
return Middleware::retry(
$this->newRetryDecider(),
$delay ? $this->getRetryDelay() : $this->getZeroRetryDelay()
);
}
/**
* Returns a method that takes the number of retries and returns the number of milliseconds
* to wait
*
* @return callable
*/
private function getRetryDelay()
{
return function ($numberOfRetries) {
return static::DELAY_INCREASE_MS * $numberOfRetries;
};
}
/**
* Returns a method that returns zero milliseconds to wait
*
* @return callable
*/
private function getZeroRetryDelay()
{
return function ($numberOfRetries) {
return 0;
};
}
/**
* @return callable
*/
private function newRetryDecider()
{
return function (
$retries,
Request $request,
?Response $response = null,
?TransferException $exception = null
) {
if ($retries >= static::MAX_RETRIES) {
return false;
}
if ($exception instanceof ConnectException) {
return true;
}
return false;
};
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Mollie\Api\HttpAdapter;
interface MollieHttpAdapterInterface
{
/**
* Send a request to the specified Mollie api url.
*
* @param string $httpMethod
* @param string $url
* @param string|array $headers
* @param string $httpBody
* @return \stdClass|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function send($httpMethod, $url, $headers, $httpBody);
/**
* The version number for the underlying http client, if available.
* @example Guzzle/6.3
*
* @return string|null
*/
public function versionString();
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Mollie\Api\HttpAdapter;
use Mollie\Api\Exceptions\UnrecognizedClientException;
class MollieHttpAdapterPicker implements MollieHttpAdapterPickerInterface
{
/**
* @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface|null|\stdClass $httpClient
*
* @return \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
* @throws \Mollie\Api\Exceptions\UnrecognizedClientException
*/
public function pickHttpAdapter($httpClient)
{
if (! $httpClient) {
if ($this->guzzleIsDetected()) {
$guzzleVersion = $this->guzzleMajorVersionNumber();
if ($guzzleVersion && in_array($guzzleVersion, [6, 7])) {
return Guzzle6And7MollieHttpAdapter::createDefault();
}
}
return new CurlMollieHttpAdapter;
}
if ($httpClient instanceof MollieHttpAdapterInterface) {
return $httpClient;
}
if ($httpClient instanceof \GuzzleHttp\ClientInterface) {
return new Guzzle6And7MollieHttpAdapter($httpClient);
}
throw new UnrecognizedClientException('The provided http client or adapter was not recognized.');
}
/**
* @return bool
*/
private function guzzleIsDetected()
{
return interface_exists('\\' . \GuzzleHttp\ClientInterface::class);
}
/**
* @return int|null
*/
private function guzzleMajorVersionNumber()
{
// Guzzle 7
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
return (int) \GuzzleHttp\ClientInterface::MAJOR_VERSION;
}
// Before Guzzle 7
if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
return (int) \GuzzleHttp\ClientInterface::VERSION[0];
}
return null;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Mollie\Api\HttpAdapter;
interface MollieHttpAdapterPickerInterface
{
/**
* @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface $httpClient
*
* @return \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
*/
public function pickHttpAdapter($httpClient);
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Mollie\Api\Idempotency;
use Mollie\Api\Exceptions\IncompatiblePlatform;
class DefaultIdempotencyKeyGenerator implements IdempotencyKeyGeneratorContract
{
const DEFAULT_LENGTH = 16;
/**
* @var int
*/
protected $length;
public function __construct($length = self::DEFAULT_LENGTH)
{
$this->length = $length;
}
/**
* @throws \Mollie\Api\Exceptions\IncompatiblePlatform
* @return string
*/
public function generate()
{
$length = $this->length;
$string = '';
while (($len = strlen($string)) < $length) {
$size = $length - $len;
try {
$bytes = random_bytes($size);
} catch (\Exception $e) {
throw new IncompatiblePlatform(
'PHP function random_bytes missing. Consider overriding the DefaultIdempotencyKeyGenerator with your own.',
IncompatiblePlatform::INCOMPATIBLE_RANDOM_BYTES_FUNCTION
);
}
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
}
return $string;
}
}

View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Idempotency;
class FakeIdempotencyKeyGenerator implements IdempotencyKeyGeneratorContract
{
/** @var string */
private $fakeKey;
public function setFakeKey($fakeKey)
{
$this->fakeKey = $fakeKey;
}
public function generate()
{
return $this->fakeKey;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace Mollie\Api\Idempotency;
interface IdempotencyKeyGeneratorContract
{
public function generate();
}

View File

@@ -0,0 +1,816 @@
<?php
namespace Mollie\Api;
use Mollie\Api\Endpoints\BalanceEndpoint;
use Mollie\Api\Endpoints\BalanceReportEndpoint;
use Mollie\Api\Endpoints\BalanceTransactionEndpoint;
use Mollie\Api\Endpoints\CapabilityEndpoint;
use Mollie\Api\Endpoints\ChargebackEndpoint;
use Mollie\Api\Endpoints\ClientEndpoint;
use Mollie\Api\Endpoints\ClientLinkEndpoint;
use Mollie\Api\Endpoints\CustomerEndpoint;
use Mollie\Api\Endpoints\CustomerPaymentsEndpoint;
use Mollie\Api\Endpoints\InvoiceEndpoint;
use Mollie\Api\Endpoints\MandateEndpoint;
use Mollie\Api\Endpoints\MethodEndpoint;
use Mollie\Api\Endpoints\MethodIssuerEndpoint;
use Mollie\Api\Endpoints\OnboardingEndpoint;
use Mollie\Api\Endpoints\OrderEndpoint;
use Mollie\Api\Endpoints\OrderLineEndpoint;
use Mollie\Api\Endpoints\OrderPaymentEndpoint;
use Mollie\Api\Endpoints\OrderRefundEndpoint;
use Mollie\Api\Endpoints\OrganizationEndpoint;
use Mollie\Api\Endpoints\OrganizationPartnerEndpoint;
use Mollie\Api\Endpoints\PaymentCaptureEndpoint;
use Mollie\Api\Endpoints\PaymentChargebackEndpoint;
use Mollie\Api\Endpoints\PaymentEndpoint;
use Mollie\Api\Endpoints\PaymentLinkEndpoint;
use Mollie\Api\Endpoints\PaymentLinkPaymentEndpoint;
use Mollie\Api\Endpoints\PaymentRefundEndpoint;
use Mollie\Api\Endpoints\PaymentRouteEndpoint;
use Mollie\Api\Endpoints\PermissionEndpoint;
use Mollie\Api\Endpoints\ProfileEndpoint;
use Mollie\Api\Endpoints\ProfileMethodEndpoint;
use Mollie\Api\Endpoints\RefundEndpoint;
use Mollie\Api\Endpoints\SalesInvoiceEndpoint;
use Mollie\Api\Endpoints\SessionEndpoint;
use Mollie\Api\Endpoints\SettlementCaptureEndpoint;
use Mollie\Api\Endpoints\SettlementChargebackEndpoint;
use Mollie\Api\Endpoints\SettlementPaymentEndpoint;
use Mollie\Api\Endpoints\SettlementRefundEndpoint;
use Mollie\Api\Endpoints\SettlementsEndpoint;
use Mollie\Api\Endpoints\ShipmentEndpoint;
use Mollie\Api\Endpoints\SubscriptionEndpoint;
use Mollie\Api\Endpoints\SubscriptionPaymentEndpoint;
use Mollie\Api\Endpoints\TerminalEndpoint;
use Mollie\Api\Endpoints\WalletEndpoint;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException;
use Mollie\Api\Exceptions\IncompatiblePlatform;
use Mollie\Api\HttpAdapter\MollieHttpAdapterPicker;
use Mollie\Api\Idempotency\DefaultIdempotencyKeyGenerator;
class MollieApiClient
{
/**
* Version of our client.
*/
public const CLIENT_VERSION = "2.79.1";
/**
* Endpoint of the remote API.
*/
public const API_ENDPOINT = "https://api.mollie.com";
/**
* Version of the remote API.
*/
public const API_VERSION = "v2";
/**
* HTTP Methods
*/
public const HTTP_GET = "GET";
public const HTTP_POST = "POST";
public const HTTP_DELETE = "DELETE";
public const HTTP_PATCH = "PATCH";
/**
* @var \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
*/
protected $httpClient;
/**
* @var string
*/
protected $apiEndpoint = self::API_ENDPOINT;
/**
* RESTful Payments resource.
*
* @var PaymentEndpoint
*/
public $payments;
/**
* RESTful Methods resource.
*
* @var MethodEndpoint
*/
public $methods;
/**
* @var ProfileMethodEndpoint
*/
public $profileMethods;
/**
* @var \Mollie\Api\Endpoints\MethodIssuerEndpoint
*/
public $methodIssuers;
/**
* @var \Mollie\Api\Endpoints\CapabilityEndpoint
*/
public $capabilities;
/**
* RESTful Customers resource.
*
* @var CustomerEndpoint
*/
public $customers;
/**
* RESTful Customer payments resource.
*
* @var CustomerPaymentsEndpoint
*/
public $customerPayments;
/**
* RESTful Sales Invoice resource.
*
* @var SalesInvoiceEndpoint
*/
public $salesInvoices;
/**
* RESTful Settlement resource.
*
* @var SettlementsEndpoint
*/
public $settlements;
/**
* RESTful Settlement capture resource.
*
* @var \Mollie\Api\Endpoints\SettlementCaptureEndpoint
*/
public $settlementCaptures;
/**
* RESTful Settlement chargeback resource.
*
* @var \Mollie\Api\Endpoints\SettlementChargebackEndpoint
*/
public $settlementChargebacks;
/**
* RESTful Settlement payment resource.
*
* @var \Mollie\Api\Endpoints\SettlementPaymentEndpoint
*/
public $settlementPayments;
/**
* RESTful Settlement refund resource.
*
* @var \Mollie\Api\Endpoints\SettlementRefundEndpoint
*/
public $settlementRefunds;
/**
* RESTful Subscription resource.
*
* @var SubscriptionEndpoint
*/
public $subscriptions;
/**
* RESTful Subscription Payments resource.
*
* @var SubscriptionPaymentEndpoint
*/
public $subscriptionPayments;
/**
* RESTful Mandate resource.
*
* @var MandateEndpoint
*/
public $mandates;
/**
* RESTful Profile resource.
*
* @var ProfileEndpoint
*/
public $profiles;
/**
* RESTful Organization resource.
*
* @var OrganizationEndpoint
*/
public $organizations;
/**
* RESTful Permission resource.
*
* @var PermissionEndpoint
*/
public $permissions;
/**
* RESTful Invoice resource.
*
* @var InvoiceEndpoint
*/
public $invoices;
/**
* RESTful Balance resource.
*
* @var BalanceEndpoint
*/
public $balances;
/**
* @var BalanceTransactionEndpoint
*/
public $balanceTransactions;
/**
* @var BalanceReportEndpoint
*/
public $balanceReports;
/**
* RESTful Onboarding resource.
*
* @var OnboardingEndpoint
*/
public $onboarding;
/**
* RESTful Order resource.
*
* @var OrderEndpoint
*/
public $orders;
/**
* RESTful OrderLine resource.
*
* @var OrderLineEndpoint
*/
public $orderLines;
/**
* RESTful OrderPayment resource.
*
* @var OrderPaymentEndpoint
*/
public $orderPayments;
/**
* RESTful Shipment resource.
*
* @var ShipmentEndpoint
*/
public $shipments;
/**
* RESTful Refunds resource.
*
* @var RefundEndpoint
*/
public $refunds;
/**
* RESTful Payment Refunds resource.
*
* @var PaymentRefundEndpoint
*/
public $paymentRefunds;
/**
* RESTful Payment Route resource.
*
* @var PaymentRouteEndpoint
*/
public $paymentRoutes;
/**
* RESTful Payment Captures resource.
*
* @var PaymentCaptureEndpoint
*/
public $paymentCaptures;
/**
* RESTful Chargebacks resource.
*
* @var ChargebackEndpoint
*/
public $chargebacks;
/**
* RESTful Payment Chargebacks resource.
*
* @var PaymentChargebackEndpoint
*/
public $paymentChargebacks;
/**
* RESTful Order Refunds resource.
*
* @var OrderRefundEndpoint
*/
public $orderRefunds;
/**
* RESTful Payment Link Payment resource.
*
* @var PaymentLinkPaymentEndpoint
*/
public $paymentLinkPayments;
/**
* Manages Payment Links requests
*
* @var PaymentLinkEndpoint
*/
public $paymentLinks;
/**
* RESTful Terminal resource.
*
* @var TerminalEndpoint
*/
public $terminals;
/**
* RESTful Onboarding resource.
*
* @var OrganizationPartnerEndpoint
*/
public $organizationPartners;
/**
* Manages Wallet requests
*
* @var WalletEndpoint
*/
public $wallets;
/**
* RESTful Client resource.
*
* @var ClientEndpoint
*/
public $clients;
/**
* RESTful Client resource.
*
* @var ClientLinkEndpoint
*/
public $clientLinks;
/**
* RESTful Session resource.
*
* @var SessionEndpoint
*/
public $sessions;
/**
* @var string
*/
protected $apiKey;
/**
* True if an OAuth access token is set as API key.
*
* @var bool
*/
protected $oauthAccess;
/**
* A unique string ensuring a request to a mutating Mollie endpoint is processed only once.
* This key resets to null after each request.
*
* @var string|null
*/
protected $idempotencyKey = null;
/**
* @var \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract|null
*/
protected $idempotencyKeyGenerator;
/**
* @var array
*/
protected $versionStrings = [];
/**
* @param \GuzzleHttp\ClientInterface|\Mollie\Api\HttpAdapter\MollieHttpAdapterInterface|null $httpClient
* @param \Mollie\Api\HttpAdapter\MollieHttpAdapterPickerInterface|null $httpAdapterPicker,
* @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $idempotencyKeyGenerator,
* @throws \Mollie\Api\Exceptions\IncompatiblePlatform|\Mollie\Api\Exceptions\UnrecognizedClientException
*/
public function __construct($httpClient = null, $httpAdapterPicker = null, $idempotencyKeyGenerator = null)
{
$httpAdapterPicker = $httpAdapterPicker ?: new MollieHttpAdapterPicker;
$this->httpClient = $httpAdapterPicker->pickHttpAdapter($httpClient);
$compatibilityChecker = new CompatibilityChecker;
$compatibilityChecker->checkCompatibility();
$this->initializeEndpoints();
$this->initializeVersionStrings();
$this->initializeIdempotencyKeyGenerator($idempotencyKeyGenerator);
}
public function initializeEndpoints()
{
$this->balanceReports = new BalanceReportEndpoint($this);
$this->balanceTransactions = new BalanceTransactionEndpoint($this);
$this->balances = new BalanceEndpoint($this);
$this->capabilities = new CapabilityEndpoint($this);
$this->chargebacks = new ChargebackEndpoint($this);
$this->clientLinks = new ClientLinkEndpoint($this);
$this->clients = new ClientEndpoint($this);
$this->customerPayments = new CustomerPaymentsEndpoint($this);
$this->customers = new CustomerEndpoint($this);
$this->invoices = new InvoiceEndpoint($this);
$this->mandates = new MandateEndpoint($this);
$this->methods = new MethodEndpoint($this);
$this->methodIssuers = new MethodIssuerEndpoint($this);
$this->onboarding = new OnboardingEndpoint($this);
$this->orderLines = new OrderLineEndpoint($this);
$this->orderPayments = new OrderPaymentEndpoint($this);
$this->orderRefunds = new OrderRefundEndpoint($this);
$this->orders = new OrderEndpoint($this);
$this->organizationPartners = new OrganizationPartnerEndpoint($this);
$this->organizations = new OrganizationEndpoint($this);
$this->paymentCaptures = new PaymentCaptureEndpoint($this);
$this->paymentChargebacks = new PaymentChargebackEndpoint($this);
$this->paymentLinkPayments = new PaymentLinkPaymentEndpoint($this);
$this->paymentLinks = new PaymentLinkEndpoint($this);
$this->paymentRefunds = new PaymentRefundEndpoint($this);
$this->paymentRoutes = new PaymentRouteEndpoint($this);
$this->payments = new PaymentEndpoint($this);
$this->permissions = new PermissionEndpoint($this);
$this->profileMethods = new ProfileMethodEndpoint($this);
$this->profiles = new ProfileEndpoint($this);
$this->refunds = new RefundEndpoint($this);
$this->salesInvoices = new SalesInvoiceEndpoint($this);
$this->settlementCaptures = new SettlementCaptureEndpoint($this);
$this->settlementChargebacks = new SettlementChargebackEndpoint($this);
$this->settlementPayments = new SettlementPaymentEndpoint($this);
$this->settlementRefunds = new SettlementRefundEndpoint($this);
$this->settlements = new SettlementsEndpoint($this);
$this->sessions = new SessionEndpoint($this);
$this->shipments = new ShipmentEndpoint($this);
$this->subscriptionPayments = new SubscriptionPaymentEndpoint($this);
$this->subscriptions = new SubscriptionEndpoint($this);
$this->terminals = new TerminalEndpoint($this);
$this->wallets = new WalletEndpoint($this);
}
protected function initializeVersionStrings()
{
$this->addVersionString("Mollie/" . self::CLIENT_VERSION);
$this->addVersionString("PHP/" . phpversion());
$httpClientVersionString = $this->httpClient->versionString();
if ($httpClientVersionString) {
$this->addVersionString($httpClientVersionString);
}
}
/**
* @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator
* @return void
*/
protected function initializeIdempotencyKeyGenerator($generator)
{
$this->idempotencyKeyGenerator = $generator ? $generator : new DefaultIdempotencyKeyGenerator;
}
/**
* @param string $url
*
* @return MollieApiClient
*/
public function setApiEndpoint($url)
{
$this->apiEndpoint = rtrim(trim($url), '/');
return $this;
}
/**
* @return string
*/
public function getApiEndpoint()
{
return $this->apiEndpoint;
}
/**
* @return array
*/
public function getVersionStrings()
{
return $this->versionStrings;
}
/**
* @param string $apiKey The Mollie API key, starting with 'test_' or 'live_'
*
* @return MollieApiClient
* @throws ApiException
*/
public function setApiKey($apiKey)
{
$apiKey = trim($apiKey);
if (! preg_match('/^(live|test)_\w{30,}$/', $apiKey)) {
throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long.");
}
$this->apiKey = $apiKey;
$this->oauthAccess = false;
return $this;
}
/**
* @param string $accessToken OAuth access token, starting with 'access_'
*
* @return MollieApiClient
* @throws ApiException
*/
public function setAccessToken($accessToken)
{
$accessToken = trim($accessToken);
if (! preg_match('/^access_\w+$/', $accessToken)) {
throw new ApiException("Invalid OAuth access token: '{$accessToken}'. An access token must start with 'access_'.");
}
$this->apiKey = $accessToken;
$this->oauthAccess = true;
return $this;
}
/**
* Returns null if no API key has been set yet.
*
* @return bool|null
*/
public function usesOAuth()
{
return $this->oauthAccess;
}
/**
* @param string $versionString
*
* @return MollieApiClient
*/
public function addVersionString($versionString)
{
$this->versionStrings[] = str_replace([" ", "\t", "\n", "\r"], '-', $versionString);
return $this;
}
/**
* Enable debugging mode. If debugging mode is enabled, the attempted request will be included in the ApiException.
* By default, debugging is disabled to prevent leaking sensitive request data into exception logs.
*
* @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException
*/
public function enableDebugging()
{
if (
! method_exists($this->httpClient, 'supportsDebugging')
|| ! $this->httpClient->supportsDebugging()
) {
throw new HttpAdapterDoesNotSupportDebuggingException(
"Debugging is not supported by " . get_class($this->httpClient) . "."
);
}
$this->httpClient->enableDebugging();
}
/**
* Disable debugging mode. If debugging mode is enabled, the attempted request will be included in the ApiException.
* By default, debugging is disabled to prevent leaking sensitive request data into exception logs.
*
* @throws \Mollie\Api\Exceptions\HttpAdapterDoesNotSupportDebuggingException
*/
public function disableDebugging()
{
if (
! method_exists($this->httpClient, 'supportsDebugging')
|| ! $this->httpClient->supportsDebugging()
) {
throw new HttpAdapterDoesNotSupportDebuggingException(
"Debugging is not supported by " . get_class($this->httpClient) . "."
);
}
$this->httpClient->disableDebugging();
}
/**
* Set the idempotency key used on the next request. The idempotency key is a unique string ensuring a request to a
* mutating Mollie endpoint is processed only once. The idempotency key resets to null after each request. Using
* the setIdempotencyKey method supersedes the IdempotencyKeyGenerator.
*
* @param $key
* @return $this
*/
public function setIdempotencyKey($key)
{
$this->idempotencyKey = $key;
return $this;
}
/**
* Retrieve the idempotency key. The idempotency key is a unique string ensuring a request to a
* mutating Mollie endpoint is processed only once. Note that the idempotency key gets reset to null after each
* request.
*
* @return string|null
*/
public function getIdempotencyKey()
{
return $this->idempotencyKey;
}
/**
* Reset the idempotency key. Note that the idempotency key automatically resets to null after each request.
* @return $this
*/
public function resetIdempotencyKey()
{
$this->idempotencyKey = null;
return $this;
}
/**
* @param \Mollie\Api\Idempotency\IdempotencyKeyGeneratorContract $generator
* @return \Mollie\Api\MollieApiClient
*/
public function setIdempotencyKeyGenerator($generator)
{
$this->idempotencyKeyGenerator = $generator;
return $this;
}
/**
* @return \Mollie\Api\MollieApiClient
*/
public function clearIdempotencyKeyGenerator()
{
$this->idempotencyKeyGenerator = null;
return $this;
}
/**
* Perform a http call. This method is used by the resource specific classes. Please use the $payments property to
* perform operations on payments.
*
* @param string $httpMethod
* @param string $apiMethod
* @param string|null $httpBody
*
* @return \stdClass
* @throws ApiException
*
* @codeCoverageIgnore
*/
public function performHttpCall($httpMethod, $apiMethod, $httpBody = null)
{
$url = $this->apiEndpoint . "/" . self::API_VERSION . "/" . $apiMethod;
return $this->performHttpCallToFullUrl($httpMethod, $url, $httpBody);
}
/**
* Perform a http call to a full url. This method is used by the resource specific classes.
*
* @see $payments
* @see $isuers
*
* @param string $httpMethod
* @param string $url
* @param string|null $httpBody
*
* @return \stdClass|null
* @throws ApiException
*
* @codeCoverageIgnore
*/
public function performHttpCallToFullUrl($httpMethod, $url, $httpBody = null)
{
if (empty($this->apiKey)) {
throw new ApiException("You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.");
}
$userAgent = implode(' ', $this->versionStrings);
if ($this->usesOAuth()) {
$userAgent .= " OAuth/2.0";
}
$headers = [
'Accept' => "application/json",
'Authorization' => "Bearer {$this->apiKey}",
'User-Agent' => $userAgent,
];
if ($httpBody !== null) {
$headers['Content-Type'] = "application/json";
}
if (function_exists("php_uname")) {
$headers['X-Mollie-Client-Info'] = php_uname();
}
$headers = $this->applyIdempotencyKey($headers, $httpMethod);
$response = $this->httpClient->send($httpMethod, $url, $headers, $httpBody);
$this->resetIdempotencyKey();
return $response;
}
/**
* Conditionally apply the idempotency key to the request headers
*
* @param array $headers
* @param string $httpMethod
* @return array
*/
private function applyIdempotencyKey(array $headers, string $httpMethod)
{
if (! in_array($httpMethod, [self::HTTP_POST, self::HTTP_PATCH, self::HTTP_DELETE])) {
unset($headers['Idempotency-Key']);
return $headers;
}
if ($this->idempotencyKey) {
$headers['Idempotency-Key'] = $this->idempotencyKey;
return $headers;
}
if ($this->idempotencyKeyGenerator) {
$headers['Idempotency-Key'] = $this->idempotencyKeyGenerator->generate();
return $headers;
}
unset($headers['Idempotency-Key']);
return $headers;
}
/**
* Serialization can be used for caching. Of course doing so can be dangerous but some like to live dangerously.
*
* \serialize() should be called on the collections or object you want to cache.
*
* We don't need any property that can be set by the constructor, only properties that are set by setters.
*
* Note that the API key is not serialized, so you need to set the key again after unserializing if you want to do
* more API calls.
*
* @deprecated
* @return string[]
*/
public function __sleep()
{
return ["apiEndpoint"];
}
/**
* When unserializing a collection or a resource, this class should restore itself.
*
* Note that if you have set an HttpAdapter, this adapter is lost on wakeup and reset to the default one.
*
* @throws IncompatiblePlatform If suddenly unserialized on an incompatible platform.
*/
public function __wakeup()
{
$this->__construct();
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace Mollie\Api\Resources;
class Balance extends BaseResource
{
/**
* Indicates this is a balance resource. The value will always be "balance" here.
*
* @var string
*/
public $resource;
/**
* The mode used to create this balance. Mode determines whether real or test payments can be moved to this balance.
* The value is either "live" or "test".
*
* @var string
*/
public $mode;
/**
* The identifier uniquely referring this balance. Mollie assigns this identifier at balance creation.
*
* @example bal_gVMhHKqSSRYJyPsuoPABC
* @var string
*/
public $id;
/**
* UTC datetime the balance was created in ISO-8601 format.
*
* @example "2021-12-25T10:30:54+00:00"
* @var string
*/
public $createdAt;
/**
* The balance's ISO 4217 currency code.
*
* @var string
*/
public $currency;
/**
* The status of the balance: "active" if the balance is operational and ready to be used.
* The status is "inactive" if the account is still being validated by Mollie or if the balance has been blocked.
*
* @var string
*/
public $status;
/**
* The total amount directly available on the balance.
*
* @var \stdClass
*/
public $availableAmount;
/**
* The total amount queued to be transferred to your balance.
* For example, a credit card payment can take a few days to clear.
*
* @var \stdClass
*/
public $incomingAmount;
/**
* The total amount that is in the process of being transferred from your balance to your verified bank account.
* @var \stdClass
*/
public $outgoingAmount;
/**
* The frequency at which the available amount on the balance will be transferred away to the configured transfer
* destination. See "transferDestination". Note that if the transfer is for an external destination, and the
* transfer is created in a weekend or during a bank holiday, the actual bank transfer will take place on the next
* business day.
*
* @var string
*/
public $transferFrequency;
/**
* The minimum amount configured for scheduled automatic balance transfers. As soon as the amount on the balance
* exceeds this threshold, the complete balance will be paid out to the "transferDestination" according to the
* configured "transferFrequency".
*
* @var \stdClass
*/
public $transferThreshold;
/**
* The reference to be included on all transfers for this balance.
*
* @var string|null
*/
public $transferReference;
/**
* The destination where the available amount will be automatically transferred to according to the configured
* "transferFrequency".
*
* @var \stdClass
*/
public $transferDestination;
/**
* Links to help navigate through the Mollie API and related resources.
*
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class BalanceCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "balances";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Balance($this->client);
}
}

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Resources;
class BalanceReport extends BaseResource
{
/**
* Indicates the response contains a balance report object. Will always contain "balance-report" for this endpoint.
*
* @var string
*/
public $resource;
/**
* The ID of the balance this report was generated for.
*
* @example bal_gVMhHKqSSRYJyPsuoPNFH
* @var string
*/
public $balanceId;
/**
* The time zone used for the "from" and "until" parameters.
* Currently only time zone "Europe/Amsterdam" is supported.
*
*
* @example Europe/Amsterdam
* @var string
*/
public $timeZone;
/**
* The start date of the report, in YYYY-MM-DD format. The "from" date is inclusive, and in Central European Time.
* This means a report with for example "from: 2020-01-01" will include movements of "2020-01-01 0:00:00 CET" and
* onwards.
*
*
* @example 2020-01-01
* @var string
*/
public $from;
/**
* The end date of the report, in YYYY-MM-DD format. The "until" date is exclusive, and in Central European Time.
* This means a report with for example "until: 2020-02-01" will include movements up
* until "2020-01-31 23:59:59 CET".
*
* @var string
*/
public $until;
/**
* You can retrieve reports in two different formats: "status-balances" or "transaction-categories".
* With the "status-balances" format, transactions are grouped by status (e.g. "pending", "available"), then by
* direction of movement (e.g. moved from "pending" to "available"), then by transaction type, and then by other
* sub-groupings where available (e.g. payment method).
* With the "transaction-categories" format, transactions are grouped by transaction type, then by direction of
* movement, and then again by other sub-groupings where available. Both reporting formats will always contain
* opening and closing amounts that correspond to the start and end dates of the report.
*
* @var string
*/
public $grouping;
/**
* The balance report totals, structured according to the defined "grouping".
*
* @var \stdClass
*/
public $totals;
/**
* Links to help navigate through the API.
*
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Resources;
class BalanceTransaction extends BaseResource
{
/**
* Indicates this is a balance transaction resource. The value will always be "balance_transaction" here.
*
* @var string
*/
public $resource;
/**
* The mode used to create this balance transaction. Mode determines whether real or test payments can be moved to
* this balance. The value is either "live" or "test".
*
* @var string
*/
public $mode;
/**
* The identifier uniquely referring this balance transaction. Mollie assigns this identifier at creation.
*
* @example baltr_QM24QwzUWR4ev4Xfgyt29d
* @var string
*/
public $id;
/**
* The type of movement, for example "payment" or "refund".
*
* @var string
*/
public $type;
/**
* UTC datetime the balance transaction was created in ISO-8601 format.
*
* @example "2021-12-25T10:30:54+00:00"
* @var string
*/
public $createdAt;
/**
* The final amount that was moved to or from the balance. If the transaction moves funds away from the balance,
* for example when it concerns a refund, the amount will be negative.
*
* @example {"currency":"EUR", "value":"100.00"}
* @var \stdClass
*/
public $resultAmount;
/**
* The amount that was to be moved to or from the balance, excluding deductions. If the transaction moves funds
* away from the balance, for example when it concerns a refund, the amount will be negative.
*
* @var \stdClass
*/
public $initialAmount;
/**
* The total amount of deductions withheld from the movement. For example, if a €10,00 payment comes in with a
* €0,29 fee, the deductions amount will be {"currency":"EUR", "value":"-0.29"}. When moving funds to a balance,
* we always round the deduction to a real amount. Any differences between these realtime rounded amounts and
* the final invoice will be compensated when the invoice is generated.
*
* @example {"currency":"EUR", "value":"-0.29"}
*
* @var \stdClass
*/
public $deductions;
/**
* Depending on the type of the balance transaction, we will try to give more context about the specific event that
* triggered the movement.
*
* @var \stdClass
*/
public $context;
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Resources;
class BalanceTransactionCollection extends CursorCollection
{
/**
* @inheritDoc
*/
public function getCollectionResourceName()
{
return "balance_transactions";
}
/**
* @inheritDoc
*/
protected function createResourceObject()
{
return new BalanceTransaction($this->client);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Mollie\Api\Resources;
abstract class BaseCollection extends \ArrayObject
{
/**
* Total number of retrieved objects.
*
* @var int
*/
public $count;
/**
* @var \stdClass|null
*/
public $_links;
/**
* @param int $count
* @param \stdClass|null $_links
*/
public function __construct($count, $_links)
{
$this->count = $count;
$this->_links = $_links;
parent::__construct();
}
/**
* @return string|null
*/
abstract public function getCollectionResourceName();
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
#[\AllowDynamicProperties]
abstract class BaseResource
{
/**
* @var MollieApiClient
*/
protected $client;
/**
* Indicates the type of resource.
*
* @example payment
*
* @var string
*/
public $resource;
/**
* @param MollieApiClient $client
*/
public function __construct(MollieApiClient $client)
{
$this->client = $client;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\CapabilityStatus;
class Capability extends BaseResource
{
/**
* @var string
*/
public $resource;
/**
* @var string
*
* @example payments
*/
public $name;
/**
* @var \stdClass
*/
public $requirements;
/**
* @var string
*
* possible values: disabled, pending, enabled
*
* @example enabled
*/
public $status;
/**
* @var string
*/
public $statusReason;
/**
* @var string
*/
public $organizationId;
/**
* Links to help navigate through the Mollie API and related resources.
*
* @var \stdClass
*/
public $_links;
public function isEnabled()
{
return $this->status === CapabilityStatus::ENABLED;
}
public function isPending()
{
return $this->status === CapabilityStatus::PENDING;
}
public function isDisabled()
{
return $this->status === CapabilityStatus::DISABLED;
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Mollie\Api\Resources;
class CapabilityCollection extends BaseCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "capabilities";
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace Mollie\Api\Resources;
class Capture extends BaseResource
{
/**
* Always 'capture' for this object
*
* @var string
*/
public $resource;
/**
* Id of the capture
* @var string
*/
public $id;
/**
* Mode of the capture, either "live" or "test" depending on the API Key that was used.
*
* @var string
*/
public $mode;
/**
* Status of the capture.
*
* @var string
*/
public $status;
/**
* Amount object containing the value and currency
*
* @var \stdClass
*/
public $amount;
/**
* Amount object containing the settlement value and currency
*
* @var \stdClass
*/
public $settlementAmount;
/**
* Id of the capture's payment (on the Mollie platform).
*
* @var string
*/
public $paymentId;
/**
* Id of the capture's shipment (on the Mollie platform).
*
* @var string
*/
public $shipmentId;
/**
* Id of the capture's settlement (on the Mollie platform).
*
* @var string
*/
public $settlementId;
/**
* Provide any data you like, for example a string or a JSON object. The data will be saved alongside the capture.
* Whenever you fetch the capture, the metadata will be included.
* You can use up to approximately 1kB on this field.
*
* @var \stdClass|mixed|null
*/
public $metadata;
/**
* @var string
*/
public $createdAt;
/**
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class CaptureCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "captures";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Capture($this->client);
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Mollie\Api\Resources;
class Chargeback extends BaseResource
{
/**
* Always 'chargeback'.
*
* @var string
*/
public $resource;
/**
* Id of the payment method.
*
* @var string
*/
public $id;
/**
* The $amount that was refunded.
*
* @var \stdClass
*/
public $amount;
/**
* UTC datetime the payment was created in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $createdAt;
/**
* The payment id that was refunded.
*
* @var string
*/
public $paymentId;
/**
* The settlement amount.
*
* @var \stdClass
*/
public $settlementAmount;
/**
* The identifier referring to the settlement this payment was settled with.
*
* @var string|null
*/
public $settlementId;
/**
* The chargeback reason
*
* @var \stdClass|null
*/
public $reason;
/**
* UTC datetime the date and time the chargeback was reversed in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $reversedAt;
/**
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class ChargebackCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "chargebacks";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Chargeback($this->client);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Mollie\Api\Resources;
class Client extends BaseResource
{
/**
* The unique identifier of the client, which corresponds to the ID of the organization
*
* @var string
*/
public $id;
/**
* UTC datetime the order was created in ISO-8601 format.
*
* @example "2018-03-21T13:13:37+00:00"
* @var string|null
*/
public $organizationCreatedAt;
/**
* @var \stdClass
*/
public $_links;
/**
* @var \stdClass[]
*/
public $_embedded;
/**
* @var \stdClass|null
*/
public $commission;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class ClientCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "clients";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Client($this->client);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\ApprovalPrompt;
class ClientLink extends BaseResource
{
/**
* @var string
*/
public $resource;
/**
* Id of the client link.
*
* @example csr_vZCnNQsV2UtfXxYifWKWH
* @var string
*/
public $id;
/**
* An object with several URL objects relevant to the client link. Every URL object will contain an href and a type field.
*
* @var \stdClass
*/
public $_links;
/**
* Get the redirect URL where the customer can complete the payment.
*
* @return string|null
*/
public function getRedirectUrl(string $client_id, string $state, array $scopes = [], string $approval_prompt = ApprovalPrompt::AUTO)
{
if (! in_array($approval_prompt, [ApprovalPrompt::AUTO, ApprovalPrompt::FORCE])) {
throw new \Exception('Invalid approval_prompt. Please use "auto" or "force".');
}
$query = http_build_query([
'client_id' => $client_id,
'state' => $state,
'approval_prompt' => $approval_prompt,
'scope' => implode(' ', $scopes),
], '', '&', PHP_QUERY_RFC3986);
return "{$this->_links->clientLink->href}?{$query}";
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
class CurrentProfile extends Profile
{
/**
* Enable a payment method for this profile.
*
* @param string $methodId
* @param array $data
* @return Method
* @throws ApiException
*/
public function enableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->createForCurrentProfile($methodId, $data);
}
/**
* Disable a payment method for this profile.
*
* @param string $methodId
* @param array $data
* @return Method
* @throws ApiException
*/
public function disableMethod($methodId, array $data = [])
{
return $this->client->profileMethods->deleteForCurrentProfile($methodId, $data);
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Mollie\Api\Resources;
use Generator;
use Mollie\Api\MollieApiClient;
abstract class CursorCollection extends BaseCollection
{
/**
* @var MollieApiClient
*/
protected $client;
/**
* @param MollieApiClient $client
* @param int $count
* @param \stdClass|null $_links
*/
final public function __construct(MollieApiClient $client, $count, $_links)
{
parent::__construct($count, $_links);
$this->client = $client;
}
/**
* @return BaseResource
*/
abstract protected function createResourceObject();
/**
* Return the next set of resources when available
*
* @return CursorCollection|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
final public function next()
{
if (! $this->hasNext()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->next->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject());
}
return $collection;
}
/**
* Return the previous set of resources when available
*
* @return CursorCollection|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
final public function previous()
{
if (! $this->hasPrevious()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->previous->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject());
}
return $collection;
}
/**
* Determine whether the collection has a next page available.
*
* @return bool
*/
public function hasNext()
{
return isset($this->_links->next->href);
}
/**
* Determine whether the collection has a previous page available.
*
* @return bool
*/
public function hasPrevious()
{
return isset($this->_links->previous->href);
}
/**
* Iterate over a CursorCollection and yield its elements.
*
* @param bool $iterateBackwards
*
* @return LazyCollection
*/
public function getAutoIterator(bool $iterateBackwards = false): LazyCollection
{
$page = $this;
return new LazyCollection(function () use ($page, $iterateBackwards): Generator {
while (true) {
foreach ($page as $item) {
yield $item;
}
if (($iterateBackwards && ! $page->hasPrevious()) || ! $page->hasNext()) {
break;
}
$page = $iterateBackwards
? $page->previous()
: $page->next();
}
});
}
}

View File

@@ -0,0 +1,226 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
class Customer extends BaseResource
{
use HasPresetOptions;
/**
* Id of the customer.
*
* @var string
*/
public $id;
/**
* Either "live" or "test". Indicates this being a test or a live (verified) customer.
*
* @var string
*/
public $mode;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $email;
/**
* @var string|null
*/
public $locale;
/**
* @var \stdClass|mixed|null
*/
public $metadata;
/**
* @var string[]|array
*/
public $recentlyUsedMethods;
/**
* @var string
*/
public $createdAt;
/**
* @var \stdClass
*/
public $_links;
/**
* @return \Mollie\Api\Resources\Customer
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update()
{
$body = [
"name" => $this->name,
"email" => $this->email,
"locale" => $this->locale,
"metadata" => $this->metadata,
];
$result = $this->client->customers->update($this->id, $body);
return ResourceFactory::createFromApiResult($result, new Customer($this->client));
}
/**
* @param array $options
* @param array $filters
*
* @return Payment
* @throws ApiException
*/
public function createPayment(array $options = [], array $filters = [])
{
return $this->client->customerPayments->createFor($this, $this->withPresetOptions($options), $filters);
}
/**
* Get all payments for this customer
*
* @return PaymentCollection
* @throws ApiException
*/
public function payments()
{
return $this->client->customerPayments->listFor($this, null, null, $this->getPresetOptions());
}
/**
* @param array $options
* @param array $filters
*
* @return Subscription
* @throws ApiException
*/
public function createSubscription(array $options = [], array $filters = [])
{
return $this->client->subscriptions->createFor($this, $this->withPresetOptions($options), $filters);
}
/**
* @param string $subscriptionId
* @param array $parameters
*
* @return Subscription
* @throws ApiException
*/
public function getSubscription($subscriptionId, array $parameters = [])
{
return $this->client->subscriptions->getFor($this, $subscriptionId, $this->withPresetOptions($parameters));
}
/**
* @param string $subscriptionId
*
* @return \Mollie\Api\Resources\Subscription
* @throws ApiException
*/
public function cancelSubscription($subscriptionId)
{
return $this->client->subscriptions->cancelFor($this, $subscriptionId, $this->getPresetOptions());
}
/**
* Get all subscriptions for this customer
*
* @return SubscriptionCollection
* @throws ApiException
*/
public function subscriptions()
{
return $this->client->subscriptions->listFor($this, null, null, $this->getPresetOptions());
}
/**
* @param array $options
* @param array $filters
*
* @return Mandate
* @throws ApiException
*/
public function createMandate(array $options = [], array $filters = [])
{
return $this->client->mandates->createFor($this, $this->withPresetOptions($options), $filters);
}
/**
* @param string $mandateId
* @param array $parameters
*
* @return Mandate
* @throws ApiException
*/
public function getMandate($mandateId, array $parameters = [])
{
return $this->client->mandates->getFor($this, $mandateId, $parameters);
}
/**
* @param string $mandateId
*
* @return null
* @throws ApiException
*/
public function revokeMandate($mandateId)
{
return $this->client->mandates->revokeFor($this, $mandateId, $this->getPresetOptions());
}
/**
* Get all mandates for this customer
*
* @return MandateCollection
* @throws ApiException
*/
public function mandates()
{
return $this->client->mandates->listFor($this, null, null, $this->getPresetOptions());
}
/**
* Helper function to check for mandate with status valid
*
* @return bool
*/
public function hasValidMandate()
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->isValid()) {
return true;
}
}
return false;
}
/**
* Helper function to check for specific payment method mandate with status valid
*
* @return bool
*/
public function hasValidMandateForMethod($method)
{
$mandates = $this->mandates();
foreach ($mandates as $mandate) {
if ($mandate->method === $method && $mandate->isValid()) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class CustomerCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "customers";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Customer($this->client);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
/**
* @property MollieApiClient $client
* @property string $mode
*/
trait HasPresetOptions
{
/**
* When accessed by oAuth we want to pass the testmode by default
*
* @return array
*/
protected function getPresetOptions()
{
$options = [];
if ($this->client->usesOAuth()) {
$options["testmode"] = $this->mode === "test" ? true : false;
}
return $options;
}
/**
* Apply the preset options.
*
* @param array $options
* @return array
*/
protected function withPresetOptions(array $options)
{
return array_merge($this->getPresetOptions(), $options);
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\InvoiceStatus;
class Invoice extends BaseResource
{
/**
* @var string
*/
public $id;
/**
* @var string
*/
public $reference;
/**
* @var string
*/
public $vatNumber;
/**
* @var string
*/
public $status;
/**
* Date the invoice was issued, e.g. 2018-01-01
*
* @var string
*/
public $issuedAt;
/**
* Date the invoice was paid, e.g. 2018-01-01
*
* @var string|null
*/
public $paidAt;
/**
* Date the invoice is due, e.g. 2018-01-01
*
* @var string|null
*/
public $dueAt;
/**
* Amount object containing the total amount of the invoice excluding VAT.
*
* @var \stdClass
*/
public $netAmount;
/**
* Amount object containing the VAT amount of the invoice. Only for merchants registered in the Netherlands.
*
* @var \stdClass
*/
public $vatAmount;
/**
* Total amount of the invoice including VAT.
*
* @var \stdClass
*/
public $grossAmount;
/**
* Array containing the invoice lines.
*
* @see https://docs.mollie.com/reference/v2/invoices-api/get-invoice
* @var array
*/
public $lines;
/**
* Contains a PDF to the Invoice
*
* @var \stdClass
*/
public $_links;
/**
* @return bool
*/
public function isPaid()
{
return $this->status == InvoiceStatus::STATUS_PAID;
}
/**
* @return bool
*/
public function isOpen()
{
return $this->status == InvoiceStatus::STATUS_OPEN;
}
/**
* @return bool
*/
public function isOverdue()
{
return $this->status == InvoiceStatus::STATUS_OVERDUE;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class InvoiceCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "invoices";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Invoice($this->client);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Mollie\Api\Resources;
class Issuer extends BaseResource
{
/**
* Id of the issuer.
*
* @var string
*/
public $id;
/**
* Name of the issuer.
*
* @var string
*/
public $name;
/**
* The payment method this issuer belongs to.
*
* @see Mollie_API_Object_Method
* @var string
*/
public $method;
/**
* Object containing a size1x or size2x image
*
* @var \stdClass
*/
public $image;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Mollie\Api\Resources;
class IssuerCollection extends BaseCollection
{
/**
* @return string|null
*/
public function getCollectionResourceName()
{
return null;
}
}

View File

@@ -0,0 +1,198 @@
<?php
namespace Mollie\Api\Resources;
use Iterator;
use IteratorAggregate;
/**
* @template TKey of array-key
* @template TValue
*
* @implements IteratorAggregate<TKey, TValue>
*/
class LazyCollection implements IteratorAggregate
{
/**
* @var callable
*/
private $source;
/**
* @param callable $source
*/
public function __construct($source)
{
$this->source = $source;
}
/**
* Get all items in the collection.
*
* @return array
*/
public function all(): array
{
return iterator_to_array($this->getIterator());
}
/**
* Get an item from the collection by key.
*
* @param TKey $key
* @return TValue|null
*/
public function get($key)
{
foreach ($this as $outerKey => $outerValue) {
if ($outerKey == $key) {
return $outerValue;
}
}
return null;
}
/**
* Run a filter over each of the items.
*
* @param (callable(TValue, TKey): bool) $callback
* @return self
*/
public function filter(callable $callback): self
{
return new self(function () use ($callback) {
foreach ($this as $key => $value) {
if ($callback($value, $key)) {
yield $key => $value;
}
}
});
}
/**
* Get the first item from the collection passing the given truth test.
*
* @param (callable(TValue, TKey): bool)|null $callback
* @return TValue|null
*/
public function first(?callable $callback = null)
{
$iterator = $this->getIterator();
if (is_null($callback)) {
if (! $iterator->valid()) {
return null;
}
return $iterator->current();
}
foreach ($iterator as $key => $value) {
if ($callback($value, $key)) {
return $value;
}
}
return null;
}
/**
* Run a map over each of the items.
*
* @template TMapValue
*
* @param callable(TValue, TKey): TMapValue $callback
* @return static<TKey, TMapValue>
*/
public function map(callable $callback): self
{
return new self(function () use ($callback) {
foreach ($this as $key => $value) {
yield $key => $callback($value, $key);
}
});
}
/**
* Take the first {$limit} items.
*
* @param int $limit
* @return static
*/
public function take(int $limit): self
{
return new self(function () use ($limit) {
$iterator = $this->getIterator();
while ($limit--) {
if (! $iterator->valid()) {
break;
}
yield $iterator->key() => $iterator->current();
if ($limit) {
$iterator->next();
}
}
});
}
/**
* Determine if all items pass the given truth test.
*
* @param (callable(TValue, TKey): bool) $callback
* @return bool
*/
public function every(callable $callback): bool
{
$iterator = $this->getIterator();
foreach ($iterator as $key => $value) {
if (! $callback($value, $key)) {
return false;
}
}
return true;
}
/**
* Count the number of items in the collection.
*
* @return int
*/
public function count(): int
{
return iterator_count($this->getIterator());
}
/**
* Get an iterator for the items.
*
* @return Iterator<TKey, TValue>
*/
public function getIterator(): Iterator
{
return $this->makeIterator($this->source);
}
/**
* Get an iterator for the given value.
*
* @template TIteratorKey of array-key
* @template TIteratorValue
*
* @param IteratorAggregate<TIteratorValue>|(callable(): \Generator<TIteratorKey, TIteratorValue>) $source
* @return Iterator<TIteratorValue>
*/
protected function makeIterator($source): Iterator
{
if ($source instanceof IteratorAggregate) {
return $source->getIterator();
}
return $source();
}
}

View File

@@ -0,0 +1,112 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\MandateStatus;
class Mandate extends BaseResource
{
/**
* @var string
*/
public $id;
/**
* @var string
*/
public $status;
/**
* @var string
*/
public $mode;
/**
* @var string
*/
public $method;
/**
* @var \stdClass|null
*/
public $details;
/**
* @var string
*/
public $customerId;
/**
* @var string
*/
public $createdAt;
/**
* @var string
*/
public $mandateReference;
/**
* Date of signature, for example: 2018-05-07
*
* @var string
*/
public $signatureDate;
/**
* @var \stdClass
*/
public $_links;
/**
* @return bool
*/
public function isValid()
{
return $this->status === MandateStatus::STATUS_VALID;
}
/**
* @return bool
*/
public function isPending()
{
return $this->status === MandateStatus::STATUS_PENDING;
}
/**
* @return bool
*/
public function isInvalid()
{
return $this->status === MandateStatus::STATUS_INVALID;
}
/**
* Revoke the mandate
*
* @return null|\stdClass|\Mollie\Api\Resources\Mandate
*/
public function revoke()
{
if (! isset($this->_links->self->href)) {
return $this;
}
$body = null;
if ($this->client->usesOAuth()) {
$body = json_encode([
"testmode" => $this->mode === "test" ? true : false,
]);
}
$result = $this->client->performHttpCallToFullUrl(
MollieApiClient::HTTP_DELETE,
$this->_links->self->href,
$body
);
return $result;
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Mollie\Api\Resources;
class MandateCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "mandates";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Mandate($this->client);
}
/**
* @param string $status
* @return array|\Mollie\Api\Resources\MandateCollection
*/
public function whereStatus($status)
{
$collection = new self($this->client, 0, $this->_links);
foreach ($this as $item) {
if ($item->status === $status) {
$collection[] = $item;
$collection->count++;
}
}
return $collection;
}
}

View File

@@ -0,0 +1,100 @@
<?php
namespace Mollie\Api\Resources;
class Method extends BaseResource
{
/**
* Id of the payment method.
*
* @var string
*/
public $id;
/**
* More legible description of the payment method.
*
* @var string
*/
public $description;
/**
* An object containing value and currency. It represents the minimum payment amount required to use this
* payment method.
*
* @var \stdClass
*/
public $minimumAmount;
/**
* An object containing value and currency. It represents the maximum payment amount allowed when using this
* payment method.
*
* @var \stdClass
*/
public $maximumAmount;
/**
* The $image->size1x and $image->size2x to display the payment method logo.
*
* @var \stdClass
*/
public $image;
/**
* The issuers available for this payment method. Only for the methods iDEAL, KBC/CBC and gift cards.
* Will only be filled when explicitly requested using the query string `include` parameter.
*
* @var array|object[]
*/
public $issuers;
/**
* The pricing for this payment method. Will only be filled when explicitly requested using the query string
* `include` parameter.
*
* @var array|object[]
*/
public $pricing;
/**
* The activation status the method is in.
* If the method has status "null", this value will be returned as a null value, not as a string.
*
* @var string | null
*/
public $status;
/**
* @var \stdClass
*/
public $_links;
/**
* Get the issuer value objects
*
* @return IssuerCollection
*/
public function issuers()
{
return ResourceFactory::createBaseResourceCollection(
$this->client,
Issuer::class,
$this->issuers
);
}
/**
* Get the method price value objects.
*
* @return MethodPriceCollection
*/
public function pricing()
{
return ResourceFactory::createBaseResourceCollection(
$this->client,
MethodPrice::class,
$this->pricing
);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Mollie\Api\Resources;
class MethodCollection extends BaseCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "methods";
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Mollie\Api\Resources;
class MethodPrice extends BaseResource
{
/**
* The area or product-type where the pricing is applied for, translated in the optional locale passed.
*
* @example "The Netherlands"
* @var string
*/
public $description;
/**
* The fixed price per transaction. This excludes the variable amount.
*
* @var \stdClass An amount object consisting of `value` and `currency`
*/
public $fixed;
/**
* A string containing the percentage being charged over the payment amount besides the fixed price.
*
* @var string An string representing the percentage as a float (for example: "0.1" for 10%)
*/
public $variable;
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Mollie\Api\Resources;
class MethodPriceCollection extends BaseCollection
{
/**
* @return string|null
*/
public function getCollectionResourceName()
{
return null;
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\OnboardingStatus;
class Onboarding extends BaseResource
{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $signedUpAt;
/**
* Either "needs-data", "in-review" or "completed".
* Indicates this current status of the organizations onboarding process.
*
* @var string
*/
public $status;
/**
* @var bool
*/
public $canReceivePayments;
/**
* @var bool
*/
public $canReceiveSettlements;
/**
* @var \stdClass
*/
public $_links;
/**
* @return bool
*/
public function needsData()
{
return $this->status === OnboardingStatus::NEEDS_DATA;
}
/**
* @return bool
*/
public function isInReview()
{
return $this->status === OnboardingStatus::IN_REVIEW;
}
/**
* @return bool
*/
public function isCompleted()
{
return $this->status === OnboardingStatus::COMPLETED;
}
}

View File

@@ -0,0 +1,534 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Types\OrderStatus;
class Order extends BaseResource
{
use HasPresetOptions;
/**
* Id of the order.
*
* @example ord_8wmqcHMN4U
* @var string
*/
public $id;
/**
* The profile ID this order belongs to.
*
* @example pfl_xH2kP6Nc6X
* @var string
*/
public $profileId;
/**
* Either "live" or "test". Indicates this being a test or a live (verified) order.
*
* @var string
*/
public $mode;
/**
* Amount object containing the value and currency
*
* @var \stdClass
*/
public $amount;
/**
* The total amount captured, thus far.
*
* @var \stdClass
*/
public $amountCaptured;
/**
* The total amount refunded, thus far.
*
* @var \stdClass
*/
public $amountRefunded;
/**
* The status of the order.
*
* @var string
*/
public $status;
/**
* The person and the address the order is billed to.
*
* @var \stdClass
*/
public $billingAddress;
/**
* The date of birth of your customer, if available.
* @example 1976-08-21
* @var string|null
*/
public $consumerDateOfBirth;
/**
* The order number that was used when creating the order.
*
* @var string
*/
public $orderNumber;
/**
* The person and the address the order is shipped to.
*
* @var \stdClass
*/
public $shippingAddress;
/**
* The payment method last used when paying for the order.
*
* @see Method
* @var string
*/
public $method;
/**
* The locale used for this order.
*
* @var string
*/
public $locale;
/**
* During creation of the order you can set custom metadata that is stored with
* the order, and given back whenever you retrieve that order.
*
* @var \stdClass|mixed|null
*/
public $metadata;
/**
* Can this order be canceled?
*
* @var bool
*/
public $isCancelable;
/**
* Webhook URL set on this payment
*
* @var string|null
*/
public $webhookUrl;
/**
* Redirect URL set on this payment
*
* @var string
*/
public $redirectUrl;
/**
* Cancel URL set on this payment
*
* @var string
*/
public $cancelUrl;
/**
* UTC datetime the order was created in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $createdAt;
/**
* UTC datetime the order the order will expire in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $expiresAt;
/**
* UTC datetime if the order is expired, the time of expiration will be present in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $expiredAt;
/**
* UTC datetime if the order has been paid, the time of payment will be present in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $paidAt;
/**
* UTC datetime if the order has been authorized, the time of authorization will be present in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $authorizedAt;
/**
* UTC datetime if the order has been canceled, the time of cancellation will be present in ISO 8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $canceledAt;
/**
* UTC datetime if the order is completed, the time of completion will be present in ISO 8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $completedAt;
/**
* The order lines contain the actual things the customer bought.
*
* @var array|object[]
*/
public $lines;
/**
* For digital goods, you must make sure to apply the VAT rate from your customers country in most jurisdictions.
* Use this parameter to restrict the payment methods available to your customer to methods from the billing country
* only.
*
* @var bool
*/
public $shopperCountryMustMatchBillingCountry;
/**
* An object with several URL objects relevant to the customer. Every URL object will contain an href and a type field.
*
* @var \stdClass
*/
public $_links;
/**
* @var \stdClass|null
*/
public $_embedded;
/**
* Is this order created?
*
* @return bool
*/
public function isCreated()
{
return $this->status === OrderStatus::STATUS_CREATED;
}
/**
* Is this order paid for?
*
* @return bool
*/
public function isPaid()
{
return $this->status === OrderStatus::STATUS_PAID;
}
/**
* Is this order authorized?
*
* @return bool
*/
public function isAuthorized()
{
return $this->status === OrderStatus::STATUS_AUTHORIZED;
}
/**
* Is this order canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === OrderStatus::STATUS_CANCELED;
}
/**
* (Deprecated) Is this order refunded?
* @deprecated 2018-11-27
*
* @return bool
*/
public function isRefunded()
{
return $this->status === OrderStatus::STATUS_REFUNDED;
}
/**
* Is this order shipping?
*
* @return bool
*/
public function isShipping()
{
return $this->status === OrderStatus::STATUS_SHIPPING;
}
/**
* Is this order completed?
*
* @return bool
*/
public function isCompleted()
{
return $this->status === OrderStatus::STATUS_COMPLETED;
}
/**
* Is this order expired?
*
* @return bool
*/
public function isExpired()
{
return $this->status === OrderStatus::STATUS_EXPIRED;
}
/**
* Is this order completed?
*
* @return bool
*/
public function isPending()
{
return $this->status === OrderStatus::STATUS_PENDING;
}
/**
* Cancels this order.
* If the order was partially shipped, the status will be "completed" instead of
* "canceled".
* Will throw a ApiException if the order id is invalid or the resource cannot
* be found.
*
* @return Order
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancel()
{
return $this->client->orders->cancel($this->id, $this->getPresetOptions());
}
/**
* Cancel a line for this order.
* The data array must contain a lines array.
* You can pass an empty lines array if you want to cancel all eligible lines.
* Returns null if successful.
*
* @param array $data
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancelLines(array $data)
{
return $this->client->orderLines->cancelFor($this, $data);
}
/**
* Cancels all eligible lines for this order.
* Returns null if successful.
*
* @param array|null $data
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancelAllLines($data = [])
{
$data['lines'] = [];
return $this->client->orderLines->cancelFor($this, $data);
}
/**
* Get the line value objects
*
* @return OrderLineCollection
*/
public function lines()
{
return ResourceFactory::createBaseResourceCollection(
$this->client,
OrderLine::class,
$this->lines
);
}
/**
* Create a shipment for some order lines. You can provide an empty array for the
* "lines" option to include all unshipped lines for this order.
*
* @param array $options
*
* @return Shipment
* @throws ApiException
*/
public function createShipment(array $options = [])
{
return $this->client->shipments->createFor($this, $this->withPresetOptions($options));
}
/**
* Create a shipment for all unshipped order lines.
*
* @param array $options
*
* @return Shipment
*/
public function shipAll(array $options = [])
{
$options['lines'] = [];
return $this->createShipment($options);
}
/**
* Retrieve a specific shipment for this order.
*
* @param string $shipmentId
* @param array $parameters
*
* @return Shipment
* @throws ApiException
*/
public function getShipment($shipmentId, array $parameters = [])
{
return $this->client->shipments->getFor($this, $shipmentId, $this->withPresetOptions($parameters));
}
/**
* Get all shipments for this order.
*
* @param array $parameters
*
* @return ShipmentCollection
* @throws ApiException
*/
public function shipments(array $parameters = [])
{
return $this->client->shipments->listFor($this, $this->withPresetOptions($parameters));
}
/**
* Get the checkout URL where the customer can complete the payment.
*
* @return string|null
*/
public function getCheckoutUrl()
{
if (empty($this->_links->checkout)) {
return null;
}
return $this->_links->checkout->href;
}
/**
* Refund specific order lines.
*
* @param array $data
* @return Refund
* @throws ApiException
*/
public function refund(array $data)
{
return $this->client->orderRefunds->createFor($this, $this->withPresetOptions($data));
}
/**
* Refund all eligible order lines.
*
* @param array $data
* @return Refund
*/
public function refundAll(array $data = [])
{
$data['lines'] = [];
return $this->refund($data);
}
/**
* Retrieves all refunds associated with this order
*
* @return RefundCollection
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function refunds()
{
return $this->client->orderRefunds->pageFor($this);
}
/**
* Saves the order's updated billingAddress and/or shippingAddress.
*
* @return \Mollie\Api\Resources\Order
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update()
{
$body = [
"billingAddress" => $this->billingAddress,
"shippingAddress" => $this->shippingAddress,
"orderNumber" => $this->orderNumber,
"redirectUrl" => $this->redirectUrl,
"cancelUrl" => $this->cancelUrl,
"webhookUrl" => $this->webhookUrl,
];
$result = $this->client->orders->update($this->id, $body);
return ResourceFactory::createFromApiResult($result, new Order($this->client));
}
/**
* Create a new payment for this Order.
*
* @param array $data
* @param array $filters
* @return \Mollie\Api\Resources\Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function createPayment($data, $filters = [])
{
return $this->client->orderPayments->createFor($this, $data, $filters);
}
/**
* Retrieve the payments for this order.
* Requires the order to be retrieved using the embed payments parameter.
*
* @return null|\Mollie\Api\Resources\PaymentCollection
*/
public function payments()
{
if (! isset($this->_embedded, $this->_embedded->payments)) {
return null;
}
return ResourceFactory::createCursorResourceCollection(
$this->client,
$this->_embedded->payments,
Payment::class
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class OrderCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "orders";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Order($this->client);
}
}

View File

@@ -0,0 +1,420 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\OrderLineStatus;
use Mollie\Api\Types\OrderLineType;
class OrderLine extends BaseResource
{
/**
* Always 'orderline'
*
* @var string
*/
public $resource;
/**
* Id of the order line.
*
* @var string
*/
public $id;
/**
* The ID of the order this line belongs to.
*
* @example ord_kEn1PlbGa
* @var string
*/
public $orderId;
/**
* The type of product bought.
*
* @example physical
* @var string
*/
public $type;
/**
* A description of the order line.
*
* @example LEGO 4440 Forest Police Station
* @var string
*/
public $name;
/**
* The status of the order line.
*
* @var string
*/
public $status;
/**
* Can this order line be canceled?
*
* @var bool
*/
public $isCancelable;
/**
* The number of items in the order line.
*
* @var int
*/
public $quantity;
/**
* The number of items that are shipped for this order line.
*
* @var int
*/
public $quantityShipped;
/**
* The total amount that is shipped for this order line.
*
* @var \stdClass
*/
public $amountShipped;
/**
* The number of items that are refunded for this order line.
*
* @var int
*/
public $quantityRefunded;
/**
* The total amount that is refunded for this order line.
*
* @var \stdClass
*/
public $amountRefunded;
/**
* The number of items that are canceled in this order line.
*
* @var int
*/
public $quantityCanceled;
/**
* The total amount that is canceled in this order line.
*
* @var \stdClass
*/
public $amountCanceled;
/**
* The number of items that can still be shipped for this order line.
*
* @var int
*/
public $shippableQuantity;
/**
* The number of items that can still be refunded for this order line.
*
* @var int
*/
public $refundableQuantity;
/**
* The number of items that can still be canceled for this order line.
*
* @var int
*/
public $cancelableQuantity;
/**
* The price of a single item in the order line.
*
* @var \stdClass
*/
public $unitPrice;
/**
* Any discounts applied to the order line.
*
* @var \stdClass|null
*/
public $discountAmount;
/**
* The total amount of the line, including VAT and discounts.
*
* @var \stdClass
*/
public $totalAmount;
/**
* The VAT rate applied to the order line. It is defined as a string
* and not as a float to ensure the correct number of decimals are
* passed.
*
* @example "21.00"
* @var string
*/
public $vatRate;
/**
* The amount of value-added tax on the line.
*
* @var \stdClass
*/
public $vatAmount;
/**
* The SKU, EAN, ISBN or UPC of the product sold.
*
* @var string|null
*/
public $sku;
/**
* A link pointing to an image of the product sold.
*
* @var string|null
*/
public $imageUrl;
/**
* A link pointing to the product page in your web shop of the product sold.
*
* @var string|null
*/
public $productUrl;
/**
* During creation of the order you can set custom metadata on order lines that is stored with
* the order, and given back whenever you retrieve that order line.
*
* @var \stdClass|mixed|null
*/
public $metadata;
/**
* The order line's date and time of creation, in ISO 8601 format.
*
* @example 2018-08-02T09:29:56+00:00
* @var string
*/
public $createdAt;
/**
* @var \stdClass
*/
public $_links;
/**
* Get the url pointing to the product page in your web shop of the product sold.
*
* @return string|null
*/
public function getProductUrl()
{
if (empty($this->_links->productUrl)) {
return null;
}
return $this->_links->productUrl;
}
/**
* Get the image URL of the product sold.
*
* @return string|null
*/
public function getImageUrl()
{
if (empty($this->_links->imageUrl)) {
return null;
}
return $this->_links->imageUrl;
}
/**
* Is this order line created?
*
* @return bool
*/
public function isCreated()
{
return $this->status === OrderLineStatus::STATUS_CREATED;
}
/**
* Is this order line paid for?
*
* @return bool
*/
public function isPaid()
{
return $this->status === OrderLineStatus::STATUS_PAID;
}
/**
* Is this order line authorized?
*
* @return bool
*/
public function isAuthorized()
{
return $this->status === OrderLineStatus::STATUS_AUTHORIZED;
}
/**
* Is this order line canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === OrderLineStatus::STATUS_CANCELED;
}
/**
* (Deprecated) Is this order line refunded?
* @deprecated 2018-11-27
*
* @return bool
*/
public function isRefunded()
{
return $this->status === OrderLineStatus::STATUS_REFUNDED;
}
/**
* Is this order line shipping?
*
* @return bool
*/
public function isShipping()
{
return $this->status === OrderLineStatus::STATUS_SHIPPING;
}
/**
* Is this order line completed?
*
* @return bool
*/
public function isCompleted()
{
return $this->status === OrderLineStatus::STATUS_COMPLETED;
}
/**
* Is this order line for a physical product?
*
* @return bool
*/
public function isPhysical()
{
return $this->type === OrderLineType::TYPE_PHYSICAL;
}
/**
* Is this order line for applying a discount?
*
* @return bool
*/
public function isDiscount()
{
return $this->type === OrderLineType::TYPE_DISCOUNT;
}
/**
* Is this order line for a digital product?
*
* @return bool
*/
public function isDigital()
{
return $this->type === OrderLineType::TYPE_DIGITAL;
}
/**
* Is this order line for applying a shipping fee?
*
* @return bool
*/
public function isShippingFee()
{
return $this->type === OrderLineType::TYPE_SHIPPING_FEE;
}
/**
* Is this order line for store credit?
*
* @return bool
*/
public function isStoreCredit()
{
return $this->type === OrderLineType::TYPE_STORE_CREDIT;
}
/**
* Is this order line for a gift card?
*
* @return bool
*/
public function isGiftCard()
{
return $this->type === OrderLineType::TYPE_GIFT_CARD;
}
/**
* Is this order line for a surcharge?
*
* @return bool
*/
public function isSurcharge()
{
return $this->type === OrderLineType::TYPE_SURCHARGE;
}
/**
* Update an orderline by supplying one or more parameters in the data array
*
* @return BaseResource
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update()
{
$result = $this->client->orderLines->update($this->orderId, $this->id, $this->getUpdateData());
return ResourceFactory::createFromApiResult($result, new Order($this->client));
}
/**
* Get sanitized array of order line data
*
* @return array
*/
public function getUpdateData()
{
$data = [
"name" => $this->name,
'imageUrl' => $this->imageUrl,
'productUrl' => $this->productUrl,
'metadata' => $this->metadata,
'sku' => $this->sku,
'quantity' => $this->quantity,
'unitPrice' => $this->unitPrice,
'discountAmount' => $this->discountAmount,
'totalAmount' => $this->totalAmount,
'vatAmount' => $this->vatAmount,
'vatRate' => $this->vatRate,
];
// Explicitly filter only NULL values to keep "vatRate => 0" intact
return array_filter($data, function ($value) {
return $value !== null;
});
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Mollie\Api\Resources;
class OrderLineCollection extends BaseCollection
{
/**
* @return string|null
*/
public function getCollectionResourceName()
{
return null;
}
/**
* Get a specific order line.
* Returns null if the order line cannot be found.
*
* @param string $lineId
* @return OrderLine|null
*/
public function get($lineId)
{
foreach ($this as $line) {
if ($line->id === $lineId) {
return $line;
}
}
return null;
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Mollie\Api\Resources;
class Organization extends BaseResource
{
/**
* Id of the payment method.
*
* @var string
*/
public $id;
/**
* The name of the organization.
*
* @var string
*/
public $name;
/**
* The email address of the organization.
*
* @var string
*/
public $email;
/**
* The preferred locale of the merchant which has been set in Mollie Dashboard.
*
* @var string
*/
public $locale;
/**
* The address of the organization.
*
* @var \stdClass
*/
public $address;
/**
* The registration number of the organization at the (local) chamber of
* commerce.
*
* @var string
*/
public $registrationNumber;
/**
* The VAT number of the organization, if based in the European Union. The VAT
* number has been checked with the VIES by Mollie.
*
* @var string
*/
public $vatNumber;
/**
* The organizations VAT regulation, if based in the European Union. Either "shifted"
* (VAT is shifted) or dutch (Dutch VAT rate).
*
* @var string|null
*/
public $vatRegulation;
/**
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Mollie\Api\Resources;
class OrganizationCollection extends CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "organizations";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new Organization($this->client);
}
}

Some files were not shown because too many files have changed in this diff Show More