Skip to content
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
10 changes: 3 additions & 7 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
4.3.0
4.4.0
## Added
- Added Carta Porte / Comercio Exterior constants classes:
- `CustomsRegimes`, `CveTransporteEnum`, `TipoEstacionEnum`, `PermisoSctEnum`, `SectorCofeprisEnum`
- `PharmaceuticalFormsEnum`, `SpecialConditionsEnum`, `MaterialTypeEnum`, `TypeOfCustomsDocumentEnum`
- `TransportTypeEnum`, `TransportFigureEnum`, `RegistroIstmoEnum`, `LoadingKey`, `ConfigMaritimaEnum`
- `RailTrafficTypeEnum`, `ContainerTypeEnum`, `MaritimeContainerTypeEnum`, `RailCarTypeEnum`, `RailServiceTypeEnum`
- `MotivoTrasladoEnum`, `IncotermEnum`, `UnidadAduanaEnum`
- Added `Receipts->toInvoice(array $data)` to call `POST /receipts/multi-invoice`.
- Added `Receipts->previewToInvoicePdf(array $data)` to call `POST /receipts/multi-invoice/preview/pdf`.
105 changes: 76 additions & 29 deletions src/Resources/Receipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use Facturapi\Http\BaseClient;
use Facturapi\Exceptions\FacturapiException;

class Receipts extends BaseClient {
class Receipts extends BaseClient
{
protected string $ENDPOINT = 'receipts';


Expand All @@ -17,10 +18,11 @@ class Receipts extends BaseClient {
*
* @throws FacturapiException
*/
public function all( $params = null ): mixed {
public function all($params = null): mixed
{
try {
return json_decode( $this->executeGetRequest( $this->getRequestUrl( $params ) ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeGetRequest($this->getRequestUrl($params)));
} catch (FacturapiException $e) {
throw $e;
}
}
Expand All @@ -33,10 +35,11 @@ public function all( $params = null ): mixed {
*
* @throws FacturapiException
*/
public function retrieve( $id ): mixed {
public function retrieve($id): mixed
{
try {
return json_decode( $this->executeGetRequest( $this->getRequestUrl( $id ) ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeGetRequest($this->getRequestUrl($id)));
} catch (FacturapiException $e) {
throw $e;
}
}
Expand All @@ -49,10 +52,11 @@ public function retrieve( $id ): mixed {
*
* @throws FacturapiException
*/
public function create( $params ): mixed {
public function create($params): mixed
{
try {
return json_decode( $this->executeJsonPostRequest( $this->getRequestUrl(), $params ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeJsonPostRequest($this->getRequestUrl(), $params));
} catch (FacturapiException $e) {
throw $e;
}
}
Expand All @@ -67,10 +71,11 @@ public function create( $params ): mixed {
*
* @throws FacturapiException
*/
public function invoice( $id, $params ): mixed {
public function invoice($id, $params): mixed
{
try {
return json_decode( $this->executeJsonPostRequest( $this->getRequestUrl( $id ) . "/invoice", $params ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeJsonPostRequest($this->getRequestUrl($id) . "/invoice", $params));
} catch (FacturapiException $e) {
throw $e;
}
}
Expand All @@ -83,14 +88,51 @@ public function invoice( $id, $params ): mixed {
*
* @throws FacturapiException
*/
public function createGlobalInvoice( $params ): mixed {
public function createGlobalInvoice($params): mixed
{
try {
return json_decode( $this->executeJsonPostRequest( $this->getRequestUrl() . "/global-invoice", $params ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeJsonPostRequest($this->getRequestUrl() . "/global-invoice", $params));
} catch (FacturapiException $e) {
throw $e;
}
}

/**
* Creates a single invoice using a list of receipt keys
*
* @param $data Array of properties and property values for creating an invoice from multiple receipts
*
* @return Response The created invoice object or preview summary when dry_run is enabled
*
* @throws FacturapiException
*/
public function toInvoice($data)
{
try {
return json_decode($this->executeJsonPostRequest($this->getRequestUrl() . "/to-invoice", $data));
} catch (FacturapiException $e) {
throw new FacturapiException('Unable to create invoice: ' . $e->getMessage());
}
}

/**
* Generates an invoice PDF preview for multiple receipts without stamping or saving it
*
* @param $data Array of properties and property values for generating an invoice PDF preview
*
* @return string PDF file contents
*
* @throws Facturapi_Exception
*/
public function previewToInvoicePdf($data)
{
try {
return $this->executeJsonPostRequest($this->getRequestUrl() . "/to-invoice/preview", $data);
} catch (FacturapiException $e) {
throw new FacturapiException('Unable to generate invoice PDF preview: ' . $e->getMessage());
}
}

/**
* Cancel a Receipt
*
Expand All @@ -99,10 +141,11 @@ public function createGlobalInvoice( $params ): mixed {
*
* @throws FacturapiException
*/
public function cancel( $id ): mixed {
public function cancel($id): mixed
{
try {
return json_decode( $this->executeDeleteRequest( $this->getRequestUrl( $id ), null ) );
} catch ( FacturapiException $e ) {
return json_decode($this->executeDeleteRequest($this->getRequestUrl($id), null));
} catch (FacturapiException $e) {
throw $e;
}
}
Expand All @@ -116,23 +159,25 @@ public function cancel( $id ): mixed {
*
* @throws FacturapiException
*/
public function sendByEmail( $id, $email = null ): mixed {
public function sendByEmail($id, $email = null): mixed
{
try {
return json_decode( $this->executeJsonPostRequest(
return json_decode($this->executeJsonPostRequest(
$this->getRequestUrl($id) . "/email",
$email == null ? null : array("email" => $email)
));
} catch ( FacturapiException $e ) {
} catch (FacturapiException $e) {
throw $e;
}
}

/**
* @deprecated Use sendByEmail() instead. Will be removed in v5.
*/
public function send_by_email( $id, $email = null ): mixed {
public function send_by_email($id, $email = null): mixed
{
trigger_error('Receipts::send_by_email() is deprecated and will be removed in v5. Use sendByEmail() instead.', E_USER_DEPRECATED);
return $this->sendByEmail( $id, $email );
return $this->sendByEmail($id, $email);
}

/**
Expand All @@ -143,19 +188,21 @@ public function send_by_email( $id, $email = null ): mixed {
*
* @throws FacturapiException
*/
public function downloadPdf( $id ): string {
public function downloadPdf($id): string
{
try {
return $this->executeGetRequest( $this->getRequestUrl( $id ) . "/pdf" );
} catch ( FacturapiException $e ) {
return $this->executeGetRequest($this->getRequestUrl($id) . "/pdf");
} catch (FacturapiException $e) {
throw $e;
}
}

/**
* @deprecated Use downloadPdf() instead. Will be removed in v5.
*/
public function download_pdf( $id ): string {
public function download_pdf($id): string
{
trigger_error('Receipts::download_pdf() is deprecated and will be removed in v5. Use downloadPdf() instead.', E_USER_DEPRECATED);
return $this->downloadPdf( $id );
return $this->downloadPdf($id);
}
}
Loading