Skip to content

Commit

Permalink
SettlementRefundEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sandervanhooft committed Oct 13, 2023
1 parent bc122ab commit 87433de
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/Endpoints/SettlementChargebackEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Mollie\Api\Endpoints;

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

Expand Down
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);
}
}
9 changes: 9 additions & 0 deletions src/MollieApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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 @@ -140,6 +141,13 @@ class MollieApiClient
*/
public $settlementPayments;

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

/**
* RESTful Subscription resource.
*
Expand Down Expand Up @@ -384,6 +392,7 @@ public function initializeEndpoints()
$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
39 changes: 20 additions & 19 deletions src/Resources/Settlement.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function isPending()
}

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

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

/**
* Retrieves the first page of 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,33 +121,34 @@ 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
Expand All @@ -165,7 +166,7 @@ public function chargebacks(int $limit = null, array $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
Expand Down

0 comments on commit 87433de

Please sign in to comment.