Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/josemmo/Verifactu-PHP/llms.txt

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

QrGenerator (josemmo\Verifactu\Services\QrGenerator) generates the URL that must be encoded into the QR code printed on every VERI*FACTU invoice. The library only produces the URL string — rendering an actual QR image is out of scope and must be handled by a separate library such as endroid/qr-code. By default the generator targets the production environment and operates in online (VERI*FACTU) mode.

Configuration methods

Both methods return static so they can be chained.

setProduction()

public function setProduction(bool $production): static
production
bool
required
Pass true (default) to generate URLs pointing to the live AEAT portal (www2.agenciatributaria.gob.es). Pass false to generate pre-production URLs (prewww2.aeat.es).

setOnlineMode()

public function setOnlineMode(bool $onlineMode): static
onlineMode
bool
required
Pass true (default) to use the VERI*FACTU (online) verification path — ValidarQR. Pass false to use the Non-VERI*FACTU (offline) path — ValidarQRNoVerifactu.

Generating URLs

fromRegistrationRecord()

public function fromRegistrationRecord(RegistrationRecord $record): string
Convenience method that reads the invoice identifier and total amount directly from a RegistrationRecord.
record
RegistrationRecord
required
A fully populated registration record. The method extracts $record->invoiceId and $record->totalAmount.

fromInvoiceId()

public function fromInvoiceId(InvoiceIdentifier $invoiceId, string $amount): string
Generates the URL from an InvoiceIdentifier object and a pre-formatted amount string.
invoiceId
InvoiceIdentifier
required
The invoice identifier containing issuer NIF, invoice number, and issue date. See InvoiceIdentifier.
amount
string
required
The invoice total amount as a decimal string, e.g. "121.00". Must match the value stored in the record.

from()

public function from(
    string $issuerId,
    string $invoiceNumber,
    DateTimeInterface $issueDate,
    string $amount,
): string
The low-level method used internally by both helpers above. Call this directly when you only have raw scalar values.
issuerId
string
required
NIF of the invoice issuer (exactly 9 characters).
invoiceNumber
string
required
Invoice series and number, e.g. "F-2024/001".
issueDate
DateTimeInterface
required
Issue date of the invoice. The time component is ignored; only the calendar date is encoded.
amount
string
required
Invoice total amount formatted as a decimal string, e.g. "1210.50".

URL format

The generated URL follows this structure:
{base}/wlpl/TIKE-CONT/{path}?nif={issuerId}&numserie={invoiceNumber}&fecha={dd-mm-yyyy}&importe={amount}
ComponentProductionPre-production
Base (online)https://www2.agenciatributaria.gob.eshttps://prewww2.aeat.es
Path (VERI*FACTU)ValidarQRValidarQR
Path (Non-VERI*FACTU)ValidarQRNoVerifactuValidarQRNoVerifactu
Query parameters:
ParameterDescription
nifIssuer NIF
numserieInvoice number
fechaIssue date in dd-mm-yyyy format
importeTotal invoice amount
The fecha parameter is always formatted as dd-mm-yyyy regardless of the locale or timezone of the DateTimeInterface object passed.

Complete example

use josemmo\Verifactu\Services\QrGenerator;
use josemmo\Verifactu\Models\Records\InvoiceIdentifier;
use DateTimeImmutable;

$generator = new QrGenerator();
$generator
    ->setProduction(false)    // pre-production for testing
    ->setOnlineMode(true);    // VERI*FACTU mode

// --- Option A: from a RegistrationRecord ---
// $url = $generator->fromRegistrationRecord($registrationRecord);

// --- Option B: from an InvoiceIdentifier ---
$invoiceId = new InvoiceIdentifier(
    'A12345678',
    'F-2024/001',
    new DateTimeImmutable('2024-06-15'),
);
$url = $generator->fromInvoiceId($invoiceId, '121.00');

// --- Option C: from raw scalars ---
$url = $generator->from(
    'A12345678',
    'F-2024/001',
    new DateTimeImmutable('2024-06-15'),
    '121.00',
);

echo $url;
// https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR
//   ?nif=A12345678&numserie=F-2024%2F001&fecha=15-06-2024&importe=121.00

// Encode $url into a QR image using your preferred library, e.g. endroid/qr-code

Build docs developers (and LLMs) love