pagseguro 0.1.11.beta1 → 0.1.11.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config CHANGED
@@ -1,2 +1,2 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
1
+ --- {}
2
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pagseguro (0.1.11.beta1)
4
+ pagseguro (0.1.11.beta2)
5
5
 
6
6
  GEM
7
7
  remote: http://gems.simplesideias.com.br/
@@ -33,7 +33,8 @@ module PagSeguro
33
33
  "Cartão de Crédito" => :credit_card,
34
34
  "Boleto" => :invoice,
35
35
  "Pagamento" => :pagseguro,
36
- "Pagamento online" => :online_transfer
36
+ "Pagamento Online" => :online_transfer,
37
+ "Doação" => :donation
37
38
  }
38
39
 
39
40
  # The Rails params hash.
@@ -169,6 +170,14 @@ module PagSeguro
169
170
  @valid
170
171
  end
171
172
 
173
+ # Return all useful properties in a single hash.
174
+ #
175
+ def to_hash
176
+ MAPPING.inject({}) do |buffer, (name,value)|
177
+ buffer.merge(name => __send__(name))
178
+ end
179
+ end
180
+
172
181
  private
173
182
  def each_value(hash, &blk) # :nodoc:
174
183
  hash.each do |key, value|
@@ -3,6 +3,6 @@ module PagSeguro
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  PATCH = 11
6
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.beta1"
6
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.beta2"
7
7
  end
8
8
  end
@@ -0,0 +1,29 @@
1
+ ---
2
+ VendedorEmail: vendedor@example.com
3
+ TransacaoID: 2339ADE917F744DEBEDA890C826386EG
4
+ Referencia: "1"
5
+ Extras: "0,00"
6
+ TipoFrete: FR
7
+ ValorFrete: "0,00"
8
+ Anotacao: "Pagamento do carro"
9
+ DataTransacao: 26/05/2011 12:17:47
10
+ TipoPagamento: Pagamento Online
11
+ StatusTransacao: Aprovado
12
+ CliNome: "Jos\xC3\xA9 da Silva"
13
+ CliEmail: comprador@exemple.com
14
+ CliEndereco: RUA DE CIMA
15
+ CliNumero: "1145"
16
+ CliComplemento: apto 1
17
+ CliBairro: "Pequen\xC3\xB3polis"
18
+ CliCidade: SAO PAULO
19
+ CliEstado: SP
20
+ CliCEP: "04253000"
21
+ CliTelefone: 11 75379467
22
+ NumItens: "1"
23
+ Parcelas: "1"
24
+ ProdID_1: "9"
25
+ ProdDescricao_1: Carro Zero Km
26
+ ProdValor_1: "15,00"
27
+ ProdQuantidade_1: "1"
28
+ ProdFrete_1: "0,00"
29
+ ProdExtras_1: "0,00"
@@ -2,122 +2,137 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe PagSeguro::Notification do
5
- before do
6
- @the_params = {}
7
- @notification = PagSeguro::Notification.new(@the_params)
8
- end
5
+ subject { PagSeguro::Notification.new(@the_params) }
6
+ let(:payload) { YAML.load_file File.dirname(__FILE__) + "/../fixtures/notification.yml" }
7
+ before { @the_params = {} }
9
8
 
10
9
  it "should not request the confirmation url when running developer mode" do
11
10
  PagSeguro.stub :developer? => true
12
11
  Net::HTTP.should_not_receive(:new)
13
- @notification.should be_valid
12
+ subject.should be_valid
13
+ end
14
+
15
+ describe "#to_hash" do
16
+ subject { PagSeguro::Notification.new(payload) }
17
+
18
+ PagSeguro::Notification::MAPPING.each do |name, value|
19
+ it "includes #{name}" do
20
+ subject.to_hash.should have_key(name)
21
+ subject.to_hash[name].should_not be_nil
22
+ end
23
+ end
14
24
  end
15
25
 
16
26
  describe "status mapping" do
17
27
  it "should be completed" do
18
28
  set_status!("Completo")
19
- @notification.status.should == :completed
29
+ subject.status.should == :completed
20
30
  end
21
31
 
22
32
  it "should be pending" do
23
33
  set_status!("Aguardando Pagto")
24
- @notification.status.should == :pending
34
+ subject.status.should == :pending
25
35
  end
26
36
 
27
37
  it "should be approved" do
28
38
  set_status!("Aprovado")
