Module: Nfcom::Helpers::Consulta

Defined in:
lib/nfcom/helpers/consulta.rb

Class Method Summary collapse

Class Method Details

.chave_from_xml(xml) ⇒ String

Optional: parse the chave from a full XML string

Parameters:

  • xml (String)

    NFCom XML (as stored in :xml_autorizado)

Returns:

  • (String)

    chave de acesso



22
23
24
25
# File 'lib/nfcom/helpers/consulta.rb', line 22

def self.chave_from_xml(xml)
  doc = Nokogiri::XML(xml)
  doc.at_xpath('//NFCom/infNFCom/@Id')&.value&.sub(/^NFCom/, '')
end

.url(chave:, ambiente: Nfcom.configuration.ambiente) ⇒ String

Returns the URL to confirm an already-authorized NFCom

Parameters:

  • chave (String)

    Chave de acesso da NFCom (44 chars)

  • ambiente (Symbol) (defaults to: Nfcom.configuration.ambiente)

    :homologacao or :producao (optional, defaults to current config)

Returns:

  • (String)

    URL to confirm the nota

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/nfcom/helpers/consulta.rb', line 11

def self.url(chave:, ambiente: Nfcom.configuration.ambiente)
  raise ArgumentError, 'Chave de acesso inválida' unless chave&.length == 44

  tp_amb = (ambiente == :producao ? 1 : 2)
  "https://dfe-portal.svrs.rs.gov.br/nfcom/qrcode?chNFCom=#{chave}&tpAmb=#{tp_amb}"
end