redocmx/client-php
Composer 安装命令:
composer require redocmx/client-php
包简介
Converción de CFDI a PDF.
README 文档
README
redocmx/client-php
The redocmx/client-php module is a PHP client for interacting with the redoc.mx REST API to convert CFDIs (Comprobante Fiscal Digital por Internet) to PDFs.
This client simplifies the process of sending XML data and retrieving the converted PDF, along with transaction details and metadata.
Requirements
PHP 5.6.0 and later.
Installation
To install the module, run:
composer require redocmx/client-php
To use the bindings, use Composer's autoload:
require_once 'vendor/autoload.php';
Usage
First, import the module and create an instance of the Redoc client.
You can optionally pass your API key as an argument, or the client will attempt to load it from the REDOC_API_KEY environment variable.
use Redocmx\RedocmxClient; # Create a Redoc instance $redoc = new RedocmxClient('your_api_key_here');
Converting CFDI to PDF
The redocmx/client-php provides two options for loading CFDI data: from a file or directly from a string.
Option 1: Load XML from the File System
$cfdi = $redoc->cfdi()->fromFile('./path/to/your/file.xml');
Option 2: Use an XML Content String
$cfdi = $redoc->cfdi()->fromString('<xml_content_string_here>');
Generating the PDF
To convert the loaded CFDI to a PDF:
try { # Create the PDF $pdf = $cfdi->toPdf(); echo("Transaction ID: " . $pdf->getTransactionId() . "\n"); echo("Total Pages: " . $pdf->getTotalPages() . "\n"); echo("Total Time: " .$pdf->getTotalTimeMs() . "\n"); print_r($pdf->getMetadata()); # Save in file system file_put_contents('./result.pdf', $pdf->toBuffer()); } catch (Exception $e) { echo "An error occurred during the conversion: " . $e->getMessage(); }
Examples
API Reference
RedocmxClient
The $redoc object is an instance of RedocmxClient, created using new RedocmxClient(api_key).
| Method | Description |
|---|---|
| $redoc->cfdi()->fromFile(filePath) | Returns: Cfdi - Instance Loads file content from the file system for converting a CFDI to PDF. The file should be valid XML for a CFDI. It returns an instance of the Cfdi class, which can be used to obtain the PDF. |
| $redoc->cfdi()->fromString(fileContent) | Returns: Cfdi - Instance Uses a CFDI as a string for converting the CFDI to PDF. The string should be valid XML for a CFDI. It returns an instance of the Cfdi class, which can be used to obtain the PDF. |
Cfdi
The $cfdi object is an instance of Cfdi, created using $redoc->cfdi()->fromFile(filePath) or $redoc->cfdi()->fromString(fileContent).
| Method | Description |
|---|---|
| $cfdi()->setAddenda(str) | Params: String Allows the use of a redoc addenda for full control over the design of the final PDF. |
| $cfdi()->toPdf(options) | Params: Object - PdfOptions Returns: Pdf - Instance An instance of the Pdf class, which, when invoked, converts the CFDI into a PDF and stores it, along with the generated data from the conversion request. |
PdfOptions
[ "style_pdf"=>"John" ]
The $pdf object is an instance of Pdf, created from $cfdi->toPdf(options).
| Method | Description |
|---|---|
| $pdf->toBuffer() | Returns: Buffer The PDF document as a buffer, ready for storage in the file system or to be sent back in an HTTP request. |
| $pdf->getTransactionId() | Returns: String - UUID A unique ID for the transaction request to the redoc service. |
| $pdf->getTotalPages() | Returns: Integer The total number of pages generated for the PDF file. |
| $pdf->getTotalTimeMs() | Returns: Integer Time in milliseconds taken to convert the CFDI to PDF. |
| $pdf->getMetadata() | Returns: Object - CfdiMetadata General information from the converted CFDI. |
CfdiMetadata
[
TDB...
]
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs, features, or improvements.
License
This project is licensed under the MIT License - see the LICENSE file for details.
redocmx/client-php 适用场景与选型建议
redocmx/client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mexico」 「cfdi」 「cfdi a pdf」 「cfdi to pdf」 「conversión cfdi a pdf」 「sat mexico」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 redocmx/client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redocmx/client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 redocmx/client-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Servicio Postal Mexicano (Sepomex) not official laravel library
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
Provides TCPDF integration for Symfony
This package allow you to convert csd to required pem files
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-25