zzantares / cfdi-wrapper
Simple wrapper to interact with a CFDI without XSD hassle.
Requires
- php: >=5.4.0
- ext-gd: *
- bacon/bacon-qr-code: ~1.0
- zzantares/helpers: ~1.0
Requires (Dev)
- phpunit/phpunit: ~5.0
- squizlabs/php_codesniffer: ~2.0
This package is not auto-updated.
Last update: 2024-12-18 10:34:41 UTC
README
This project is a neat wrapper for CFDI XSD files, this library allows you to manipulate CFDI attributes in a very simple and intuitive way without dealing with XML, XSD or XPATH at all!
Instalation
Add the dependency to your composer.json
:
{
"require": {
"zzantares/cfdi-wrapper": "dev-master",
}
}
Now just run composer install
or composer update
depending on the stage of
your project
Usage
In order to use the CFDI Wrapper advantages create an instance of the Cfdi
class by passing the XML content of the CFDI to inspect:
<?php require 'vendor/autoload.php'; use ZzAntares\CfdiWrapper\Cfdi; $xmlContent = file_get_contents('/path/to/cfdi.xml'); $cfdi = new Cfdi($xmlContent); echo $cfdi->emisor->rfc; // 'some123456rfc'
It is also possible to create an instance from a path file, like this:
<?php require 'vendor/autoload.php'; use ZzAntares\CfdiWrapper\Cfdi; $cfdi = new Cfdi('/path/to/cfdi.xml');
Available attributes
'version', 'serie', 'folio', 'fecha', 'subTotal', 'subtotal', // Alias of subTotal 'total', 'certificado' , 'noCertificado', 'condicionesDePago', 'descuento', 'motivoDescuento', 'TipoCambio', 'tipoCambio', // Alias of TipoCambio 'Moneda', 'moneda', // Alias of Moneda 'metodoDePago', 'sello' , 'tipoDeComprobante', 'formaDePago', 'LugarExpedicion', 'lugarExpedicion', // Alias of LugarExpedcion 'NumCtaPago', 'numCtaPago', // Alias of numCtaPago
Also you can access to the nested objects:
'emisor', 'receptor', 'conceptos', 'impuestos', 'impuestosLocales', 'timbreFiscalDigital', 'timbre', // Alias of timbreFiscalDigital
Every one of this nested objects has it's own attributes, you can get them very intuitively by reading the CFDI XSD file, here are some common examples:
<?php $cfdi->folio; $cfdi->fecha; $cfdi->emisor->rfc; $cfdi->emisor->nombre; $cfdi->emisor->domicilio->calle; $cfdi->receptor->rfc; $cfdi->receptor->nombre; $cfdi->receptor->domicilio->calle; $cfdi->timbre->uuid; $cfdi->conceptos; // Is an array $cfdi->conceptos[0]->descripcion;