Initial commit

This commit is contained in:
“VeLiTi”
2025-01-30 11:43:37 +01:00
commit 6f1cc27ec4
823 changed files with 233091 additions and 0 deletions

BIN
lib/mollie/src/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,47 @@
<?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 \Mollie\Api\Exceptions\IncompatiblePlatform("The client requires PHP version >= " . self::MIN_PHP_VERSION . ", you have " . \PHP_VERSION . ".", \Mollie\Api\Exceptions\IncompatiblePlatform::INCOMPATIBLE_PHP_VERSION);
}
if (!$this->satisfiesJsonExtension()) {
throw new \Mollie\Api\Exceptions\IncompatiblePlatform("PHP extension json is not enabled. Please make sure to enable 'json' in your PHP configuration.", \Mollie\Api\Exceptions\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,74 @@
<?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;
class BalanceEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
/**
* @var string
*/
const RESOURCE_ID_PREFIX = 'bal_';
protected $resourcePath = "balances";
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new \Mollie\Api\Resources\BalanceCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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);
}
}

View File

@@ -0,0 +1,57 @@
<?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 \Mollie\Api\Endpoints\EndpointAbstract
{
protected $resourcePath = "balances_report";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\Balance $balance, array $parameters = [])
{
return $this->getForId($balance->id, $parameters);
}
}

View File

