From be3dbe7d17bf67b3ac7a224f58dd372ca9a139a8 Mon Sep 17 00:00:00 2001 From: Krishan Koenig Date: Tue, 10 Dec 2024 14:00:14 +0100 Subject: [PATCH] wip --- src/Endpoints/SalesInvoiceEndpoint.php | 123 +++++++++++++++++ src/MollieApiClient.php | 9 ++ src/Resources/SalesInvoice.php | 167 +++++++++++++++++++++++ src/Resources/SalesInvoiceCollection.php | 22 +++ src/Types/SalesInvoiceStatus.php | 21 +++ 5 files changed, 342 insertions(+) create mode 100644 src/Endpoints/SalesInvoiceEndpoint.php create mode 100644 src/Resources/SalesInvoice.php create mode 100644 src/Resources/SalesInvoiceCollection.php create mode 100644 src/Types/SalesInvoiceStatus.php diff --git a/src/Endpoints/SalesInvoiceEndpoint.php b/src/Endpoints/SalesInvoiceEndpoint.php new file mode 100644 index 00000000..9be1aded --- /dev/null +++ b/src/Endpoints/SalesInvoiceEndpoint.php @@ -0,0 +1,123 @@ +client); + } + + /** + * Get the collection object that is used by this API endpoint. Every API endpoint uses one type of collection object. + * + * @param int $count + * @param \stdClass $_links + * + * @return SalesInvoiceCollection + */ + protected function getResourceCollectionObject($count, $_links): SalesInvoiceCollection + { + return new SalesInvoiceCollection($this->client, $count, $_links); + } + + /** + * Creates a payment in Mollie. + * + * @param array $data An array containing details on the payment. + * @param array $filters + * + * @return SalesInvoice + * @throws ApiException + */ + public function create(array $data = []): SalesInvoice + { + return $this->rest_create($data, []); + } + + /** + * Update the given Payment. + * + * Will throw a ApiException if the payment id is invalid or the resource cannot be found. + * + * @param string $salesInvoiceId + * + * @param array $data + * @return SalesInvoice + * @throws ApiException + */ + public function update($salesInvoiceId, array $data = []): SalesInvoice + { + if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) { + throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + } + + return parent::rest_update($salesInvoiceId, $data); + } + + /** + * @param string $salesInvoiceId + * @param array $parameters + * @return SalesInvoice + * @throws ApiException + */ + public function get($salesInvoiceId, array $parameters = []): SalesInvoice + { + if (empty($salesInvoiceId) || strpos($salesInvoiceId, self::RESOURCE_ID_PREFIX) !== 0) { + throw new ApiException("Invalid sales invoice ID: '{$salesInvoiceId}'. A sales invoice ID should start with '" . self::RESOURCE_ID_PREFIX . "'."); + } + + return parent::rest_read($salesInvoiceId, $parameters); + } + + /** + * @param string $salesInvoiceId + * + * @param array $data + * @throws ApiException + */ + public function delete($salesInvoiceId, array $data = []): void + { + $this->rest_delete($salesInvoiceId, $data); + } + + /** + * @param string $from The first payment ID you want to include in your list. + * @param int $limit + * + * @return SalesInvoiceCollection + * @throws ApiException + */ + public function page($from = null, $limit = null) + { + return $this->rest_list($from, $limit, []); + } + + /** + * @param string $from The first resource ID you want to include in your list. + * @param int $limit + * @param bool $iterateBackwards Set to true for reverse order iteration (default is false). + * + * @return LazyCollection + */ + public function iterator(?string $from = null, ?int $limit = null, bool $iterateBackwards = false): LazyCollection + { + return $this->rest_iterator($from, $limit, [], $iterateBackwards); + } +} diff --git a/src/MollieApiClient.php b/src/MollieApiClient.php index 6ae63f25..04b02d74 100644 --- a/src/MollieApiClient.php +++ b/src/MollieApiClient.php @@ -32,6 +32,7 @@ use Mollie\Api\Endpoints\ProfileEndpoint; use Mollie\Api\Endpoints\ProfileMethodEndpoint; use Mollie\Api\Endpoints\RefundEndpoint; +use Mollie\Api\Endpoints\SalesInvoiceEndpoint; use Mollie\Api\Endpoints\SessionEndpoint; use Mollie\Api\Endpoints\SettlementCaptureEndpoint; use Mollie\Api\Endpoints\SettlementChargebackEndpoint; @@ -122,6 +123,13 @@ class MollieApiClient */ public $customerPayments; + /** + * RESTful Sales Invoice resource. + * + * @var SalesInvoiceEndpoint + */ + public $salesInvoices; + /** * RESTful Settlement resource. * @@ -444,6 +452,7 @@ public function initializeEndpoints() $this->profileMethods = new ProfileMethodEndpoint($this); $this->profiles = new ProfileEndpoint($this); $this->refunds = new RefundEndpoint($this); + $this->salesInvoices = new SalesInvoiceEndpoint($this); $this->settlementCaptures = new SettlementCaptureEndpoint($this); $this->settlementChargebacks = new SettlementChargebackEndpoint($this); $this->settlementPayments = new SettlementPaymentEndpoint($this); diff --git a/src/Resources/SalesInvoice.php b/src/Resources/SalesInvoice.php new file mode 100644 index 00000000..432d0cde --- /dev/null +++ b/src/Resources/SalesInvoice.php @@ -0,0 +1,167 @@ +status === SalesInvoiceStatus::DRAFT; + } + + /** + * Returns whether the sales invoice is issued. + * + * @return bool + */ + public function isIssued() + { + return $this->status === SalesInvoiceStatus::ISSUED; + } + + /** + * Returns whether the sales invoice is paid. + * + * @return bool + */ + public function isPaid() + { + return $this->status === SalesInvoiceStatus::PAID; + } +} diff --git a/src/Resources/SalesInvoiceCollection.php b/src/Resources/SalesInvoiceCollection.php new file mode 100644 index 00000000..6a76b995 --- /dev/null +++ b/src/Resources/SalesInvoiceCollection.php @@ -0,0 +1,22 @@ +client); + } +} diff --git a/src/Types/SalesInvoiceStatus.php b/src/Types/SalesInvoiceStatus.php new file mode 100644 index 00000000..02dc1369 --- /dev/null +++ b/src/Types/SalesInvoiceStatus.php @@ -0,0 +1,21 @@ +