Initial commit

This commit is contained in:
Piet Nijbacker committed 2026-10-10 21:32:00 +02:00
commit 2b9e58beee
822 files changed
+62544

No files matched your search

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace Mollie\Api;
use Mollie\Api\Exceptions\IncompatiblePlatformException;
class CompatibilityChecker
{
/**
* @var string
*/
public const MIN_PHP_VERSION = '8.2';
public static function make(): self
{
return new self;
}
/**
* @return void
*
* @throws IncompatiblePlatformException
*/
public function checkCompatibility()
{
if (! $this->satisfiesPhpVersion()) {
throw new IncompatiblePlatformException(
'The client requires PHP version >= '.self::MIN_PHP_VERSION.', you have '.PHP_VERSION.'.',
IncompatiblePlatformException::INCOMPATIBLE_PHP_VERSION
);
}
if (! $this->satisfiesJsonExtension()) {
throw new IncompatiblePlatformException(
"PHP extension json is not enabled. Please make sure to enable 'json' in your PHP configuration.",
IncompatiblePlatformException::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;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Mollie\Api;
use Mollie\Api\Resources\ResourceRegistry;
class Config
{
/**
* Resolver used to fetch the global ResourceRegistry, e.g. from a container.
*
* @var callable():ResourceRegistry|null
*/
private static $resourceRegistryResolver = null;
/**
* Set a resolver that returns a ResourceRegistry instance. Pass null to reset.
*
* @param callable():ResourceRegistry|null $resolver
*/
public static function setResourceRegistryResolver(?callable $resolver): void
{
self::$resourceRegistryResolver = $resolver;
}
/**
* Resolve the ResourceRegistry. Uses the resolver if set, otherwise defaults.
*/
public static function resourceRegistry(): ResourceRegistry
{
$resolver = self::$resourceRegistryResolver;
if (! is_callable($resolver)) {
return ResourceRegistry::default();
}
$registry = call_user_func($resolver);
if (! $registry instanceof ResourceRegistry) {
return ResourceRegistry::default();
}
return $registry;
}
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface Arrayable
{
public function toArray(): array;
}
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface Authenticatable
{
public function setApiKey(string $apiKey): self;
public function setAccessToken(string $accessToken): self;
public function getAuthenticator(): ?Authenticator;
}
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\PendingRequest;
interface Authenticator
{
public function authenticate(PendingRequest $pendingRequest): void;
}
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\Middleware;
use Mollie\Api\Http\Request;
interface Connector extends Authenticatable, IdempotencyContract, SupportsDebuggingContract, Testable
{
/**
* @return mixed
*/
public function send(Request $request);
public function resolveBaseUrl(): string;
public function headers(): Repository;
public function query(): Repository;
public function middleware(): Middleware;
public function addVersionString($versionString): self;
public function getVersionStrings(): array;
public function getHttpClient(): HttpAdapterContract;
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface EmbeddedResourcesContract
{
public function getEmbeddedResourcesMap(): array;
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface HasPayload
{
public function payload(): PayloadRepository;
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\PendingRequest;
use Mollie\Api\Http\Response;
use Mollie\Api\Utils\Factories;
interface HttpAdapterContract
{
public function factories(): Factories;
/**
* Send a request to the specified Mollie api url.
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function sendRequest(PendingRequest $pendingRequest): Response;
/**
* The version number for the underlying http client, if available.
*
* @example Guzzle/6.3
*/
public function version(): ?string;
}
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface IdempotencyContract
{
public function getIdempotencyKey(): ?string;
public function resetIdempotencyKey(): self;
public function getIdempotencyKeyGenerator(): ?IdempotencyKeyGeneratorContract;
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface IdempotencyKeyGeneratorContract
{
public function generate(): string;
}
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface IsIteratable
{
public function iteratorEnabled(): bool;
public function iteratesBackwards(): bool;
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\Response;
interface IsResponseAware extends ViableResponse
{
/**
* Returns the HTTP `Response` this resource was hydrated from, or
* `null` when the resource was hydrated from a non-HTTP origin
* (for example a signed webhook envelope). Use
* {@see \Mollie\Api\Contracts\ResourceOrigin} via
* `$resource->getOrigin()` to inspect provenance across both cases.
*/
public function getResponse(): ?Response;
/**
* @return $this
*/
public function setResponse(Response $response);
}
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\Response;
use Mollie\Api\Resources\BaseCollection;
use Mollie\Api\Resources\BaseResource;
use Mollie\Api\Resources\LazyCollection;
interface IsWrapper extends ViableResponse
{
/**
* @param Response|BaseResource|BaseCollection|LazyCollection $resource
*/
public static function fromResource($resource): self;
}
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface MollieHttpAdapterPickerContract
{
/**
* @param \GuzzleHttp\ClientInterface|HttpAdapterContract $httpClient
*/
public function pickHttpAdapter($httpClient): HttpAdapterContract;
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
interface PayloadRepository extends Repository
{
/**
* Convert the repository contents into a stream
*/
public function toStream(StreamFactoryInterface $streamFactory): StreamInterface;
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface Repository
{
/**
* Set the entire repository data
*
* @param mixed $data Array for array repositories, mixed for payload repositories
* @return static
*/
public function set($data);
/**
* Get a value by key
*
* @param mixed $default
* @return mixed
*/
public function get(string $key, $default = null);
/**
* Check if a key exists
*/
public function has(string $key): bool;
/**
* Add a value to the repository
*
* @param mixed $value
* @return static
*/
public function add(string $key, $value);
/**
* Merge data into the repository
*
* @return static
*/
public function merge(array ...$data);
/**
* Remove a key from the repository
*/
public function remove(string $key);
/**
* Get all data from the repository
*
* @return mixed
*/
public function all();
/**
* Check if the repository is empty
*/
public function isEmpty(): bool;
/**
* Check if the repository is not empty
*/
public function isNotEmpty(): bool;
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\PendingRequest;
interface RequestMiddleware
{
/**
* @return PendingRequest|void
*/
public function __invoke(PendingRequest $pendingRequest);
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface Resolvable extends Arrayable
{
}
@@ -0,0 +1,16 @@
<?php
namespace Mollie\Api\Contracts;
/**
* Marker contract for "where did this hydrated resource come from."
*
* Implemented by {@see \Mollie\Api\Http\Response} for HTTP-hydrated
* resources and by {@see \Mollie\Api\Webhooks\WebhookSnapshotOrigin}
* for resources hydrated from a signed webhook envelope. Additional
* implementations can be added without touching the hydrator.
*/
interface ResourceOrigin
{
public function getConnector(): Connector;
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Mollie\Api\Http\Response;
interface ResponseMiddleware
{
/**
* @return Response|void
*/
public function __invoke(Response $response);
}
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
use Throwable;
/**
* Defines how retries are performed for retryable network errors.
*/
interface RetryStrategyContract
{
/**
* The maximum number of retries after the initial attempt.
*/
public function maxRetries(): int;
/**
* Whether a given exception should trigger a retry.
*
* Implementations decide which exception classes are retryable.
* Non-retryable exceptions propagate immediately.
*/
public function shouldRetry(Throwable $exception): bool;
/**
* Delay in milliseconds before performing the given retry attempt.
*
* The $attempt parameter starts at 1 for the first retry. Implementations
* may inspect the triggering exception (for example, a 429's Retry-After
* header) to decide the delay.
*/
public function delayBeforeAttemptMs(int $attempt, ?Throwable $exception = null): int;
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
/**
* @internal
*
* Remove this once we drop support for PHP 7.4
*/
interface Stringable
{
public function __toString(): string;
}
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface SupportsDebuggingContract
{
public function debugRequest(?callable $debugger = null, bool $die = false): self;
public function debugResponse(?callable $debugger = null, bool $die = false): self;
public function debug(bool $die = false): self;
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface SupportsTestmode
{
//
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface SupportsTestmodeInPayload extends HasPayload, SupportsTestmode
{
//
}
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface SupportsTestmodeInQuery extends SupportsTestmode
{
//
}
+10
View File
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
interface Testable
{
public function getTestmode(): ?bool;
}
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Contracts;
/**
* Marks a class as returnable from a middleware handler.
*/
interface ViableResponse
{
//
}
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Http\Requests\GetBalanceRequest;
use Mollie\Api\Http\Requests\GetPaginatedBalanceRequest;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Utils\Utility;
class BalanceEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single balance from Mollie.
*
* Will throw an ApiException if the balance id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $id, $testmode = false): Balance
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send((new GetBalanceRequest($id))->test($testmode));
}
/**
* Retrieve the primary balance from Mollie.
*
* Will throw an ApiException if the balance id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function primary($testmode = false): Balance
{
/** @var Balance */
return $this->get('primary', $testmode);
}
/**
* Get the balance endpoint.
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): BalanceCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send((new GetPaginatedBalanceRequest(
$query->from,
$query->limit,
$query->sort,
))->test($testmode));
}
/**
* Create an iterator for iterating over balances retrieved from Mollie.
*
* @param string $from The first Balance ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
(new GetPaginatedBalanceRequest(
$query->from,
$query->limit,
$query->sort,
))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Factories\GetBalanceReportRequestFactory;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceReport;
use Mollie\Api\Utils\Utility;
class BalanceReportEndpointCollection extends EndpointCollection
{
/**
* Retrieve a balance report for the provided balance id and parameters.
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function getForId(string $balanceId, array $query = []): ?BalanceReport
{
$testmode = Utility::extractBool($query, 'testmode', false);
$request = GetBalanceReportRequestFactory::new($balanceId)
->withQuery($query)
->create();
/** @var BalanceReport */
return $this->send($request->test($testmode));
}
/**
* Retrieve the primary balance.
* This is the balance of your account’s primary currency, where all payments are settled to by default.
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function getForPrimary(array $query = []): ?BalanceReport
{
return $this->getForId('primary', $query);
}
/**
* Retrieve a balance report for the provided balance resource and parameters.
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function getFor(Balance $balance, array $query = []): ?BalanceReport
{
return $this->getForId($balance->id, $query);
}
}
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\PaginatedQueryFactory;
use Mollie\Api\Http\Requests\GetPaginatedBalanceTransactionRequest;
use Mollie\Api\Resources\Balance;
use Mollie\Api\Resources\BalanceTransactionCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Utils\Utility;
class BalanceTransactionEndpointCollection extends EndpointCollection
{
/**
* List the transactions for a specific Balance.
*
* @throws RequestException
*/
public function pageFor(Balance $balance, array $query = [], bool $testmode = false): BalanceTransactionCollection
{
return $this->pageForId($balance->id, $query, $testmode);
}
/**
* List the transactions for the primary Balance.
*
* @throws RequestException
*/
public function pageForPrimary(array $query = [], bool $testmode = false): BalanceTransactionCollection
{
/** @var BalanceTransactionCollection */
return $this->pageForId('primary', $query, $testmode);
}
/**
* List the transactions for a specific Balance ID.
*
* @throws RequestException
*/
public function pageForId(string $balanceId, array $query = [], bool $testmode = false): BalanceTransactionCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$query = PaginatedQueryFactory::new()
->withQuery($query)
->create();
/** @var BalanceTransactionCollection */
return $this->send((new GetPaginatedBalanceTransactionRequest(
$balanceId,
$query->from,
$query->limit,
))->test($testmode));
}
/**
* Create an iterator for iterating over balance transactions for the given balance retrieved from Mollie.
*
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(Balance $balance, array $query = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection
{
return $this->iteratorForId($balance->id, $query, $iterateBackwards, $testmode);
}
/**
* Create an iterator for iterating over transactions for the primary balance retrieved from Mollie.
*
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
* @param bool|null $testmode Passing null is deprecated; null is treated as false.
*/
public function iteratorForPrimary(array $query = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection
{
$testmode ??= false;
return $this->iteratorForId('primary', $query, $iterateBackwards, $testmode);
}
/**
* Create an iterator for iterating over balance transactions for the given balance id retrieved from Mollie.
*
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(string $balanceId, array $query = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$query = PaginatedQueryFactory::new()
->withQuery($query)
->create();
return $this->send(
(new GetPaginatedBalanceTransactionRequest(
$balanceId,
$query->from,
$query->limit,
))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetCapabilityRequest;
use Mollie\Api\Http\Requests\ListCapabilitiesRequest;
use Mollie\Api\Resources\Capability;
use Mollie\Api\Resources\CapabilityCollection;
class CapabilityEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single Permission from Mollie.
*
* Will throw an ApiException if the permission id is invalid.
*
* @throws RequestException
*/
public function get(string $name): Capability
{
/** @var Capability */
return $this->send((new GetCapabilityRequest($name)));
}
/**
* Retrieve all capabilities from Mollie.
*
* @throws RequestException
*/
public function list(): CapabilityCollection
{
/** @var CapabilityCollection */
return $this->send(new ListCapabilitiesRequest);
}
}
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedChargebacksRequestFactory;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Utils\Utility;
class ChargebackEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Chargebacks from Mollie.
*
* @param string $from The first chargeback ID you want to include in your list.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): ChargebackCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedChargebacksRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
/** @var ChargebackCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over chargeback retrieved from Mollie.
*
* @param string $from The first chargevback ID you want to include in your list.
* @param array $filters
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, $filters = [], bool $iterateBackwards = false): LazyCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedChargebacksRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetClientRequestFactory;
use Mollie\Api\Factories\GetPaginatedClientRequestFactory;
use Mollie\Api\Resources\Client;
use Mollie\Api\Resources\ClientCollection;
use Mollie\Api\Resources\LazyCollection;
class ClientEndpointCollection extends EndpointCollection
{
/**
* 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 $id The client ID.
*
* @throws RequestException
*/
public function get(string $id, array $query = []): Client
{
$request = GetClientRequestFactory::new($id)
->withQuery($query)
->create();
/** @var Client */
return $this->send($request);
}
/**
* Retrieves a page of clients from Mollie.
*
* @param string $from The first client ID you want to include in your list.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): ClientCollection
{
$request = GetPaginatedClientRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
/** @var ClientCollection */
return $this->send($request);
}
/**
* Create an iterator for iterating over clients retrieved from Mollie.
*
* @param string $from The first client ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$request = GetPaginatedClientRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateClientLinkRequestFactory;
use Mollie\Api\Resources\ClientLink;
class ClientLinkEndpointCollection extends EndpointCollection
{
/**
* Creates a client link in Mollie.
*
* @param array $payload An array containing details on the client link.
*
* @throws RequestException
*/
public function create(array $payload = []): ClientLink
{
$request = CreateClientLinkRequestFactory::new()
->withPayload($payload)
->create();
/** @var ClientLink */
return $this->send($request);
}
}
@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateConnectBalanceTransferRequestFactory;
use Mollie\Api\Http\Requests\GetConnectBalanceTransferRequest;
use Mollie\Api\Http\Requests\ListConnectBalanceTransfersRequest;
use Mollie\Api\Resources\ConnectBalanceTransfer;
use Mollie\Api\Resources\ConnectBalanceTransferCollection;
use Mollie\Api\Resources\LazyCollection;
class ConnectBalanceTransferEndpointCollection extends EndpointCollection
{
/**
* Creates a Connect balance transfer in Mollie.
*
* @param array $payload An array containing details on the balance transfer.
*
* @throws RequestException
*/
public function create(array $payload = [], bool $test = false): ConnectBalanceTransfer
{
$request = CreateConnectBalanceTransferRequestFactory::new()
->withPayload($payload)
->create();
/** @var ConnectBalanceTransfer */
return $this->send($request->test($test));
}
/**
* Retrieve a Connect balance transfer from Mollie.
*
* Will throw an ApiException if the balance transfer id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $id, bool $test = false): ConnectBalanceTransfer
{
/** @var ConnectBalanceTransfer */
return $this->send((new GetConnectBalanceTransferRequest($id))->test($test));
}
/**
* Retrieves a collection of Connect balance transfers from Mollie.
*
* @throws RequestException
*/
public function page(
?string $from = null,
?int $limit = null,
?string $sort = null
): ConnectBalanceTransferCollection {
$request = new ListConnectBalanceTransfersRequest(
$from,
$limit,
$sort
);
/** @var ConnectBalanceTransferCollection */
return $this->send($request);
}
/**
* Create an iterator for iterating over Connect balance transfers retrieved from Mollie.
*
* @param string|null $from The first balance transfer ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
?string $sort = null,
bool $iterateBackwards = false,
bool $test = false
): LazyCollection {
$request = new ListConnectBalanceTransfersRequest(
$from,
$limit,
$sort
);
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($test)
);
}
}
@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateCustomerRequestFactory;
use Mollie\Api\Factories\UpdateCustomerRequestFactory;
use Mollie\Api\Http\Requests\DeleteCustomerRequest;
use Mollie\Api\Http\Requests\GetCustomerRequest;
use Mollie\Api\Http\Requests\GetPaginatedCustomerRequest;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\CustomerCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Utils\Utility;
class CustomerEndpointCollection extends EndpointCollection
{
/**
* Creates a customer in Mollie.
*
* @param array|bool|null $testmode
*
* @throws RequestException
*/
public function create($data = [], $testmode = false): Customer
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
$request = CreateCustomerRequestFactory::new()
->withPayload($data)
->create();
/** @var Customer */
return $this->send($request->test($testmode));
}
/**
* Retrieve a single customer from Mollie.
*
* Will throw a ApiException if the customer id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $id, $testmode = false): Customer
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Customer */
return $this->send((new GetCustomerRequest($id))->test($testmode));
}
/**
* Update a specific Customer resource.
*
* Will throw an ApiException if the customer id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function update(string $id, array $data = []): ?Customer
{
$request = UpdateCustomerRequestFactory::new($id)
->withPayload($data)
->create();
/** @var null|Customer */
return $this->send($request);
}
/**
* 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 bool|array $testmode
*
* @throws RequestException
*/
public function delete(string $id, $testmode = false): void
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
$this->send((new DeleteCustomerRequest($id))->test($testmode));
}
/**
* Retrieves a collection of Customers from Mollie.
*
* @param string $from The first customer ID you want to include in your list.
* @param bool|array $testmode
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, $testmode = false): CustomerCollection
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var CustomerCollection */
return $this->send((new GetPaginatedCustomerRequest($from, $limit))->test($testmode));
}
/**
* Create an iterator for iterating over customers retrieved from Mollie.
*
* @param string $from The first customer ID you want to include in your list.
* @param bool|array $testmode
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, $testmode = false, bool $iterateBackwards = false): LazyCollection
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedCustomerRequest($from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateCustomerPaymentRequestFactory;
use Mollie\Api\Factories\GetPaginatedCustomerPaymentsRequestFactory;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Utils\Utility;
class CustomerPaymentsEndpointCollection extends EndpointCollection
{
/**
* Create a subscription for a Customer
*
* @throws RequestException
*/
public function createFor(Customer $customer, array $payload = [], array $query = [], bool $testmode = false): Payment
{
return $this->createForId($customer->id, $payload, $query, $testmode);
}
/**
* Create a subscription for a Customer ID
*
* @throws RequestException
*/
public function createForId(string $customerId, array $payload = [], array $query = [], bool $testmode = false): Payment
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreateCustomerPaymentRequestFactory::new($customerId)
->withPayload($payload)
->withQuery($query)
->create();
/** @var Payment */
return $this->send($request->test($testmode));
}
/**
* @param string $from The first resource ID you want to include in your list.
*
* @throws RequestException
*/
public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection
{
return $this->pageForId($customer->id, $from, $limit, $filters);
}
/**
* @param string $from The first resource ID you want to include in your list.
*
* @throws RequestException
*/
public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedCustomerPaymentsRequestFactory::new($customerId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over payments for the given customer, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Customer $customer,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($customer->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over payments for the given customer id, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $customerId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedCustomerPaymentsRequestFactory::new($customerId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Contracts\Connector;
use Mollie\Api\Http\Request;
abstract class EndpointCollection
{
protected Connector $connector;
public function __construct(Connector $connector)
{
$this->connector = $connector;
}
/**
* @return mixed
*/
protected function send(Request $request)
{
return $this->connector->send($request);
}
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedInvoiceRequestFactory;
use Mollie\Api\Http\Requests\GetInvoiceRequest;
use Mollie\Api\Resources\Invoice;
use Mollie\Api\Resources\InvoiceCollection;
use Mollie\Api\Resources\LazyCollection;
class InvoiceEndpointCollection extends EndpointCollection
{
/**
* Retrieve an Invoice from Mollie.
*
* Will throw a ApiException if the invoice id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $invoiceId): Invoice
{
/** @var Invoice */
return $this->send(new GetInvoiceRequest($invoiceId));
}
/**
* Retrieves a collection of Invoices from Mollie.
*
* @param string|null $from The first invoice ID you want to include in your list.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): InvoiceCollection
{
$request = GetPaginatedInvoiceRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
/** @var InvoiceCollection */
return $this->send($request);
}
/**
* Create an iterator for iterating over invoices retrieved from Mollie.
*
* @param string|null $from The first invoice ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$request = GetPaginatedInvoiceRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,177 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateMandateRequestFactory;
use Mollie\Api\Http\Requests\GetMandateRequest;
use Mollie\Api\Http\Requests\GetPaginatedMandateRequest;
use Mollie\Api\Http\Requests\RevokeMandateRequest;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Mandate;
use Mollie\Api\Resources\MandateCollection;
use Mollie\Api\Utils\Utility;
class MandateEndpointCollection extends EndpointCollection
{
/**
* Creates a mandate for a specific customer.
*
*
* @throws RequestException
*/
public function createFor(Customer $customer, array $payload = [], bool $testmode = false): Mandate
{
return $this->createForId($customer->id, $payload, $testmode);
}
/**
* Creates a mandate for a specific customer ID.
*
*
* @throws RequestException
*/
public function createForId(string $customerId, array $payload = [], bool $testmode = false): Mandate
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreateMandateRequestFactory::new($customerId)
->withPayload($payload)
->create();
/** @var Mandate */
return $this->send($request->test($testmode));
}
/**
* Retrieve a specific mandate for a customer.
*
*
* @throws RequestException
*/
public function getFor(Customer $customer, string $mandateId, array $parameters = []): Mandate
{
return $this->getForId($customer->id, $mandateId, $parameters);
}
/**
* Retrieve a specific mandate for a customer ID.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function getForId(string $customerId, string $mandateId, $testmode = false): Mandate
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Mandate */
return $this->send((new GetMandateRequest($customerId, $mandateId))->test($testmode));
}
/**
* Revoke a mandate for a specific customer.
*
*
* @throws RequestException
*/
public function revokeFor(Customer $customer, string $mandateId, $data = []): void
{
$this->revokeForId($customer->id, $mandateId, $data);
}
/**
* Revoke a mandate for a specific customer ID.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function revokeForId(string $customerId, string $mandateId, $testmode = false): void
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
$this->send((new RevokeMandateRequest($customerId, $mandateId))->test($testmode));
}
/**
* Retrieves a collection of mandates for the given customer.
*
* @param string $from The first mandate ID you want to include in your list.
* @param bool|array $testmode
* @param string[]|null $scopes Filter mandates by their scope. See \Mollie\Api\Types\MandateQuery.
*
* @throws RequestException
*/
public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, $testmode = false, ?array $scopes = null): MandateCollection
{
return $this->pageForId($customer->id, $from, $limit, $testmode, $scopes);
}
/**
* Retrieves a collection of mandates for the given customer ID.
*
* @param string $from The first mandate ID you want to include in your list.
* @param bool|array $testmode
* @param string[]|null $scopes Filter mandates by their scope. See \Mollie\Api\Types\MandateQuery.
*
* @throws RequestException
*/
public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, $testmode = false, ?array $scopes = null): MandateCollection
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var MandateCollection */
return $this->send(
(new GetPaginatedMandateRequest($customerId, $from, $limit, $scopes))->test($testmode)
);
}
/**
* Create an iterator for iterating over mandates for the given customer.
*
* @param string $from The first mandate ID you want to include in your list.
* @param bool|array $testmode
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
* @param string[]|null $scopes Filter mandates by their scope. See \Mollie\Api\Types\MandateQuery.
*/
public function iteratorFor(
Customer $customer,
?string $from = null,
?int $limit = null,
$testmode = false,
bool $iterateBackwards = false,
?array $scopes = null
): LazyCollection {
return $this->iteratorForId($customer->id, $from, $limit, $testmode, $iterateBackwards, $scopes);
}
/**
* Create an iterator for iterating over mandates for the given customer ID.
*
* @param string $from The first mandate ID you want to include in your list.
* @param bool|array $testmode
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
* @param string[]|null $scopes Filter mandates by their scope. See \Mollie\Api\Types\MandateQuery.
*/
public function iteratorForId(
string $customerId,
?string $from = null,
?int $limit = null,
$testmode = false,
bool $iterateBackwards = false,
?array $scopes = null
): LazyCollection {
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedMandateRequest($customerId, $from, $limit, $scopes))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetAllPaymentMethodsRequestFactory;
use Mollie\Api\Factories\GetEnabledMethodsRequestFactory;
use Mollie\Api\Factories\GetMethodRequestFactory;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\MethodCollection;
use Mollie\Api\Utils\Utility;
class MethodEndpointCollection extends EndpointCollection
{
/**
* Retrieve all methods from Mollie.
* Will return all available methods, both enabled and disabled.
*
* @param array $query Query string parameters
*
* @throws RequestException
*/
public function all(array $query = []): MethodCollection
{
$request = GetAllPaymentMethodsRequestFactory::new()
->withQuery($query)
->create();
/** @var MethodCollection */
return $this->send($request);
}
/**
* Retrieve all enabled methods for the organization.
* In test mode, this includes pending methods.
* The results are not paginated.
*
* @throws RequestException
*/
public function allEnabled(array $query = [], bool $testmode = false): MethodCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetEnabledMethodsRequestFactory::new()
->withQuery($query)
->create();
/** @var MethodCollection */
return $this->send($request->test($testmode));
}
/**
* @deprecated Use allEnabled() instead
*
* @throws RequestException
*/
public function allActive($query = [], bool $testmode = false): MethodCollection
{
return $this->allEnabled($query, $testmode);
}
/**
* Retrieve a payment method from Mollie.
*
* Will throw an ApiException if the method id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $methodId, $query = [], bool $testmode = false): Method
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetMethodRequestFactory::new($methodId)
->withQuery($query)
->create();
/** @var Method */
return $this->send($request->test($testmode));
}
}
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\DisableMethodIssuerRequest;
use Mollie\Api\Http\Requests\EnableMethodIssuerRequest;
use Mollie\Api\Resources\Issuer;
class MethodIssuerEndpointCollection extends EndpointCollection
{
/**
* Enable an issuer for a specific payment method.
*
* @throws RequestException
*/
public function enable(string $profileId, string $methodId, string $issuerId, ?string $contractId = null): Issuer
{
return $this->send(new EnableMethodIssuerRequest($profileId, $methodId, $issuerId, $contractId));
}
/**
* Disable an issuer for a specific payment method.
*
* @throws RequestException
*/
public function disable(string $profileId, string $methodId, string $issuerId): void
{
$this->send(new DisableMethodIssuerRequest($profileId, $methodId, $issuerId));
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Http\Requests\GetOnboardingStatusRequest;
use Mollie\Api\Resources\Onboarding;
class OnboardingEndpointCollection extends EndpointCollection
{
public function status(): Onboarding
{
return $this->send(new GetOnboardingStatusRequest);
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest;
use Mollie\Api\Http\Requests\GetOrganizationRequest;
use Mollie\Api\Resources\Organization;
use Mollie\Api\Resources\Partner;
use Mollie\Api\Utils\Utility;
class OrganizationEndpointCollection extends EndpointCollection
{
/**
* Retrieve an organization from Mollie.
*
* Will throw a ApiException if the organization id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $id, $testmode = false): Organization
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Organization */
return $this->send((new GetOrganizationRequest($id))->test($testmode));
}
/**
* Retrieve the current organization from Mollie.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function current($testmode = false): Organization
{
/** @var Organization */
return $this->get('me', $testmode);
}
/**
* Retrieve the partner status of the current organization.
*
* @throws RequestException
*/
public function partnerStatus(): Partner
{
return $this->send(new GetOrganizationPartnerStatusRequest);
}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Http\Requests\GetOrganizationPartnerStatusRequest;
use Mollie\Api\Resources\Partner;
/**
* @deprecated Use OrganizationEndpointCollection::partnerStatus() instead
*/
class OrganizationPartnerEndpointCollection extends EndpointCollection
{
public function status(): Partner
{
return $this->send(new GetOrganizationPartnerStatusRequest);
}
}
@@ -0,0 +1,138 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreatePaymentCaptureRequestFactory;
use Mollie\Api\Factories\GetPaginatedPaymentCapturesRequestFactory;
use Mollie\Api\Factories\GetPaymentCaptureRequestFactory;
use Mollie\Api\Resources\Capture;
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Utils\Utility;
class PaymentCaptureEndpointCollection extends EndpointCollection
{
/**
* Creates a payment capture in Mollie.
*
* @throws RequestException
*/
public function createFor(Payment $payment, array $payload = [], bool $testmode = false): Capture
{
return $this->createForId($payment->id, $payload, $testmode);
}
/**
* Creates a payment capture in Mollie.
*
* @throws RequestException
*/
public function createForId(string $paymentId, array $payload = [], bool $testmode = false): Capture
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreatePaymentCaptureRequestFactory::new($paymentId)
->withPayload($payload)
->create();
/** @var Capture */
return $this->send($request->test($testmode));
}
/**
* @throws RequestException
*/
public function getFor(Payment $payment, string $captureId, array $query = [], bool $testmode = false): Capture
{
return $this->getForId($payment->id, $captureId, $query, $testmode);
}
/**
* @throws RequestException
*/
public function getForId(string $paymentId, string $captureId, array $query = [], bool $testmode = false): Capture
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaymentCaptureRequestFactory::new($paymentId, $captureId)
->withQuery($query)
->create();
/** @var Capture */
return $this->send($request->test($testmode));
}
/**
* @throws RequestException
*/
public function pageFor(Payment $payment, array $query = [], bool $testmode = false): CaptureCollection
{
return $this->pageForId($payment->id, $query, $testmode);
}
/**
* @throws RequestException
*/
public function pageForId(string $paymentId, array $query = [], bool $testmode = false): CaptureCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaginatedPaymentCapturesRequestFactory::new($paymentId)
->withQuery($query)
->create();
/** @var CaptureCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over captures for the given payment, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Payment $payment,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over captures for the given payment id, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $paymentId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedPaymentCapturesRequestFactory::new($paymentId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedPaymentChargebacksRequestFactory;
use Mollie\Api\Factories\GetPaymentChargebackRequestFactory;
use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Utils\Utility;
class PaymentChargebackEndpointCollection extends EndpointCollection
{
/**
* @throws RequestException
*/
public function getFor(Payment $payment, string $chargebackId, array $query = [], bool $testmode = false): Chargeback
{
return $this->getForId($payment->id, $chargebackId, $query, $testmode);
}
/**
* @throws RequestException
*/
public function getForId(string $paymentId, string $chargebackId, array $query = [], bool $testmode = false): Chargeback
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaymentChargebackRequestFactory::new($paymentId, $chargebackId)
->withQuery($query)
->create();
/** @var Chargeback */
return $this->send($request->test($testmode));
}
/**
* @throws RequestException
*/
public function pageFor(Payment $payment, array $query = []): ChargebackCollection
{
return $this->pageForId($payment->id, $query);
}
/**
* @throws RequestException
*/
public function pageForId(string $paymentId, array $query = [], bool $testmode = false): ChargebackCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaginatedPaymentChargebacksRequestFactory::new($paymentId)
->withQuery($query)
->create();
/** @var ChargebackCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over chargebacks for the given payment, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Payment $payment,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over chargebacks for the given payment id, retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $paymentId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedPaymentChargebacksRequestFactory::new($paymentId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,201 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreatePaymentRefundRequestFactory;
use Mollie\Api\Factories\CreatePaymentRequestFactory;
use Mollie\Api\Factories\GetPaymentRequestFactory;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Factories\UpdatePaymentRequestFactory;
use Mollie\Api\Http\Requests\CancelPaymentRequest;
use Mollie\Api\Http\Requests\GetPaginatedPaymentsRequest;
use Mollie\Api\Http\Requests\ReleasePaymentAuthorizationRequest;
use Mollie\Api\Http\Response;
use Mollie\Api\Resources\AnyResource;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Utils\Utility;
class PaymentEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single payment from Mollie.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $id, array $query = [], bool $testmode = false): Payment
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaymentRequestFactory::new($id)
->withQuery($query)
->create();
return $this->send($request->test($testmode));
}
/**
* Creates a payment in Mollie.
*
* @param array $payload An array containing details on the payment.
* @param array $query An array of strings or a single string containing the details to include.
*
* @throws RequestException
*/
public function create(array $payload = [], array $query = [], bool $testmode = false): Payment
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = CreatePaymentRequestFactory::new()
->withPayload($payload)
->withQuery($query)
->create();
/** @var Payment */
return $this->send($request->test($testmode));
}
/**
* Update the given Payment.
*
* Will throw a ApiException if the payment id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function update(string $id, array $data = [], bool $testmode = false): ?Payment
{
$testmode = Utility::extractBool($data, 'testmode', $testmode);
$request = UpdatePaymentRequestFactory::new($id)
->withPayload($data)
->create();
/** @var null|Payment */
return $this->send($request->test($testmode));
}
/**
* 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.
*
* @throws RequestException
*/
public function delete(string $id, $data = []): Payment
{
return $this->cancel($id, $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 array|bool $testmode
*
* @throws RequestException
*/
public function cancel(string $id, $testmode = false): Payment
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Payment */
return $this->send((new CancelPaymentRequest($id))->test($testmode));
}
/**
* Issue a refund for the given payment.
*
* The $data parameter may either be an array of endpoint
* parameters, or an instance of CreateRefundPaymentData.
*
*
* @throws RequestException
*/
public function refund(Payment $payment, array $payload = [], bool $testmode = false): Refund
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreatePaymentRefundRequestFactory::new($payment->id)
->withPayload($payload)
->create();
return $this->send($request->test($testmode));
}
/**
* Release the authorization for the given payment.
*
* @param Payment|string $paymentId
* @return AnyResource|Response
*
* @throws RequestException
*/
public function releaseAuthorization($paymentId)
{
$paymentId = $paymentId instanceof Payment ? $paymentId->id : $paymentId;
return $this->send(new ReleasePaymentAuthorizationRequest($paymentId));
}
/**
* Get the balance endpoint.
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send((new GetPaginatedPaymentsRequest(
$query->from,
$query->limit,
$query->sort,
))->test($testmode));
}
/**
* Create an iterator for iterating over payments retrieved from Mollie.
*
* @param string $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
(new GetPaginatedPaymentsRequest(
$query->from,
$query->limit,
$query->sort,
))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreatePaymentLinkRequestFactory;
use Mollie\Api\Factories\UpdatePaymentLinkRequestFactory;
use Mollie\Api\Http\Requests\DeletePaymentLinkRequest;
use Mollie\Api\Http\Requests\GetPaginatedPaymentLinksRequest;
use Mollie\Api\Http\Requests\GetPaymentLinkRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\PaymentLink;
use Mollie\Api\Resources\PaymentLinkCollection;
use Mollie\Api\Utils\Utility;
class PaymentLinkEndpointCollection extends EndpointCollection
{
/**
* Creates a payment link in Mollie.
*
* @throws RequestException
*/
public function create(array $payload = [], bool $testmode = false): PaymentLink
{
$request = CreatePaymentLinkRequestFactory::new()
->withPayload($payload)
->create();
/** @var PaymentLink */
return $this->send($request->test($testmode));
}
/**
* Retrieve a payment link from Mollie.
*
* Will throw an ApiException if the payment link id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $paymentLinkId, $testmode = false): PaymentLink
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var PaymentLink */
return $this->send((new GetPaymentLinkRequest($paymentLinkId))->test($testmode));
}
/**
* Update a Payment Link.
*
* @throws RequestException
*/
public function update(string $paymentLinkId, array $payload = [], bool $testmode = false): PaymentLink
{
$request = UpdatePaymentLinkRequestFactory::new($paymentLinkId)
->withPayload($payload)
->create();
/** @var PaymentLink */
return $this->send($request->test($testmode));
}
/**
* Delete a Payment Link.
*
* @throws RequestException
*/
public function delete(string $paymentLinkId, bool $testmode = false): void
{
$this->send((new DeletePaymentLinkRequest($paymentLinkId))->test($testmode));
}
/**
* Retrieves a collection of Payment Links from Mollie.
*
* @param string|null $from The first payment link ID you want to include in your list.
* @param bool|array $testmode
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, $testmode = false): PaymentLinkCollection
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var PaymentLinkCollection */
return $this->send(
(new GetPaginatedPaymentLinksRequest($from, $limit))
->test($testmode)
);
}
/**
* Create an iterator for iterating over payment links retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
bool $testmode = false,
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedPaymentLinksRequest($from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Http\Requests\GetPaginatedPaymentLinkPaymentsRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\PaymentLink;
use Mollie\Api\Utils\Utility;
class PaymentLinkPaymentEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Payments from Mollie for the given Payment Link.
*
* @param string|null $from The first payment ID you want to include in your list.
*
* @throws RequestException
*/
public function pageFor(PaymentLink $paymentLink, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection
{
return $this->pageForId($paymentLink->id, $from, $limit, $filters);
}
/**
* Retrieves a collection of Payments from Mollie for the given Payment Link ID.
*
* @param string|null $from The first payment ID you want to include in your list.
*
* @throws RequestException
*/
public function pageForId(string $paymentLinkId, ?string $from = null, ?int $limit = null, array $filters = []): PaymentCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])->create();
/** @var PaymentCollection */
return $this->send(
(new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query->from, $query->limit, $query->sort))
->test($testmode)
);
}
/**
* Create an iterator for iterating over payments associated with the provided Payment Link object, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
PaymentLink $paymentLink,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId(
$paymentLink->id,
$from,
$limit,
$filters,
$iterateBackwards
);
}
/**
* Create an iterator for iterating over payments associated with the provided Payment Link id, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $paymentLinkId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])->create();
return $this->send(
(new GetPaginatedPaymentLinkPaymentsRequest($paymentLinkId, $query->from, $query->limit, $query->sort))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,169 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Factories\CreatePaymentRefundRequestFactory;
use Mollie\Api\Factories\GetPaginatedPaymentRefundsRequestFactory;
use Mollie\Api\Factories\GetPaymentRefundRequestFactory;
use Mollie\Api\Http\Requests\CancelPaymentRefundRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;
use Mollie\Api\Utils\Utility;
class PaymentRefundEndpointCollection extends EndpointCollection
{
/**
* Creates a refund for a specific payment.
*
* @param bool|array $testmode
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function createFor(Payment $payment, array $data, $testmode = false): Refund
{
return $this->createForId($payment->id, $data, $testmode);
}
/**
* Creates a refund for a specific payment.
*
* @param bool|array $testmode
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function createForId(string $paymentId, array $payload = [], $testmode = false): Refund
{
$testmode = Utility::extractBool($payload, 'testmode', false) ?:
Utility::extractBool($testmode, 'testmode', false);
$request = CreatePaymentRefundRequestFactory::new($paymentId)
->withPayload($payload)
->create();
return $this->send($request->test($testmode));
}
/**
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function getFor(Payment $payment, string $refundId, array $parameters = [], bool $testmode = false): Refund
{
return $this->getForId($payment->id, $refundId, $parameters, $testmode);
}
/**
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function getForId(string $paymentId, string $refundId, array $query = [], bool $testmode = false): Refund
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaymentRefundRequestFactory::new($paymentId, $refundId)
->withQuery($query)
->create();
/** @var Refund */
return $this->send($request->test($testmode));
}
/**
* @param array|bool $testmode
* @return null
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function cancelForPayment(Payment $payment, string $refundId, $testmode = false)
{
return $this->cancelForId($payment->id, $refundId, $testmode);
}
/**
* @param array|bool $testmode
* @return null
*
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function cancelForId(string $paymentId, string $refundId, $testmode = false)
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send((new CancelPaymentRefundRequest($paymentId, $refundId))->test($testmode));
}
/**
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function pageForId(string $paymentId, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedPaymentRefundsRequestFactory::new($paymentId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send($request->test($testmode));
}
/**
* @throws \Mollie\Api\Exceptions\RequestException
*/
public function pageFor(Payment $payment, ?string $from = null, ?int $limit = null, array $filters = []): RefundCollection
{
return $this->pageForId($payment->id, $from, $limit, $filters);
}
/**
* Create an iterator for iterating over refunds for the given payment, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Payment $payment,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($payment->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over refunds for the given payment id, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $paymentId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedPaymentRefundsRequestFactory::new($paymentId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateDelayedPaymentRouteRequestFactory;
use Mollie\Api\Factories\UpdatePaymentRouteRequestFactory;
use Mollie\Api\Http\Requests\ListPaymentRoutesRequest;
use Mollie\Api\Resources\Payment;
use Mollie\Api\Resources\Route;
use Mollie\Api\Resources\RouteCollection;
class PaymentRouteEndpointCollection extends EndpointCollection
{
/**
* Create a delayed route for a payment.
*
* @throws RequestException
*/
public function createFor(Payment $payment, array $amount, array $destination, ?string $releaseDate = null, bool $testmode = false): Route
{
return $this->createForId($payment->id, $amount, $destination, $releaseDate, $testmode);
}
/**
* Create a delayed route for a payment using payment ID.
*
* @throws RequestException
*/
public function createForId(string $paymentId, array $amount, array $destination, ?string $releaseDate = null, bool $testmode = false): Route
{
$payload = [
'amount' => $amount,
'destination' => $destination,
];
$request = CreateDelayedPaymentRouteRequestFactory::new($paymentId)
->withPayload($payload)
->create();
/** @var Route */
return $this->send($request->test($testmode));
}
/**
* List payment routes for a payment.
*
* @throws RequestException
*/
public function listFor(Payment $payment, bool $testmode = false): RouteCollection
{
return $this->listForId($payment->id, $testmode);
}
/**
* List payment routes for a payment using payment ID.
*
* @throws RequestException
*/
public function listForId(string $paymentId, bool $testmode = false): RouteCollection
{
$request = new ListPaymentRoutesRequest($paymentId);
/** @var RouteCollection */
return $this->send($request->test($testmode));
}
/**
* Update the release date for a payment route.
*
* @param string $releaseDate UTC datetime in ISO-8601 format when the funds will become available
*
* @throws RequestException
*/
public function updateReleaseDateFor(Payment $payment, string $routeId, string $releaseDate, bool $testmode = false): Route
{
return $this->updateReleaseDateForId($payment->id, $routeId, $releaseDate, $testmode);
}
/**
* Update the release date for a payment route using payment ID.
*
* @param string $releaseDate UTC datetime when the funds will become available
*
* @throws RequestException
*/
public function updateReleaseDateForId(string $paymentId, string $routeId, string $releaseDate, bool $testmode = false): Route
{
$request = UpdatePaymentRouteRequestFactory::new($paymentId, $routeId)
->withPayload([
'releaseDate' => $releaseDate,
])
->create();
/** @var Route */
return $this->send($request->test($testmode));
}
}
@@ -0,0 +1,138 @@
<?php
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreatePayoutRequestFactory;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Http\Requests\CancelPayoutRequest;
use Mollie\Api\Http\Requests\GetPaginatedPayoutsRequest;
use Mollie\Api\Http\Requests\GetPayoutRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Payout;
use Mollie\Api\Resources\PayoutCollection;
use Mollie\Api\Utils\Utility;
class PayoutEndpointCollection extends EndpointCollection
{
/**
* Creates a payout in Mollie.
*
* @param array $payload An array containing details on the payout.
* @param bool $testmode Set to true to create the payout in test mode.
*
* @throws RequestException
*/
public function create(array $payload = [], bool $testmode = false): Payout
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreatePayoutRequestFactory::new()
->withPayload($payload)
->create();
/** @var Payout */
return $this->send($request->test($testmode));
}
/**
* Retrieve a payout from Mollie.
*
* Will throw an ApiException if the payout id is invalid or the resource cannot be found.
*
* @param string $id The payout ID.
* @param bool $testmode Set to true to retrieve the payout in test mode.
*
* @throws RequestException
*/
public function get(string $id, bool $testmode = false): Payout
{
/** @var Payout */
return $this->send((new GetPayoutRequest($id))->test($testmode));
}
/**
* Cancel the given payout.
*
* Will throw an ApiException if the payout id is invalid, the resource cannot be found, or the payout can no longer be canceled.
*
* @param string $id The payout ID.
* @param bool $testmode Set to true to cancel the payout in test mode.
*
* @throws RequestException
*/
public function cancel(string $id, bool $testmode = false): Payout
{
/** @var Payout */
return $this->send((new CancelPayoutRequest($id))->test($testmode));
}
/**
* Retrieves a collection of payouts from Mollie.
*
* @param string|null $from The first payout ID you want to include in your list.
* @param int|null $limit The maximum number of payouts to return.
* @param array $filters An array of filters, such as "balanceId", "sort", and "testmode".
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): PayoutCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
$request = new GetPaginatedPayoutsRequest(
$query->from,
$query->limit,
$query->sort,
$filters['balanceId'] ?? null
);
/** @var PayoutCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over payouts retrieved from Mollie.
*
* @param string|null $from The first payout ID you want to include in your list.
* @param int|null $limit The maximum number of payouts to return per page.
* @param array $filters An array of filters, such as "balanceId", "sort", and "testmode".
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*
* @throws RequestException
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
$request = new GetPaginatedPayoutsRequest(
$query->from,
$query->limit,
$query->sort,
$filters['balanceId'] ?? null
);
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetPermissionRequest;
use Mollie\Api\Http\Requests\ListPermissionsRequest;
use Mollie\Api\Resources\Permission;
use Mollie\Api\Resources\PermissionCollection;
use Mollie\Api\Utils\Utility;
class PermissionEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single Permission from Mollie.
*
* Will throw an ApiException if the permission id is invalid.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $permissionId, $testmode = false): Permission
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Permission */
return $this->send((new GetPermissionRequest($permissionId))->test($testmode));
}
/**
* Retrieve all permissions from Mollie.
*
* @throws RequestException
*/
public function list(): PermissionCollection
{
/** @var PermissionCollection */
return $this->send(new ListPermissionsRequest);
}
}
@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateProfileRequestFactory;
use Mollie\Api\Factories\UpdateProfileRequestFactory;
use Mollie\Api\Http\Requests\DeleteProfileRequest;
use Mollie\Api\Http\Requests\GetCurrentProfileRequest;
use Mollie\Api\Http\Requests\GetPaginatedProfilesRequest;
use Mollie\Api\Http\Requests\GetProfileRequest;
use Mollie\Api\Resources\CurrentProfile;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Profile;
use Mollie\Api\Resources\ProfileCollection;
use Mollie\Api\Utils\Utility;
class ProfileEndpointCollection extends EndpointCollection
{
/**
* Creates a Profile in Mollie.
*
* @throws RequestException
*/
public function create(array $payload = []): Profile
{
$request = CreateProfileRequestFactory::new()
->withPayload($payload)
->create();
/** @var Profile */
return $this->send($request);
}
/**
* Retrieve a Profile from Mollie.
*
* Will throw an ApiException if the profile id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
* @return Profile|CurrentProfile
*
* @throws RequestException
*/
public function get(string $profileId, $testmode = false): Profile
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var Profile */
return $this->send((new GetProfileRequest($profileId))->test($testmode));
}
/**
* Retrieve the current Profile from Mollie.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function getCurrent($testmode = false): CurrentProfile
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var CurrentProfile */
return $this->send((new GetCurrentProfileRequest)->test($testmode));
}
/**
* Update a specific Profile resource.
*
* @throws RequestException
*/
public function update(string $profileId, array $payload = []): ?Profile
{
$request = UpdateProfileRequestFactory::new($profileId)
->withPayload($payload)
->create();
/** @var Profile|null */
return $this->send($request);
}
/**
* 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.
*
* @throws RequestException
*/
public function delete(string $profileId): void
{
$this->send(new DeleteProfileRequest($profileId));
}
/**
* Retrieves a collection of Profiles from Mollie.
*
* @param string|null $from The first profile ID you want to include in your list.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null): ProfileCollection
{
/** @var ProfileCollection */
return $this->send(new GetPaginatedProfilesRequest($from, $limit));
}
/**
* Create an iterator for iterating over profiles retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
bool $iterateBackwards = false
): LazyCollection {
return $this->send(
(new GetPaginatedProfilesRequest($from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,155 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\DisableMethodRequest;
use Mollie\Api\Http\Requests\EnableMethodRequest;
use Mollie\Api\Resources\Method;
use Mollie\Api\Resources\Profile;
class ProfileMethodEndpointCollection extends EndpointCollection
{
/**
* Enable a method for the provided Profile ID.
* Alias of enableForId for backwards compatibility.
*
* @throws RequestException
*/
public function createForId(string $profileId, string $id): Method
{
return $this->enableForId($profileId, $id);
}
/**
* Enable a method for the provided Profile object.
* Alias of enableFor for backwards compatibility.
*
* @throws RequestException
*/
public function createFor(Profile $profile, string $id): Method
{
return $this->enableFor($profile, $id);
}
/**
* Enable a method for the current profile.
* Alias of enable for backwards compatibility.
*
* @throws RequestException
*/
public function createForCurrentProfile(string $id): Method
{
return $this->enable($id);
}
/**
* Enable a payment method for a specific profile.
*
* @param string $profileId The profile's ID or 'me' for the current profile
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function enableForId(string $profileId, string $id): Method
{
/** @var Method */
return $this->send(new EnableMethodRequest($profileId, $id));
}
/**
* Enable a payment method for the provided Profile object.
*
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function enableFor(Profile $profile, string $id): Method
{
return $this->enableForId($profile->id, $id);
}
/**
* Enable a payment method for the current profile.
*
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function enable(string $id): Method
{
return $this->enableForId('me', $id);
}
/**
* Disable a method for the provided Profile ID.
* Alias of disableForId for backwards compatibility.
*
* @throws RequestException
*/
public function deleteForId(string $profileId, string $id): void
{
$this->disableForId($profileId, $id);
}
/**
* Disable a method for the provided Profile object.
* Alias of disableFor for backwards compatibility.
*
* @throws RequestException
*/
public function deleteFor(Profile $profile, string $id): void
{
$this->disableFor($profile, $id);
}
/**
* Disable a method for the current profile.
* Alias of disable for backwards compatibility.
*
* @throws RequestException
*/
public function deleteForCurrentProfile(string $id): void
{
$this->disable($id);
}
/**
* Disable a payment method for a specific profile.
*
* @param string $profileId The profile's ID or 'me' for the current profile
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function disableForId(string $profileId, string $id): void
{
$this->send(new DisableMethodRequest($profileId, $id));
}
/**
* Disable a payment method for the provided Profile object.
*
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function disableFor(Profile $profile, string $id): void
{
$this->disableForId($profile->id, $id);
}
/**
* Disable a payment method for the current profile.
*
* @param string $id The payment method ID
*
* @throws RequestException
*/
public function disable(string $id): void
{
$this->disableForId('me', $id);
}
}
@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedRefundsRequestFactory;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\RefundCollection;
use Mollie\Api\Utils\Utility;
class RefundEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Refunds from Mollie.
*
* @param string|null $from The first refund ID you want to include in your list.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): RefundCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedRefundsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
/** @var RefundCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over refunds retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedRefundsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateSalesInvoiceRequestFactory;
use Mollie\Api\Factories\UpdateSalesInvoiceRequestFactory;
use Mollie\Api\Http\Requests\DeleteSalesInvoiceRequest;
use Mollie\Api\Http\Requests\GetPaginatedSalesInvoicesRequest;
use Mollie\Api\Http\Requests\GetSalesInvoiceRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\SalesInvoice;
use Mollie\Api\Resources\SalesInvoiceCollection;
class SalesInvoiceEndpointCollection extends EndpointCollection
{
/**
* Retrieve a SalesInvoice from Mollie.
*
* @throws RequestException
*/
public function get(string $id): SalesInvoice
{
return $this->send(new GetSalesInvoiceRequest($id));
}
/**
* Creates a SalesInvoice in Mollie.
*
* @throws RequestException
*/
public function create(array $payload = []): SalesInvoice
{
$request = CreateSalesInvoiceRequestFactory::new()
->withPayload($payload)
->create();
return $this->send($request);
}
/**
* Update a specific SalesInvoice resource.
*
* @throws RequestException
*/
public function update(string $id, array $payload = []): ?SalesInvoice
{
$request = UpdateSalesInvoiceRequestFactory::new($id)
->withPayload($payload)
->create();
return $this->send($request);
}
/**
* Delete a SalesInvoice from Mollie.
*
* @throws RequestException
*/
public function delete(string $id): void
{
$this->send(new DeleteSalesInvoiceRequest($id));
}
/**
* Retrieves a collection of SalesInvoices from Mollie.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null): SalesInvoiceCollection
{
return $this->send(new GetPaginatedSalesInvoicesRequest($from, $limit));
}
/**
* Create an iterator for iterating over sales invoices retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
bool $iterateBackwards = false
): LazyCollection {
return $this->send(
(new GetPaginatedSalesInvoicesRequest($from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateSessionRequestFactory;
use Mollie\Api\Http\Requests\GetSessionRequest;
use Mollie\Api\Resources\Session;
class SessionEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single session from Mollie.
*
* @throws RequestException
*/
public function get(string $sessionId): Session
{
/** @var Session */
return $this->send(new GetSessionRequest($sessionId));
}
/**
* Creates a session in Mollie.
*
* @throws RequestException
*/
public function create(array $payload = []): Session
{
$request = CreateSessionRequestFactory::new()
->withPayload($payload)
->create();
/** @var Session */
return $this->send($request);
}
}
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedSettlementCapturesRequestFactory;
use Mollie\Api\Resources\CaptureCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Utils\Utility;
class SettlementCaptureEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Settlement Captures from Mollie.
*
* @throws RequestException
*/
public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): CaptureCollection
{
return $this->pageForId($settlement->id, $query, $testmode);
}
/**
* Retrieves a collection of Settlement Captures from Mollie.
*
* @throws RequestException
*/
public function pageForId(string $settlementId, array $query = [], bool $testmode = false): CaptureCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaginatedSettlementCapturesRequestFactory::new($settlementId)
->withQuery($query)
->create();
/** @var CaptureCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over captures for the given settlement, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Settlement $settlement,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over captures for the given settlement id, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $settlementId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedSettlementCapturesRequestFactory::new($settlementId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedSettlementChargebacksRequestFactory;
use Mollie\Api\Resources\ChargebackCollection;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Utils\Utility;
class SettlementChargebackEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Settlement Chargebacks from Mollie.
*
* @throws RequestException
*/
public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): ChargebackCollection
{
return $this->pageForId($settlement->id, $query, $testmode);
}
/**
* Retrieves a collection of Settlement Chargebacks from Mollie.
*
* @throws RequestException
*/
public function pageForId(string $settlementId, array $query = [], bool $testmode = false): ChargebackCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaginatedSettlementChargebacksRequestFactory::new($settlementId)
->withQuery($query)
->create();
/** @var ChargebackCollection */
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over chargebacks for the given settlement, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(
Settlement $settlement,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over chargebacks for the given settlement id, retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorForId(
string $settlementId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedSettlementChargebacksRequestFactory::new($settlementId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedSettlementsRequestFactory;
use Mollie\Api\Http\Requests\GetSettlementRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Resources\SettlementCollection;
class SettlementEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single settlement from Mollie.
*
* Will throw a ApiException if the settlement id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $settlementId): Settlement
{
return $this->send(new GetSettlementRequest($settlementId));
}
/**
* Retrieve the details of the current settlement that has not yet been paid out.
*
* @throws RequestException
*/
public function next(): Settlement
{
return $this->send(new GetSettlementRequest('next'));
}
/**
* Retrieve the details of the open balance of the organization.
*
* @throws RequestException
*/
public function open(): Settlement
{
return $this->send(new GetSettlementRequest('open'));
}
/**
* Retrieves a collection of Settlements from Mollie.
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection
{
$request = GetPaginatedSettlementsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send($request);
}
/**
* Create an iterator for iterating over settlements retrieved from Mollie.
*/
public function iterator(?string $from = null, ?int $limit = null, array $filters = [], bool $iterateBackwards = false): LazyCollection
{
$request = GetPaginatedSettlementsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\SortablePaginatedQueryFactory;
use Mollie\Api\Http\Requests\GetPaginatedSettlementPaymentsRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Utils\Utility;
class SettlementPaymentEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Settlement Payments from Mollie.
*
* @throws RequestException
*/
public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): PaymentCollection
{
return $this->pageForId($settlement->id, $query, $testmode);
}
/**
* Retrieves a collection of Settlement Payments from Mollie.
*
* @throws RequestException
*/
public function pageForId(string $settlementId, array $query = [], bool $testmode = false): PaymentCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$query = SortablePaginatedQueryFactory::new($query)->create();
return $this->send(
(new GetPaginatedSettlementPaymentsRequest(
$settlementId,
$query->from,
$query->limit,
$query->sort
))
->test($testmode)
);
}
/**
* Create an iterator for iterating over payments for the given settlement, retrieved from Mollie.
*/
public function iteratorFor(
Settlement $settlement,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards);
}
public function iteratorForId(
string $settlementId,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($parameters, 'testmode', false);
$query = SortablePaginatedQueryFactory::new([
'from' => $from,
'limit' => $limit,
'filters' => $parameters,
])->create();
return $this->send(
(new GetPaginatedSettlementPaymentsRequest(
$settlementId,
$query->from,
$query->limit,
$query->sort
))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\GetPaginatedSettlementRefundsQueryFactory;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\RefundCollection;
use Mollie\Api\Resources\Settlement;
use Mollie\Api\Utils\Utility;
class SettlementRefundEndpointCollection extends EndpointCollection
{
/**
* Retrieves a collection of Settlement Refunds from Mollie.
*
* @throws RequestException
*/
public function pageFor(Settlement $settlement, array $query = [], bool $testmode = false): RefundCollection
{
return $this->pageForId($settlement->id, $query, $testmode);
}
/**
* Retrieves a collection of Settlement Refunds from Mollie.
*
* @throws RequestException
*/
public function pageForId(string $settlementId, array $query = [], bool $testmode = false): RefundCollection
{
$testmode = Utility::extractBool($query, 'testmode', $testmode);
$request = GetPaginatedSettlementRefundsQueryFactory::new($settlementId)
->withQuery($query)
->create();
return $this->send($request->test($testmode));
}
/**
* Create an iterator for iterating over refunds for the given settlement, retrieved from Mollie.
*/
public function iteratorFor(
Settlement $settlement,
?string $from = null,
?int $limit = null,
array $parameters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($settlement->id, $from, $limit, $parameters, $iterateBackwards);
}
/**
* Create an iterator for iterating over refunds for the given settlement id, retrieved from Mollie.
*/
public function iteratorForId(
string $settlementId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetPaginatedSettlementRefundsQueryFactory::new($settlementId)
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,211 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateSubscriptionRequestFactory;
use Mollie\Api\Factories\GetAllPaginatedSubscriptionsRequestFactory;
use Mollie\Api\Factories\UpdateSubscriptionRequestFactory;
use Mollie\Api\Http\Requests\CancelSubscriptionRequest;
use Mollie\Api\Http\Requests\GetPaginatedSubscriptionsRequest;
use Mollie\Api\Http\Requests\GetSubscriptionRequest;
use Mollie\Api\Resources\Customer;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Subscription;
use Mollie\Api\Resources\SubscriptionCollection;
use Mollie\Api\Utils\Utility;
class SubscriptionEndpointCollection extends EndpointCollection
{
/**
* Retrieve a single subscription from Mollie.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function getFor(Customer $customer, string $subscriptionId, $testmode = false): Subscription
{
return $this->getForId($customer->id, $subscriptionId, $testmode);
}
/**
* Retrieve a single subscription from Mollie.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function getForId(string $customerId, string $subscriptionId, $testmode = false): Subscription
{
$testmode = Utility::extractBool($testmode, 'testmode');
return $this->send((new GetSubscriptionRequest($customerId, $subscriptionId))->test($testmode));
}
/**
* Creates a subscription for a Customer in Mollie.
*
* @throws RequestException
*/
public function createFor(Customer $customer, array $payload = [], bool $testmode = false): Subscription
{
return $this->createForId($customer->id, $payload, $testmode);
}
/**
* Creates a subscription for a Customer in Mollie.
*
* @throws RequestException
*/
public function createForId(string $customerId, array $payload = [], bool $testmode = false): Subscription
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = CreateSubscriptionRequestFactory::new($customerId)
->withPayload($payload)
->create();
return $this->send($request->test($testmode));
}
/**
* Update the given Subscription.
*
* @throws RequestException
*/
public function update(string $customerId, string $subscriptionId, array $payload = [], bool $testmode = false): ?Subscription
{
$testmode = Utility::extractBool($payload, 'testmode', $testmode);
$request = UpdateSubscriptionRequestFactory::new($customerId, $subscriptionId)
->withPayload($payload)
->create();
return $this->send($request->test($testmode));
}
/**
* Cancel the given Subscription.
*
* @throws RequestException
*/
public function cancelFor(Customer $customer, string $subscriptionId, bool $testmode = false): Subscription
{
return $this->cancelForId($customer->id, $subscriptionId, $testmode);
}
/**
* Cancel the given Subscription.
*
* @throws RequestException
*/
public function cancelForId(string $customerId, string $subscriptionId, bool $testmode = false): Subscription
{
return $this->send((new CancelSubscriptionRequest($customerId, $subscriptionId))->test($testmode));
}
/**
* Retrieve a page of subscriptions from Mollie.
*
* @throws RequestException
*/
public function pageFor(Customer $customer, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection
{
return $this->pageForId($customer->id, $from, $limit, $filters);
}
/**
* Retrieve a page of subscriptions from Mollie.
*
* @throws RequestException
*/
public function pageForId(string $customerId, ?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection
{
$testmode = Utility::extractBool($filters, 'testmode', false);
return $this->send((new GetPaginatedSubscriptionsRequest($customerId, $from, $limit))->test($testmode));
}
/**
* Create an iterator for iterating over subscriptions for the given customer, retrieved from Mollie.
*/
public function iteratorFor(
Customer $customer,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForId($customer->id, $from, $limit, $filters, $iterateBackwards);
}
/**
* Create an iterator for iterating over subscriptions for the given customer id, retrieved from Mollie.
*/
public function iteratorForId(
string $customerId,
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
return $this->send(
(new GetPaginatedSubscriptionsRequest($customerId, $from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
public function allFor(?string $from = null, ?int $limit = null, array $filters = []): SubscriptionCollection
{
return $this->allForId($from, $limit, $filters);
}
public function allForId(
?string $from = null,
?int $limit = null,
array $filters = []
): SubscriptionCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetAllPaginatedSubscriptionsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send($request->test($testmode));
}
public function iteratorForAll(
?string $from = null,
?int $limit = null,
array $filters = [],
bool $iterateBackwards = true
): LazyCollection {
$testmode = Utility::extractBool($filters, 'testmode', false);
$request = GetAllPaginatedSubscriptionsRequestFactory::new()
->withQuery([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])
->create();
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetPaginatedSubscriptionPaymentsRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\PaymentCollection;
use Mollie\Api\Resources\Subscription;
use Mollie\Api\Utils\Utility;
class SubscriptionPaymentEndpointCollection extends EndpointCollection
{
/**
* Retrieves a paginated collection of Subscription Payments from Mollie.
*
* @param string|null $from The first payment ID you want to include in your list.
* @param int|null $limit The maximum amount of results you want to retrieve per page.
* @param bool|array $testmode
*
* @throws RequestException
*/
public function pageFor(Subscription $subscription, ?string $from = null, ?int $limit = null, $testmode = false): PaymentCollection
{
return $this->pageForIds($subscription->customerId, $subscription->id, $from, $limit, $testmode);
}
/**
* Retrieves a paginated collection of Subscription Payments from Mollie.
*
* @param string|null $from The first payment ID you want to include in your list.
* @param int|null $limit The maximum amount of results you want to retrieve per page.
* @param bool|array $testmode
*
* @throws RequestException
*/
public function pageForIds(
string $customerId,
string $subscriptionId,
?string $from = null,
?int $limit = null,
$testmode = false
): PaymentCollection {
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $from, $limit))
->test($testmode)
);
}
/**
* Create an iterator for iterating over payments for the given subscription, retrieved from Mollie.
*
* @param bool|array $testmode
*/
public function iteratorFor(
Subscription $subscription,
?string $from = null,
?int $limit = null,
$testmode = false,
bool $iterateBackwards = false
): LazyCollection {
return $this->iteratorForIds($subscription->customerId, $subscription->id, $from, $limit, $testmode, $iterateBackwards);
}
/**
* Create an iterator for iterating over payments for the given subscription ID, retrieved from Mollie.
*
* @param bool|array $testmode
*/
public function iteratorForIds(
string $customerId,
string $subscriptionId,
?string $from = null,
?int $limit = null,
$testmode = false,
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedSubscriptionPaymentsRequest($customerId, $subscriptionId, $from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetPaginatedTerminalsRequest;
use Mollie\Api\Http\Requests\GetTerminalRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Terminal;
use Mollie\Api\Resources\TerminalCollection;
use Mollie\Api\Utils\Utility;
class TerminalEndpointCollection extends EndpointCollection
{
/**
* Retrieve terminal from Mollie.
*
* Will throw a ApiException if the terminal id is invalid or the resource cannot be found.
*
* @param bool|array $testmode
*
* @throws RequestException
*/
public function get(string $id, $testmode = false): Terminal
{
$testmode = Utility::extractBool($testmode, 'testmode');
/** @var Terminal */
return $this->send((new GetTerminalRequest($id))->test($testmode));
}
/**
* Retrieves a collection of Terminals from Mollie for the current organization / profile, ordered from newest to oldest.
*
* @param string|null $from The first terminal ID you want to include in your list.
* @param bool|array $testmode
*
* @throws RequestException
*/
public function page(?string $from = null, ?int $limit = null, $testmode = false): TerminalCollection
{
$testmode = Utility::extractBool($testmode, 'testmode', false);
/** @var TerminalCollection */
return $this->send((new GetPaginatedTerminalsRequest($from, $limit))->test($testmode));
}
/**
* Create an iterator for iterating over terminals retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
* @param bool|array $testmode
*/
public function iterator(
?string $from = null,
?int $limit = null,
$testmode = false,
bool $iterateBackwards = false
): LazyCollection {
$testmode = Utility::extractBool($testmode, 'testmode', false);
return $this->send(
(new GetPaginatedTerminalsRequest($from, $limit))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
@@ -0,0 +1,91 @@
<?php
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetPaginatedTerminalPairingCodesRequest;
use Mollie\Api\Http\Requests\GetTerminalPairingCodeRequest;
use Mollie\Api\Http\Requests\RequestTerminalPairingCodeRequest;
use Mollie\Api\Http\Requests\RevokeTerminalPairingCodeRequest;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\TerminalPairingCode;
use Mollie\Api\Resources\TerminalPairingCodeCollection;
class TerminalPairingCodeEndpointCollection extends EndpointCollection
{
/**
* Request a new pairing code to onboard a point-of-sale terminal.
*
* @throws RequestException
*/
public function request(string $profileId, bool $includeQrCode = false): TerminalPairingCode
{
/** @var TerminalPairingCode */
return $this->send(new RequestTerminalPairingCodeRequest($profileId, $includeQrCode));
}
/**
* Retrieve a terminal pairing code from Mollie.
*
* Will throw an ApiException if the pairing code ID is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $id, bool $includeQrCode = false): TerminalPairingCode
{
/** @var TerminalPairingCode */
return $this->send(new GetTerminalPairingCodeRequest($id, $includeQrCode));
}
/**
* Retrieve a collection of terminal pairing codes from Mollie, ordered from newest to oldest.
*
* @param string|null $from The first pairing code ID you want to include in your list.
*
* @throws RequestException
*/
public function page(
?string $from = null,
?int $limit = null,
?string $sort = null,
?string $profileId = null
): TerminalPairingCodeCollection {
/** @var TerminalPairingCodeCollection */
return $this->send(new GetPaginatedTerminalPairingCodesRequest($from, $limit, $sort, $profileId));
}
/**
* Revoke a terminal pairing code, preventing onboarding of new terminals.
*
* Terminals that have already paired with this code are not affected.
*
* Will throw an ApiException if the pairing code ID is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function revoke(string $id): TerminalPairingCode
{
/** @var TerminalPairingCode */
return $this->send(new RevokeTerminalPairingCodeRequest($id));
}
/**
* Create an iterator for iterating over terminal pairing codes retrieved from Mollie.
*
* @param string|null $from The first resource ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
?string $sort = null,
?string $profileId = null,
bool $iterateBackwards = false
): LazyCollection {
return $this->send(
(new GetPaginatedTerminalPairingCodesRequest($from, $limit, $sort, $profileId))
->useIterator()
->setIterationDirection($iterateBackwards)
);
}
}
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\ApplePayPaymentSessionRequestFactory;
use Mollie\Api\Resources\AnyResource;
class WalletEndpointCollection extends EndpointCollection
{
/**
* Obtain a new ApplePay payment session.
*
* @param array $parameters Additional parameters
* @return AnyResource The payment session data
*
* @throws RequestException
*/
public function requestApplePayPaymentSession(string $domain, string $validationUrl, array $parameters = []): AnyResource
{
$request = ApplePayPaymentSessionRequestFactory::new()
->withPayload(array_merge([
'domain' => $domain,
'validationUrl' => $validationUrl,
], $parameters))
->create();
return $this->send($request);
}
}
@@ -0,0 +1,137 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Factories\CreateWebhookRequestFactory;
use Mollie\Api\Factories\UpdateWebhookRequestFactory;
use Mollie\Api\Http\Requests\DeleteWebhookRequest;
use Mollie\Api\Http\Requests\GetPaginatedWebhooksRequest;
use Mollie\Api\Http\Requests\GetWebhookRequest;
use Mollie\Api\Http\Requests\TestWebhookRequest;
use Mollie\Api\Resources\AnyResource;
use Mollie\Api\Resources\LazyCollection;
use Mollie\Api\Resources\Webhook;
use Mollie\Api\Resources\WebhookCollection;
class WebhookEndpointCollection extends EndpointCollection
{
/**
* Creates a webhook in Mollie.
*
* @param array $payload An array containing details on the webhook.
*
* @throws RequestException
*/
public function create(array $payload = [], bool $test = false): Webhook
{
$request = CreateWebhookRequestFactory::new()
->withPayload($payload)
->create();
/** @var Webhook */
return $this->send($request->test($test));
}
/**
* Retrieve a webhook from Mollie.
*
* Will throw an ApiException if the webhook id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $id, bool $test = false): Webhook
{
/** @var Webhook */
return $this->send((new GetWebhookRequest($id))->test($test));
}
/**
* Update a webhook.
*
* @throws RequestException
*/
public function update(string $id, array $payload = [], bool $test = false): Webhook
{
$request = UpdateWebhookRequestFactory::new($id)
->withPayload($payload)
->create();
/** @var Webhook */
return $this->send($request->test($test));
}
/**
* Delete a webhook from Mollie.
*
* @throws RequestException
*/
public function delete(string $id, bool $test = false): void
{
$this->send((new DeleteWebhookRequest($id))->test($test));
}
/**
* Test a webhook by sending a test event.
*
* @throws RequestException
*/
public function test(string $id, bool $test = false): AnyResource
{
/** @var AnyResource */
return $this->send((new TestWebhookRequest($id))->test($test));
}
/**
* Retrieves a collection of webhooks from Mollie.
*
* @throws RequestException
*/
public function page(
?string $from = null,
?int $limit = null,
?string $sort = null,
?string $eventTypes = null
): WebhookCollection {
$request = new GetPaginatedWebhooksRequest(
$from,
$limit,
$sort,
$eventTypes
);
/** @var WebhookCollection */
return $this->send($request);
}
/**
* Create an iterator for iterating over webhooks retrieved from Mollie.
*
* @param string|null $from The first webhook ID you want to include in your list.
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iterator(
?string $from = null,
?int $limit = null,
?string $sort = null,
?string $eventTypes = null,
bool $iterateBackwards = false,
bool $test = false
): LazyCollection {
$request = new GetPaginatedWebhooksRequest(
$from,
$limit,
$sort,
$eventTypes
);
return $this->send(
$request
->useIterator()
->setIterationDirection($iterateBackwards)
->test($test)
);
}
}
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\EndpointCollection;
use Mollie\Api\Exceptions\RequestException;
use Mollie\Api\Http\Requests\GetWebhookEventRequest;
use Mollie\Api\Resources\WebhookEvent;
class WebhookEventEndpointCollection extends EndpointCollection
{
/**
* Retrieve a webhook event from Mollie.
*
* Will throw an ApiException if the webhook event id is invalid or the resource cannot be found.
*
* @throws RequestException
*/
public function get(string $id): WebhookEvent
{
/** @var WebhookEvent */
return $this->send(new GetWebhookEventRequest($id));
}
}
@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use DateTimeImmutable;
use Mollie\Api\Http\Response;
use Throwable;
/**
* Exception thrown when Mollie's API returns an error response.
* This exception always has both a request and a response, where the response
* contains error details from Mollie's API.
*/
class ApiException extends RequestException
{
public readonly string $plainMessage;
public readonly DateTimeImmutable $raisedAt;
/** @var array<string, \stdClass> */
public readonly array $links;
/**
* @param Response $response The response that caused this exception
* @param string $message The error message
* @param int $code The error code
* @param Throwable|null $previous Previous exception if any
*
* @throws ApiException
*/
public function __construct(
Response $response,
string $message,
int $code,
?Throwable $previous = null
) {
$this->plainMessage = $message;
$this->raisedAt = new DateTimeImmutable;
$formattedRaisedAt = $this->raisedAt->format(DateTimeImmutable::ATOM);
$message = "[{$formattedRaisedAt}] ".$message;
$links = [];
$object = $response->json();
if (isset($object->_links)) {
foreach ($object->_links as $key => $value) {
$links[$key] = $value;
}
}
$this->links = $links;
if ($this->hasLink('documentation')) {
$message .= ". Documentation: {$this->getDocumentationUrl()}";
}
parent::__construct($response, $message, $code, $previous);
}
public static function fromResponse(Response $response): self
{
$body = $response->json();
$status = $response->status();
return new self(
$response,
sprintf(
'Error executing API call (%d: %s): %s',
$status,
$body->title ?? 'Unknown',
$body->detail ?? 'Unknown'
),
$status,
null
);
}
public function getDocumentationUrl(): ?string
{
return $this->getUrl('documentation');
}
public function getDashboardUrl(): ?string
{
return $this->getUrl('dashboard');
}
public function hasLink(string $key): bool
{
return array_key_exists($key, $this->links);
}
public function getLink(string $key): \stdClass
{
if ($this->hasLink($key)) {
return $this->links[$key];
}
throw new \RuntimeException("Link '{$key}' not found");
}
public function getUrl(string $key): ?string
{
if (! $this->hasLink($key)) {
return null;
}
$link = $this->getLink($key);
return $link->href;
}
/**
* Get the ISO8601 representation of the moment this exception was thrown
*/
public function getRaisedAt(): DateTimeImmutable
{
return $this->raisedAt;
}
/**
* Retrieve the plain exception message without timestamp and metadata.
*/
public function getPlainMessage(): string
{
return $this->plainMessage;
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class ClientException extends RequestException
{
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class EmbeddedResourcesNotParseableException extends MollieException
{
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
class ForbiddenException extends ApiException
{
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response,
'Your request was understood but not allowed. '.
sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_FORBIDDEN, $body->title, $body->detail),
ResponseStatusCode::HTTP_FORBIDDEN
);
}
}
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class IncompatiblePlatformException extends MollieException
{
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;
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class InvalidAuthenticationException extends MollieException
{
public function __construct(
public readonly string $token,
string $message = ''
) {
parent::__construct($this->resolveMessage($token, $message));
}
public function getToken(): string
{
return $this->token;
}
private function resolveMessage(string $token, string $message): string
{
if ($message === '') {
return 'Invalid authentication token.';
}
return $token === '' ? $message : str_replace($token, '[redacted]', $message);
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class InvalidSignatureException extends MollieException
{
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class JsonParseException extends MollieException
{
public function __construct(
string $message,
public readonly string $rawResponse
) {
parent::__construct($message);
}
public function getRawResponse(): string
{
return $this->rawResponse;
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class LogicException extends MollieException
{
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
class MethodNotAllowedException extends ApiException
{
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response,
'The HTTP method is not supported. '.
sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_METHOD_NOT_ALLOWED, $body->title, $body->detail),
ResponseStatusCode::HTTP_METHOD_NOT_ALLOWED
);
}
}
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class MissingAuthenticationException extends MollieException
{
public function __construct()
{
parent::__construct('You have not set an API key or OAuth access token. Please use setApiKey() to set the API key.');
}
}
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Psr\Http\Client\ClientExceptionInterface;
abstract class MollieException extends \Exception implements ClientExceptionInterface
{
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\PendingRequest;
use Mollie\Api\Http\ResponseStatusCode;
use Psr\Http\Client\NetworkExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Throwable;
/**
* Exception thrown when a request cannot be completed due to network-level errors.
* This includes connection failures, DNS issues, timeouts, etc.
*/
class NetworkRequestException extends MollieException implements NetworkExceptionInterface
{
public readonly string $plainMessage;
public function __construct(
public readonly PendingRequest $pendingRequest,
?Throwable $previous = null,
?string $message = null,
int $code = ResponseStatusCode::HTTP_GATEWAY_TIMEOUT
) {
$this->plainMessage = $message ?? 'The request failed due to network issues.';
parent::__construct($this->plainMessage, $code, $previous);
}
public function getPendingRequest(): PendingRequest
{
return $this->pendingRequest;
}
public function getPlainMessage(): string
{
return $this->plainMessage;
}
public function getRequest(): RequestInterface
{
return $this->pendingRequest->createPsrRequest();
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
class NotFoundException extends ApiException
{
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response,
'The object referenced by your API request does not exist. '.
sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_NOT_FOUND, $body->title, $body->detail),
ResponseStatusCode::HTTP_NOT_FOUND
);
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\PendingRequest;
use Mollie\Api\Http\Response;
use Psr\Http\Client\RequestExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Throwable;
class RequestException extends MollieException implements RequestExceptionInterface
{
public function __construct(
public readonly Response $response,
?string $message = null,
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message ?? '', $code, $previous);
}
public function getRequest(): RequestInterface
{
return $this->response->getPsrRequest();
}
public function getResponse(): Response
{
return $this->response;
}
public function getPendingRequest(): PendingRequest
{
return $this->response->getPendingRequest();
}
public function getStatusCode(): int
{
return $this->response->status();
}
}
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
/**
* Exception thrown when a request times out (either during connection or while waiting for response).
*/
class RequestTimeoutException extends NetworkRequestException
{
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response->getPendingRequest(),
null,
'The request took too long to complete. '.
sprintf('Error executing API call (%d: %s): %s', 408, $body->title, $body->detail)
);
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\PendingRequest;
use Mollie\Api\Http\ResponseStatusCode;
use Throwable;
/**
* Exception thrown when a request fails due to a temporary network issue that may resolve on retry.
* This includes timeouts, temporary DNS issues, connection drops, etc.
*/
class RetryableNetworkRequestException extends NetworkRequestException
{
public function __construct(
PendingRequest $pendingRequest,
?string $message = null,
?Throwable $previous = null
) {
parent::__construct(
$pendingRequest,
$previous,
$message ?? 'The request failed due to a temporary network issue. Retrying may resolve this.',
ResponseStatusCode::HTTP_SERVICE_UNAVAILABLE
);
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class ServerException extends RequestException
{
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
class ServiceUnavailableException extends ServerException
{
public static function fromResponse(Response $response): self
{
$message = 'The service is temporarily unavailable.';
$body = $response->body();
if (! $response->isEmpty()) {
$message .= sprintf(' Server response: %s', $body);
}
return new self(
$response,
$message,
ResponseStatusCode::HTTP_SERVICE_UNAVAILABLE
);
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use DateTimeImmutable;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
use Throwable;
class TooManyRequestsException extends ApiException
{
public function __construct(
Response $response,
string $message,
int $code,
public readonly ?int $retryAfterSeconds = null,
?Throwable $previous = null
) {
parent::__construct($response, $message, $code, $previous);
}
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response,
'Your request exceeded the rate limit. '.
sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_TOO_MANY_REQUESTS, $body->title, $body->detail),
ResponseStatusCode::HTTP_TOO_MANY_REQUESTS,
self::parseRetryAfter($response->header('Retry-After'))
);
}
/**
* Get the value of the Retry-After header converted to seconds from now,
* or null if the header is missing or unparseable.
*/
public function getRetryAfterSeconds(): ?int
{
return $this->retryAfterSeconds;
}
/**
* Parse a Retry-After header value.
*
* Supports:
* - Integer seconds (RFC 7231), e.g. "120"
* - HTTP-date, e.g. "Wed, 21 Oct 2015 07:28:00 GMT"
*
* Returns null when the header is absent or cannot be parsed.
*/
private static function parseRetryAfter(?string $value): ?int
{
if ($value === null) {
return null;
}
$value = trim($value);
if ($value === '') {
return null;
}
if (ctype_digit($value)) {
return (int) $value;
}
try {
$retryAt = new DateTimeImmutable($value);
} catch (\Exception $e) {
return null;
}
$seconds = $retryAt->getTimestamp() - (new DateTimeImmutable)->getTimestamp();
return max(0, $seconds);
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
class UnauthorizedException extends ApiException
{
public static function fromResponse(Response $response): self
{
$body = $response->json();
return new self(
$response,
'Your request wasn\'t executed due to failed authentication. Check your API key. '.
sprintf('Error executing API call (%d: %s): %s', ResponseStatusCode::HTTP_UNAUTHORIZED, $body->title, $body->detail),
ResponseStatusCode::HTTP_UNAUTHORIZED
);
}
}
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
class UnrecognizedClientException extends MollieException
{
}
@@ -0,0 +1,182 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Exceptions;
use Mollie\Api\Http\Response;
use Mollie\Api\Http\ResponseStatusCode;
use stdClass;
use Throwable;
class ValidationException extends ApiException
{
/**
* @param Response $response
* @param string $field
* @param string $message
* @param array<string, string> $errors Map of field name to error message.
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(
Response $response,
public readonly string $field,
string $message,
public readonly array $errors = [],
int $code = ResponseStatusCode::HTTP_UNPROCESSABLE_ENTITY,
?Throwable $previous = null
) {
parent::__construct($response, $message, $code, $previous);
}
public function getField(): string
{
return $this->field;
}
/**
* Get the full field -> message map.
*
* @return array<string, string>
*/
public function getErrors(): array
{
return $this->errors;
}
public function hasError(string $field): bool
{
return array_key_exists($field, $this->errors);
}
public function getError(string $field): ?string
{
return $this->errors[$field] ?? null;
}
public static function fromResponse(Response $response): self
{
$body = $response->json();
$field = $body->field ?? '';
$detail = $body->detail ?? '';
return new self(
$response,
$field,
'We could not process your request due to validation errors. '.
sprintf('Error executing API call (%d: %s): %s', 422, $body->title ?? 'Unknown', $detail),
self::extractErrors($body, $field, $detail),
ResponseStatusCode::HTTP_UNPROCESSABLE_ENTITY
);
}
/**
* Build a field => message map from the Mollie error body.
*
* Mollie's standard 422 body has a single top-level `field` plus `detail`.
* Some error responses additionally expose per-field errors under `details`,
* `errors`, or `extra.errors` (shape: field -> message, or a list of
* { field, message } objects). We accept all those forms.
*
* @return array<string, string>
*/
private static function extractErrors(stdClass $body, string $field, string $detail): array
{
$errors = array_merge(...array_map(
self::normalizeErrorBag(...),
self::errorBags($body)
));
if ($field !== '' && ! array_key_exists($field, $errors)) {
$errors[$field] = $detail;
}
return $errors;
}
/**
* @return array<int, mixed>
*/
private static function errorBags(stdClass $body): array
{
$bags = [];
foreach (['details', 'errors'] as $key) {
if (isset($body->{$key})) {
$bags[] = $body->{$key};
}
}
if (isset($body->extra, $body->extra->errors)) {
$bags[] = $body->extra->errors;
}
return $bags;
}
/**
* Normalize an error bag into a field => message map.
*
* Accepts:
* - stdClass { field: message }
* - array<string, string>
* - list of stdClass { field, message|detail }
*
* @param mixed $bag
* @return array<string, string>
*/
private static function normalizeErrorBag($bag): array
{
if ($bag instanceof stdClass) {
return self::normalizeErrorEntries((array) $bag);
}
return is_array($bag)
? self::normalizeErrorEntries($bag)
: [];
}
/**
* @param array<array-key, mixed> $entries
* @return array<string, string>
*/
private static function normalizeErrorEntries(array $entries): array
{
$errors = [];
foreach ($entries as $key => $value) {
$error = self::normalizeErrorEntry($key, $value);
if ($error !== null) {
[$field, $message] = $error;
$errors[$field] = $message;
}
}
return $errors;
}
/**
* @param array-key $key
* @param mixed $value
* @return array{0: string, 1: string}|null
*/
private static function normalizeErrorEntry($key, mixed $value): ?array
{
if (is_string($key) && is_string($value)) {
return [$key, $value];
}
if (! $value instanceof stdClass) {
return null;
}
$field = $value->field ?? null;
$message = $value->message ?? $value->detail ?? null;
return is_string($field) && is_string($message)
? [$field, $message]
: null;
}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Factories;
use Mollie\Api\Http\Requests\ApplePayPaymentSessionRequest;
class ApplePayPaymentSessionRequestFactory extends RequestFactory
{
public function create(): ApplePayPaymentSessionRequest
{
return new ApplePayPaymentSessionRequest(
$this->payload('domain'),
$this->payload('validationUrl'),
$this->payload('profileId'),
);
}
}
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Factories;
use Mollie\Api\Http\Data\ApplicationFee;
class ApplicationFeeFactory extends Factory
{
public function create(): ApplicationFee
{
return new ApplicationFee(
MoneyFactory::new($this->get('amount'))->create(),
$this->get('description'),
);
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Factories;
use Mollie\Api\Http\Data\Owner;
use Mollie\Api\Http\Data\OwnerAddress;
use Mollie\Api\Http\Requests\CreateClientLinkRequest;
class CreateClientLinkRequestFactory extends RequestFactory
{
public function create(): CreateClientLinkRequest
{
return new CreateClientLinkRequest(
Owner::fromArray($this->payload('owner')),
$this->payload('name'),
OwnerAddress::fromArray($this->payload('address')),
$this->payload('registrationNumber'),
$this->payload('vatNumber')
);
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Mollie\Api\Factories;
use Mollie\Api\Http\Data\TransferParty;
use Mollie\Api\Http\Requests\CreateConnectBalanceTransferRequest;
class CreateConnectBalanceTransferRequestFactory extends RequestFactory
{
public function create(): CreateConnectBalanceTransferRequest
{
return new CreateConnectBalanceTransferRequest(
$this->transformFromPayload('amount', fn ($item) => MoneyFactory::new($item)->create()),
$this->payload('description'),
$this->transformFromPayload('source', fn ($item) => TransferParty::fromArray($item)),
$this->transformFromPayload('destination', fn ($item) => TransferParty::fromArray($item)),
$this->payload('category'),
$this->payload('metadata')
);
}
}
Loaded 100 of 822 files, more files were not shown because too many files have changed in this diff. Show more