Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mdiago/VeriFactu/llms.txt

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

This quickstart walks you through the full onboarding flow for the VeriFactu .NET library: installing the NuGet package, pointing it at your digital certificate, building an Invoice object with tax breakdown lines, submitting it to the AEAT VERI*FACTU web service, and inspecting the response. By the end you’ll have a working end-to-end submission running against the AEAT test environment.
1

Install the package

NuGet Package Manager

Search for VeriFactu in the NuGet Package Manager UI inside Visual Studio and click Install. The package targets net461, net472, net48, netcoreapp3.1, net7.0, and net8.0.

.NET CLI

dotnet add package VeriFactu
2

Configure your certificate

Before submitting any records to the AEAT you must configure the certificate that will sign and authenticate each request. The entire library configuration is accessible through the static Settings.Current property. Call Settings.Save() to persist your changes to disk.

Load a certificate from a .pfx / .p12 file

// Valores actuales de configuración de certificado
Debug.Print($"{Settings.Current.CertificatePath}");
Debug.Print($"{Settings.Current.CertificatePassword}");

// Establezco nuevos valores
Settings.Current.CertificatePath = @"C:\CERTIFICADO.pfx";
Settings.Current.CertificatePassword = "pass certificado";

// Guardo los cambios
Settings.Save();

Load a certificate from the Windows certificate store

On Windows you can select a certificate already installed in the system store by its serial number or thumbprint (SHA-1 hash). Only one of the two properties is required.
// Seleccionar por número de serie
Settings.Current.CertificateSerial = "YOUR_CERTIFICATE_SERIAL";
Settings.Save();

// — o bien — seleccionar por huella digital (thumbprint)
Settings.Current.CertificateThumbprint = "YOUR_CERTIFICATE_THUMBPRINT";
Settings.Save();
PropertyDescription
CertificatePathPath to the .pfx / .p12 certificate file on disk.
CertificatePasswordPassword for the certificate file. Required only when CertificatePath is set and the file is password-protected.
CertificateSerialSerial number used to locate the certificate in the Windows certificate store.
CertificateThumbprintSHA-1 thumbprint (fingerprint) used to locate the certificate in the Windows certificate store.
3

Create and send an invoice

Construct an Invoice using the three-argument constructor — invoice number, issue date, and seller tax ID (NIF). Set the optional properties you need (InvoiceType, SellerName, BuyerID, etc.) and populate TaxItems with one TaxItem per VAT rate that applies to the operation.Wrap the Invoice in an InvoiceEntry and call Save(). The library will:
  1. Add the record to the seller’s local blockchain.
  2. Build and sign the VERI*FACTU XML envelope.
  3. Submit it to the AEAT web service endpoint.
  4. Persist the request and response to disk.
// Creamos una instacia de la clase factura
var invoice = new Invoice("GIT-EJ-0002", new DateTime(2024, 11, 15), "B72877814")
{
    InvoiceType = TipoFactura.F1,
    SellerName = "WEFINZ GANDIA SL",
    BuyerID = "B44531218",
    BuyerName = "WEFINZ SOLUTIONS SL",
    Text = "PRESTACION SERVICIOS DESARROLLO SOFTWARE",
    TaxItems = new List<TaxItem>() {
        new TaxItem()
        {
            TaxRate = 4,
            TaxBase = 10,
            TaxAmount = 0.4m
        },
        new TaxItem()
        {
            TaxRate = 21,
            TaxBase = 100,
            TaxAmount = 21
        }
    }
};

// Creamos la entrada de la factura
var invoiceEntry = new InvoiceEntry(invoice);

// Guardamos la factura
invoiceEntry.Save();
4

Check the response

After Save() returns, inspect the properties on invoiceEntry to determine the outcome of the submission. A successful submission sets Status to "Correcto" and populates CSV with the AEAT’s Código Seguro de Verificación. If the AEAT rejected the record, ErrorCode and ErrorDescription carry the rejection details.
// Consultamos el estado
Debug.Print($"Respuesta de la AEAT:\n{invoiceEntry.Status}");

if (invoiceEntry.Status == "Correcto")
{
    // Consultamos el CSV
    Debug.Print($"Respuesta de la AEAT:\n{invoiceEntry.CSV}");
}
else
{
    // Consultamos el error
    Debug.Print($"Respuesta de la AEAT:\n{invoiceEntry.ErrorCode}: {invoiceEntry.ErrorDescription}");
}

// Consultamos el resultado devuelto por la AEAT
Debug.Print($"Respuesta de la AEAT:\n{invoiceEntry.Response}");
PropertyTypeDescription
StatusstringOverall result returned by the AEAT ("Correcto" on success). Maps to EstadoEnvio in the VERI*FACTU response.
CSVstringCódigo Seguro de Verificación issued by the AEAT for a successful submission. null on error.
ErrorCodestringAEAT error code (CodigoErrorRegistro) or SOAP fault code when the submission fails. null on success.
ErrorDescriptionstringHuman-readable description of the error (DescripcionErrorRegistro) or SOAP fault string. null on success.
ResponsestringRaw XML response envelope returned by the AEAT web service.

VeriFactu connects to the AEAT test environment (prewww) by default — no real records are submitted and no fiscal obligations are incurred. When you are ready to go live, update Settings.Current.VeriFactuEndPointPrefix to the production endpoint. See the Settings reference for the full list of configurable endpoints and options.
During development you may encounter validation errors caused by NIF lookups against the AEAT census service. Set Settings.Current.SkipNifAeatValidation = true to bypass online NIF validation and speed up your local testing loop. Remember to disable this flag before going to production.
// Deshabilito la validación de NIF en línea con la AEAT
Settings.Current.SkipNifAeatValidation = true;

Next steps

Configurar el sistema

Explore every Settings property — storage paths, AEAT endpoints, blockchain options, and logging.

Gestión del certificado

Learn how to load certificates from a file or the Windows store, rotate them, and troubleshoot common issues.

Anular facturas

Submit cancellation records (RegistroAnulacion) for invoices previously accepted by the AEAT.

Control de flujo

Use InvoiceQueue to handle the AEAT’s mandatory inter-submission wait times and batch up to 1 000 records per call.

Build docs developers (and LLMs) love