Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/eclipxe13/CfdiUtils/llms.txt

Use this file to discover all available pages before exploring further.

CfdiCreator33 mirrors CfdiCreator40 in every respect — the same constructor signature, the same helper methods, and the same underlying CfdiCreatorTrait — but it targets the CFDI version 3.3 namespace and element set (CfdiUtils\Elements\Cfdi33\Comprobante). All the general creation rules documented for CFDI 4.0 apply equally here; the only differences are the namespace URIs, the element classes used, and the XSLT location resolved when generating the cadena de origen.
CFDI 3.3 has been suspended by the SAT. The SAT requires all new electronic invoices to be issued as CFDI 4.0. The CfdiCreator33 class is kept in CfdiUtils for backward compatibility only, and it will be removed in the next major version. All new integrations must use CfdiCreator40. If you are maintaining an existing CFDI 3.3 integration, plan your migration promptly.

Constructor

new CfdiCreator33(
    array $comprobanteAttributes = [],
    ?Certificado $certificado = null,
    ?XmlResolver $xmlResolver = null,
    ?XsltBuilderInterface $xsltBuilder = null,
)
comprobanteAttributes
array
default:"[]"
Key/value pairs set as attributes on the root cfdi:Comprobante element. Fixed attributes (Version, xmlns:cfdi, xsi:schemaLocation) are set automatically by the Cfdi33\Comprobante element.
certificado
Certificado|null
default:"null"
An optional CfdiUtils\Certificado\Certificado instance. When provided, putCertificado() is called immediately at construction time.
xmlResolver
XmlResolver|null
default:"null"
Manages local caching of SAT XSD and XSLT resources. Defaults to a new XmlResolver with SAT remote URLs.
xsltBuilder
XsltBuilderInterface|null
default:"null"
The XSLT engine used to build the cadena de origen. Defaults to CfdiUtils\CadenaOrigen\DOMBuilder.

Methods

CfdiCreator33 exposes the same methods as CfdiCreator40, all provided by the shared CfdiCreatorTrait:
MethodDescription
comprobante(): ComprobanteReturns the CfdiUtils\Elements\Cfdi33\Comprobante root element.
putCertificado(Certificado $cert, bool $putEmisorRfcNombre = true): voidWrites NoCertificado and Certificado attributes; optionally sets Emisor.Rfc and Emisor.Nombre.
asXml(): stringSerializes the element tree to an XML string.
saveXml(string $filename): boolWrites the XML to a file.
buildCadenaDeOrigen(): stringApplies the CFDI 3.3 XSLT and returns the cadena de origen string.
buildSumasConceptos(int $precision = 2): SumasConceptosComputes totals from the Conceptos without writing them.
addSumasConceptos(?SumasConceptos $sumas = null, int $precision = 2): voidComputes and writes totals to SubTotal, Total, Descuento, and Impuestos.
addSello(string $key, string $passPhrase = ''): voidSigns the document and stores the Base64 signature in the Sello attribute.
validate(): AssertsRuns the CFDI 3.3 validation suite (MultiValidatorFactory::newCreated33()).
moveSatDefinitionsToComprobante(): voidMoves all namespace declarations to the root node.

Key Differences from CFDI 4.0

AspectCFDI 3.3CFDI 4.0
Creator classCfdiUtils\CfdiCreator33CfdiUtils\CfdiCreator40
Element namespaceCfdiUtils\Elements\Cfdi33CfdiUtils\Elements\Cfdi40
XML namespace URIhttp://www.sat.gob.mx/cfd/3http://www.sat.gob.mx/cfd/4
Schema location.../cfd/3/cfdv33.xsd.../cfd/4/cfdv40.xsd
XSLT location.../cadenaoriginal_3_3/cadenaoriginal_3_3.xslt.../cadenaoriginal_4_0/cadenaoriginal_4_0.xslt
Emisor suffix trimNot appliedApplied for 12-char RFC
SAT statusSuspendedCurrent standard
Migrating from CFDI 3.3 to 4.0 within CfdiUtils is straightforward: replace every reference to CfdiUtils\Elements\Cfdi33 with CfdiUtils\Elements\Cfdi40 and swap CfdiCreator33 for CfdiCreator40. Then adjust attribute names and values to match the SAT’s CFDI 4.0 specification (the library’s element compatibility layer minimises the breaking surface).

Basic Usage Example

<?php
declare(strict_types=1);

use CfdiUtils\CfdiCreator33;
use CfdiUtils\Certificado\Certificado;

$certificado = new Certificado('/certs/my_cert.cer');

$creator = new CfdiCreator33(
    [
        'Serie'             => 'B',
        'Folio'             => '00001',
        'Fecha'             => '2022-12-01T08:00:00',
        'FormaPago'         => '01',
        'MetodoPago'        => 'PUE',
        'LugarExpedicion'   => '06600',
        'TipoDeComprobante' => 'I',
        'Moneda'            => 'MXN',
    ],
    $certificado
);

$comprobante = $creator->comprobante();

// RFC and Nombre are populated from the certificate
$comprobante->addEmisor([
    'RegimenFiscal' => '601',
]);

$comprobante->addReceptor([
    'Rfc'     => 'XAXX010101000',
    'Nombre'  => 'PUBLICO EN GENERAL',
    'UsoCFDI' => 'P01',
]);

$comprobante->addConcepto([
    'ClaveProdServ' => '84111506',
    'Cantidad'      => '1',
    'ClaveUnidad'   => 'ACT',
    'Descripcion'   => 'Servicio',
    'ValorUnitario' => '1000.00',
    'Importe'       => '1000.00',
])->addTraslado([
    'Base'       => '1000.00',
    'Impuesto'   => '002',
    'TipoFactor' => 'Tasa',
    'TasaOCuota' => '0.160000',
    'Importe'    => '160.00',
]);

$creator->addSumasConceptos(null, 2);
$creator->addSello('file:///certs/my_key.pem', 'my-passphrase');
$creator->moveSatDefinitionsToComprobante();

$asserts = $creator->validate();
if ($asserts->hasErrors()) {
    print_r($asserts->errors());
    exit(1);
}

$creator->saveXml('/output/cfdi33_B_00001.xml');

Upgrade to CFDI 4.0

CFDI 3.3 has been suspended by the SAT. Follow the CFDI 4.0 guide to migrate your integration to the current standard.

Build docs developers (and LLMs) love