pagseguro 0.1.10 → 0.1.11.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +35 -35
- data/README.markdown +6 -0
- data/lib/pagseguro/base.rb +1 -1
- data/lib/pagseguro/notification.rb +44 -18
- data/lib/pagseguro/utils.rb +2 -2
- data/lib/pagseguro/version.rb +2 -2
- data/pagseguro.gemspec +1 -1
- data/spec/pagseguro/notification_spec.rb +8 -8
- data/spec/pagseguro/pagseguro_spec.rb +5 -5
- metadata +7 -7
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "http://gems.simplesideias.com.br"
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pagseguro (0.1.
|
4
|
+
pagseguro (0.1.11.beta1)
|
5
5
|
|
6
6
|
GEM
|
7
|
-
remote: http://
|
7
|
+
remote: http://gems.simplesideias.com.br/
|
8
8
|
specs:
|
9
9
|
abstract (1.0.0)
|
10
|
-
actionmailer (3.0.
|
11
|
-
actionpack (= 3.0.
|
10
|
+
actionmailer (3.0.7)
|
11
|
+
actionpack (= 3.0.7)
|
12
12
|
mail (~> 2.2.15)
|
13
|
-
actionpack (3.0.
|
14
|
-
activemodel (= 3.0.
|
15
|
-
activesupport (= 3.0.
|
13
|
+
actionpack (3.0.7)
|
14
|
+
activemodel (= 3.0.7)
|
15
|
+
activesupport (= 3.0.7)
|
16
16
|
builder (~> 2.1.2)
|
17
17
|
erubis (~> 2.6.6)
|
18
|
-
i18n (~> 0.
|
18
|
+
i18n (~> 0.5.0)
|
19
19
|
rack (~> 1.2.1)
|
20
|
-
rack-mount (~> 0.6.
|
20
|
+
rack-mount (~> 0.6.14)
|
21
21
|
rack-test (~> 0.5.7)
|
22
22
|
tzinfo (~> 0.3.23)
|
23
|
-
activemodel (3.0.
|
24
|
-
activesupport (= 3.0.
|
23
|
+
activemodel (3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
25
|
builder (~> 2.1.2)
|
26
|
-
i18n (~> 0.
|
27
|
-
activerecord (3.0.
|
28
|
-
activemodel (= 3.0.
|
29
|
-
activesupport (= 3.0.
|
26
|
+
i18n (~> 0.5.0)
|
27
|
+
activerecord (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
30
|
arel (~> 2.0.2)
|
31
31
|
tzinfo (~> 0.3.23)
|
32
|
-
activeresource (3.0.
|
33
|
-
activemodel (= 3.0.
|
34
|
-
activesupport (= 3.0.
|
35
|
-
activesupport (3.0.
|
32
|
+
activeresource (3.0.7)
|
33
|
+
activemodel (= 3.0.7)
|
34
|
+
activesupport (= 3.0.7)
|
35
|
+
activesupport (3.0.7)
|
36
36
|
archive-tar-minitar (0.5.2)
|
37
|
-
arel (2.0.
|
37
|
+
arel (2.0.10)
|
38
38
|
builder (2.1.2)
|
39
39
|
columnize (0.3.2)
|
40
40
|
diff-lcs (1.1.2)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
i18n (0.5.0)
|
45
45
|
linecache19 (0.5.12)
|
46
46
|
ruby_core_source (>= 0.1.4)
|
47
|
-
mail (2.2.
|
47
|
+
mail (2.2.19)
|
48
48
|
activesupport (>= 2.3.6)
|
49
49
|
i18n (>= 0.4.0)
|
50
50
|
mime-types (~> 1.16)
|
@@ -52,22 +52,22 @@ GEM
|
|
52
52
|
mime-types (1.16)
|
53
53
|
nokogiri (1.4.4)
|
54
54
|
polyglot (0.3.1)
|
55
|
-
rack (1.2.
|
55
|
+
rack (1.2.3)
|
56
56
|
rack-mount (0.6.14)
|
57
57
|
rack (>= 1.0.0)
|
58
58
|
rack-test (0.5.7)
|
59
59
|
rack (>= 1.0)
|
60
|
-
rails (3.0.
|
61
|
-
actionmailer (= 3.0.
|
62
|
-
actionpack (= 3.0.
|
63
|
-
activerecord (= 3.0.
|
64
|
-
activeresource (= 3.0.
|
65
|
-
activesupport (= 3.0.
|
60
|
+
rails (3.0.7)
|
61
|
+
actionmailer (= 3.0.7)
|
62
|
+
actionpack (= 3.0.7)
|
63
|
+
activerecord (= 3.0.7)
|
64
|
+
activeresource (= 3.0.7)
|
65
|
+
activesupport (= 3.0.7)
|
66
66
|
bundler (~> 1.0)
|
67
|
-
railties (= 3.0.
|
68
|
-
railties (3.0.
|
69
|
-
actionpack (= 3.0.
|
70
|
-
activesupport (= 3.0.
|
67
|
+
railties (= 3.0.7)
|
68
|
+
railties (3.0.7)
|
69
|
+
actionpack (= 3.0.7)
|
70
|
+
activesupport (= 3.0.7)
|
71
71
|
rake (>= 0.8.7)
|
72
72
|
thor (~> 0.14.4)
|
73
73
|
rake (0.8.7)
|
@@ -75,7 +75,7 @@ GEM
|
|
75
75
|
rspec-core (~> 2.5.0)
|
76
76
|
rspec-expectations (~> 2.5.0)
|
77
77
|
rspec-mocks (~> 2.5.0)
|
78
|
-
rspec-core (2.5.
|
78
|
+
rspec-core (2.5.2)
|
79
79
|
rspec-expectations (2.5.0)
|
80
80
|
diff-lcs (~> 1.1.2)
|
81
81
|
rspec-mocks (2.5.0)
|
@@ -100,7 +100,7 @@ GEM
|
|
100
100
|
thor (0.14.6)
|
101
101
|
treetop (1.4.9)
|
102
102
|
polyglot (>= 0.3.1)
|
103
|
-
tzinfo (0.3.
|
103
|
+
tzinfo (0.3.27)
|
104
104
|
|
105
105
|
PLATFORMS
|
106
106
|
ruby
|
@@ -109,7 +109,7 @@ DEPENDENCIES
|
|
109
109
|
fakeweb (~> 1.3.0)
|
110
110
|
nokogiri (~> 1.4.4)
|
111
111
|
pagseguro!
|
112
|
-
rails (~> 3.0
|
112
|
+
rails (~> 3.0)
|
113
113
|
rspec-rails (~> 2.5.0)
|
114
114
|
ruby-debug19
|
115
115
|
sqlite3-ruby (~> 1.3.3)
|
data/README.markdown
CHANGED
@@ -28,6 +28,12 @@ O primeiro passo é instalar a biblioteca. Para isso, basta executar o comando
|
|
28
28
|
|
29
29
|
gem install pagseguro
|
30
30
|
|
31
|
+
Adicione a biblioteca ao arquivo Gemfile:
|
32
|
+
|
33
|
+
gem "pagseguro", "~> 0.1.10"
|
34
|
+
|
35
|
+
Lembre-se de utilizar a versão que você acabou de instalar.
|
36
|
+
|
31
37
|
Depois de instalar a biblioteca, você precisará executar gerar o arquivo de configuração, que deve residir em `config/pagseguro.yml`. Para gerar um arquivo de modelo execute
|
32
38
|
|
33
39
|
rails generate pagseguro:install
|
data/lib/pagseguro/base.rb
CHANGED
@@ -3,7 +3,7 @@ module PagSeguro
|
|
3
3
|
|
4
4
|
# PagSeguro receives all invoices in this URL. If developer mode is enabled,
|
5
5
|
# then the URL will be /pagseguro_developer/invoice
|
6
|
-
GATEWAY_URL = "https://pagseguro.uol.com.br/
|
6
|
+
GATEWAY_URL = "https://pagseguro.uol.com.br/pagseguro-ws/checkout/NPI.jhtml"
|
7
7
|
|
8
8
|
# Hold the config/pagseguro.yml contents
|
9
9
|
@@config = nil
|
@@ -3,7 +3,8 @@ module PagSeguro
|
|
3
3
|
class Notification
|
4
4
|
API_URL = "https://pagseguro.uol.com.br/Security/NPI/Default.aspx"
|
5
5
|
|
6
|
-
# Map all the attributes from PagSeguro
|
6
|
+
# Map all the attributes from PagSeguro.
|
7
|
+
#
|
7
8
|
MAPPING = {
|
8
9
|
:payment_method => "TipoPagamento",
|
9
10
|
:order_id => "Referencia",
|
@@ -15,7 +16,8 @@ module PagSeguro
|
|
15
16
|
:notes => "Anotacao"
|
16
17
|
}
|
17
18
|
|
18
|
-
# Map order status from PagSeguro
|
19
|
+
# Map order status from PagSeguro.
|
20
|
+
#
|
19
21
|
STATUS = {
|
20
22
|
"Completo" => :completed,
|
21
23
|
"Aguardando Pagto" => :pending,
|
@@ -25,7 +27,8 @@ module PagSeguro
|
|
25
27
|
"Devolvido" => :refunded
|
26
28
|
}
|
27
29
|
|
28
|
-
# Map payment method from PagSeguro
|
30
|
+
# Map payment method from PagSeguro.
|
31
|
+
#
|
29
32
|
PAYMENT_METHOD = {
|
30
33
|
"Cartão de Crédito" => :credit_card,
|
31
34
|
"Boleto" => :invoice,
|
@@ -33,25 +36,39 @@ module PagSeguro
|
|
33
36
|
"Pagamento online" => :online_transfer
|
34
37
|
}
|
35
38
|
|
36
|
-
# The Rails params hash
|
39
|
+
# The Rails params hash.
|
40
|
+
#
|
37
41
|
attr_accessor :params
|
38
42
|
|
39
|
-
# Expects the params object from the current request
|
43
|
+
# Expects the params object from the current request.
|
44
|
+
# PagSeguro will send POST with ISO-8859-1 encoded data,
|
45
|
+
# so we need to normalize it to UTF-8.
|
46
|
+
#
|
40
47
|
def initialize(params, token = nil)
|
41
48
|
@token = token
|
42
49
|
@params = PagSeguro.developer? ? params : normalize(params)
|
43
50
|
end
|
44
51
|
|
45
|
-
# Normalize the specified hash converting all data to UTF-8
|
52
|
+
# Normalize the specified hash converting all data to UTF-8.
|
53
|
+
#
|
46
54
|
def normalize(hash)
|
47
55
|
each_value(hash) do |value|
|
48
56
|
Utils.to_utf8(value)
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
60
|
+
# Denormalize the specified hash converting all data to ISO-8859-1.
|
61
|
+
#
|
62
|
+
def denormalize(hash)
|
63
|
+
each_value(hash) do |value|
|
64
|
+
Utils.to_iso8859(value)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
52
68
|
# Return a list of products sent by PagSeguro.
|
53
69
|
# The values will be normalized
|
54
70
|
# (e.g. currencies will be converted to cents, quantity will be an integer)
|
71
|
+
#
|
55
72
|
def products
|
56
73
|
@products ||= begin
|
57
74
|
items = []
|
@@ -71,25 +88,29 @@ module PagSeguro
|
|
71
88
|
end
|
72
89
|
end
|
73
90
|
|
74
|
-
# Return the shipping fee
|
75
|
-
# Will be converted to a float number
|
91
|
+
# Return the shipping fee.
|
92
|
+
# Will be converted to a float number.
|
93
|
+
#
|
76
94
|
def shipping
|
77
95
|
to_price mapping_for(:shipping)
|
78
96
|
end
|
79
97
|
|
80
|
-
# Return the order status
|
81
|
-
# Will be mapped to the STATUS constant
|
98
|
+
# Return the order status.
|
99
|
+
# Will be mapped to the STATUS constant.
|
100
|
+
#
|
82
101
|
def status
|
83
102
|
@status ||= STATUS[mapping_for(:status)]
|
84
103
|
end
|
85
104
|
|
86
|
-
# Return the payment method
|
87
|
-
# Will be mapped to the PAYMENT_METHOD constant
|
105
|
+
# Return the payment method.
|
106
|
+
# Will be mapped to the PAYMENT_METHOD constant.
|
107
|
+
#
|
88
108
|
def payment_method
|
89
109
|
@payment_method ||= PAYMENT_METHOD[mapping_for(:payment_method)]
|
90
110
|
end
|
91
111
|
|
92
|
-
# Parse the processing date to a Ruby object
|
112
|
+
# Parse the processing date to a Ruby object.
|
113
|
+
#
|
93
114
|
def processed_at
|
94
115
|
@processed_at ||= begin
|
95
116
|
groups = *mapping_for(:processed_at).match(/(\d{2})\/(\d{2})\/(\d{4}) ([\d:]+)/sm)
|
@@ -97,7 +118,8 @@ module PagSeguro
|
|
97
118
|
end
|
98
119
|
end
|
99
120
|
|
100
|
-
# Return the buyer info
|
121
|
+
# Return the buyer info.
|
122
|
+
#
|
101
123
|
def buyer
|
102
124
|
@buyer ||= {
|
103
125
|
:name => params["CliNome"],
|
@@ -129,7 +151,8 @@ module PagSeguro
|
|
129
151
|
end
|
130
152
|
|
131
153
|
# A wrapper to the params hash,
|
132
|
-
# sanitizing the return to symbols
|
154
|
+
# sanitizing the return to symbols.
|
155
|
+
#
|
133
156
|
def mapping_for(name)
|
134
157
|
params[MAPPING[name]]
|
135
158
|
end
|
@@ -139,6 +162,7 @@ module PagSeguro
|
|
139
162
|
#
|
140
163
|
# invoice.valid?
|
141
164
|
# invoice.valid?(:nocache)
|
165
|
+
#
|
142
166
|
def valid?(force=false)
|
143
167
|
@valid = nil if force
|
144
168
|
@valid = validates? if @valid.nil?
|
@@ -146,7 +170,7 @@ module PagSeguro
|
|
146
170
|
end
|
147
171
|
|
148
172
|
private
|
149
|
-
def each_value(hash, &blk)
|
173
|
+
def each_value(hash, &blk) # :nodoc:
|
150
174
|
hash.each do |key, value|
|
151
175
|
if value.kind_of?(Hash)
|
152
176
|
hash[key] = each_value(value, &blk)
|
@@ -158,7 +182,8 @@ module PagSeguro
|
|
158
182
|
hash
|
159
183
|
end
|
160
184
|
|
161
|
-
# Convert amount format to float
|
185
|
+
# Convert amount format to float.
|
186
|
+
#
|
162
187
|
def to_price(amount)
|
163
188
|
amount = "0#{amount}" if amount =~ /^\,/
|
164
189
|
amount.to_s.gsub(/[^\d]/, "").gsub(/^(\d+)(\d{2})$/, '\1.\2').to_f
|
@@ -167,6 +192,7 @@ module PagSeguro
|
|
167
192
|
# Check if the provided data is valid by requesting the
|
168
193
|
# confirmation API url. The request will always be valid while running in
|
169
194
|
# developer mode.
|
195
|
+
#
|
170
196
|
def validates?
|
171
197
|
return true if PagSeguro.developer?
|
172
198
|
|
@@ -184,7 +210,7 @@ module PagSeguro
|
|
184
210
|
http.ca_file = File.dirname(__FILE__) + "/cacert.pem"
|
185
211
|
|
186
212
|
request = Net::HTTP::Post.new(uri.path)
|
187
|
-
request.
|
213
|
+
request.form_data = denormalize(request_params)
|
188
214
|
response = http.start {|r| r.request request }
|
189
215
|
(response.body =~ /VERIFICADO/) != nil
|
190
216
|
end
|
data/lib/pagseguro/utils.rb
CHANGED
@@ -3,11 +3,11 @@ module PagSeguro
|
|
3
3
|
extend self
|
4
4
|
|
5
5
|
def to_utf8(string)
|
6
|
-
string.to_s.unpack(
|
6
|
+
string.to_s.unpack("C*").pack("U*")
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_iso8859(string)
|
10
|
-
string.to_s.unpack(
|
10
|
+
string.to_s.unpack("U*").pack("C*")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/pagseguro/version.rb
CHANGED
data/pagseguro.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_development_dependency "rails" , "~> 3.0
|
20
|
+
s.add_development_dependency "rails" , "~> 3.0"
|
21
21
|
s.add_development_dependency "fakeweb" , "~> 1.3.0"
|
22
22
|
s.add_development_dependency "rspec-rails" , "~> 2.5.0"
|
23
23
|
s.add_development_dependency "nokogiri" , "~> 1.4.4"
|
@@ -8,7 +8,7 @@ describe PagSeguro::Notification do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should not request the confirmation url when running developer mode" do
|
11
|
-
PagSeguro.stub
|
11
|
+
PagSeguro.stub :developer? => true
|
12
12
|
Net::HTTP.should_not_receive(:new)
|
13
13
|
@notification.should be_valid
|
14
14
|
end
|
@@ -217,9 +217,9 @@ describe PagSeguro::Notification do
|
|
217
217
|
|
218
218
|
describe "confirmation" do
|
219
219
|
before do
|
220
|
-
PagSeguro.stub
|
220
|
+
PagSeguro.stub :developer? => false
|
221
221
|
@url = PagSeguro::Notification::API_URL
|
222
|
-
@notification.stub
|
222
|
+
@notification.stub :api_url => @url
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should be valid" do
|
@@ -245,7 +245,7 @@ describe PagSeguro::Notification do
|
|
245
245
|
notification = PagSeguro::Notification.new(@the_params, 'ABCDEF')
|
246
246
|
|
247
247
|
post = mock("post").as_null_object
|
248
|
-
post.should_receive(:
|
248
|
+
post.should_receive(:form_data=).with({:Comando => "validar", :Token => "ABCDEF"})
|
249
249
|
|
250
250
|
Net::HTTP.should_receive(:new).and_return(mock("http").as_null_object)
|
251
251
|
Net::HTTP::Post.should_receive(:new).and_return(post)
|
@@ -254,10 +254,10 @@ describe PagSeguro::Notification do
|
|
254
254
|
end
|
255
255
|
|
256
256
|
it "should set the authenticity token from the configuration" do
|
257
|
-
PagSeguro.stub
|
257
|
+
PagSeguro.stub :config => {"authenticity_token" => "ABCDEF"}
|
258
258
|
|
259
259
|
post = mock("post").as_null_object
|
260
|
-
post.should_receive(:
|
260
|
+
post.should_receive(:form_data=).with({:Comando => "validar", :Token => "ABCDEF"})
|
261
261
|
|
262
262
|
Net::HTTP.should_receive(:new).and_return(mock("http").as_null_object)
|
263
263
|
Net::HTTP::Post.should_receive(:new).and_return(post)
|
@@ -268,10 +268,10 @@ describe PagSeguro::Notification do
|
|
268
268
|
it "should propagate params" do
|
269
269
|
param!("VendedorEmail", "john@doe.com")
|
270
270
|
param!("NumItens", "14")
|
271
|
-
PagSeguro.stub
|
271
|
+
PagSeguro.stub :config => {"authenticity_token" => "ABCDEF"}
|
272
272
|
|
273
273
|
post = mock("post").as_null_object
|
274
|
-
post.should_receive(:
|
274
|
+
post.should_receive(:form_data=).with({
|
275
275
|
:Comando => "validar",
|
276
276
|
:Token => "ABCDEF",
|
277
277
|
"VendedorEmail" => "john@doe.com",
|
@@ -5,8 +5,8 @@ describe PagSeguro do
|
|
5
5
|
before do
|
6
6
|
@config_file = Rails.root.join("config/pagseguro.yml")
|
7
7
|
@contents = YAML.load_file(@config_file)
|
8
|
-
File.stub
|
9
|
-
YAML.stub
|
8
|
+
File.stub :exists? => true
|
9
|
+
YAML.stub :load_file => @contents
|
10
10
|
|
11
11
|
module PagSeguro; @@config = nil; end
|
12
12
|
end
|
@@ -34,14 +34,14 @@ describe PagSeguro do
|
|
34
34
|
|
35
35
|
it "should return real url if developer mode is disabled" do
|
36
36
|
PagSeguro.should_receive(:developer?).and_return(false)
|
37
|
-
PagSeguro.gateway_url.should == "https://pagseguro.uol.com.br/
|
37
|
+
PagSeguro.gateway_url.should == "https://pagseguro.uol.com.br/pagseguro-ws/checkout/NPI.jhtml"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should read configuration developer mode" do
|
41
|
-
PagSeguro.stub
|
41
|
+
PagSeguro.stub :config => {"developer" => true}
|
42
42
|
PagSeguro.should be_developer
|
43
43
|
|
44
|
-
PagSeguro.stub
|
44
|
+
PagSeguro.stub :config => {"developer" => false}
|
45
45
|
PagSeguro.should_not be_developer
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagseguro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.1.
|
4
|
+
prerelease: 7
|
5
|
+
version: 0.1.11.beta1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nando Vieira
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 3.0
|
23
|
+
version: "3.0"
|
24
24
|
type: :development
|
25
25
|
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
@@ -153,13 +153,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
none: false
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - ">"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: 1.3.1
|
159
159
|
requirements: []
|
160
160
|
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 1.
|
162
|
+
rubygems_version: 1.8.3
|
163
163
|
signing_key:
|
164
164
|
specification_version: 3
|
165
165
|
summary: The official PagSeguro library
|