Use this file to discover all available pages before exploring further.
A Retenciones e Información de Pagos document is a special category of CFDI that reports tax withholdings and payment information to the SAT. Unlike a regular income or expense CFDI, a Retenciones document uses its own XML schema (retenciones) and is not a cfdi:Comprobante — it is a retenciones:Retenciones root element with its own namespace, attribute set, and validation rules.CfdiUtils provides two creator classes for this document type:
CfdiUtils\Retenciones\RetencionesCreator10 — targets the version 1.0 schema (older format, signs with SHA-1).
CfdiUtils\Retenciones\RetencionesCreator20 — targets the version 2.0 schema (current format, signs with SHA-256).
Both classes share their implementation through RetencionesCreatorTrait and mirror the design of CfdiCreator40: you get a root element object (retenciones()), helper methods to set the certificate, sign, validate, and export to XML.
Key/value pairs set as attributes on the root Retenciones element. For version 1.0, typical keys are FechaExp and CveRetenc. For version 2.0, LugarExpRetenc is also required.
All methods below are available on both RetencionesCreator10 and RetencionesCreator20 via the shared RetencionesCreatorTrait, plus the version-specific putCertificado() and buildCadenaDeOrigen() methods defined on each class.
Method
Description
retenciones(): Retenciones
Returns the root Retenciones element object (Retenciones10\Retenciones or Retenciones20\Retenciones).
putCertificado(Certificado $certificado): void
Stores the certificate serial and PEM content on the retenciones node. Version 1.0 writes NumCert and Cert; version 2.0 writes NoCertificado and Certificado.
Signs the cadena de origen and stores the Base64 result in the Sello attribute. Version 1.0 uses SHA-1; version 2.0 uses SHA-256.
buildCadenaDeOrigen(): string
Fetches the version-specific XSLT and applies it to the current XML, returning the cadena de origen string. Throws \LogicException if the XmlResolver or XSLT builder is not set.
asXml(): string
Serializes the entire element tree to an XML string.
moveSatDefinitionsToRetenciones(): void
Moves namespace declarations to the root Retenciones node (SAT requirement).
validate(): Asserts
Validates the document against its XSD schema. Returns a CfdiUtils\Validate\Asserts collection.
Unlike regular CFDI validation (which runs multiple business-rule validators), Retenciones validation only checks XSD schema conformance via XmlFollowSchema.
use CfdiUtils\Certificado\Certificado;$creator->putCertificado(new Certificado('/certs/my_cert.cer'));$creator->addSello('file:///certs/my_key.pem', 'my-passphrase');