facturapi / facturapi-php
Facturapi's PHP client library
4.1.0
2026-03-31 17:55 UTC
Requires
- php: >=8.2
- guzzlehttp/guzzle: ^7.9
- psr/http-client: ^1.0
Requires (Dev)
- phpunit/phpunit: ^11.5
- dev-main
- 4.1.0
- 4.0.0
- 3.7.0
- 3.6.0
- 3.5.0
- v3.4.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.7.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-v4-cleanup-modernization
- dev-deploy-automation
- dev-chore/catalogComercioExterior
- dev-chore/delete_retentions
- dev-chhore/catalogs_cartaporte
- dev-FAC-1383/feature/self-invoice-settings
- dev-FAC-1254/feature/customer-edit-links
- dev-hotfix/conditional_body_put
- dev-chore/validate_signature
- dev-chore/list_delete_api_keys
- dev-fix/post_with_body_null
- dev-feat/error_exception
- dev-dev
This package is auto-updated.
Last update: 2026-03-31 17:55:50 UTC
README
Official PHP SDK for Facturapi.
Language: English | Español
Installation ⚡
composer require facturapi/facturapi-php
Without Composer (supported workaround):
require_once __DIR__ . '/path/to/facturapi-php/src/Facturapi.php';
Requirements:
- PHP
>=8.2
Quick Start 🚀
<?php require_once __DIR__ . '/vendor/autoload.php'; use Facturapi\Facturapi; $apiKey = getenv('FACTURAPI_KEY') ?: 'YOUR_API_KEY'; $facturapi = new Facturapi($apiKey); $customer = $facturapi->Customers->create([ 'email' => 'walterwhite@gmail.com', 'legal_name' => 'Walter White', 'tax_id' => 'WIWA761018', 'address' => [ 'zip' => '06800', 'street' => 'Av. de los Rosales', 'exterior' => '123', 'neighborhood' => 'Tepito', ], ]);
Client Configuration ⚙️
Constructor signature:
new Facturapi(string $apiKey, ?array $config = null)
Supported config keys:
apiVersion(string, default:v2)timeout(int|float, default:360seconds)httpClient(Psr\Http\Client\ClientInterface, advanced)
Example:
use Facturapi\Facturapi; $facturapi = new Facturapi($apiKey, [ 'apiVersion' => 'v2', 'timeout' => 420, ]);
Custom HTTP Client (Advanced)
The SDK works out of the box with its internal Guzzle-based client.
If you provide httpClient, pass any PSR-18 compatible client and configure its timeout values in that client:
use Facturapi\Facturapi; use GuzzleHttp\Client; $httpClient = new Client([ 'timeout' => 420, ]); $facturapi = new Facturapi($apiKey, [ 'httpClient' => $httpClient, ]);
Common Usage 🧾
Create a Product
$product = $facturapi->Products->create([ 'product_key' => '4319150114', 'description' => 'Apple iPhone 8', 'price' => 345.60, ]);
Create an Invoice
$invoice = $facturapi->Invoices->create([ 'customer' => 'YOUR_CUSTOMER_ID', 'items' => [[ 'quantity' => 1, 'product' => 'YOUR_PRODUCT_ID', ]], 'payment_form' => \Facturapi\PaymentForm::EFECTIVO, 'folio_number' => '581', 'series' => 'F', ]);
Download Files
$zipBytes = $facturapi->Invoices->downloadZip('INVOICE_ID'); $pdfBytes = $facturapi->Invoices->downloadPdf('INVOICE_ID'); $xmlBytes = $facturapi->Invoices->downloadXml('INVOICE_ID');
downloadPdf() returns raw PDF bytes (binary string), not base64.
file_put_contents('invoice.pdf', $pdfBytes);
Send by Email
$facturapi->Invoices->sendByEmail('INVOICE_ID');
Comercio Exterior Catalogs
$results = $facturapi->ComercioExteriorCatalogs->searchTariffFractions([ 'q' => '0101', 'page' => 0, 'limit' => 10, ]);
Error Handling ⚠️
On non-2xx responses, the SDK throws Facturapi\Exceptions\FacturapiException.
The exception includes:
getMessage(): API error message when present.getStatusCode(): HTTP status code.getErrorData(): decoded JSON error payload (full API shape).getRawBody(): raw response body string.
use Facturapi\Exceptions\FacturapiException; try { $facturapi->Invoices->create($payload); } catch (FacturapiException $e) { $status = $e->getStatusCode(); $error = $e->getErrorData(); // Full API error shape when body is valid JSON. $firstDetail = $error['details'][0] ?? null; // e.g. ['path' => 'items.0.quantity', 'message' => '...', 'code' => '...'] }
Migration Notes (v4) 🔄
- Minimum PHP version is now
>=8.2. - Removed support for the positional
apiVersionconstructor argument. - Composer projects: no loader changes needed; keep using
vendor/autoload.php. - Non-Composer projects can keep using the SDK by loading
src/Facturapi.phpdirectly. - Snake_case method aliases are deprecated in v4 and will be removed in v5.
Facturapi\\Exceptions\\Facturapi_Exceptionis deprecated in v4 and will be removed in v5.- Use
Facturapi\\Exceptions\\FacturapiException.
Documentation 📚
Full docs: https://docs.facturapi.io
Support 💬
- Issues: open a GitHub issue
- Email:
contacto@facturapi.io