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.

CFDI 4.0 introduced significant changes to Mexico’s electronic invoicing standard, and CfdiUtils reflects those changes in its validation pipeline. The CfdiValidator40 class and the associated MultiValidatorFactory::newCreated40() / newReceived40() methods configure a dedicated validator set for CFDI 4.0 documents. While many of the underlying business rules are similar to the 3.3 validators, there are important additions and modifications you need to be aware of when working with CFDI 4.0 documents. All validation messages remain in Spanish, consistent with the SAT’s own terminology. The four-status system (OK, ERROR, WARN, NONE) and the mustStop behavior are identical to CFDI 3.3 — see the Validation Overview for a full explanation of the architecture.

Validating CFDI 4.0 Documents

Received documents

<?php
use CfdiUtils\CfdiValidator40;

$xmlContent = file_get_contents('/path/to/cfdi40.xml');

$validator = new CfdiValidator40();
$asserts = $validator->validateXml($xmlContent);

if ($asserts->hasErrors()) {
    echo 'Validation failed:' . PHP_EOL;
    foreach ($asserts->errors() as $error) {
        echo vsprintf('%-10s %-8s %s => %s', [
            $error->getCode(),
            $error->getStatus(),
            $error->getTitle(),
            $error->getExplanation(),
        ]) . PHP_EOL;
    }
} else {
    echo 'CFDI 4.0 passed all validation rules.' . PHP_EOL;
}

Created documents

<?php
use CfdiUtils\CfdiCreator40;

/** @var CfdiCreator40 $creator */
$asserts = $creator->validate();

