doc

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package doc provides the VeriFactu document mappings from GOBL

Index

Constants

View Source
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 */
	EnvNamespace = "http://schemas.xmlsoap.org/soap/envelope/"
)

SUM is the namespace for the main VeriFactu schema

View Source
const (
	// CurrentVersion is the current version of the VeriFactu document
	CurrentVersion = "1.0"
)
View Source
const TipoHuella = "01"

TipoHuella is the SHA-256 fingerprint type for Verifactu - L12 Might include support for other encryption types in the future.

Variables

View Source
var (
	ErrConnection = newError("connection")
	ErrValidation = newError("validation")
	ErrDuplicate  = newError("duplicate")
)

Standard gateway error responses

View Source
var (
	ErrNotSpanish       = ErrValidation.WithMessage("only spanish invoices are supported")
	ErrAlreadyProcessed = ErrValidation.WithMessage("already processed")
	ErrOnlyInvoices     = ErrValidation.WithMessage("only invoices are supported")
)

Standard error responses.

Functions

This section is empty.

Types

type Body

type Body struct {
	VeriFactu *RegFactuSistemaFacturacion `xml:"sum:RegFactuSistemaFacturacion"`
}

Body is the body of the SOAP envelope

type Cabecera

type Cabecera struct {
	Obligado              Obligado               `xml:"sum1:ObligadoEmision"`
	Representante         *Obligado              `xml:"sum1:Representante,omitempty"`
	RemisionVoluntaria    *RemisionVoluntaria    `xml:"sum1:RemisionVoluntaria,omitempty"`
	RemisionRequerimiento *RemisionRequerimiento `xml:"sum1:RemisionRequerimiento,omitempty"`
}

