Class: Nfcom::Parsers::Autorizacao

Inherits:
Base
  • Object
show all
Defined in:
lib/nfcom/parsers/autorizacao.rb

Instance Attribute Summary

Attributes inherited from Base

#document

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Nfcom::Parsers::Base

Instance Method Details

#parseObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nfcom/parsers/autorizacao.rb', line 6

def parse
  ret = find('//nfcom:retNFCom')
  raise Errors::NotaRejeitada.new('000', 'Resposta inválida') unless ret

  c_stat   = xpath(ret, './/nfcom:cStat')
  x_motivo = xpath(ret, './/nfcom:xMotivo')

  raise Errors::NotaRejeitada.new(c_stat, x_motivo) unless c_stat == '100'

  prot = ret.at_xpath('.//nfcom:protNFCom', nfcom_namespaces)

  {
    autorizada: true,
    protocolo: xpath(prot, './/nfcom:nProt'),
    chave: xpath(prot, './/nfcom:chNFCom'),
    data_autorizacao: xpath(prot, './/nfcom:dhRecbto'),
    xml: prot&.to_xml,
    mensagem: x_motivo
  }
end