Class: Nfe::Operations::NfeSend

Inherits:
Base
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/nfe/operations/nfe_send.rb

Instance Attribute Summary

Attributes inherited from Base

#errors, #result

Instance Method Summary collapse

Methods inherited from Base

#execute

Constructor Details

#initialize(certificate, private_key, nfe, lot = nil, use_schema: true) ⇒ NfeSend

Returns a new instance of NfeSend.



8
9
10
11
12
13
14
# 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

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/nfe/operations/nfe_send.rb', line 16

def authorized?
  @retEnviNFe.protNFe.cStat == authorized_code
end

#authorized_xmlObject



28
29
30
31
32
33
# 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?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/nfe/operations/nfe_send.rb', line 20

def denied?
  denied_codes.include? @retEnviNFe.protNFe.cStat
end

#messageObject



63
64
65
# File 'lib/nfe/operations/nfe_send.rb', line 63

def message
  @retEnviNFe.protNFe.xMotivo if processed?
end

#nfe_keyObject



53
54
55
56
57
# File 'lib/nfe/operations/nfe_send.rb', line 53

def nfe_key
  if authorized?
    @retEnviNFe.protNFe.chNFe
  end
end

#nfe_statusObject



41
42
43
44
45
46
47
48
49
50
51
# 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?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/nfe/operations/nfe_send.rb', line 59

def processed?
  authorized? || rejected? || denied?
end

#protocol_numberObject



35
36
37
38
39
# File 'lib/nfe/operations/nfe_send.rb', line 35

def protocol_number
  if authorized?
    @retEnviNFe.protNFe.nProt
  end
end

#rejected?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/nfe/operations/nfe_send.rb', line 24

def rejected?
  rejected_code? && !denied?
end