foreach ($asserts as $assert) {
    echo vsprintf('%-10s %-8s %s => %s', [
        $assert->getCode(),
        $assert->getStatus(),
        $assert->getTitle(),
        $assert->getExplanation(),
    ]) . PHP_EOL;
}
CfdiValidator40 accepts an XmlResolver in its constructor or via setXmlResolver(). The resolver is used by XmlFollowSchema (to locate SAT XSD files) and TimbreFiscalDigitalSello (to fetch the SAT certificate from https://rdc.sat.gob.mx/). A default resolver is created automatically if you do not supply one.For XML documents that may contain whitespace artifacts or encoding irregularities, run them through CfdiUtils\Cleaner\Cleaner::staticClean($xmlContent) before passing them to the validator.

New Validators in CFDI 4.0

CFDI 4.0 introduces two validators that do not exist in the 3.3 pipeline.

XmlDefinition

This validator runs immediately after XmlFollowSchema and checks CFDI 4.0-specific structural requirements that are not covered by the XSD alone. It verifies three things: the correct SAT namespace for CFDI 4.0, the root element name, and the version attribute. The expected namespace is http://www.sat.gob.mx/cfd/4.
CodeTitle
XML01El XML implementa el namespace http://www.sat.gob.mx/cfd/4 con el prefijo cfdi
XML02El nodo principal se llama cfdi:Comprobante
XML03La versión es 4.0
These three rules make XmlDefinition a prerequisite guard for CFDI 4.0 processing. If a document uses the CFDI 3.3 namespace or declares version 3.3, all three codes will fail. Ensure your XML declares the correct namespace before submitting it for full validation.

Validators Shared with CFDI 3.3 (with Differences)

Several validators exist in both the 3.3 and 4.0 pipelines but have meaningful behavioral differences in CFDI 4.0.

SelloDigitalCertificado — Updated name-matching logic

The digital seal validator runs the same eight checks (SELLO01SELLO08) in both versions, but CFDI 4.0 introduces a change in how SELLO04 (issuer name) is evaluated:
VersionPersona Moral (12-char RFC)Persona Física (13-char RFC)
CFDI 3.3Name comparison is optional; an empty name is silently acceptedName is compared if non-empty
CFDI 4.0Régimen de capital suffix is stripped before comparing; an empty name causes an errorAn empty name causes an error
In CFDI 4.0, both persona física and persona moral issuers must provide a name that matches the certificate. For persona moral, the legal entity type suffix (e.g., “S.A. de C.V.”) is removed from the certificate name before the comparison is made.
CodeTitle
SELLO01Se puede obtener el certificado del comprobante
SELLO02El número de certificado del comprobante igual al encontrado en el certificado
SELLO03El RFC del comprobante igual al encontrado en el certificado
SELLO04El nombre del emisor del comprobante es igual al encontrado en el certificado
SELLO05La fecha del documento es mayor o igual a la fecha de inicio de vigencia del certificado
SELLO06La fecha del documento menor o igual a la fecha de fin de vigencia del certificado
SELLO07El sello del comprobante está en base 64
SELLO08El sello del comprobante coincide con el certificado y la cadena de origen generada

TimbreFiscalDigitalSello — SAT stamp integrity

Identical behavior to CFDI 3.3. This remains the most critical validator: it fetches the SAT certificate, builds the TFD cadena de origen, and verifies the SAT seal.
CodeTitle
TFDSELLO01El Sello SAT del Timbre Fiscal Digital corresponde al certificado SAT

TimbreFiscalDigitalVersion — TFD version

Identical behavior to CFDI 3.3.
CodeTitle
TFDVERSION01Si existe el complemento timbre fiscal digital, entonces su versión debe ser 1.1

Differences from CFDI 3.3

The table below summarizes the key differences between the two validator pipelines.
AreaCFDI 3.3CFDI 4.0
XML namespacehttp://www.sat.gob.mx/cfd/3 (enforced via XSD)http://www.sat.gob.mx/cfd/4 — also explicitly checked by XmlDefinition (XML01)
Root element checkXSD onlyXmlDefinition explicitly verifies cfdi:Comprobante (XML02)
Version attributeXSD onlyXmlDefinition explicitly verifies Version = 4.0 (XML03)
Issuer name (SELLO04)Empty name is silently accepted for both RFC typesEmpty name causes an error; persona moral removes capital suffix before comparing
RecepcionPagos validatorsFull set of PAGO*, COMPPAG*, PAGREL*, PAGUSO*, PAGCON* codesNot present in the 4.0 standard validator set (Complemento Pagos 2.0 has its own validation path)
Factory methodMultiValidatorFactory::newCreated33() / newReceived33()MultiValidatorFactory::newCreated40() / newReceived40()
Discoverer source directoryCfdi33/Standard + Cfdi33/RecepcionPagosCfdi40/Standard
Validator classCfdiValidator33CfdiValidator40
Creator classCfdiCreator33CfdiCreator40
The CFDI 4.0 standard validator set (Cfdi40/Standard) does not include the Recepción de Pagos validators that exist in CFDI 3.3. The Complemento para Recepción de Pagos version 2.0 (used with CFDI 4.0) follows a separate validation path.

Validator Pipeline Order

Understanding the execution order helps diagnose partial validation results.
1

XmlFollowSchema (XSD01)

Validates the document against all declared XSD schemas. Sets mustStop on failure — no further validators run.
2

XmlDefinition (XML01–XML03)

Checks CFDI 4.0-specific namespace, root element name, and version. Runs after schema validation.
3

Standard validators (Cfdi40/Standard)

All validators discovered in the Cfdi40/Standard directory run in order: SelloDigitalCertificado, TimbreFiscalDigitalSello, and TimbreFiscalDigitalVersion.

Complete CFDI 4.0 Validation Code Reference

CodeValidatorTitle
XSD01XmlFollowSchemaEl contenido XML sigue los esquemas XSD
XML01XmlDefinitionEl XML implementa el namespace http://www.sat.gob.mx/cfd/4 con el prefijo cfdi
XML02XmlDefinitionEl nodo principal se llama cfdi:Comprobante
XML03XmlDefinitionLa versión es 4.0
SELLO01SelloDigitalCertificadoSe puede obtener el certificado del comprobante
SELLO02SelloDigitalCertificadoEl número de certificado del comprobante igual al encontrado en el certificado
SELLO03SelloDigitalCertificadoEl RFC del comprobante igual al encontrado en el certificado
SELLO04SelloDigitalCertificadoEl nombre del emisor del comprobante es igual al encontrado en el certificado
SELLO05SelloDigitalCertificadoLa fecha del documento es mayor o igual a la fecha de inicio de vigencia del certificado
SELLO06SelloDigitalCertificadoLa fecha del documento menor o igual a la fecha de fin de vigencia del certificado
SELLO07SelloDigitalCertificadoEl sello del comprobante está en base 64
SELLO08SelloDigitalCertificadoEl sello del comprobante coincide con el certificado y la cadena de origen generada
TFDSELLO01TimbreFiscalDigitalSelloEl Sello SAT del Timbre Fiscal Digital corresponde al certificado SAT
TFDVERSION01TimbreFiscalDigitalVersionSi existe el complemento timbre fiscal digital, entonces su versión debe ser 1.1

See Also

Validation Overview

Architecture, statuses, mustStop behavior, and complete usage examples.

Standard CFDI 3.3 Rules

Full reference for all CFDI 3.3 standard and RecepcionPagos validators.

Build docs developers (and LLMs) love