facturapi/facturapi-php
Composer 安装命令:
composer require facturapi/facturapi-php
包简介
Facturapi's PHP client library
README 文档
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
Backward Compatibility With Older PHP Versions
Since version 4.0.0, the SDK requires PHP >= 8.2.
- If your project already runs on PHP 8.2+, no extra changes are needed.
- If your project runs on PHP 8.1 or lower, pin to version 3.7.0 (latest compatible release before PHP 8.2 requirement).
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, ]);
Organizations: Set Default Series
$result = $facturapi->Organizations->updateDefaultSeries( 'ORGANIZATION_ID', [ 'type' => 'I', 'series' => 'A', ] );
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
facturapi/facturapi-php 适用场景与选型建议
facturapi/facturapi-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50.2k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「mexico」 「sat」 「cfdi」 「factura」 「facturapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 facturapi/facturapi-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 facturapi/facturapi-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 facturapi/facturapi-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Servicio Postal Mexicano (Sepomex) not official laravel library
A PSR-7 compatible library for making CRUD API endpoints
Servicio Postal Mexicano PHP Library (Unofficial)
Librería para descargar los XSLT de la Cadena Original del Servicio de Administración Tributaria (SAT)
Parse and validate CFDIs against SAT México
Librería para generar Comprobantes Fiscales para la versión 3.3
统计信息
- 总下载量: 50.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-04