cbraspag 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.md +4 -3
  2. data/cbraspag.gemspec +2 -0
  3. data/coverage/.resultset.json +3445 -0
  4. data/coverage/assets/0.5.3/app.js +88 -0
  5. data/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  6. data/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  7. data/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  8. data/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  9. data/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  10. data/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  11. data/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  12. data/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  13. data/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  14. data/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  15. data/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  16. data/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  17. data/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  18. data/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  19. data/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  20. data/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  21. data/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  22. data/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  23. data/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  24. data/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  25. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +363 -0
  26. data/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
  27. data/coverage/assets/0.5.3/favicon_green.png +0 -0
  28. data/coverage/assets/0.5.3/favicon_red.png +0 -0
  29. data/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  30. data/coverage/assets/0.5.3/highlight.css +129 -0
  31. data/coverage/assets/0.5.3/highlight.pack.js +1 -0
  32. data/coverage/assets/0.5.3/jquery-1.6.2.min.js +18 -0
  33. data/coverage/assets/0.5.3/jquery.dataTables.min.js +152 -0
  34. data/coverage/assets/0.5.3/jquery.timeago.js +141 -0
  35. data/coverage/assets/0.5.3/jquery.url.js +174 -0
  36. data/coverage/assets/0.5.3/loading.gif +0 -0
  37. data/coverage/assets/0.5.3/magnify.png +0 -0
  38. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  39. data/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  40. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  41. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  42. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  43. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  44. data/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  45. data/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  46. data/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  47. data/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  48. data/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  49. data/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  50. data/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  51. data/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +295 -0
  52. data/coverage/assets/0.5.3/stylesheet.css +383 -0
  53. data/coverage/index.html +21549 -0
  54. data/lib/cbraspag.rb +1 -1
  55. data/lib/cbraspag/core/connection.rb +25 -20
  56. data/lib/cbraspag/core/converter.rb +22 -119
  57. data/lib/cbraspag/core/customer.rb +0 -24
  58. data/lib/cbraspag/core/order.rb +179 -129
  59. data/lib/cbraspag/payment/billet.rb +38 -17
  60. data/lib/cbraspag/payment/credit_card.rb +86 -112
  61. data/lib/cbraspag/payment/eft.rb +0 -16
  62. data/lib/cbraspag/payment/recurrency_credit_card.rb +99 -0
  63. data/lib/cbraspag/version.rb +1 -1
  64. data/spec/core/connection_spec.rb +56 -2
  65. data/spec/core/converter_spec.rb +49 -10
  66. data/spec/core/order_spec.rb +315 -193
  67. data/spec/integration/billet_spec.rb +38 -0
  68. data/spec/integration/credit_card_spec.rb +0 -0
  69. data/spec/payment/billet_spec.rb +130 -81
  70. data/spec/payment/credit_card_spec.rb +263 -487
  71. data/spec/payment/recurrency_credit_card_spec.rb +479 -0
  72. data/spec/spec_helper.rb +15 -2
  73. metadata +92 -6
  74. data/Guardfile +0 -10
  75. data/lib/cbraspag/core/response.rb +0 -27
  76. data/spec/core/response_spec.rb +0 -5