@@ -0,0 +1,73 @@
<?php
declare (strict_types=1);
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceTransaction;
use Mollie\Api\Resources\BalanceTransactionCollection;
class BalanceTransactionEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
/**
* @var string
*/
const RESOURCE_ID_PREFIX = 'baltr_';
/**
* @var string
*/
protected $resourcePath = "balances_transactions";
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new \Mollie\Api\Resources\BalanceTransactionCollection($this->client, $count, $_links);
}
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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(\Mollie\Api\Resources\Balance $balance, array $parameters = [])
{
return $this->listForId($balance->id, $parameters);
}
/**
* 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);
}
/**
* 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);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
class ChargebackEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Client;
use Mollie\Api\Resources\ClientCollection;
class ClientEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "clients";
/**
* @return Client
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\ClientLink;
class ClientLinkEndpoint extends \Mollie\Api\Endpoints\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() : \Mollie\Api\Resources\ClientLink
{
return new \Mollie\Api\Resources\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 = []) : \Mollie\Api\Resources\ClientLink
{
return $this->rest_create($data, []);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\BaseCollection;
use Mollie\Api\Resources\ResourceFactory;
abstract class CollectionEndpointAbstract extends \Mollie\Api\Endpoints\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($from = null, $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[] = \Mollie\Api\Resources\ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
return $collection;
}
/**
* 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
*/
protected abstract function getResourceCollectionObject($count, $_links);
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\CustomerCollection;
class CustomerEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Invalid order ID: '{$customerId}'. An order 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($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class CustomerPaymentsEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Customer $customer, $from = null, $limit = null, array $parameters = [])
{
return $this->listForId($customer->id, $from, $limit, $parameters);
}
/**
* @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, $from = null, $limit = null, array $parameters = [])
{
$this->parentId = $customerId;
return parent::rest_list($from, $limit, $parameters);
}
}

View File

@@ -0,0 +1,163 @@
<?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 = \Mollie\Api\MollieApiClient::HTTP_POST;
public const REST_UPDATE = \Mollie\Api\MollieApiClient::HTTP_PATCH;
public const REST_READ = \Mollie\Api\MollieApiClient::HTTP_GET;
public const REST_LIST = \Mollie\Api\MollieApiClient::HTTP_GET;
public const REST_DELETE = \Mollie\Api\MollieApiClient::HTTP_DELETE;
/**
* @var MollieApiClient
*/
protected $client;
/**
* @var string
*/
protected $resourcePath;
/**
* @var string|null
*/
protected $parentId;
/**
* @param MollieApiClient $api
*/
public function __construct(\Mollie\Api\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Invalid resource id.");
}
$id = \urlencode($id);
$result = $this->client->performHttpCall(self::REST_READ, "{$this->getResourcePath()}/{$id}" . $this->buildQueryString($filters));
return \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
/**
* Sends a DELETE request to a single Molle API object.
*
* @param string $id
* @param array $body
*
* @return mixed
* @throws ApiException
*/
protected function rest_delete($id, array $body = [])
{
if (empty($id)) {
throw new \Mollie\Api\Exceptions\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 \Mollie\Api\Resources\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
*/
protected abstract 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 \Mollie\Api\Exceptions\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,73 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Invoice;
use Mollie\Api\Resources\InvoiceCollection;
class InvoiceEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\Mandate;
use Mollie\Api\Resources\MandateCollection;
class MandateEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Customer $customer, $from = null, $limit = null, array $parameters = [])
{
return $this->listForId($customer->id, $from, $limit, $parameters);
}
/**
* @param string $customerId
* @param null $from
* @param 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);
}
/**
* @param Customer $customer
* @param string $mandateId
* @param array $data
*
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function revokeFor(\Mollie\Api\Resources\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,88 @@
<?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 \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "methods";
/**
* @return Method
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createBaseResourceCollection($this->client, \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Method ID is empty.");
}
return parent::rest_read($methodId, $parameters);
}
}

View File

@@ -0,0 +1,74 @@
<?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 \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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('', []);
}
/**
* 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 a 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 \Mollie\Api\Resources\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,119 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\OrderCollection;
class OrderEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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($from = null, $limit = null, array $parameters = [])
{
return $this->rest_list($from, $limit, $parameters);
}
}

View File

@@ -0,0 +1,115 @@
<?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 \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\ApiException("Invalid resource id.");
}
$this->parentId = $orderId;
$parameters['operations'] = $operations;
$result = $this->client->performHttpCall(self::REST_UPDATE, "{$this->getResourcePath()}", $this->parseRequestBody($parameters));
return \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\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(\Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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,67 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class OrderPaymentEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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,63 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Order;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class OrderRefundEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Organization;
use Mollie\Api\Resources\OrganizationCollection;
class OrganizationEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "organizations";
/**
* @return Organization
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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,49 @@
<?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 \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, $this->getResourceObject());
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Capture;
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\Payment;
class PaymentCaptureEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Payment $payment, array $parameters = [])
{
return $this->listForId($payment->id, $parameters);
}
/**
* @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);
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\Payment;
class PaymentChargebackEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\ChargebackCollection($this->client, $count, $_links);
}
/**
* @param Payment $payment
* @param string $chargebackId
* @param array $parameters
*
* @return Chargeback
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Payment $payment, array $parameters = [])
{
return $this->listForId($payment->id, $parameters);
}
/**
* @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);
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\ResourceFactory;
class PaymentEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "payments";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'tr_';
/**
* @return Payment
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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);
}
/**
* 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(\Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\Refund($this->client));
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentLink;
use Mollie\Api\Resources\PaymentLinkCollection;
class PaymentLinkEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "payment-links";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'pl_';
/**
* @return PaymentLink
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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);
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class PaymentRefundEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\RefundCollection($this->client, $count, $_links);
}
/**
* @param Payment $payment
* @param string $refundId
* @param array $parameters
*
* @return Refund
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function getFor(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Payment $payment, array $parameters = [])
{
return $this->listForId($payment->id, $parameters);
}
/**
* @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);
}
/**
* 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(\Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Route;
use Mollie\Api\Resources\RouteCollection;
class PaymentRouteEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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,60 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Permission;
use Mollie\Api\Resources\PermissionCollection;
class PermissionEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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,130 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\CurrentProfile;
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ProfileCollection;
class ProfileEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "profiles";
protected $resourceClass = \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Invalid profile id: '{$profileId}'. An 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 = \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,116 @@
<?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 \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\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,46 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
class RefundEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
class SettlementPaymentEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "settlements_payments";
/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\Payment($this->client);
}
/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Resources\SettlementCollection;
class SettlementsEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,145 @@
<?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 \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Invalid subscription ID: '{$shipmentId}'. An subscription 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(\Mollie\Api\Resources\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,187 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\ResourceFactory;
use Mollie\Api\Resources\Subscription;
use Mollie\Api\Resources\SubscriptionCollection;
class SubscriptionEndpoint extends \Mollie\Api\Endpoints\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 \Mollie\Api\Resources\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 \Mollie\Api\Resources\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(\Mollie\Api\Resources\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 \Mollie\Api\Exceptions\ApiException("Invalid subscription ID: '{$subscriptionId}'. An 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(\Mollie\Api\Resources\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(\Mollie\Api\Resources\Customer $customer, $from = null, $limit = null, array $parameters = [])
{
return $this->listForId($customer->id, $from, $limit, $parameters);
}
/**
* @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);
}
/**
* @param Customer $customer
* @param string $subscriptionId
* @param array $data
*
* @return null
* @throws ApiException
*/
public function cancelFor(\Mollie\Api\Resources\Customer $customer, $subscriptionId, array $data = [])
{
return $this->cancelForId($customer->id, $subscriptionId, $data);
}
/**
* @param string $customerId
* @param string $subscriptionId
* @param array $data
*
* @return null
* @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[] = \Mollie\Api\Resources\ResourceFactory::createFromApiResult($dataResult, $this->getResourceObject());
}
return $collection;
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Resources\Terminal;
use Mollie\Api\Resources\TerminalCollection;
class TerminalEndpoint extends \Mollie\Api\Endpoints\CollectionEndpointAbstract
{
protected $resourcePath = "terminals";
/**
* @var string
*/
public const RESOURCE_ID_PREFIX = 'term_';
/**
* @return Terminal
*/
protected function getResourceObject()
{
return new \Mollie\Api\Resources\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 \Mollie\Api\Resources\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 \Mollie\Api\Exceptions\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);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Mollie\Api\Endpoints;
use Mollie\Api\Resources\BaseResource;
class WalletEndpoint extends \Mollie\Api\Endpoints\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,194 @@
<?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 \Mollie\Api\Exceptions\ApiException
{
}

View File

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

View File

@@ -0,0 +1,12 @@
<?php
namespace Mollie\Api\Exceptions;
class IncompatiblePlatform extends \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\ApiException
{
}

View File

@@ -0,0 +1,190 @@
<?php
namespace Mollie\Api\HttpAdapter;
use _PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Exceptions\CurlConnectTimeoutException;
use Mollie\Api\MollieApiClient;
final class CurlMollieHttpAdapter implements \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
{
/**
* Default response timeout (in seconds).
*/
public const DEFAULT_TIMEOUT = 10;
/**
* Default connect timeout (in seconds).
*/
public const DEFAULT_CONNECT_TIMEOUT = 2;
/**
* HTTP status code for an empty ok response.
*/
public const HTTP_NO_CONTENT = 204;
/**
* 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 (\Mollie\Api\Exceptions\CurlConnectTimeoutException $e) {
// Nothing
}
}
throw new \Mollie\Api\Exceptions\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, \_PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle::getBundledCaBundlePath());
switch ($httpMethod) {
case \Mollie\Api\MollieApiClient::HTTP_POST:
\curl_setopt($curl, \CURLOPT_POST, \true);
\curl_setopt($curl, \CURLOPT_POSTFIELDS, $httpBody);
break;
case \Mollie\Api\MollieApiClient::HTTP_GET:
break;
case \Mollie\Api\MollieApiClient::HTTP_PATCH:
\curl_setopt($curl, \CURLOPT_CUSTOMREQUEST, 'PATCH');
\curl_setopt($curl, \CURLOPT_POSTFIELDS, $httpBody);
break;
case \Mollie\Api\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 \Mollie\Api\Exceptions\CurlConnectTimeoutException("Unable to connect to Mollie. " . $curlErrorMessage);
}
throw new \Mollie\Api\Exceptions\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)) {
if ($statusCode === self::HTTP_NO_CONTENT) {
return null;
}
throw new \Mollie\Api\Exceptions\ApiException("No response body found.");
}
$body = @\json_decode($response);
// GUARDS
if (\json_last_error() !== \JSON_ERROR_NONE) {
throw new \Mollie\Api\Exceptions\ApiException("Unable to decode Mollie response: '{$response}'.");
}
if (isset($body->error)) {
throw new \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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,169 @@
<?php
namespace Mollie\Api\HttpAdapter;
use _PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Client;
use _PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Exception\GuzzleException;
use _PhpScoperf7c63b60b99d\GuzzleHttp\HandlerStack;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request;
use _PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions as GuzzleRequestOptions;
use Mollie\Api\Exceptions\ApiException;
use _PhpScoperf7c63b60b99d\Psr\Http\Message\ResponseInterface;
final class Guzzle6And7MollieHttpAdapter implements \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface
{
/**
* Default response timeout (in seconds).
*/
public const DEFAULT_TIMEOUT = 10;
/**
* Default connect timeout (in seconds).
*/
public const DEFAULT_CONNECT_TIMEOUT = 2;
/**
* HTTP status code for an empty ok response.
*/
public const HTTP_NO_CONTENT = 204;
/**
* @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(\_PhpScoperf7c63b60b99d\GuzzleHttp\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 \Mollie\Api\HttpAdapter\Guzzle6And7RetryMiddlewareFactory();
$handlerStack = \_PhpScoperf7c63b60b99d\GuzzleHttp\HandlerStack::create();
$handlerStack->push($retryMiddlewareFactory->retry());
$client = new \_PhpScoperf7c63b60b99d\GuzzleHttp\Client([\_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::VERIFY => \_PhpScoperf7c63b60b99d\Composer\CaBundle\CaBundle::getBundledCaBundlePath(), \_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::TIMEOUT => self::DEFAULT_TIMEOUT, \_PhpScoperf7c63b60b99d\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => self::DEFAULT_CONNECT_TIMEOUT, 'handler' => $handlerStack]);
return new \Mollie\Api\HttpAdapter\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 \_PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request($httpMethod, $url, $headers, $httpBody);
try {
$response = $this->httpClient->send($request, ['http_errors' => \false]);
} catch (\_PhpScoperf7c63b60b99d\GuzzleHttp\Exception\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 \Mollie\Api\Exceptions\ApiException::createFromResponse($e->getResponse(), $request);
}
}
throw new \Mollie\Api\Exceptions\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(\_PhpScoperf7c63b60b99d\Psr\Http\Message\ResponseInterface $response)
{
$body = (string) $response->getBody();
if (empty($body)) {
if ($response->getStatusCode() === self::HTTP_NO_CONTENT) {
return null;
}
throw new \Mollie\Api\Exceptions\ApiException("No response body found.");
}
$object = @\json_decode($body);
if (\json_last_error() !== \JSON_ERROR_NONE) {
throw new \Mollie\Api\Exceptions\ApiException("Unable to decode Mollie response: '{$body}'.");
}
if ($response->getStatusCode() >= 400) {
throw \Mollie\Api\Exceptions\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/" . \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::MAJOR_VERSION;
} elseif (\defined('\\GuzzleHttp\\ClientInterface::VERSION')) {
// Before Guzzle 7
return "Guzzle/" . \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::VERSION;
}
return null;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Mollie\Api\HttpAdapter;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Exception\ConnectException;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Exception\TransferException;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Middleware;
use _PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request;
use _PhpScoperf7c63b60b99d\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 \_PhpScoperf7c63b60b99d\GuzzleHttp\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, \_PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Request $request, \_PhpScoperf7c63b60b99d\GuzzleHttp\Psr7\Response $response = null, \_PhpScoperf7c63b60b99d\GuzzleHttp\Exception\TransferException $exception = null) {
if ($retries >= static::MAX_RETRIES) {
return \false;
}
if ($exception instanceof \_PhpScoperf7c63b60b99d\GuzzleHttp\Exception\ConnectException) {
return \true;
}
return \false;
};
}
}

View File

@@ -0,0 +1,25 @@
<?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,55 @@
<?php
namespace Mollie\Api\HttpAdapter;
use Mollie\Api\Exceptions\UnrecognizedClientException;
class MollieHttpAdapterPicker implements \Mollie\Api\HttpAdapter\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 \Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter::createDefault();
}
}
return new \Mollie\Api\HttpAdapter\CurlMollieHttpAdapter();
}
if ($httpClient instanceof \Mollie\Api\HttpAdapter\MollieHttpAdapterInterface) {
return $httpClient;
}
if ($httpClient instanceof \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface) {
return new \Mollie\Api\HttpAdapter\Guzzle6And7MollieHttpAdapter($httpClient);
}
throw new \Mollie\Api\Exceptions\UnrecognizedClientException('The provided http client or adapter was not recognized.');
}
/**
* @return bool
*/
private function guzzleIsDetected()
{
return \interface_exists('\\' . \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::class);
}
/**
* @return int|null
*/
private function guzzleMajorVersionNumber()
{
// Guzzle 7
if (\defined('\\GuzzleHttp\\ClientInterface::MAJOR_VERSION')) {
return (int) \_PhpScoperf7c63b60b99d\GuzzleHttp\ClientInterface::MAJOR_VERSION;
}
// Before Guzzle 7
if (\defined('\\GuzzleHttp\\ClientInterface::VERSION')) {
return (int) \_PhpScoperf7c63b60b99d\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,36 @@
<?php
namespace Mollie\Api\Idempotency;
use Mollie\Api\Exceptions\IncompatiblePlatform;
class DefaultIdempotencyKeyGenerator implements \Mollie\Api\Idempotency\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 \Mollie\Api\Exceptions\IncompatiblePlatform('PHP function random_bytes missing. Consider overriding the DefaultIdempotencyKeyGenerator with your own.', \Mollie\Api\Exceptions\IncompatiblePlatform::INCOMPATIBLE_RANDOM_BYTES_FUNCTION);
}
$string .= \substr(\str_replace(['/', '+', '='], '', \base64_encode($bytes)), 0, $size);
}
return $string;
}
}

