diff --git a/examples/get_invoice.php b/examples/get_invoice.php index 50e498a..92cc6ef 100644 --- a/examples/get_invoice.php +++ b/examples/get_invoice.php @@ -22,3 +22,12 @@ } catch (\Throwable $e) { echo "Error: " . $e->getMessage(); } + +// Get 2 invoices, skip 2 +try { + echo 'Get invoices:' . PHP_EOL; + $client = new Invoice($host, $apiKey); + var_dump($client->getAllInvoices($storeId, 2,2)); +} catch (\Throwable $e) { + echo "Error: " . $e->getMessage(); +} diff --git a/src/Client/Invoice.php b/src/Client/Invoice.php index d96293f..e187a6c 100644 --- a/src/Client/Invoice.php +++ b/src/Client/Invoice.php @@ -116,19 +116,71 @@ public function getInvoice( } } - public function getAllInvoices(string $storeId): InvoiceList - { - return $this->_getAllInvoicesWithFilter($storeId, null); + public function getAllInvoices( + string $storeId, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, null, null, null, null, null, $take, $skip); } - public function getInvoicesByOrderIds(string $storeId, array $orderIds): InvoiceList - { - return $this->_getAllInvoicesWithFilter($storeId, $orderIds); + public function getInvoicesByOrderIds( + string $storeId, + array $orderIds, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, $orderIds, null, null, null, null, $take, $skip); + } + + public function getInvoicesByText( + string $storeId, + string $text, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, null, $text, null, null, null, $take, $skip); + } + + public function getInvoicesByStatus( + string $storeId, + array $status, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, null, null, $status, null, null, $take, $skip); } - private function _getAllInvoicesWithFilter( + public function getInvoicesByStartDate( string $storeId, - array $filterByOrderIds = null + int $startDate, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, null, null, null, $startDate, null, $take, $skip); + } + + public function getInvoicesByEndDate( + string $storeId, + int $endDate, + int $take = null, + int $skip = null + ): InvoiceList { + return $this->getAllInvoicesWithFilter($storeId, null, null, null, null, $endDate, $take, $skip); + } + + /** + * @see https://docs.btcpayserver.org/API/Greenfield/v1/#operation/Invoices_GetInvoices + */ + public function getAllInvoicesWithFilter( + string $storeId, + array $filterByOrderIds = null, + string $filterByText = null, + array $filterByStatus = null, + int $filterByStartDate = null, + int $filterByEndDate = null, + int $take = null, + int $skip = null ): InvoiceList { $url = $this->getApiUrl() . 'stores/' . urlencode($storeId) . '/invoices?'; if ($filterByOrderIds !== null) { @@ -136,6 +188,26 @@ private function _getAllInvoicesWithFilter( $url .= 'orderId=' . urlencode($filterByOrderId) . '&'; } } + if ($filterByText !== null) { + $url .= 'textSearch=' . urlencode($filterByText) . '&'; + } + if ($filterByStatus !== null) { + foreach ($filterByStatus as $filterByStatusItem) { + $url .= 'status=' . urlencode($filterByStatusItem) . '&'; + } + } + if ($filterByStartDate !== null) { + $url .= 'startDate=' . $filterByStartDate . '&'; + } + if ($filterByEndDate !== null) { + $url .= 'endDate=' . $filterByEndDate . '&'; + } + if ($take !== null) { + $url .= 'take=' . $take . '&'; + } + if ($skip !== null) { + $url .= 'skip=' . $skip . '&'; + } // Clean URL. $url = rtrim($url, '&');