cielox 0.0.0 → 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.travis.yml +6 -0
  2. data/README.md +46 -17
  3. data/cielox.gemspec +5 -2
  4. data/lib/cielo.rb +38 -0
  5. data/lib/cielo/authorization.rb +14 -0
  6. data/lib/cielo/authorization_request.rb +27 -0
  7. data/lib/cielo/capture.rb +11 -0
  8. data/lib/cielo/capture_request.rb +27 -0
  9. data/lib/cielo/card.rb +12 -0
  10. data/lib/cielo/configuration.rb +11 -0
  11. data/lib/cielo/order.rb +12 -0
  12. data/lib/cielo/payment.rb +10 -0
  13. data/lib/cielo/shop.rb +9 -0
  14. data/lib/cielo/transaction.rb +14 -0
  15. data/lib/cielo/transaction_request.rb +34 -0
  16. data/lib/cielo/validity.rb +19 -0
  17. data/lib/cielo/version.rb +3 -0
  18. data/lib/cielox.rb +1 -5
  19. data/spec/cielo/authorization_request_spec.rb +49 -0
  20. data/spec/cielo/capture_request_spec.rb +49 -0
  21. data/spec/cielo/card_spec.rb +16 -0
  22. data/spec/cielo/configuration_spec.rb +35 -0
  23. data/spec/cielo/order_spec.rb +24 -0
  24. data/spec/cielo/payment_spec.rb +14 -0
  25. data/spec/cielo/shop_spec.rb +13 -0
  26. data/spec/cielo/transaction_request_spec.rb +88 -0
  27. data/spec/cielo/transaction_spec.rb +9 -0
  28. data/spec/cielo/validity_spec.rb +24 -0
  29. data/spec/cielo_spec.rb +13 -0
  30. data/spec/fixtures/authorization_request.xml +8 -0
  31. data/spec/fixtures/capture_request.xml +8 -0
  32. data/spec/fixtures/card.xml +8 -0
  33. data/spec/fixtures/order.xml +8 -0
  34. data/spec/fixtures/payment.xml +6 -0
  35. data/spec/fixtures/shop.xml +5 -0
  36. data/spec/fixtures/transaction.xml +19 -0
  37. data/spec/fixtures/transaction_1.xml +12 -0
  38. data/spec/fixtures/transaction_2.xml +15 -0
  39. data/spec/fixtures/transaction_request.xml +22 -0
  40. data/spec/spec_helper.rb +2 -0
  41. metadata +97 -8
  42. data/lib/cielox/version.rb +0 -3
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,29 +1,58 @@
1
- # Cielox
1
+ # CieloX
2
2
 
3
- TODO: Write a gem description
3
+ Gem para integração de pagamentos via Cielo
4
4
 
5
- ## Installation
5
+ ## Instalação
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Adicione a gem ao seu Gemfile
8
8
 
9
9
  gem 'cielox'
10
10
 
11
- And then execute:
11
+ E depois execute:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ Ou instale usando:
16
16
 
17
17
  $ gem install cielox
