Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/NemonInvocash/verifactu-php/llms.txt

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

verifactuPHP includes a built-in debug mode that prints real-time diagnostic messages to standard output as the library performs operations. When enabled, you can observe every stage of the request lifecycle — from the initial login token exchange through individual API calls to the construction of each model object. This makes it straightforward to verify that your data is being assembled correctly before it is submitted to AEAT. Debug mode is off by default. It is controlled through a pair of methods on ClienteVerifactu: setDebug(bool) and getDebug(). All output is produced by the private mostrarDebug() method, which checks the flag before printing — so there is no performance overhead when the mode is disabled.

Enabling debug mode

Instantiate the client as normal and then call setDebug(true). Because the constructor triggers authentication immediately, the login attempt itself will not produce debug output unless you enable the mode before construction — which is not possible given the current API. All subsequent operations after the setDebug() call will emit diagnostic messages.
use verifactuPHP\ClienteVerifactu;

$client = new ClienteVerifactu('you@example.com', 'password');
$client->setDebug(true);

What gets logged

The following messages are printed to stdout while debug mode is active:
TriggerMessage
Successful loginToken recibido: <token-value>
Login returns no tokenNo se ha recibido token
Login HTTP errorError en la solicitud: <guzzle-message>
Any successful API request (read/list operations)Petición realizada correctamente followed by a print_r dump of the full response array. Write operations (altaEmisor, altaRegistroAlta, altaRegistroAnulacion) print only Petición realizada correctamente — no response dump, because they pass $requiereRetorno = false.
nuevoEmisor() successEmisor creado con éxito! followed by a print_r of getArrayData()
nuevoDestinatario() successDestinatario creado con éxito! followed by a print_r of getArrayData()
nuevoTercero() successTercero creado con éxito! followed by a print_r of getArrayData()
nuevoDesglose() successDesglose creado con éxito! followed by a print_r of getArrayData()
nuevoRegistroAlta() successRegistro Alta creado con éxito! followed by a print_r of getArrayData()
nuevoRegistroAnulacion() successRegistro de anulacion creado con éxito! followed by a print_r of getArrayData()
nuevaFacturaRectificada() successFactura Rectificada creada con éxito! followed by a print_r of getArrayData()
nuevaFacturaSustituida() successFactura Sustituida creada con éxito! followed by a print_r of getArrayData()
altaEmisor() successEmisor dado de alta con éxito!
altaRegistroAlta() successRegistro Alta dado de alta con éxito!
altaRegistroAnulacion() successRegistro de anulacion dado de alta con éxito!
Any factory method errorError al crear <resource>: <exception-message>

Using debug mode during development

A typical development workflow is to enable debug mode after construction and then build your objects step by step, inspecting the output of getArrayData() at each stage to confirm the fields are correct before making a live submission.
use verifactuPHP\ClienteVerifactu;

$client = new ClienteVerifactu('you@example.com', 'password');
$client->setDebug(true);

// Each of these calls will print confirmation and field data to stdout.
$emisor = $client->nuevoEmisor([
    'nif'        => 'A39200019',
    'nombre'     => 'Mi Empresa S.L.',
    'enviarAeat' => true,
]);

$desglose = $client->nuevoDesglose([
    'impuesto'                      => 1,
    'tipoImpositivo'                => 21.0,
    'baseImponibleOImporteNoSujeto' => 100.0,
    'cuotaRepercutida'              => 21.0,
]);

$registro = $client->nuevoRegistroAlta(
    ['emisor' => $emisor, 'desglose' => $desglose],
    [
        'numSerieFactura'        => 'FAC/2024-001',
        'fechaExpedicionFactura' => '2024-12-01',
        'tipoFactura'            => 'F1',
        'cuotaTotal'             => 21.0,
        'importeTotal'           => 121.0,
    ]
);

Disabling debug mode

Call setDebug(false) at any point to stop output. You can toggle the mode on and off within a single script if you only want to trace a specific portion of the execution.
$client->setDebug(false);

Checking the current state

getDebug() returns the current value of the debug flag as a bool. Use this if you need to conditionally branch on whether debug mode is active in your own code.
$isDebug = $client->getDebug(); // true or false
Debug mode writes sensitive information — including the full Bearer token, invoice data, and complete API responses — directly to stdout. Never enable debug mode in production environments or in any context where stdout is captured by insecure logging infrastructure. Token exposure could allow an attacker to submit or cancel invoices on your behalf.
Use debug mode during development to verify that each model’s getArrayData() output contains exactly the fields you expect before calling altaRegistroAlta() or altaRegistroAnulacion(). Catching a missing or mis-typed field at construction time is far cheaper than diagnosing a rejection from AEAT.

Build docs developers (and LLMs) love