Class: BrNfe::Product::Response::Build::NfeRetAutorizacao

Inherits:
Base show all
Defined in:
lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb

Instance Attribute Summary

Attributes inherited from Base

#operation, #savon_response

Attributes inherited from ActiveModelBase

#reference

Instance Method Summary collapse

Methods inherited from Base

#body_xml, #doc_original_xml, #header_xml, #nf_xmlns, #original_xml, #response, #response_xml, #url_xmlns_retorno, #xml_version, #xml_version_str

Methods inherited from ActiveModelBase

#assign_attributes, #default_values, #initialize

Constructor Details

This class inherits a constructor from BrNfe::ActiveModelBase

Instance Method Details

#get_invoicesObject

Responsável por instânciar as notas fiscais presentes na resposta a partir das tags de resposta do xml (protNFe). Também irá ajustar e setar o xml atualizado na nota fiscal, já com o protocolo incluso. Irá setar a tag nfeProc como raiz do XML.

Type: Array



52
53
54
55
56
57
58
59
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 52

def get_invoices
	invoices = []
	protocol_nfe_nodes.each do |prot_nfe|
		prot_nfe = parse_nokogiri_xml(prot_nfe.to_xml)
		invoices << build_invoice_by_prot_nfe(prot_nfe)
	end
	invoices
end

#protocol_nfe_nodesObject

Responsável por buscar os protocolos no XML da resposta.

Type: Nokogiri::XML::NodeSet



41
42
43
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 41

def protocol_nfe_nodes
	@protocol_nfe_nodes ||= body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:protNFe', nf: nf_xmlns, ret: url_xmlns_retorno)
end

#response_classObject

Responsável por definir qual classe será instânciada para setar os valores de retorno referentes a cada operação.

Type: Class



12
13
14
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 12

def response_class
	BrNfe::Product::Response::NfeRetAutorizacao
end

#specific_attributesObject

Responsável por setar os atributos específicos para cada tipo de operação. Nesse caso irá setar as notas fiscais com seus respectivos XMLs.

Type: Hash



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 23

def specific_attributes
	{
		environment:              body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:tpAmb',    nf: nf_xmlns, ret: url_xmlns_retorno).text,
		app_version:              body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:verAplic', nf: nf_xmlns, ret: url_xmlns_retorno).text,
		processed_at:             body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:dhRecbto', nf: nf_xmlns, ret: url_xmlns_retorno).text,
		protocol:                 body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:nRec',     nf: nf_xmlns, ret: url_xmlns_retorno).text,

		processing_status_code:   body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:cStat',    nf: nf_xmlns, ret: url_xmlns_retorno).text,
		processing_status_motive: body_xml.xpath('//ret:nfeRetAutorizacaoLoteResult/nf:retConsReciNFe/nf:xMotivo',  nf: nf_xmlns, ret: url_xmlns_retorno).text,

		notas_fiscais:            get_invoices
	}
end