Class: Cieloloja::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/cieloloja/transaction.rb

Instance Method Summary collapse

Constructor Details

#initializeTransaction

Returns a new instance of Transaction.



4
5
6
# File 'lib/cieloloja/transaction.rb', line 4

def initialize
  @connection = Cieloloja::Connection.new
end

Instance Method Details

#catch!(cieloloja_tid) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/cieloloja/transaction.rb', line 44

def catch!(cieloloja_tid)
  return nil unless cieloloja_tid
  message = xml_builder("requisicao-captura", :before) do |xml|
    xml.tid "#{cieloloja_tid}"
  end
  make_request! message
end

#create!(parameters = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cieloloja/transaction.rb', line 7

def create!(parameters={})
  analysis_parameters(parameters)
  message = xml_builder("requisicao-transacao") do |xml|

    if parameters[:"numero-cartao"] != nil
      xml.tag!("dados-portador") do
        [:"numero-cartao", :validade, :indicador, :"codigo-seguranca"].each do |key|
          xml.tag!(if key == :"numero-cartao" then "numero" else key.to_s end, parameters[key].to_s)
        end
      end
    end
    xml.tag!("dados-pedido") do
      [:numero, :valor, :moeda, :"data-hora", :idioma].each do |key|
        xml.tag!(key.to_s, parameters[key].to_s)
      end
    end
    xml.tag!("forma-pagamento") do
      [:bandeira, :produto, :parcelas].each do |key|
        xml.tag!(key.to_s, parameters[key].to_s)
      end
    end
    xml.tag!("url-retorno", parameters[:"url-retorno"])
    xml.autorizar parameters[:autorizar].to_s
    xml.capturar parameters[:capturar].to_s
  end
  make_request! message
end

#verify!(cieloloja_tid) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/cieloloja/transaction.rb', line 35

def verify!(cieloloja_tid)
  return nil unless cieloloja_tid
  message = xml_builder("requisicao-consulta", :before) do |xml|
    xml.tid "#{cieloloja_tid}"
  end
  
  make_request! message
end