Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Nov 28, 2024
1 parent f842f91 commit be6161e
Show file tree
Hide file tree
Showing 127 changed files with 4,955 additions and 260 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/Testable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface Testable
{
public function getTestmode(): bool;
public function getTestmode(): ?bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BalanceTransactionEndpointCollection extends EndpointCollection
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageFor(Balance $balance, $query = [], ?bool $testmode = null): BalanceTransactionCollection
public function pageFor(Balance $balance, $query = [], bool $testmode = false): BalanceTransactionCollection
{
return $this->pageForId($balance->id, $query, $testmode);
}
Expand All @@ -30,7 +30,7 @@ public function pageFor(Balance $balance, $query = [], ?bool $testmode = null):
*
* @param bool $iterateBackwards Set to true for reverse order iteration (default is false).
*/
public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, ?bool $testmode = null): LazyCollection
public function iteratorFor(Balance $balance, array $parameters = [], bool $iterateBackwards = false, bool $testmode = false): LazyCollection
{
return $this->iteratorForId($balance->id, $parameters, $iterateBackwards, $testmode);
}
Expand All @@ -42,7 +42,7 @@ public function iteratorFor(Balance $balance, array $parameters = [], bool $iter
*
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForPrimary($query = [], ?bool $testmode = null): BalanceTransactionCollection
public function pageForPrimary($query = [], bool $testmode = false): BalanceTransactionCollection
{
/** @var BalanceTransactionCollection */
return $this->pageForId('primary', $query, $testmode);
Expand Down
12 changes: 10 additions & 2 deletions src/EndpointCollection/ClientEndpointCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Mollie\Api\EndpointCollection;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Factories\GetClientQueryFactory;
use Mollie\Api\Factories\GetPaginatedClientQueryFactory;
use Mollie\Api\Http\Query\GetClientQuery;
use Mollie\Api\Http\Requests\GetClientRequest;
use Mollie\Api\Http\Requests\GetPaginatedClientRequest;
use Mollie\Api\Resources\Client;
Expand All @@ -18,13 +20,19 @@ class ClientEndpointCollection extends EndpointCollection
* 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.
* @param GetClientQuery|array $query The query parameters.
*
* @throws ApiException
*/
public function get(string $id, array $embed = []): Client
public function get(string $id, $query = []): Client
{
if (!$query instanceof GetClientQuery) {
$query = GetClientQueryFactory::new($query)->create();
}

/** @var Client */
return $this->send(new GetClientRequest($id, $embed));
return $this->send(new GetClientRequest($id, $query));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/EndpointCollection/MethodEndpointCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Mollie\Api\EndpointCollection;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Factories\GetAllMethodsQueryFactory as GetAllPaymentMethodsQueryFactory;
use Mollie\Api\Factories\GetEnabledMethodsQueryFactory as GetEnabledPaymentMethodsQueryFactory;
use Mollie\Api\Factories\GetAllPaymentMethodsQueryFactory;
use Mollie\Api\Factories\GetEnabledPaymentMethodsQueryFactory;
use Mollie\Api\Factories\GetPaymentMethodQueryFactory;
use Mollie\Api\Helpers;
use Mollie\Api\Http\Query\GetAllMethodsQuery as GetAllPaymentMethodsQuery;
use Mollie\Api\Http\Query\GetEnabledMethodsQuery as GetEnabledPaymentMethodsQuery;
use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery;
use Mollie\Api\Http\Query\GetPaymentMethodQuery;
use Mollie\Api\Http\Requests\GetAllMethodsRequest as GetAllPaymentMethodsRequest;
use Mollie\Api\Http\Requests\GetEnabledMethodsRequest as GetEnabledPaymentMethodsRequest;
Expand Down
101 changes: 101 additions & 0 deletions src/EndpointCollection/SettlementEndpointCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace Mollie\Api\EndpointCollection;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\Factories\PaginatedQueryFactory;
use Mollie\Api\Helpers;
use Mollie\Api\Http\Requests\GetPaginatedSettlementRequest;
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 an ApiException if the settlement id is invalid or the resource cannot be found.
*
* @param array|bool $testmode
* @throws ApiException
*/
public function get(string $settlementId, $testmode = []): Settlement
{
$testmode = Helpers::extractBool($testmode, 'testmode', false);

/** @var Settlement */
return $this->send((new GetSettlementRequest($settlementId))->test($testmode));
}

/**
* Retrieve the next settlement from Mollie.
*
* @param array|bool $testmode
* @throws ApiException
*/
public function next($testmode = []): ?Settlement
{
return $this->get('next', $testmode);
}

/**
* Retrieve the open balance from Mollie.
*
* @param array|bool $testmode
* @throws ApiException
*/
public function open($testmode = []): ?Settlement
{
return $this->get('open', $testmode);
}

/**
* Retrieve a collection of settlements from Mollie.
*
* @param string|null $from The first settlement ID you want to include in your list.
* @throws ApiException
*/
public function page(?string $from = null, ?int $limit = null, array $filters = []): SettlementCollection
{
$testmode = Helpers::extractBool($filters, 'testmode', false);

$query = PaginatedQueryFactory::new([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])->create();

/** @var SettlementCollection */
return $this->send((new GetPaginatedSettlementRequest($query))->test($testmode));
}

/**
* Create an iterator for iterating over settlements retrieved from Mollie.
*
* @param string|null $from The first settlement 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 = Helpers::extractBool($filters, 'testmode', false);

$query = PaginatedQueryFactory::new([
'from' => $from,
'limit' => $limit,
'filters' => $filters,
])->create();

return $this->send(
(new GetPaginatedSettlementRequest($query))
->useIterator()
->setIterationDirection($iterateBackwards)
->test($testmode)
);
}
}
9 changes: 9 additions & 0 deletions src/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ protected function has($keys): bool
return Arr::has($this->data, $keys);
}

/**
* @param string|array<string> $key
* @param mixed $value
*/
protected function includes($key, $value, $backupKey = 'filters.'): bool
{
return Arr::includes($this->data, [$backupKey.$key, $key], $value);
}

/**
* Map a value to a new form if it is not null.
*
Expand Down
17 changes: 0 additions & 17 deletions src/Factories/GetAllMethodsQueryFactory.php

This file was deleted.

23 changes: 23 additions & 0 deletions src/Factories/GetAllPaymentMethodsQueryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetAllMethodsQuery;
use Mollie\Api\Types\MethodQuery;
use Mollie\Api\Types\PaymentMethod;

class GetAllPaymentMethodsQueryFactory extends Factory
{
public function create(): GetAllMethodsQuery
{
$includeIssuers = $this->includes('include', MethodQuery::INCLUDE_ISSUERS);
$includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING);

return new GetAllMethodsQuery(
$this->get('locale'),
$this->get('includeIssuers', $includeIssuers),
$this->get('includePricing', $includePricing),
$this->mapIfNotNull('amount', MoneyFactory::class)
);
}
}
2 changes: 1 addition & 1 deletion src/Factories/GetBalanceReportQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GetBalanceReportQueryFactory extends Factory
{
public function create(): GetBalanceReportQuery
{
if (! $this->has(['from', 'unitl'])) {
if (! $this->has(['from', 'until'])) {
throw new \InvalidArgumentException('The "from" and "until" fields are required.');
}

Expand Down
20 changes: 20 additions & 0 deletions src/Factories/GetClientQueryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetClientQuery;
use Mollie\Api\Types\ClientQuery;

class GetClientQueryFactory extends Factory
{
public function create(): GetClientQuery
{
$embedOrganization = $this->includes('embed', ClientQuery::EMBED_ORGANIZATION);
$embedOnboarding = $this->includes('embed', ClientQuery::EMBED_ONBOARDING);

return new GetClientQuery(
$this->get('embedOrganization', $embedOrganization),
$this->get('embedOnboarding', $embedOnboarding),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetEnabledMethodsQuery;
use Mollie\Api\Http\Query\GetEnabledPaymentMethodsQuery;
use Mollie\Api\Types\MethodQuery;

class GetEnabledMethodsQueryFactory extends Factory
class GetEnabledPaymentMethodsQueryFactory extends Factory
{
public function create(): GetEnabledMethodsQuery
public function create(): GetEnabledPaymentMethodsQuery
{
return new GetEnabledMethodsQuery(
$includeIssuers = $this->includes('include', MethodQuery::INCLUDE_ISSUERS);
$includePricing = $this->includes('include', MethodQuery::INCLUDE_PRICING);

return new GetEnabledPaymentMethodsQuery(
$this->get('sequenceType', MethodQuery::SEQUENCE_TYPE_ONEOFF),
$this->get('resource', MethodQuery::RESOURCE_PAYMENTS),
$this->get('locale'),
Expand All @@ -18,7 +21,8 @@ public function create(): GetEnabledMethodsQuery
$this->get('includeWallets'),
$this->get('orderLineCategories', []),
$this->get('profileId'),
$this->get('include', []),
$this->get('includeIssuers', $includeIssuers),
$this->get('includePricing', $includePricing),
$this->get('testmode')
);
}
Expand Down
18 changes: 7 additions & 11 deletions src/Factories/GetPaginatedClientQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetPaginatedClientQuery;

use Mollie\Api\Types\ClientQuery;
class GetPaginatedClientQueryFactory extends Factory
{
private PaginatedQueryFactory $paginatedQueryFactory;

public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->paginatedQueryFactory = new PaginatedQueryFactory($attributes);
}

public function create(): GetPaginatedClientQuery
{
$embedOrganization = $this->includes('embed', ClientQuery::EMBED_ORGANIZATION);
$embedOnboarding = $this->includes('embed', ClientQuery::EMBED_ONBOARDING);

return new GetPaginatedClientQuery(
$this->paginatedQueryFactory->create(),
$this->get('embed', [])
PaginatedQueryFactory::new($this->data)->create(),
$this->get('embedOrganization', $embedOrganization),
$this->get('embedOnboarding', $embedOnboarding),
);
}
}
5 changes: 3 additions & 2 deletions src/Factories/GetPaginatedPaymentCapturesQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetPaginatedPaymentCapturesQuery;
use Mollie\Api\Types\PaymentIncludesQuery;

class GetPaginatedPaymentCapturesQueryFactory extends Factory
{
public function create(): GetPaginatedPaymentCapturesQuery
{
$include = $this->get('filters.include', []);
$includePayments = $this->includes('include', PaymentIncludesQuery::PAYMENT);

return new GetPaginatedPaymentCapturesQuery(
PaginatedQueryFactory::new($this->data)->create(),
$this->get('include', $include)
$this->get('includePayments', $includePayments)
);
}
}
5 changes: 3 additions & 2 deletions src/Factories/GetPaginatedPaymentChargebacksQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetPaginatedPaymentChargebacksQuery;
use Mollie\Api\Types\PaymentIncludesQuery;

class GetPaginatedPaymentChargebacksQueryFactory extends Factory
{
public function create(): GetPaginatedPaymentChargebacksQuery
{
$include = $this->get('filters.include', []);
$includePayment = $this->includes('include', PaymentIncludesQuery::PAYMENT);

return new GetPaginatedPaymentChargebacksQuery(
PaginatedQueryFactory::new($this->data)->create(),
$this->get('include', $include),
$this->get('includePayment', $includePayment),
);
}
}
6 changes: 4 additions & 2 deletions src/Factories/GetPaginatedRefundsQueryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Mollie\Api\Factories;

use Mollie\Api\Http\Query\GetPaginatedRefundsQuery;

use Mollie\Api\Types\PaymentIncludesQuery;
class GetPaginatedRefundsQueryFactory extends Factory
{
public function create(): GetPaginatedRefundsQuery
{
$embedPayment = $this->includes('embed', PaymentIncludesQuery::PAYMENT);

return new GetPaginatedRefundsQuery(
PaginatedQueryFactory::new($this->data)->create(),
$this->get('embed'),
$this->get('embedPayment', $embedPayment),
$this->get('profileId')
);
}
Expand Down
Loading

0 comments on commit be6161e

Please sign in to comment.