View File

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

View File

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

View File

@@ -0,0 +1,623 @@
<?php
namespace Mollie\Api;
use Mollie\Api\Endpoints\BalanceEndpoint;
use Mollie\Api\Endpoints\BalanceReportEndpoint;
use Mollie\Api\Endpoints\BalanceTransactionEndpoint;
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\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\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\SettlementPaymentEndpoint;
use Mollie\Api\Endpoints\SettlementsEndpoint;
use Mollie\Api\Endpoints\ShipmentEndpoint;
use Mollie\Api\Endpoints\SubscriptionEndpoint;
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.61.0";
/**
* 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;
/**
* RESTful Customers resource.
*
* @var CustomerEndpoint
*/
public $customers;
/**
* RESTful Customer payments resource.
*
* @var CustomerPaymentsEndpoint
*/
public $customerPayments;
/**
* RESTful Settlement resource.
*
* @var SettlementsEndpoint
*/
public $settlements;
/**
* RESTful Settlement payment resource.
*
* @var \Mollie\Api\Endpoints\SettlementPaymentEndpoint
*/
public $settlementPayments;
/**
* RESTful Subscription resource.
*
* @var SubscriptionEndpoint
*/
public $subscriptions;
/**
* 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;
/**
* 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;
/**
* @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 = [];
/**
* RESTful Client resource.
*
* @var ClientEndpoint
*/
public $clients;
/**
* RESTful Client resource.
*
* @var ClientLinkEndpoint
*/
public $clientLinks;
/**
* @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 \Mollie\Api\HttpAdapter\MollieHttpAdapterPicker();
$this->httpClient = $httpAdapterPicker->pickHttpAdapter($httpClient);
$compatibilityChecker = new \Mollie\Api\CompatibilityChecker();
$compatibilityChecker->checkCompatibility();
$this->initializeEndpoints();
$this->initializeVersionStrings();
$this->initializeIdempotencyKeyGenerator($idempotencyKeyGenerator);
}
public function initializeEndpoints()
{
$this->payments = new \Mollie\Api\Endpoints\PaymentEndpoint($this);
$this->methods = new \Mollie\Api\Endpoints\MethodEndpoint($this);
$this->profileMethods = new \Mollie\Api\Endpoints\ProfileMethodEndpoint($this);
$this->customers = new \Mollie\Api\Endpoints\CustomerEndpoint($this);
$this->settlements = new \Mollie\Api\Endpoints\SettlementsEndpoint($this);
$this->settlementPayments = new \Mollie\Api\Endpoints\SettlementPaymentEndpoint($this);
$this->subscriptions = new \Mollie\Api\Endpoints\SubscriptionEndpoint($this);
$this->customerPayments = new \Mollie\Api\Endpoints\CustomerPaymentsEndpoint($this);
$this->mandates = new \Mollie\Api\Endpoints\MandateEndpoint($this);
$this->balances = new \Mollie\Api\Endpoints\BalanceEndpoint($this);
$this->balanceTransactions = new \Mollie\Api\Endpoints\BalanceTransactionEndpoint($this);
$this->balanceReports = new \Mollie\Api\Endpoints\BalanceReportEndpoint($this);
$this->invoices = new \Mollie\Api\Endpoints\InvoiceEndpoint($this);
$this->permissions = new \Mollie\Api\Endpoints\PermissionEndpoint($this);
$this->profiles = new \Mollie\Api\Endpoints\ProfileEndpoint($this);
$this->onboarding = new \Mollie\Api\Endpoints\OnboardingEndpoint($this);
$this->organizations = new \Mollie\Api\Endpoints\OrganizationEndpoint($this);
$this->orders = new \Mollie\Api\Endpoints\OrderEndpoint($this);
$this->orderLines = new \Mollie\Api\Endpoints\OrderLineEndpoint($this);
$this->orderPayments = new \Mollie\Api\Endpoints\OrderPaymentEndpoint($this);
$this->orderRefunds = new \Mollie\Api\Endpoints\OrderRefundEndpoint($this);
$this->shipments = new \Mollie\Api\Endpoints\ShipmentEndpoint($this);
$this->refunds = new \Mollie\Api\Endpoints\RefundEndpoint($this);
$this->paymentRefunds = new \Mollie\Api\Endpoints\PaymentRefundEndpoint($this);
$this->paymentCaptures = new \Mollie\Api\Endpoints\PaymentCaptureEndpoint($this);
$this->paymentRoutes = new \Mollie\Api\Endpoints\PaymentRouteEndpoint($this);
$this->chargebacks = new \Mollie\Api\Endpoints\ChargebackEndpoint($this);
$this->paymentChargebacks = new \Mollie\Api\Endpoints\PaymentChargebackEndpoint($this);
$this->wallets = new \Mollie\Api\Endpoints\WalletEndpoint($this);
$this->paymentLinks = new \Mollie\Api\Endpoints\PaymentLinkEndpoint($this);
$this->terminals = new \Mollie\Api\Endpoints\TerminalEndpoint($this);
$this->organizationPartners = new \Mollie\Api\Endpoints\OrganizationPartnerEndpoint($this);
$this->clients = new \Mollie\Api\Endpoints\ClientEndpoint($this);
$this->clientLinks = new \Mollie\Api\Endpoints\ClientLinkEndpoint($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 \Mollie\Api\Idempotency\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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 \Mollie\Api\Exceptions\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,101 @@
<?php
namespace Mollie\Api\Resources;
class Balance extends \Mollie\Api\Resources\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,21 @@
<?php
namespace Mollie\Api\Resources;
class BalanceCollection extends \Mollie\Api\Resources\CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "balances";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new \Mollie\Api\Resources\Balance($this->client);
}
}

View File

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

View File

@@ -0,0 +1,31 @@
<?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
*/
public abstract function getCollectionResourceName();
}

