Class: BrNfe::Product::Response::Build::NfeAutorizacao
- Inherits:
-
Base
- Object
- ActiveModelBase
- Base
- BrNfe::Product::Response::Build::NfeAutorizacao
- Defined in:
- lib/br_nfe/product/response/build/nfe_autorizacao.rb
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from ActiveModelBase
Instance Method Summary collapse
- #async_protocol ⇒ Object
- #manage_invoices! ⇒ Object
- #node_prot_nfe ⇒ Object
- #notas_fiscais ⇒ Object
- #paths ⇒ Object
-
#response_class ⇒ Object
Responsável por definir qual classe será instânciada para setar os valores de retorno referentes a cada operação.
-
#set_invoice_protocol!(invoice, prot_nfe) ⇒ Object
Seta na nota fiscal os valores presentes no protocolo de autorização Quando a nota fiscal for autorizada, também adiciona o protocolo de autorização no XML da nota fiscal.
-
#specific_attributes ⇒ Object
Responsável por setar os atributos específicos para cada tipo de operação.
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
#async_protocol ⇒ Object
57 58 59 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 57 def async_protocol @async_protocol ||= body_xml.xpath(paths[:async_protocol], paths[:namespaces]).text end |
#manage_invoices! ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 65 def manage_invoices! if async_protocol.present? notas_fiscais.each do |nf| nf.protocol = async_protocol nf.processed_at = request_processed_at nf.status_code = get_processing_status_code nf.status_motive = get_processing_status_motive end elsif node_prot_nfe.present? notas_fiscais.each do |nfe| prot_nfe = parse_nokogiri_xml( node_prot_nfe.to_xml ) set_invoice_protocol!(nfe, prot_nfe) end end end |
#node_prot_nfe ⇒ Object
61 62 63 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 61 def node_prot_nfe body_xml.xpath(paths[:prot_nfe], paths[:namespaces]) end |
#notas_fiscais ⇒ Object
11 12 13 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 11 def notas_fiscais operation.notas_fiscais end |
#paths ⇒ Object
7 8 9 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 7 def paths operation.gateway_settings[:xml_paths][:autorizacao][:return_paths] end |
#response_class ⇒ Object
Responsável por definir qual classe será instânciada para setar os valores de retorno referentes a cada operação.
Type: Class
20 21 22 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 20 def response_class BrNfe::Product::Response::NfeAutorizacao end |
#set_invoice_protocol!(invoice, prot_nfe) ⇒ Object
Seta na nota fiscal os valores presentes no protocolo de autorização Quando a nota fiscal for autorizada, também adiciona o protocolo de autorização no XML da nota fiscal
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 85 def set_invoice_protocol! invoice, prot_nfe invoice.processed_at = get_processed_at_from_prot_nfe( prot_nfe ) invoice.protocol = get_protocol_from_prot_nfe( prot_nfe ) invoice.digest_value = get_digest_value_from_prot_nfe( prot_nfe ) invoice.status_code = get_status_code_from_prot_nfe( prot_nfe ) invoice.status_motive = get_status_motive_from_prot_nfe( prot_nfe ) invoice.chave_de_acesso = get_access_key_from_prot_nfe( prot_nfe ) # Seta o XML da respectiva NF-e no objeto já com a tag <nfeProc> # e a tag do protocolo(<protNFe>) set_invoice_xml_with_prot_nfe!( invoice, prot_nfe ) if invoice.status == :success end |
#specific_attributes ⇒ Object
Responsável por setar os atributos específicos para cada tipo de operação.
Type: Hash
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 29 def specific_attributes attrs = { environment: body_xml.xpath(paths[:ambiente], paths[:namespaces]).text, app_version: body_xml.xpath(paths[:app_version], paths[:namespaces]).text, processed_at: request_processed_at, processing_status_code: get_processing_status_code, processing_status_motive: get_processing_status_motive, } if async_protocol.present? # Se entrar aqui é porque o lote é assíncrono e tem um protocolo attrs[:protocol] = async_protocol attrs[:average_time] = body_xml.xpath(paths[:average_time], paths[:namespaces]).text end manage_invoices! attrs[:notas_fiscais] = notas_fiscais # Notas fiscais sincronas só podem ter uma nota fiscal no lote # então o protocolo da resposta é igual ao da nota fiscal # if async_protocol.blank? && notas_fiscais.size == 1 attrs[:protocol] ||= notas_fiscais.first.protocol end attrs end |