Documentation
¶
Overview ¶
Package ticketbai provides a client for generating and sending TicketBAI documents to the different regional services in the Basque Country.
Index ¶
- Constants
- Variables
- func ParseAmendmentDocument(data []byte) (*convert.Amendment, error)
- func ParseCancelDocument(data []byte) (*convert.AnulaTicketBAI, error)
- func ParseDocument(data []byte) (*convert.TicketBAI, error)
- func ZoneFor(env *gobl.Envelope) l10n.Code
- type Client
- func (c *Client) Cancel(ctx context.Context, env *gobl.Envelope, d *convert.AnulaTicketBAI) error
- func (c *Client) CancelAmendment(ctx context.Context, env *gobl.Envelope, d *convert.CancelAmendment) error
- func (c *Client) Convert(env *gobl.Envelope) (*convert.TicketBAI, error)
- func (c *Client) CurrentTime() time.Time
- func (c *Client) Fingerprint(d *convert.TicketBAI, prev *convert.ChainData) error
- func (c *Client) FingerprintCancel(cd *convert.AnulaTicketBAI) error
- func (c *Client) GenerateAmendment(env *gobl.Envelope, orig *convert.TicketBAI, action convert.AmendmentAction) (*convert.Amendment, error)
- func (c *Client) GenerateCancel(env *gobl.Envelope) (*convert.AnulaTicketBAI, error)
- func (c *Client) GenerateCancelAmendment(orig *convert.AnulaTicketBAI) (*convert.CancelAmendment, error)
- func (c *Client) Post(ctx context.Context, env *gobl.Envelope, d *convert.TicketBAI) error
- func (c *Client) PostAmendment(ctx context.Context, env *gobl.Envelope, d *convert.Amendment) error
- func (c *Client) Sandbox() bool
- func (c *Client) Sign(d *convert.TicketBAI, env *gobl.Envelope) error
- func (c *Client) SignCancel(cd *convert.AnulaTicketBAI, env *gobl.Envelope) error
- func (c *Client) SupportsAmendments() bool
- func (c *Client) Zone() l10n.Code
- type Error
- type Licenses
- type Option
- func InProduction() Option
- func InSandbox() Option
- func WithCertificate(cert *xmldsig.Certificate) Option
- func WithConnection(conn gateways.Connection) Option
- func WithCurrentTime(curTime time.Time) Option
- func WithCustomerIssuer() Option
- func WithSupplierIssuer() Option
- func WithThirdPartyIssuer() Option
- type Software
- type TestConnection
- func (tc *TestConnection) Cancel(_ context.Context, _ *bill.Invoice, _ *convert.AnulaTicketBAI) error
- func (tc *TestConnection) CancelAmendment(_ context.Context, _ *bill.Invoice, _ *convert.CancelAmendment) error
- func (tc *TestConnection) Post(_ context.Context, _ *bill.Invoice, _ *convert.TicketBAI) error
- func (tc *TestConnection) PostAmendment(_ context.Context, _ *bill.Invoice, _ *convert.Amendment) error
Constants ¶
const ( AmendRejected = convert.AmendRejected // Subsanar a rejected document AmendReceived = convert.AmendReceived // Modificar a document received with errors )
Expose amendment actions for external use.
const ( ZoneBI l10n.Code = convert.ZoneBI // Bizkaia ZoneSS l10n.Code = convert.ZoneSS // Gipuzkoa ZoneVI l10n.Code = convert.ZoneVI // Araba )
Expose zone codes for external use.
Variables ¶
var ( // ErrValidation implies there is something wrong with the contents of the // document that needs to be fixed before sending it again. ErrValidation = newError("validation") // ErrDuplicate is used when the gateway has already received the document. ErrDuplicate = newError("duplicate") // ErrConnection is used when the gateway could not be reached or gave a // response we're unable to understand. ErrConnection = newError("connection") // ErrServer indicates the gateway had an internal problem handling the // request, which may succeed if attempted again later. ErrServer = newError("server") // ErrInternal is used for any other unexpected error. ErrInternal = newError("internal") )
Main error types return by this package.
Functions ¶
func ParseAmendmentDocument ¶ added in v0.55.0
ParseAmendmentDocument will parse the XML data into an amendment document.
func ParseCancelDocument ¶
func ParseCancelDocument(data []byte) (*convert.AnulaTicketBAI, error)
ParseCancelDocument will parse the XML data into a Cancel TicketBAI document.
func ParseDocument ¶
ParseDocument will parse the XML data into a TicketBAI document.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides the main interface to the TicketBAI package.
func New ¶
New creates a new TicketBAI client with shared software and configuration options for creating and sending new documents.
func (*Client) CancelAmendment ¶ added in v0.55.0
func (c *Client) CancelAmendment(ctx context.Context, env *gobl.Envelope, d *convert.CancelAmendment) error
CancelAmendment will send the cancel amendment document to the TicketBAI gateway.
func (*Client) Convert ¶
Convert creates a new TicketBAI document from the provided GOBL Envelope. The envelope must contain a valid Invoice.
func (*Client) CurrentTime ¶
CurrentTime returns the current time to use when generating the TicketBAI document.
func (*Client) Fingerprint ¶
Fingerprint generates a fingerprint for the TicketBAI document using the data provided from the previous chain data. If there was no previous document in the chain, the parameter should be nil. The document is updated in place.
func (*Client) FingerprintCancel ¶
func (c *Client) FingerprintCancel(cd *convert.AnulaTicketBAI) error
FingerprintCancel generates a finger print for the TicketBAI document using the data provided from the previous invoice data.
func (*Client) GenerateAmendment ¶ added in v0.55.0
func (c *Client) GenerateAmendment(env *gobl.Envelope, orig *convert.TicketBAI, action convert.AmendmentAction) (*convert.Amendment, error)
GenerateAmendment creates a new amendment document to resend or modify the original signed TicketBAI document using the current contents of the GOBL Envelope. The original document is required as amendments are not signed, and instead refer to the original's fingerprint and signature, so the envelope's existing stamps remain valid.
Use AmendRejected when the original document was rejected, and AmendReceived when it was received with errors. Amendments are sent through the Zuzendu service, which is only available in the Gipuzkoa and Araba regions.
func (*Client) GenerateCancel ¶
GenerateCancel creates a new AnulaTicketBAI document from the provided GOBL Envelope.
func (*Client) GenerateCancelAmendment ¶ added in v0.55.0
func (c *Client) GenerateCancelAmendment(orig *convert.AnulaTicketBAI) (*convert.CancelAmendment, error)
GenerateCancelAmendment creates a new amendment document to resend the original signed cancellation document that was rejected.
func (*Client) PostAmendment ¶ added in v0.55.0
PostAmendment will send the amendment document to the TicketBAI gateway.
When an AmendRejected document is refused because the original document was registered after all, the amendment is automatically sent again as AmendReceived. The document's action is updated to reflect what was sent, so callers only need to know the original was issued, not whether the tax agency accepted it.
func (*Client) Sign ¶
Sign is used to generate the XML DSig components of the final XML document. This method will also update the GOBL Envelope with the QR codes that are generated.
func (*Client) SignCancel ¶
SignCancel is used to generate the XML DSig components of the final XML document.
func (*Client) SupportsAmendments ¶ added in v0.55.0
SupportsAmendments returns true when the client's zone offers the Zuzendu service used to send amendments, which is the case in Gipuzkoa and Araba.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error allows for structured responses to better handle errors upstream.
type Licenses ¶
type Licenses map[gateways.Environment]map[l10n.Code]string
Licenses stores the licenses for the different zones and environments.
type Option ¶
type Option func(*Client)
Option is used to configure the client.
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 WithCertificate ¶
func WithCertificate(cert *xmldsig.Certificate) Option
WithCertificate defines the signing certificate to use when producing the TicketBAI document.
func WithConnection ¶
func WithConnection(conn gateways.Connection) Option
WithConnection defines a new gateway connection to use for the client. Useful for testing and mocking the connection responses.
func WithCurrentTime ¶
WithCurrentTime defines the current time to use when generating the TicketBAI document. Useful for testing.
func WithCustomerIssuer ¶
func WithCustomerIssuer() Option
WithCustomerIssuer set the issuer type to customer. To be used when the invoice's supplier, using their own certificate, is issuing the document.
func WithSupplierIssuer ¶
func WithSupplierIssuer() Option
WithSupplierIssuer set the issuer type to supplier. To be used when the invoice's supplier, using their own certificate, is issuing the document.
func WithThirdPartyIssuer ¶
func WithThirdPartyIssuer() Option
WithThirdPartyIssuer set the issuer type to third party. To be used when the an authorised third party, using their own certificate, is issuing the document on behalf of the invoice's supplier.
type Software ¶
Software defines the details about the software that is using this library to generate TicketBAI documents. These details are included in the final document.
type TestConnection ¶
type TestConnection struct {
// PostError, CancelError, PostAmendmentError and CancelAmendmentError, when
// set, are returned by the corresponding method so that error handling can
// be exercised by tests.
PostError error
CancelError error
PostAmendmentError error
CancelAmendmentError error
// contains filtered or unexported fields
}
TestConnection is a mock gateway connection for testing purposes
func (*TestConnection) Cancel ¶
func (tc *TestConnection) Cancel(_ context.Context, _ *bill.Invoice, _ *convert.AnulaTicketBAI) error
Cancel mocks the Cancel method of the Connection interface
func (*TestConnection) CancelAmendment ¶ added in v0.55.0
func (tc *TestConnection) CancelAmendment(_ context.Context, _ *bill.Invoice, _ *convert.CancelAmendment) error
CancelAmendment mocks the CancelAmendment method of the Connection interface
func (*TestConnection) PostAmendment ¶ added in v0.55.0
func (tc *TestConnection) PostAmendment(_ context.Context, _ *bill.Invoice, _ *convert.Amendment) error
PostAmendment mocks the PostAmendment method of the Connection interface
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ca is used to provide the root certificates used by the TicketBAI services.
|
Package ca is used to provide the root certificates used by the TicketBAI services. |
|
cmd
|
|
|
gobl.ticketbai
command
Package main provides the command line interface to the TicketBAI package.
|
Package main provides the command line interface to the TicketBAI package. |
|
Package convert contains the TicketBAI document structures and methods to generate it.
|
Package convert contains the TicketBAI document structures and methods to generate it. |
|
internal
|
|
|
gateways
Package gateways contains the different interfaces to send the TicketBAI documents to.
|
Package gateways contains the different interfaces to send the TicketBAI documents to. |
|
gateways/ebizkaia
Package ebizkaia provides a gatewy for generating and sending documents to the Bizkaia region.
|
Package ebizkaia provides a gatewy for generating and sending documents to the Bizkaia region. |
|
Package test provides common functions for testing.
|
Package test provides common functions for testing. |