cieloloja 0.2.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 TByte Consultoria
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
+ = cieloloja
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 cieloloja
14
+
15
+ === Ambiente de teste (Homologação)
16
+
17
+ transaction = Cieloloja::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 cieloloja:install
25
+
26
+ Esse comando vai gerar um arquivo config/initializers/cieloloja.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 Cieloloja
31
+
32
+ Cieloloja.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/cieloloja/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 = "cieloloja"
21
+ gem.homepage = "http://github.com/giubueno/cieloloja"
22
+ gem.license = "MIT"
23
+ gem.summary = %Q{Integração com a cielo Buy Page Loja}
24
+ gem.description = %Q{Integração com a cielo}
25
+ gem.email = "giulliano@e-processamento.com"
26
+ gem.authors = ["TByte Consultoria", "Giulliano Bueno"]
27
+ gem.version = Cieloloja::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 = "cieloloja #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/cieloloja.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 = "cieloloja"
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["TByte Consultoria", "Giulliano Bueno"]
12
+ s.date = "2012-07-20"
13
+ s.description = "Integra\u{e7}\u{e3}o com a cielo"
14
+ s.email = "giulliano@e-processamento.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
+ "cieloloja.gemspec",
27
+ "lib/cieloloja.rb",
28
+ "lib/cieloloja/connection.rb",
29
+ "lib/cieloloja/transaction.rb",
30
+ "lib/cieloloja/version.rb",
31
+ "lib/generators/cielo/install_generator.rb",
32
+ "lib/generators/templates/cieloloja.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/cieloloja"
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 Buy Page 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
+
@@ -0,0 +1,22 @@
1
+ module Cieloloja
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 Cieloloja
3
+ class Transaction
4
+ def initialize
5
+ @connection = Cieloloja::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!(cieloloja_tid)
33
+ return nil unless cieloloja_tid
34
+ message = xml_builder("requisicao-consulta", :before) do |xml|
35
+ xml.tid "#{cieloloja_tid}"
36
+ end
37
+
38
+ make_request! message
39
+ end
40
+
41
+ def catch!(cieloloja_tid)
42
+ return nil unless cieloloja_tid
43
+ message = xml_builder("requisicao-captura", :before) do |xml|
44
+ xml.tid "#{cieloloja_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 Cieloloja::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" => Cieloloja.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 Cieloloja.numero_afiliacao
72
+ xml.chave Cieloloja.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 Cieloloja
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ PATCH = 1
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
+ end
8
+ end
data/lib/cieloloja.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 "cieloloja/#{lib}" }
9
+
10
+ module Cieloloja
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,14 @@
1
+ module Cieloloja
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Cria o initializer da cieloloja na app rails"
7
+
8
+ def copy_initializer
9
+ template "cieloloja.rb", "config/initializers/cieloloja.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
+ Cieloloja.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,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cieloloja
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TByte Consultoria
9
+ - Giulliano Bueno
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-07-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.7
31
+ - !ruby/object:Gem::Dependency
32
+ name: i18n
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: builder
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - <
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 2.0.0
58
+ type: :runtime
59
+ prerelease: false
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - <
64
+ - !ruby/object:Gem::Version
65
+ version: 3.1.0
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: bundler
87
+ requirement: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ - !ruby/object:Gem::Dependency
102
+ name: jeweler
103
+ requirement: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: 1.8.3
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ~>
115
+ - !ruby/object:Gem::Version
116
+ version: 1.8.3
117
+ - !ruby/object:Gem::Dependency
118
+ name: rspec
119
+ requirement: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: fakeweb
135
+ requirement: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ type: :development
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ description: Integração com a cielo
150
+ email: giulliano@e-processamento.com
151
+ executables: []
152
+ extensions: []
153
+ extra_rdoc_files:
154
+ - LICENSE.txt
155
+ - README.rdoc
156
+ files:
157
+ - .document
158
+ - Gemfile
159
+ - Gemfile.lock
160
+ - LICENSE.txt
161
+ - README.rdoc
162
+ - Rakefile
163
+ - cieloloja.gemspec
164
+ - lib/cieloloja.rb
165
+ - lib/cieloloja/connection.rb
166
+ - lib/cieloloja/transaction.rb
167
+ - lib/cieloloja/version.rb
168
+ - lib/generators/cielo/install_generator.rb
169
+ - lib/generators/templates/cieloloja.rb
170
+ - spec/cielo/connection_spec.rb
171
+ - spec/cielo/transaction_spec.rb
172
+ - spec/spec_helper.rb
173
+ homepage: http://github.com/giubueno/cieloloja
174
+ licenses:
175
+ - MIT
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ segments:
187
+ - 0
188
+ hash: 487574936464702134
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ! '>='
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 1.8.24
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: Integração com a cielo Buy Page Loja
201
+ test_files: []