rbraspag 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +3 -3
- data/config/braspag.yml +12 -0
- data/lib/rbraspag/bill.rb +79 -79
- data/lib/rbraspag/connection.rb +15 -5
- data/lib/rbraspag/credit_card.rb +52 -42
- data/lib/rbraspag/crypto/jar_webservice.rb +12 -14
- data/lib/rbraspag/crypto/webservice.rb +14 -17
- data/lib/rbraspag/eft.rb +32 -48
- data/lib/rbraspag/order.rb +7 -37
- data/lib/rbraspag/utils.rb +27 -3
- data/lib/rbraspag/version.rb +1 -1
- data/lib/rbraspag.rb +0 -7
- data/rbraspag-0.0.11.gem +0 -0
- data/spec/bill_spec.rb +399 -314
- data/spec/connection_spec.rb +101 -26
- data/spec/credit_card_spec.rb +117 -48
- data/spec/crypto/jar_webservice_spec.rb +3 -6
- data/spec/crypto/webservice_spec.rb +9 -31
- data/spec/eft_spec.rb +137 -156
- data/spec/order_spec.rb +10 -24
- data/spec/utils_spec.rb +2 -0
- metadata +22 -20
data/spec/connection_spec.rb
CHANGED
@@ -2,53 +2,128 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::Connection do
|
5
|
-
let!(:connection) { Braspag::Connection }
|
6
5
|
let!(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
6
|
+
let!(:braspag_url) { "https://homologacao.pagador.com.br" }
|
7
|
+
let!(:crypto_key) {"{84BE7E7F-698A-6C74-F820-AE359C2A07C2}"}
|
8
|
+
let!(:crypto_url) {"http://localhost:9292"}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
let!(:mock_for_connection) {
|
11
|
+
mock = {}
|
12
|
+
mock[ENV["RACK_ENV"]] = {
|
13
|
+
"merchant_id" => merchant_id,
|
14
|
+
"braspag_url" => braspag_url,
|
15
|
+
"crypto_key" => crypto_key,
|
16
|
+
"crypto_url" => crypto_url
|
17
|
+
}
|
18
|
+
mock
|
19
|
+
}
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
@connection = Braspag::Connection.clone
|
11
23
|
end
|
12
24
|
|
13
|
-
it "
|
14
|
-
|
15
|
-
|
25
|
+
it "should read config/braspag.yml when alloc first instance" do
|
26
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_for_connection)
|
27
|
+
@connection.instance
|
16
28
|
end
|
17
29
|
|
18
|
-
it "
|
19
|
-
|
20
|
-
|
30
|
+
it "should not read config/braspag.yml when alloc second instance" do
|
31
|
+
YAML.should_not_receive(:load_file)
|
32
|
+
@connection.instance
|
33
|
+
end
|
21
34
|
|
22
|
-
|
35
|
+
it "should generate exception when RACK_ENV is nil" do
|
36
|
+
backup = ENV["RACK_ENV"].clone
|
37
|
+
ENV["RACK_ENV"] = nil
|
38
|
+
expect {
|
39
|
+
other_connection = Braspag::Connection.clone
|
40
|
+
other_connection.instance
|
41
|
+
}.should raise_error(Braspag::Connection::InvalidEnv)
|
42
|
+
ENV["RACK_ENV"] = backup
|
23
43
|
end
|
24
44
|
|
25
|
-
it "
|
26
|
-
|
45
|
+
it "should generate exception when RACK_ENV is empty" do
|
46
|
+
backup = ENV["RACK_ENV"].clone
|
47
|
+
ENV["RACK_ENV"] = ""
|
48
|
+
expect {
|
49
|
+
other_connection = Braspag::Connection.clone
|
50
|
+
other_connection.instance
|
51
|
+
}.should raise_error(Braspag::Connection::InvalidEnv)
|
52
|
+
ENV["RACK_ENV"] = backup
|
27
53
|
end
|
28
54
|
|
29
|
-
|
30
|
-
|
55
|
+
|
56
|
+
it "should generate exception when :merchant_id is more than 38 chars" do
|
57
|
+
mock_merchant = mock_for_connection
|
58
|
+
mock_merchant[ENV["RACK_ENV"]]["merchant_id"] = (1..100).collect{"A"}.join
|
59
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
60
|
+
other_connection = Braspag::Connection.clone
|
61
|
+
|
62
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidMerchantId)
|
31
63
|
end
|
32
64
|
|
33
|
-
it "
|
34
|
-
|
65
|
+
it "should generate exception when :merchant_id is less than 38 chars" do
|
66
|
+
mock_merchant = mock_for_connection
|
67
|
+
mock_merchant[ENV["RACK_ENV"]]["merchant_id"] = (1..37).collect{"B"}.join
|
68
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
69
|
+
other_connection = Braspag::Connection.clone
|
70
|
+
|
71
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidMerchantId)
|
35
72
|
end
|
36
73
|
|
37
|
-
|
38
|
-
|
74
|
+
context "should generate exception when :merchant_id not follow format {00000000-0000-0000-0000-000000000000}" do
|
75
|
+
it "0000000-0000-0000-0000-000000000000" do
|
76
|
+
mock_merchant = mock_for_connection
|
77
|
+
mock_merchant[ENV["RACK_ENV"]]["merchant_id"] = "0000000-0000-0000-0000-000000000000"
|
78
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
79
|
+
other_connection = Braspag::Connection.clone
|
80
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidMerchantId)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "{000000000000000000000000000000000000}" do
|
84
|
+
mock_merchant = mock_for_connection
|
85
|
+
mock_merchant[ENV["RACK_ENV"]]["merchant_id"] = "{000000000000000000000000000000000000}"
|
86
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
87
|
+
other_connection = Braspag::Connection.clone
|
88
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidMerchantId)
|
89
|
+
end
|
39
90
|
end
|
40
91
|
|
41
|
-
it "
|
42
|
-
connection.
|
92
|
+
it "should :merchant_id has correct in instance" do
|
93
|
+
new_connection = @connection.instance
|
94
|
+
new_connection.merchant_id.should == merchant_id
|
43
95
|
end
|
44
96
|
|
45
|
-
it "
|
46
|
-
|
97
|
+
it "should generate exception when :braspag_url is nil" do
|
98
|
+
mock_merchant = mock_for_connection
|
99
|
+
mock_merchant[ENV["RACK_ENV"]]["braspag_url"] = nil
|
100
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
101
|
+
other_connection = Braspag::Connection.clone
|
102
|
+
|
103
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidBraspagUrl)
|
47
104
|
end
|
48
105
|
|
49
|
-
it "
|
50
|
-
|
106
|
+
it "should generate exception when :braspag_url is empty" do
|
107
|
+
mock_merchant = mock_for_connection
|
108
|
+
mock_merchant[ENV["RACK_ENV"]]["braspag_url"] = ""
|
109
|
+
YAML.should_receive(:load_file).with("config/braspag.yml").and_return(mock_merchant)
|
110
|
+
other_connection = Braspag::Connection.clone
|
111
|
+
|
112
|
+
expect { other_connection.instance }.should raise_error(Braspag::Connection::InvalidBraspagUrl)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should :braspag_url has correct in instance" do
|
116
|
+
new_connection = @connection.instance
|
117
|
+
new_connection.braspag_url.should == braspag_url
|
51
118
|
end
|
52
|
-
|
53
119
|
|
120
|
+
it "should :crypto_url has correct in instance" do
|
121
|
+
new_connection = @connection.instance
|
122
|
+
new_connection.crypto_url.should == crypto_url
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should :crypto_key has correct in instance" do
|
126
|
+
new_connection = @connection.instance
|
127
|
+
new_connection.crypto_key.should == crypto_key
|
128
|
+
end
|
54
129
|
end
|
data/spec/credit_card_spec.rb
CHANGED
@@ -2,25 +2,12 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::CreditCard do
|
5
|
-
|
6
|
-
let!(:merchant_id) { "{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" }
|
7
|
-
let!(:connection) { Braspag::Connection.new(merchant_id, :test) }
|
8
|
-
|
9
|
-
describe ".new" do
|
10
|
-
|
11
|
-
it "should raise an error when no connection is given" do
|
12
|
-
expect {
|
13
|
-
Braspag::CreditCard.new(Object.new)
|
14
|
-
}.to raise_error(Braspag::InvalidConnection)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
5
|
+
let!(:braspag_url) { "https://homologacao.pagador.com.br" }
|
18
6
|
|
19
7
|
describe ".authorize" do
|
20
|
-
|
21
8
|
it "should raise an error when :order_id is not present" do
|
22
9
|
expect {
|
23
|
-
Braspag::CreditCard.
|
10
|
+
Braspag::CreditCard.authorize({
|
24
11
|
:customer_name => "W" * 21,
|
25
12
|
:amount => "100.00",
|
26
13
|
:payment_method => :redecard,
|
@@ -36,7 +23,7 @@ describe Braspag::CreditCard do
|
|
36
23
|
|
37
24
|
it "should raise an error when :customer_name is not present" do
|
38
25
|
expect {
|
39
|
-
Braspag::CreditCard.
|
26
|
+
Braspag::CreditCard.authorize({
|
40
27
|
:order_id => "1" * 5,
|
41
28
|
:amount => "100.00",
|
42
29
|
:payment_method => :redecard,
|
@@ -52,7 +39,7 @@ describe Braspag::CreditCard do
|
|
52
39
|
|
53
40
|
it "should raise an error when :amount is not present" do
|
54
41
|
expect {
|
55
|
-
Braspag::CreditCard.
|
42
|
+
Braspag::CreditCard.authorize({
|
56
43
|
:order_id => "1" * 5,
|
57
44
|
:customer_name => "",
|
58
45
|
:payment_method => :redecard,
|
@@ -68,7 +55,7 @@ describe Braspag::CreditCard do
|
|
68
55
|
|
69
56
|
it "should raise an error when :payment_method is not present" do
|
70
57
|
expect {
|
71
|
-
Braspag::CreditCard.
|
58
|
+
Braspag::CreditCard.authorize({
|
72
59
|
:order_id => "1" * 5,
|
73
60
|
:customer_name => "",
|
74
61
|
:amount => "100.00",
|
@@ -84,7 +71,7 @@ describe Braspag::CreditCard do
|
|
84
71
|
|
85
72
|
it "should raise an error when :holder is not present" do
|
86
73
|
expect {
|
87
|
-
Braspag::CreditCard.
|
74
|
+
Braspag::CreditCard.authorize({
|
88
75
|
:order_id => "1" * 5,
|
89
76
|
:customer_name => "",
|
90
77
|
:payment_method => :redecard,
|
@@ -100,7 +87,7 @@ describe Braspag::CreditCard do
|
|
100
87
|
|
101
88
|
it "should raise an error when :card_number is not present" do
|
102
89
|
expect {
|
103
|
-
Braspag::CreditCard.
|
90
|
+
Braspag::CreditCard.authorize({
|
104
91
|
:order_id => "1" * 5,
|
105
92
|
:customer_name => "",
|
106
93
|
:payment_method => :redecard,
|
@@ -116,7 +103,7 @@ describe Braspag::CreditCard do
|
|
116
103
|
|
117
104
|
it "should raise an error when :expiration is not present" do
|
118
105
|
expect {
|
119
|
-
Braspag::CreditCard.
|
106
|
+
Braspag::CreditCard.authorize({
|
120
107
|
:order_id => "1" * 5,
|
121
108
|
:customer_name => "",
|
122
109
|
:payment_method => :redecard,
|
@@ -132,7 +119,7 @@ describe Braspag::CreditCard do
|
|
132
119
|
|
133
120
|
it "should raise an error when :security_code is not present" do
|
134
121
|
expect {
|
135
|
-
Braspag::CreditCard.
|
122
|
+
Braspag::CreditCard.authorize({
|
136
123
|
:order_id => "1" * 5,
|
137
124
|
:customer_name => "AAAAAAAA",
|
138
125
|
:payment_method => :redecard,
|
@@ -148,7 +135,7 @@ describe Braspag::CreditCard do
|
|
148
135
|
|
149
136
|
it "should raise an error when :number_payments is not present" do
|
150
137
|
expect {
|
151
|
-
Braspag::CreditCard.
|
138
|
+
Braspag::CreditCard.authorize({
|
152
139
|
:order_id => "1" * 5,
|
153
140
|
:customer_name => "AAAAAAAA",
|
154
141
|
:payment_method => :redecard,
|
@@ -163,7 +150,7 @@ describe Braspag::CreditCard do
|
|
163
150
|
|
164
151
|
it "should raise an error when :type is not present" do
|
165
152
|
expect {
|
166
|
-
Braspag::CreditCard.
|
153
|
+
Braspag::CreditCard.authorize({
|
167
154
|
:order_id => "1" * 5,
|
168
155
|
:customer_name => "AAAAAAAA",
|
169
156
|
:payment_method => :redecard,
|
@@ -195,7 +182,7 @@ describe Braspag::CreditCard do
|
|
195
182
|
expect {
|
196
183
|
params = valid_params
|
197
184
|
params[:order_id] = "A" * 21
|
198
|
-
Braspag::CreditCard.
|
185
|
+
Braspag::CreditCard.authorize(params)
|
199
186
|
}.to raise_error(Braspag::InvalidOrderId)
|
200
187
|
end
|
201
188
|
|
@@ -203,7 +190,7 @@ describe Braspag::CreditCard do
|
|
203
190
|
expect {
|
204
191
|
params = valid_params
|
205
192
|
params[:customer_name] = "B" * 101
|
206
|
-
Braspag::CreditCard.
|
193
|
+
Braspag::CreditCard.authorize(params)
|
207
194
|
}.to raise_error(Braspag::InvalidCustomerName)
|
208
195
|
end
|
209
196
|
|
@@ -211,7 +198,7 @@ describe Braspag::CreditCard do
|
|
211
198
|
expect {
|
212
199
|
params = valid_params
|
213
200
|
params[:amount] = "1234567890,00"
|
214
|
-
Braspag::CreditCard.
|
201
|
+
Braspag::CreditCard.authorize(params)
|
215
202
|
}.to raise_error(Braspag::InvalidAmount)
|
216
203
|
end
|
217
204
|
|
@@ -219,7 +206,7 @@ describe Braspag::CreditCard do
|
|
219
206
|
expect {
|
220
207
|
params = valid_params
|
221
208
|
params[:holder] = "E" * 101
|
222
|
-
Braspag::CreditCard.
|
209
|
+
Braspag::CreditCard.authorize(params)
|
223
210
|
}.to raise_error(Braspag::InvalidHolder)
|
224
211
|
end
|
225
212
|
|
@@ -227,7 +214,7 @@ describe Braspag::CreditCard do
|
|
227
214
|
expect {
|
228
215
|
params = valid_params
|
229
216
|
params[:expiration] = "7" * 8
|
230
|
-
Braspag::CreditCard.
|
217
|
+
Braspag::CreditCard.authorize(params)
|
231
218
|
}.to raise_error(Braspag::InvalidExpirationDate)
|
232
219
|
end
|
233
220
|
|
@@ -235,7 +222,7 @@ describe Braspag::CreditCard do
|
|
235
222
|
expect {
|
236
223
|
params = valid_params
|
237
224
|
params[:security_code] = "9" * 5
|
238
|
-
Braspag::CreditCard.
|
225
|
+
Braspag::CreditCard.authorize(params)
|
239
226
|
}.to raise_error(Braspag::InvalidSecurityCode)
|
240
227
|
end
|
241
228
|
|
@@ -243,7 +230,7 @@ describe Braspag::CreditCard do
|
|
243
230
|
expect {
|
244
231
|
params = valid_params
|
245
232
|
params[:number_payments] = "123"
|
246
|
-
Braspag::CreditCard.
|
233
|
+
Braspag::CreditCard.authorize(params)
|
247
234
|
}.to raise_error(Braspag::InvalidNumberPayments)
|
248
235
|
end
|
249
236
|
|
@@ -251,7 +238,7 @@ describe Braspag::CreditCard do
|
|
251
238
|
expect {
|
252
239
|
params = valid_params
|
253
240
|
params[:type] = "123"
|
254
|
-
Braspag::CreditCard.
|
241
|
+
Braspag::CreditCard.authorize(params)
|
255
242
|
}.to raise_error(Braspag::InvalidType)
|
256
243
|
end
|
257
244
|
|
@@ -287,9 +274,9 @@ describe Braspag::CreditCard do
|
|
287
274
|
</PagadorReturn>
|
288
275
|
EOXML
|
289
276
|
|
290
|
-
FakeWeb.register_uri(:post, "#{
|
277
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
291
278
|
|
292
|
-
result = Braspag::CreditCard.
|
279
|
+
result = Braspag::CreditCard.authorize(params)
|
293
280
|
result[:status].should == "1"
|
294
281
|
|
295
282
|
FakeWeb.clean_registry
|
@@ -315,9 +302,9 @@ describe Braspag::CreditCard do
|
|
315
302
|
</PagadorReturn>
|
316
303
|
EOXML
|
317
304
|
|
318
|
-
FakeWeb.register_uri(:post, "#{
|
305
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
319
306
|
|
320
|
-
result = Braspag::CreditCard.
|
307
|
+
result = Braspag::CreditCard.authorize(invalid_params)
|
321
308
|
result[:status].should == "2"
|
322
309
|
|
323
310
|
FakeWeb.clean_registry
|
@@ -344,9 +331,9 @@ describe Braspag::CreditCard do
|
|
344
331
|
</PagadorReturn>
|
345
332
|
EOXML
|
346
333
|
|
347
|
-
FakeWeb.register_uri(:post, "#{
|
334
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
348
335
|
|
349
|
-
result = Braspag::CreditCard.
|
336
|
+
result = Braspag::CreditCard.authorize(invalid_params)
|
350
337
|
result[:status].should == "null"
|
351
338
|
|
352
339
|
FakeWeb.clean_registry
|
@@ -360,7 +347,7 @@ describe Braspag::CreditCard do
|
|
360
347
|
|
361
348
|
it "should raise an error when :order_id is more than 20 characters" do
|
362
349
|
expect {
|
363
|
-
Braspag::CreditCard.
|
350
|
+
Braspag::CreditCard.capture(("A" * 21))
|
364
351
|
}.to raise_error(Braspag::InvalidOrderId)
|
365
352
|
end
|
366
353
|
|
@@ -377,9 +364,9 @@ describe Braspag::CreditCard do
|
|
377
364
|
</PagadorReturn>
|
378
365
|
EOXML
|
379
366
|
|
380
|
-
FakeWeb.register_uri(:post, "#{
|
367
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
|
381
368
|
|
382
|
-
result = Braspag::CreditCard.
|
369
|
+
result = Braspag::CreditCard.capture('123456')
|
383
370
|
|
384
371
|
result[:amount].should_not be_nil
|
385
372
|
result[:message].should_not be_nil
|
@@ -404,9 +391,9 @@ describe Braspag::CreditCard do
|
|
404
391
|
</PagadorReturn>
|
405
392
|
EOXML
|
406
393
|
|
407
|
-
FakeWeb.register_uri(:post, "#{
|
394
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
|
408
395
|
|
409
|
-
result = Braspag::CreditCard.
|
396
|
+
result = Braspag::CreditCard.capture('123456')
|
410
397
|
result[:status].should == "0"
|
411
398
|
|
412
399
|
FakeWeb.clean_registry
|
@@ -429,9 +416,9 @@ describe Braspag::CreditCard do
|
|
429
416
|
</PagadorReturn>
|
430
417
|
EOXML
|
431
418
|
|
432
|
-
FakeWeb.register_uri(:post, "#{
|
419
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
|
433
420
|
|
434
|
-
result = Braspag::CreditCard.
|
421
|
+
result = Braspag::CreditCard.capture("1")
|
435
422
|
result[:status].should == "2"
|
436
423
|
|
437
424
|
FakeWeb.clean_registry
|
@@ -454,9 +441,9 @@ describe Braspag::CreditCard do
|
|
454
441
|
</PagadorReturn>
|
455
442
|
EOXML
|
456
443
|
|
457
|
-
FakeWeb.register_uri(:post, "#{
|
444
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
|
458
445
|
|
459
|
-
result = Braspag::CreditCard.
|
446
|
+
result = Braspag::CreditCard.capture("1234")
|
460
447
|
result[:status].should == "null"
|
461
448
|
|
462
449
|
FakeWeb.clean_registry
|
@@ -471,7 +458,89 @@ describe Braspag::CreditCard do
|
|
471
458
|
end
|
472
459
|
end
|
473
460
|
|
461
|
+
|
462
|
+
describe "#status" do
|
463
|
+
it "should raise an error when no order_id is given" do
|
464
|
+
expect {
|
465
|
+
Braspag::CreditCard.info(nil)
|
466
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
467
|
+
end
|
468
|
+
|
469
|
+
it "should raise an error when order_id is empty" do
|
470
|
+
expect {
|
471
|
+
Braspag::CreditCard.info("")
|
472
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
473
|
+
end
|
474
|
+
|
475
|
+
it "should raise an error when order_id is more than 50 characters" do
|
476
|
+
expect {
|
477
|
+
Braspag::CreditCard.info("1" * 51)
|
478
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
479
|
+
end
|
480
|
+
|
481
|
+
it "should raise an error for incorrect data" do
|
482
|
+
xml = <<-EOXML
|
483
|
+
<?xml version="1.0" encoding="utf-8"?>
|
484
|
+
<DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
485
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
486
|
+
xsi:nil="true"
|
487
|
+
xmlns="http://www.pagador.com.br/" />
|
488
|
+
EOXML
|
489
|
+
|
490
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/pagador/webservice/pedido.asmx/GetDadosCartao",
|
491
|
+
:body => xml)
|
492
|
+
|
493
|
+
expect {
|
494
|
+
Braspag::CreditCard.info("sadpoakjspodqdouq09wduwq")
|
495
|
+
}.to raise_error(Braspag::UnknownError)
|
496
|
+
|
497
|
+
|
498
|
+
expect {
|
499
|
+
Braspag::CreditCard.info("asdnasdniousa")
|
500
|
+
}.to raise_error(Braspag::UnknownError)
|
501
|
+
|
502
|
+
FakeWeb.clean_registry
|
503
|
+
end
|
504
|
+
|
505
|
+
context "with correct data" do
|
506
|
+
|
507
|
+
let(:order_info) {
|
508
|
+
xml = <<-EOXML
|
509
|
+
<DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.pagador.com.br/">
|
510
|
+
<NumeroComprovante>225296</NumeroComprovante>
|
511
|
+
<Autenticada>false</Autenticada>
|
512
|
+
<NumeroAutorizacao>557593</NumeroAutorizacao>
|
513
|
+
<NumeroCartao>345678*****0007</NumeroCartao>
|
514
|
+
<NumeroTransacao>101001225645</NumeroTransacao>
|
515
|
+
</DadosCartao>
|
516
|
+
EOXML
|
517
|
+
|
518
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/pagador/webservice/pedido.asmx/GetDadosCartao",
|
519
|
+
:body => xml)
|
520
|
+
order_info = Braspag::CreditCard.info("12345")
|
521
|
+
FakeWeb.clean_registry
|
522
|
+
order_info
|
523
|
+
}
|
524
|
+
|
525
|
+
it "should return a Hash" do
|
526
|
+
order_info.should be_kind_of Hash
|
527
|
+
end
|
528
|
+
|
529
|
+
{
|
530
|
+
:checking_number => "225296",
|
531
|
+
:certified => "false",
|
532
|
+
:autorization_number => "557593",
|
533
|
+
:card_number => "345678*****0007",
|
534
|
+
:transaction_number => "101001225645"
|
535
|
+
}.each do |key, value|
|
536
|
+
|
537
|
+
it "should return a Hash with :#{key.to_s} key" do
|
538
|
+
order_info[key].should == value
|
539
|
+
end
|
540
|
+
end
|
541
|
+
end
|
474
542
|
end
|
475
543
|
|
476
|
-
end
|
477
544
|
|
545
|
+
end
|
546
|
+
end
|
@@ -2,10 +2,7 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::Crypto::JarWebservice do
|
5
|
-
let!(:
|
6
|
-
let!(:uri) {"http://localhost:9292"}
|
7
|
-
let!(:crypt) {Braspag::Crypto::JarWebservice.new(crypto_key, uri)}
|
8
|
-
let!(:crypt_invalid) {Braspag::Crypto::JarWebservice.new("00000", uri)}
|
5
|
+
let!(:crypt) {Braspag::Crypto::JarWebservice}
|
9
6
|
let! (:key) {"5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7"}
|
10
7
|
|
11
8
|
after (:each) do
|
@@ -90,7 +87,7 @@ INVALIDO
|
|
90
87
|
)
|
91
88
|
|
92
89
|
expect {
|
93
|
-
|
90
|
+
crypt.encrypt(:venda => "value")
|
94
91
|
}.to raise_error(Braspag::InvalidCryptKey)
|
95
92
|
end
|
96
93
|
|
@@ -182,7 +179,7 @@ INVALIDO
|
|
182
179
|
)
|
183
180
|
|
184
181
|
expect {
|
185
|
-
|
182
|
+
crypt.decrypt(key, [:nome, :sobrenome])
|
186
183
|
}.to raise_error(Braspag::InvalidCryptKey)
|
187
184
|
end
|
188
185
|
|
@@ -2,11 +2,6 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::Crypto::Webservice do
|
5
|
-
let!(:merchant_id) {"{84BE7E7F-698A-6C74-F820-AE359C2A07C2}"}
|
6
|
-
let!(:connection) {Braspag::Connection.new(merchant_id, :test)}
|
7
|
-
let!(:connection_invalid) {Braspag::Connection.new("{83BE7E7F-698A-6C74-F820-AE359C2A07A1}", :test)}
|
8
|
-
let!(:crypt) {Braspag::Crypto::Webservice.new(connection)}
|
9
|
-
let!(:crypt_invalid) {Braspag::Crypto::Webservice.new(connection_invalid)}
|
10
5
|
|
11
6
|
context "encrypt" do
|
12
7
|
let!(:key) {"XXXXX"}
|
@@ -14,7 +9,7 @@ describe Braspag::Crypto::Webservice do
|
|
14
9
|
context "consistencies" do
|
15
10
|
it "should return error with invalid data" do
|
16
11
|
expect {
|
17
|
-
|
12
|
+
Braspag::Crypto::Webservice.encrypt("INVALID DATA")
|
18
13
|
}.to raise_error(Braspag::IncompleteParams)
|
19
14
|
end
|
20
15
|
|
@@ -26,7 +21,7 @@ EOXML
|
|
26
21
|
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
27
22
|
:body => body_invalid )
|
28
23
|
expect {
|
29
|
-
|
24
|
+
Braspag::Crypto::Webservice.encrypt(:key => "INVALID DATA")
|
30
25
|
}.to raise_error(Braspag::UnknownError)
|
31
26
|
FakeWeb.clean_registry
|
32
27
|
end
|
@@ -43,7 +38,7 @@ EOXML
|
|
43
38
|
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
44
39
|
:body => body_invalid )
|
45
40
|
expect {
|
46
|
-
|
41
|
+
Braspag::Crypto::Webservice.encrypt(:key => "value")
|
47
42
|
}.to raise_error(Braspag::InvalidMerchantId)
|
48
43
|
FakeWeb.clean_registry
|
49
44
|
end
|
@@ -60,7 +55,7 @@ EOXML
|
|
60
55
|
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
61
56
|
:body => body_invalid )
|
62
57
|
expect {
|
63
|
-
|
58
|
+
Braspag::Crypto::Webservice.encrypt(:key => "value")
|
64
59
|
}.to raise_error(Braspag::InvalidIP)
|
65
60
|
FakeWeb.clean_registry
|
66
61
|
end
|
@@ -79,7 +74,7 @@ EOXML
|
|
79
74
|
</soap:Body></soap:Envelope>
|
80
75
|
EOXML
|
81
76
|
)
|
82
|
-
|
77
|
+
Braspag::Crypto::Webservice.encrypt(:key => "value").should == key
|
83
78
|
FakeWeb.clean_registry
|
84
79
|
end
|
85
80
|
end
|
@@ -89,7 +84,7 @@ EOXML
|
|
89
84
|
context "consistencies" do
|
90
85
|
it "should return error with invalid data" do
|
91
86
|
expect {
|
92
|
-
|
87
|
+
Braspag::Crypto::Webservice.decrypt(1213123)
|
93
88
|
}.to raise_error(Braspag::IncompleteParams)
|
94
89
|
end
|
95
90
|
|
@@ -101,28 +96,11 @@ EOXML
|
|
101
96
|
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
102
97
|
:body => body_invalid )
|
103
98
|
expect {
|
104
|
-
|
99
|
+
Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")
|
105
100
|
}.to raise_error(Braspag::UnknownError)
|
106
101
|
FakeWeb.clean_registry
|
107
102
|
end
|
108
103
|
|
109
|
-
it "should return error with invalid merchant_id" do
|
110
|
-
body_invalid = <<-EOXML
|
111
|
-
<?xml version="1.0" encoding="utf-8"?>
|
112
|
-
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
113
|
-
<soap:Body><DecryptRequestResponse xmlns="https://www.pagador.com.br/webservice/BraspagGeneralService">
|
114
|
-
<DecryptRequestResult><string>Erro BP 011</string></DecryptRequestResult>
|
115
|
-
</DecryptRequestResponse></soap:Body></soap:Envelope>
|
116
|
-
EOXML
|
117
|
-
FakeWeb.register_uri(:post,
|
118
|
-
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
119
|
-
:body => body_invalid )
|
120
|
-
expect {
|
121
|
-
crypt_invalid.decrypt("{sdfsdf34543534}")
|
122
|
-
}.to raise_error(Braspag::InvalidMerchantId)
|
123
|
-
FakeWeb.clean_registry
|
124
|
-
end
|
125
|
-
|
126
104
|
it "should return error with invalid ip" do
|
127
105
|
body_invalid = <<-EOXML
|
128
106
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -135,7 +113,7 @@ EOXML
|
|
135
113
|
"https://homologacao.pagador.com.br/BraspagGeneralService/BraspagGeneralService.asmx",
|
136
114
|
:body => body_invalid )
|
137
115
|
expect {
|
138
|
-
|
116
|
+
Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")
|
139
117
|
}.to raise_error(Braspag::InvalidIP)
|
140
118
|
FakeWeb.clean_registry
|
141
119
|
end
|
@@ -157,7 +135,7 @@ EOXML
|
|
157
135
|
</soap:Body></soap:Envelope>
|
158
136
|
EOXML
|
159
137
|
)
|
160
|
-
|
138
|
+
Braspag::Crypto::Webservice.decrypt("{sdfsdf34543534}")[:parcelas].should eql("1")
|
161
139
|
FakeWeb.clean_registry
|
162
140
|
end
|
163
141
|
|