18
18
 
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Added some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
19
+ ## Uso
20
+
21
+ request = Cielo::TransactionRequest.new
22
+ request.id = "1"
23
+ request.return_url = "http://minha.loja.com/pedido/285813768"
24
+ request.authorize = 2
25
+ request.capture = false
26
+
27
+ request.card = Cielo::Card.new
28
+ request.card.number = "4012001037141112"
29
+ request.card.validity = "201511"
30
+ request.card.indicator = 1
31
+ request.card.security_code = 371
32
+ request.card.owner = "FULANO DE TAL"
33
+
34
+ request.shop = Cielo::Shop.new
35
+ request.shop.number = 1006993069
36
+ request.shop.key = "25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3"
37
+
38
+ request.order = Cielo::Order.new
39
+ request.order.number = 285813768
40
+ request.order.total = 1
41
+ request.order.currency = 986 # reais
42
+ request.order.time = Time.now
43
+ request.order.language = "PT"
44
+
45
+ request.payment = Cielo::Payment.new
46
+ request.payment.flag = "visa"
47
+ request.payment.product = 1
48
+ request.payment.installments = 1
49
+
50
+ transaction = request.create # retorna uma instância de Transaction
51
+
52
+ ## Contribuindo
53
+
54
+ 1. Fork o projeto
55
+ 2. Crie seu feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit as alterações (`git commit -am 'add some feature'`)
57
+ 4. Push para o branch (`git push origin my-new-feature`)
58
+ 5. Crie um novo pull request
data/cielox.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/cielox/version', __FILE__)
2
+ require File.expand_path('../lib/cielo/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Rafael Souza"]
@@ -13,7 +13,10 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
14
  gem.name = "cielox"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = Cielox::VERSION
16
+ gem.version = Cielo::VERSION
17
17
 
18
+ gem.add_dependency "happymapper", "~> 0.4.0"
18
19
  gem.add_development_dependency "rspec", "~> 2.9.0"
20
+ gem.add_development_dependency "timecop", "~> 0.3.5"
21
+ gem.add_development_dependency "webmock", "~> 1.8.6"
19
22
  end
data/lib/cielo.rb ADDED
@@ -0,0 +1,38 @@
1
+ require "cielo/version"
2
+ require "happymapper"
3
+
4
+ module Cielo
5
+ autoload :Configuration, "cielo/configuration"
6
+
7
+ autoload :Shop, "cielo/shop"
8
+ autoload :Order, "cielo/order"
9
+ autoload :Payment, "cielo/payment"
10
+ autoload :Validity, "cielo/validity"
11
+ autoload :Card, "cielo/card"
12
+
13
+ autoload :TransactionRequest, "cielo/transaction_request"
14
+ autoload :Transaction, "cielo/transaction"
15
+
16
+ autoload :AuthorizationRequest, "cielo/authorization_request"
17
+ autoload :Authorization, "cielo/authorization"
18
+
19
+ autoload :CaptureRequest, "cielo/capture_request"
20
+ autoload :Capture, "cielo/capture"
21
+
22
+ class << self
23
+ def configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def configure
28
+ yield configuration if block_given?
29
+ end
30
+
31
+ def logger
32
+ configuration.logger ||= begin
33
+ require "logger"
34
+ Logger.new(STDOUT)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module Cielo
2
+ class Authorization
3
+ include HappyMapper
4
+
5
+ tag "autorizacao"
6
+ element :code, Integer, :tag => "codigo"
7
+ element :message, String, :tag => "mensagem"
8
+ element :time, Time, :tag => "data-hora"
9
+ element :total, Integer, :tag => "valor"
10
+ element :lr, Integer
11
+ element :arp, String
12
+ element :nsu, String
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module Cielo
2
+ class AuthorizationRequest
3
+ include HappyMapper
4
+
5
+ tag "requisicao-autorizacao-tid"
6
+ attribute :id, Integer, :on_save => proc { |value| value.to_s }
7
+ attribute :version, String, :tag => "versao", :on_save => proc { |value| value ? value : "1.1.1" }
8
+ element :tid, String
9
+ has_one :shop, Shop
10
+
11
+ def authorize
12
+ http = Net::HTTP.new(Cielo.configuration.host, Cielo.configuration.port)
13
+ http.use_ssl = true
14
+ http.open_timeout = 10 * 1000
15
+ http.read_timeout = 40 * 1000
16
+ Cielo.logger.info(http.inspect)
17
+
18
+ post_body = "mensagem=#{to_xml}"
19
+ Cielo.logger.info(post_body)
20
+
21
+ response = http.request_post(Cielo.configuration.path, post_body)
22
+ Cielo.logger.info(response.body)
23
+
24
+ Transaction.parse(response.body, :single => true)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Cielo
2
+ class Capture
3
+ include HappyMapper
4
+
5
+ tag "captura"
6
+ element :code, Integer, :tag => "codigo"
7
+ element :message, String, :tag => "mensagem"
8
+ element :time, Time, :tag => "data-hora"
9
+ element :total, Integer, :tag => "valor"
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Cielo
2
+ class CaptureRequest
3
+ include HappyMapper
4
+
5
+ tag "requisicao-captura"
6
+ attribute :id, Integer, :on_save => proc { |value| value.to_s }
7
+ attribute :version, String, :tag => "versao", :on_save => proc { |value| value ? value : "1.1.1" }
8
+ element :tid, String
9
+ has_one :shop, Shop
10
+
11
+ def capture
12
+ http = Net::HTTP.new(Cielo.configuration.host, Cielo.configuration.port)
13
+ http.use_ssl = true
14
+ http.open_timeout = 10 * 1000
15
+ http.read_timeout = 40 * 1000
16
+ Cielo.logger.info(http.inspect)
17
+
18
+ post_body = "mensagem=#{to_xml}"
19
+ Cielo.logger.info(post_body)
20
+
21
+ response = http.request_post(Cielo.configuration.path, post_body)
22
+ Cielo.logger.info(response.body)
23
+
24
+ Transaction.parse(response.body, :single => true)
25
+ end
26
+ end
27
+ end
data/lib/cielo/card.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Cielo
2
+ class Card
3
+ include HappyMapper
4
+
5
+ tag "dados-portador"
6
+ element :number, String, :tag => "numero"
7
+ element :validity, Validity, :tag => "validade"
8
+ element :indicator, String, :tag => "indicador"
9
+ element :security_code, Integer, :tag => "codigo-seguranca"
10
+ element :owner, String, :tag => "nome-portador"
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Cielo
2
+ class Configuration
3
+ attr_accessor :host, :port, :path, :logger
4
+
5
+ def initialize
6
+ @host = "qasecommerce.cielo.com.br"
7
+ @port = 443
8
+ @path = "/servicos/ecommwsec.do"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Cielo
2
+ class Order
3
+ include HappyMapper
4
+
5
+ tag "dados-pedido"
6
+ element :number, Integer, :tag => "numero"
7
+ element :total, Integer, :tag => "valor", :on_save => proc { |value| (value * 100).to_i }
8
+ element :currency, String, :tag => "moeda"
9
+ element :time, Time, :tag => "data-hora", :on_save => proc { |value| value.strftime("%Y-%m-%dT%H:%M:%S") }
10
+ element :language, String, :tag => "idioma"
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Cielo
2
+ class Payment
3
+ include HappyMapper
4
+
5
+ tag "forma-pagamento"
6
+ element :flag, String, :tag => "bandeira"
7
+ element :product, Integer, :tag => "produto"
8
+ element :installments, Integer, :tag => "parcelas"
9
+ end
10
+ end
data/lib/cielo/shop.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Cielo
2
+ class Shop
3
+ include HappyMapper
4
+
5
+ tag "dados-ec"
6
+ element :number, Integer, :tag => "numero"
7
+ element :key, String, :tag => "chave"
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Cielo
2
+ class Transaction
3
+ include HappyMapper
4
+
5
+ tag "transacao"
6
+ element :tid, String
7
+ element :pan, String
8
+ element :status, Integer
9
+ element :authentication_url, String, :tag => "url-autenticacao"
10
+
11
+ has_one :authorization, Authorization
12
+ has_one :capture, Capture
13
+ end
14
+ end
@@ -0,0 +1,34 @@
1
+ require "net/http"
2
+
3
+ module Cielo
4
+ class TransactionRequest
5
+ include HappyMapper
6
+
7
+ tag "requisicao-transacao"
8
+ attribute :id, Integer, :on_save => proc { |value| value.to_s }
9
+ attribute :version, String, :tag => "versao", :on_save => proc { |value| value ? value : "1.1.1" }
10
+ has_one :shop, Shop
11
+ has_one :card, Card
12
+ has_one :order, Order
13
+ has_one :payment, Payment
14
+ element :return_url, String, :tag => "url-retorno"
15
+ element :authorize, Integer, :tag => "autorizar"
16
+ element :capture, Boolean, :tag => "capturar", :on_save => proc { |value| value.to_s }
17
+
18
+ def create
19
+ http = Net::HTTP.new(Cielo.configuration.host, Cielo.configuration.port)
20
+ http.use_ssl = true
21
+ http.open_timeout = 10 * 1000
22
+ http.read_timeout = 40 * 1000
23
+ Cielo.logger.info(http.inspect)
24
+
25
+ post_body = "mensagem=#{to_xml}"
26
+ Cielo.logger.info(post_body)
27
+
28
+ response = http.request_post(Cielo.configuration.path, post_body)
29
+ Cielo.logger.info(response.body)
30
+
31
+ Transaction.parse(response.body, :single => true)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ module Cielo
2
+ class Validity
3
+ class InvalidDate < StandardError; end
4
+
5
+ def initialize(year, month)
6
+ @year = year.to_i
7
+ @month = month.to_i
8
+
9
+ now = Time.now
10
+ if @year < now.year || @month < now.month
11
+ raise InvalidDate, "#{@month}/#{@year} is not valid"
12
+ end
13
+ end
14
+
15
+ def to_s
16
+ [@year, "%02d" % @month].join
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Cielo
2
+ VERSION = "0.0.1a"
3
+ end
data/lib/cielox.rb CHANGED
@@ -1,5 +1 @@
1
- require "cielox/version"
2
-
3
- module Cielox
4
- # Your code goes here...
5
- end
1
+ require "cielo"
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Cielo::AuthorizationRequest do
5
+ subject { described_class.new }
6
+
7
+ let(:shop) do
8
+ Cielo::Shop.new.tap do |s|
9
+ s.number = 1006993069
10
+ s.key = "25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3"
11
+ end
12
+ end
13
+
14
+ let(:request_xml) { File.read(File.expand_path("../../fixtures/authorization_request.xml", __FILE__)) }
15
+
16
+ it "#to_xml" do
17
+ subject.shop = shop
18
+ subject.id = 2
19
+ subject.tid = "100699306904CC7E1001"
20
+ xml = subject.to_xml
21
+
22
+ xml.should == request_xml
23
+ end
24
+
25
+ it "#authorize" do
26
+ stub_request(:post, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do").
27
+ with(
28
+ :body => "mensagem=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<requisicao-autorizacao-tid id=\"1\" versao=\"1.1.1\">\n <tid>100699306904CC7E1001</tid>\n <dados-ec>\n <numero>1006993069</numero>\n <chave>25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3</chave>\n </dados-ec>\n</requisicao-autorizacao-tid>\n",
29
+ ).
30
+ to_return(
31
+ :status => 200,
32
+ :body => File.read(File.expand_path("../../fixtures/transaction_2.xml", __FILE__)),
33
+ :headers => { "Content-Type" => "text/xml" }
34
+ )
35
+
36
+ subject.shop = shop
37
+ subject.id = 1
38
+ subject.tid = "100699306904CC7E1001"
39
+ transaction = subject.authorize
40
+
41
+ transaction.authorization.code.should == 1
42
+ transaction.authorization.message.should == "Transação autorizada"
43
+ transaction.authorization.time.should == Time.new(2010, 7, 14, 13, 56, 12)
44
+ transaction.authorization.total.should == 100
45
+ transaction.authorization.lr.should == 1
46
+ transaction.authorization.arp.should == "a1b2c3"
47
+ transaction.authorization.nsu.should == "5e4d3c"
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe Cielo::CaptureRequest do
5
+ subject { described_class.new }
6
+
7
+ let(:shop) do
8
+ Cielo::Shop.new.tap do |s|
9
+ s.number = 1006993069
10
+ s.key = "25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3"
11
+ end
12
+ end
13
+
14
+ let(:request_xml) { File.read(File.expand_path("../../fixtures/capture_request.xml", __FILE__)) }
15
+
16
+ it "#to_xml" do
17
+ subject.shop = shop
18
+ subject.id = 1
19
+ subject.tid = "100699306904CC7E1001"
20
+ xml = subject.to_xml
21
+
22
+ xml.should == request_xml
23
+ end
24
+
25
+ it "#capture" do
26
+ stub_request(:post, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do").
27
+ with(
28
+ :body => "mensagem=#{request_xml}"
29
+ ).
30
+ to_return(
31
+ :status => 200,
32
+ :body => File.read(File.expand_path("../../fixtures/transaction_1.xml", __FILE__)),
33
+ :headers => { "Content-Type" => "text/xml" }
34
+ )
35
+
36
+ subject.shop = shop
37
+ subject.id = 1
38
+ subject.tid = "100699306904CC7E1001"
39
+ transaction = subject.capture
40
+
41
+ transaction.tid.should == "100699306904CC7E1001"
42
+ transaction.pan.should == "IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0="
43
+ transaction.status.should == 6
44
+ transaction.capture.code.should == 1
45
+ transaction.capture.message.should == "Transação capturada"
46
+ transaction.capture.time.should == Time.new(2010, 7, 14, 13, 56, 12)
47
+ transaction.capture.total.should == 100
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Card do
4
+ subject { described_class.new }
5
+
6
+ it "#to_xml" do
7
+ subject.number = "4012001037141112"
8
+ subject.validity = Cielo::Validity.new(2015, 11)
9
+ subject.indicator = 1
10
+ subject.security_code = 371
11
+ subject.owner = "FULANO DE TAL"
12
+ xml = subject.to_xml
13
+
14
+ xml.should == File.read(File.expand_path("../../fixtures/card.xml", __FILE__))
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Configuration do
4
+ subject { described_class.new }
5
+
6
+ its(:host) { should == "qasecommerce.cielo.com.br" }
7
+ its(:port) { should == 443 }
8
+ its(:path) { should == "/servicos/ecommwsec.do" }
9
+ its(:logger) { should be_nil }
10
+
11
+ context "defining new values" do
12
+ it "changes the host" do
13
+ subject.host = "a.com"
14
+ subject.host.should == "a.com"
15
+ end
16
+
17
+ it "changes the port" do
18
+ subject.host = 80
19
+ subject.host.should == 80
20
+ end
21
+
22
+ it "changes the path" do
23
+ subject.host = "/something_else"
24
+ subject.host.should == "/something_else"
25
+ end
26
+
27
+ it "changes the logger" do
28
+ require "logger"
29
+ MyLogger = Class.new(Logger)
30
+
31
+ subject.logger = MyLogger.new(STDOUT)
32
+ subject.logger.should be_instance_of(MyLogger)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Order do
4
+ subject { described_class.new }
5
+
6
+ before do
7
+ Timecop.freeze(Time.parse("2010-07-14T13:56:12"))
8
+ end
9
+
10
+ after do
11
+ Timecop.return
12
+ end
13
+
14
+ it "#to_xml" do
15
+ subject.number = 285813768
16
+ subject.total = 1
17
+ subject.currency = 986
18
+ subject.time = Time.now
19
+ subject.language = "PT"
20
+ xml = subject.to_xml
21
+
22
+ xml.should == File.read(File.expand_path("../../fixtures/order.xml", __FILE__))
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Payment do
4
+ subject { described_class.new }
5
+
6
+ it "#to_xml" do
7
+ subject.flag = "visa"
8
+ subject.product = 1
9
+ subject.installments = 1
10
+ xml = subject.to_xml
11
+
12
+ xml.should == File.read(File.expand_path("../../fixtures/payment.xml", __FILE__))
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Shop do
4
+ subject { described_class.new }
5
+
6
+ it "#to_xml" do
7
+ subject.number = 1001734898
8
+ subject.key = "e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832"
9
+ xml = subject.to_xml
10
+
11
+ xml.should == File.read(File.expand_path("../../fixtures/shop.xml", __FILE__))
12
+ end
13
+ end
@@ -0,0 +1,88 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::TransactionRequest do
4
+ subject { described_class.new }
5
+
6
+ let(:shop) do
7
+ Cielo::Shop.new.tap do |s|
8
+ s.number = 1006993069
9
+ s.key = "25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3"
10
+ end
11
+ end
12
+
13
+ let(:order) do
14
+ Cielo::Order.new.tap do |o|
15
+ o.number = 285813768
16
+ o.total = 1
17
+ o.currency = 986
18
+ o.time = Time.now
19
+ o.language = "PT"
20
+ end
21
+ end
22
+
23
+ let(:payment) do
24
+ Cielo::Payment.new.tap do |p|
25
+ p.flag = "visa"
26
+ p.product = 1
27
+ p.installments = 1
28
+ end
29
+ end
30
+
31
+ let(:card) do
32
+ Cielo::Card.new.tap do |c|
33
+ c.number = "4012001037141112"
34
+ c.validity = "201511"
35
+ c.indicator = 1
36
+ c.security_code = 371
37
+ c.owner = "FULANO DE TAL"
38
+ end
39
+ end
40
+
41
+ before do
42
+ Timecop.freeze(Time.parse("2010-07-14T13:56:12"))
43
+ end
44
+
45
+ after do
46
+ Timecop.return
47
+ end
48
+
49
+ it "#to_xml" do
50
+ subject.id = "1"
51
+ subject.shop = shop
52
+ subject.order = order
53
+ subject.payment = payment
54
+ subject.return_url = "http://minha.loja.com/pedido/285813768"
55
+ subject.authorize = 2
56
+ subject.capture = false
57
+ xml = subject.to_xml
58
+
59
+ xml.should == File.read(File.expand_path("../../fixtures/transaction_request.xml", __FILE__))
60
+ end
61
+
62
+ it "#create" do
63
+ stub_request(:post, "https://qasecommerce.cielo.com.br/servicos/ecommwsec.do").
64
+ with(
65
+ :body => "mensagem=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<requisicao-transacao id=\"1\" versao=\"1.1.1\">\n <dados-ec>\n <numero>1006993069</numero>\n <chave>25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3</chave>\n </dados-ec>\n <dados-portador>\n <numero>4012001037141112</numero>\n <validade>201511</validade>\n <indicador>1</indicador>\n <codigo-seguranca>371</codigo-seguranca>\n <nome-portador>FULANO DE TAL</nome-portador>\n </dados-portador>\n <dados-pedido>\n <numero>285813768</numero>\n <valor>100</valor>\n <moeda>986</moeda>\n <data-hora>2010-07-14T13:56:12</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 <url-retorno>http://minha.loja.com/pedido/285813768</url-retorno>\n <autorizar>2</autorizar>\n <capturar>false</capturar>\n</requisicao-transacao>\n"
66
+ ).
67
+ to_return(
68
+ :status => 200,
69
+ :body => File.read(File.expand_path("../../fixtures/transaction.xml", __FILE__)),
70
+ :headers => {}
71
+ )
72
+
73
+ subject.id = "1"
74
+ subject.card = card
75
+ subject.shop = shop
76
+ subject.order = order
77
+ subject.payment = payment
78
+ subject.return_url = "http://minha.loja.com/pedido/285813768"
79
+ subject.authorize = 2
80
+ subject.capture = false
81
+ transaction = subject.create
82
+
83
+ transaction.tid.should == "100699306904CC7E1001"
84
+ transaction.pan.should == "IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0="
85
+ transaction.status.should == 0
86
+ transaction.authentication_url = "https://qasecommerce.cielo.com.br/web/index.cbmp?id=4c0476919b9ea10d11f761bd3158bde0"
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Transaction do
4
+ subject { described_class.parse(File.read(File.expand_path("../../fixtures/transaction.xml", __FILE__)), :single => true) }
5
+ its(:tid) { should == "100699306904CC7E1001" }
6
+ its(:pan) { should == "IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0=" }
7
+ its(:status) { should == 0 }
8
+ its(:authentication_url) { should == "https://qasecommerce.cielo.com.br/web/index.cbmp?id=f7054b88de13b407d8aa4e802189aa92" }
9
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo::Validity do
4
+ before do
5
+ Timecop.freeze(Time.parse("2012-05-14 09:23:00"))
6
+ end
7
+
8
+ after do
9
+ Timecop.return
10
+ end
11
+
12
+ it "raises an exception if year is not valid" do
13
+ expect { described_class.new(Time.now.year - 1, Time.now.month) }.should raise_error(described_class::InvalidDate)
14
+ end
15
+
16
+ it "raises an exception if month is not valid" do
17
+ expect { described_class.new(Time.now.year, Time.now.month - 1) }.should raise_error(described_class::InvalidDate)
18
+ end
19
+
20
+ it "#to_s" do
21
+ validity = described_class.new(Time.now.year, Time.now.month)
22
+ validity.to_s.should == "201205"
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Cielo do
4
+ it "returns a configuration instance" do
5
+ Cielo.configuration.should be_instance_of(Cielo::Configuration)
6
+ end
7
+
8
+ it "yields a configuration instance" do
9
+ configuration = nil
10
+ Cielo.configure { |c| configuration = c }
11
+ configuration.should be_instance_of(Cielo::Configuration)
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <requisicao-autorizacao-tid id="2" versao="1.1.1">
3
+ <tid>100699306904CC7E1001</tid>
4
+ <dados-ec>
5
+ <numero>1006993069</numero>
6
+ <chave>25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3</chave>
7
+ </dados-ec>
8
+ </requisicao-autorizacao-tid>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <requisicao-captura id="1" versao="1.1.1">
3
+ <tid>100699306904CC7E1001</tid>
4
+ <dados-ec>
5
+ <numero>1006993069</numero>
6
+ <chave>25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3</chave>
7
+ </dados-ec>
8
+ </requisicao-captura>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <dados-portador>
3
+ <numero>4012001037141112</numero>
4
+ <validade>201511</validade>
5
+ <indicador>1</indicador>
6
+ <codigo-seguranca>371</codigo-seguranca>
7
+ <nome-portador>FULANO DE TAL</nome-portador>
8
+ </dados-portador>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <dados-pedido>
3
+ <numero>285813768</numero>
4
+ <valor>100</valor>
5
+ <moeda>986</moeda>
6
+ <data-hora>2010-07-14T13:56:12</data-hora>
7
+ <idioma>PT</idioma>
8
+ </dados-pedido>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <forma-pagamento>
3
+ <bandeira>visa</bandeira>
4
+ <produto>1</produto>
5
+ <parcelas>1</parcelas>
6
+ </forma-pagamento>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <dados-ec>
3
+ <numero>1001734898</numero>
4
+ <chave>e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832</chave>
5
+ </dados-ec>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1"?>
2
+ <transacao versao="1.1.1" id="1" xmlns="http://ecommerce.cbmp.com.br">
3
+ <tid>100699306904CC7E1001</tid>
4
+ <pan>IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0=</pan>
5
+ <dados-pedido>
6
+ <numero>285813768</numero>
7
+ <valor>100</valor>
8
+ <moeda>986</moeda>
9
+ <data-hora>2012-04-30T08:30:15.358-03:00</data-hora>
10
+ <idioma>PT</idioma>
11
+ </dados-pedido>
12
+ <forma-pagamento>
13
+ <bandeira>visa</bandeira>
14
+ <produto>1</produto>
15
+ <parcelas>1</parcelas>
16
+ </forma-pagamento>
17
+ <status>0</status>
18
+ <url-autenticacao>https://qasecommerce.cielo.com.br/web/index.cbmp?id=f7054b88de13b407d8aa4e802189aa92</url-autenticacao>
19
+ </transacao>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <transacao versao="1.1.1" id="1" xmlns="http://ecommerce.cbmp.com.br">
3
+ <tid>100699306904CC7E1001</tid>
4
+ <pan>IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0=</pan>
5
+ <status>6</status>
6
+ <captura>
7
+ <codigo>1</codigo>
8
+ <mensagem>Transação capturada</mensagem>
9
+ <data-hora>2010-07-14T13:56:12</data-hora>
10
+ <valor>100</valor>
11
+ </captura>
12
+ </transacao>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <transacao versao="1.1.1" id="1" xmlns="http://ecommerce.cbmp.com.br">
3
+ <tid>100699306904CC7E1001</tid>
4
+ <pan>IqVz7P9zaIgTYdU41HaW/OB/d7Idwttqwb2vaTt8MT0=</pan>
5
+ <status>6</status>
6
+ <autorizacao>
7
+ <codigo>1</codigo>
8
+ <mensagem>Transação autorizada</mensagem>
9
+ <data-hora>2010-07-14T13:56:12</data-hora>
10
+ <valor>100</valor>
11
+ <lr>1</lr>
12
+ <arp>a1b2c3</arp>
13
+ <nsu>5e4d3c</nsu>
14
+ </autorizacao>
15
+ </transacao>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <requisicao-transacao id="1" versao="1.1.1">
3
+ <dados-ec>
4
+ <numero>1006993069</numero>
5
+ <chave>25fbb99741c739dd84d7b06ec78c9bac718838630f30b112d033ce2e621b34f3</chave>
6
+ </dados-ec>
7
+ <dados-pedido>
8
+ <numero>285813768</numero>
9
+ <valor>100</valor>
10
+ <moeda>986</moeda>
11
+ <data-hora>2010-07-14T13:56:12</data-hora>
12
+ <idioma>PT</idioma>
13
+ </dados-pedido>
14
+ <forma-pagamento>
15
+ <bandeira>visa</bandeira>
16
+ <produto>1</produto>
17
+ <parcelas>1</parcelas>
18
+ </forma-pagamento>
19
+ <url-retorno>http://minha.loja.com/pedido/285813768</url-retorno>
20
+ <autorizar>2</autorizar>
21
+ <capturar>false</capturar>
22
+ </requisicao-transacao>
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "bundler/setup"
2
2
  require "cielox"
3
+ require "timecop"
4
+ require "webmock/rspec"
3
5
 
4
6
  RSpec.configure do |config|
5
7
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,19 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cielox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
5
- prerelease:
4
+ version: 0.0.1a
5
+ prerelease: 5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rafael Souza
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-29 00:00:00.000000000 Z
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: happymapper
16
+ requirement: &70303395388980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70303395388980
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rspec
16
- requirement: &70363946606620 !ruby/object:Gem::Requirement
27
+ requirement: &70303395388480 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ~>
@@ -21,7 +32,29 @@ dependencies:
21
32
  version: 2.9.0
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70363946606620
35
+ version_requirements: *70303395388480
36
+ - !ruby/object:Gem::Dependency
37
+ name: timecop
38
+ requirement: &70303395387980 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.5
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70303395387980
47
+ - !ruby/object:Gem::Dependency
48
+ name: webmock
49
+ requirement: &70303395387500 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.6
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70303395387500
25
58
  description: Gem for integration with Cielo
26
59
  email:
27
60
  - me@rafaelss.com
@@ -31,13 +64,48 @@ extra_rdoc_files: []
31
64
  files:
32
65
  - .gitignore
33
66
  - .rspec
67
+ - .travis.yml
34
68
  - Gemfile
35
69
  - LICENSE
36
70
  - README.md
37
71
  - Rakefile
38
72
  - cielox.gemspec
73
+ - lib/cielo.rb
74
+ - lib/cielo/authorization.rb
75
+ - lib/cielo/authorization_request.rb
76
+ - lib/cielo/capture.rb
77
+ - lib/cielo/capture_request.rb
78
+ - lib/cielo/card.rb
79
+ - lib/cielo/configuration.rb
80
+ - lib/cielo/order.rb
81
+ - lib/cielo/payment.rb
82
+ - lib/cielo/shop.rb
83
+ - lib/cielo/transaction.rb
84
+ - lib/cielo/transaction_request.rb
85
+ - lib/cielo/validity.rb
86
+ - lib/cielo/version.rb
39
87
  - lib/cielox.rb
40
- - lib/cielox/version.rb
88
+ - spec/cielo/authorization_request_spec.rb
89
+ - spec/cielo/capture_request_spec.rb
90
+ - spec/cielo/card_spec.rb
91
+ - spec/cielo/configuration_spec.rb
92
+ - spec/cielo/order_spec.rb
93
+ - spec/cielo/payment_spec.rb
94
+ - spec/cielo/shop_spec.rb
95
+ - spec/cielo/transaction_request_spec.rb
96
+ - spec/cielo/transaction_spec.rb
97
+ - spec/cielo/validity_spec.rb
98
+ - spec/cielo_spec.rb
99
+ - spec/fixtures/authorization_request.xml
100
+ - spec/fixtures/capture_request.xml
101
+ - spec/fixtures/card.xml
102
+ - spec/fixtures/order.xml
103
+ - spec/fixtures/payment.xml
104
+ - spec/fixtures/shop.xml
105
+ - spec/fixtures/transaction.xml
106
+ - spec/fixtures/transaction_1.xml
107
+ - spec/fixtures/transaction_2.xml
108
+ - spec/fixtures/transaction_request.xml
41
109
  - spec/spec_helper.rb
42
110
  homepage: http://github.com/rafaelss/cielo
43
111
  licenses: []
@@ -54,9 +122,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
122
  required_rubygems_version: !ruby/object:Gem::Requirement
55
123
  none: false
56
124
  requirements:
57
- - - ! '>='
125
+ - - ! '>'
58
126
  - !ruby/object:Gem::Version
59
- version: '0'
127
+ version: 1.3.1
60
128
  requirements: []
61
129
  rubyforge_project:
62
130
  rubygems_version: 1.8.11
@@ -64,5 +132,26 @@ signing_key:
64
132
  specification_version: 3
65
133
  summary: Gem for integration with Cielo
66
134
  test_files:
135
+ - spec/cielo/authorization_request_spec.rb
136
+ - spec/cielo/capture_request_spec.rb
137
+ - spec/cielo/card_spec.rb
138
+ - spec/cielo/configuration_spec.rb
139
+ - spec/cielo/order_spec.rb
140
+ - spec/cielo/payment_spec.rb
141
+ - spec/cielo/shop_spec.rb
142
+ - spec/cielo/transaction_request_spec.rb
143
+ - spec/cielo/transaction_spec.rb
144
+ - spec/cielo/validity_spec.rb
145
+ - spec/cielo_spec.rb
146
+ - spec/fixtures/authorization_request.xml
147
+ - spec/fixtures/capture_request.xml
148
+ - spec/fixtures/card.xml
149
+ - spec/fixtures/order.xml
150
+ - spec/fixtures/payment.xml
151
+ - spec/fixtures/shop.xml
152
+ - spec/fixtures/transaction.xml
153
+ - spec/fixtures/transaction_1.xml
154
+ - spec/fixtures/transaction_2.xml
155
+ - spec/fixtures/transaction_request.xml
67
156
  - spec/spec_helper.rb
68
157
  has_rdoc:
@@ -1,3 +0,0 @@
1
- module Cielox
2
- VERSION = "0.0.0"
3
- end