rbraspag 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- 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/bill_spec.rb
CHANGED
@@ -2,337 +2,265 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::Bill do
|
5
|
+
let!(:braspag_url) { "https://homologacao.pagador.com.br" }
|
6
|
+
|
7
|
+
describe ".generate" do
|
8
|
+
context "consitencies" do
|
9
|
+
before do
|
10
|
+
xml = <<-EOXML
|
11
|
+
<?xml version="1.0" encoding="utf-8"?>
|
12
|
+
<PagadorBoletoReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://www.pagador.com.br/webservice/pagador">
|
13
|
+
<amount>1234.56</amount>
|
14
|
+
<boletoNumber>70345</boletoNumber>
|
15
|
+
<expirationDate>2011-08-13T00:00:00-03:00</expirationDate>
|
16
|
+
<url>https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=0224306d-d483-4026-9022-a855a645e7ec</url>
|
17
|
+
<returnCode>0</returnCode>
|
18
|
+
<status>0</status>
|
19
|
+
</PagadorBoletoReturn>
|
20
|
+
EOXML
|
21
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
22
|
+
end
|
5
23
|
|
6
|
-
|
7
|
-
|
24
|
+
after do
|
25
|
+
FakeWeb.clean_registry
|
26
|
+
end
|
8
27
|
|
9
|
-
|
28
|
+
it "should raise an error when :order_id is not present" do
|
29
|
+
expect {
|
30
|
+
Braspag::Bill.generate( {
|
31
|
+
:amount => "100.00",
|
32
|
+
:payment_method => :bradesco
|
33
|
+
})
|
34
|
+
}.to raise_error(Braspag::IncompleteParams)
|
35
|
+
end
|
10
36
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
37
|
+
it "should raise an error when :amount is not present" do
|
38
|
+
expect {
|
39
|
+
Braspag::Bill.generate( {
|
40
|
+
:order_id => "12",
|
41
|
+
:payment_method => :bradesco
|
42
|
+
})
|
43
|
+
}.to raise_error(Braspag::IncompleteParams)
|
44
|
+
end
|
16
45
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
46
|
+
it "should raise an error when :payment_method is not present" do
|
47
|
+
expect {
|
48
|
+
Braspag::Bill.generate( {
|
49
|
+
:order_id => "13",
|
50
|
+
:amount => "120.00"
|
51
|
+
})
|
52
|
+
}.to raise_error(Braspag::IncompleteParams)
|
53
|
+
end
|
25
54
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
55
|
+
it "should raise an error when invalid string :payment_method" do
|
56
|
+
expect {
|
57
|
+
Braspag::Bill.generate( {
|
58
|
+
:order_id => "13",
|
59
|
+
:amount => "120.00",
|
60
|
+
:payment_method => "10"
|
61
|
+
})
|
62
|
+
}.to raise_error(Braspag::InvalidPaymentMethod)
|
63
|
+
end
|
34
64
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
65
|
+
it "should raise an error when invalid symbol :payment_method" do
|
66
|
+
expect {
|
67
|
+
Braspag::Bill.generate( {
|
68
|
+
:order_id => "13",
|
69
|
+
:amount => "120.00",
|
70
|
+
:payment_method => :invalid
|
71
|
+
})
|
72
|
+
}.to raise_error(Braspag::InvalidPaymentMethod)
|
73
|
+
end
|
43
74
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
75
|
+
it "should raise an error when :order_id is less than 1 character" do
|
76
|
+
expect {
|
77
|
+
Braspag::Bill.generate( {
|
78
|
+
:order_id => "",
|
79
|
+
:amount => "123.00",
|
80
|
+
:payment_method => :bradesco
|
81
|
+
})
|
82
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
83
|
+
end
|
53
84
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
85
|
+
it "should raise an error when :order_id is more than 50 characters" do
|
86
|
+
expect {
|
87
|
+
Braspag::Bill.generate( {
|
88
|
+
:order_id => "1" * 51,
|
89
|
+
:amount => "12.00",
|
90
|
+
:payment_method => :bradesco
|
91
|
+
})
|
92
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
93
|
+
end
|
63
94
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
95
|
+
it "should raise an error when :customer_name is less than 1 character" do
|
96
|
+
expect {
|
97
|
+
Braspag::Bill.generate( {
|
98
|
+
:order_id => "102",
|
99
|
+
:amount => "42.00",
|
100
|
+
:payment_method => :bradesco,
|
101
|
+
:customer_name => ""
|
102
|
+
})
|
103
|
+
}.to raise_error(Braspag::InvalidCustomerName)
|
104
|
+
end
|
73
105
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
106
|
+
it "should raise an error when :customer_name is more than 255 characters" do
|
107
|
+
expect {
|
108
|
+
Braspag::Bill.generate( {
|
109
|
+
:order_id => "112",
|
110
|
+
:amount => "121.00",
|
111
|
+
:payment_method => :bradesco,
|
112
|
+
:customer_name => "A" * 256
|
113
|
+
})
|
114
|
+
}.to raise_error(Braspag::InvalidCustomerName)
|
115
|
+
end
|
83
116
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
117
|
+
it "should raise an error when :customer_id is less than 11 characters" do
|
118
|
+
expect {
|
119
|
+
Braspag::Bill.generate( {
|
120
|
+
:order_id => "23",
|
121
|
+
:amount => "251.00",
|
122
|
+
:payment_method => :bradesco,
|
123
|
+
:customer_id => "2" * 10
|
124
|
+
})
|
125
|
+
}.to raise_error(Braspag::InvalidCustomerId)
|
126
|
+
end
|
94
127
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
128
|
+
it "should raise an error when :customer_id is more than 18 characters" do
|
129
|
+
expect {
|
130
|
+
Braspag::Bill.generate( {
|
131
|
+
:order_id => "90",
|
132
|
+
:amount => "90.00",
|
133
|
+
:payment_method => :bradesco,
|
134
|
+
:customer_id => "3" * 19
|
135
|
+
})
|
136
|
+
}.to raise_error(Braspag::InvalidCustomerId)
|
137
|
+
end
|
105
138
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
139
|
+
it "should raise an error when :number is less than 1 character" do
|
140
|
+
expect {
|
141
|
+
Braspag::Bill.generate( {
|
142
|
+
:order_id => "900",
|
143
|
+
:amount => "92.00",
|
144
|
+
:payment_method => :bradesco,
|
145
|
+
:number => ""
|
146
|
+
})
|
147
|
+
}.to raise_error(Braspag::InvalidNumber)
|
148
|
+
end
|
116
149
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
150
|
+
it "should raise an error when :number is more than 255 characters" do
|
151
|
+
expect {
|
152
|
+
Braspag::Bill.generate( {
|
153
|
+
:order_id => "91",
|
154
|
+
:amount => "80.00",
|
155
|
+
:payment_method => :bradesco,
|
156
|
+
:number => "5" * 256
|
157
|
+
})
|
158
|
+
}.to raise_error(Braspag::InvalidNumber)
|
159
|
+
end
|
127
160
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
161
|
+
it "should raise an error when :instructions is less than 1 character" do
|
162
|
+
expect {
|
163
|
+
Braspag::Bill.generate( {
|
164
|
+
:order_id => "76",
|
165
|
+
:amount => "50.00",
|
166
|
+
:payment_method => :bradesco,
|
167
|
+
:instructions => ""
|
168
|
+
})
|
169
|
+
}.to raise_error(Braspag::InvalidInstructions)
|
170
|
+
end
|
138
171
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
172
|
+
it "should raise an error when :instructions is more than 512 characters" do
|
173
|
+
expect {
|
174
|
+
Braspag::Bill.generate( {
|
175
|
+
:order_id => "65",
|
176
|
+
:amount => "210.00",
|
177
|
+
:payment_method => :bradesco,
|
178
|
+
:instructions => "O" * 513
|
179
|
+
})
|
180
|
+
}.to raise_error(Braspag::InvalidInstructions)
|
181
|
+
end
|
149
182
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
183
|
+
it "should raise an error when :expiration_date is more or less than 8 characters" do
|
184
|
+
expect {
|
185
|
+
Braspag::Bill.generate( {
|
186
|
+
:order_id => "34",
|
187
|
+
:amount => "245.00",
|
188
|
+
:payment_method => :bradesco,
|
189
|
+
:expiration_date => "1" * 7
|
190
|
+
})
|
191
|
+
}.to raise_error(Braspag::InvalidExpirationDate)
|
160
192
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
end
|
193
|
+
expect {
|
194
|
+
Braspag::Bill.generate( {
|
195
|
+
:order_id => "67",
|
196
|
+
:amount => "321.00",
|
197
|
+
:payment_method => :bradesco,
|
198
|
+
:expiration_date => "2" * 9
|
199
|
+
})
|
200
|
+
}.to raise_error(Braspag::InvalidExpirationDate)
|
201
|
+
end
|
171
202
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
}.to raise_error(Braspag::InvalidExpirationDate)
|
203
|
+
it "should accept :payment_method as Symbol Object and convert to relative String value" do
|
204
|
+
Braspag::Bill.generate( {
|
205
|
+
:order_id => "67",
|
206
|
+
:amount => "321.00",
|
207
|
+
:payment_method => :itau,
|
208
|
+
:expiration_date => Date.today + 2
|
209
|
+
}).should be_instance_of(Hash)
|
210
|
+
end
|
181
211
|
|
182
|
-
|
183
|
-
Braspag::Bill.
|
212
|
+
it "should accept :expiration_date with Date Object" do
|
213
|
+
Braspag::Bill.generate( {
|
184
214
|
:order_id => "67",
|
185
215
|
:amount => "321.00",
|
186
216
|
:payment_method => :bradesco,
|
187
|
-
:expiration_date => "2" * 9
|
188
|
-
})
|
189
|
-
}.to raise_error(Braspag::InvalidExpirationDate)
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should accept :payment_method as Symbol Object and convert to relative String value" do
|
193
|
-
(bill = Braspag::Bill.new(connection, {
|
194
|
-
:order_id => "67",
|
195
|
-
:amount => "321.00",
|
196
|
-
:payment_method => :itau,
|
197
217
|
:expiration_date => Date.today + 2
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
bill[:payment_method].should == :itau
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should accept :expiration_date with Date Object" do
|
205
|
-
Braspag::Bill.new(connection, {
|
206
|
-
:order_id => "67",
|
207
|
-
:amount => "321.00",
|
208
|
-
:payment_method => :bradesco,
|
209
|
-
:expiration_date => Date.today + 2
|
210
|
-
}).should be_ok
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should accept :expiration_date with valid string date" do
|
214
|
-
Braspag::Bill.new(connection, {
|
215
|
-
:order_id => "67",
|
216
|
-
:amount => "321.00",
|
217
|
-
:payment_method => :bradesco,
|
218
|
-
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
219
|
-
}).should be_ok
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should accept string as :amount" do
|
223
|
-
(bill = Braspag::Bill.new(connection, {
|
224
|
-
:order_id => "67",
|
225
|
-
:amount => "54321.45",
|
226
|
-
:payment_method => :bradesco,
|
227
|
-
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
228
|
-
})
|
229
|
-
).should be_ok
|
230
|
-
|
231
|
-
bill[:amount].should == BigDecimal.new("54321.45")
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should accept integer as :amount" do
|
235
|
-
(bill = Braspag::Bill.new(connection, {
|
236
|
-
:order_id => "67",
|
237
|
-
:amount => 123,
|
238
|
-
:payment_method => :bradesco,
|
239
|
-
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
240
|
-
})
|
241
|
-
).should be_ok
|
242
|
-
|
243
|
-
bill[:amount].should == BigDecimal.new("123.00")
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should accept BigDecimal as :amount" do
|
247
|
-
(bill = Braspag::Bill.new(connection, {
|
248
|
-
:order_id => "67",
|
249
|
-
:amount => BigDecimal.new("123.45"),
|
250
|
-
:payment_method => :bradesco,
|
251
|
-
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
252
|
-
})
|
253
|
-
).should be_ok
|
254
|
-
|
255
|
-
bill[:amount].should == BigDecimal.new("123.45")
|
256
|
-
end
|
218
|
+
}).should be_instance_of(Hash)
|
219
|
+
end
|
257
220
|
|
258
|
-
|
259
|
-
|
221
|
+
it "should accept :expiration_date with valid string date" do
|
222
|
+
Braspag::Bill.generate( {
|
260
223
|
:order_id => "67",
|
261
|
-
:amount =>
|
224
|
+
:amount => "321.00",
|
262
225
|
:payment_method => :bradesco,
|
263
226
|
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
264
|
-
|
265
|
-
).should be_ok
|
266
|
-
|
267
|
-
bill[:amount].should == BigDecimal.new("12345.00")
|
268
|
-
end
|
269
|
-
|
270
|
-
end
|
271
|
-
|
272
|
-
describe ".generate" do
|
273
|
-
context "with all data" do
|
274
|
-
before do
|
275
|
-
@tomorrow = (Time.now + 3600 * 24 * 2)
|
276
|
-
|
277
|
-
data = {
|
278
|
-
:order_id => Time.now.to_i.to_s,
|
279
|
-
:amount => 3,
|
280
|
-
:payment_method => :real,
|
281
|
-
:number => "123123",
|
282
|
-
:expiration_date => @tomorrow.strftime("%d/%m/%y")
|
283
|
-
}
|
284
|
-
|
285
|
-
@bill = Braspag::Bill.new(connection, data)
|
286
|
-
@response = @bill.generate
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should return the bill number" do
|
290
|
-
@response[:number].should == "123123"
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should return the expiration date" do
|
294
|
-
@response[:expiration_date].should be_kind_of Date
|
295
|
-
@response[:expiration_date].strftime("%d/%m/%Y").should == @tomorrow.strftime("%d/%m/%Y")
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
context "with minimum correct data" do
|
300
|
-
before(:all) do
|
301
|
-
data = {
|
302
|
-
:order_id => Time.now.to_i.to_s,
|
303
|
-
:amount => 1234.56,
|
304
|
-
:payment_method => :real
|
305
|
-
}
|
306
|
-
@bill = Braspag::Bill.new(connection, data)
|
307
|
-
@response = @bill.generate
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should return a public url" do
|
311
|
-
regexp = %r"https://homologacao\.pagador\.com\.br/pagador/reenvia\.asp\?Id_Transacao=[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}"
|
312
|
-
@response[:url].should match(regexp)
|
227
|
+
}).should be_instance_of(Hash)
|
313
228
|
end
|
314
229
|
|
315
|
-
it "should
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
230
|
+
it "should accept string as :amount" do
|
231
|
+
Braspag::Bill.generate( {
|
232
|
+
:order_id => "67",
|
233
|
+
:amount => "54321.45",
|
234
|
+
:payment_method => :bradesco,
|
235
|
+
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
236
|
+
}).should be_instance_of(Hash)
|
321
237
|
end
|
322
238
|
|
323
|
-
it "should
|
324
|
-
|
239
|
+
it "should accept integer as :amount" do
|
240
|
+
Braspag::Bill.generate( {
|
241
|
+
:order_id => "67",
|
242
|
+
:amount => 123,
|
243
|
+
:payment_method => :bradesco,
|
244
|
+
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
245
|
+
}).should be_instance_of(Hash)
|
325
246
|
end
|
326
247
|
|
327
|
-
it "should
|
328
|
-
|
248
|
+
it "should accept BigDecimal as :amount" do
|
249
|
+
Braspag::Bill.generate( {
|
250
|
+
:order_id => "67",
|
251
|
+
:amount => BigDecimal.new("123.45"),
|
252
|
+
:payment_method => :bradesco,
|
253
|
+
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
254
|
+
}).should be_instance_of(Hash)
|
329
255
|
end
|
330
256
|
|
331
|
-
it "should
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
257
|
+
it "should accept integer as :amount" do
|
258
|
+
Braspag::Bill.generate( {
|
259
|
+
:order_id => "67",
|
260
|
+
:amount => 12345,
|
261
|
+
:payment_method => :bradesco,
|
262
|
+
:expiration_date => (Date.today + 2).strftime("%d/%m/%y")
|
263
|
+
}).should be_instance_of(Hash)
|
336
264
|
end
|
337
265
|
end
|
338
266
|
|
@@ -351,17 +279,14 @@ describe Braspag::Bill do
|
|
351
279
|
</PagadorBoletoReturn>
|
352
280
|
EOXML
|
353
281
|
|
354
|
-
FakeWeb.register_uri(:post, "#{
|
355
|
-
|
356
|
-
connection = Braspag::Connection.new("{12345678-1234-1234-1234-123456789000}", :test)
|
282
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
357
283
|
|
358
284
|
expect {
|
359
|
-
|
285
|
+
Braspag::Bill.generate( {
|
360
286
|
:order_id => 1,
|
361
287
|
:amount => 3,
|
362
288
|
:payment_method => :hsbc
|
363
289
|
})
|
364
|
-
bill.generate
|
365
290
|
}.to raise_error(Braspag::InvalidMerchantId)
|
366
291
|
|
367
292
|
FakeWeb.clean_registry
|
@@ -381,16 +306,15 @@ describe Braspag::Bill do
|
|
381
306
|
</PagadorBoletoReturn>
|
382
307
|
EOXML
|
383
308
|
|
384
|
-
FakeWeb.register_uri(:post, "#{
|
309
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
385
310
|
|
386
311
|
expect {
|
387
|
-
|
312
|
+
Braspag::Bill.generate( {
|
388
313
|
:number => "A" * 50,
|
389
314
|
:order_id => "x",
|
390
315
|
:amount => 3,
|
391
316
|
:payment_method => :hsbc
|
392
317
|
})
|
393
|
-
bill.generate
|
394
318
|
}.to raise_error(Braspag::InvalidStringFormat)
|
395
319
|
|
396
320
|
FakeWeb.clean_registry
|
@@ -410,15 +334,14 @@ describe Braspag::Bill do
|
|
410
334
|
</PagadorBoletoReturn>
|
411
335
|
EOXML
|
412
336
|
|
413
|
-
FakeWeb.register_uri(:post, "#{
|
337
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
414
338
|
|
415
339
|
expect {
|
416
|
-
bill = Braspag::Bill.
|
340
|
+
bill = Braspag::Bill.generate( {
|
417
341
|
:order_id => 1,
|
418
342
|
:amount => "0000",
|
419
343
|
:payment_method => :hsbc
|
420
344
|
})
|
421
|
-
bill.generate
|
422
345
|
}.to raise_error(Braspag::InvalidPaymentMethod)
|
423
346
|
|
424
347
|
FakeWeb.clean_registry
|
@@ -438,15 +361,14 @@ describe Braspag::Bill do
|
|
438
361
|
</PagadorBoletoReturn>
|
439
362
|
EOXML
|
440
363
|
|
441
|
-
FakeWeb.register_uri(:post, "#{
|
364
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
442
365
|
|
443
366
|
expect {
|
444
|
-
bill = Braspag::Bill.
|
367
|
+
bill = Braspag::Bill.generate( {
|
445
368
|
:order_id => 1,
|
446
369
|
:amount => -33,
|
447
370
|
:payment_method => :hsbc
|
448
371
|
})
|
449
|
-
bill.generate
|
450
372
|
}.to raise_error(Braspag::InvalidAmount)
|
451
373
|
|
452
374
|
FakeWeb.clean_registry
|
@@ -466,26 +388,189 @@ describe Braspag::Bill do
|
|
466
388
|
</PagadorBoletoReturn>
|
467
389
|
EOXML
|
468
390
|
|
469
|
-
FakeWeb.register_uri(:post, "#{
|
391
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/webservices/pagador/Boleto.asmx/CreateBoleto", :body => xml)
|
470
392
|
|
471
393
|
expect {
|
472
|
-
bill = Braspag::Bill.
|
394
|
+
bill = Braspag::Bill.generate( {
|
473
395
|
:order_id => 1,
|
474
396
|
:amount => 3,
|
475
397
|
:payment_method => :real
|
476
398
|
})
|
477
|
-
bill.generate
|
478
399
|
}.to raise_error(Braspag::UnknownError)
|
479
400
|
|
480
401
|
FakeWeb.clean_registry
|
481
402
|
end
|
482
403
|
end
|
483
404
|
|
484
|
-
|
405
|
+
|
406
|
+
context "with all data" do
|
407
|
+
before(:all) do
|
408
|
+
@tomorrow = (Time.now + 3600 * 24 * 2)
|
409
|
+
|
410
|
+
data = {
|
411
|
+
:order_id => Time.now.to_i.to_s,
|
412
|
+
:amount => 3,
|
413
|
+
:payment_method => :real,
|
414
|
+
:number => "123123",
|
415
|
+
:expiration_date => @tomorrow.strftime("%d/%m/%y")
|
416
|
+
}
|
417
|
+
|
418
|
+
@response = Braspag::Bill.generate( data)
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should return the bill number" do
|
422
|
+
@response[:number].should == "123123"
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should return the expiration date" do
|
426
|
+
@response[:expiration_date].should be_kind_of Date
|
427
|
+
@response[:expiration_date].strftime("%d/%m/%Y").should == @tomorrow.strftime("%d/%m/%Y")
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
context "with minimum correct data" do
|
432
|
+
before(:all) do
|
433
|
+
data = {
|
434
|
+
:order_id => Time.now.to_i.to_s,
|
435
|
+
:amount => 1234.56,
|
436
|
+
:payment_method => :real
|
437
|
+
}
|
438
|
+
@response = Braspag::Bill.generate( data)
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should return a public url" do
|
442
|
+
regexp = %r"https://homologacao\.pagador\.com\.br/pagador/reenvia\.asp\?Id_Transacao=[a-z0-9]{8}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{4}\-[a-z0-9]{12}"
|
443
|
+
@response[:url].should match(regexp)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should return 0 (waiting payment) as the status" do
|
447
|
+
@response[:status].should == "0"
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should return 0 (success) as the return_code" do
|
451
|
+
@response[:return_code].should == "0"
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should return 3 as the amount" do
|
455
|
+
@response[:amount].should == BigDecimal.new("1234.56")
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should return the bill number" do
|
459
|
+
@response[:number].should_not be_empty
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should return the expiration date" do
|
463
|
+
ten_days_after_today = (Time.now + 3600 * 24 * 10)
|
464
|
+
|
465
|
+
@response[:expiration_date].should be_kind_of Date
|
466
|
+
@response[:expiration_date].strftime("%d/%m/%Y").should == ten_days_after_today.strftime("%d/%m/%Y")
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
describe "#status" do
|
472
|
+
it "should raise an error when no Bill_id is given" do
|
473
|
+
expect {
|
474
|
+
Braspag::Bill.info(nil)
|
475
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "should raise an error when Bill_id is empty" do
|
479
|
+
expect {
|
480
|
+
Braspag::Bill.info("")
|
481
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
482
|
+
end
|
483
|
+
|
484
|
+
it "should raise an error when Bill_id is more than 50 characters" do
|
485
|
+
expect {
|
486
|
+
Braspag::Bill.info("1" * 51)
|
487
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should raise an error for incorrect data" do
|
491
|
+
xml = <<-EOXML
|
492
|
+
<?xml version="1.0" encoding="utf-8"?>
|
493
|
+
<DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
494
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
495
|
+
xsi:nil="true"
|
496
|
+
xmlns="http://www.pagador.com.br/" />
|
497
|
+
EOXML
|
498
|
+
|
499
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/pagador/webservice/pedido.asmx/GetDadosBoleto",
|
500
|
+
:body => xml)
|
501
|
+
|
502
|
+
expect {
|
503
|
+
Braspag::Bill.info("sadpoakjspodqdouq09wduwq")
|
504
|
+
}.to raise_error(Braspag::UnknownError)
|
505
|
+
|
506
|
+
|
507
|
+
expect {
|
508
|
+
Braspag::Bill.info("asdnasdniousa")
|
509
|
+
}.to raise_error(Braspag::UnknownError)
|
510
|
+
|
511
|
+
FakeWeb.clean_registry
|
512
|
+
end
|
513
|
+
|
514
|
+
context "with correct data" do
|
515
|
+
|
516
|
+
let(:status) {
|
517
|
+
xml = <<-EOXML
|
518
|
+
<?xml version="1.0" encoding="utf-8"?>
|
519
|
+
<DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
520
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
521
|
+
xmlns="http://www.pagador.com.br/">
|
522
|
+
<NumeroDocumento>999</NumeroDocumento>
|
523
|
+
<Sacado/>
|
524
|
+
<NossoNumero>999</NossoNumero>
|
525
|
+
<LinhaDigitavel>35690.00361 03962.070003 00000.009993 4 50160000001000</LinhaDigitavel>
|
526
|
+
<DataDocumento>22/6/2011</DataDocumento>
|
527
|
+
<DataVencimento>2/7/2011</DataVencimento>
|
528
|
+
<Cedente>Gonow Tecnologia e Acessoria Empresarial Ltda</Cedente>
|
529
|
+
<Banco>356-5</Banco>
|
530
|
+
<Agencia>0003</Agencia>
|
531
|
+
<Conta>6039620</Conta>
|
532
|
+
<Carteira>57</Carteira>
|
533
|
+
<ValorDocumento>10,00</ValorDocumento>
|
534
|
+
</DadosBoleto>
|
535
|
+
EOXML
|
536
|
+
|
537
|
+
FakeWeb.register_uri(:post, "#{braspag_url}/pagador/webservice/pedido.asmx/GetDadosBoleto",
|
538
|
+
:body => xml)
|
539
|
+
status = Braspag::Bill.info("12345")
|
540
|
+
FakeWeb.clean_registry
|
541
|
+
status
|
542
|
+
}
|
543
|
+
|
544
|
+
it "should return a Hash" do
|
545
|
+
status.should be_kind_of Hash
|
546
|
+
end
|
547
|
+
|
548
|
+
{
|
549
|
+
:document_number => "999",
|
550
|
+
:payer => nil,
|
551
|
+
:our_number => "999",
|
552
|
+
:bill_line => "35690.00361 03962.070003 00000.009993 4 50160000001000",
|
553
|
+
:document_date => "22/6/2011",
|
554
|
+
:expiration_date => "2/7/2011",
|
555
|
+
:receiver => "Gonow Tecnologia e Acessoria Empresarial Ltda",
|
556
|
+
:bank => "356-5",
|
557
|
+
:agency => "0003",
|
558
|
+
:account => "6039620",
|
559
|
+
:wallet => "57",
|
560
|
+
:amount => "10,00",
|
561
|
+
}.each do |key, value|
|
562
|
+
|
563
|
+
it "should return a Hash with :#{key.to_s} key" do
|
564
|
+
status[key].should == value
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
describe ".payment_method_from_id" do
|
485
571
|
it 'Credit card amex' do
|
486
572
|
Braspag::Bill::payment_method_from_id("06").should == :bradesco
|
487
573
|
Braspag::Bill::payment_method_from_id("06").should be_kind_of Symbol
|
488
574
|
end
|
489
|
-
end
|
490
575
|
end
|
491
576
|
end
|