Skip to content

Commit

Permalink
Get token generation working with buy page store transaction and adding
Browse files Browse the repository at this point in the history
a method to request authorization for a transaction created previously.
  • Loading branch information
wilbert committed Jan 21, 2014
1 parent 08217b3 commit 94cb00f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ gem 'builder', ">= 2.0.0"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "bundler"
gem "jeweler"
gem 'watir-webdriver'
gem "shoulda", ">= 0"
gem "bundler"
gem "jeweler"
gem "rspec"
gem "fakeweb"
end
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ GEM
addressable (2.3.5)
atomic (1.1.14)
builder (3.2.2)
childprocess (0.4.0)
ffi (~> 1.0, >= 1.0.11)
diff-lcs (1.2.5)
fakeweb (1.3.0)
faraday (0.8.8)
multipart-post (~> 1.2.0)
ffi (1.9.3)
git (1.2.6)
github_api (0.10.1)
addressable
Expand Down Expand Up @@ -62,6 +65,12 @@ GEM
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rubyzip (1.1.0)
selenium-webdriver (2.39.0)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
Expand All @@ -71,6 +80,9 @@ GEM
thread_safe (0.1.3)
atomic
tzinfo (0.3.38)
watir-webdriver (0.6.4)
selenium-webdriver (>= 2.18.0)
websocket (1.0.7)

PLATFORMS
ruby
Expand All @@ -84,3 +96,4 @@ DEPENDENCIES
jeweler
rspec
shoulda
watir-webdriver
10 changes: 9 additions & 1 deletion lib/cielo/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def catch!(cielo_tid)
@connection.make_request! message
end

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

private
def default_transaction_xml(xml, parameters)
xml.tag!("dados-pedido") do
Expand All @@ -81,7 +89,7 @@ def analysis_parameters(parameters={}, buy_page = :buy_page_cielo)
to_analyze = [:numero, :valor, :bandeira, :"url-retorno"]

if buy_page == :buy_page_store
if parameters[:token]
if parameters[:token].present?
to_analyze.concat([:token])
else
to_analyze.concat([:cartao_numero, :cartao_validade, :cartao_seguranca, :cartao_portador])
Expand Down
40 changes: 24 additions & 16 deletions spec/cielo/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:default_params) { {:numero => "1", :valor => "100", :bandeira => "visa", :"url-retorno" => "http://some.thing.com"} }
let(:card_params) { { :cartao_numero => '4012888888881881', :cartao_validade => '201508', :cartao_indicador => '1', :cartao_seguranca => '973', :cartao_portador => 'Nome portador' } }
let(:card_token_params) { { :cartao_numero => '4012888888881881', :cartao_validade => '201508', :cartao_portador => 'Nome portador' } }
let(:authentication_card_params){ { :cartao_numero => '5453010000066167', :cartao_validade => '201805', :cartao_seguranca => "123", :cartao_portador => "Nome portador" }}

before do
@transaction = Cielo::Transaction.new
Expand Down Expand Up @@ -34,10 +35,16 @@
# 7 is when transactions was not autenticated
response[:transacao][:autenticacao][:eci].should eq("7")
end
end

describe "create a recurring transaction with token" do
before do
Cielo.stub(:numero_afiliacao).and_return('1006993069')
Cielo.stub(:chave_acesso).and_return('25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3')

FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
:body => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><retorno-token versao=\"1.2.1\" id=\"57239017\" xmlns=\"http://ecommerce.cbmp.com.br\"><token><dados-token><codigo-token>TuS6LeBHWjqFFtE7S3zR052Jl/KUlD+tYJFpAdlA87E=</codigo-token><status>1</status><numero-cartao-truncado>455187******0183</numero-cartao-truncado></dados-token></token></retorno-token>", :content_type => "application/xml")

response = @token.create! card_token_params, :store
token = response[:"retorno-token"][:token][:"dados-token"][:"codigo-token"]

Expand All @@ -56,26 +63,27 @@
end
end

# Error on system whe uses gerar-token => true (Verify with Cielo)
# describe "create a buy page store transaction with token generation" do
# before do
# Cielo.stub(:numero_afiliacao).and_return('1006993069')
# Cielo.stub(:chave_acesso).and_return('25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3')
# Error on system when uses gerar-token => true (Verify with Cielo)
describe "create a buy page store transaction with token generation" do
before do
FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
:body => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><transacao versao=\"1.2.1\" id=\"1390315327\" xmlns=\"http://ecommerce.cbmp.com.br\"><tid>10069930690DCC341001</tid><pan>52WC7RsmcNuEUSjrYWAEhCOjoLMnMCm4KMTQBqN7PdM=</pan><dados-pedido><numero>1</numero><valor>100</valor><moeda>986</moeda><data-hora>2014-01-21T12:42:08.865-02:00</data-hora><idioma>PT</idioma><taxa-embarque>0</taxa-embarque></dados-pedido><forma-pagamento><bandeira>visa</bandeira><produto>1</produto><parcelas>1</parcelas></forma-pagamento><status>6</status><autenticacao><codigo>6</codigo><mensagem>Transacao sem autenticacao</mensagem><data-hora>2014-01-21T12:42:08.872-02:00</data-hora><valor>100</valor><eci>7</eci></autenticacao><autorizacao><codigo>6</codigo><mensagem>Transa??o autorizada</mensagem><data-hora>2014-01-21T12:42:08.885-02:00</data-hora><valor>100</valor><lr>00</lr><arp>123456</arp><nsu>904244</nsu></autorizacao><captura><codigo>6</codigo><mensagem>Transacao capturada com sucesso</mensagem><data-hora>2014-01-21T12:42:08.912-02:00</data-hora><valor>100</valor></captura><token><dados-token><codigo-token>2ta/YqYaeyolf2NHkBWO8grPqZE44j3PvRAQxVQQGgE=</codigo-token><status>1</status><numero-cartao-truncado>401288******1881</numero-cartao-truncado></dados-token></token></transacao>", :content_type => "application/xml")

Cielo.stub(:numero_afiliacao).and_return('1006993069')
Cielo.stub(:chave_acesso).and_return('25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3')

# default_params.merge!(:"gerar-token" => false)
default_params.merge!(:"gerar-token" => true, :autorizar => 3)

# @params = default_params.merge(card_params)
# end
@params = default_params.merge(card_params)
end

# it 'delivers an successful message and have a card token' do
# response = @transaction.create! @params, :store
it 'delivers an successful message and have a card token' do
response = @transaction.create! @params, :store

# response[:transacao][:tid].should_not be_nil
# response[:transacao][:"url-autenticacao"].should_not be_nil
# # Verifies if token is not nil, it can be used for future transactions
# response[:transacao][:"codigo-token"].should_not be_nil
# end
# end
response[:transacao][:tid].should_not be_nil
response[:transacao][:token][:"dados-token"][:"codigo-token"].should_not be_nil
end
end

describe "create a buy page store transaction" do
before do
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'cielo'
require 'fakeweb'
require 'watir-webdriver'

FakeWeb.allow_net_connect = true
FakeWeb.allow_net_connect = false

0 comments on commit 94cb00f

Please sign in to comment.