View File

@@ -0,0 +1,28 @@
<?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(\Mollie\Api\MollieApiClient $client)
{
$this->client = $client;
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace Mollie\Api\Resources;
class Capture extends \Mollie\Api\Resources\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;
/**
* 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;
/**
* @var string
*/
public $createdAt;
/**
* @var \stdClass
*/
public $_links;
}

View File

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

View File

@@ -0,0 +1,67 @@
<?php
namespace Mollie\Api\Resources;
/**
* @method Refund[]|RefundCollection all($from = null, $limit = 50, array $filters = [])
* @method Refund get($refundId, array $filters = [])
* @method Refund create(array $data = [], array $filters = [])
* @method Refund delete($refundId)
*/
class Chargeback extends \Mollie\Api\Resources\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 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,21 @@
<?php
namespace Mollie\Api\Resources;
class ChargebackCollection extends \Mollie\Api\Resources\CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "chargebacks";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new \Mollie\Api\Resources\Chargeback($this->client);
}
}

View File

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

View File

@@ -0,0 +1,38 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\ApprovalPrompt;
class ClientLink extends \Mollie\Api\Resources\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 = \Mollie\Api\Types\ApprovalPrompt::AUTO)
{
if (!\in_array($approval_prompt, [\Mollie\Api\Types\ApprovalPrompt::AUTO, \Mollie\Api\Types\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,32 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
class CurrentProfile extends \Mollie\Api\Resources\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,80 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
abstract class CursorCollection extends \Mollie\Api\Resources\BaseCollection
{
/**
* @var MollieApiClient
*/
protected $client;
/**
* @param MollieApiClient $client
* @param int $count
* @param \stdClass|null $_links
*/
public final function __construct(\Mollie\Api\MollieApiClient $client, $count, $_links)
{
parent::__construct($count, $_links);
$this->client = $client;
}
/**
* @return BaseResource
*/
protected abstract function createResourceObject();
/**
* Return the next set of resources when available
*
* @return CursorCollection|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public final function next()
{
if (!$this->hasNext()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->next->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = \Mollie\Api\Resources\ResourceFactory::createFromApiResult($dataResult, $this->createResourceObject());
}
return $collection;
}
/**
* Return the previous set of resources when available
*
* @return CursorCollection|null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public final function previous()
{
if (!$this->hasPrevious()) {
return null;
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->previous->href);
$collection = new static($this->client, $result->count, $result->_links);
foreach ($result->_embedded->{$collection->getCollectionResourceName()} as $dataResult) {
$collection[] = \Mollie\Api\Resources\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);
}
}

View File

@@ -0,0 +1,216 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
class Customer extends \Mollie\Api\Resources\BaseResource
{
/**
* 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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\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 null
* @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;
}
/**
* When accessed by oAuth we want to pass the testmode by default
*
* @return array
*/
private 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
*/
private function withPresetOptions(array $options)
{
return \array_merge($this->getPresetOptions(), $options);
}
}

View File

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

View File

@@ -0,0 +1,94 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\InvoiceStatus;
class Invoice extends \Mollie\Api\Resources\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 == \Mollie\Api\Types\InvoiceStatus::STATUS_PAID;
}
/**
* @return bool
*/
public function isOpen()
{
return $this->status == \Mollie\Api\Types\InvoiceStatus::STATUS_OPEN;
}
/**
* @return bool
*/
public function isOverdue()
{
return $this->status == \Mollie\Api\Types\InvoiceStatus::STATUS_OVERDUE;
}
}

View File

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

View File

@@ -0,0 +1,32 @@
<?php
namespace Mollie\Api\Resources;
class Issuer extends \Mollie\Api\Resources\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 \Mollie\Api\Resources\BaseCollection
{
/**
* @return string|null
*/
public function getCollectionResourceName()
{
return null;
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\MandateStatus;
class Mandate extends \Mollie\Api\Resources\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 === \Mollie\Api\Types\MandateStatus::STATUS_VALID;
}
/**
* @return bool
*/
public function isPending()
{
return $this->status === \Mollie\Api\Types\MandateStatus::STATUS_PENDING;
}
/**
* @return bool
*/
public function isInvalid()
{
return $this->status === \Mollie\Api\Types\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(\Mollie\Api\MollieApiClient::HTTP_DELETE, $this->_links->self->href, $body);
return $result;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace Mollie\Api\Resources;
class MandateCollection extends \Mollie\Api\Resources\CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "mandates";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new \Mollie\Api\Resources\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,82 @@
<?php
namespace Mollie\Api\Resources;
class Method extends \Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createBaseResourceCollection($this->client, \Mollie\Api\Resources\Issuer::class, $this->issuers);
}
/**
* Get the method price value objects.
*
* @return MethodPriceCollection
*/
public function pricing()
{
return \Mollie\Api\Resources\ResourceFactory::createBaseResourceCollection($this->client, \Mollie\Api\Resources\MethodPrice::class, $this->pricing);
}
}

View File

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

View File

@@ -0,0 +1,26 @@
<?php
namespace Mollie\Api\Resources;
class MethodPrice extends \Mollie\Api\Resources\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 \Mollie\Api\Resources\BaseCollection
{
/**
* @return string|null
*/
public function getCollectionResourceName()
{
return null;
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\OnboardingStatus;
class Onboarding extends \Mollie\Api\Resources\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 === \Mollie\Api\Types\OnboardingStatus::NEEDS_DATA;
}
/**
* @return bool
*/
public function isInReview()
{
return $this->status === \Mollie\Api\Types\OnboardingStatus::IN_REVIEW;
}
/**
* @return bool
*/
public function isCompleted()
{
return $this->status === \Mollie\Api\Types\OnboardingStatus::COMPLETED;
}
}

View File

@@ -0,0 +1,485 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\OrderStatus;
class Order extends \Mollie\Api\Resources\BaseResource
{
/**
* 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 billed 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 === \Mollie\Api\Types\OrderStatus::STATUS_CREATED;
}
/**
* Is this order paid for?
*
* @return bool
*/
public function isPaid()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_PAID;
}
/**
* Is this order authorized?
*
* @return bool
*/
public function isAuthorized()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_AUTHORIZED;
}
/**
* Is this order canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_CANCELED;
}
/**
* (Deprecated) Is this order refunded?
* @deprecated 2018-11-27
*
* @return bool
*/
public function isRefunded()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_REFUNDED;
}
/**
* Is this order shipping?
*
* @return bool
*/
public function isShipping()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_SHIPPING;
}
/**
* Is this order completed?
*
* @return bool
*/
public function isCompleted()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_COMPLETED;
}
/**
* Is this order expired?
*
* @return bool
*/
public function isExpired()
{
return $this->status === \Mollie\Api\Types\OrderStatus::STATUS_EXPIRED;
}
/**
* Is this order completed?
*
* @return bool
*/
public function isPending()
{
return $this->status === \Mollie\Api\Types\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 \Mollie\Api\Resources\ResourceFactory::createBaseResourceCollection($this->client, \Mollie\Api\Resources\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()
{
if (!isset($this->_links->refunds->href)) {
return new \Mollie\Api\Resources\RefundCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->refunds->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->refunds, \Mollie\Api\Resources\Refund::class, $result->_links);
}
/**
* 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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\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 \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $this->_embedded->payments, \Mollie\Api\Resources\Payment::class);
}
/**
* When accessed by oAuth we want to pass the testmode by default
*
* @return array
*/
private 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
*/
private function withPresetOptions(array $options)
{
return \array_merge($this->getPresetOptions(), $options);
}
}

View File

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

View File

@@ -0,0 +1,358 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Types\OrderLineStatus;
use Mollie\Api\Types\OrderLineType;
class OrderLine extends \Mollie\Api\Resources\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 === \Mollie\Api\Types\OrderLineStatus::STATUS_CREATED;
}
/**
* Is this order line paid for?
*
* @return bool
*/
public function isPaid()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_PAID;
}
/**
* Is this order line authorized?
*
* @return bool
*/
public function isAuthorized()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_AUTHORIZED;
}
/**
* Is this order line canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_CANCELED;
}
/**
* (Deprecated) Is this order line refunded?
* @deprecated 2018-11-27
*
* @return bool
*/
public function isRefunded()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_REFUNDED;
}
/**
* Is this order line shipping?
*
* @return bool
*/
public function isShipping()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_SHIPPING;
}
/**
* Is this order line completed?
*
* @return bool
*/
public function isCompleted()
{
return $this->status === \Mollie\Api\Types\OrderLineStatus::STATUS_COMPLETED;
}
/**
* Is this order line for a physical product?
*
* @return bool
*/
public function isPhysical()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_PHYSICAL;
}
/**
* Is this order line for applying a discount?
*
* @return bool
*/
public function isDiscount()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_DISCOUNT;
}
/**
* Is this order line for a digital product?
*
* @return bool
*/
public function isDigital()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_DIGITAL;
}
/**
* Is this order line for applying a shipping fee?
*
* @return bool
*/
public function isShippingFee()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_SHIPPING_FEE;
}
/**
* Is this order line for store credit?
*
* @return bool
*/
public function isStoreCredit()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_STORE_CREDIT;
}
/**
* Is this order line for a gift card?
*
* @return bool
*/
public function isGiftCard()
{
return $this->type === \Mollie\Api\Types\OrderLineType::TYPE_GIFT_CARD;
}
/**
* Is this order line for a surcharge?
*
* @return bool
*/
public function isSurcharge()
{
return $this->type === \Mollie\Api\Types\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 \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\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,30 @@
<?php
namespace Mollie\Api\Resources;
class OrderLineCollection extends \Mollie\Api\Resources\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,62 @@
<?php
namespace Mollie\Api\Resources;
class Organization extends \Mollie\Api\Resources\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,21 @@
<?php
namespace Mollie\Api\Resources;
class OrganizationCollection extends \Mollie\Api\Resources\CursorCollection
{
/**
* @return string
*/
public function getCollectionResourceName()
{
return "organizations";
}
/**
* @return BaseResource
*/
protected function createResourceObject()
{
return new \Mollie\Api\Resources\Organization($this->client);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Mollie\Api\Resources;
class Partner extends \Mollie\Api\Resources\BaseResource
{
/**
* Indicates the type of partner. Will be null if the currently authenticated organization is
* not enrolled as a partner. Possible values: "oauth", "signuplink", "useragent".
*
* @var string
*/
public $partnerType;
/**
* Will be true if partner is receiving commissions. Will be null otherwise.
*
* @var bool|null
*/
public $isCommissionPartner;
/**
* Array of user agent token objects. Present if the partner is of type "useragent" or if the partner
* has had user agent tokens in the past. Will be null otherwise.
*
* @var array|null
*/
public $userAgentTokens;
/**
* The date and time the contract was signed, in ISO 8601 format. Will be null if the contract has
* not yet been signed, or if "partnerType" is null.
*
* @var string|null
*/
public $partnerContractSignedAt;
/**
* Will be true if an updated contract is available, requiring the partners agreement.
* Will be null otherwise.
*
* @var bool|null
*/
public $partnerContractUpdateAvailable;
/**
* @var \stdClass
*/
public $_links;
}

View File

@@ -0,0 +1,672 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\PaymentStatus;
use Mollie\Api\Types\SequenceType;
class Payment extends \Mollie\Api\Resources\BaseResource
{
/**
* Id of the payment (on the Mollie platform).
*
* @var string
*/
public $id;
/**
* Mode of the payment, either "live" or "test" depending on the API Key that was
* used.
*
* @var string
*/
public $mode;
/**
* Amount object containing the value and currency
*
* @var \stdClass
*/
public $amount;
/**
* The amount that has been settled containing the value and currency
*
* @var \stdClass|null
*/
public $settlementAmount;
/**
* The amount of the payment that has been refunded to the consumer, in EURO with
* 2 decimals. This field will be null if the payment can not be refunded.
*
* @var \stdClass|null
*/
public $amountRefunded;
/**
* The amount of a refunded payment that can still be refunded, in EURO with 2
* decimals. This field will be null if the payment can not be refunded.
*
* For some payment methods this amount can be higher than the payment amount.
* This is possible to reimburse the costs for a return shipment to your customer
* for example.
*
* @var \stdClass|null
*/
public $amountRemaining;
/**
* The total amount that was charged back for this payment. Only available when the
* total charged back amount is not zero.
*
* @var \stdClass|null
*/
public $amountChargedBack;
/**
* Description of the payment that is shown to the customer during the payment,
* and possibly on the bank or credit card statement.
*
* @var string
*/
public $description;
/**
* If method is empty/null, the customer can pick his/her preferred payment
* method.
*
* @see Method
* @var string|null
*/
public $method;
/**
* The status of the payment.
*
* @var string
*/
public $status = \Mollie\Api\Types\PaymentStatus::STATUS_OPEN;
/**
* UTC datetime the payment was created in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $createdAt;
/**
* UTC datetime the payment was paid in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $paidAt;
/**
* UTC datetime the payment was canceled in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $canceledAt;
/**
* UTC datetime the payment expired in ISO-8601 format.
*
* @var string|null
*/
public $expiresAt;
/**
* UTC datetime the payment failed in ISO-8601 format.
*
* @var string|null
*/
public $failedAt;
/**
* $dueDate is used only for banktransfer method
* The date the payment should expire. Please note: the minimum date is tomorrow and the maximum date is 100 days after tomorrow.
* UTC due date for the banktransfer payment in ISO-8601 format.
*
* @example "2021-01-19"
* @var string|null
*/
public $dueDate;
/**
* Consumers email address, to automatically send the bank transfer details to.
* Please note: the payment instructions will be sent immediately when creating the payment.
*
* @example "user@mollie.com"
* @var string|null
*/
public $billingEmail;
/**
* The profile ID this payment belongs to.
*
* @example pfl_xH2kP6Nc6X
* @var string
*/
public $profileId;
/**
* Either "first", "recurring", or "oneoff" for regular payments.
*
* @var string|null
*/
public $sequenceType;
/**
* Redirect URL set on this payment
*
* @var string
*/
public $redirectUrl;
/**
* Cancel URL set on this payment
*
* @var string
*/
public $cancelUrl;
/**
* Webhook URL set on this payment
*
* @var string|null
*/
public $webhookUrl;
/**
* The mandate ID this payment is performed with.
*
* @example mdt_pXm1g3ND
* @var string|null
*/
public $mandateId;
/**
* The subscription ID this payment belongs to.
*
* @example sub_rVKGtNd6s3
* @var string|null
*/
public $subscriptionId;
/**
* The order ID this payment belongs to.
*
* @example ord_pbjz8x
* @var string|null
*/
public $orderId;
/**
* The settlement ID this payment belongs to.
*
* @example stl_jDk30akdN
* @var string|null
*/
public $settlementId;
/**
* The locale used for this payment.
*
* @var string|null
*/
public $locale;
/**
* During creation of the payment you can set custom metadata that is stored with
* the payment, and given back whenever you retrieve that payment.
*
* @var \stdClass|mixed|null
*/
public $metadata;
/**
* Details of a successfully paid payment are set here. For example, the iDEAL
* payment method will set $details->consumerName and $details->consumerAccount.
*
* @var \stdClass|null
*/
public $details;
/**
* Used to restrict the payment methods available to your customer to those from a single country.
*
* @var string|null;
*/
public $restrictPaymentMethodsToCountry;
/**
* @var \stdClass
*/
public $_links;
/**
* @var \stdClass[]
*/
public $_embedded;
/**
* Whether or not this payment can be canceled.
*
* @var bool|null
*/
public $isCancelable;
/**
* The total amount that is already captured for this payment. Only available
* when this payment supports captures.
*
* @var \stdClass|null
*/
public $amountCaptured;
/**
* Indicates whether the capture will be scheduled automatically or not. Set
* to manual to capture the payment manually using the Create capture endpoint.
*
* Possible values: "automatic", "manual"
*
* @var string|null
*/
public $captureMode;
/**
* Indicates the interval to wait before the payment is
* captured, for example `8 hours` or `2 days. The capture delay
* will be added to the date and time the payment became authorized.
*
* Possible values: ... hours ... days
* @example 8 hours
* @var string|null
*/
public $captureDelay;
/**
* UTC datetime on which the merchant has to have captured the payment in
* ISO-8601 format. This parameter is omitted if the payment is not authorized (yet).
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $captureBefore;
/**
* The application fee, if the payment was created with one. Contains amount
* (the value and currency) and description.
*
* @var \stdClass|null
*/
public $applicationFee;
/**
* An optional routing configuration which enables you to route a successful payment,
* or part of the payment, to one or more connected accounts. Additionally, you can
* schedule (parts of) the payment to become available on the connected account on a
* future date.
*
* @var array|null
*/
public $routing;
/**
* The date and time the payment became authorized, in ISO 8601 format. This
* parameter is omitted if the payment is not authorized (yet).
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $authorizedAt;
/**
* The date and time the payment was expired, in ISO 8601 format. This
* parameter is omitted if the payment did not expire (yet).
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $expiredAt;
/**
* If a customer was specified upon payment creation, the customers token will
* be available here as well.
*
* @example cst_XPn78q9CfT
* @var string|null
*/
public $customerId;
/**
* This optional field contains your customers ISO 3166-1 alpha-2 country code,
* detected by us during checkout. For example: BE. This field is omitted if the
* country code was not detected.
*
* @var string|null
*/
public $countryCode;
/**
* Is this payment canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_CANCELED;
}
/**
* Is this payment expired?
*
* @return bool
*/
public function isExpired()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_EXPIRED;
}
/**
* Is this payment still open / ongoing?
*
* @return bool
*/
public function isOpen()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_OPEN;
}
/**
* Is this payment pending?
*
* @return bool
*/
public function isPending()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_PENDING;
}
/**
* Is this payment authorized?
*
* @return bool
*/
public function isAuthorized()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_AUTHORIZED;
}
/**
* Is this payment paid for?
*
* @return bool
*/
public function isPaid()
{
return !empty($this->paidAt);
}
/**
* Does the payment have refunds
*
* @return bool
*/
public function hasRefunds()
{
return !empty($this->_links->refunds);
}
/**
* Does this payment has chargebacks
*
* @return bool
*/
public function hasChargebacks()
{
return !empty($this->_links->chargebacks);
}
/**
* Is this payment failing?
*
* @return bool
*/
public function isFailed()
{
return $this->status === \Mollie\Api\Types\PaymentStatus::STATUS_FAILED;
}
/**
* Check whether 'sequenceType' is set to 'first'. If a 'first' payment has been
* completed successfully, the consumer's account may be charged automatically
* using recurring payments.
*
* @return bool
*/
public function hasSequenceTypeFirst()
{
return $this->sequenceType === \Mollie\Api\Types\SequenceType::SEQUENCETYPE_FIRST;
}
/**
* Check whether 'sequenceType' is set to 'recurring'. This type of payment is
* processed without involving
* the consumer.
*
* @return bool
*/
public function hasSequenceTypeRecurring()
{
return $this->sequenceType === \Mollie\Api\Types\SequenceType::SEQUENCETYPE_RECURRING;
}
/**
* 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;
}
/**
* Get the mobile checkout URL where the customer can complete the payment.
*
* @return string|null
*/
public function getMobileAppCheckoutUrl()
{
if (empty($this->_links->mobileAppCheckout)) {
return null;
}
return $this->_links->mobileAppCheckout->href;
}
/**
* @return bool
*/
public function canBeRefunded()
{
return $this->amountRemaining !== null;
}
/**
* @return bool
*/
public function canBePartiallyRefunded()
{
return $this->canBeRefunded();
}
/**
* Get the amount that is already refunded
*
* @return float
*/
public function getAmountRefunded()
{
if ($this->amountRefunded) {
return (float) $this->amountRefunded->value;
}
return 0.0;
}
/**
* Get the remaining amount that can be refunded. For some payment methods this
* amount can be higher than the payment amount. This is possible to reimburse
* the costs for a return shipment to your customer for example.
*
* @return float
*/
public function getAmountRemaining()
{
if ($this->amountRemaining) {
return (float) $this->amountRemaining->value;
}
return 0.0;
}
/**
* Get the total amount that was charged back for this payment. Only available when the
* total charged back amount is not zero.
*
* @return float
*/
public function getAmountChargedBack()
{
if ($this->amountChargedBack) {
return (float) $this->amountChargedBack->value;
}
return 0.0;
}
/**
* Does the payment have split payments
*
* @return bool
*/
public function hasSplitPayments()
{
return !empty($this->routing);
}
/**
* Retrieves all refunds associated with this payment
*
* @return RefundCollection
* @throws ApiException
*/
public function refunds()
{
if (!isset($this->_links->refunds->href)) {
return new \Mollie\Api\Resources\RefundCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->refunds->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->refunds, \Mollie\Api\Resources\Refund::class, $result->_links);
}
/**
* @param string $refundId
* @param array $parameters
*
* @return Refund
* @throws ApiException
*/
public function getRefund($refundId, array $parameters = [])
{
return $this->client->paymentRefunds->getFor($this, $refundId, $this->withPresetOptions($parameters));
}
/**
* @param array $parameters
*
* @return Refund
* @throws ApiException
*/
public function listRefunds(array $parameters = [])
{
return $this->client->paymentRefunds->listFor($this, $this->withPresetOptions($parameters));
}
/**
* Retrieves all captures associated with this payment
*
* @return CaptureCollection
* @throws ApiException
*/
public function captures()
{
if (!isset($this->_links->captures->href)) {
return new \Mollie\Api\Resources\CaptureCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->captures->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->captures, \Mollie\Api\Resources\Capture::class, $result->_links);
}
/**
* @param string $captureId
* @param array $parameters
*
* @return Capture
* @throws ApiException
*/
public function getCapture($captureId, array $parameters = [])
{
return $this->client->paymentCaptures->getFor($this, $captureId, $this->withPresetOptions($parameters));
}
/**
* Retrieves all chargebacks associated with this payment
*
* @return ChargebackCollection
* @throws ApiException
*/
public function chargebacks()
{
if (!isset($this->_links->chargebacks->href)) {
return new \Mollie\Api\Resources\ChargebackCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->chargebacks->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->chargebacks, \Mollie\Api\Resources\Chargeback::class, $result->_links);
}
/**
* Retrieves a specific chargeback for this payment.
*
* @param string $chargebackId
* @param array $parameters
*
* @return Chargeback
* @throws ApiException
*/
public function getChargeback($chargebackId, array $parameters = [])
{
return $this->client->paymentChargebacks->getFor($this, $chargebackId, $this->withPresetOptions($parameters));
}
/**
* Issue a refund for this payment.
*
* @param array $data
*
* @return \Mollie\Api\Resources\Refund
* @throws ApiException
*/
public function refund($data)
{
return $this->client->paymentRefunds->createFor($this, $data);
}
/**
* @return \Mollie\Api\Resources\Payment
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function update()
{
$body = ["description" => $this->description, "cancelUrl" => $this->cancelUrl, "redirectUrl" => $this->redirectUrl, "webhookUrl" => $this->webhookUrl, "metadata" => $this->metadata, "restrictPaymentMethodsToCountry" => $this->restrictPaymentMethodsToCountry, "locale" => $this->locale, "dueDate" => $this->dueDate];
$result = $this->client->payments->update($this->id, $body);
return \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\Payment($this->client));
}
/**
* When accessed by oAuth we want to pass the testmode by default
*
* @return array
*/
private 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
*/
private function withPresetOptions(array $options)
{
return \array_merge($this->getPresetOptions(), $options);
}
/**
* The total amount that is already captured for this payment. Only available
* when this payment supports captures.
*
* @return float
*/
public function getAmountCaptured()
{
if ($this->amountCaptured) {
return (float) $this->amountCaptured->value;
}
return 0.0;
}
/**
* The amount that has been settled.
*
* @return float
*/
public function getSettlementAmount()
{
if ($this->settlementAmount) {
return (float) $this->settlementAmount->value;
}
return 0.0;
}
/**
* The total amount that is already captured for this payment. Only available
* when this payment supports captures.
*
* @return float
*/
public function getApplicationFeeAmount()
{
if ($this->applicationFee) {
return (float) $this->applicationFee->amount->value;
}
return 0.0;
}
}

