SefazNfe.SOAP.Envelope (sefaz_nfe v0.1.0)

Copy Markdown View Source

Builds the SOAP 1.2 envelope the 4.00 webservices expect.

Each service takes its message inside nfeDadosMsg, whose namespace is the service's own WSDL namespace — that is what routes the call on the .asmx endpoint, so it is per service rather than global.

The message itself is passed through untouched. For SefazNfe.authorize/1 that matters: the ERP owns the XML and a signed document must reach SEFAZ byte for byte, or the signature breaks (SEFAZ-04).

Summary

Functions

SOAPAction URI for service.

consReciNFe for NFeRetAutorizacao4.

consSitNFe for NFeConsultaProtocolo4.

distDFeInt for NFeDistribuicaoDFe.

envEvento for NFeRecepcaoEvento4, carrying one already signed event.

enviNFe for NFeAutorizacao4, carrying one already signed NF-e.

consStatServ for NFeStatusServico4.

A CPF is 11 digits; anything else is treated as a CNPJ.

tpAmb for an environment: 1 is production, 2 is homologation.

Wraps message for service.

Types

service()

@type service() :: SefazNfe.Endpoints.service()

Functions

action(service)

@spec action(service()) :: {:ok, String.t()} | {:error, {:unknown_service, term()}}

SOAPAction URI for service.

authorization_result(n_rec, tp_amb)

@spec authorization_result(String.t(), 1 | 2) :: binary()

consReciNFe for NFeRetAutorizacao4.

consult_protocol(ch_nfe, tp_amb)

@spec consult_protocol(String.t(), 1 | 2) :: binary()

consSitNFe for NFeConsultaProtocolo4.

dist_dfe(tax_id, uf_code, tp_amb, cursor)

@spec dist_dfe(String.t(), pos_integer(), 1 | 2, {atom(), String.t()}) :: binary()

distDFeInt for NFeDistribuicaoDFe.

The cursor is one of {:ult_nsu, nsu} to walk forward, {:nsu, nsu} for a single document, or {:ch_nfe, key} to fetch one by access key.

send_event(signed_event, id_lote)

@spec send_event(String.t(), String.t()) :: binary()

envEvento for NFeRecepcaoEvento4, carrying one already signed event.

send_nfe(signed_nfe, id_lote, ind_sinc)

@spec send_nfe(String.t(), String.t(), 0 | 1) :: binary()

enviNFe for NFeAutorizacao4, carrying one already signed NF-e.

ind_sinc 1 asks SEFAZ to process the batch in the same call and answer with the protocol; 0 answers a receipt that SefazNfe.authorization_result/1 then consults. The MOC allows up to 50 documents per batch, and v1 sends one.

The signed document is embedded verbatim apart from its XML declaration, which is not allowed inside another document. Touching anything else would break the signature.

status_service(uf_code, tp_amb)

@spec status_service(pos_integer(), 1 | 2) :: binary()

consStatServ for NFeStatusServico4.

xServ is fixed at STATUS; it is the only operation the service defines.

tax_id_element(tax_id)

@spec tax_id_element(String.t()) :: binary()

A CPF is 11 digits; anything else is treated as a CNPJ.

tp_amb(atom)

@spec tp_amb(:production | :homologation) :: 1 | 2

tpAmb for an environment: 1 is production, 2 is homologation.

wrap(service, message)

@spec wrap(service(), iodata()) ::
  {:ok, binary()} | {:error, {:unknown_service, term()}}

Wraps message for service.

The UF services take nfeDadosMsg directly in the body. NFeDistribuicaoDFe nests it one level deeper, inside the operation element — sending it flat makes the Ambiente Nacional answer a null reference from its own .NET stack rather than a cStat.