Documentation
¶
Overview ¶
Package verifactu provides the VeriFactu client
Index ¶
- Constants
- Variables
- func SignDocument(doc any, cert *xmldsig.Certificate, opts ...xmldsig.Option) (*xmldsig.Signature, error)
- type AggregatedEventType
- type ChainData
- type Client
- func (c *Client) CancelInvoice(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceCancellation, error)
- func (c *Client) CurrentTime() time.Time
- func (c *Client) NewEnvelopeInvoiceRequest(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceRequest, error)
- func (c *Client) NewInvoiceRequest(supplier *org.Party) (*InvoiceRequest, error)
- func (c *Client) RegisterEvent(env *gobl.Envelope, prev *EventChainData, opts ...GenerateOption) (*EventRegistration, error)
- func (c *Client) RegisterInvoice(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceRegistration, error)
- func (c *Client) Sandbox() bool
- func (c *Client) SendInvoiceRequest(ctx context.Context, ir *InvoiceRequest) (*InvoiceResponse, error)
- type Desglose
- type Destinatario
- type DetalleDesglose
- type Encadenamiento
- type Envelope
- type EnvelopeResponse
- type Environment
- type Error
- type Event
- type EventAnomalyDetection
- type EventAnomalyDetectionLaunch
- type EventChainData
- type EventChaining
- type EventData
- type EventExportPeriod
- type EventInvoiceRecord
- type EventInvoiceRecordWithFingerprint
- type EventIssuer
- type EventOtherID
- type EventParty
- type EventRecord
- type EventRegistration
- type EventSoftware
- type EventSummary
- type FacturaRectificada
- type FacturaSustituida
- type FacturasRectificadas
- type FacturasSustituidas
- type Fault
- type GenerateOption
- type IDFactura
- type IDFacturaAnulada
- type IDOtro
- type ImporteRectificacion
- type InvoiceAnomalyDetection
- type InvoiceAnomalyDetectionLaunch
- type InvoiceCancellation
- type InvoiceExportPeriod
- type InvoiceRegistration
- type InvoiceRequest
- type InvoiceRequestHeader
- type InvoiceRequestLine
- type InvoiceResponse
- type InvoiceResponseIssuer
- type InvoiceResponseLine
- type InvoiceResponseLineDuplicated
- type InvoiceResponseVoluntarySubmission
- type Issuer
- type OpType
- type Option
- type Party
- type PreviousEvent
- type Record
- type RegistroAnterior
- type RemisionVoluntaria
- type Software
Constants ¶
const ( EnvironmentProduction Environment = "production" EnvironmentSandbox Environment = "sandbox" BaseURLProduction = "https://www1.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" BaseURLProductionWithSeal = "https://www10.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" BaseURLTesting = "https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" BaseURLTestingWithSeal = "https://prewww10.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP" )
Environment to use for connections
const ( SUM = "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/SuministroLR.xsd" SUM1 = "" /* 130-byte string literal not displayed */ DS = "http://www.w3.org/2000/09/xmldsig#" EnvNamespace = "http://schemas.xmlsoap.org/soap/envelope/" )
VeriFactu XML namespace constants
const ( StatusCorrect string = "Correcto" StatusAcceptedWithErrors string = "AceptadoConErrores" StatusCancelled string = "Anulada" StatusIncorrect string = "Incorrecto" )
Default response status
const (
// CurrentVersion is the current version of the VeriFactu document
CurrentVersion = "1.0"
)
const FingerprintType = "01"
FingerprintType is the SHA-256 fingerprint type for Verifactu - L12. Might include support for other encryption types in the future.
const (
SF = "https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/aplicaciones/es/aeat/tike/cont/ws/EventosSIF.xsd"
)
XML namespaces
const ( // StampKeyHash defines the key used to store the Hash in the envelope // stamps. StampKeyHash cbc.Key = "verifactu-hash" )
Variables ¶
var ( // ErrConnection is used when the gateway could not be reached or gave a // response we're unable to understand. ErrConnection = newError("connection") // ErrValidation implies there is something wrong with the contents of the // request that needs to be fixed before sending it again. ErrValidation = newError("validation") // ErrDuplicate is used when the gateway has already received the request. ErrDuplicate = newError("duplicate") // ErrWarning means the request was accepted, but the gateway reported // issues that should be reviewed. ErrWarning = newError("warning") // ErrServer indicates the gateway had an internal problem handling the // request, which may succeed if attempted again later. ErrServer = newError("server") )
Standard gateway error responses
var ( ErrNotSpanish = ErrValidation.WithMessage("only spanish invoices are supported") ErrAlreadyProcessed = ErrValidation.WithMessage("already processed") ErrOnlyInvoices = ErrValidation.WithMessage("only invoices are supported") ErrOnlyStatuses = ErrValidation.WithMessage("only bill status documents are supported") ErrOnlyRecords = ErrValidation.WithMessage("only invoice registration, invoice cancellation and event records are supported") ErrIncompleteRecord = ErrValidation.WithMessage("record is missing the details its fingerprint is computed from") )
Standard error responses.
Functions ¶
func SignDocument ¶
func SignDocument(doc any, cert *xmldsig.Certificate, opts ...xmldsig.Option) (*xmldsig.Signature, error)
SignDocument signs any XML-marshalable struct using the VeriFactu XAdES configuration. It can be used to sign registration, cancellation, and event records (or any other document type) with the provided certificate.
Types ¶
type AggregatedEventType ¶
type AggregatedEventType struct {
EventType string `xml:"sf:TipoEvento"`
EventCount string `xml:"sf:NumeroDeEventos"`
}
AggregatedEventType represents an aggregated event type count (TipoEventoAgrType).
type ChainData ¶
type ChainData struct {
IDIssuer string `json:"issuer"`
NumSeries string `json:"num_series"`
IssueDate string `json:"issue_date"`
Fingerprint string `json:"fingerprint"`
}
ChainData contains the fields of this invoice that will be required for fingerprinting the _next_ invoice. JSON tags are provided to help with serialization.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides the main interface to the VeriFactu package.
func New ¶
New creates a new VeriFactu client with shared software and configuration options for creating and sending new documents.
func (*Client) CancelInvoice ¶
func (c *Client) CancelInvoice(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceCancellation, error)
CancelInvoice builds a cancellation message from the provided document and previous chain data. Note that the cancellation does not require Hash information of the last, invoice, and instead only requires the previous chain entry.
func (*Client) CurrentTime ¶
CurrentTime returns the current time to use when generating the VeriFactu document.
func (*Client) NewEnvelopeInvoiceRequest ¶
func (c *Client) NewEnvelopeInvoiceRequest(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceRequest, error)
NewEnvelopeInvoiceRequest is a convenience method that prepares a new InvoiceRequest from the GOBL envelope in a single method call.
func (*Client) NewInvoiceRequest ¶
func (c *Client) NewInvoiceRequest(supplier *org.Party) (*InvoiceRequest, error)
NewInvoiceRequest prepares a new invoice request for the provided supplier.
func (*Client) RegisterEvent ¶
func (c *Client) RegisterEvent(env *gobl.Envelope, prev *EventChainData, opts ...GenerateOption) (*EventRegistration, error)
RegisterEvent prepares a new event registration document from the provided bill status inside the GOBL envelope. It will fingerprint and optionally sign the event. The resulting document can be persisted locally.
func (*Client) RegisterInvoice ¶
func (c *Client) RegisterInvoice(env *gobl.Envelope, prev *ChainData, opts ...GenerateOption) (*InvoiceRegistration, error)
RegisterInvoice prepares a new registration document from the provided invoice inside the GOBL envelope. It will fingerprint and update the registration with the chaining hash and QR code. The resulting document can be persisted for sending later.
func (*Client) SendInvoiceRequest ¶
func (c *Client) SendInvoiceRequest(ctx context.Context, ir *InvoiceRequest) (*InvoiceResponse, error)
SendInvoiceRequest will prepare the final SOAP envelope with the invoice request data and send it the agency API.
type Desglose ¶
type Desglose struct {
DetalleDesglose []*DetalleDesglose `xml:"sum1:DetalleDesglose"`
}
Desglose contains the breakdown details
type Destinatario ¶
type Destinatario struct {
IDDestinatario *Party `xml:"sum1:IDDestinatario"`
}
Destinatario represents a recipient in the document
type DetalleDesglose ¶
type DetalleDesglose struct {
Impuesto string `xml:"sum1:Impuesto,omitempty"`
ClaveRegimen string `xml:"sum1:ClaveRegimen,omitempty"`
CalificacionOperacion string `xml:"sum1:CalificacionOperacion,omitempty"`
OperacionExenta string `xml:"sum1:OperacionExenta,omitempty"`
TipoImpositivo string `xml:"sum1:TipoImpositivo,omitempty"`
BaseImponibleOImporteNoSujeto string `xml:"sum1:BaseImponibleOimporteNoSujeto"`
BaseImponibleACoste string `xml:"sum1:BaseImponibleACoste,omitempty"`
CuotaRepercutida string `xml:"sum1:CuotaRepercutida,omitempty"`
TipoRecargoEquivalencia string `xml:"sum1:TipoRecargoEquivalencia,omitempty"`
CuotaRecargoEquivalencia string `xml:"sum1:CuotaRecargoEquivalencia,omitempty"`
}
DetalleDesglose contains detailed breakdown information
type Encadenamiento ¶
type Encadenamiento struct {
PrimerRegistro string `xml:"sum1:PrimerRegistro,omitempty"`
RegistroAnterior *RegistroAnterior `xml:"sum1:RegistroAnterior,omitempty"`
}
Encadenamiento contains chaining information between invoice documents
type Envelope ¶
type Envelope struct {
XMLName xml.Name `xml:"soapenv:Envelope"`
XMLNs string `xml:"xmlns:soapenv,attr"`
SUM string `xml:"xmlns:sum,attr,omitempty"`
SUM1 string `xml:"xmlns:sum1,attr,omitempty"`
DS string `xml:"xmlns:ds,attr,omitempty"`
Body struct {
ID string `xml:"soapenv:Id,attr,omitempty"`
InvoiceRequest *InvoiceRequest `xml:"sum:RegFactuSistemaFacturacion,omitempty"`
} `xml:"soapenv:Body"`
}
Envelope is the SOAP envelope wrapper used for sending messages to the remote service.
func (*Envelope) BytesIndent ¶
BytesIndent returns the indented XML document bytes
type EnvelopeResponse ¶
type EnvelopeResponse struct {
XMLName xml.Name `xml:"Envelope"`
Body struct {
ID string `xml:"Id,attr,omitempty"`
Fault *Fault `xml:"Fault,omitempty"`
InvoiceResponse *InvoiceResponse `xml:"RespuestaRegFactuSistemaFacturacion,omitempty"`
} `xml:"Body"`
}
EnvelopeResponse handles a SOAP response object that will correctly handle the namespaces.
type Environment ¶
type Environment string
Environment defines the environment to use for connections
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error allows for structured responses from the gateway to be able to response codes and messages.
func (*Error) Is ¶
Is checks to see if the target error is the same as the current one or forms part of the chain.
func (*Error) WithMessage ¶
WithMessage duplicates and adds the message to the error.
type Event ¶
type Event struct {
Software *EventSoftware `xml:"sf:SistemaInformatico"`
Issuer *EventIssuer `xml:"sf:ObligadoEmision"`
IssuedByThirdPartyOrRecipient string `xml:"sf:EmitidaPorTerceroODestinatario,omitempty"`
ThirdPartyOrRecipient *EventParty `xml:"sf:TerceroODestinatario,omitempty"`
GenerationTimestamp string `xml:"sf:FechaHoraHusoGenEvento"`
EventType string `xml:"sf:TipoEvento"`
EventData *EventData `xml:"sf:DatosPropiosEvento,omitempty"`
OtherEventData string `xml:"sf:OtrosDatosEvento,omitempty"`
Chaining *EventChaining `xml:"sf:Encadenamiento"`
FingerprintType string `xml:"sf:TipoHuella"`
Fingerprint string `xml:"sf:HuellaEvento"`
Signature *xmldsig.Signature `xml:"ds:Signature,omitempty"`
}
Event contains the event data (EventoType).
func (*Event) ChainData ¶
func (e *Event) ChainData() *EventChainData
ChainData returns the chaining data from this event for use when fingerprinting the next event in the chain.
type EventAnomalyDetection ¶
type EventAnomalyDetection struct {
AnomalyType string `xml:"sf:TipoAnomalia"`
OtherAnomalyData string `xml:"sf:OtrosDatosAnomalia,omitempty"`
AnomalousEvent *EventRecord `xml:"sf:RegEventoAnomalo,omitempty"`
}
EventAnomalyDetection contains data for a detected anomaly in event registration records.
type EventAnomalyDetectionLaunch ¶
type EventAnomalyDetectionLaunch struct {
FingerprintCheck string `xml:"sf:RealizadoProcesoSobreIntegridadHuellasRegEvento"`
FingerprintCount string `xml:"sf:NumeroDeRegistrosEventoProcesadosSobreIntegridadHuellas,omitempty"`
SignatureCheck string `xml:"sf:RealizadoProcesoSobreIntegridadFirmasRegEvento"`
SignatureCount string `xml:"sf:NumeroDeRegistrosEventoProcesadosSobreIntegridadFirmas,omitempty"`
ChainCheck string `xml:"sf:RealizadoProcesoSobreTrazabilidadCadenaRegEvento"`
ChainCount string `xml:"sf:NumeroDeRegistrosEventoProcesadosSobreTrazabilidadCadena,omitempty"`
DateCheck string `xml:"sf:RealizadoProcesoSobreTrazabilidadFechasRegEvento"`
DateCount string `xml:"sf:NumeroDeRegistrosEventoProcesadosSobreTrazabilidadFechas,omitempty"`
}
EventAnomalyDetectionLaunch contains data for launching the anomaly detection process on event registration records.
type EventChainData ¶
type EventChainData struct {
EventType string `json:"event_type"`
GenerationTimestamp string `json:"generation_timestamp"`
Fingerprint string `json:"fingerprint"`
}
EventChainData contains the fields of this event that will be required for fingerprinting the _next_ event. JSON tags are provided to help with serialization.
type EventChaining ¶
type EventChaining struct {
FirstEvent string `xml:"sf:PrimerEvento,omitempty"`
PreviousEvent *PreviousEvent `xml:"sf:EventoAnterior,omitempty"`
}
EventChaining contains chaining information between event registrations
type EventData ¶
type EventData struct {
InvoiceAnomalyDetectionLaunch *InvoiceAnomalyDetectionLaunch `xml:"sf:LanzamientoProcesoDeteccionAnomaliasRegFacturacion,omitempty"`
InvoiceAnomalyDetection *InvoiceAnomalyDetection `xml:"sf:DeteccionAnomaliasRegFacturacion,omitempty"`
EventAnomalyDetectionLaunch *EventAnomalyDetectionLaunch `xml:"sf:LanzamientoProcesoDeteccionAnomaliasRegEvento,omitempty"`
EventAnomalyDetection *EventAnomalyDetection `xml:"sf:DeteccionAnomaliasRegEvento,omitempty"`
InvoiceExportPeriod *InvoiceExportPeriod `xml:"sf:ExportacionRegFacturacionPeriodo,omitempty"`
EventExportPeriod *EventExportPeriod `xml:"sf:ExportacionRegEventoPeriodo,omitempty"`
EventSummary *EventSummary `xml:"sf:ResumenEventos,omitempty"`
}
EventData contains event-specific data (DatosPropiosEventoType). Only one of the fields should be set at a time (choice).
type EventExportPeriod ¶
type EventExportPeriod struct {
PeriodStart string `xml:"sf:FechaHoraHusoInicioPeriodoExport"`
PeriodEnd string `xml:"sf:FechaHoraHusoFinPeriodoExport"`
FirstEventRecord *EventRecord `xml:"sf:RegistroEventoInicialPeriodo"`
LastEventRecord *EventRecord `xml:"sf:RegistroEventoFinalPeriodo"`
EventRecordCount string `xml:"sf:NumeroDeRegEventoExportados"`
ExportedRecordsDiscarded string `xml:"sf:RegEventoExportadosDejanDeConservarse"`
}
EventExportPeriod contains data about an export of event registration records for a given period.
type EventInvoiceRecord ¶
type EventInvoiceRecord struct {
IssuerNIF string `xml:"sf:IDEmisorFactura"`
InvoiceNumber string `xml:"sf:NumSerieFactura"`
IssueDate string `xml:"sf:FechaExpedicionFactura"`
}
EventInvoiceRecord identifies an issued invoice (IDFacturaExpedidaType) in the events namespace.
type EventInvoiceRecordWithFingerprint ¶
type EventInvoiceRecordWithFingerprint struct {
IssuerNIF string `xml:"sf:IDEmisorFactura"`
InvoiceNumber string `xml:"sf:NumSerieFactura"`
IssueDate string `xml:"sf:FechaExpedicionFactura"`
Fingerprint string `xml:"sf:Huella"`
}
EventInvoiceRecordWithFingerprint identifies an issued invoice with its fingerprint (IDFacturaExpedidaHuellaType) in the events namespace.
type EventIssuer ¶
EventIssuer represents a Spanish person or entity obligated to issue invoices (PersonaFisicaJuridicaESType) in the events namespace.
type EventOtherID ¶
type EventOtherID struct {
CountryCode string `xml:"sf:CodigoPais,omitempty"`
IDType string `xml:"sf:IDType"`
ID string `xml:"sf:ID"`
}
EventOtherID contains alternative identification for non-NIF entities (IDOtroType) in the events namespace.
type EventParty ¶
type EventParty struct {
Name string `xml:"sf:NombreRazon"`
NIF string `xml:"sf:NIF,omitempty"`
IDOther *EventOtherID `xml:"sf:IDOtro,omitempty"`
}
EventParty represents a person or entity that may be Spanish or foreign (PersonaFisicaJuridicaType) in the events namespace.
type EventRecord ¶
type EventRecord struct {
EventType string `xml:"sf:TipoEvento"`
EventTimestamp string `xml:"sf:FechaHoraHusoEvento"`
Fingerprint string `xml:"sf:HuellaEvento"`
}
EventRecord identifies an event registration record (RegEventoType).
type EventRegistration ¶
type EventRegistration struct {
XMLName xml.Name `xml:"sf:RegistroEvento"`
SF string `xml:"xmlns:sf,attr,omitempty"`
Version string `xml:"sf:IDVersion"`
Event *Event `xml:"sf:Evento"`
}
EventRegistration represents the root element of a RegistroEvento document.
func (*EventRegistration) Bytes ¶
func (r *EventRegistration) Bytes() ([]byte, error)
Bytes prepares an XML document suitable for persistence. Signed documents use compact XML to preserve the enveloped signature.
func (*EventRegistration) BytesIndent ¶ added in v0.43.0
func (r *EventRegistration) BytesIndent() ([]byte, error)
BytesIndent returns the indented XML document bytes, which breaks the signature of a signed document.
func (*EventRegistration) ChainData ¶
func (r *EventRegistration) ChainData() *EventChainData
ChainData returns the chaining data from the inner event.
type EventSoftware ¶
type EventSoftware struct {
Name string `xml:"sf:NombreRazon"`
NIF string `xml:"sf:NIF,omitempty"`
IDOther *EventOtherID `xml:"sf:IDOtro,omitempty"`
SoftwareName string `xml:"sf:NombreSistemaInformatico,omitempty"`
SoftwareID string `xml:"sf:IdSistemaInformatico"`
Version string `xml:"sf:Version"`
InstallationNumber string `xml:"sf:NumeroInstalacion"`
OnlyVerifactu string `xml:"sf:TipoUsoPosibleSoloVerifactu,omitempty"`
MultiOT string `xml:"sf:TipoUsoPosibleMultiOT,omitempty"`
MultipleOT string `xml:"sf:IndicadorMultiplesOT,omitempty"`
}
EventSoftware contains the details about the software system that generated the event (SistemaInformaticoType).
type EventSummary ¶
type EventSummary struct {
EventTypes []*AggregatedEventType `xml:"sf:TipoEvento"`
FirstInvoiceRecord *EventInvoiceRecordWithFingerprint `xml:"sf:RegistroFacturacionInicialPeriodo,omitempty"`
LastInvoiceRecord *EventInvoiceRecordWithFingerprint `xml:"sf:RegistroFacturacionFinalPeriodo,omitempty"`
RegistrationRecordCount string `xml:"sf:NumeroDeRegistrosFacturacionAltaGenerados"`
TotalTaxSum string `xml:"sf:SumaCuotaTotalAlta"`
TotalAmountSum string `xml:"sf:SumaImporteTotalAlta"`
CancellationRecordCount string `xml:"sf:NumeroDeRegistrosFacturacionAnulacionGenerados"`
}
EventSummary contains a summary of events (ResumenEventosType).
type FacturaRectificada ¶
type FacturaRectificada struct {
IDEmisorFactura string `xml:"sum1:IDEmisorFactura"`
NumSerieFactura string `xml:"sum1:NumSerieFactura"`
FechaExpedicionFactura string `xml:"sum1:FechaExpedicionFactura"`
}
FacturaRectificada represents a rectified invoice
type FacturaSustituida ¶
type FacturaSustituida struct {
IDEmisorFactura string `xml:"sum1:IDEmisorFactura"`
NumSerieFactura string `xml:"sum1:NumSerieFactura"`
FechaExpedicionFactura string `xml:"sum1:FechaExpedicionFactura"`
}
FacturaSustituida represents a substituted invoice
type FacturasRectificadas ¶
type FacturasRectificadas struct {
Items []*FacturaRectificada `xml:"sum1:IDFacturaRectificada"`
}
FacturasRectificadas is a wrapper for multiple rectified invoices
type FacturasSustituidas ¶
type FacturasSustituidas struct {
Items []*FacturaSustituida `xml:"sum1:IDFacturaSustituida"`
}
FacturasSustituidas is a wrapper for multiple substituted invoices
type Fault ¶
Fault is issued by the SOAP server when something goes wrong.
func (*Fault) Err ¶
Err converts the fault into a structured error that the consumer can use to determine how the issue should be handled.
func (*Fault) ErrorCode ¶
ErrorCode provides the VeriFactu error code of the fault, if one could be extracted from the fault string.
func (*Fault) ErrorMessage ¶
ErrorMessage provides the fault string without the error code prefix and with any indentation reduced to single spaces.
type GenerateOption ¶
type GenerateOption func(*generateOptions)
GenerateOption defines what is expected from an option used in generate methods.
func Amended ¶
func Amended() GenerateOption
Amended indicates that the incoming document is an amendment of a previous document, known in Spanish as "Subsanación". If incorrect data was sent, this will allow the new document to replace the old.
func NoPriorRecord ¶
func NoPriorRecord() GenerateOption
NoPriorRecord is used with cancellation documents when no previous attempt was made to issue an invoice via Verifactu, or if the document to cancel was rejected.
func PreviouslyRejected ¶
func PreviouslyRejected() GenerateOption
PreviouslyRejected indicates that an earlier attempt to process the document was rejected and thus never received by the verifactu system. This option automatically implies the Amended option when supported by the document.
func WithInstallationNumber ¶
func WithInstallationNumber(code string) GenerateOption
WithInstallationNumber is used to override the installation number defined in the connection configuration while generating the invoice.
type IDFactura ¶
type IDFactura struct {
IDEmisorFactura string `xml:"sum1:IDEmisorFactura"`
NumSerieFactura string `xml:"sum1:NumSerieFactura"`
FechaExpedicionFactura string `xml:"sum1:FechaExpedicionFactura"`
}
IDFactura contains the identifying information for an invoice
type IDFacturaAnulada ¶
type IDFacturaAnulada struct {
IDEmisorFactura string `xml:"sum1:IDEmisorFacturaAnulada"`
NumSerieFactura string `xml:"sum1:NumSerieFacturaAnulada"`
FechaExpedicionFactura string `xml:"sum1:FechaExpedicionFacturaAnulada"`
}
IDFacturaAnulada contains the identifying information for an invoice
type IDOtro ¶
type IDOtro struct {
CodigoPais string `xml:"sum1:CodigoPais"`
IDType string `xml:"sum1:IDType"`
ID string `xml:"sum1:ID"`
}
IDOtro contains alternative identifying information
type ImporteRectificacion ¶
type ImporteRectificacion struct {
BaseRectificada num.Amount `xml:"sum1:BaseRectificada"`
CuotaRectificada num.Amount `xml:"sum1:CuotaRectificada"`
CuotaRecargoRectificado num.Amount `xml:"sum1:CuotaRecargoRectificado,omitempty"`
}
ImporteRectificacion contains rectification amounts
type InvoiceAnomalyDetection ¶
type InvoiceAnomalyDetection struct {
AnomalyType string `xml:"sf:TipoAnomalia"`
OtherAnomalyData string `xml:"sf:OtrosDatosAnomalia,omitempty"`
AnomalousInvoice *EventInvoiceRecord `xml:"sf:RegistroFacturacionAnomalo,omitempty"`
}
InvoiceAnomalyDetection contains data for a detected anomaly in invoice registration records.
type InvoiceAnomalyDetectionLaunch ¶
type InvoiceAnomalyDetectionLaunch struct {
FingerprintCheck string `xml:"sf:RealizadoProcesoSobreIntegridadHuellasRegFacturacion"`
FingerprintCount string `xml:"sf:NumeroDeRegistrosFacturacionProcesadosSobreIntegridadHuellas,omitempty"`
SignatureCheck string `xml:"sf:RealizadoProcesoSobreIntegridadFirmasRegFacturacion"`
SignatureCount string `xml:"sf:NumeroDeRegistrosFacturacionProcesadosSobreIntegridadFirmas,omitempty"`
ChainCheck string `xml:"sf:RealizadoProcesoSobreTrazabilidadCadenaRegFacturacion"`
ChainCount string `xml:"sf:NumeroDeRegistrosFacturacionProcesadosSobreTrazabilidadCadena,omitempty"`
DateCheck string `xml:"sf:RealizadoProcesoSobreTrazabilidadFechasRegFacturacion"`
DateCount string `xml:"sf:NumeroDeRegistrosFacturacionProcesadosSobreTrazabilidadFechas,omitempty"`
}
InvoiceAnomalyDetectionLaunch contains data for launching the anomaly detection process on invoice registration records.
type InvoiceCancellation ¶
type InvoiceCancellation struct {
XMLName xml.Name `xml:"sum1:RegistroAnulacion"`
SUM1 string `xml:"xmlns:sum1,attr,omitempty"`
IDVersion string `xml:"sum1:IDVersion"`
IDFactura *IDFacturaAnulada `xml:"sum1:IDFactura"`
RefExterna string `xml:"sum1:RefExterna,omitempty"`
SinRegistroPrevio string `xml:"sum1:SinRegistroPrevio,omitempty"`
RechazoPrevio string `xml:"sum1:RechazoPrevio,omitempty"`
GeneradoPor string `xml:"sum1:GeneradoPor,omitempty"`
Generador *Party `xml:"sum1:Generador,omitempty"`
Encadenamiento *Encadenamiento `xml:"sum1:Encadenamiento"`
SistemaInformatico *Software `xml:"sum1:SistemaInformatico"`
FechaHoraHusoGenRegistro string `xml:"sum1:FechaHoraHusoGenRegistro"`
TipoHuella string `xml:"sum1:TipoHuella"`
Huella string `xml:"sum1:Huella"`
Signature *xmldsig.Signature `xml:"ds:Signature,omitempty"`
}
InvoiceCancellation contains the details of an invoice cancellation
func (*InvoiceCancellation) Bytes ¶
func (c *InvoiceCancellation) Bytes() ([]byte, error)
Bytes prepares an XML document suitable for persistence. Signed documents use compact XML to preserve the enveloped signature.
func (*InvoiceCancellation) BytesIndent ¶ added in v0.43.0
func (c *InvoiceCancellation) BytesIndent() ([]byte, error)
BytesIndent returns the indented XML document bytes, which breaks the signature of a signed document.
func (*InvoiceCancellation) ChainData ¶
func (c *InvoiceCancellation) ChainData() *ChainData
ChainData provides the details for this cancellation entry.
type InvoiceExportPeriod ¶
type InvoiceExportPeriod struct {
PeriodStart string `xml:"sf:FechaHoraHusoInicioPeriodoExport"`
PeriodEnd string `xml:"sf:FechaHoraHusoFinPeriodoExport"`
FirstInvoiceRecord *EventInvoiceRecordWithFingerprint `xml:"sf:RegistroFacturacionInicialPeriodo"`
LastInvoiceRecord *EventInvoiceRecordWithFingerprint `xml:"sf:RegistroFacturacionFinalPeriodo"`
RegistrationRecordCount string `xml:"sf:NumeroDeRegistrosFacturacionAltaExportados"`
TotalTaxSum string `xml:"sf:SumaCuotaTotalAlta"`
TotalAmountSum string `xml:"sf:SumaImporteTotalAlta"`
CancellationRecordCount string `xml:"sf:NumeroDeRegistrosFacturacionAnulacionExportados"`
ExportedRecordsDiscarded string `xml:"sf:RegistrosFacturacionExportadosDejanDeConservarse"`
}
InvoiceExportPeriod contains data about an export of invoice registration records for a given period.
type InvoiceRegistration ¶
type InvoiceRegistration struct {
XMLName xml.Name `xml:"sum1:RegistroAlta"`
SUM1 string `xml:"xmlns:sum1,attr,omitempty"`
IDVersion string `xml:"sum1:IDVersion"`
IDFactura *IDFactura `xml:"sum1:IDFactura"`
RefExterna string `xml:"sum1:RefExterna,omitempty"`
NombreRazonEmisor string `xml:"sum1:NombreRazonEmisor"`
Subsanacion string `xml:"sum1:Subsanacion,omitempty"`
RechazoPrevio string `xml:"sum1:RechazoPrevio,omitempty"`
TipoFactura string `xml:"sum1:TipoFactura"`
TipoRectificativa string `xml:"sum1:TipoRectificativa,omitempty"`
FacturasRectificadas *FacturasRectificadas `xml:"sum1:FacturasRectificadas,omitempty"`
FacturasSustituidas *FacturasSustituidas `xml:"sum1:FacturasSustituidas,omitempty"`
ImporteRectificacion *ImporteRectificacion `xml:"sum1:ImporteRectificacion,omitempty"`
FechaOperacion string `xml:"sum1:FechaOperacion,omitempty"`
DescripcionOperacion string `xml:"sum1:DescripcionOperacion"`
FacturaSimplificadaArt7273 string `xml:"sum1:FacturaSimplificadaArt7273,omitempty"`
FacturaSinIdentifDestinatarioArt61d string `xml:"sum1:FacturaSinIdentifDestinatarioArt61d,omitempty"`
Macrodato string `xml:"sum1:Macrodato,omitempty"`
EmitidaPorTerceroODestinatario string `xml:"sum1:EmitidaPorTerceroODestinatario,omitempty"`
Tercero *Party `xml:"sum1:Tercero,omitempty"`
Destinatarios []*Destinatario `xml:"sum1:Destinatarios,omitempty"`
Cupon string `xml:"sum1:Cupon,omitempty"`
Desglose *Desglose `xml:"sum1:Desglose"`
CuotaTotal num.Amount `xml:"sum1:CuotaTotal"`
ImporteTotal num.Amount `xml:"sum1:ImporteTotal"`
Encadenamiento *Encadenamiento `xml:"sum1:Encadenamiento"`
SistemaInformatico *Software `xml:"sum1:SistemaInformatico"`
FechaHoraHusoGenRegistro string `xml:"sum1:FechaHoraHusoGenRegistro"`
NumRegistroAcuerdoFacturacion string `xml:"sum1:NumRegistroAcuerdoFacturacion,omitempty"`
IdAcuerdoSistemaInformatico string `xml:"sum1:IdAcuerdoSistemaInformatico,omitempty"` //nolint:revive,staticcheck
TipoHuella string `xml:"sum1:TipoHuella"`
Huella string `xml:"sum1:Huella"`
Signature *xmldsig.Signature `xml:"ds:Signature,omitempty"`
}
InvoiceRegistration contains the details of an invoice registration
func (*InvoiceRegistration) Bytes ¶
func (r *InvoiceRegistration) Bytes() ([]byte, error)
Bytes prepares an XML document suitable for persistence. Signed documents use compact XML to preserve the enveloped signature.
func (*InvoiceRegistration) BytesIndent ¶ added in v0.43.0
func (r *InvoiceRegistration) BytesIndent() ([]byte, error)
BytesIndent returns the indented XML document bytes, which breaks the signature of a signed document.
func (*InvoiceRegistration) ChainData ¶
func (r *InvoiceRegistration) ChainData() *ChainData
ChainData provides the details for this registration entry.
type InvoiceRequest ¶
type InvoiceRequest struct {
XMLName xml.Name `xml:"sum:RegFactuSistemaFacturacion"`
Header *InvoiceRequestHeader `xml:"sum:Cabecera"`
Lines []*InvoiceRequestLine `xml:"sum:RegistroFactura,omitempty"`
}
InvoiceRequest represents the root element of a RegFactuSistemaFacturacion document
func (*InvoiceRequest) AddCancellation ¶
func (req *InvoiceRequest) AddCancellation(d *InvoiceCancellation)
AddCancellation adds the requested document to the request body.
func (*InvoiceRequest) AddRegistration ¶
func (req *InvoiceRequest) AddRegistration(d *InvoiceRegistration)
AddRegistration adds the provided document to the list of registrations.
func (*InvoiceRequest) Envelop ¶
func (req *InvoiceRequest) Envelop() *Envelope
Envelop provides a SOAP Envelope around the InvoiceRequest, ready to send off via the API.
type InvoiceRequestHeader ¶
type InvoiceRequestHeader struct {
Obligado Issuer `xml:"sum1:ObligadoEmision"`
Representante *Issuer `xml:"sum1:Representante,omitempty"`
RemisionVoluntaria *RemisionVoluntaria `xml:"sum1:RemisionVoluntaria,omitempty"`
}
InvoiceRequestHeader contains the header information for a VeriFactu document
type InvoiceRequestLine ¶
type InvoiceRequestLine struct {
Registration *InvoiceRegistration `xml:"sum1:RegistroAlta,omitempty"`
Cancellation *InvoiceCancellation `xml:"sum1:RegistroAnulacion,omitempty"`
}
InvoiceRequestLine contains either an invoice registration or cancellation
func (*InvoiceRequestLine) ChainData ¶
func (line *InvoiceRequestLine) ChainData() *ChainData
ChainData provides the chaining data for this line inside the invoice request.
type InvoiceResponse ¶
type InvoiceResponse struct {
XMLName xml.Name `xml:"RespuestaRegFactuSistemaFacturacion"`
Header struct {
Issuer InvoiceResponseIssuer `xml:"ObligadoEmision"`
Representative *InvoiceResponseIssuer `xml:"Representante,omitempty"`
RemisionVoluntaria *InvoiceResponseVoluntarySubmission `xml:"sum1:RemisionVoluntaria,omitempty"`
} `xml:"Cabecera"`
Wait int `xml:"TiempoEsperaEnvio"`
Status string `xml:"EstadoEnvio"`
Lines []*InvoiceResponseLine `xml:"RespuestaLinea"`
}
InvoiceResponse defines the response fields from the VeriFactu gateway.
func (*InvoiceResponse) Bytes ¶
func (ir *InvoiceResponse) Bytes() ([]byte, error)
Bytes returns the XML document bytes.
func (*InvoiceResponse) BytesIndent ¶ added in v0.43.0
func (ir *InvoiceResponse) BytesIndent() ([]byte, error)
BytesIndent returns the indented XML document bytes.
type InvoiceResponseIssuer ¶
InvoiceResponseIssuer maps the response from the invoice request for the issuer.
type InvoiceResponseLine ¶
type InvoiceResponseLine struct {
XMLName xml.Name `xml:"RespuestaLinea"`
ID struct {
Issuer string `xml:"IDEmisorFactura"`
Code string `xml:"NumSerieFactura"`
Date string `xml:"FechaExpedicionFactura"`
} `xml:"IDFactura"`
Operation struct {
Type OpType `xml:"TipoOperacion"`
Correction string `xml:"Subsanacion,omitempty"`
RejectedPrevious string `xml:"RechazoPrevio,omitempty"`
NoPrevious string `xml:"SinRegistroPrevio,omitempty"`
} `xml:"Operacion"`
Ref string `xml:"RefExterna,omitempty"`
Status string `xml:"EstadoRegistro"`
Code string `xml:"CodigoErrorRegistro,omitempty"`
Description string `xml:"DescripcionErrorRegistro,omitempty"`
// Duplicated contains information about possible duplicated requests
// that may need to be handled differently.
Duplicated *InvoiceResponseLineDuplicated `xml:"RegistroDuplicado,omitempty"`
}
InvoiceResponseLine defines the contents of a single line of the request.
func (*InvoiceResponseLine) Error ¶
func (r *InvoiceResponseLine) Error() error
Error provides a specific error repsonse for the individual line so that it can be handled correctly by the consumer.
func (*InvoiceResponseLine) Message ¶
func (r *InvoiceResponseLine) Message() string
Message provides the description of the issue reported by the gateway, or the status of the line when no description was provided. The status is not included alongside the description as it is already available separately.
type InvoiceResponseLineDuplicated ¶
type InvoiceResponseLineDuplicated struct {
ID string `xml:"IdPeticionRegistroDuplicado"`
Status string `xml:"EstadoRegistroDuplicado"`
Code string `xml:"CodigoErrorRegistro,omitempty"`
Description string `xml:"DescripcionErrorRegistro,omitempty"`
}
InvoiceResponseLineDuplicated describes details about the detected duplicate.
type InvoiceResponseVoluntarySubmission ¶
type InvoiceResponseVoluntarySubmission struct {
Date string `xml:"FechaFinVerifactu,omitempty"`
Incident string `xml:"Incidencia,omitempty"`
}
InvoiceResponseVoluntarySubmission for additional header data.
type Option ¶
type Option func(*Client)
Option is used to configure the client.
WithCorporateSeal uses the specific VERI*FACTU endpoints for communicating with a legal entity's corporate seal instead of a regular certificate issued to individuals. In Spanish these are called "Sello de Entidad".
func InProduction ¶
func InProduction() Option
InProduction defines the connection to use the production environment.
func InSandbox ¶
func InSandbox() Option
InSandbox defines the connection to use the testing environment.
func NoVerifactu ¶ added in v0.40.0
func NoVerifactu() Option
NoVerifactu configures the client for a NO VERI*FACTU invoicing system. Records in NO VERI*FACTU systems must be signed, so this option also enables signing; use WithSigning to pass additional signing options if needed.
func WithCertificate ¶
func WithCertificate(cert *xmldsig.Certificate) Option
WithCertificate defines the signing certificate to use when producing the VeriFactu document.
func WithCurrentTime ¶
WithCurrentTime defines the current time to use when generating the VeriFactu document. Only useful for testing.
func WithRepresentative ¶
WithRepresentative can be used to define a legal representative of the entity legally obliged to issue the invoice, usually the supplier. This may be required when the supplier's digital certificate is not available.
func WithSigning ¶
WithSigning sets additional xmldsig options that will be passed through to SignDocument for each record. This is useful for controlling the document ID and signing time in tests.
type Party ¶
type Party struct {
NombreRazon string `xml:"sum1:NombreRazon"`
NIF string `xml:"sum1:NIF,omitempty"`
IDOtro *IDOtro `xml:"sum1:IDOtro,omitempty"`
}
Party represents a in the document, covering fields Generador, Tercero and IDDestinatario
type PreviousEvent ¶
type PreviousEvent struct {
EventType string `xml:"sf:TipoEvento"`
GenerationTimestamp string `xml:"sf:FechaHoraHusoGenEvento"`
Fingerprint string `xml:"sf:HuellaEvento"`
}
PreviousEvent contains information about the previous event registration used for chaining.
type Record ¶ added in v0.43.0
type Record struct {
// Fingerprint as stated in the record.
Fingerprint string
// PreviousFingerprint as stated in the record, empty for the first record of a chain.
PreviousFingerprint string
// ComputedFingerprint is recomputed from the fields the fingerprint covers, differing when any of them was altered.
ComputedFingerprint string
// GenerationTimestamp is when the record was generated, with its time zone.
GenerationTimestamp string
}
Record contains the chain details read back from a record, to check its fingerprint, which covers only some fields and not the signature.
func ParseRecord ¶ added in v0.43.0
ParseRecord reads the chain details of an invoice registration, cancellation or event record.
type RegistroAnterior ¶
type RegistroAnterior struct {
IDEmisorFactura string `xml:"sum1:IDEmisorFactura"`
NumSerieFactura string `xml:"sum1:NumSerieFactura"`
FechaExpedicionFactura string `xml:"sum1:FechaExpedicionFactura"`
Huella string `xml:"sum1:Huella"`
}
RegistroAnterior contains information about the previous registration
type RemisionVoluntaria ¶
type RemisionVoluntaria struct {
FechaFinVerifactu string `xml:"sum1:FechaFinVerifactu,omitempty"`
Incidencia string `xml:"sum1:Incidencia,omitempty"`
}
RemisionVoluntaria contains voluntary submission details
type Software ¶
type Software struct {
NombreRazon string `xml:"sum1:NombreRazon"`
NIF string `xml:"sum1:NIF"`
NombreSistemaInformatico string `xml:"sum1:NombreSistemaInformatico"`
IdSistemaInformatico string `xml:"sum1:IdSistemaInformatico"` //nolint:revive,staticcheck
Version string `xml:"sum1:Version"`
NumeroInstalacion string `xml:"sum1:NumeroInstalacion"` // may need to be overridden at run time
TipoUsoPosibleSoloVerifactu string `xml:"sum1:TipoUsoPosibleSoloVerifactu,omitempty"`
TipoUsoPosibleMultiOT string `xml:"sum1:TipoUsoPosibleMultiOT,omitempty"`
IndicadorMultiplesOT string `xml:"sum1:IndicadorMultiplesOT,omitempty"`
}
Software contains the details about the software that is using this library to generate VeriFactu documents. These details are included in the final document.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package addon provides the VeriFactu addon for GOBL, covering both the VERI*FACTU and NO VERI*FACTU modalities.
|
Package addon provides the VeriFactu addon for GOBL, covering both the VERI*FACTU and NO VERI*FACTU modalities. |
|
cmd
|
|
|
gobl.verifactu
command
Package main provides the command line interface to the VeriFactu package.
|
Package main provides the command line interface to the VeriFactu package. |
|
Package test provides common functions for testing.
|
Package test provides common functions for testing. |