29
- @notification.status.should == :approved
39
+ subject.status.should == :approved
30
40
  end
31
41
 
32
42
  it "should be verifying" do
33
43
  set_status!("Em Análise")
34
- @notification.status.should == :verifying
44
+ subject.status.should == :verifying
35
45
  end
36
46
 
37
47
  it "should be canceled" do
38
48
  set_status!("Cancelado")
39
- @notification.status.should == :canceled
49
+ subject.status.should == :canceled
40
50
  end
41
51
 
42
52
  it "should be refunded" do
43
53
  set_status!("Devolvido")
44
- @notification.status.should == :refunded
54
+ subject.status.should == :refunded
45
55
  end
46
56
  end
47
57
 
48
58
  describe "payment mapping" do
49
59
  it "should be credit card" do
50
60
  set_payment!("Cartão de Crédito")
51
- @notification.payment_method.should == :credit_card
61
+ subject.payment_method.should == :credit_card
52
62
  end
53
63
 
54
64
  it "should be invoice" do
55
65
  set_payment!("Boleto")
56
- @notification.payment_method.should == :invoice
66
+ subject.payment_method.should == :invoice
57
67
  end
58
68
 
59
69
  it "should be pagseguro" do
60
70
  set_payment!("Pagamento")
61
- @notification.payment_method.should == :pagseguro
71
+ subject.payment_method.should == :pagseguro
62
72
  end
63
73
 
64
74
  it "should be online transfer" do
65
- set_payment!("Pagamento online")
66
- @notification.payment_method.should == :online_transfer
75
+ set_payment!("Pagamento Online")
76
+ subject.payment_method.should == :online_transfer
77
+ end
78
+
79
+ it "should be donation" do
80
+ set_payment!("Doação")
81
+ subject.payment_method.should == :donation
67
82
  end
68
83
  end
69
84
 
70
85
  describe "buyer mapping" do
71
86
  it "should return client name" do
72
87
  param!("CliNome", "John Doe")
73
- @notification.buyer[:name].should == "John Doe"
88
+ subject.buyer[:name].should == "John Doe"
74
89
  end
75
90
 
76
91
  it "should return client email" do
77
92
  param!("CliEmail", "john@doe.com")
78
- @notification.buyer[:email].should == "john@doe.com"
93
+ subject.buyer[:email].should == "john@doe.com"
79
94
  end
80
95
 
81
96
  it "should return client phone" do
82
97
  param!("CliTelefone", "11 55551234")
83
- @notification.buyer[:phone][:area_code].should == "11"
84
- @notification.buyer[:phone][:number].should == "55551234"
98
+ subject.buyer[:phone][:area_code].should == "11"
99
+ subject.buyer[:phone][:number].should == "55551234"
85
100
  end
86
101
 
87
102
  describe "address" do
88
103
  it "should return street" do
89
104
  param!("CliEndereco", "Av. Paulista")
90
- @notification.buyer[:address][:street].should == "Av. Paulista"
105
+ subject.buyer[:address][:street].should == "Av. Paulista"
91
106
  end
92
107
 
93
108
  it "should return number" do
94
109
  param!("CliNumero", "2500")
95
- @notification.buyer[:address][:number].should == "2500"
110
+ subject.buyer[:address][:number].should == "2500"
96
111
  end
97
112
 
98
113
  it "should return complements" do
99
114
  param!("CliComplemento", "Apto 123-A")
100
- @notification.buyer[:address][:complements].should == "Apto 123-A"
115
+ subject.buyer[:address][:complements].should == "Apto 123-A"
101
116
  end
102
117
 
103
118
  it "should return neighbourhood" do
104
119
  param!("CliBairro", "Bela Vista")
105
- @notification.buyer[:address][:neighbourhood].should == "Bela Vista"
120
+ subject.buyer[:address][:neighbourhood].should == "Bela Vista"
106
121
  end
107
122
 
108
123
  it "should return city" do
109
124
  param!("CliCidade", "São Paulo")
110
- @notification.buyer[:address][:city].should == "São Paulo"
125
+ subject.buyer[:address][:city].should == "São Paulo"
111
126
  end
112
127
 
113
128
  it "should return state" do
114
129
  param!("CliEstado", "SP")
115
- @notification.buyer[:address][:state].should == "SP"
130
+ subject.buyer[:address][:state].should == "SP"
116
131
  end
117
132
 
118
133
  it "should return postal code" do
119
134
  param!("CliCEP", "01310300")
