cielo-loja 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "activesupport", ">= 3.0.7"
5
+ gem "i18n"
6
+ gem 'builder', ">= 2.0.0", "< 3.1.0"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "bundler"
13
+ gem "jeweler", "~> 1.8.3"
14
+ gem "rspec"
15
+ gem "fakeweb"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.3)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ builder (3.0.0)
8
+ diff-lcs (1.1.3)
9
+ fakeweb (1.3.0)
10
+ git (1.2.5)
11
+ i18n (0.6.0)
12
+ jeweler (1.8.3)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.7.3)
18
+ multi_json (1.3.4)
19
+ rake (0.9.2.2)
20
+ rdoc (3.12)
21
+ json (~> 1.4)
22
+ rspec (2.10.0)
23
+ rspec-core (~> 2.10.0)
24
+ rspec-expectations (~> 2.10.0)
25
+ rspec-mocks (~> 2.10.0)
26
+ rspec-core (2.10.0)
27
+ rspec-expectations (2.10.0)
28
+ diff-lcs (~> 1.1.3)
29
+ rspec-mocks (2.10.1)
30
+ shoulda (3.0.1)
31
+ shoulda-context (~> 1.0.0)
32
+ shoulda-matchers (~> 1.0.0)
33
+ shoulda-context (1.0.0)
34
+ shoulda-matchers (1.0.0)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ activesupport (>= 3.0.7)
41
+ builder (>= 2.0.0, < 3.1.0)
42
+ bundler
43
+ fakeweb
44
+ i18n
45
+ jeweler (~> 1.8.3)
46
+ rspec
47
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Crafters Software Studio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = cielo
2
+
3
+ Integração com a Cielo via WebServices
4
+
5
+ == Funcionalidades Implementadas
6
+
7
+ * Criação de transação
8
+ * Consulta de stauts de transação
9
+ * Caputra de transação
10
+
11
+ == USO
12
+
13
+ gem install cielo
14
+
15
+ === Ambiente de teste (Homologação)
16
+
17
+ transaction = Cielo::Transaction.new
18
+ transaction.create!(numero: "XXX", valor: "123123", moeda: "BRL", ...) #inicia uma nova transação
19
+ transaction.verify!("TID OF THE TRANSACTION") #verifica o status de uma transação
20
+ transaction.catch!("TID OF THE TRANSACTION") #captura a transação
21
+
22
+ === Rails
23
+
24
+ rails g cielo:install
25
+
26
+ Esse comando vai gerar um arquivo config/initializers/cielo.rb que já vem configurado para o ambiente de testes, para produção garanta que os dados estão corretos.
27
+
28
+ === Outras plataformas
29
+
30
+ Se torna necessário somente configurar o módulo Cielo
31
+
32
+ Cielo.setup do |config|
33
+ config.environment = :test #:production
34
+ config.numero_afiliacao = "XXX" # fornecido pela cielo
35
+ config.chave_acesso = "XXX" # fornecido pela cielo
36
+ config.return_path = "http://path/to" # URL para onde a cielo redirecionara seu usuário após inserir os dados na cielo.
37
+ end
38
+
39
+ == Avisos
40
+
41
+ * O retorno da cielo é convertido em um hash, então, atributos no xml como url-retorno ficam :"url-retorno", cuidado com esses detalhes.
42
+ * Foi desenvolvido e testado em ruby 1.9.2 e 1.8.7
43
+
44
+ == Contributing to cielo
45
+
46
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
47
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
48
+ * Fork the project
49
+ * Start a feature/bugfix branch
50
+ * Commit and push until you are happy with your contribution
51
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
52
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
53
+
54
+ == Colaboradores
55
+
56
+ * Felipe Rodrigues [ http://github/felipero http://twitter.com/felipero ]
57
+ * Rafael Felix [ http://github/fellix http://twitter.com/rs_felix ]
58
+ * Gabriel Paladino and Scupen [https://github.com/gabpaladino , https://github.com/scupen] (Ruby 1.8.7 support)
59
+
60
+ == Copyright
61
+
62
+ Copyright (c) 2011 Crafters Software Studio. See LICENSE.txt for
63
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require "rspec/core/rake_task"
14
+ RSpec::Core::RakeTask.new
15
+
16
+ require 'jeweler'
17
+ require './lib/cielo/version.rb'
18
+ Jeweler::Tasks.new do |gem|
19
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
20
+ gem.name = "cielo"
21
+ gem.homepage = "http://github.com/crafters/cielo"
22
+ gem.license = "MIT"
23
+ gem.summary = %Q{Integração com a cielo}
24
+ gem.description = %Q{Integração com a cielo}
25
+ gem.email = "crafters@crafters.com.br"
26
+ gem.authors = ["Crafters Software Studio", "Rafael Felix", "Felipe Rodrigues"]
27
+ gem.version = Cielo::Version::STRING
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ task :default => :test
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "cielo #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/cielo.gemspec ADDED
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cielo-loja"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Giulliano Bueno"]
12
+ s.date = "2012-07-19"
13
+ s.description = "Integra\u{e7}\u{e3}o com a cielo"
14
+ s.email = "giubueno@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "cielo.gemspec",
27
+ "lib/cielo.rb",
28
+ "lib/cielo/connection.rb",
29
+ "lib/cielo/transaction.rb",
30
+ "lib/cielo/version.rb",
31
+ "lib/generators/cielo/install_generator.rb",
32
+ "lib/generators/templates/cielo.rb",
33
+ "spec/cielo/connection_spec.rb",
34
+ "spec/cielo/transaction_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = "http://github.com/giubueno/cielo-loja"
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.24"
41
+ s.summary = "Integra\u{e7}\u{e3}o com a cielo usando BuyPage loja."
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.7"])
48
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
49
+ s.add_runtime_dependency(%q<builder>, ["< 3.1.0", ">= 2.0.0"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<bundler>, [">= 0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ s.add_development_dependency(%q<rspec>, [">= 0"])
54
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<activesupport>, [">= 3.0.7"])
57
+ s.add_dependency(%q<i18n>, [">= 0"])
58
+ s.add_dependency(%q<builder>, ["< 3.1.0", ">= 2.0.0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
62
+ s.add_dependency(%q<rspec>, [">= 0"])
63
+ s.add_dependency(%q<fakeweb>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<activesupport>, [">= 3.0.7"])
67
+ s.add_dependency(%q<i18n>, [">= 0"])
68
+ s.add_dependency(%q<builder>, ["< 3.1.0", ">= 2.0.0"])
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<bundler>, [">= 0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
72
+ s.add_dependency(%q<rspec>, [">= 0"])
73
+ s.add_dependency(%q<fakeweb>, [">= 0"])
74
+ end
75
+ end
76
+
data/lib/cielo.rb ADDED
@@ -0,0 +1,35 @@
1
+ #encoding: utf-8
2
+ require 'active_support/core_ext/class/attribute_accessors'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
+ require 'active_support/core_ext/hash'
5
+ require "net/http"
6
+ require "rexml/document"
7
+ require "builder"
8
+ [:connection, :transaction].each { |lib| require "cielo/#{lib}" }
9
+
10
+ module Cielo
11
+
12
+ class Production
13
+ BASE_URL = "ecommerce.cbmp.com.br"
14
+ WS_PATH = "/servicos/ecommwsec.do"
15
+ end
16
+
17
+ class Test
18
+ BASE_URL = "qasecommerce.cielo.com.br"
19
+ WS_PATH = "/servicos/ecommwsec.do"
20
+ end
21
+
22
+ @@environment = :test
23
+ mattr_accessor :environment
24
+ @@numero_afiliacao = "1001734898"
25
+ mattr_accessor :numero_afiliacao
26
+ @@chave_acesso="e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832"
27
+ mattr_accessor :chave_acesso
28
+ @@return_path = "http://localhost:3000"
29
+ mattr_accessor :return_path
30
+
31
+ def self.setup
32
+ yield self
33
+ end
34
+ class MissingArgumentError < StandardError; end
35
+ end
@@ -0,0 +1,22 @@
1
+ module Cielo
2
+ class Connection
3
+ attr_reader :environment
4
+ def initialize
5
+ @environment = eval(Cielo.environment.to_s.capitalize)
6
+ port = 443
7
+ @http = Net::HTTP.new(@environment::BASE_URL,port)
8
+ @http.use_ssl = true
9
+ @http.open_timeout = 10*1000
10
+ @http.read_timeout = 40*1000
11
+ end
12
+
13
+ def request!(params={})
14
+ str_params = ""
15
+ params.each do |key, value|
16
+ str_params+="&" unless str_params.empty?
17
+ str_params+="#{key}=#{value}"
18
+ end
19
+ @http.request_post(self.environment::WS_PATH, str_params)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,107 @@
1
+ #encoding: utf-8
2
+ module Cielo
3
+ class Transaction
4
+ def initialize
5
+ @connection = Cielo::Connection.new
6
+ end
7
+ def create!(parameters={})
8
+ analysis_parameters(parameters)
9
+ message = xml_builder("requisicao-transacao") do |xml|
10
+ xml.tag!("dados-portador") do
11
+ [:"numero-cartao", :validade, :indicador, :"codigo-seguranca"].each do |key|
12
+ xml.tag!(if key == :"numero-cartao" then "numero" else key.to_s end, parameters[key].to_s)
13
+ end
14
+ end
15
+ xml.tag!("dados-pedido") do
16
+ [:numero, :valor, :moeda, :"data-hora", :idioma].each do |key|
17
+ xml.tag!(key.to_s, parameters[key].to_s)
18
+ end
19
+ end
20
+ xml.tag!("forma-pagamento") do
21
+ [:bandeira, :produto, :parcelas].each do |key|
22
+ xml.tag!(key.to_s, parameters[key].to_s)
23
+ end
24
+ end
25
+ xml.tag!("url-retorno", parameters[:"url-retorno"])
26
+ xml.autorizar parameters[:autorizar].to_s
27
+ xml.capturar parameters[:capturar].to_s
28
+ end
29
+ make_request! message
30
+ end
31
+
32
+ def verify!(cielo_tid)
33
+ return nil unless cielo_tid
34
+ message = xml_builder("requisicao-consulta", :before) do |xml|
35
+ xml.tid "#{cielo_tid}"
36
+ end
37
+
38
+ make_request! message
39
+ end
40
+
41
+ def catch!(cielo_tid)
42
+ return nil unless cielo_tid
43
+ message = xml_builder("requisicao-captura", :before) do |xml|
44
+ xml.tid "#{cielo_tid}"
45
+ end
46
+ make_request! message
47
+ end
48
+
49
+ private
50
+ def analysis_parameters(parameters={})
51
+ [:numero, :valor, :bandeira, :"url-retorno"].each do |parameter|
52
+ raise Cielo::MissingArgumentError, "Required parameter #{parameter} not found" unless parameters[parameter]
53
+ end
54
+ parameters.merge!(:moeda => "986") unless parameters[:moeda]
55
+ parameters.merge!(:"data-hora" => Time.now.strftime("%Y-%m-%dT%H:%M:%S")) unless parameters[:"data-hora"]
56
+ parameters.merge!(:idioma => "PT") unless parameters[:idioma]
57
+ parameters.merge!(:produto => "1") unless parameters[:produto]
58
+ parameters.merge!(:parcelas => "1") unless parameters[:parcelas]
59
+ parameters.merge!(:autorizar => "2") unless parameters[:autorizar]
60
+ parameters.merge!(:capturar => "true") unless parameters[:capturar]
61
+ parameters.merge!(:"url-retorno" => Cielo.return_path) unless parameters[:"url-retorno"]
62
+ parameters
63
+ end
64
+
65
+ def xml_builder(group_name, target=:after, &block)
66
+ xml = Builder::XmlMarkup.new
67
+ xml.instruct! :xml, :version=>"1.0", :encoding=>"ISO-8859-1"
68
+ xml.tag!(group_name, :id => "#{Time.now.to_i}", :versao => "1.1.0") do
69
+ block.call(xml) if target == :before
70
+ xml.tag!("dados-ec") do
71
+ xml.numero Cielo.numero_afiliacao
72
+ xml.chave Cielo.chave_acesso
73
+ end
74
+ block.call(xml) if target == :after
75
+ end
76
+ xml
77
+ end
78
+
79
+ def make_request!(message)
80
+ params = { :mensagem => message.target! }
81
+
82
+ result = @connection.request! params
83
+ parse_response(result)
84
+ end
85
+
86
+ def parse_response(response)
87
+ case response
88
+ when Net::HTTPSuccess
89
+ document = REXML::Document.new(response.body)
90
+ parse_elements(document.elements)
91
+ else
92
+ {:erro => { :codigo => "000", :mensagem => "Impossível contactar o servidor"}}
93
+ end
94
+ end
95
+ def parse_elements(elements)
96
+ map={}
97
+ elements.each do |element|
98
+ element_map = {}
99
+ element_map = element.text if element.elements.empty? && element.attributes.empty?
100
+ element_map.merge!("value" => element.text) if element.elements.empty? && !element.attributes.empty?
101
+ element_map.merge!(parse_elements(element.elements)) unless element.elements.empty?
102
+ map.merge!(element.name => element_map)
103
+ end
104
+ map.symbolize_keys
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,8 @@
1
+ module Cielo
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ PATCH = 1
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ module Cielo
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Cria o initializer da cielo na app rails"
7
+
8
+ def copy_initializer
9
+ template "cielo.rb", "config/initializers/cielo.rb"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ # Use esse arquivo para configurar a integração com a cielo.
3
+ Cielo.setup do |config|
4
+ # Altere para production ao final dos seus testes
5
+ # config.environment = :test
6
+
7
+ # Número de afiliação fornecido pela cielo.
8
+ # O numero padrão é o número usado para testes.
9
+ # config.numero_afiliacao = "1001734898"
10
+
11
+ # Chave de acesso para autenticação.
12
+ # O número padrão é o número usado para os testes.
13
+ # config.chave_acesso = "e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832"
14
+
15
+ # Após o processamento pela cielo, o usuário será redirecionado para uma página.
16
+ # que é configurada abaixo, nessa action você pode consultar o status do TID
17
+ # para poder mostrar na tela.
18
+ # config.return_path = "http://localhost:3000"
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cielo::Connection do
4
+ before do
5
+ @connection = Cielo::Connection.new
6
+ end
7
+ it "should estabilish connection when was created" do
8
+ @connection.environment.should_not be_nil
9
+ end
10
+ describe "making a request" do
11
+ it "should make a request" do
12
+ response = @connection.request! :data => "Anything"
13
+
14
+ response.body.should_not be_nil
15
+ response.should be_kind_of Net::HTTPSuccess
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,94 @@
1
+ #encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Cielo::Transaction do
5
+ before do
6
+ @transaction = Cielo::Transaction.new
7
+ end
8
+
9
+ describe "create a transaction" do
10
+ before do
11
+ @params = {:numero => "1", :valor => "100", :bandeira => "visa", :"url-retorno" => "http://some.thing.com"}
12
+ end
13
+ [:numero, :valor, :bandeira, :"url-retorno"].each do |parameter|
14
+ it "raises an error when #{parameter} isn't informed" do
15
+ lambda { @transaction.create! @params.except!(parameter) }.should raise_error(Cielo::MissingArgumentError)
16
+ end
17
+ end
18
+ it "delivers an successful message" do
19
+ response = @transaction.create! @params
20
+
21
+ response[:transacao][:tid].should_not be_nil
22
+ response[:transacao][:"url-autenticacao"].should_not be_nil
23
+
24
+ response = @transaction.catch!("1001734898056B3C1001")
25
+
26
+ end
27
+
28
+ it "delivers a response with error message when status isn't 200" do
29
+ FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
30
+ :body => "Nothing to be found 'round here",
31
+ :status => ["404", "Not Found"])
32
+ response = @transaction.create! @params
33
+
34
+ response[:erro].should_not be_nil
35
+ response[:erro][:codigo].should be_eql("000")
36
+ end
37
+
38
+ it "delivers a response with error message when the server send" do
39
+ FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
40
+ :body => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <erro xmlns=\"http://ecommerce.cbmp.com.br\"> <codigo>001</codigo> <mensagem>Requisição inválida</mensagem> </erro>", :content_type => "application/xml")
41
+ response = @transaction.create! @params
42
+
43
+ response[:erro].should_not be_nil
44
+ response[:erro][:codigo].should be_eql("001")
45
+ end
46
+
47
+ end
48
+
49
+ describe "Verify a transaction status" do
50
+ it "returns null when no tid is informed" do
51
+ @transaction.verify!(nil).should be_nil
52
+ end
53
+ it "returns a successfull message" do
54
+ FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
55
+ :body => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<transacao id=\"1308170973\" versao=\"1.1.0\" xmlns=\"http://ecommerce.cbmp.com.br\">\n <tid>1001734898056B3C1001</tid>\n <dados-pedido>\n <numero>1</numero>\n <valor>100</valor>\n <moeda>986</moeda>\n <data-hora>2011-06-15T18:45:16.705-02:00</data-hora>\n <idioma>PT</idioma>\n </dados-pedido>\n <forma-pagamento>\n <bandeira>visa</bandeira>\n <produto>1</produto>\n <parcelas>1</parcelas>\n </forma-pagamento>\n <status>0</status>\n</transacao>\n\n", :content_type => "application/xml")
56
+
57
+ response = @transaction.verify!("1001734898056B3C1001")
58
+
59
+ response[:transacao][:tid].should_not be_nil
60
+ response[:transacao][:status].should_not be_nil
61
+ end
62
+ end
63
+
64
+ describe "Catch a transaction" do
65
+ it "returns null when no tid is informed" do
66
+ @transaction.catch!(nil).should be_nil
67
+ end
68
+ it "returns a successfull message" do
69
+ FakeWeb.register_uri(:any, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do",
70
+ :body => "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<transacao id=\"1308170973\" versao=\"1.1.0\" xmlns=\"http://ecommerce.cbmp.com.br\">\n <tid>1001734898056B3C1001</tid>\n <dados-pedido>\n <numero>1</numero>\n <valor>100</valor>\n <moeda>986</moeda>\n <data-hora>2011-06-15T18:45:16.705-02:00</data-hora>\n <idioma>PT</idioma>\n </dados-pedido>\n <forma-pagamento>\n <bandeira>visa</bandeira>\n <produto>1</produto>\n <parcelas>1</parcelas>\n </forma-pagamento>\n <status>0</status>\n</transacao>\n\n", :content_type => "application/xml")
71
+
72
+ response = @transaction.catch!("1001734898056B3C1001")
73
+
74
+ response[:transacao][:tid].should_not be_nil
75
+ response[:transacao][:status].should_not be_nil
76
+ end
77
+ end
78
+
79
+ describe "Using a production environment" do
80
+ before do
81
+ Cielo.setup do |config|
82
+ config.environment = :production
83
+ config.numero_afiliacao = "1001734891"
84
+ config.chave_acesso="e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832"
85
+ end
86
+ end
87
+
88
+ it "must use the production environment" do
89
+ Cielo.numero_afiliacao.should be_eql "1001734891"
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,2 @@
1
+ require 'cielo'
2
+ require 'fakeweb'
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cielo-loja
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Giulliano Bueno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: i18n
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: builder
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - <
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 2.0.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - <
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.0
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 2.0.0
68
+ - !ruby/object:Gem::Dependency
69
+ name: shoulda
70
+ requirement: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: bundler
86
+ requirement: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: jeweler
102
+ requirement: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: 1.8.3
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: 1.8.3
116
+ - !ruby/object:Gem::Dependency
117
+ name: rspec
118
+ requirement: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ - !ruby/object:Gem::Dependency
133
+ name: fakeweb
134
+ requirement: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ description: Integração com a cielo
149
+ email: giubueno@gmail.com
150
+ executables: []
151
+ extensions: []
152
+ extra_rdoc_files:
153
+ - LICENSE.txt
154
+ - README.rdoc
155
+ files:
156
+ - .document
157
+ - Gemfile
158
+ - Gemfile.lock
159
+ - LICENSE.txt
160
+ - README.rdoc
161
+ - Rakefile
162
+ - cielo.gemspec
163
+ - lib/cielo.rb
164
+ - lib/cielo/connection.rb
165
+ - lib/cielo/transaction.rb
166
+ - lib/cielo/version.rb
167
+ - lib/generators/cielo/install_generator.rb
168
+ - lib/generators/templates/cielo.rb
169
+ - spec/cielo/connection_spec.rb
170
+ - spec/cielo/transaction_spec.rb
171
+ - spec/spec_helper.rb
172
+ homepage: http://github.com/giubueno/cielo-loja
173
+ licenses:
174
+ - MIT
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 1.8.24
194
+ signing_key:
195
+ specification_version: 3
196
+ summary: Integração com a cielo usando BuyPage loja.
197
+ test_files: []