braspag-pagador 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +164 -162
- data/braspag-pagador.gemspec +3 -3
- data/coverage/.resultset.json +69 -26
- data/coverage/index.html +1431 -1147
- data/lib/{braspag.rb → braspag-pagador.rb} +14 -14
- data/lib/{braspag → braspag-pagador}/core/connection.rb +5 -3
- data/lib/{braspag → braspag-pagador}/core/converter.rb +4 -4
- data/lib/{braspag → braspag-pagador}/core/customer.rb +2 -2
- data/lib/{braspag → braspag-pagador}/core/order.rb +51 -51
- data/lib/{braspag → braspag-pagador}/core/poster.rb +1 -1
- data/lib/{braspag → braspag-pagador}/crypto/no_crypto.rb +2 -2
- data/lib/{braspag → braspag-pagador}/crypto/webservice.rb +10 -10
- data/lib/{braspag → braspag-pagador}/payment/billet.rb +10 -10
- data/lib/{braspag → braspag-pagador}/payment/credit_card.rb +8 -8
- data/lib/{braspag → braspag-pagador}/payment/eft.rb +3 -3
- data/lib/{braspag → braspag-pagador}/payment/recurrency_credit_card.rb +1 -1
- data/lib/{braspag → braspag-pagador}/templates/crypto/decrypt.xml.erb +0 -0
- data/lib/{braspag → braspag-pagador}/templates/crypto/encrypt.xml.erb +0 -0
- data/lib/{braspag → braspag-pagador}/templates/justclick/archive.xml.erb +0 -0
- data/lib/{braspag → braspag-pagador}/templates/justclick/get_recurrency.xml.erb +0 -0
- data/lib/{braspag → braspag-pagador}/templates/justclick/recurrency.xml.erb +0 -0
- data/lib/braspag-pagador/version.rb +3 -0
- data/spec/core/connection_spec.rb +50 -50
- data/spec/core/converter_spec.rb +41 -41
- data/spec/core/customer_spec.rb +2 -2
- data/spec/core/order_spec.rb +78 -78
- data/spec/core/poster_spec.rb +8 -8
- data/spec/crypto/webservice_spec.rb +23 -23
- data/spec/integration/billet_spec.rb +11 -11
- data/spec/payment/billet_spec.rb +48 -48
- data/spec/payment/credit_card_spec.rb +82 -82
- data/spec/payment/eft_spec.rb +25 -25
- data/spec/payment/recurrency_credit_card_spec.rb +11 -11
- data/spec/spec_helper.rb +5 -5
- metadata +20 -20
- data/lib/braspag/version.rb +0 -3
@@ -1,18 +1,18 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe BraspagPagador::Crypto::Webservice do
|
5
5
|
|
6
6
|
let(:merchant_id) { "merchant_id" }
|
7
7
|
let(:connection) do
|
8
|
-
conn = double(
|
8
|
+
conn = double(BraspagPagador::Connection)
|
9
9
|
conn.stub(:merchant_id => merchant_id)
|
10
10
|
conn.stub(:url_for => 'fakeurl')
|
11
11
|
conn
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
let(:poster) { mock }
|
15
|
-
|
15
|
+
|
16
16
|
describe "encrypt" do
|
17
17
|
let(:key) {"XXXXX"}
|
18
18
|
|
@@ -21,10 +21,10 @@ describe Braspag::Crypto::Webservice do
|
|
21
21
|
SERVER was unable to process
|
22
22
|
EOXML
|
23
23
|
poster.stub(:do_post => mock(:body => body_invalid))
|
24
|
-
|
24
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
25
25
|
|
26
26
|
expect {
|
27
|
-
|
27
|
+
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
|
28
28
|
}.to raise_error(RuntimeError, 'UnknownError')
|
29
29
|
end
|
30
30
|
|
@@ -36,12 +36,12 @@ EOXML
|
|
36
36
|
<EncryptRequestResult>Erro BP 011</EncryptRequestResult></EncryptRequestResponse>
|
37
37
|
</soap:Body></soap:Envelope>
|
38
38
|
EOXML
|
39
|
-
|
39
|
+
|
40
40
|
poster.stub(:do_post => mock(:body => body_invalid))
|
41
|
-
|
41
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
42
42
|
|
43
43
|
expect {
|
44
|
-
|
44
|
+
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
|
45
45
|
}.to raise_error(RuntimeError, 'InvalidMerchantId')
|
46
46
|
end
|
47
47
|
|
@@ -54,12 +54,12 @@ EOXML
|
|
54
54
|
</soap:Body></soap:Envelope>
|
55
55
|
EOXML
|
56
56
|
poster.stub(:do_post => mock(:body => body_invalid))
|
57
|
-
|
57
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
58
58
|
|
59
59
|
expect {
|
60
|
-
|
60
|
+
BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
|
61
61
|
}.to raise_error(RuntimeError, 'InvalidIP')
|
62
|
-
|
62
|
+
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should return a string" do
|
@@ -72,11 +72,11 @@ EOXML
|
|
72
72
|
</EncryptRequestResponse>
|
73
73
|
</soap:Body></soap:Envelope>
|
74
74
|
EOXML
|
75
|
-
|
75
|
+
|
76
76
|
poster.stub(:do_post => mock(:body => valid_body))
|
77
|
-
|
77
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
78
78
|
|
79
|
-
resp =
|
79
|
+
resp = BraspagPagador::Crypto::Webservice.new.encrypt(connection, {key: key})
|
80
80
|
resp.should eq(key)
|
81
81
|
end
|
82
82
|
end
|
@@ -88,12 +88,12 @@ EOXML
|
|
88
88
|
SERVER was unable to process
|
89
89
|
EOXML
|
90
90
|
poster.stub(:do_post => mock(:body => body_invalid))
|
91
|
-
|
91
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
92
92
|
|
93
93
|
expect {
|
94
|
-
|
94
|
+
BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
|
95
95
|
}.to raise_error(RuntimeError, 'UnknownError')
|
96
|
-
|
96
|
+
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should return error with invalid ip" do
|
@@ -105,10 +105,10 @@ EOXML
|
|
105
105
|
</DecryptRequestResponse></soap:Body></soap:Envelope>
|
106
106
|
EOXML
|
107
107
|
poster.stub(:do_post => mock(:body => body_invalid))
|
108
|
-
|
108
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
109
109
|
|
110
110
|
expect {
|
111
|
-
|
111
|
+
BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
|
112
112
|
}.to raise_error(RuntimeError, 'InvalidIP')
|
113
113
|
end
|
114
114
|
|
@@ -127,10 +127,10 @@ EOXML
|
|
127
127
|
EOXML
|
128
128
|
|
129
129
|
poster.stub(:do_post => mock(:body => valid_body))
|
130
|
-
|
130
|
+
BraspagPagador::Poster.should_receive(:new).with(connection, 'fakeurl').and_return(poster)
|
131
131
|
|
132
|
-
resp =
|
132
|
+
resp = BraspagPagador::Crypto::Webservice.new.decrypt(connection, crypt_string)
|
133
133
|
resp.should eq({:codpagamento=>"18", :vendaid=>"teste123", :valor=>"100", :parcelas=>"1", :nome=>"comprador"})
|
134
134
|
end
|
135
135
|
end
|
136
|
-
end
|
136
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe BraspagPagador::Connection do
|
5
5
|
it "should generate a billet", :billet_integration => true do
|
6
|
-
gateway =
|
6
|
+
gateway = BraspagPagador::Connection.new(
|
7
7
|
:merchant_id => ENV['BRASPAG_MERCHANT_ID'],
|
8
8
|
:environment => :homologation
|
9
9
|
)
|
10
|
-
|
11
|
-
billet =
|
10
|
+
|
11
|
+
billet = BraspagPagador::Billet.new(
|
12
12
|
:instructions => 'does not accepted after due date', # (optional)
|
13
13
|
:due_date_on => Date.today + 2
|
14
14
|
)
|
15
|
-
|
16
|
-
customer =
|
15
|
+
|
16
|
+
customer = BraspagPagador::Customer.new(
|
17
17
|
:document => '21473696240', # (OPTIONAL)
|
18
18
|
:name => 'Bob Dela Bobsen',
|
19
19
|
:email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
|
20
20
|
)
|
21
|
-
|
22
|
-
order =
|
23
|
-
:payment_method =>
|
21
|
+
|
22
|
+
order = BraspagPagador::Order.new(
|
23
|
+
:payment_method => BraspagPagador::PAYMENT_METHOD[:billet_santader],
|
24
24
|
:id => 11,
|
25
25
|
:amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
|
26
26
|
:customer => customer
|
27
27
|
)
|
28
|
-
|
28
|
+
|
29
29
|
# Validating the card automatically detects the card type
|
30
30
|
if billet.valid?(:generate) && customer.valid?(:generate) && order.valid?(:generate)
|
31
31
|
response = gateway.generate_billet(order, billet)
|
@@ -35,4 +35,4 @@ describe Braspag::Connection do
|
|
35
35
|
fail "Invalid Params"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
data/spec/payment/billet_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe BraspagPagador::Connection do
|
5
5
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
6
|
-
let(:connection) {
|
6
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
7
7
|
|
8
8
|
context ".generate_billet" do
|
9
9
|
it "should return response" do
|
@@ -12,11 +12,11 @@ describe Braspag::Connection do
|
|
12
12
|
:message => "BLA",
|
13
13
|
:number => "12345"
|
14
14
|
}
|
15
|
-
|
15
|
+
|
16
16
|
connection.should_receive(:post).and_return(generate_billet)
|
17
|
-
|
17
|
+
|
18
18
|
response = connection.generate_billet(mock, mock)
|
19
|
-
|
19
|
+
|
20
20
|
response.success?.should eq(false)
|
21
21
|
response.message.should eq(generate_billet[:message])
|
22
22
|
response.authorization.should eq(generate_billet[:number])
|
@@ -30,67 +30,67 @@ describe Braspag::Connection do
|
|
30
30
|
:message => "BLA",
|
31
31
|
:number => "12345"
|
32
32
|
}
|
33
|
-
|
33
|
+
|
34
34
|
connection.should_receive(:post).and_return(generate_billet)
|
35
|
-
|
35
|
+
|
36
36
|
response = connection.generate_billet(mock, mock)
|
37
|
-
|
37
|
+
|
38
38
|
response.success?.should eq(true)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
describe
|
43
|
+
describe BraspagPagador::Billet do
|
44
44
|
context "on generate" do
|
45
45
|
it "should allow blank for id" do
|
46
46
|
subject.id = ''
|
47
47
|
subject.valid?(:generate)
|
48
48
|
subject.errors.messages[:id].should be(nil)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should validate maximum 255 length of id" do
|
52
52
|
subject.id = '*' * 260
|
53
53
|
subject.valid?(:generate)
|
54
54
|
subject.errors.messages[:id].should include("is too long (maximum is 255 characters)")
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "should allow blank for instructions" do
|
58
58
|
subject.instructions = ''
|
59
59
|
subject.valid?(:generate)
|
60
60
|
subject.errors.messages[:instructions].should be(nil)
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should validate maximum 512 length of instructions" do
|
64
64
|
subject.instructions = '*' * 520
|
65
65
|
subject.valid?(:generate)
|
66
66
|
subject.errors.messages[:instructions].should include("is too long (maximum is 512 characters)")
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should not allow blank for due_date_on" do
|
70
70
|
subject.due_date_on = ''
|
71
71
|
subject.valid?(:generate)
|
72
72
|
subject.errors.messages[:due_date_on].should include("can't be blank")
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should not allow invalid date for due_date_on" do
|
76
76
|
subject.due_date_on = '12345'
|
77
77
|
subject.valid?(:generate)
|
78
78
|
subject.errors.messages[:due_date_on].should include("invalid date")
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should allow date for due_date_on" do
|
82
82
|
subject.due_date_on = Date.parse('07/03/1988')
|
83
83
|
subject.valid?(:generate)
|
84
84
|
subject.errors.messages[:due_date_on].should be(nil)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
context "on generate billet" do
|
89
89
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
90
|
-
let(:connection) {
|
91
|
-
|
90
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
91
|
+
|
92
92
|
let(:customer) do
|
93
|
-
|
93
|
+
BraspagPagador::Customer.new(
|
94
94
|
:document => '21473696240', # (OPTIONAL)
|
95
95
|
:name => 'Bob Dela Bobsen',
|
96
96
|
:email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
|
@@ -98,24 +98,24 @@ describe Braspag::Billet do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
let(:order) do
|
101
|
-
|
101
|
+
BraspagPagador::Order.new(
|
102
102
|
:id => "um order id",
|
103
103
|
:amount => 100.00,
|
104
|
-
:payment_method =>
|
104
|
+
:payment_method => BraspagPagador::PAYMENT_METHOD[:billet_bradesco],
|
105
105
|
:customer => customer
|
106
106
|
)
|
107
107
|
end
|
108
108
|
|
109
109
|
let(:billet) do
|
110
|
-
|
110
|
+
BraspagPagador::Billet.new(
|
111
111
|
:id => '123456',
|
112
|
-
:instructions => 'does not accepted after due date',
|
112
|
+
:instructions => 'does not accepted after due date',
|
113
113
|
:due_date_on => Date.parse('2012-01-01')
|
114
114
|
)
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
let(:url) { "https://homologacao.pagador.com.br/pagador/reenvia.asp?Id_Transacao=722934be-6756-477a-87ab-42115ee1424d" }
|
118
|
-
|
118
|
+
|
119
119
|
let(:valid_xml) do
|
120
120
|
<<-EOXML
|
121
121
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -131,7 +131,7 @@ describe Braspag::Billet do
|
|
131
131
|
</PagadorBoletoReturn>
|
132
132
|
EOXML
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
let(:invalid_xml) do
|
136
136
|
<<-EOXML
|
137
137
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -148,7 +148,7 @@ describe Braspag::Billet do
|
|
148
148
|
end
|
149
149
|
|
150
150
|
it "should convert objects to hash" do
|
151
|
-
|
151
|
+
BraspagPagador::Billet.to_generate_billet(connection, order, billet).should eq({
|
152
152
|
"merchantId" => connection.merchant_id,
|
153
153
|
"boletoNumber" => billet.id.to_s,
|
154
154
|
"instructions" => billet.instructions.to_s,
|
@@ -157,46 +157,46 @@ describe Braspag::Billet do
|
|
157
157
|
"customerIdNumber" => order.customer.document.to_s,
|
158
158
|
"emails" => order.customer.email.to_s,
|
159
159
|
"orderId" => order.id.to_s,
|
160
|
-
"amount" =>
|
160
|
+
"amount" => BraspagPagador::Converter::decimal_to_string(order.amount),
|
161
161
|
"paymentMethod" => order.payment_method
|
162
162
|
})
|
163
163
|
end
|
164
|
-
|
165
|
-
|
164
|
+
|
165
|
+
|
166
166
|
it "should convert response from xml" do
|
167
|
-
resp =
|
168
|
-
|
167
|
+
resp = BraspagPagador::Billet.from_generate_billet(connection, order, billet, mock(:body => valid_xml))
|
168
|
+
|
169
169
|
billet.url.should eq(url)
|
170
170
|
order.gateway_return_code.should eq('0')
|
171
171
|
order.gateway_status.should eq('0')
|
172
172
|
order.gateway_amount.should eq(3.00)
|
173
|
-
|
173
|
+
|
174
174
|
resp.should eq({
|
175
|
-
:url => url,
|
176
|
-
:amount => "3.00",
|
177
|
-
:number => "123123",
|
178
|
-
:expiration_date => Date.parse('2012-01-08'),
|
179
|
-
:return_code => "0",
|
180
|
-
:status => "0",
|
175
|
+
:url => url,
|
176
|
+
:amount => "3.00",
|
177
|
+
:number => "123123",
|
178
|
+
:expiration_date => Date.parse('2012-01-08'),
|
179
|
+
:return_code => "0",
|
180
|
+
:status => "0",
|
181
181
|
:message => nil
|
182
182
|
})
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
it "should convert response from xml with invalid date" do
|
186
|
-
resp =
|
187
|
-
|
186
|
+
resp = BraspagPagador::Billet.from_generate_billet(connection, order, billet, mock(:body => invalid_xml))
|
187
|
+
|
188
188
|
billet.url.should eq(nil)
|
189
189
|
order.gateway_return_code.should eq('1')
|
190
190
|
order.gateway_status.should eq(nil)
|
191
191
|
order.gateway_amount.should eq(nil)
|
192
|
-
|
192
|
+
|
193
193
|
resp.should eq({
|
194
|
-
:url => nil,
|
195
|
-
:amount => nil,
|
196
|
-
:number => nil,
|
194
|
+
:url => nil,
|
195
|
+
:amount => nil,
|
196
|
+
:number => nil,
|
197
197
|
:expiration_date => nil,
|
198
|
-
:return_code => "1",
|
199
|
-
:status => nil,
|
198
|
+
:return_code => "1",
|
199
|
+
:status => nil,
|
200
200
|
:message => "Invalid merchantId"
|
201
201
|
})
|
202
202
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe BraspagPagador::Connection do
|
4
4
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
5
|
-
let(:connection) {
|
6
|
-
|
5
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
6
|
+
|
7
7
|
context ".purchase" do
|
8
8
|
it "should return authorize when authroize response failed" do
|
9
9
|
auth = mock(:success? => false)
|
10
10
|
connection.stub(:authorize).and_return(auth)
|
11
11
|
connection.purchase(mock, mock).should eq(auth)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should return capture when authorize response success" do
|
15
15
|
cap = mock(:success? => true)
|
16
16
|
connection.stub(:authorize).and_return(mock(:success? => true))
|
@@ -18,7 +18,7 @@ describe Braspag::Connection do
|
|
18
18
|
connection.purchase(mock, mock).should eq(cap)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
context ".authorize" do
|
23
23
|
it "should return response" do
|
24
24
|
authorize = {
|
@@ -26,11 +26,11 @@ describe Braspag::Connection do
|
|
26
26
|
:message => "BLA",
|
27
27
|
:number => "12345"
|
28
28
|
}
|
29
|
-
|
29
|
+
|
30
30
|
connection.should_receive(:post).and_return(authorize)
|
31
|
-
|
31
|
+
|
32
32
|
response = connection.authorize(mock, mock)
|
33
|
-
|
33
|
+
|
34
34
|
response.success?.should eq(false)
|
35
35
|
response.message.should eq(authorize[:message])
|
36
36
|
response.authorization.should eq(authorize[:number])
|
@@ -44,29 +44,29 @@ describe Braspag::Connection do
|
|
44
44
|
:message => "BLA",
|
45
45
|
:number => "12345"
|
46
46
|
}
|
47
|
-
|
47
|
+
|
48
48
|
connection.should_receive(:post).and_return(authorize)
|
49
|
-
|
49
|
+
|
50
50
|
response = connection.authorize(mock, mock)
|
51
|
-
|
51
|
+
|
52
52
|
response.success?.should eq(true)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it "should return success when status is one" do
|
56
56
|
authorize = {
|
57
57
|
:status => "1",
|
58
58
|
:message => "BLA",
|
59
59
|
:number => "12345"
|
60
60
|
}
|
61
|
-
|
61
|
+
|
62
62
|
connection.should_receive(:post).and_return(authorize)
|
63
|
-
|
63
|
+
|
64
64
|
response = connection.authorize(mock, mock)
|
65
|
-
|
65
|
+
|
66
66
|
response.success?.should eq(true)
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
context ".capture" do
|
71
71
|
it "should return response" do
|
72
72
|
capture = {
|
@@ -74,11 +74,11 @@ describe Braspag::Connection do
|
|
74
74
|
:message => "BLA",
|
75
75
|
:number => "12345"
|
76
76
|
}
|
77
|
-
|
77
|
+
|
78
78
|
connection.should_receive(:post).and_return(capture)
|
79
|
-
|
79
|
+
|
80
80
|
response = connection.capture(mock)
|
81
|
-
|
81
|
+
|
82
82
|
response.success?.should eq(false)
|
83
83
|
response.message.should eq(capture[:message])
|
84
84
|
response.authorization.should eq(capture[:number])
|
@@ -92,26 +92,26 @@ describe Braspag::Connection do
|
|
92
92
|
:message => "BLA",
|
93
93
|
:number => "12345"
|
94
94
|
}
|
95
|
-
|
95
|
+
|
96
96
|
connection.should_receive(:post).and_return(capture)
|
97
|
-
|
97
|
+
|
98
98
|
response = connection.capture(mock)
|
99
|
-
|
99
|
+
|
100
100
|
response.success?.should eq(true)
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
context ".void" do
|
105
105
|
it "should return response" do
|
106
106
|
void = {
|
107
107
|
:status => "1",
|
108
108
|
:message => "BLA"
|
109
109
|
}
|
110
|
-
|
110
|
+
|
111
111
|
connection.should_receive(:post).and_return(void)
|
112
|
-
|
112
|
+
|
113
113
|
response = connection.void(mock)
|
114
|
-
|
114
|
+
|
115
115
|
response.success?.should eq(false)
|
116
116
|
response.message.should eq(void[:message])
|
117
117
|
response.params.should eq({"status"=>"1", "message"=>"BLA"})
|
@@ -123,18 +123,18 @@ describe Braspag::Connection do
|
|
123
123
|
:status => "0",
|
124
124
|
:message => "BLA"
|
125
125
|
}
|
126
|
-
|
126
|
+
|
127
127
|
connection.should_receive(:post).and_return(void)
|
128
|
-
|
128
|
+
|
129
129
|
response = connection.void(mock)
|
130
|
-
|
130
|
+
|
131
131
|
response.success?.should eq(true)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
describe
|
137
|
-
|
136
|
+
describe BraspagPagador::CreditCard do
|
137
|
+
|
138
138
|
[:purchase, :authorize, :archive].each do |context_type|
|
139
139
|
context "on #{context_type}" do
|
140
140
|
it "should validate minimum 1 length of holder_name" do
|
@@ -166,7 +166,7 @@ describe Braspag::CreditCard do
|
|
166
166
|
subject.valid?(context_type)
|
167
167
|
subject.errors.messages[:year].should include("can't be blank")
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
it "should not allow invalid date for month & year" do
|
171
171
|
subject.month = "14"
|
172
172
|
subject.year = "2012"
|
@@ -192,7 +192,7 @@ describe Braspag::CreditCard do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
[:purchase, :authorize, :recurrency].each do |context_type|
|
197
197
|
context "on #{context_type}" do
|
198
198
|
it "should validate minimum 1 length of verification_value" do
|
@@ -208,7 +208,7 @@ describe Braspag::CreditCard do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
211
|
-
|
211
|
+
|
212
212
|
[:get_recurrency, :recurrency].each do |context_type|
|
213
213
|
context "on #{context_type}" do
|
214
214
|
it "should validate length of id" do
|
@@ -218,24 +218,24 @@ describe Braspag::CreditCard do
|
|
218
218
|
end
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
let(:customer) do
|
223
|
-
|
223
|
+
BraspagPagador::Customer.new(:name => "W" * 21)
|
224
224
|
end
|
225
225
|
|
226
226
|
let(:order) do
|
227
|
-
|
227
|
+
BraspagPagador::Order.new(
|
228
228
|
:id => "um order id",
|
229
229
|
:amount => 1000.00,
|
230
|
-
:payment_method =>
|
230
|
+
:payment_method => BraspagPagador::PAYMENT_METHOD[:redecard],
|
231
231
|
:installments => 1,
|
232
|
-
:installments_type =>
|
232
|
+
:installments_type => BraspagPagador::INTEREST[:no],
|
233
233
|
:customer => customer
|
234
234
|
)
|
235
235
|
end
|
236
236
|
|
237
237
|
let(:credit_card) do
|
238
|
-
|
238
|
+
BraspagPagador::CreditCard.new(
|
239
239
|
:holder_name => "Joao Maria Souza",
|
240
240
|
:number => "9" * 10,
|
241
241
|
:month => "10",
|
@@ -243,10 +243,10 @@ describe Braspag::CreditCard do
|
|
243
243
|
:verification_value => "123"
|
244
244
|
)
|
245
245
|
end
|
246
|
-
|
246
|
+
|
247
247
|
context "on authorize credit card" do
|
248
248
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
249
|
-
let(:connection) {
|
249
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
250
250
|
|
251
251
|
let(:valid_xml) do
|
252
252
|
<<-EOXML
|
@@ -265,33 +265,33 @@ describe Braspag::CreditCard do
|
|
265
265
|
end
|
266
266
|
|
267
267
|
it "should convert objects to hash" do
|
268
|
-
|
269
|
-
"merchantId" => "#{merchant_id}",
|
270
|
-
"orderId" => "#{order.id}",
|
271
|
-
"customerName" => "#{customer.name}",
|
272
|
-
"amount" => "1000,00",
|
273
|
-
"paymentMethod" => 20,
|
274
|
-
"holder" => "#{credit_card.holder_name}",
|
275
|
-
"cardNumber" => "#{credit_card.number}",
|
276
|
-
"expiration" => "10/12",
|
277
|
-
"securityCode" => "123",
|
278
|
-
"numberPayments" => order.installments,
|
268
|
+
BraspagPagador::CreditCard.to_authorize(connection, order, credit_card).should eq({
|
269
|
+
"merchantId" => "#{merchant_id}",
|
270
|
+
"orderId" => "#{order.id}",
|
271
|
+
"customerName" => "#{customer.name}",
|
272
|
+
"amount" => "1000,00",
|
273
|
+
"paymentMethod" => 20,
|
274
|
+
"holder" => "#{credit_card.holder_name}",
|
275
|
+
"cardNumber" => "#{credit_card.number}",
|
276
|
+
"expiration" => "10/12",
|
277
|
+
"securityCode" => "123",
|
278
|
+
"numberPayments" => order.installments,
|
279
279
|
"typePayment" => order.installments_type
|
280
280
|
})
|
281
281
|
end
|
282
|
-
|
282
|
+
|
283
283
|
it "should populate data" do
|
284
|
-
resp =
|
285
|
-
|
284
|
+
resp = BraspagPagador::CreditCard.from_authorize(connection, order, credit_card, mock(:body => valid_xml))
|
285
|
+
|
286
286
|
order.gateway_authorization.should eq('733610')
|
287
287
|
order.gateway_id.should eq('01231234')
|
288
288
|
order.gateway_return_code.should eq('0')
|
289
289
|
order.gateway_status.should eq('1')
|
290
290
|
order.gateway_message.should eq('Transaction Successful')
|
291
291
|
order.gateway_amount.should eq(1000.00)
|
292
|
-
|
292
|
+
|
293
293
|
resp.should eq({
|
294
|
-
:amount=>"1.000,00",
|
294
|
+
:amount=>"1.000,00",
|
295
295
|
:number=>"733610",
|
296
296
|
:message=>"Transaction Successful",
|
297
297
|
:return_code=>"0",
|
@@ -299,11 +299,11 @@ describe Braspag::CreditCard do
|
|
299
299
|
:transaction_id=>"01231234"})
|
300
300
|
end
|
301
301
|
end
|
302
|
-
|
302
|
+
|
303
303
|
context "on capture credit card" do
|
304
304
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
305
|
-
let(:connection) {
|
306
|
-
|
305
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
306
|
+
|
307
307
|
let(:valid_xml) do
|
308
308
|
<<-EOXML
|
309
309
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -317,37 +317,37 @@ describe Braspag::CreditCard do
|
|
317
317
|
</PagadorReturn>
|
318
318
|
EOXML
|
319
319
|
end
|
320
|
-
|
320
|
+
|
321
321
|
it "should convert objects to hash" do
|
322
|
-
|
323
|
-
"merchantId" => "#{merchant_id}",
|
322
|
+
BraspagPagador::CreditCard.to_capture(connection, order).should eq({
|
323
|
+
"merchantId" => "#{merchant_id}",
|
324
324
|
"orderId" => "#{order.id}"
|
325
325
|
})
|
326
326
|
end
|
327
|
-
|
327
|
+
|
328
328
|
it "should populate data" do
|
329
|
-
resp =
|
330
|
-
|
329
|
+
resp = BraspagPagador::CreditCard.from_capture(connection, order, mock(:body => valid_xml))
|
330
|
+
|
331
331
|
order.gateway_capture_return_code.should eq('0')
|
332
332
|
order.gateway_capture_status.should eq('0')
|
333
333
|
order.gateway_capture_message.should eq('Approved')
|
334
334
|
order.gateway_capture_amount.should eq(2.00)
|
335
335
|
|
336
|
-
|
336
|
+
|
337
337
|
resp.should eq({
|
338
|
-
:amount=>"2",
|
339
|
-
:message=>"Approved",
|
340
|
-
:return_code=>"0",
|
341
|
-
:status=>"0",
|
338
|
+
:amount=>"2",
|
339
|
+
:message=>"Approved",
|
340
|
+
:return_code=>"0",
|
341
|
+
:status=>"0",
|
342
342
|
:transaction_id=>nil
|
343
343
|
})
|
344
344
|
end
|
345
345
|
end
|
346
|
-
|
346
|
+
|
347
347
|
context "on void credit card" do
|
348
348
|
let(:merchant_id) { "{12345678-1234-1234-1234-123456789000}" }
|
349
|
-
let(:connection) {
|
350
|
-
|
349
|
+
let(:connection) { BraspagPagador::Connection.new(:merchant_id => merchant_id, :environment => :homologation)}
|
350
|
+
|
351
351
|
let(:valid_xml) do
|
352
352
|
<<-EOXML
|
353
353
|
<?xml version="1.0" encoding="utf-8"?>
|
@@ -363,22 +363,22 @@ describe Braspag::CreditCard do
|
|
363
363
|
</PagadorReturn>
|
364
364
|
EOXML
|
365
365
|
end
|
366
|
-
|
366
|
+
|
367
367
|
it "should convert objects to hash" do
|
368
|
-
|
369
|
-
"merchantId" => "#{merchant_id}",
|
368
|
+
BraspagPagador::CreditCard.to_void(connection, order).should eq({
|
369
|
+
"merchantId" => "#{merchant_id}",
|
370
370
|
"order" => "#{order.id}"
|
371
371
|
})
|
372
372
|
end
|
373
|
-
|
373
|
+
|
374
374
|
it "should populate data" do
|
375
|
-
resp =
|
376
|
-
|
375
|
+
resp = BraspagPagador::CreditCard.from_void(connection, order, mock(:body => valid_xml))
|
376
|
+
|
377
377
|
order.gateway_void_return_code.should eq('0')
|
378
378
|
order.gateway_void_status.should eq('0')
|
379
379
|
order.gateway_void_message.should eq('Approved')
|
380
380
|
order.gateway_void_amount.should eq(100.00)
|
381
|
-
|
381
|
+
|
382
382
|
resp.should eq({:order_id=>"1234", :amount=>"100", :message=>"Approved", :return_code=>"0", :status=>"0", :transaction_id=>"0"})
|
383
383
|
end
|
384
384
|
end
|