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, #nfe_settings, #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



56
57
58
59
60
61
62
63
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 56

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

#pathsObject



7
8
9
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 7

def paths
  operation.gateway_settings[:xml_paths][:retorno_autorizacao][:return_paths]
end

#protocol_nfe_nodesObject

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

Type: Nokogiri::XML::NodeSet



45
46
47
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 45

def protocol_nfe_nodes
  @protocol_nfe_nodes ||= body_xml.xpath(paths[:prot_nfe], paths[:namespaces] )
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



16
17
18
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 16

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



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/br_nfe/product/response/build/nfe_ret_autorizacao.rb', line 27

def specific_attributes
  {
    environment:              body_xml.xpath(paths[:environment],  paths[:namespaces]).text,
    app_version:              body_xml.xpath(paths[:app_version],  paths[:namespaces]).text,
    processed_at:             body_xml.xpath(paths[:processed_at], paths[:namespaces]).text,
    protocol:                 body_xml.xpath(paths[:protocol],     paths[:namespaces]).text,

    processing_status_code:   body_xml.xpath(paths[:processing_status_code],   paths[:namespaces]).text,
    processing_status_motive: body_xml.xpath(paths[:processing_status_motive], paths[:namespaces]).text,

    notas_fiscais:            get_invoices
  }
end