Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Eseperio/verifactu-php/llms.txt
Use this file to discover all available pages before exploring further.
QrGeneratorService generates the AEAT VERI*FACTU QR code that must be printed on every invoice. The QR encodes a verification URL containing the issuer’s NIF, the invoice series number, the issue date, and the SHA-256 huella. Any citizen or inspector can scan the QR to verify the invoice at the AEAT portal.
Namespace: eseperio\verifactu\services\QrGeneratorService
Requires: bacon/bacon-qr-code (installed automatically as a Composer dependency).
Constants
Destination constants
| Constant | Value | Description |
|---|---|---|
DESTINATION_STRING | "string" | Return the raw image binary (PNG) or text (SVG) as a PHP string. |
DESTINATION_FILE | "file" | Save the QR to a temporary file and return its absolute path. |
Renderer constants
| Constant | Value | Description |
|---|---|---|
RENDERER_GD | "gd" | PNG output via PHP’s built-in GD extension. Broadest compatibility. |
RENDERER_IMAGICK | "imagick" | PNG output via ImageMagick. Higher quality; requires the imagick PHP extension. |
RENDERER_SVG | "svg" | Scalable Vector Graphics output. Ideal for print and PDF embedding. |
Methods
generateQr(InvoiceRecord $record, string $baseVerificationUrl, string $dest, int $size, string $engine): string
Generates a QR code for the given invoice record.
An
InvoiceSubmission or InvoiceCancellation. The hash field should be populated before calling this method — if hash is empty the huella query parameter is omitted from the QR URL.The AEAT verification base URL. This is prepended to the query string. Example:
"https://sede.agenciatributaria.gob.es/Sede/verifactu/verifactu.html".Output destination.
DESTINATION_STRING returns raw image/SVG data. DESTINATION_FILE writes to a temp file via sys_get_temp_dir() and returns the path. The file is named qr_<uniqid>.<ext>.Output resolution in pixels (PNG) or viewBox units (SVG). AEAT regulations require the QR code to be legible — a minimum of 300 px / 300 pt is recommended.
Renderer backend. One of
RENDERER_GD, RENDERER_IMAGICK, or RENDERER_SVG. Throws \RuntimeException if an unsupported value is supplied.buildQrContent() (protected)
Constructs the full QR payload URL from an InvoiceRecord. Although protected (not directly callable), understanding its output is important for debugging and compliance.
URL format:
huella parameter is only appended when $record->hash is non-empty. For a VERI*FACTU submission the hash must always be set before generating the QR.
Query parameters:
| Parameter | Source | Example |
|---|---|---|
nif | InvoiceId::$issuerNif | B12345678 |
num | InvoiceId::$seriesNumber | FACT-2024-001 |
fecha | InvoiceId::$issueDate | 01-01-2024 |
huella | InvoiceRecord::$hash | 3B4C1A2D... |
http_build_query().
Code examples
PNG via GD (default)
PNG via GD — save to file
High-quality PNG via ImageMagick
Scalable SVG (for PDF / print)
Via VerifactuService (reads base URL from config)
File extension mapping
| Renderer | File extension |
|---|---|
RENDERER_GD | .png |
RENDERER_IMAGICK | .png |
RENDERER_SVG | .svg |
Requirements by renderer
| Renderer | PHP extension required | Notes |
|---|---|---|
RENDERER_GD | ext-gd | Available in most PHP distributions by default. |
RENDERER_IMAGICK | ext-imagick | Must be compiled against ImageMagick. |
RENDERER_SVG | None | Pure PHP SVG rendering via bacon/bacon-qr-code. |