class Nfe::Operations::NfeSend

Public Class Methods

new(certificate, private_key, nfe, lot=nil, use_schema: true) click to toggle source
Calls superclass method Nfe::Operations::Base::new
# File lib/nfe/operations/nfe_send.rb, line 8
def initialize(certificate, private_key, nfe, lot=nil, use_schema: true)
  super(certificate, private_key, use_schema: use_schema)
  @nfe = nfe
  @lot = lot || lot_default

  @retEnviNFe = Services::Regress::RetEnviNFe.new
end

Public Instance Methods

authorized?() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 16
def authorized?
  @retEnviNFe.protNFe.cStat == authorized_code
end
authorized_xml() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 28
def authorized_xml
  if authorized?
    nfeProc = Nfe::Models::NFeProc.new(@nfe, @retEnviNFe.protNFe)
    nfeProc.to_xml
  end
end
denied?() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 20
def denied?
  denied_codes.include? @retEnviNFe.protNFe.cStat
end
message() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 63
def message
  @retEnviNFe.protNFe.xMotivo if processed?
end
nfe_key() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 53
def nfe_key
  if authorized?
    @retEnviNFe.protNFe.chNFe
  end
end
nfe_status() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 41
def nfe_status
  if authorized?
    :authorized
  elsif denied?
    :denied
  elsif rejected?
    :rejected
  else
    :pending
  end
end
processed?() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 59
def processed?
  authorized? || rejected? || denied?
end
protocol_number() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 35
def protocol_number
  if authorized?
    @retEnviNFe.protNFe.nProt
  end
end
rejected?() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 24
def rejected?
  rejected_code? && !denied?
end

Protected Instance Methods

before_execute() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 68
def before_execute
  sign @nfe, @nfe.infNFe.id
  @object = Services::Dispatch::EnviNFe.new(@nfe, @lot, ws_info.version)
end
handle_result(xml) click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 77
def handle_result(xml)
  @retEnviNFe.parse! xml

  if !processed_lot_code.include? @retEnviNFe.cStat
    errors.add(:base, @retEnviNFe.xMotivo)
  end

  @retEnviNFe
end
schema_name() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 91
def schema_name
  ws_info.schema
end
ws_info() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 73
def ws_info
  Webservices::Wsinfo::NfeSend.new(environment, uf)
end
xpath() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 87
def xpath
  "//ns:retEnviNFe"
end

Private Instance Methods

authorized_code() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 96
def authorized_code
  100
end
denied_codes() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 104
def denied_codes
  [301, 302]
end
environment() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 116
def environment
  @nfe.infNFe.ide.tpAmb
end
lot_default() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 120
def lot_default
  "#{@nfe.infNFe.ide.serie}#{@nfe.infNFe.ide.nNF}".to_i
end
processed_lot_code() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 100
def processed_lot_code
  [104, 110]
end
rejected_code?() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 108
def rejected_code?
  @retEnviNFe.protNFe.cStat.to_i > 200
end
uf() click to toggle source
# File lib/nfe/operations/nfe_send.rb, line 112
def uf
  Nfe::Helpers::UfHelper.acronym(@nfe.infNFe.ide.cUF)
end