Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settlement dedicated subresource endpoints #699

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/Endpoints/SettlementCaptureEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Mollie\Api\Endpoints;

use Mollie\Api\Resources\Capture;
use Mollie\Api\Resources\CaptureCollection;

class SettlementCaptureEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_captures";

/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Capture($this->client);
}

protected function getResourceCollectionObject($count, $_links)
{
return new CaptureCollection($this->client, $count, $_links);
}

/**
* Retrieves a collection of Settlement Captures from Mollie.
*
* @param string $settlementId
* @param string|null $from The first capture ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;

return $this->rest_list($from, $limit, $parameters);
}
}
47 changes: 47 additions & 0 deletions src/Endpoints/SettlementChargebackEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Mollie\Api\Endpoints;

use Mollie\Api\Resources\Chargeback;
use Mollie\Api\Resources\ChargebackCollection;

class SettlementChargebackEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_chargebacks";

/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Chargeback($this->client);
}

/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new ChargebackCollection($this->client, $count, $_links);
}

/**
* Retrieves a collection of Settlement Chargebacks from Mollie.
*
* @param string $settlementId
* @param string|null $from The first chargeback ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;

return $this->rest_list($from, $limit, $parameters);
}
}
47 changes: 47 additions & 0 deletions src/Endpoints/SettlementRefundEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Mollie\Api\Endpoints;

use Mollie\Api\Resources\Refund;
use Mollie\Api\Resources\RefundCollection;

class SettlementRefundEndpoint extends CollectionEndpointAbstract
{
protected $resourcePath = "settlements_refunds";

/**
* @inheritDoc
*/
protected function getResourceCollectionObject($count, $_links)
{
return new RefundCollection($this->client, $count, $_links);
}

/**
* @inheritDoc
*/
protected function getResourceObject()
{
return new Refund($this->client);
}

/**
* Retrieves a collection of Settlement Refunds from Mollie.
*
* @param string $settlementId
* @param string|null $from The first refund ID you want to include in your list.
* @param int|null $limit
* @param array $parameters
*
* @return mixed
* @throws \Mollie\Api\Exceptions\ApiException
*/
public function pageForId(string $settlementId, string $from = null, int $limit = null, array $parameters = [])
{
$this->parentId = $settlementId;

return $this->rest_list($from, $limit, $parameters);
}
}
27 changes: 27 additions & 0 deletions src/MollieApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
use Mollie\Api\Endpoints\ProfileEndpoint;
use Mollie\Api\Endpoints\ProfileMethodEndpoint;
use Mollie\Api\Endpoints\RefundEndpoint;
use Mollie\Api\Endpoints\SettlementCaptureEndpoint;
use Mollie\Api\Endpoints\SettlementChargebackEndpoint;
use Mollie\Api\Endpoints\SettlementPaymentEndpoint;
use Mollie\Api\Endpoints\SettlementRefundEndpoint;
use Mollie\Api\Endpoints\SettlementsEndpoint;
use Mollie\Api\Endpoints\ShipmentEndpoint;
use Mollie\Api\Endpoints\SubscriptionEndpoint;
Expand Down Expand Up @@ -117,13 +120,34 @@ class MollieApiClient
*/
public $settlements;

/**
* RESTful Settlement capture resource.
*
* @var \Mollie\Api\Endpoints\SettlementCaptureEndpoint
*/
public $settlementCaptures;

/**
* RESTful Settlement chargeback resource.
*
* @var \Mollie\Api\Endpoints\SettlementChargebackEndpoint
*/
public $settlementChargebacks;

/**
* RESTful Settlement payment resource.
*
* @var \Mollie\Api\Endpoints\SettlementPaymentEndpoint
*/
public $settlementPayments;

/**
* RESTful Settlement refund resource.
*
* @var \Mollie\Api\Endpoints\SettlementRefundEndpoint
*/
public $settlementRefunds;