View File

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

View File

@@ -0,0 +1,112 @@
<?php
namespace Mollie\Api\Resources;
class PaymentLink extends \Mollie\Api\Resources\BaseResource
{
/**
* Id of the payment link (on the Mollie platform).
*
* @var string
*/
public $id;
/**
* Mode of the payment link, either "live" or "test" depending on the API Key that was
* used.
*
* @var string
*/
public $mode;
/**
* The profile ID this payment link belongs to.
*
* @example pfl_QkEhN94Ba
* @var string
*/
public $profileId;
/**
* UTC datetime the payment link was created in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $createdAt;
/**
* UTC datetime the payment was paid in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $paidAt;
/**
* Whether the payment link is archived. Customers will not be able to complete
* payments on archived payment links.
*
* @var bool
*/
public $archived;
/**
* UTC datetime the payment link was updated in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $updatedAt;
/**
* UTC datetime - the expiry date of the payment link in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string|null
*/
public $expiresAt;
/**
* Amount object containing the value and currency
*
* @var \stdClass
*/
public $amount;
/**
* Description of the payment link that is shown to the customer during the payment,
* and possibly on the bank or credit card statement.
*
* @var string
*/
public $description;
/**
* Redirect URL set on this payment
*
* @var string
*/
public $redirectUrl;
/**
* Webhook URL set on this payment link
*
* @var string|null
*/
public $webhookUrl;
/**
* @var \stdClass
*/
public $_links;
/**
* Is this payment paid for?
*
* @return bool
*/
public function isPaid()
{
return !empty($this->paidAt);
}
/**
* Get the checkout URL where the customer can complete the payment.
*
* @return string|null
*/
public function getCheckoutUrl()
{
if (empty($this->_links->paymentLink)) {
return null;
}
return $this->_links->paymentLink->href;
}
}

