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.

Every resource in the VeriFactuAPI is represented by a dedicated PHP class in verifactuPHP. These model classes encapsulate the fields required by the API, enforce correct data types, and expose a single getArrayData() method that serializes the object into the exact array structure the API expects. Models are designed to be composable — smaller models such as Emisor, Destinatario, and Desglose are nested inside the top-level submission objects RegistroAlta and RegistroAnulacion.

Available models

ClassFactory methodPurpose
EmisornuevoEmisor()The invoice issuer. Holds the NIF, company name, optional representative details, webhook assignment, and AEAT submission flags.
DestinatarionuevoDestinatario()The invoice recipient. Holds the NIF or foreign identification details (otroCodPais, otroIDType, otroID) for domestic and cross-border invoices.
TerceronuevoTercero()A third party that issues an invoice on behalf of the emisor. Uses prefixed fields (tercNombreRazon, tercNIF, etc.) to avoid field-name collisions with Destinatario.
DesglosenuevoDesglose()A single tax breakdown line. Specifies the tax type (Impuesto, lista L1), fiscal regime (ClaveRegimen / ClaveRegimenIGIC), rate (TipoImpositivo), taxable base, and charged tax amount.
RegistroAltanuevoRegistroAlta()The main invoice registration record submitted to AEAT. Aggregates an Emisor, Destinatario, Desglose, and optionally a Tercero, FacturaRectificada, or FacturaSustituida.
RegistroAnulacionnuevoRegistroAnulacion()An invoice cancellation record. References a previously registered invoice by IDEmisorFactura, NumSerieFactura, and FechaExpedicionFactura.
FacturaRectificadanuevaFacturaRectificada()Identifies a prior invoice being corrected by the current RegistroAlta. Contains the issuer ID, series number, and issue date of the original invoice.
FacturaSustituidanuevaFacturaSustituida()Identifies a prior invoice being replaced (substituted) by the current RegistroAlta. Shares the same three-field structure as FacturaRectificada.

Key patterns

1. Models are created through ClienteVerifactu factory methods

All models must be instantiated through the corresponding factory method on ClienteVerifactu. The factory wraps the constructor, emits debug output when debug mode is enabled, and propagates any construction errors as Exception instances with descriptive messages.
use verifactuPHP\ClienteVerifactu;

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

$emisor = $client->nuevoEmisor(['nif' => 'A39200019', 'nombre' => 'Mi Empresa S.L.']);

2. Models accept a flat array in their constructor

Each model class accepts a single associative array whose keys match the PHP property names (camelCase). Any key not supplied defaults to an empty string, 0, or 0.0 depending on the property type — there is no need to pass every field.
// Only supply the fields you actually need.
$destinatario = $client->nuevoDestinatario([
    'nombreRazon' => 'Cliente S.A.',
    'nif'         => '39707287H',
]);

3. getArrayData() serialises only non-empty fields

When you call getArrayData() on any model, it iterates over its internal $APIids map and includes only fields whose value is neither an empty string nor 0 (nor 0.0 for floats). Empty fields are silently omitted. This means the resulting array contains exactly the fields the API needs — no nulls, no empty strings.
$data = $emisor->getArrayData();
// Returns, for example:
// ['nif' => 'A39200019', 'nombre' => 'Mi Empresa S.L.', 'enviar_aeat' => true]

4. empty() provides a safe default placeholder

Every model exposes a static empty() factory that returns a fully-initialised instance with all fields set to their zero values. RegistroAlta uses this internally — if you omit 'destinatario', 'tercero', 'facturaRectificada', or 'facturaSustituida' from the objects array, the constructor falls back to the corresponding empty() instance. Because getArrayData() omits zero-value fields, an empty model contributes nothing to the serialised output.
// FacturaRectificada::empty() is used automatically when the key is absent.
$registro = $client->nuevoRegistroAlta(
    ['emisor' => $emisor, 'desglose' => $desglose],
    ['numSerieFactura' => 'FAC/2024-001', /* ... */]
);

Composing a RegistroAlta

The example below shows how the individual models are built and composed into a RegistroAlta ready for submission:
use verifactuPHP\ClienteVerifactu;

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

// 1. Build the issuer.
$emisor = $client->nuevoEmisor([
    'nif'        => 'A39200019',
    'nombre'     => 'Mi Empresa S.L.',
    'enviarAeat' => true,
]);

// 2. Build the recipient.
$destinatario = $client->nuevoDestinatario([
    'nombreRazon' => 'Cliente S.A.',
    'nif'         => '39707287H',
]);

// 3. Build the tax breakdown (21 % IVA on a €100 base).
$desglose = $client->nuevoDesglose([
    'impuesto'                       => 1,
    'tipoImpositivo'                 => 21.0,
    'baseImponibleOImporteNoSujeto'  => 100.0,
    'cuotaRepercutida'               => 21.0,
]);

// 4. Compose all three into a registration record.
$registro = $client->nuevoRegistroAlta(
    [
        'emisor'        => $emisor,
        'destinatario'  => $destinatario,
        'desglose'      => $desglose,
    ],
    [
        'numSerieFactura'        => 'FAC/2024-001',
        'fechaExpedicionFactura' => '2024-12-01',
        'tipoFactura'            => 'F1',
        'cuotaTotal'             => 21.0,
        'importeTotal'           => 121.0,
    ]
);

// 5. Submit to AEAT.
$client->altaRegistroAlta($registro);
Use idValorLista(string $nombreLista, string $valorLista): int to resolve human-readable list values — such as tax type names or regime codes — into the integer IDs required by the API before passing them to a model constructor.

Model reference pages

Emisor

Invoice issuer — NIF, name, AEAT submission settings.

Destinatario

Invoice recipient — NIF or foreign identification fields.

Desglose

Tax breakdown — IVA/IGIC type, regime, rates, and amounts.

Tercero

Third-party issuer acting on behalf of the emisor.

RegistroAlta

Main invoice registration record submitted to AEAT.

RegistroAnulacion

Invoice cancellation record.

FacturaRectificada

Reference to the invoice being corrected.

FacturaSustituida

Reference to the invoice being substituted.

Build docs developers (and LLMs) love