Documentation
¶
Overview ¶
Package eet records GOBL payments with the Czech EET 2.0 service and returns the POK of each; the GOBL addon, with the eet-pok stamp to keep it in, lives in the addon subpackage.
The package embeds the time zone database (time/tzdata, about 450 KB) so that Europe/Prague always loads, as falling back to UTC would record every sale an hour or two off.
Index ¶
Constants ¶
const ( MinTimeout = 2 * time.Second DefaultTimeout = 10 * time.Second )
MinTimeout is the shortest wait for a reply the EET Act allows (§ 19; item description, chapter 6), and DefaultTimeout the one used when none is set.
const MaxRequestSize = 12000
MaxRequestSize is the largest signed request the service accepts, the smaller reading of the "12 kB" of error 7 (interface description, 3.5.4).
const SOAPAction = "http://fs.gov.cz/eet/OdeslaniTrzby"
SOAPAction is the action of the service's one operation, OdeslaniTrzby, which SOAP 1.1 sends in quotes in the SOAPAction header.
Variables ¶
var ( // ErrConnection is used when the service could not be reached or gave a // response we're unable to understand, including one that answers // another message. 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") // ErrServer indicates the service had a problem handling the request, // which may succeed if sent again later. ErrServer = newError("server") // ErrDuplicate is used when the envelope has a POK that records the sale // in the client's environment (any in the Playground, a production one // in production), as a sale is only sent again when none came back // (item description, chapter 3). ErrDuplicate = newError("duplicate") // ErrUntrusted says the confirmation's signature is valid but its // certificate isn't the environment's signer, or couldn't be checked (a // clock set wrong, say), while a missing or broken signature is // ErrConnection: send the sale again with WithResend, and have someone // check the certificate and the clock. ErrUntrusted = newError("untrusted") // ErrEnvironment says a confirmation comes from the other environment: // send the sale again with WithResend, and have someone check where it // was sent. ErrEnvironment = newError("environment") )
Errors returned by this package, matched with errors.Is on their key.
var ( // ErrOnlyPayments is returned for an envelope whose document isn't a // payment. ErrOnlyPayments = ErrValidation.WithMessage("only payments are supported") )
Standard error responses.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client builds sale messages from GOBL payments and sends them to one environment of the EET service.
func New ¶
New creates a client for the Playground, or production with InProduction, which without a certificate builds sales but doesn't send them.
func (*Client) CurrentTime ¶
CurrentTime returns the send time for the sale messages.
func (*Client) Environment ¶
func (c *Client) Environment() Environment
Environment returns the environment the client sends to.
func (*Client) NewSale ¶
NewSale builds the message for the calculated payment in the envelope, one for every attempt, refusing it with the rules' faults, or with ErrDuplicate for an envelope whose POK records the sale in the client's environment (any in the Playground, a production one in production) unless WithVerification is given.
func (*Client) Send ¶
Send signs and posts the sale, which can't have been signed before, and reads the reply as ParseResponse does; a context deadline under MinTimeout cuts the wait short, and errors about a reply carry its transaction ID, when the service sent one.
func (*Client) Sign ¶
Sign returns the SOAP request carrying the sale, signed with the client's certificate as the interface description asks (5.2), with the send time (dat_odesl, 3.3.3.2) set now; a sale is used once (3.3.3.1), so Sign followed by Send fails, and an app that posts the request itself uses Sign and ParseResponse while any other uses only Send.
type Confirmation ¶
type Confirmation struct {
// POK (pok) is the confirmation code, unique to each confirmed message.
POK string `xml:"pok,attr"`
// Test (test) is true outside production.
Test bool `xml:"test,attr"`
}
Confirmation (Potvrzeni) that the sale was recorded.
func (*Confirmation) UnmarshalXML ¶
func (c *Confirmation) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML reads a Potvrzeni element, refusing one without a POK.
type Data ¶
type Data struct {
// TaxID (eic_popl) of whoever records the sale, which should be the CN of
// the signing certificate, or the service adds warning 1.
TaxID string `xml:"eic_popl,attr"`
// DelegatingTaxID (eic_poverujiciho) of the merchant that delegated the
// recording, when there is one.
DelegatingTaxID string `xml:"eic_poverujiciho,attr,omitempty"`
// DelegatedByMany (povereni_vice_popl) when several merchants delegated
// the recording.
DelegatedByMany bool `xml:"povereni_vice_popl,attr,omitempty"`
// UnitID (id_jednotky) of the recording unit, as registered in DIS+.
UnitID string `xml:"id_jednotky,attr"`
// DeviceID (id_pokl) of the end device within the unit.
DeviceID string `xml:"id_pokl,attr"`
// Number (porad_cis) of the sale in the device's sequence.
Number string `xml:"porad_cis,attr"`
// SoldAt (dat_trzby) is the local time of the sale.
SoldAt string `xml:"dat_trzby,attr"`
// Total (celk_trzba) amount paid, in CZK.
Total string `xml:"celk_trzba,attr"`
// PrepaidLoaded (urceno_cerp_zuct) is the part of the total meant to be
// drawn down or settled later.
PrepaidLoaded string `xml:"urceno_cerp_zuct,attr,omitempty"`
// PrepaidDrawn (cerp_zuct) is the part paid by drawing down an earlier
// prepayment.
PrepaidDrawn string `xml:"cerp_zuct,attr,omitempty"`
}
Data (Data) describes the sale itself.
type Environment ¶
type Environment string
Environment is one of the EET service's two environments, production or the Playground, and gives both the URL to send a sale to and the signer its confirmations must have.
const ( EnvironmentProduction Environment = "production" EnvironmentPlayground Environment = "playground" )
The service's environments.
func (Environment) URL ¶
func (e Environment) URL() string
URL is where the environment receives sales ("Přístupové a provozní informace" v1.2, chapter 2.1), or empty for an unknown environment.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is an error of this package: a key that says how to handle it, with a code and message when there are any.
func (*Error) Code ¶
Code returns the code provided by the service: the EET error code of a Chyba, the faultcode of a SOAP fault, or the HTTP status.
func (*Error) Is ¶
Is matches an Error with the same key, and the same code and message where the target has them.
func (*Error) WithMessage ¶
WithMessage duplicates and adds the message to the error.
type ErrorCode ¶
type ErrorCode int
ErrorCode (kod) of a response. Match on the code, not on the text, which differs between versions of the spec.
const ( // ErrorCodeTemporary is a temporary technical error: send again later. ErrorCodeTemporary ErrorCode = -1 // ErrorCodeVerified says, in verification mode, that the message passed // every check. ErrorCodeVerified ErrorCode = 0 // ErrorCodeEncoding says the XML encoding is not valid. ErrorCodeEncoding ErrorCode = 2 // ErrorCodeSchema says the message fails the XML schema. ErrorCodeSchema ErrorCode = 3 // ErrorCodeSignature says the signature is invalid, or the certificate is // not trusted, not valid or revoked. ErrorCodeSignature ErrorCode = 4 // ErrorCodeTaxID says the merchant's tax ID (eic_popl) has a wrong // structure. ErrorCodeTaxID ErrorCode = 6 // ErrorCodeTooLarge says the message is over 12 kB. ErrorCodeTooLarge ErrorCode = 7 // ErrorCodeProcessing is a technical or data error in processing: send // again later. ErrorCodeProcessing ErrorCode = 8 )
Error codes of the interface description, chapter 3.5. Code 1 does not exist and 5 was used before version 4 only.
type GenerateOption ¶
type GenerateOption func(*generateOptions)
GenerateOption adjusts the message built for a sale.
func WithResend ¶
func WithResend() GenerateOption
WithResend marks the message as a resend (prvni_zaslani false), for every attempt after the first.
func WithVerification ¶
func WithVerification() GenerateOption
WithVerification asks the service to check the message without recording the sale (overeni): the response carries error code 0 and no POK.
type Header ¶
type Header struct {
// UUID (uuid_zpravy) of the message, new for every attempt, resends
// included.
UUID string `xml:"uuid_zpravy,attr"`
// SentAt (dat_odesl) is when the message was sent.
SentAt string `xml:"dat_odesl,attr"`
// FirstAttempt (prvni_zaslani) is false on a resend.
FirstAttempt bool `xml:"prvni_zaslani,attr"`
// Verification (overeni) asks the service to check the message without
// recording it.
Verification *bool `xml:"overeni,attr,omitempty"`
}
Header (Hlavicka) identifies one attempt to send a sale.
type Option ¶
type Option func(*Client)
Option is used to configure the client.
func InPlayground ¶
func InPlayground() Option
InPlayground sends to the Playground, the EET service's public test environment.
func InProduction ¶
func InProduction() Option
InProduction sends to the production environment, where sales are recorded.
func WithCertificate ¶
func WithCertificate(cert *xmldsig.Certificate) Option
WithCertificate sets the merchant's CA EET certificate, whose tax ID is its CN, to sign the sales with.
func WithCurrentTime ¶
WithCurrentTime fixes the send time of the sale messages.
func WithTimeout ¶
WithTimeout sets how long to wait for a reply, at least MinTimeout.
type Response ¶
type Response struct {
Header *ResponseHeader `xml:"http://fs.gov.cz/eet/schema/v4 Hlavicka"`
Confirmation *Confirmation `xml:"http://fs.gov.cz/eet/schema/v4 Potvrzeni"`
Error *ResponseError `xml:"http://fs.gov.cz/eet/schema/v4 Chyba"`
Warnings []*Warning `xml:"http://fs.gov.cz/eet/schema/v4 Varovani"`
// TransactionID is the X-Global-Transaction-Id the service tagged the
// exchange with (interface description, 5.4), which only Send sees.
TransactionID string `xml:"-"`
}
Response (Odpoved) is the service's answer to a sale message: a confirmation with the POK when the sale is recorded, or an error, and up to ten warnings either way.
func ParseResponse ¶
func ParseResponse(data []byte, sale *Sale, env Environment) (*Response, error)
ParseResponse reads the service's reply to the sale, accepting a confirmation only when the environment's certificate signs it for that very message, and returns an error code other than 0 as an error alongside the reply.
type ResponseError ¶
type ResponseError struct {
Code ErrorCode `xml:"kod,attr"`
Test bool `xml:"test,attr"`
Message string `xml:",chardata"`
}
ResponseError (Chyba) explains why a sale was not recorded. In verification mode, code 0 says the message passed every check.
func (*ResponseError) Err ¶
func (e *ResponseError) Err() error
Err maps the error by its code: nil for code 0, a verification that passed, ErrServer when the code says to send again later, ErrValidation otherwise.
func (*ResponseError) UnmarshalXML ¶
func (e *ResponseError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML reads a Chyba element, refusing one without a numeric code: a missing code would otherwise read as 0, the verification success.
type ResponseHeader ¶
type ResponseHeader struct {
// UUID (uuid_zpravy) of the message answered.
UUID string `xml:"uuid_zpravy,attr"`
// ReceivedAt (dat_prij) is when the sale was recorded.
ReceivedAt string `xml:"dat_prij,attr"`
// RejectedAt (dat_odmit) is when the message was rejected.
RejectedAt string `xml:"dat_odmit,attr"`
}
ResponseHeader (Hlavicka) of a response.
func (*ResponseHeader) UnmarshalXML ¶
func (h *ResponseHeader) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
UnmarshalXML reads a Hlavicka element, refusing attributes in another namespace.
type Sale ¶
type Sale struct {
XMLName xml.Name `xml:"v4:Trzba"`
Header *Header `xml:"v4:Hlavicka"`
Data *Data `xml:"v4:Data"`
// contains filtered or unexported fields
}
Sale is the data message of a sale (Trzba), with its values in the text form the schema takes and optional attributes left empty when they don't apply, as the service refuses empty ones.
type Warning ¶
type Warning struct {
Code WarningCode `xml:"kod_varov,attr"`
Message string `xml:",chardata"`
}
Warning (Varovani) about a sale that was recorded all the same.
func (*Warning) UnmarshalXML ¶
UnmarshalXML reads a Varovani element, refusing attributes in another namespace.
type WarningCode ¶
type WarningCode int
WarningCode (kod_varov) of a response.
const ( // WarningCodeTaxIDMismatch says the merchant's tax ID differs from the // CN of the signing certificate. WarningCodeTaxIDMismatch WarningCode = 1 // WarningCodeDelegatingTaxID says the delegating merchant's tax ID has a // wrong structure. WarningCodeDelegatingTaxID WarningCode = 2 // WarningCodeSaleTimeAhead says the sale time is more than 2 hours after // the message was received. WarningCodeSaleTimeAhead WarningCode = 4 // WarningCodeSaleTimeOld says the sale time is more than 2 years before // the message was received, or before the environment's first day. WarningCodeSaleTimeOld WarningCode = 5 // WarningCodeUnitID says the unit ID doesn't have the form DIS+ gives // units. WarningCodeUnitID WarningCode = 6 // WarningCodeSelfDelegation says the delegating merchant is the merchant // itself. WarningCodeSelfDelegation WarningCode = 7 )
Warning codes of the interface description, chapter 3.4.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package addon provides the cz-eet-v1 GOBL addon for Czech EET 2.0 sales recording: the extensions that say where a sale happened, whether it is income of several taxpayers and which lines load prepaid credit, the payment means key for credit drawn, the stamp for the confirmation code, and the rules a payment must meet before it can be sent.
|
Package addon provides the cz-eet-v1 GOBL addon for Czech EET 2.0 sales recording: the extensions that say where a sale happened, whether it is income of several taxpayers and which lines load prepaid credit, the payment means key for credit drawn, the stamp for the confirmation code, and the rules a payment must meet before it can be sent. |