View File

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

View File

@@ -0,0 +1,24 @@
<?php
namespace Mollie\Api\Resources;
class Permission extends \Mollie\Api\Resources\BaseResource
{
/**
* @var string
* @example payments.read
*/
public $id;
/**
* @var string
*/
public $description;
/**
* @var bool
*/
public $granted;
/**
* @var \stdClass
*/
public $_links;
}

View File

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

View File

@@ -0,0 +1,180 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\ProfileStatus;
class Profile extends \Mollie\Api\Resources\BaseResource
{
/**
* @var string
*/
public $id;
/**
* Test or live mode
*
* @var string
*/
public $mode;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $website;
/**
* @var string
*/
public $email;
/**
* @var string
*/
public $phone;
/**
* See https://docs.mollie.com/reference/v2/profiles-api/get-profile
* This parameter is deprecated and will be removed in 2022. Please use the businessCategory parameter instead.
*
* @deprecated
* @var int|null
*/
public $categoryCode;
/**
* See https://docs.mollie.com/reference/v2/profiles-api/get-profile
*
* @var string|null
*/
public $businessCategory;
/**
* @var string
*/
public $status;
/**
* @var \stdClass
*/
public $review;
/**
* UTC datetime the profile was created in ISO-8601 format.
*
* @example "2013-12-25T10:30:54+00:00"
* @var string
*/
public $createdAt;
/**
* @var \stdClass
*/
public $_links;
/**
* @return bool
*/
public function isUnverified()
{
return $this->status == \Mollie\Api\Types\ProfileStatus::STATUS_UNVERIFIED;
}
/**
* @return bool
*/
public function isVerified()
{
return $this->status == \Mollie\Api\Types\ProfileStatus::STATUS_VERIFIED;
}
/**
* @return bool
*/
public function isBlocked()
{
return $this->status == \Mollie\Api\Types\ProfileStatus::STATUS_BLOCKED;
}
/**
* @return \Mollie\Api\Resources\Profile
* @throws ApiException
*/
public function update()
{
$body = ["name" => $this->name, "website" => $this->website, "email" => $this->email, "phone" => $this->phone, "businessCategory" => $this->businessCategory, "mode" => $this->mode];
$result = $this->client->profiles->update($this->id, $body);
return \Mollie\Api\Resources\ResourceFactory::createFromApiResult($result, new \Mollie\Api\Resources\Profile($this->client));
}
/**
* Retrieves all chargebacks associated with this profile
*
* @return ChargebackCollection
* @throws ApiException
*/
public function chargebacks()
{
if (!isset($this->_links->chargebacks->href)) {
return new \Mollie\Api\Resources\ChargebackCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->chargebacks->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->chargebacks, \Mollie\Api\Resources\Chargeback::class, $result->_links);
}
/**
* Retrieves all methods activated on this profile
*
* @return MethodCollection
* @throws ApiException
*/
public function methods()
{
if (!isset($this->_links->methods->href)) {
return new \Mollie\Api\Resources\MethodCollection(0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->methods->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->methods, \Mollie\Api\Resources\Method::class, $result->_links);
}
/**
* 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->createFor($this, $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->deleteFor($this, $methodId, $data);
}
/**
* Retrieves all payments associated with this profile
*
* @return PaymentCollection
* @throws ApiException
*/
public function payments()
{
if (!isset($this->_links->payments->href)) {
return new \Mollie\Api\Resources\PaymentCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->payments->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->methods, \Mollie\Api\Resources\Method::class, $result->_links);
}
/**
* Retrieves all refunds associated with this profile
*
* @return RefundCollection
* @throws ApiException
*/
public function refunds()
{
if (!isset($this->_links->refunds->href)) {
return new \Mollie\Api\Resources\RefundCollection($this->client, 0, null);
}
$result = $this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_GET, $this->_links->refunds->href);
return \Mollie\Api\Resources\ResourceFactory::createCursorResourceCollection($this->client, $result->_embedded->refunds, \Mollie\Api\Resources\Refund::class, $result->_links);
}
}

