Class: Cielo::Transaction

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

Instance Method Summary collapse

Constructor Details

#initializeTransaction

Returns a new instance of Transaction.



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

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

Instance Method Details

#catch!(cielo_tid) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/cielo/transaction.rb', line 41

def catch!(cielo_tid)
  return nil unless cielo_tid
  message = xml_builder("requisicao-captura", :before) do |xml|
    xml.tid "#{cielo_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
# File 'lib/cielo/transaction.rb', line 7

def create!(parameters={})
  analysis_parameters(parameters)
  message = xml_builder("requisicao-transacao") do |xml|
    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
    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!(cielo_tid) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cielo/transaction.rb', line 32

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