120
- @notification.buyer[:address][:postal_code].should == "01310300"
135
+ subject.buyer[:address][:postal_code].should == "01310300"
121
136
  end
122
137
  end
123
138
  end
@@ -125,35 +140,35 @@ describe PagSeguro::Notification do
125
140
  describe "other mappings" do
126
141
  it "should map the order id" do
127
142
  param!("Referencia", "ABCDEF")
128
- @notification.order_id.should == "ABCDEF"
143
+ subject.order_id.should == "ABCDEF"
129
144
  end
130
145
 
131
146
  it "should map the processing date" do
132
147
  param!("DataTransacao", "04/09/2009 16:23:44")
133
- @notification.processed_at.should == Time.parse("2009-09-04 16:23:44").utc
148
+ subject.processed_at.should == Time.parse("2009-09-04 16:23:44").utc
134
149
  end
135
150
 
136
151
  it "should map the shipping type" do
137
152
  param!("TipoFrete", "SD")
138
- @notification.shipping_type.should == "SD"
153
+ subject.shipping_type.should == "SD"
139
154
  end
140
155
 
141
156
  it "should map the client annotation" do
142
157
  param!("Anotacao", "Gift package, please!")
143
- @notification.notes.should == "Gift package, please!"
158
+ subject.notes.should == "Gift package, please!"
144
159
  end
145
160
 
146
161
  it "should map the shipping price" do
147
162
  param!("ValorFrete", "199,38")
148
- @notification.shipping.should == 199.38
163
+ subject.shipping.should == 199.38
149
164
 
150
165
  param!("ValorFrete", "1.799,38")
151
- @notification.shipping.should == 1799.38
166
+ subject.shipping.should == 1799.38
152
167
  end
153
168
 
154
169
  it "should map the transaction id" do
155
170
  param!("TransacaoID", "ABCDEF")
156
- @notification.transaction_id.should == "ABCDEF"
171
+ subject.transaction_id.should == "ABCDEF"
157
172
  end
158
173
  end
159
174
 
@@ -164,17 +179,17 @@ describe PagSeguro::Notification do
164
179
 
165
180
  it "should map 5 products" do
166
181
  param!("NumItens", "5")
167
- @notification.products.should have(5).items
182
+ subject.products.should have(5).items
168
183
  end
169
184
 
170
185
  it "should map 25 products" do
171
186
  param!("NumItens", "25")
172
- @notification.products.should have(25).items
187
+ subject.products.should have(25).items
173
188
  end
174
189
 
175
190
  it "should set attributes with defaults" do
176
191
  set_product! :description => "Ruby 1.9 PDF", :price => "12,90", :id => 1
177
- p = @notification.products.first
192
+ p = subject.products.first
178
193
 
179
194
  p[:description].should == "Ruby 1.9 PDF"
180
195
  p[:price].should == 12.90
@@ -194,7 +209,7 @@ describe PagSeguro::Notification do
194
209
  :quantity => 10
195
210
  })
196
211
 
197
- p = @notification.products.first
212
+ p = subject.products.first
198
213
 
199
214
  p[:description].should == "Rails Application Templates"
200
215
  p[:price].should == 1.00
@@ -209,7 +224,7 @@ describe PagSeguro::Notification do
209
224
  :price => ",90",
210
225
  })
211
226
 
212
- p = @notification.products.first
227
+ p = subject.products.first
213
228
 
214
229
  p[:price].should == 0.9
215
230
  end
@@ -219,26 +234,26 @@ describe PagSeguro::Notification do
219
234
  before do
220
235
  PagSeguro.stub :developer? => false
221
236
  @url = PagSeguro::Notification::API_URL
222
- @notification.stub :api_url => @url
237
+ subject.stub :api_url => @url
223
238
  end
224
239
 
225
240
  it "should be valid" do
226
241
  FakeWeb.register_uri(:post, @url, :body => "VERIFICADO")
227
- @notification.should be_valid
242
+ subject.should be_valid
228
243
  end
229
244
 
230
245
  it "should be invalid" do
231
246
  FakeWeb.register_uri(:post, @url, :body => "")
232
- @notification.should_not be_valid
247
+ subject.should_not be_valid
233
248
  end
234
249
 
235
250
  it "should force validation" do
236
251
  FakeWeb.register_uri(:post, @url, :body => "")
237
- @notification.should_not be_valid
252
+ subject.should_not be_valid
238
253
 
239
254
  FakeWeb.register_uri(:post, @url, :body => "VERIFICADO")