Cabecera contains the header information for a VeriFactu document

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 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                float64 `xml:"sum1:TipoImpositivo,omitempty"`
	BaseImponibleOImporteNoSujeto float64 `xml:"sum1:BaseImponibleOimporteNoSujeto"`
	BaseImponibleACoste           float64 `xml:"sum1:BaseImponibleACoste,omitempty"`
	CuotaRepercutida              float64 `xml:"sum1:CuotaRepercutida,omitempty"`
	TipoRecargoEquivalencia       float64 `xml:"sum1:TipoRecargoEquivalencia,omitempty"`
	CuotaRecargoEquivalencia      float64 `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 documents

type Envelope

type Envelope struct {
	XMLName xml.Name `xml:"soapenv:Envelope"`
	XMLNs   string   `xml:"xmlns:soapenv,attr"`
	SUM     string   `xml:"xmlns:sum,attr"`
	SUM1    string   `xml:"xmlns:sum1,attr"`
	Body    *Body    `xml:"soapenv:Body"`
}

Envelope is the SOAP envelope wrapper

func NewCancel

func NewCancel(inv *bill.Invoice, opts *Options) (*Envelope, error)

NewCancel creates a new VeriFactu cancellation document from the provided GOBL Invoice.

func NewInvoice

func NewInvoice(inv *bill.Invoice, opts *Options) (*Envelope, error)

NewInvoice creates a new VeriFactu invoice document from the provided GOBL Invoice.

func (*Envelope) Bytes

func (d *Envelope) Bytes() ([]byte, error)

Bytes returns the XML document bytes

func (*Envelope) BytesIndent

func (d *Envelope) BytesIndent() ([]byte, error)

BytesIndent returns the indented XML document bytes

func (*Envelope) ChainData

func (d *Envelope) ChainData() Encadenamiento

ChainData generates the data to be used to link to this one in the next entry.

func (*Envelope) ChainDataCancel

func (d *Envelope) ChainDataCancel() Encadenamiento

ChainDataCancel generates the data to be used to link to this one in the next entry for cancelling invoices.

func (*Envelope) Fingerprint

func (d *Envelope) Fingerprint(prev *ChainData) error

Fingerprint generates the SHA-256 fingerprint for the document

func (*Envelope) FingerprintCancel

func (d *Envelope) FingerprintCancel(prev *ChainData) error

FingerprintCancel generates the SHA-256 fingerprint for the document

func (*Envelope) QRCodes

func (d *Envelope) QRCodes(production bool) string

QRCodes generates the QR code for the document

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 NewErrorFrom

func NewErrorFrom(err error) *Error

NewErrorFrom attempts to wrap the provided error into the Error type.

func (*Error) Code

func (e *Error) Code() string

Code returns the code provided by the remote service.

func (*Error) Error

func (e *Error) Error() string

Error produces a human readable error message.

func (*Error) Is

func (e *Error) Is(target error) bool

Is checks to see if the target error is the same as the current one or forms part of the chain.

func (*Error) Key

func (e *Error) Key() string

Key returns the key for the error.

func (*Error) Message

func (e *Error) Message() string

Message returns the human message for the error.

func (*Error) WithCode

func (e *Error) WithCode(code string) *Error

WithCode duplicates and adds the code to the error.

func (*Error) WithMessage

func (e *Error) WithMessage(msg string) *Error

WithMessage duplicates and adds the message to the error.

type FacturaRectificada

type FacturaRectificada struct {
	IDFactura IDFactura `xml:"sum1:IDFacturaRectificada"`
}

FacturaRectificada represents a rectified invoice

type FacturaSustituida

type FacturaSustituida struct {
	IDFactura IDFactura `xml:"sum1:IDFacturaSustituida"`
}

FacturaSustituida represents a substituted 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         string `xml:"sum1:BaseRectificada"`
	CuotaRectificada        string `xml:"sum1:CuotaRectificada"`
	CuotaRecargoRectificado string `xml:"sum1:CuotaRecargoRectificado"`
}

ImporteRectificacion contains rectification amounts

type IssuerRole

type IssuerRole string

IssuerRole defines the role of the issuer in the invoice.

const (
	IssuerRoleSupplier   IssuerRole = "E"
	IssuerRoleCustomer   IssuerRole = "D"
	IssuerRoleThirdParty IssuerRole = "T"
)

IssuerRole constants

type Obligado

type Obligado struct {
	NombreRazon string `xml:"sum1:NombreRazon"`
	NIF         string `xml:"sum1:NIF"`
}

Obligado represents an obligated party in the document

type Options added in v0.3.0

type Options struct {
	// Software defines the software used to generate the document.
	Software *Software

	// IssuerRole defines the role of the issuer in the document.
	IssuerRole IssuerRole

	// Representative defines the legal representative of the entity
	// legally obliged to issue the invoice, usually the supplier.
	Representative *Obligado

	// Timestamp defines the current time to use when signing the
	// document.
	Timestamp time.Time
}

Options defines the set of options to be used when building a new VeriFactu document.

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 RegFactuSistemaFacturacion

type RegFactuSistemaFacturacion struct {
	// XMLName         xml.Name         `xml:"sum:RegFactuSistemaFacturacion"`
	Cabecera        *Cabecera        `xml:"sum:Cabecera"`
	RegistroFactura *RegistroFactura `xml:"sum:RegistroFactura"`
}

RegFactuSistemaFacturacion represents the root element of a RegFactuSistemaFacturacion document

func (*RegFactuSistemaFacturacion) Bytes

func (d *RegFactuSistemaFacturacion) Bytes() ([]byte, error)

Bytes returns the XML document bytes

type RegistroAlta

type RegistroAlta struct {
	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                []*FacturaRectificada `xml:"sum1:FacturasRectificadas,omitempty"`
	FacturasSustituidas                 []*FacturaSustituida  `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                          float64               `xml:"sum1:CuotaTotal"`
	ImporteTotal                        float64               `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
	TipoHuella                          string                `xml:"sum1:TipoHuella"`
	Huella                              string                `xml:"sum1:Huella"`
}

RegistroAlta contains the details of an invoice registration

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 RegistroAnulacion

type RegistroAnulacion struct {
	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"`
}

RegistroAnulacion contains the details of an invoice cancellation

type RegistroFactura

type RegistroFactura struct {
	RegistroAlta      *RegistroAlta      `xml:"sum1:RegistroAlta,omitempty"`
	RegistroAnulacion *RegistroAnulacion `xml:"sum1:RegistroAnulacion,omitempty"`
}

RegistroFactura contains either an invoice registration or cancellation

type RemisionRequerimiento

type RemisionRequerimiento struct {
	RefRequerimiento string `xml:"sum1:RefRequerimiento"`
	FinRequerimiento string `xml:"sum1:FinRequerimiento,omitempty"`
}

RemisionRequerimiento contains requirement submission details

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
	Version                     string `xml:"sum1:Version"`
	NumeroInstalacion           string `xml:"sum1:NumeroInstalacion"`
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL