Assembles the processed documents that are archived and delivered: the signed
document plus SEFAZ's answer (NFePHP's Complements).
| Function | Result | Parts |
|---|---|---|
nfe_proc/2 | nfeProc | NFe + protNFe |
event_proc/2 | procEventoNFe | evento + retEvento |
void_proc/2 | procInutNFe | inutNFe + retInutNFe |
cancel_register/2 | the same nfeProc | + the cancellation's retEvento |
Bytes are spliced, never re-serialised (AD-011)
The signature covers the document exactly as it was sent, and the protocol is SEFAZ's own. Both are copied byte for byte out of what the caller passed (the signed document, the SOAP body of the answer) and wrapped; nothing is parsed and written back. The only thing removed is the XML declaration of the inner document, which a wrapper cannot carry twice. The wrapper declares the NF-e namespace, which is what lets the answer's elements, that inherit it from the SOAP body they were cut from, stay in it.
The answer may be the whole SOAP envelope, the retEnviNFe / retEnvEvento /
retInutNFe or the element itself. Its elements are found unprefixed, the
way SEFAZ sends them.
What is checked
Like NFePHP, an answer is only joined to the document it is about, and only when SEFAZ accepted it:
nfe_proc/2: theprotNFewhosechNFeis the document's key (IdwithoutNFe) and, when both carry one, whosedigValis the document'sDigestValue;cStat100, 150, 120, 110, 205, 301, 302 or 303 (the authorized and the denied ones: a denial is archived too).event_proc/2: theretEventoof the samechNFeandtpEvento;cStat135 or 136, and 155 for a cancellation (110111).void_proc/2:cStat102 and the sameversao,tpAmb,cUF,ano,CNPJ/CPF,mod,serie,nNFIniandnNFFinas the request.cancel_register/2:cStat135, 136 or 155,tpEvento110111 or 110112 (cancelamento por substituição) and thechNFeof thenfeProc.
Each returns {:ok, xml} or {:error, reason}:
:no_protocol,:no_event_return,:no_void_return- the answer has no such element (a receipt, a rejection of the batch);:key_mismatch,:digest_mismatch,{:mismatch, field}- it is about another document;{:not_accepted, c_stat}- SEFAZ did not accept it;{:not_a_cancellation, tp_evento}-cancel_register/2of another event;{:xml, reason}- a part is not XML (SefazNfe.XML).
SefazNfe.Result.xml is what these return, for the authorization, events and
voiding of the facade.
Summary
Functions
Marks an authorized nfeProc as cancelled by appending the cancellation's
retEvento after its protNFe (NFePHP's cancelRegister).
procEventoNFe: the signed evento and the retEvento SEFAZ answered it
with, for a cancellation, a CCe, an EPEC or a manifestação.
Marks an mdfeProc cancelled. See SefazNfe.MDFe.Proc.mdfe_cancel_register/2.
Marks an mdfeProc closed (NFePHP closeRegister). See SefazNfe.MDFe.Proc.mdfe_close_register/2.
procEventoMDFe. See SefazNfe.MDFe.Proc.mdfe_event_proc/2.
mdfeProc (MDF-e 58). See SefazNfe.MDFe.Proc.mdfe_proc/2.
nfeProc: the signed NFe and its protNFe, from the answer of the
authorization or of a protocol query.
procInutNFe: the signed inutNFe and SEFAZ's retInutNFe.
Types
@type reason() :: term()
Functions
Marks an authorized nfeProc as cancelled by appending the cancellation's
retEvento after its protNFe (NFePHP's cancelRegister).
event_xml is the procEventoNFe from event_proc/2 or SEFAZ's answer
itself; the first retEvento that is an accepted cancellation (110111 or
- of the
nfeProc's key is the one appended. It is spliced as received. Registering the sameretEventoagain returns thenfeProcunchanged.
Unlike NFePHP, which returns the nfeProc untouched for anything else, an
answer that does not qualify is an error that says why: :no_protocol (the
nfeProc carries no protNFe), :no_event_return, :key_mismatch,
{:not_a_cancellation, tp_evento} or {:not_accepted, c_stat}.
procEventoNFe: the signed evento and the retEvento SEFAZ answered it
with, for a cancellation, a CCe, an EPEC or a manifestação.
signed_event_xml is the signed evento (or an envEvento holding it).
Marks an mdfeProc cancelled. See SefazNfe.MDFe.Proc.mdfe_cancel_register/2.
Marks an mdfeProc closed (NFePHP closeRegister). See SefazNfe.MDFe.Proc.mdfe_close_register/2.
procEventoMDFe. See SefazNfe.MDFe.Proc.mdfe_event_proc/2.
mdfeProc (MDF-e 58). See SefazNfe.MDFe.Proc.mdfe_proc/2.
nfeProc: the signed NFe and its protNFe, from the answer of the
authorization or of a protocol query.
procInutNFe: the signed inutNFe and SEFAZ's retInutNFe.