rbraspag 0.0.19 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/rbraspag/bill.rb +65 -63
- data/lib/rbraspag/connection.rb +2 -11
- data/lib/rbraspag/credit_card.rb +59 -36
- data/lib/rbraspag/crypto/jar_webservice.rb +21 -21
- data/lib/rbraspag/crypto/webservice.rb +1 -1
- data/lib/rbraspag/eft.rb +40 -61
- data/lib/rbraspag/errors.rb +10 -0
- data/lib/rbraspag/order.rb +11 -5
- data/lib/rbraspag/payment_method.rb +32 -0
- data/lib/rbraspag/utils.rb +13 -16
- data/lib/rbraspag/version.rb +1 -1
- data/rbraspag.gemspec +1 -1
- data/spec/bill_spec.rb +261 -411
- data/spec/connection_spec.rb +0 -5
- data/spec/credit_card_spec.rb +240 -446
- data/spec/crypto/jar_webservice_spec.rb +30 -30
- data/spec/crypto/webservice_spec.rb +20 -20
- data/spec/eft_spec.rb +183 -203
- data/spec/order_spec.rb +97 -84
- data/spec/spec_helper.rb +5 -1
- data/spec/utils_spec.rb +39 -18
- metadata +23 -24
- data/Gemfile.lock +0 -63
data/spec/connection_spec.rb
CHANGED
@@ -11,9 +11,6 @@ describe Braspag::Connection do
|
|
11
11
|
let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
|
12
12
|
let(:braspag_production_url) { "https://transaction.pagador.com.br" }
|
13
13
|
|
14
|
-
let(:braspag_homologation_query_url) { "https://homologacao.pagador.com.br/pagador/webservice/pedido.asmx" }
|
15
|
-
let(:braspag_production_query_url) { "https://query.pagador.com.br/webservices/pagador/pedido.asmx" }
|
16
|
-
|
17
14
|
let(:braspag_config) do
|
18
15
|
config = {}
|
19
16
|
config[ENV["RACK_ENV"]] = {
|
@@ -135,7 +132,6 @@ describe Braspag::Connection do
|
|
135
132
|
|
136
133
|
connection = Braspag::Connection.clone.instance
|
137
134
|
connection.braspag_url.should == braspag_homologation_url
|
138
|
-
connection.braspag_query_url.should == braspag_homologation_query_url
|
139
135
|
end
|
140
136
|
end
|
141
137
|
|
@@ -148,7 +144,6 @@ describe Braspag::Connection do
|
|
148
144
|
|
149
145
|
connection = Braspag::Connection.clone.instance
|
150
146
|
connection.braspag_url.should == braspag_production_url
|
151
|
-
connection.braspag_query_url.should == braspag_production_query_url
|
152
147
|
end
|
153
148
|
end
|
154
149
|
end
|
data/spec/credit_card_spec.rb
CHANGED
@@ -1,386 +1,108 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
2
|
|
4
3
|
describe Braspag::CreditCard do
|
5
|
-
let
|
6
|
-
let
|
4
|
+
let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
|
5
|
+
let(:braspag_production_url) { "https://transaction.pagador.com.br" }
|
6
|
+
let(:merchant_id) { "um id qualquer" }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:customer_name => "W" * 21,
|
13
|
-
:amount => "100.00",
|
14
|
-
:payment_method => :redecard,
|
15
|
-
:holder => "Joao Maria Souza",
|
16
|
-
:card_number => "9" * 10,
|
17
|
-
:expiration => "10/12",
|
18
|
-
:security_code => "123",
|
19
|
-
:number_payments => 1,
|
20
|
-
:type => 0
|
21
|
-
})
|
22
|
-
}.to raise_error(Braspag::IncompleteParams)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should raise an error when :customer_name is not present" do
|
26
|
-
expect {
|
27
|
-
Braspag::CreditCard.authorize({
|
28
|
-
:order_id => "1" * 5,
|
29
|
-
:amount => "100.00",
|
30
|
-
:payment_method => :redecard,
|
31
|
-
:holder => "Joao Maria Souza",
|
32
|
-
:card_number => "9" * 10,
|
33
|
-
:expiration => "10/12",
|
34
|
-
:security_code => "123",
|
35
|
-
:number_payments => 1,
|
36
|
-
:type => 0
|
37
|
-
})
|
38
|
-
}.to raise_error(Braspag::IncompleteParams)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should raise an error when :amount is not present" do
|
42
|
-
expect {
|
43
|
-
Braspag::CreditCard.authorize({
|
44
|
-
:order_id => "1" * 5,
|
45
|
-
:customer_name => "",
|
46
|
-
:payment_method => :redecard,
|
47
|
-
:holder => "Joao Maria Souza",
|
48
|
-
:card_number => "9" * 10,
|
49
|
-
:expiration => "10/12",
|
50
|
-
:security_code => "123",
|
51
|
-
:number_payments => 1,
|
52
|
-
:type => 0
|
53
|
-
})
|
54
|
-
}.to raise_error(Braspag::IncompleteParams)
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should raise an error when :payment_method is not present" do
|
58
|
-
expect {
|
59
|
-
Braspag::CreditCard.authorize({
|
60
|
-
:order_id => "1" * 5,
|
61
|
-
:customer_name => "",
|
62
|
-
:amount => "100.00",
|
63
|
-
:holder => "Joao Maria Souza",
|
64
|
-
:card_number => "9" * 10,
|
65
|
-
:expiration => "10/12",
|
66
|
-
:security_code => "123",
|
67
|
-
:number_payments => 1,
|
68
|
-
:type => 0
|
69
|
-
})
|
70
|
-
}.to raise_error(Braspag::IncompleteParams)
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should raise an error when :holder is not present" do
|
74
|
-
expect {
|
75
|
-
Braspag::CreditCard.authorize({
|
76
|
-
:order_id => "1" * 5,
|
77
|
-
:customer_name => "",
|
78
|
-
:payment_method => :redecard,
|
79
|
-
:amount => "100.00",
|
80
|
-
:card_number => "9" * 10,
|
81
|
-
:expiration => "10/12",
|
82
|
-
:security_code => "123",
|
83
|
-
:number_payments => 1,
|
84
|
-
:type => 0
|
85
|
-
})
|
86
|
-
}.to raise_error(Braspag::IncompleteParams)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should raise an error when :card_number is not present" do
|
90
|
-
expect {
|
91
|
-
Braspag::CreditCard.authorize({
|
92
|
-
:order_id => "1" * 5,
|
93
|
-
:customer_name => "",
|
94
|
-
:payment_method => :redecard,
|
95
|
-
:amount => "100.00",
|
96
|
-
:holder => "Joao Maria Souza",
|
97
|
-
:expiration => "10/12",
|
98
|
-
:security_code => "123",
|
99
|
-
:number_payments => 1,
|
100
|
-
:type => 0
|
101
|
-
})
|
102
|
-
}.to raise_error(Braspag::IncompleteParams)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should raise an error when :expiration is not present" do
|
106
|
-
expect {
|
107
|
-
Braspag::CreditCard.authorize({
|
108
|
-
:order_id => "1" * 5,
|
109
|
-
:customer_name => "",
|
110
|
-
:payment_method => :redecard,
|
111
|
-
:amount => "100.00",
|
112
|
-
:holder => "Joao Maria Souza",
|
113
|
-
:card_number => "9" * 10,
|
114
|
-
:security_code => "123",
|
115
|
-
:number_payments => 1,
|
116
|
-
:type => 0
|
117
|
-
})
|
118
|
-
}.to raise_error(Braspag::IncompleteParams)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should raise an error when :security_code is not present" do
|
122
|
-
expect {
|
123
|
-
Braspag::CreditCard.authorize({
|
124
|
-
:order_id => "1" * 5,
|
125
|
-
:customer_name => "AAAAAAAA",
|
126
|
-
:payment_method => :redecard,
|
127
|
-
:amount => "100.00",
|
128
|
-
:holder => "Joao Maria Souza",
|
129
|
-
:expiration => "10/12",
|
130
|
-
:card_number => "9" * 10,
|
131
|
-
:number_payments => 1,
|
132
|
-
:type => 0
|
133
|
-
})
|
134
|
-
}.to raise_error(Braspag::IncompleteParams)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should raise an error when :number_payments is not present" do
|
138
|
-
expect {
|
139
|
-
Braspag::CreditCard.authorize({
|
140
|
-
:order_id => "1" * 5,
|
141
|
-
:customer_name => "AAAAAAAA",
|
142
|
-
:payment_method => :redecard,
|
143
|
-
:amount => "100.00",
|
144
|
-
:holder => "Joao Maria Souza",
|
145
|
-
:expiration => "10/12",
|
146
|
-
:card_number => "9" * 10,
|
147
|
-
:type => 0
|
148
|
-
})
|
149
|
-
}.to raise_error(Braspag::IncompleteParams)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should raise an error when :type is not present" do
|
153
|
-
expect {
|
154
|
-
Braspag::CreditCard.authorize({
|
155
|
-
:order_id => "1" * 5,
|
156
|
-
:customer_name => "AAAAAAAA",
|
157
|
-
:payment_method => :redecard,
|
158
|
-
:amount => "100.00",
|
159
|
-
:holder => "Joao Maria Souza",
|
160
|
-
:expiration => "10/12",
|
161
|
-
:card_number => "9" * 10,
|
162
|
-
:number_payments => 1
|
163
|
-
})
|
164
|
-
}.to raise_error(Braspag::IncompleteParams)
|
165
|
-
end
|
8
|
+
before do
|
9
|
+
@connection = mock(:merchant_id => merchant_id)
|
10
|
+
Braspag::Connection.stub(:instance => @connection)
|
11
|
+
end
|
166
12
|
|
167
|
-
|
13
|
+
describe ".authorize" do
|
14
|
+
let(:params) do
|
168
15
|
{
|
169
|
-
:order_id => "
|
170
|
-
:customer_name => "
|
171
|
-
:payment_method => :amex_2p,
|
16
|
+
:order_id => "um order id",
|
17
|
+
:customer_name => "W" * 21,
|
172
18
|
:amount => "100.00",
|
19
|
+
:payment_method => :redecard,
|
173
20
|
:holder => "Joao Maria Souza",
|
174
|
-
:expiration => "10/12",
|
175
21
|
:card_number => "9" * 10,
|
22
|
+
:expiration => "10/12",
|
176
23
|
:security_code => "123",
|
177
24
|
:number_payments => 1,
|
178
25
|
:type => 0
|
179
26
|
}
|
180
|
-
}
|
181
|
-
|
182
|
-
it "should raise an error when :order_id is more than 20 characters" do
|
183
|
-
expect {
|
184
|
-
params = valid_params
|
185
|
-
params[:order_id] = "A" * 21
|
186
|
-
Braspag::CreditCard.authorize(params)
|
187
|
-
}.to raise_error(Braspag::InvalidOrderId)
|
188
27
|
end
|
189
28
|
|
190
|
-
|
191
|
-
|
192
|
-
params = valid_params
|
193
|
-
params[:customer_name] = "B" * 101
|
194
|
-
Braspag::CreditCard.authorize(params)
|
195
|
-
}.to raise_error(Braspag::InvalidCustomerName)
|
29
|
+
let(:params_with_merchant_id) do
|
30
|
+
params.merge!(:merchant_id => merchant_id)
|
196
31
|
end
|
197
32
|
|
198
|
-
|
199
|
-
expect {
|
200
|
-
params = valid_params
|
201
|
-
params[:amount] = "1234567890,00"
|
202
|
-
Braspag::CreditCard.authorize(params)
|
203
|
-
}.to raise_error(Braspag::InvalidAmount)
|
204
|
-
end
|
33
|
+
let(:authorize_url) { "http://braspag/bla" }
|
205
34
|
|
206
|
-
|
207
|
-
|
208
|
-
params = valid_params
|
209
|
-
params[:holder] = "E" * 101
|
210
|
-
Braspag::CreditCard.authorize(params)
|
211
|
-
}.to raise_error(Braspag::InvalidHolder)
|
212
|
-
end
|
35
|
+
before do
|
36
|
+
@connection.should_receive(:merchant_id)
|
213
37
|
|
214
|
-
|
215
|
-
|
216
|
-
params = valid_params
|
217
|
-
params[:expiration] = "7" * 8
|
218
|
-
Braspag::CreditCard.authorize(params)
|
219
|
-
}.to raise_error(Braspag::InvalidExpirationDate)
|
220
|
-
end
|
38
|
+
Braspag::CreditCard.should_receive(:authorize_url)
|
39
|
+
.and_return(authorize_url)
|
221
40
|
|
222
|
-
|
223
|
-
|
224
|
-
params = valid_params
|
225
|
-
params[:security_code] = "9" * 5
|
226
|
-
Braspag::CreditCard.authorize(params)
|
227
|
-
}.to raise_error(Braspag::InvalidSecurityCode)
|
41
|
+
Braspag::CreditCard.should_receive(:check_params)
|
42
|
+
.and_return(true)
|
228
43
|
end
|
229
44
|
|
230
|
-
|
231
|
-
expect {
|
232
|
-
params = valid_params
|
233
|
-
params[:number_payments] = "123"
|
234
|
-
Braspag::CreditCard.authorize(params)
|
235
|
-
}.to raise_error(Braspag::InvalidNumberPayments)
|
236
|
-
end
|
45
|
+
context "with invalid params"
|
237
46
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
:holder => "teste",
|
253
|
-
:expiration => "05/13",
|
254
|
-
:card_number => "345678000000007",
|
255
|
-
:security_code => "1234",
|
256
|
-
:number_payments => "1",
|
257
|
-
:type => "0"
|
258
|
-
}
|
259
|
-
}
|
260
|
-
|
261
|
-
context "with a successful transaction" do
|
262
|
-
|
263
|
-
it "should return an array with :status => 1" do
|
264
|
-
xml = <<-EOXML
|
265
|
-
<?xml version="1.0" encoding="utf-8"?>
|
266
|
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
267
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
268
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
269
|
-
<amount>2</amount>
|
270
|
-
<authorisationNumber>733610</authorisationNumber>
|
271
|
-
<message>Transaction Successful</message>
|
272
|
-
<returnCode>0</returnCode>
|
273
|
-
<status>1</status>
|
274
|
-
<transactionId>398662</transactionId>
|
275
|
-
</PagadorReturn>
|
47
|
+
context "with valid params" do
|
48
|
+
let(:valid_xml) do
|
49
|
+
<<-EOXML
|
50
|
+
<?xml version="1.0" encoding="utf-8"?>
|
51
|
+
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
52
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
53
|
+
xmlns="https://www.pagador.com.br/webservice/pagador">
|
54
|
+
<amount>5</amount>
|
55
|
+
<message>Transaction Successful</message>
|
56
|
+
<authorisationNumber>733610</authorisationNumber>
|
57
|
+
<returnCode>7</returnCode>
|
58
|
+
<status>2</status>
|
59
|
+
<transactionId>0</transactionId>
|
60
|
+
</PagadorReturn>
|
276
61
|
EOXML
|
277
|
-
|
278
|
-
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
279
|
-
|
280
|
-
result = Braspag::CreditCard.authorize(params)
|
281
|
-
result[:status].should == "1"
|
282
|
-
|
283
|
-
FakeWeb.clean_registry
|
284
62
|
end
|
285
63
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
it "should return an array with :status => 2" do
|
291
|
-
invalid_params = params
|
292
|
-
invalid_params[:security_code] = 1
|
293
|
-
|
294
|
-
xml = <<-EOXML
|
295
|
-
<?xml version="1.0" encoding="utf-8"?>
|
296
|
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
297
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://www.pagador.com.br/webservice/pagador">
|
298
|
-
<amount>5</amount>
|
299
|
-
<message>Payment Server detected an error</message>
|
300
|
-
<returnCode>7</returnCode>
|
301
|
-
<status>2</status>
|
302
|
-
<transactionId>0</transactionId>
|
303
|
-
</PagadorReturn>
|
304
|
-
EOXML
|
305
|
-
|
306
|
-
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
307
|
-
|
308
|
-
result = Braspag::CreditCard.authorize(invalid_params)
|
309
|
-
result[:status].should == "2"
|
310
|
-
|
311
|
-
FakeWeb.clean_registry
|
64
|
+
before do
|
65
|
+
FakeWeb.register_uri(:post, authorize_url, :body => valid_xml)
|
66
|
+
@response = Braspag::CreditCard.authorize(params)
|
312
67
|
end
|
313
68
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
325
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
326
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
327
|
-
<amount>5</amount>
|
328
|
-
<message>Payment Server detected an error</message>
|
329
|
-
<returnCode>7</returnCode>
|
330
|
-
<status>null</status>
|
331
|
-
<transactionId>0</transactionId>
|
332
|
-
</PagadorReturn>
|
333
|
-
EOXML
|
334
|
-
|
335
|
-
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Authorize", :body => xml)
|
336
|
-
|
337
|
-
result = Braspag::CreditCard.authorize(invalid_params)
|
338
|
-
result[:status].should == "null"
|
339
|
-
|
340
|
-
FakeWeb.clean_registry
|
69
|
+
it "should return a Hash" do
|
70
|
+
@response.should be_kind_of Hash
|
71
|
+
@response.should == {
|
72
|
+
:amount => "5",
|
73
|
+
:message => "Transaction Successful",
|
74
|
+
:number => "733610",
|
75
|
+
:return_code => "7",
|
76
|
+
:status => "2",
|
77
|
+
:transaction_id => "0"
|
78
|
+
}
|
341
79
|
end
|
342
|
-
|
343
80
|
end
|
344
|
-
|
345
81
|
end
|
346
82
|
|
347
83
|
describe ".capture" do
|
84
|
+
let(:capture_url) { "http://foo.bar/bar/baz" }
|
85
|
+
let(:order_id) { "um id qualquer" }
|
348
86
|
|
349
|
-
|
350
|
-
|
351
|
-
Braspag::CreditCard.capture(("A" * 21))
|
352
|
-
}.to raise_error(Braspag::InvalidOrderId)
|
87
|
+
before do
|
88
|
+
@connection.should_receive(:merchant_id)
|
353
89
|
end
|
354
90
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
361
|
-
<amount>0.01</amount>
|
362
|
-
<message>Capture Successful</message>
|
363
|
-
<returnCode>07</returnCode>
|
364
|
-
<status>0</status>
|
365
|
-
</PagadorReturn>
|
366
|
-
EOXML
|
367
|
-
|
368
|
-
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Pagador.asmx/Capture", :body => xml)
|
91
|
+
context "invalid order id" do
|
92
|
+
it "should raise an error" do
|
93
|
+
Braspag::CreditCard.should_receive(:valid_order_id?)
|
94
|
+
.with(order_id)
|
95
|
+
.and_return(false)
|
369
96
|
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
result[:return_code].should_not be_nil
|
375
|
-
result[:status].should_not be_nil
|
376
|
-
|
377
|
-
FakeWeb.clean_registry
|
97
|
+
expect {
|
98
|
+
Braspag::CreditCard.capture(order_id)
|
99
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
100
|
+
end
|
378
101
|
end
|
379
102
|
|
380
|
-
context "
|
381
|
-
|
382
|
-
|
383
|
-
xml = <<-EOXML
|
103
|
+
context "valid order id" do
|
104
|
+
let(:valid_xml) do
|
105
|
+
<<-EOXML
|
384
106
|
<?xml version="1.0" encoding="utf-8"?>
|
385
107
|
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
386
108
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
@@ -391,157 +113,229 @@ describe Braspag::CreditCard do
|
|
391
113
|
<status>0</status>
|
392
114
|
</PagadorReturn>
|
393
115
|
EOXML
|
116
|
+
end
|
394
117
|
|
395
|
-
|
118
|
+
before do
|
119
|
+
Braspag::CreditCard.should_receive(:capture_url)
|
120
|
+
.and_return(capture_url)
|
396
121
|
|
397
|
-
|
398
|
-
|
122
|
+
FakeWeb.register_uri(:post, capture_url, :body => valid_xml)
|
123
|
+
@response = Braspag::CreditCard.capture("order id qualquer")
|
124
|
+
end
|
399
125
|
|
400
|
-
|
126
|
+
it "should return a Hash" do
|
127
|
+
@response.should be_kind_of Hash
|
128
|
+
@response.should == {
|
129
|
+
:amount => "2",
|
130
|
+
:number => nil,
|
131
|
+
:message => "Approved",
|
132
|
+
:return_code => "0",
|
133
|
+
:status => "0",
|
134
|
+
:transaction_id => nil
|
135
|
+
}
|
401
136
|
end
|
137
|
+
end
|
138
|
+
end
|
402
139
|
|
140
|
+
describe ".info" do
|
141
|
+
let(:info_url) { "http://braspag/bla" }
|
142
|
+
|
143
|
+
let(:invalid_xml) do
|
144
|
+
<<-EOXML
|
145
|
+
<DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
146
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
147
|
+
xmlns="http://www.pagador.com.br/">
|
148
|
+
<NumeroComprovante></NumeroComprovante>
|
149
|
+
<Autenticada>false</Autenticada>
|
150
|
+
<NumeroAutorizacao>557593</NumeroAutorizacao>
|
151
|
+
<NumeroCartao>345678*****0007</NumeroCartao>
|
152
|
+
<NumeroTransacao>101001225645</NumeroTransacao>
|
153
|
+
</DadosCartao>
|
154
|
+
EOXML
|
403
155
|
end
|
404
156
|
|
405
|
-
|
157
|
+
let(:valid_xml) do
|
158
|
+
<<-EOXML
|
159
|
+
<DadosCartao xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
160
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
161
|
+
xmlns="http://www.pagador.com.br/">
|
162
|
+
<NumeroComprovante>11111</NumeroComprovante>
|
163
|
+
<Autenticada>false</Autenticada>
|
164
|
+
<NumeroAutorizacao>557593</NumeroAutorizacao>
|
165
|
+
<NumeroCartao>345678*****0007</NumeroCartao>
|
166
|
+
<NumeroTransacao>101001225645</NumeroTransacao>
|
167
|
+
</DadosCartao>
|
168
|
+
EOXML
|
169
|
+
end
|
406
170
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
412
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
413
|
-
<amount>0.01</amount>
|
414
|
-
<message>Payment Server detected an error</message>
|
415
|
-
<returnCode>7</returnCode>
|
416
|
-
<status>2</status>
|
417
|
-
</PagadorReturn>
|
418
|
-
EOXML
|
171
|
+
it "should raise an error when order id is not valid" do
|
172
|
+
Braspag::CreditCard.should_receive(:valid_order_id?)
|
173
|
+
.with("bla")
|
174
|
+
.and_return(false)
|
419
175
|
|
420
|
-
|
176
|
+
expect {
|
177
|
+
Braspag::CreditCard.info "bla"
|
178
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
179
|
+
end
|
421
180
|
|
422
|
-
|
423
|
-
|
181
|
+
it "should raise an error when Braspag returned an invalid xml as response" do
|
182
|
+
FakeWeb.register_uri(:post, info_url, :body => invalid_xml)
|
424
183
|
|
425
|
-
|
426
|
-
|
184
|
+
Braspag::CreditCard.should_receive(:info_url)
|
185
|
+
.and_return(info_url)
|
427
186
|
|
187
|
+
expect {
|
188
|
+
Braspag::CreditCard.info("orderid")
|
189
|
+
}.to raise_error(Braspag::UnknownError)
|
428
190
|
end
|
429
191
|
|
430
|
-
|
192
|
+
it "should return a Hash when Braspag returned a valid xml as response" do
|
193
|
+
FakeWeb.register_uri(:post, info_url, :body => valid_xml)
|
431
194
|
|
432
|
-
|
433
|
-
|
434
|
-
<?xml version="1.0" encoding="utf-8"?>
|
435
|
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
436
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
437
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
438
|
-
<amount>0.01</amount>
|
439
|
-
<message>Payment Server detected an error</message>
|
440
|
-
<returnCode>7</returnCode>
|
441
|
-
<status>null</status>
|
442
|
-
</PagadorReturn>
|
443
|
-
EOXML
|
195
|
+
Braspag::CreditCard.should_receive(:info_url)
|
196
|
+
.and_return(info_url)
|
444
197
|
|
445
|
-
|
198
|
+
response = Braspag::CreditCard.info("orderid")
|
199
|
+
response.should be_kind_of Hash
|
446
200
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
201
|
+
response.should == {
|
202
|
+
:checking_number => "11111",
|
203
|
+
:certified => "false",
|
204
|
+
:autorization_number => "557593",
|
205
|
+
:card_number => "345678*****0007",
|
206
|
+
:transaction_number => "101001225645"
|
207
|
+
}
|
208
|
+
end
|
209
|
+
end
|
452
210
|
|
211
|
+
describe ".check_params" do
|
212
|
+
let(:params) do
|
213
|
+
{
|
214
|
+
:order_id => 12345,
|
215
|
+
:customer_name => "AAAAAAAA",
|
216
|
+
:payment_method => :amex_2p,
|
217
|
+
:amount => "100.00",
|
218
|
+
:holder => "Joao Maria Souza",
|
219
|
+
:expiration => "10/12",
|
220
|
+
:card_number => "9" * 10,
|
221
|
+
:security_code => "123",
|
222
|
+
:number_payments => 1,
|
223
|
+
:type => 0
|
224
|
+
}
|
453
225
|
end
|
454
226
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
227
|
+
[:order_id, :amount, :payment_method, :customer_name, :holder, :card_number, :expiration,
|
228
|
+
:security_code, :number_payments, :type].each do |param|
|
229
|
+
it "should raise an error when #{param} is not present" do
|
230
|
+
expect {
|
231
|
+
params[param] = nil
|
232
|
+
Braspag::CreditCard.check_params(params)
|
233
|
+
}.to raise_error Braspag::IncompleteParams
|
459
234
|
end
|
460
235
|
end
|
461
236
|
|
237
|
+
it "should raise an error when order_id is not valid" do
|
238
|
+
Braspag::CreditCard.should_receive(:valid_order_id?)
|
239
|
+
.with(params[:order_id])
|
240
|
+
.and_return(false)
|
462
241
|
|
463
|
-
describe "#status" do
|
464
|
-
it "should raise an error when no order_id is given" do
|
465
242
|
expect {
|
466
|
-
Braspag::CreditCard.
|
467
|
-
}.to raise_error
|
243
|
+
Braspag::CreditCard.check_params(params)
|
244
|
+
}.to raise_error Braspag::InvalidOrderId
|
468
245
|
end
|
469
246
|
|
470
|
-
it "should raise an error when
|
247
|
+
it "should raise an error when payment_method is not invalid" do
|
471
248
|
expect {
|
472
|
-
|
473
|
-
|
249
|
+
params[:payment_method] = "non ecziste"
|
250
|
+
Braspag::CreditCard.check_params(params)
|
251
|
+
}.to raise_error Braspag::InvalidPaymentMethod
|
474
252
|
end
|
475
253
|
|
476
|
-
it "should raise an error when
|
254
|
+
it "should raise an error when customer_name is greater than 255 chars" do
|
477
255
|
expect {
|
478
|
-
|
479
|
-
|
256
|
+
params[:customer_name] = "b" * 256
|
257
|
+
Braspag::CreditCard.check_params(params)
|
258
|
+
}.to raise_error Braspag::InvalidCustomerName
|
480
259
|
end
|
481
260
|
|
482
|
-
it "should raise an error
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
xmlns="http://www.pagador.com.br/" />
|
489
|
-
EOXML
|
261
|
+
it "should raise an error when holder is greater than 100 chars" do
|
262
|
+
expect {
|
263
|
+
params[:holder] = "r" * 101
|
264
|
+
Braspag::CreditCard.check_params(params)
|
265
|
+
}.to raise_error Braspag::InvalidHolder
|
266
|
+
end
|
490
267
|
|
491
|
-
|
492
|
-
|
268
|
+
it "should raise an error when expiration is not in a valid format" do
|
269
|
+
expect {
|
270
|
+
params[:expiration] = "2011/19/19"
|
271
|
+
Braspag::CreditCard.check_params(params)
|
272
|
+
}.to raise_error Braspag::InvalidExpirationDate
|
493
273
|
|
494
274
|
expect {
|
495
|
-
|
496
|
-
|
275
|
+
params[:expiration] = "12/2012"
|
276
|
+
Braspag::CreditCard.check_params(params)
|
277
|
+
}.to_not raise_error Braspag::InvalidExpirationDate
|
497
278
|
|
279
|
+
expect {
|
280
|
+
params[:expiration] = "12/12"
|
281
|
+
Braspag::CreditCard.check_params(params)
|
282
|
+
}.to_not raise_error Braspag::InvalidExpirationDate
|
283
|
+
end
|
498
284
|
|
285
|
+
it "should raise an error when security code is greater than 4 chars" do
|
499
286
|
expect {
|
500
|
-
|
501
|
-
|
287
|
+
params[:security_code] = "12345"
|
288
|
+
Braspag::CreditCard.check_params(params)
|
289
|
+
}.to raise_error Braspag::InvalidSecurityCode
|
502
290
|
|
503
|
-
|
291
|
+
expect {
|
292
|
+
params[:security_code] = ""
|
293
|
+
Braspag::CreditCard.check_params(params)
|
294
|
+
}.to raise_error Braspag::InvalidSecurityCode
|
504
295
|
end
|
505
296
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
<NumeroComprovante>225296</NumeroComprovante>
|
512
|
-
<Autenticada>false</Autenticada>
|
513
|
-
<NumeroAutorizacao>557593</NumeroAutorizacao>
|
514
|
-
<NumeroCartao>345678*****0007</NumeroCartao>
|
515
|
-
<NumeroTransacao>101001225645</NumeroTransacao>
|
516
|
-
</DadosCartao>
|
517
|
-
EOXML
|
297
|
+
it "should raise an error when number_payments is greater than 99" do
|
298
|
+
expect {
|
299
|
+
params[:number_payments] = 100
|
300
|
+
Braspag::CreditCard.check_params(params)
|
301
|
+
}.to raise_error Braspag::InvalidNumberPayments
|
518
302
|
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
303
|
+
expect {
|
304
|
+
params[:number_payments] = 0
|
305
|
+
Braspag::CreditCard.check_params(params)
|
306
|
+
}.to raise_error Braspag::InvalidNumberPayments
|
307
|
+
end
|
308
|
+
end
|
525
309
|
|
526
|
-
|
527
|
-
|
528
|
-
|
310
|
+
describe ".info_url" do
|
311
|
+
it "should return the correct info url when connection environment is homologation" do
|
312
|
+
@connection.stub(:braspag_url => braspag_homologation_url)
|
313
|
+
@connection.should_receive(:production?)
|
314
|
+
.and_return(false)
|
529
315
|
|
530
|
-
{
|
531
|
-
|
532
|
-
:certified => "false",
|
533
|
-
:autorization_number => "557593",
|
534
|
-
:card_number => "345678*****0007",
|
535
|
-
:transaction_number => "101001225645"
|
536
|
-
}.each do |key, value|
|
316
|
+
Braspag::CreditCard.info_url.should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosCartao"
|
317
|
+
end
|
537
318
|
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
319
|
+
it "should return the correct info url when connection environment is production" do
|
320
|
+
@connection.stub(:braspag_url => braspag_production_url)
|
321
|
+
@connection.should_receive(:production?)
|
322
|
+
.and_return(true)
|
323
|
+
|
324
|
+
Braspag::CreditCard.info_url.should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosCartao"
|
542
325
|
end
|
543
326
|
end
|
544
327
|
|
328
|
+
describe ".authorize_url .capture_url" do
|
329
|
+
it "should return the correct credit card creation url when connection environment is homologation" do
|
330
|
+
@connection.stub(:braspag_url => braspag_homologation_url)
|
331
|
+
Braspag::CreditCard.authorize_url.should == "#{braspag_homologation_url}/webservices/pagador/Pagador.asmx/Authorize"
|
332
|
+
Braspag::CreditCard.capture_url.should == "#{braspag_homologation_url}/webservices/pagador/Pagador.asmx/Capture"
|
333
|
+
end
|
545
334
|
|
335
|
+
it "should return the correct credit card creation url when connection environment is production" do
|
336
|
+
@connection.stub(:braspag_url => braspag_production_url)
|
337
|
+
Braspag::CreditCard.authorize_url.should == "#{braspag_production_url}/webservices/pagador/Pagador.asmx/Authorize"
|
338
|
+
Braspag::CreditCard.capture_url.should == "#{braspag_production_url}/webservices/pagador/Pagador.asmx/Capture"
|
339
|
+
end
|
546
340
|
end
|
547
341
|
end
|