SefazNfe.CStat (sefaz_nfe v0.5.0)

Copy Markdown View Source

Classifies a SEFAZ cStat into what the host has to do about it.

This is classification, not translation: the library does not ship a cStat dictionary, and the xMotivo SEFAZ sends is the text to show. What the host cannot get from xMotivo is the decision, so the codes whose consequence the MOC 4.00 fixes are named here and every other code falls back to its range.

StatusCodesWhy
:authorized100, 150NF-e authorized (150: outside the deadline)
102number range voided (inutilização homologada)
134, 135, 136, 155event registered (134: with a warning about the document's situation; 155: cancellation homologated outside the deadline)
124EPEC authorized
:denied110, 301, 302, 303uso denegado: the document exists and must be stored; the number is consumed, never retry with it and never reuse it
:cancelled101, 151a consultation found the NF-e cancelled
:closed132a consultation found the MDF-e encerrado (closed): terminal, like :cancelled
:in_operation107service status answer: the service is up (not a rejection)
:batch_received103lote received, collect with the recibo
:batch_processed104, 128lote (128: event lote) processed, the outcome is per item
:processing105lote still being processed, ask again later
:retryable108, 109service paused (momentarily / without forecast)
656consumo indevido: wait at least 1 hour before asking again
999uncatalogued error on SEFAZ's side
:rejectedevery other code200..999 (minus the above) and any unknown 1xx: definitive, fix the document and send again

CT-e (models 57 and 67)

The CT-e MOC 4.00 uses the same codes with the same consequence (100, 101, 110, 134, 135, 136, 107, 108, 109 and 301 included) except one: 678 is "Consumo Indevido" for CT-e, where for NF-e it is an ordinary rejection (NF referenciada com UF diferente). classify/1 cannot tell them apart, so classify/2 takes the model: 678 under 57 or 67 is :retryable (wait about an hour, like 656), and every other code is classify/1. SefazNfe.CTe classifies with it.

On :retryable the same request may be sent again later, unchanged. For an authorization, consult by key first: SEFAZ may have processed the document despite the answer, and a resend would then come back as 204 (duplicidade). On :rejected the request itself is wrong and must change before it is sent again.

Summary

Functions

Maps a cStat to its status/0. Unknown codes are :rejected.

classify/1 for a document model. Only CT-e (57, 67) differs: 678 is :retryable there (Consumo Indevido). See the moduledoc.

Types

status()

@type status() ::
  :authorized
  | :denied
  | :cancelled
  | :closed
  | :in_operation
  | :batch_received
  | :batch_processed
  | :processing
  | :retryable
  | :rejected

Functions

classify(c_stat)

@spec classify(pos_integer()) :: status()

Maps a cStat to its status/0. Unknown codes are :rejected.

classify(c_stat, model)

@spec classify(pos_integer(), pos_integer()) :: status()

classify/1 for a document model. Only CT-e (57, 67) differs: 678 is :retryable there (Consumo Indevido). See the moduledoc.