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.

This guide walks you through the complete workflow: installing the library, instantiating the client, creating an issuer, building an invoice registration record, and submitting it to AEAT via the VeriFactuAPI. By the end you will have a working end-to-end PHP integration.

Prerequisites

  • PHP 7.4 or 8.x with Composer installed
  • A VeriFactuAPI account — register at verifactuapi.es to get your email and password credentials

Step-by-Step

1

Install the library

Add the VCS repository to your composer.json and require the package:
composer.json
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/NemonInvocash/verifactu-php"
        }
    ]
}
composer require invocash/verifactu-php
See Installation for the full details including the git clone method.
2

Instantiate the client

The constructor handles authentication automatically. It POSTs your credentials to the API and stores the Bearer token:
<?php
require 'vendor/autoload.php';

use verifactuPHP\ClienteVerifactu;

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

// Optional: enable debug output during development
$client->setDebug(true);
If authentication fails (wrong credentials, network error) the constructor throws an Exception.
3

Register an issuer

Create an Emisor object and register it with VeriFactuAPI. The issuer represents the company that will be submitting invoices.
// Build the issuer object
$emisor = $client->nuevoEmisor([
    'nif'        => 'A39200019',   // Must be a valid Spanish NIF
    'nombre'     => 'Mi Empresa S.L.',
    'enviarAeat' => true,           // Auto-submit invoices to AEAT
]);

// Register the issuer with the API
$client->altaEmisor($emisor);
The NIF must be a valid Spanish tax identification number. Invalid NIFs will be rejected by the API.
4

Build the invoice components

A RegistroAlta (invoice registration record) is composed of several objects. At minimum you need an Emisor and a Desglose (tax breakdown).
// Invoice recipient
$destinatario = $client->nuevoDestinatario([
    'nombreRazon' => 'Cliente S.A.',
    'nif'         => '39707287H',
]);

// Tax breakdown: 21% VAT on a €100 base
$desglose = $client->nuevoDesglose([
    'impuesto'                       => '01',   // IVA (lista L1)
    'claveRegimen'                   => 1,      // General regime (lista L8A)
    'tipoImpositivo'                 => 21.0,   // 21% VAT rate
    'baseImponibleOImporteNoSujeto'  => 100.0,  // Taxable base
    'cuotaRepercutida'               => 21.0,   // VAT amount
]);
5

Create and submit the RegistroAlta

Assemble the objects and data arrays, create the RegistroAlta, and submit it:
// Objects that compose the invoice
$objetos = [
    'emisor'       => $emisor,
    'destinatario' => $destinatario,
    'desglose'     => $desglose,
];

// Invoice header data
$data = [
    'numSerieFactura'        => 'AX/202412-001',
    'fechaExpedicionFactura' => '2024-12-16',
    'tipoFactura'            => 'F1',    // Standard invoice (lista L2)
    'cuotaTotal'             => 21.0,
    'importeTotal'           => 121.0,
];

// Build the record
$registroAlta = $client->nuevoRegistroAlta($objetos, $data);

// Submit to AEAT via VeriFactuAPI
$client->altaRegistroAlta($registroAlta);

echo "Invoice submitted successfully!";

Complete Example

Here is the full working example in one file, drawn from the library’s example scripts:
complete-example.php
<?php
require 'vendor/autoload.php';

use verifactuPHP\ClienteVerifactu;

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

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

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

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

    // 3. Build and submit the RegistroAlta
    $registroAlta = $client->nuevoRegistroAlta(
        ['emisor' => $emisor, 'destinatario' => $destinatario, 'desglose' => $desglose],
        [
            'numSerieFactura'        => 'AX/202412-001',
            'fechaExpedicionFactura' => '2024-12-16',
            'tipoFactura'            => 'F1',
            'cuotaTotal'             => 21.0,
            'importeTotal'           => 121.0,
        ]
    );
    $client->altaRegistroAlta($registroAlta);

    echo "Invoice submitted successfully!\n";

} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage() . "\n";
}
With setDebug(true), the library prints the Bearer token, object creation confirmations, and API responses to stdout — very useful for verifying your objects are constructed correctly before submitting to AEAT.

Next Steps

Creating Invoices

Detailed guide covering standard, simplified, and rectified invoice types.

Managing Emisores

Register and query invoice issuers with the API.

Cancelling Invoices

Cancel invoice records by ID or with a full RegistroAnulacion.

API Reference

Full reference for every ClienteVerifactu method.

Build docs developers (and LLMs) love