/**
* RESTful Subscription resource.
*
Expand Down Expand Up @@ -365,7 +389,10 @@ public function initializeEndpoints()
$this->profileMethods = new ProfileMethodEndpoint($this);
$this->customers = new CustomerEndpoint($this);
$this->settlements = new SettlementsEndpoint($this);
$this->settlementCaptures = new SettlementCaptureEndpoint($this);
$this->settlementChargebacks = new SettlementChargebackEndpoint($this);
$this->settlementPayments = new SettlementPaymentEndpoint($this);
$this->settlementRefunds = new SettlementRefundEndpoint($this);
$this->subscriptions = new SubscriptionEndpoint($this);
$this->customerPayments = new CustomerPaymentsEndpoint($this);
$this->mandates = new MandateEndpoint($this);
Expand Down
80 changes: 36 additions & 44 deletions src/Resources/Settlement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Mollie\Api\Resources;

use Mollie\Api\Exceptions\ApiException;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Types\SettlementStatus;

class Settlement extends BaseResource
Expand Down Expand Up @@ -92,7 +91,7 @@ public function isPending()
}

/**
* Is this settlement paidout?
* Is this settlement paid out?
*
* @return bool
*/
Expand All @@ -102,7 +101,7 @@ public function isPaidout()
}

/**
* Is this settlement failed?
* Has this settlement failed?
*
* @return bool
*/
Expand All @@ -112,7 +111,7 @@ public function isFailed()
}

/**
* Retrieves all payments associated with this settlement
* Retrieve the first page of payments associated with this settlement.
*
* @param int|null $limit
* @param array $parameters
Expand All @@ -121,72 +120,65 @@ public function isFailed()
*/
public function payments(int $limit = null, array $parameters = []): PaymentCollection
{
return $this->client->settlementPayments->pageForId($this->id, null, $limit, $parameters);
return $this->client->settlementPayments->pageForId(
$this->id,
null,
$limit,
$parameters
);
}

/**
* Retrieves all refunds associated with this settlement
* Retrieve the first page of refunds associated with this settlement.
*
* @param int|null $limit
* @param array $parameters
* @return RefundCollection
* @throws ApiException
*/
public function refunds()
public function refunds(int $limit = null, array $parameters = [])
{
if (! isset($this->_links->refunds->href)) {
return new RefundCollection($this->client, 0, null);
}

$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->refunds->href);

return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->refunds,
Refund::class,
$result->_links
return $this->client->settlementRefunds->pageForId(
$this->id,
null,
$limit,
$parameters
);
}

/**
* Retrieves all chargebacks associated with this settlement
* Retrieve the first page of chargebacks associated with this settlement.
*
* @param int|null $limit
* @param array $parameters
* @return ChargebackCollection
* @throws ApiException
*/
public function chargebacks()
public function chargebacks(int $limit = null, array $parameters = [])
{
if (! isset($this->_links->chargebacks->href)) {
return new ChargebackCollection($this->client, 0, null);
}

$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->chargebacks->href);

return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->chargebacks,
Chargeback::class,
$result->_links
return $this->client->settlementChargebacks->pageForId(
$this->id,
null,
$limit,
$parameters
);
}

/**
* Retrieves all captures associated with this settlement
* Retrieve the first page of cap associated with this settlement.
*
* @param int|null $limit
* @param array $parameters
* @return CaptureCollection
* @throws ApiException
*/
public function captures()
public function captures(int $limit = null, array $parameters = [])
{
if (! isset($this->_links->captures->href)) {
return new CaptureCollection($this->client, 0, null);
}

$result = $this->client->performHttpCallToFullUrl(MollieApiClient::HTTP_GET, $this->_links->captures->href);

return ResourceFactory::createCursorResourceCollection(
$this->client,
$result->_embedded->captures,
Capture::class,
$result->_links
return $this->client->settlementCaptures->pageForId(
$this->id,
null,
$limit,
$parameters
);
}
}
Loading
Loading