SefazNfe.MDFe.Proc (sefaz_nfe v0.5.0)

Copy Markdown View Source

The processed MDF-e documents (NFePHP's Complements for sped-mdfe), reached through SefazNfe.Proc as mdfe_proc/2, mdfe_event_proc/2, mdfe_cancel_register/2 and mdfe_close_register/2.

FunctionResultParts
mdfe_proc/2mdfeProcMDFe + protMDFe
mdfe_event_proc/2procEventoMDFeeventoMDFe + retEventoMDFe
mdfe_cancel_register/2the same mdfeProc+ the cancellation's retEventoMDFe
mdfe_close_register/2the same mdfeProc+ the encerramento's retEventoMDFe

Bytes are spliced, never re-serialised, exactly as in SefazNfe.Proc (AD-011): the signed MDFe (with its infMDFeSupl) and SEFAZ's own protMDFe or retEventoMDFe are copied verbatim and wrapped in the MDF-e namespace.

What is checked

  • mdfe_proc/2: the protMDFe whose chMDFe is the document's key (Id without MDFe) and, when both carry one, whose digVal is the document's DigestValue; cStat 100 only (MDF-e has no denial).
  • mdfe_event_proc/2: the retEventoMDFe of the same chMDFe and tpEvento; cStat 135 or 136 (and 132 for an encerramento).
  • the registers: cStat 135, 136 or 155 (and 132 for an encerramento), the right tpEvento (110111, or 110112) and the chMDFe of the mdfeProc.

Errors are those of SefazNfe.Proc with MDF-e names: :no_protocol, :no_event, :no_event_return, :key_mismatch, :digest_mismatch, :no_inf_mdfe, {:not_accepted, c_stat}, {:not_a_cancellation, tp_evento}, {:not_a_closure, tp_evento}, :not_an_mdfe_proc and {:xml, reason}.

Summary

Functions

Marks an authorized mdfeProc as cancelled by appending the cancellation's retEventoMDFe after its protMDFe (NFePHP's cancelRegister).

Marks an authorized mdfeProc as closed (encerrado) by appending the encerramento's retEventoMDFe (NFePHP's closeRegister). Same rules as mdfe_cancel_register/2 for event 110112, with {:not_a_closure, tp_evento}.

procEventoMDFe: the signed eventoMDFe and the retEventoMDFe SEFAZ answered it with.

mdfeProc: the signed MDFe and its protMDFe, from the answer of the authorization or of a consultation.

Types

reason()

@type reason() :: term()

Functions

mdfe_cancel_register(mdfe_proc_xml, event_xml)

@spec mdfe_cancel_register(String.t(), String.t()) ::
  {:ok, String.t()} | {:error, reason()}

Marks an authorized mdfeProc as cancelled by appending the cancellation's retEventoMDFe after its protMDFe (NFePHP's cancelRegister).

event_xml is the procEventoMDFe from mdfe_event_proc/2 or SEFAZ's answer itself. Registering the same retEventoMDFe again returns the mdfeProc unchanged. Unlike NFePHP, which returns the document untouched for anything else, an answer that does not qualify is an error that says why.

mdfe_close_register(mdfe_proc_xml, event_xml)

@spec mdfe_close_register(String.t(), String.t()) ::
  {:ok, String.t()} | {:error, reason()}

Marks an authorized mdfeProc as closed (encerrado) by appending the encerramento's retEventoMDFe (NFePHP's closeRegister). Same rules as mdfe_cancel_register/2 for event 110112, with {:not_a_closure, tp_evento}.

mdfe_event_proc(signed_event_xml, response)

@spec mdfe_event_proc(String.t(), String.t()) ::
  {:ok, String.t()} | {:error, reason()}

procEventoMDFe: the signed eventoMDFe and the retEventoMDFe SEFAZ answered it with.

mdfe_proc(signed_mdfe_xml, response)

@spec mdfe_proc(String.t(), String.t()) :: {:ok, String.t()} | {:error, reason()}

mdfeProc: the signed MDFe and its protMDFe, from the answer of the authorization or of a consultation.