diff --git a/VERSION.md b/VERSION.md index 513572f..db95fa3 100644 --- a/VERSION.md +++ b/VERSION.md @@ -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`. diff --git a/src/Resources/Receipts.php b/src/Resources/Receipts.php index 06b7dc3..626b554 100644 --- a/src/Resources/Receipts.php +++ b/src/Resources/Receipts.php @@ -5,7 +5,8 @@ use Facturapi\Http\BaseClient; use Facturapi\Exceptions\FacturapiException; -class Receipts extends BaseClient { +class Receipts extends BaseClient +{ protected string $ENDPOINT = 'receipts'; @@ -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; } } @@ -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; } } @@ -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; } } @@ -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; } } @@ -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 * @@ -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; } } @@ -116,13 +159,14 @@ 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; } } @@ -130,9 +174,10 @@ public function sendByEmail( $id, $email = null ): mixed { /** * @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); } /** @@ -143,10 +188,11 @@ 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; } } @@ -154,8 +200,9 @@ public function downloadPdf( $id ): string { /** * @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); } }