pagseguro_catcher 0.0.3

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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ gem "httparty"
10
+ gem "activesupport"
11
+ gem "i18n"
12
+
13
+ group :development do
14
+ gem "rspec", "~> 2.3.0"
15
+ gem "bundler", "~> 1.0.0"
16
+ gem "jeweler", "~> 1.6.4"
17
+ gem "rcov", ">= 0"
18
+ gem "fakeweb"
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.1.0)
5
+ multi_json (~> 1.0)
6
+ diff-lcs (1.1.3)
7
+ fakeweb (1.3.0)
8
+ git (1.2.5)
9
+ httparty (0.8.0)
10
+ multi_json
11
+ multi_xml
12
+ i18n (0.6.0)
13
+ jeweler (1.6.4)
14
+ bundler (~> 1.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ multi_json (1.0.3)
18
+ multi_xml (0.4.1)
19
+ rake (0.9.2)
20
+ rcov (0.9.10)
21
+ rspec (2.3.0)
22
+ rspec-core (~> 2.3.0)
23
+ rspec-expectations (~> 2.3.0)
24
+ rspec-mocks (~> 2.3.0)
25
+ rspec-core (2.3.1)
26
+ rspec-expectations (2.3.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.3.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activesupport
35
+ bundler (~> 1.0.0)
36
+ fakeweb
37
+ httparty
38
+ i18n
39
+ jeweler (~> 1.6.4)
40
+ rcov
41
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Matias H. Leidemer
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.textile ADDED
@@ -0,0 +1,23 @@
1
+ h1. PagseguroCatcher
2
+
3
+ !https://secure.travis-ci.org/matiasleidemer/pagseguro_catcher.png!:http://travis-ci.org/#!/matiasleidemer/pagseguro_catcher
4
+
5
+ h2. Soon
6
+
7
+ I'll describe how to use this one, but it's easy :-)
8
+
9
+ h2. Contributing to pagseguro_catcher
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
13
+ * Fork the project
14
+ * Start a feature/bugfix branch
15
+ * Commit and push until you are happy with your contribution
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * 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.
18
+
19
+ h2. Copyright
20
+
21
+ Copyright (c) 2011 Matias H. Leidemer. See LICENSE.txt for
22
+ further details.
23
+
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
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "pagseguro_catcher"
18
+ gem.homepage = "http://github.com/matiasleidemer/pagseguro_catcher"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A simple gem to parse PagSeguro transaction notification.}
21
+ gem.description = %Q{This gem provides a simple way to check and parse the PagSeguro transaction notification.}
22
+ gem.email = "matiasleidemer@gmail.com"
23
+ gem.authors = ["Matias H. Leidemer"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "pagseguro_catcher #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.3
@@ -0,0 +1,29 @@
1
+ require "httparty"
2
+
3
+ module PagseguroCatcher
4
+ class Checker
5
+ include HTTParty
6
+
7
+ attr_accessor :code, :type, :response
8
+
9
+ def initialize(code, type)
10
+ self.code = code
11
+ self.type = type
12
+ end
13
+
14
+ def check(force=false)
15
+ self.response = HTTParty.get(url).body if force
16
+ self.response ||= HTTParty.get(url).body
17
+
18
+ if self.response
19
+ PagseguroCatcher::Transaction::Base.new(self.response)
20
+ end
21
+ end
22
+
23
+ private
24
+ def url
25
+ "#{PagseguroCatcher.url}/#{self.code}?email=#{PagseguroCatcher.email}&token=#{PagseguroCatcher.token}"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ module PagseguroCatcher
3
+ #maybe YML?... this doesn't seem right...
4
+
5
+ TRANSACTION_TYPES = {
6
+ 1 => "Pagamento",
7
+ 2 => "Transferência",
8
+ 3 => "Adição de fundos",
9
+ 4 => "Cobrança",
10
+ 5 => "Bônus"
11
+ }
12
+
13
+ TRANSACTION_STATUS = {
14
+ 1 => "Aguardando pagamento",
15
+ 2 => "Em análise",
16
+ 3 => "Paga",
17
+ 4 => "Disponível",
18
+ 5 => "Em disputa",
19
+ 6 => "Devolvida",
20
+ 7 => "Cancelada"
21
+ }
22
+
23
+ PAYMENT_TYPES = {
24
+ 1 => "Cartão de crédito",
25
+ 2 => "Boleto",
26
+ 3 => "Débito online (TEF)",
27
+ 4 => "Saldo PagSeguro",
28
+ 5 => "Oi Paggo"
29
+ }
30
+
31
+ PAYMENT_CODES = {
32
+ 101 => "Cartão de crédito Visa",
33
+ 102 => "Cartão de crédito MasterCard",
34
+ 103 => "Cartão de crédito American Express",
35
+ 104 => "Cartão de crédito Diners",
36
+ 105 => "Cartão de crédito Hipercard",
37
+ 106 => "Cartão de crédito Aura",
38
+ 107 => "Cartão de crédito Elo",
39
+ 201 => "Boleto Bradesco",
40
+ 202 => "Boleto Santander",
41
+ 301 => "Débito online Bradesco",
42
+ 302 => "Débito online Itaú",
43
+ 303 => "Débito online Unibanco",
44
+ 304 => "Débito online Banco do Brasil",
45
+ 305 => "Débito online Banco Real",
46
+ 306 => "Débito online Banrisul",
47
+ 401 => "Saldo PagSeguro",
48
+ 501 => "Oi Paggo"
49
+ }
50
+
51
+ end
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ def recursive_symbolize_keys!
3
+ symbolize_keys!
4
+ # symbolize each hash in .values
5
+ values.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
6
+ # symbolize each hash inside an array in .values
7
+ values.select{|v| v.is_a?(Array) }.flatten.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
8
+ self
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ module PagseguroCatcher
2
+ module Transaction
3
+
4
+ class Amount
5
+ attr_accessor :body
6
+
7
+ def initialize(body)
8
+ self.body = body
9
+ end
10
+
11
+ def gross
12
+ self.body[:grossAmount].to_f
13
+ end
14
+
15
+ def discount
16
+ self.body[:discountAmount].to_f
17
+ end
18
+
19
+ def fee
20
+ self.body[:feeAmount].to_f
21
+ end
22
+
23
+ def net
24
+ self.body[:netAmount].to_f
25
+ end
26
+
27
+ def extra
28
+ self.body[:extraAmount].to_f
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ module PagseguroCatcher
2
+ module Transaction
3
+
4
+ class Base
5
+ attr_accessor :body
6
+
7
+ def initialize(xml)
8
+ self.body = Hash.from_xml(xml)["transaction"]
9
+ self.body.recursive_symbolize_keys! if self.body
10
+ end
11
+
12
+ def amount
13
+ @amount ||= PagseguroCatcher::Transaction::Amount.new(self.body)
14
+ @amount
15
+ end
16
+
17
+ def [](param)
18
+ self.body[param.to_sym]
19
+ end
20
+
21
+ def date
22
+ self[:date].to_datetime.change(:offset => "-0300")
23
+ end
24
+
25
+ def last_event_date
26
+ self[:lastEventDate].to_datetime.change(:offset => "-0300")
27
+ end
28
+
29
+ def transaction_type
30
+ TRANSACTION_TYPES[self[:type].to_i]
31
+ end
32
+
33
+ def transaction_status
34
+ TRANSACTION_STATUS[self[:status].to_i]
35
+ end
36
+
37
+ def payment_method_type
38
+ PAYMENT_TYPES[self[:paymentMethod][:type].to_i]
39
+ end
40
+
41
+ def payment_method_code
42
+ PAYMENT_CODES[self[:paymentMethod][:code].to_i]
43
+ end
44
+
45
+ #TODO - method missing
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,6 @@
1
+ module PagseguroCatcher
2
+ module Transaction
3
+ autoload :Base, 'pagseguro_catcher/transaction/base'
4
+ autoload :Amount, 'pagseguro_catcher/transaction/amount'
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ # https://pagseguro.uol.com.br/integracao/notificacao-de-transacoes.jhtml
2
+ # https://pagseguro.uol.com.br/v2/guia-de-integracao/api-de-notificacoes.html
3
+
4
+ require "active_support/core_ext"
5
+ require "pagseguro_catcher/core_ext/Hash"
6
+ require "pagseguro_catcher/constants"
7
+ require "pagseguro_catcher/transaction"
8
+
9
+ module PagseguroCatcher
10
+ autoload :Checker, 'pagseguro_catcher/checker'
11
+ mattr_accessor :url
12
+
13
+ self.url = "https://ws.pagseguro.uol.com.br/v2/transactions/notifications"
14
+
15
+ class << self
16
+ attr_accessor :token, :email
17
+
18
+ def configure
19
+ yield self
20
+ end
21
+ end
22
+
23
+
24
+
25
+ end
@@ -0,0 +1,83 @@
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 = %q{pagseguro_catcher}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Matias H. Leidemer}]
12
+ s.date = %q{2011-10-11}
13
+ s.description = %q{This gem provides a simple way to check and parse the PagSeguro transaction notification.}
14
+ s.email = %q{matiasleidemer@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.textile",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/pagseguro_catcher.rb",
30
+ "lib/pagseguro_catcher/checker.rb",
31
+ "lib/pagseguro_catcher/constants.rb",
32
+ "lib/pagseguro_catcher/core_ext/Hash.rb",
33
+ "lib/pagseguro_catcher/transaction.rb",
34
+ "lib/pagseguro_catcher/transaction/amount.rb",
35
+ "lib/pagseguro_catcher/transaction/base.rb",
36
+ "pagseguro_catcher.gemspec",
37
+ "spec/checker_spec.rb",
38
+ "spec/pagseguro_catcher_spec.rb",
39
+ "spec/spec_helper.rb",
40
+ "spec/support/return.xml",
41
+ "spec/transaction/amount_spec.rb",
42
+ "spec/transaction/base_spec.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/matiasleidemer/pagseguro_catcher}
45
+ s.licenses = [%q{MIT}]
46
+ s.require_paths = [%q{lib}]
47
+ s.rubygems_version = %q{1.8.6}
48
+ s.summary = %q{A simple gem to parse PagSeguro transaction notification.}
49
+
50
+ if s.respond_to? :specification_version then
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
55
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
56
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
57
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
58
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_development_dependency(%q<rcov>, [">= 0"])
61
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<httparty>, [">= 0"])
64
+ s.add_dependency(%q<activesupport>, [">= 0"])
65
+ s.add_dependency(%q<i18n>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
70
+ s.add_dependency(%q<fakeweb>, [">= 0"])
71
+ end
72
+ else
73
+ s.add_dependency(%q<httparty>, [">= 0"])
74
+ s.add_dependency(%q<activesupport>, [">= 0"])
75
+ s.add_dependency(%q<i18n>, [">= 0"])
76
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
78
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
79
+ s.add_dependency(%q<rcov>, [">= 0"])
80
+ s.add_dependency(%q<fakeweb>, [">= 0"])
81
+ end
82
+ end
83
+
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'fakeweb'
3
+
4
+ describe "Checker" do
5
+
6
+ let(:notification_code) { "B7CEC7-4521D221D2EC-CFF43F1F959E-0C9B2E" }
7
+ let(:checker) { PagseguroCatcher::Checker.new(notification_code, 'transaction') }
8
+ let(:url) { "https://ws.pagseguro.uol.com.br/v2/transactions/notifications/B7CEC7-4521D221D2EC-CFF43F1F959E-0C9B2E?email=john@doe.com&token=1234" }
9
+
10
+ before(:each) do
11
+ FakeWeb.register_uri(:get, url, :body => File.open(File.expand_path(File.dirname(__FILE__) + '/support/return.xml')).read)
12
+
13
+ PagseguroCatcher.configure do |config|
14
+ config.token = "1234"
15
+ config.email = "john@doe.com"
16
+ end
17
+ end
18
+
19
+ # Processing PaymentGatewaysController#pagseguro (for 186.234.16.8 at 2011-10-03 15:12:37) [POST]
20
+ # Parameters: {"action"=>"pagseguro", "notificationCode"=>"B7CEC7-4521D221D2EC-CFF43F1F959E-0C9B2E", "notificationType"=>"transaction", "controller"=>"payment_gateways"}
21
+
22
+ describe ".initialize" do
23
+ it "assigns the code and type" do
24
+ code = "B7CEC7-4521D221D2EC-CFF43F1F959E-0C9B2E"
25
+ type = "transaction"
26
+
27
+ checker = PagseguroCatcher::Checker.new(code, type)
28
+ checker.code.should == code
29
+ checker.type.should == type
30
+ end
31
+ end
32
+
33
+ describe "#check" do
34
+ it "creates a Transaction from the Pagseguro server response" do
35
+ checker.check.should be_a(PagseguroCatcher::Transaction::Base)
36
+ end
37
+
38
+ it "assigns the response with the Pagseguro server response" do
39
+ checker.check
40
+ checker.response.should be_a(String)
41
+ end
42
+
43
+ it "overwrites the response if force is true" do
44
+ checker.response = "<transaction></transaction>"
45
+ checker.check
46
+ checker.response.should == "<transaction></transaction>"
47
+
48
+ checker.check(true)
49
+ checker.response.should_not == "<transaction></transaction>"
50
+ end
51
+ end
52
+
53
+ describe "#url" do
54
+ it "uses the specific url with the params on PagseguroCatcher module" do
55
+ checker.send(:url).should == url
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "PagseguroCatcher" do
4
+ it "yields the configuration" do
5
+ PagseguroCatcher.configure do |config|
6
+ config.should respond_to :token
7
+ config.should respond_to :email
8
+ config.should respond_to :url
9
+ end
10
+ end
11
+
12
+
13
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'pagseguro_catcher'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,56 @@
1
+ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
+ <transaction>
3
+ <date>2011-02-10T16:13:41.000-03:00</date>
4
+ <code>9E884542-81B3-4419-9A75-BCC6FB495EF1</code>
5
+ <reference>REF1234</reference>
6
+ <type>1</type>
7
+ <status>3</status>
8
+ <lastEventDate>2011-10-04T15:48:59.000-03:00</lastEventDate>
9
+ <paymentMethod>
10
+ <type>1</type>
11
+ <code>101</code>
12
+ </paymentMethod>
13
+ <grossAmount>49900.00</grossAmount>
14
+ <discountAmount>0.00</discountAmount>
15
+ <feeAmount>0.00</feeAmount>
16
+ <netAmount>49900.00</netAmount>
17
+ <extraAmount>0.00</extraAmount>
18
+ <installmentCount>1</installmentCount>
19
+ <itemCount>2</itemCount>
20
+ <items>
21
+ <item>
22
+ <id>0001</id>
23
+ <description>Notebook Prata</description>
24
+ <quantity>1</quantity>
25
+ <amount>24300.00</amount>
26
+ </item>
27
+ <item>
28
+ <id>0002</id>
29
+ <description>Notebook Rosa</description>
30
+ <quantity>1</quantity>
31
+ <amount>25600.00</amount>
32
+ </item>
33
+ </items>
34
+ <sender>
35
+ <name>José Comprador</name>
36
+ <email>comprador@uol.com.br</email>
37
+ <phone>
38
+ <areaCode>11</areaCode>
39
+ <number>56273440</number>
40
+ </phone>
41
+ </sender>
42
+ <shipping>
43
+ <address>
44
+ <street>Av. Brig. Faria Lima</street>
45
+ <number>1384</number>
46
+ <complement>5o andar</complement>
47
+ <district>Jardim Paulistano</district>
48
+ <postalCode>01452002</postalCode>
49
+ <city>Sao Paulo</city>
50
+ <state>SP</state>
51
+ <country>BRA</country>
52
+ </address>
53
+ <type>1</type>
54
+ <cost>21.50</cost>
55
+ </shipping>
56
+ </transaction>
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Amount" do
4
+
5
+ let(:xml) { File.open(File.expand_path(File.dirname(__FILE__) + '/../support/return.xml')).read }
6
+ let(:transaction) { PagseguroCatcher::Transaction::Base.new(xml) }
7
+ let(:amount) { PagseguroCatcher::Transaction::Amount.new(transaction.body) }
8
+
9
+ describe ".initialize" do
10
+ it "assigns the body" do
11
+ amount.body.should be_a(Hash)
12
+ end
13
+ end
14
+
15
+ describe "#gross" do
16
+ it "returns the gross amount as a float" do
17
+ amount.body[:grossAmount] = "49900.00"
18
+ amount.gross.should == 49900.00
19
+ end
20
+ end
21
+
22
+ describe "#discount" do
23
+ it "returns the discount amount as a float" do
24
+ amount.body[:discountAmount] = "900.00"
25
+ amount.discount.should == 900.00
26
+ end
27
+ end
28
+
29
+ describe "#fee" do
30
+ it "returns the fee amount as a float" do
31
+ amount.body[:feeAmount] = "150.00"
32
+ amount.fee.should == 150.00
33
+ end
34
+ end
35
+
36
+ describe "#net" do
37
+ it "returns the net amount as a float" do
38
+ amount.body[:netAmount] = "160.00"
39
+ amount.net.should == 160.00
40
+ end
41
+ end
42
+
43
+ describe "#extra" do
44
+ it "returns the extra amount as a float" do
45
+ amount.body[:extraAmount] = "170.00"
46
+ amount.extra.should == 170.00
47
+ end
48
+ end
49
+
50
+
51
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe "Transaction" do
5
+
6
+ let(:xml) { File.open(File.expand_path(File.dirname(__FILE__) + '/../support/return.xml')).read }
7
+ let(:transaction) { PagseguroCatcher::Transaction::Base.new(xml) }
8
+
9
+ describe ".initialize" do
10
+ it "assigns the body as Hash with the passed XML" do
11
+ transaction.body.should be_a(Hash)
12
+ end
13
+ end
14
+
15
+ describe "#[]" do
16
+ it "returns the hash value of the body" do
17
+ transaction.body[:code] = "1234"
18
+ transaction[:code].should == "1234"
19
+ end
20
+ end
21
+
22
+ describe "#amount" do
23
+ it "returns an Amount object" do
24
+ transaction.amount.should be_a(PagseguroCatcher::Transaction::Amount)
25
+ end
26
+ end
27
+
28
+ describe "#date" do
29
+ it "returns the date response as a DateTime object" do
30
+ transaction.body[:date] = "2011-02-10T16:13:41.000-03:00"
31
+ transaction.date.should == DateTime.new(2011, 02, 10, 16, 13, 41, "-03:00")
32
+ end
33
+ end
34
+
35
+ describe "#last_even_date" do
36
+ it "returns the last event date response as a DateTime object" do
37
+ transaction.body[:lastEventDate] = "2011-10-04T15:48:59.000-03:00"
38
+ transaction.last_event_date.should == DateTime.new(2011, 10, 04, 15, 48, 59, "-03:00")
39
+ end
40
+ end
41
+
42
+ describe "#transaction_type" do
43
+ it "returns the human value for the transaction type" do
44
+ transaction.body[:type] = "1"
45
+ transaction.transaction_type.should == "Pagamento"
46
+ end
47
+ end
48
+
49
+ describe "#transaction_status" do
50
+ it "returns the human value for the transaction status" do
51
+ transaction.body[:status] = "3"
52
+ transaction.transaction_status.should == "Paga"
53
+ end
54
+ end
55
+
56
+ describe "#payment_method_type" do
57
+ it "return the human value for the payment method" do
58
+ transaction.body[:paymentMethod][:type] = "1"
59
+ transaction.payment_method_type.should == "Cartão de crédito"
60
+ end
61
+ end
62
+
63
+ describe "#payment_method_code" do
64
+ it "return the human value for the payment method" do
65
+ transaction.body[:paymentMethod][:code] = "101"
66
+ transaction.payment_method_code.should == "Cartão de crédito Visa"
67
+ end
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pagseguro_catcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matias H. Leidemer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70216239563300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70216239563300
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70216239562580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70216239562580
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ requirement: &70216239561880 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70216239561880
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70216239561360 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70216239561360
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70216239560820 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70216239560820
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70216239560220 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.4
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70216239560220
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &70216239559400 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70216239559400
91
+ - !ruby/object:Gem::Dependency
92
+ name: fakeweb
93
+ requirement: &70216239558560 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70216239558560
102
+ description: This gem provides a simple way to check and parse the PagSeguro transaction
103
+ notification.
104
+ email: matiasleidemer@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files:
108
+ - LICENSE.txt
109
+ - README.textile
110
+ files:
111
+ - .document
112
+ - .rspec
113
+ - .travis.yml
114
+ - Gemfile
115
+ - Gemfile.lock
116
+ - LICENSE.txt
117
+ - README.textile
118
+ - Rakefile
119
+ - VERSION
120
+ - lib/pagseguro_catcher.rb
121
+ - lib/pagseguro_catcher/checker.rb
122
+ - lib/pagseguro_catcher/constants.rb
123
+ - lib/pagseguro_catcher/core_ext/Hash.rb
124
+ - lib/pagseguro_catcher/transaction.rb
125
+ - lib/pagseguro_catcher/transaction/amount.rb
126
+ - lib/pagseguro_catcher/transaction/base.rb
127
+ - pagseguro_catcher.gemspec
128
+ - spec/checker_spec.rb
129
+ - spec/pagseguro_catcher_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/support/return.xml
132
+ - spec/transaction/amount_spec.rb
133
+ - spec/transaction/base_spec.rb
134
+ homepage: http://github.com/matiasleidemer/pagseguro_catcher
135
+ licenses:
136
+ - MIT
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ segments:
148
+ - 0
149
+ hash: -4499129393277897347
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.6
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: A simple gem to parse PagSeguro transaction notification.
162
+ test_files: []