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!
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
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');
'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;