Documentation
¶
Overview ¶
Package nibussatws provides shared primitives (status codes, errors, versioning) for a native Go client of the Mexican SAT "Descarga Masiva de CFDI" web service.
The concrete functionality lives in subpackages:
- credential: load and use a FIEL (e.firma) — parse .cer/.key, sign with RSA.
- xmlsig: WS-Security XML signing required by the SAT SOAP endpoints.
- service: the four SAT operations (Authenticate, Query, Verify, Download).
- satpackage: read the downloaded ZIP packages (CFDI XML / Metadata).
- backfill: high-level orchestration to download a full date range.
- transport: HTTP client with proxy and retry support.
This is a clean-room reimplementation of the SAT protocol inspired by phpcfdi/sat-ws-descarga-masiva. It does not copy that project's code.
Index ¶
- Constants
- func IsCertificateInvalid(err error) bool
- func IsCertificateRevoked(err error) bool
- func IsCredentialRejected(err error) bool
- func IsDuplicate(err error) bool
- func IsExhausted(err error) bool
- func IsLimitExceeded(err error) bool
- func IsNoInfo(err error) bool
- type SolicitudState
- type StatusCode
- type StatusError
Constants ¶
const Version = "0.0.0-dev"
Version is the current module version. Kept in sync with the git tag.
Variables ¶
This section is empty.
Functions ¶
func IsCertificateInvalid ¶
IsCertificateInvalid reports whether err is a SAT 305 (e.firma invalid).
func IsCertificateRevoked ¶
IsCertificateRevoked reports whether err is a SAT 304 (e.firma revoked/expired).
func IsCredentialRejected ¶
IsCredentialRejected reports whether the SAT rejected the FIEL itself (revoked, expired or invalid). When true, the end user needs to provide a current, valid e.firma — it is not a bug in the request. Combine with the pre-flight credential.Validate() check to catch most of these before sending.
func IsDuplicate ¶
IsDuplicate reports whether err is a SAT 5005 (duplicate in-progress request).
func IsExhausted ¶
IsExhausted reports whether err is a SAT 5002 (lifetime requests exhausted).
func IsLimitExceeded ¶
IsLimitExceeded reports whether err is a SAT 5003 (split the date range).
Types ¶
type SolicitudState ¶
type SolicitudState int
SolicitudState is the processing state of a download request, as reported by VerificaSolicitudDescarga (the "EstadoSolicitud" field).
const ( StateAccepted SolicitudState = 1 // received, not yet processed StateInProgress SolicitudState = 2 // packages being generated StateFinished SolicitudState = 3 // ready — PackageIDs are available StateError SolicitudState = 4 // processing failed StateRejected SolicitudState = 5 // rejected (e.g. by limit) StateExpired SolicitudState = 6 // expired — packages no longer available )
func (SolicitudState) String ¶
func (s SolicitudState) String() string
String renders the state name.
func (SolicitudState) Terminal ¶
func (s SolicitudState) Terminal() bool
Terminal reports whether the state is final (no more polling needed).
type StatusCode ¶
type StatusCode string
StatusCode is the SAT "CodEstatus" / "CodigoEstadoSolicitud" returned by the web service operations.
const ( // StatusAccepted (5000) — request was received/accepted successfully. StatusAccepted StatusCode = "5000" // StatusUserInvalid (300) — "Usuario No Válido". StatusUserInvalid StatusCode = "300" // StatusXMLMalformed (301) — "XML Mal Formado". StatusXMLMalformed StatusCode = "301" // StatusSealMalformed (302) — "Sello Mal Formado" (bad signature). StatusSealMalformed StatusCode = "302" // StatusSealMismatch (303) — "Sello no corresponde con RfcSolicitante". StatusSealMismatch StatusCode = "303" // StatusCertRevoked (304) — "Certificado Revocado o Caduco": the e.firma was // revoked or has expired. The user must use a current FIEL. StatusCertRevoked StatusCode = "304" // StatusCertInvalid (305) — "Certificado Inválido". StatusCertInvalid StatusCode = "305" // StatusExhausted (5002) — the same period+parameters was requested too many // times ("Se han agotado las solicitudes de por vida"). Vary the date range by // at least one second to make it a new period. StatusExhausted StatusCode = "5002" // StatusLimitExceeded (5003) — the query exceeds the max records per request // (~200k CFDI / ~1M metadata). Split the date range. StatusLimitExceeded StatusCode = "5003" // StatusNoInfo (5004) — no CFDI found for the requested period. StatusNoInfo StatusCode = "5004" // StatusDuplicate (5005) — an in-progress request with the same parameters // already exists. StatusDuplicate StatusCode = "5005" )
Well-known SAT status codes. The SAT returns many more; these are the ones a caller commonly needs to branch on.
func (StatusCode) Description ¶
func (c StatusCode) Description() string
Description returns the known SAT meaning of the code, or "" if unknown.
type StatusError ¶
type StatusError struct {
Code StatusCode
Message string
// Operation is the SAT operation that produced the error (e.g. "SolicitaDescarga").
Operation string
}
StatusError wraps a non-successful SAT status code with its message.
func AsStatusError ¶
func AsStatusError(err error) (*StatusError, bool)
AsStatusError returns the *StatusError in err's chain, if any.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package backfill orchestrates downloading a whole date range from the SAT: it splits the range into periods, submits a SolicitaDescarga per period, polls until each is ready, downloads every package and hands it to a callback.
|
Package backfill orchestrates downloading a whole date range from the SAT: it splits the range into periods, submits a SolicitaDescarga per period, polls until each is ready, downloads every package and hands it to a callback. |
|
cmd
|
|
|
nibus-sat-ws
command
Command nibus-sat-ws is a CLI for the SAT Descarga Masiva web service.
|
Command nibus-sat-ws is a CLI for the SAT Descarga Masiva web service. |
|
Package credential loads and uses a Mexican SAT e.firma (FIEL) — parsing the public certificate (.cer, DER X.509) and the encrypted private key (.key, encrypted PKCS#8 DER), and signing data with it.
|
Package credential loads and uses a Mexican SAT e.firma (FIEL) — parsing the public certificate (.cer, DER X.509) and the encrypted private key (.key, encrypted PKCS#8 DER), and signing data with it. |
|
examples
|
|
|
authenticate
command
Command authenticate loads a FIEL and obtains a SAT Descarga Masiva token.
|
Command authenticate loads a FIEL and obtains a SAT Descarga Masiva token. |
|
descarga
command
Command descarga runs the full Descarga Masiva flow with a real FIEL: Query -> Verify (poll) -> Download.
|
Command descarga runs the full Descarga Masiva flow with a real FIEL: Query -> Verify (poll) -> Download. |
|
inspect
command
Command inspect prints the contents of a DescargaMasiva ZIP package (metadata rows or CFDI documents).
|
Command inspect prints the contents of a DescargaMasiva ZIP package (metadata rows or CFDI documents). |
|
validate-fiel
command
Command validate-fiel loads a FIEL (e.firma) and prints its validation status.
|
Command validate-fiel loads a FIEL (e.firma) and prints its validation status. |
|
Package satpackage reads the ZIP packages returned by DescargaMasiva: either CFDI packages (containing .xml documents) or Metadata packages (a single tilde-delimited .txt with one row per CFDI).
|
Package satpackage reads the ZIP packages returned by DescargaMasiva: either CFDI packages (containing .xml documents) or Metadata packages (a single tilde-delimited .txt with one row per CFDI). |
|
Package service implements the four SAT "Descarga Masiva" web-service operations: Authenticate, Query (SolicitaDescarga), Verify (VerificaSolicitudDescarga) and Download (DescargaMasiva).
|
Package service implements the four SAT "Descarga Masiva" web-service operations: Authenticate, Query (SolicitaDescarga), Verify (VerificaSolicitudDescarga) and Download (DescargaMasiva). |
|
Package transport builds http.Clients for talking to the SAT, including routing through a proxy — the SAT geo-blocks non-Mexican egress, so callers running outside Mexico must provide a Mexican proxy.
|
Package transport builds http.Clients for talking to the SAT, including routing through a proxy — the SAT geo-blocks non-Mexican egress, so callers running outside Mexico must provide a Mexican proxy. |
|
Package xmlsig builds the WS-Security signed SOAP envelopes required by the SAT "Descarga Masiva" web service.
|
Package xmlsig builds the WS-Security signed SOAP envelopes required by the SAT "Descarga Masiva" web service. |