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.

Invoice is the core business object representing a Spanish invoice in the VeriFactu system. It holds all invoice data and produces the low-level RegistroAlta and RegistroAnulacion XML objects required by AEAT.

Namespace

VeriFactu.Business

Constructores

Invoice(string invoiceID, DateTime invoiceDate, string sellerID)

Primary constructor. Creates a new invoice from its three required identifiers. Leading/trailing whitespace is trimmed from invoiceID and sellerID; sellerID is also uppercased to match AEAT hash requirements. Throws ArgumentNullException if either invoiceID or sellerID is null.
invoiceID
string
required
Invoice number / series identifier (e.g. "FAC-2024-001"). Must not be null. Whitespace is trimmed automatically.
invoiceDate
DateTime
required
Issue date of the invoice document.
sellerID
string
required
Seller’s tax identifier (NIF/VAT number). Must not be null. Whitespace is trimmed and the value is uppercased automatically.

Invoice(RegistroAlta registroAlta)

Creates an Invoice instance from an existing low-level RegistroAlta XML object (e.g. one previously deserialized from disk or received from the AEAT). All available fields — type, seller name, buyer details, tax breakdown, and rectification info — are mapped into the Invoice properties automatically.
registroAlta
RegistroAlta
required
A VeriFactu.Xml.Factu.Alta.RegistroAlta instance to reconstruct the invoice from. Throws NotImplementedException if the record has more than one buyer (Destinatarios).

Invoice(InvoiceData invoiceData)

Creates an Invoice from a plain data object (InvoiceData). Useful when invoice data is loaded from JSON or constructed programmatically via the InvoiceData DTO. Totals are calculated automatically from the contained TaxItems.
invoiceData
InvoiceData
required
A populated VeriFactu.Business.InvoiceData plain-data object.

Propiedades

InvoiceID
string
Invoice series/number identifier (e.g. "FAC-2024-001"). Set by the constructor; read-only after construction.
InvoiceDate
DateTime
Issue date of the invoice document. Set by the constructor; read-only after construction.
InvoiceType
TipoFactura
Invoice type code (list L2). Common values: F1 (standard), F2 (simplified), R1R5 (rectification), F3 (conversion of simplified). Defaults to the enum’s zero value if not set.
SellerID
string
Seller’s tax identifier (NIF/VAT number). Set by the constructor; read-only after construction.
SellerName
string
Seller’s company or personal name (NombreRazonEmisor). Required before calling Save() on an InvoiceEntry.
BuyerID
string
Buyer’s tax identifier. Use the fiscal identifier if one exists (NIF, EU VAT number, DUNS, etc.).
BuyerName
string
Buyer’s company or personal name.
BuyerCountryID
string
ISO 3166-1 alpha-2 country code for the buyer (e.g. "FR", "DE"). Required when BuyerID is not a valid Spanish identifier and BuyerIDType is not NIF_IVA.
BuyerIDType
IDType
Buyer identifier type per list L7. Required for non-Spanish buyers when BuyerCountryID is set. For EU intra-community buyers set this to IDType.NIF_IVA.
OperationDate
DateTime?
Optional operation date (FechaOperacion) when the taxable event date differs from the invoice issue date.
Text
string
Free-text description of the operation (DescripcionOperacion). Appears verbatim in the AEAT record.
TaxItems
List<TaxItem>
List of tax breakdown lines (Desglose). Maximum 12 items. Each item defines a tax rate, base, amount, scheme, and optional exemption cause. See TaxItem.
TotalAmount
decimal
Computed total invoice amount: NetAmount + TotalTaxOutput + TotalTaxOutputSurcharge − TotalTaxWithheld. Recalculated automatically whenever GetRegistroAlta() is called.
TotalTaxOutput
decimal
Sum of output tax amounts (CuotaRepercutida) across all TaxOutput tax items.
TotalTaxOutputSurcharge
decimal
Sum of equivalence surcharge amounts (CuotaRecargoEquivalencia) across all TaxOutput tax items.
TotalTaxWithheld
decimal
Sum of withheld tax amounts across all TaxWithheld tax items.
RectificationType
TipoRectificativa
Rectification method (list L3): S (substitution) or I (differences). Only relevant when InvoiceType is R1R5. Defaults to I when the invoice is rectificative and this field is left at its default.
RectificationItems
List<RectificationItem>
References to the original invoices being rectified or substituted (FacturasRectificadas / FacturasSustituidas). Each item holds an InvoiceID and InvoiceDate. Maximum 1 000 items.
RectificationTaxBase
decimal
BaseRectificada for substitution-type (S) rectifications. Only used when RectificationType == S and RectificationTaxBase != 0.
RectificationTaxAmount
decimal
CuotaRectificada for substitution-type rectifications.
RectificationTaxAmountSurcharge
decimal
CuotaRecargoRectificado for substitution-type rectifications.
RegistroAltaSource
RegistroAlta
The original RegistroAlta from which this invoice was created, if the Invoice(RegistroAlta) constructor was used. null otherwise. When non-null, GetRegistroAlta() returns this object directly without rebuilding it.
ServiceKey
string
REST API access key for the Irene Solutions VeriFactu REST service. Inherited from JsonSerializable. Set this when using the Irene Solutions hosted REST endpoint. Obtain your key at https://facturae.irenesolutions.com/verifactu/go.

Métodos

GetRegistroAlta()RegistroAlta

Builds and returns the VeriFactu.Xml.Factu.Alta.RegistroAlta low-level XML record. All totals are recalculated, monetary values are rounded to 2 decimal places, and all AEAT-required fields (blockchain hash type, system info, etc.) are populated from global settings. If the instance was created via Invoice(RegistroAlta), the cached source record is returned directly. Throws InvalidOperationException if TaxItems is empty or null (no Desglose block can be built).

GetRegistroAnulacion()RegistroAnulacion

Builds and returns the VeriFactu.Xml.Factu.Anulacion.RegistroAnulacion low-level XML record used to cancel the invoice. Only InvoiceID, InvoiceDate, and SellerID are needed — the full tax breakdown is not required for cancellations.

ToJson()string

Serializes the invoice data to a JSON string via the underlying InvoiceData object. Useful for logging, persistence, or REST API integration.

ToString()string

Returns a human-readable identifier in the format "SellerID-InvoiceID-Date" where date is formatted as dd-MM-yyyy (via XmlParser.GetXmlDate), e.g. "B72877814-FAC-2024-001-15-11-2024".

Ejemplo

using VeriFactu.Business;
using VeriFactu.Xml.Factu;
using VeriFactu.Xml.Factu.Alta;

var invoice = new Invoice("FAC-2024-001", new DateTime(2024, 11, 15), "B72877814")
{
    InvoiceType  = TipoFactura.F1,
    SellerName   = "MI EMPRESA SL",
    BuyerID      = "B44531218",
    BuyerName    = "CLIENTE SL",
    Text         = "SERVICIOS PROFESIONALES",
    TaxItems     = new List<TaxItem>
    {
        new TaxItem
        {
            TaxScheme = ClaveRegimen.RegimenGeneral,
            TaxType   = CalificacionOperacion.S1,
            TaxRate   = 21,
            TaxBase   = 1000,
            TaxAmount = 210
        }
    }
};

// Build the low-level AEAT XML record
RegistroAlta registroAlta = invoice.GetRegistroAlta();

// Submit to AEAT
var entry = new InvoiceEntry(invoice);
entry.Save();
Console.WriteLine(entry.Status); // "Correcto"

Build docs developers (and LLMs) love