240
- @notification.should_not be_valid
241
- @notification.should be_valid(:nocache)
255
+ subject.should_not be_valid
256
+ subject.should be_valid(:nocache)
242
257
  end
243
258
 
244
259
  it "should set the authenticity token from the initialization" do
@@ -262,7 +277,7 @@ describe PagSeguro::Notification do
262
277
  Net::HTTP.should_receive(:new).and_return(mock("http").as_null_object)
263
278
  Net::HTTP::Post.should_receive(:new).and_return(post)
264
279
 
265
- @notification.valid?
280
+ subject.valid?
266
281
  end
267
282
 
268
283
  it "should propagate params" do
@@ -281,45 +296,45 @@ describe PagSeguro::Notification do
281
296
  Net::HTTP.should_receive(:new).and_return(mock("http").as_null_object)
282
297
  Net::HTTP::Post.should_receive(:new).and_return(post)
283
298
 
284
- @notification.valid?
299
+ subject.valid?
285
300
  end
286
301
  end
287
302
 
288
303
  private
289
- def set_status!(value)
290
- param!("StatusTransacao", value)
291
- end
292
-
293
- def set_payment!(value)
294
- param!("TipoPagamento", value)
295
- end
296
-
297
- def param!(name, value)
298
- @notification.params.merge!(name => value)
299
- end
300
-
301
- def set_product!(options={})
302
- @__products ||= []
303
-
304
- i = @__products.size + 1
304
+ def set_status!(value)
305
+ param!("StatusTransacao", value)
306
+ end
305
307
 
306
- options = {
307
- :quantity => 1,
308
- :fees => "0,00",
309
- :shipping => "0,00"
310
- }.merge(options)
308
+ def set_payment!(value)
309
+ param!("TipoPagamento", value)
310
+ end
311
311
 
312
- @__products << {
313
- "ProdID_#{i}" => options[:id].to_s,
314
- "ProdDescricao_#{i}" => options[:description].to_s,
315
- "ProdValor_#{i}" => options[:price].to_s,
316
- "ProdFrete_#{i}" => options[:shipping].to_s,
317
- "ProdExtras_#{i}" => options[:fees].to_s,
318
- "ProdQuantidade_#{i}" => options[:quantity].to_s
319
- }
312
+ def param!(name, value)
313
+ subject.params.merge!(name => value)
314
+ end
320
315
 
321
- @notification.params.merge!(@__products.last)
322
- @notification.params.merge!("NumItens" => i)
323
- @__products.last
324
- end
316
+ def set_product!(options={})
317
+ @__products ||= []
318
+
319
+ i = @__products.size + 1
320
+
321
+ options = {
322
+ :quantity => 1,
323
+ :fees => "0,00",
324
+ :shipping => "0,00"
325
+ }.merge(options)
326
+
327
+ @__products << {
328
+ "ProdID_#{i}" => options[:id].to_s,
329
+ "ProdDescricao_#{i}" => options[:description].to_s,
330
+ "ProdValor_#{i}" => options[:price].to_s,
331
+ "ProdFrete_#{i}" => options[:shipping].to_s,
332
+ "ProdExtras_#{i}" => options[:fees].to_s,
333
+ "ProdQuantidade_#{i}" => options[:quantity].to_s
334
+ }
335
+
336
+ subject.params.merge!(@__products.last)
337
+ subject.params.merge!("NumItens" => i)
338
+ @__products.last
339
+ end
325
340
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pagseguro
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 7
5
- version: 0.1.11.beta1
5
+ version: 0.1.11.beta2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira
@@ -114,6 +114,7 @@ files:
114
114
  - lib/tasks/pagseguro.rake
115
115
  - pagseguro.gemspec
116
116
  - spec/controllers/developer_controller_spec.rb
117
+ - spec/fixtures/notification.yml
117
118
  - spec/helpers/helper_spec.rb
118
119
  - spec/pagseguro/faker_spec.rb
119
120
  - spec/pagseguro/notification_spec.rb
@@ -165,6 +166,7 @@ specification_version: 3
165
166
  summary: The official PagSeguro library
166
167
  test_files:
167
168
  - spec/controllers/developer_controller_spec.rb
169
+ - spec/fixtures/notification.yml
168
170
  - spec/helpers/helper_spec.rb
169
171
  - spec/pagseguro/faker_spec.rb
170
172
  - spec/pagseguro/notification_spec.rb