-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created InvoiceRequest, Invoice and InvoiceItem classes. Also code cl…
…eanup.
- Loading branch information
Showing
12 changed files
with
866 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"require": { | ||
"php": "^7.4|^8.0", | ||
"ext-json": "*", | ||
"ext-bcmath": "*", | ||
"guzzlehttp/guzzle": "^7.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Mvdgeijn\Pax8\Requests; | ||
|
||
use Mvdgeijn\Pax8\Collections\PaginatedCollection; | ||
use Mvdgeijn\Pax8\Responses\AbstractResponse; | ||
use Mvdgeijn\Pax8\Responses\Invoice; | ||
use Mvdgeijn\Pax8\Responses\InvoiceItem; | ||
|
||
class InvoiceRequest extends AbstractRequest | ||
{ | ||
/** | ||
* Returns a paginated list of all your invoices filtered by optional parameters | ||
* | ||
* Check https://docs.pax8.com/api/v1#tag/Invoices for possible | ||
* options | ||
* | ||
* @param array $options | ||
* @return PaginatedCollection|null | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function list(array $options = [] ): ?PaginatedCollection | ||
{ | ||
$response = $this->getRequest( '/v1/invoices', $options ); | ||
|
||
if ($response->getStatusCode() == 200) | ||
return Invoice::createFromBody( $response->getBody() ); | ||
else | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns a single invoice record matching the invoiceId you specify | ||
* | ||
* @param string $invoiceId | ||
* @return Invoice|null | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
* @throws \Exception | ||
*/ | ||
public function get(string $invoiceId): ?Invoice | ||
{ | ||
$response = $this->getRequest('/v1/invoices/' . $invoiceId); | ||
|
||
if ($response->getStatusCode() == 200) | ||
return Invoice::parse(json_decode($response->getBody())); | ||
else | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns a paginated list of all your invoice items filtered by invoiceId | ||
* and optional parameters | ||
* | ||
* Check https://docs.pax8.com/api/v1#operation/findPartnerInvoiceItems | ||
* for possible options | ||
* | ||
* @param array $options | ||
* @return PaginatedCollection|null | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function listItems(string $invoiceId, array $options = []): ?PaginatedCollection | ||
{ | ||
$response = $this->getRequest( "/v1/invoices/$invoiceId/items", $options ); | ||
|
||
if ($response->getStatusCode() == 200) | ||
return InvoiceItem::createFromBody( $response->getBody() ); | ||
else | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.