View File

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

View File

@@ -0,0 +1,153 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\RefundStatus;
class Refund extends \Mollie\Api\Resources\BaseResource
{
/**
* 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
*/
public $createdAt;
/**
* The refund's description, if available.
*
* @var string|null
*/
public $description;
/**
* The payment id that was refunded.
*
* @var string
*/
public $paymentId;
/**
* The order id that was refunded.
*
* @var string|null
*/
public $orderId;
/**
* The order lines contain the actual things the customer ordered.
* The lines will show the quantity, discountAmount, vatAmount and totalAmount
* refunded.
*
* @var array|object[]|null
*/
public $lines;
/**
* The settlement amount
*
* @var \stdClass
*/
public $settlementAmount;
/**
* The refund status
*
* @var string
*/
public $status;
/**
* @var \stdClass
*/
public $_links;
/**
* An object containing information relevant to a refund issued for a split payment.
*
* @var array|object[]|null
*/
public $routingReversal;
/**
* @var \stdClass|null
*/
public $metadata;
/**
* @return bool
*/
public function canBeCanceled()
{
return $this->isQueued() || $this->isPending();
}
/**
* Is this refund queued?
*
* @return bool
*/
public function isQueued()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_QUEUED;
}
/**
* Is this refund pending?
*
* @return bool
*/
public function isPending()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_PENDING;
}
/**
* Is this refund processing?
*
* @return bool
*/
public function isProcessing()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_PROCESSING;
}
/**
* Is this refund transferred to consumer?
*
* @return bool
*/
public function isTransferred()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_REFUNDED;
}
/**
* Is this refund failed?
*
* @return bool
*/
public function isFailed()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_FAILED;
}
/**
* Is this refund canceled?
*
* @return bool
*/
public function isCanceled()
{
return $this->status === \Mollie\Api\Types\RefundStatus::STATUS_CANCELED;
}
/**
* Cancel the refund.
* Returns null if successful.
*
* @return null
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function cancel()
{
$this->client->performHttpCallToFullUrl(\Mollie\Api\MollieApiClient::HTTP_DELETE, $this->_links->self->href);
return null;
}
}

View File

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

View File

@@ -0,0 +1,61 @@
<?php
namespace Mollie\Api\Resources;
use Mollie\Api\MollieApiClient;
#[\AllowDynamicProperties]
class ResourceFactory
{
/**
* Create resource object from Api result
*
* @param object $apiResult
* @param BaseResource $resource
*
* @return mixed
*/
public static function createFromApiResult($apiResult, \Mollie\Api\Resources\BaseResource $resource)
{
foreach ($apiResult as $property => $value) {
$resource->{$property} = $value;
}
return $resource;
}
/**
* @param MollieApiClient $client
* @param string $resourceClass
* @param array $data
* @param null $_links
* @param string $resourceCollectionClass
* @return mixed
*/
public static function createBaseResourceCollection(\Mollie\Api\MollieApiClient $client, $resourceClass, $data, $_links = null, $resourceCollectionClass = null)
{
$resourceCollectionClass = $resourceCollectionClass ?: $resourceClass . 'Collection';
$data = $data ?: [];
$result = new $resourceCollectionClass(\count($data), $_links);
foreach ($data as $item) {
$result[] = static::createFromApiResult($item, new $resourceClass($client));
}
return $result;
}
/**
* @param MollieApiClient $client
* @param array $input
* @param string $resourceClass
* @param null $_links
* @param null $resourceCollectionClass
* @return mixed
*/
public static function createCursorResourceCollection($client, array $input, $resourceClass, $_links = null, $resourceCollectionClass = null)
{
if (null === $resourceCollectionClass) {
$resourceCollectionClass = $resourceClass . 'Collection';
}
$data = new $resourceCollectionClass($client, \count($input), $_links);
foreach ($input as $item) {
$data[] = static::createFromApiResult($item, new $resourceClass($client));
}
return $data;
}
}

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