@@ -0,0 +1,479 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Braspag::Connection do
4
+ let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
5
+ let(:connection) { Braspag::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
6
+
7
+ context ".purchase" do
8
+ it "should return authorize when authroize response failed" do
9
+ auth = mock(:success? => false)
10
+ connection.stub(:authorize).and_return(auth)
11
+ connection.purchase(mock, mock).should eq(auth)
12
+ end
13
+
14
+ it "should return capture when authorize response success" do
15
+ cap = mock(:success? => true)
16
+ connection.stub(:authorize).and_return(mock(:success? => true))
17
+ connection.stub(:capture).and_return(cap)
18
+ connection.purchase(mock, mock).should eq(cap)
19
+ end
20
+ end
21
+
22
+ context ".authorize" do
23
+ it "should return response" do
24
+ authorize = {
25
+ :status => "2",
26
+ :message => "BLA",
27
+ :number => "12345"
28
+ }
29
+
30
+ connection.should_receive(:post).and_return(authorize)
31
+
32
+ response = connection.authorize(mock, mock)
33
+
34
+ response.success?.should eq(false)
35
+ response.message.should eq(authorize[:message])
36
+ response.authorization.should eq(authorize[:number])
37
+ response.params.should eq({"status"=>"2", "message"=>"BLA", "number"=>"12345"})
38
+ response.test.should eq(true)
39
+ end
40
+
41
+ it "should return success when status is zero" do
42
+ authorize = {
43
+ :status => "0",
44
+ :message => "BLA",
45
+ :number => "12345"
46
+ }
47
+
48
+ connection.should_receive(:post).and_return(authorize)
49
+
50
+ response = connection.authorize(mock, mock)
51
+
52
+ response.success?.should eq(true)
53
+ end
54
+
55
+ it "should return success when status is one" do
56
+ authorize = {
57
+ :status => "1",
58
+ :message => "BLA",
59
+ :number => "12345"
60
+ }
61
+
62
+ connection.should_receive(:post).and_return(authorize)
63
+
64
+ response = connection.authorize(mock, mock)
65
+
66
+ response.success?.should eq(true)
67
+ end
68
+ end
69
+
70
+ context ".capture" do
71
+ it "should return response" do
72
+ capture = {
73
+ :status => "1",
74
+ :message => "BLA",
75
+ :number => "12345"
76
+ }
77
+
78
+ connection.should_receive(:post).and_return(capture)
79
+
80
+ response = connection.capture(mock)
81
+
82
+ response.success?.should eq(false)
83
+ response.message.should eq(capture[:message])
84
+ response.authorization.should eq(capture[:number])
85
+ response.params.should eq({"status"=>"1", "message"=>"BLA", "number"=>"12345"})
86
+ response.test.should eq(true)
87
+ end
88
+
89
+ it "should return success when status is zero" do
90
+ capture = {
91
+ :status => "0",
92
+ :message => "BLA",
93
+ :number => "12345"
94
+ }
95
+
96
+ connection.should_receive(:post).and_return(capture)
97
+
98
+ response = connection.capture(mock)
99
+
100
+ response.success?.should eq(true)
101
+ end
102
+ end
103
+
104
+ context ".void" do
105
+ it "should return response" do
106
+ void = {
107
+ :status => "1",
108
+ :message => "BLA"
109
+ }
110
+
111
+ connection.should_receive(:post).and_return(void)
112
+
113
+ response = connection.void(mock)
114
+
115
+ response.success?.should eq(false)
116
+ response.message.should eq(void[:message])
117
+ response.params.should eq({"status"=>"1", "message"=>"BLA"})
118
+ response.test.should eq(true)
119
+ end
120
+
121
+ it "should return success when status is zero" do
122
+ void = {
123
+ :status => "0",
124
+ :message => "BLA"
125
+ }
126
+
127
+ connection.should_receive(:post).and_return(void)
128
+
129
+ response = connection.void(mock)
130
+
131
+ response.success?.should eq(true)
132
+ end
133
+ end
134
+
135
+ pending ".save" do
136
+ let(:params) do
137
+ {
138
+ :customer_name => "W" * 21,
139
+ :holder => "Joao Maria Souza",
140
+ :card_number => "9" * 10,
141
+ :expiration => "10/12",
142
+ :order_id => "um order id",
143
+ :request_id => "00000000-0000-0000-0000-000000000044"
144
+ }
145
+ end
146
+
147
+ let(:params_with_merchant_id) do
148
+ params.merge!(:merchant_id => merchant_id)
149
+ end
150
+
151
+ let(:save_protected_card_url) { "http://braspag.com/bla" }
152
+
153
+ let(:savon_double) { double('Savon') }
154
+
155
+ before do
156
+ @connection.should_receive(:merchant_id)
157
+ end
158
+
159
+ context "with valid params" do
160
+ let(:valid_hash) do
161
+ {
162
+ :save_credit_card_response => {
163
+ :save_credit_card_result => {
164
+ :just_click_key => 'SAVE-PROTECTED-CARD-TOKEN',
165
+ :success => true
166
+ }
167
+ }
168
+ }
169
+ end
170
+
171
+ let(:response) do
172
+ double('Response', :to_hash => valid_hash)
173
+ end
174
+
175
+ before do
176
+ Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
177
+ Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
178
+ .and_return(true)
179
+ Savon::Client.should_receive(:new).and_return(savon_double)
180
+ savon_double.should_receive(:request).and_return(response)
181
+
182
+ @response = Braspag::ProtectedCreditCard.save(params)
183
+ end
184
+
185
+ it "should return a Hash" do
186
+ @response.should be_kind_of Hash
187
+ @response.should == {
188
+ :just_click_key => "SAVE-PROTECTED-CARD-TOKEN",
189
+ :success => true
190
+ }
191
+ end
192
+ end
193
+
194
+ context "with invalid params" do
195
+ let(:invalid_hash) do
196
+ {
197
+ :save_credit_card_response => {
198
+ :save_credit_card_result => {
199
+ :just_click_key => nil,
200
+ :success => false
201
+ }
202
+ }
203
+ }
204
+ end
205
+
206
+ let(:response) do
207
+ double('Response', :to_hash => invalid_hash)
208
+ end
209
+
210
+ before do
211
+ Braspag::ProtectedCreditCard.should_receive(:check_protected_card_params)
212
+ .and_return(true)
213
+ Braspag::ProtectedCreditCard.should_receive(:save_protected_card_url)
214
+ .and_return(save_protected_card_url)
215
+ Savon::Client.should_receive(:new).and_return(savon_double)
216
+ savon_double.should_receive(:request).and_return(response)
217
+
218
+ @response = Braspag::ProtectedCreditCard.save(params)
219
+ end
220
+
221
+ it "should return a Hash" do
222
+ @response.should be_kind_of Hash
223
+ @response.should == {
224
+ :just_click_key => nil,
225
+ :success => false
226
+ }
227
+ end
228
+ end
229
+ end
230
+
231
+ pending ".get" do
232
+ let(:get_protected_card_url) { "http://braspag/bla" }
233
+
234
+ let(:invalid_xml) do
235
+ <<-EOXML
236
+ <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
237
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
238
+ xmlns="http://www.pagador.com.br/">
239
+ <CardHolder>Joao Maria Souza</CardHolder>
240
+ <CardNumber></CardNumber>
241
+ <CardExpiration>10/12</CardExpiration>
242
+ <MaskedCardNumber>******9999</MaskedCardNumber>
243
+ </CartaoProtegidoReturn>
244
+ EOXML
245
+ end
246
+
247
+ let(:valid_xml) do
248
+ <<-EOXML
249
+ <CartaoProtegidoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
250
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
251
+ xmlns="http://www.pagador.com.br/">
252
+ <CardHolder>Joao Maria Souza</CardHolder>
253
+ <CardNumber>9999999999</CardNumber>
254
+ <CardExpiration>10/12</CardExpiration>
255
+ <MaskedCardNumber>******9999</MaskedCardNumber>
256
+ </CartaoProtegidoReturn>
257
+ EOXML
258
+ end
259
+
260
+ it "should raise an error when just click key is not valid" do
261
+ Braspag::ProtectedCreditCard.should_receive(:valid_just_click_key?)
262
+ .with("bla")
263
+ .and_return(false)
264
+
265
+ expect {
266
+ Braspag::ProtectedCreditCard.get "bla"
267
+ }.to raise_error(Braspag::InvalidJustClickKey)
268
+ end
269
+
270
+ it "should raise an error when Braspag returned an invalid xml as response" do
271
+ FakeWeb.register_uri(:post, get_protected_card_url, :body => invalid_xml)
272
+
273
+ Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
274
+ .and_return(get_protected_card_url)
275
+
276
+ expect {
277
+ Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
278
+ }.to raise_error(Braspag::UnknownError)
279
+ end
280
+
281
+ it "should return a Hash when Braspag returned a valid xml as response" do
282
+ FakeWeb.register_uri(:post, get_protected_card_url, :body => valid_xml)
283
+
284
+ Braspag::ProtectedCreditCard.should_receive(:get_protected_card_url)
285
+ .and_return(get_protected_card_url)
286
+
287
+ response = Braspag::ProtectedCreditCard.get("b0b0b0b0-bbbb-4d4d-bd27-f1f1f1ededed")
288
+ response.should be_kind_of Hash
289
+
290
+ response.should == {
291
+ :holder => "Joao Maria Souza",
292
+ :expiration => "10/12",
293
+ :card_number => "9" * 10,
294
+ :masked_card_number => "*" * 6 + "9" * 4
295
+ }
296
+ end
297
+
298
+ end
299
+
300
+ pending ".just_click_shop" do
301
+ context "body" do
302
+ let(:params) { {
303
+ :request_id => "123",
304
+ :customer_name => "Joao Silva",
305
+ :order_id => "999",
306
+ :amount => 10.50,
307
+ :payment_method => :redecard,
308
+ :number_installments => 3,
309
+ :payment_type => "test",
310
+ :just_click_key => "key",
311
+ :security_code => "123"
312
+ } }
313
+
314
+ class SavonClientTest
315
+ attr_accessor :response
316
+ attr_reader :method
317
+
318
+ def request(web, method, &block)
319
+ @method = method
320
+ instance_eval &block
321
+
322
+ @response
323
+ end
324
+
325
+ def soap
326
+ @soap ||= OpenStruct.new
327
+ end
328
+ end
329
+
330
+ before :each do
331
+ @savon_client_test = SavonClientTest.new
332
+ @savon_client_test.response = {:just_click_shop_response => {}}
333
+ Savon::Client.stub(:new).with('https://www.cartaoprotegido.com.br/Services/TestEnvironment/CartaoProtegido.asmx?wsdl').and_return(@savon_client_test)
334
+ end
335
+
336
+ after :each do
337
+ Savon::Client.unstub(:new)
338
+ end
339
+
340
+ it "should have RequestId" do
341
+ described_class.just_click_shop(params)
342
+ @savon_client_test.soap.body['justClickShopRequestWS']['RequestId'].should eq '123'
343
+ end
344
+
345
+ it "should have MerchantKey" do
346
+ described_class.just_click_shop(params)
347
+ @savon_client_test.soap.body['justClickShopRequestWS']['MerchantKey'].should eq 'um id qualquer'
348
+ end
349
+
350
+ it "should have CustomerName" do
351
+ described_class.just_click_shop(params)
352
+ @savon_client_test.soap.body['justClickShopRequestWS']['CustomerName'].should eq 'Joao Silva'
353
+ end
354
+
355
+ it "should have OrderId" do
356
+ described_class.just_click_shop(params)
357
+ @savon_client_test.soap.body['justClickShopRequestWS']['OrderId'].should eq '999'
358
+ end
359
+
360
+ it "should have Amount" do
361
+ described_class.just_click_shop(params)
362
+ @savon_client_test.soap.body['justClickShopRequestWS']['Amount'].should eq 10.50
363
+ end
364
+
365
+ it "should have PaymentMethod" do
366
+ described_class.just_click_shop(params)
367
+ @savon_client_test.soap.body['justClickShopRequestWS']['PaymentMethod'].should eq 20
368
+ end
369
+
370
+ it "should have PaymentType" do
371
+ described_class.just_click_shop(params)
372
+ @savon_client_test.soap.body['justClickShopRequestWS']['PaymentType'].should eq 'test'
373
+ end
374
+
375
+ it "should have NumberInstallments" do
376
+ described_class.just_click_shop(params)
377
+ @savon_client_test.soap.body['justClickShopRequestWS']['NumberInstallments'].should eq 3
378
+ end
379
+
380
+ it "should have JustClickKey" do
381
+ described_class.just_click_shop(params)
382
+ @savon_client_test.soap.body['justClickShopRequestWS']['JustClickKey'].should eq 'key'
383
+ end
384
+
385
+ it "should have SecurityCode" do
386
+ described_class.just_click_shop(params)
387
+ @savon_client_test.soap.body['justClickShopRequestWS']['SecurityCode'].should eq '123'
388
+ end
389
+ end
390
+ end
391
+ end
392
+
393
+ describe Braspag::CreditCard do
394
+
395
+ [:purchase, :authorize, :archive].each do |context_type|
396
+ context "on #{context_type}" do
397
+ it "should validate minimum 1 length of holder_name" do
398
+ subject.holder_name = ''
399
+ subject.valid?(context_type)
400
+ subject.errors.messages[:holder_name].should include("is too short (minimum is 1 characters)")
401
+ end
402
+
403
+ it "should validate maximum 100 length of holder_name" do
404
+ subject.holder_name = '*' * 110
405
+ subject.valid?(context_type)
406
+ subject.errors.messages[:holder_name].should include("is too long (maximum is 100 characters)")
407
+ end
408
+
409
+ it "should not allow blank for number" do
410
+ subject.number = ''
411
+ subject.valid?(context_type)
412
+ subject.errors.messages[:number].should include("can't be blank")
413
+ end
414
+
415
+ it "should not allow blank for month" do
416
+ subject.month = ''
417
+ subject.valid?(context_type)
418
+ subject.errors.messages[:month].should include("can't be blank")
419
+ end
420
+
421
+ it "should not allow blank for year" do
422
+ subject.year = ''
423
+ subject.valid?(context_type)
424
+ subject.errors.messages[:year].should include("can't be blank")
425
+ end
426
+
427
+ it "should not allow invalid date for month & year" do
428
+ subject.month = "14"
429
+ subject.year = "2012"
430
+ subject.valid?(context_type)
431
+ subject.errors.messages[:month].should include("invalid date")
432
+ subject.errors.messages[:year].should include("invalid date")
433
+ end
434
+
435
+ it "should allow valid date for month & year" do
436
+ subject.month = "09"
437
+ subject.year = "12"
438
+ subject.valid?(context_type)
439
+ subject.errors.messages[:month].should be(nil)
440
+ subject.errors.messages[:year].should be(nil)
441
+ end
442
+
443
+ it "should allow valid date for month & year" do
444
+ subject.month = 12
445
+ subject.year = 2014
446
+ subject.valid?(context_type)
447
+ subject.errors.messages[:month].should be(nil)
448
+ subject.errors.messages[:year].should be(nil)
449
+ end
450
+ end
451
+ end
452
+
453
+ [:purchase, :authorize, :recurrency].each do |context_type|
454
+ context "on #{context_type}" do
455
+ it "should validate minimum 1 length of verification_value" do
456
+ subject.verification_value = ''
457
+ subject.valid?(context_type)
458
+ subject.errors.messages[:verification_value].should include("is too short (minimum is 1 characters)")
459
+ end
460
+
461
+ it "should validate maximum 4 length of verification_value" do
462
+ subject.verification_value = '*' * 5
463
+ subject.valid?(context_type)
464
+ subject.errors.messages[:verification_value].should include("is too long (maximum is 4 characters)")
465
+ end
466
+ end
467
+ end
468
+
469
+ [:get_recurrency, :recurrency].each do |context_type|
470
+ context "on #{context_type}" do
471
+ it "should validate length of id" do
472
+ subject.id = '*' * 37
473
+ subject.valid?(context_type)
474
+ subject.errors.messages[:id].should include("is the wrong length (should be 36 characters)")
475
+ end
476
+ end
477
+ end
478
+
479
+ end