baby-braspag 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/baby-braspag/connection.rb +8 -0
- data/lib/baby-braspag/credit_card.rb +14 -43
- data/lib/baby-braspag/version.rb +1 -1
- data/spec/connection_spec.rb +40 -0
- data/spec/credit_card_spec.rb +0 -67
- metadata +1 -1
@@ -3,7 +3,7 @@ module Braspag
|
|
3
3
|
|
4
4
|
MAPPING = {
|
5
5
|
:merchant_id => "merchantId",
|
6
|
-
:order =>
|
6
|
+
:order => 'order',
|
7
7
|
:order_id => "orderId",
|
8
8
|
:customer_name => "customerName",
|
9
9
|
:amount => "amount",
|
@@ -20,7 +20,6 @@ module Braspag
|
|
20
20
|
CAPTURE_URI = "/webservices/pagador/Pagador.asmx/Capture"
|
21
21
|
PARTIAL_CAPTURE_URI = "/webservices/pagador/Pagador.asmx/CapturePartial"
|
22
22
|
CANCELLATION_URI = "/webservices/pagador/Pagador.asmx/VoidTransaction"
|
23
|
-
PARTIAL_CANCELLATION_URI = "/webservices/pagador/Pagador.asmx/VoidPartial"
|
24
23
|
PRODUCTION_INFO_URI = "/webservices/pagador/pedido.asmx/GetDadosCartao"
|
25
24
|
HOMOLOGATION_INFO_URI = "/pagador/webservice/pedido.asmx/GetDadosCartao"
|
26
25
|
|
@@ -47,9 +46,9 @@ module Braspag
|
|
47
46
|
Utils::convert_to_map(response.body, {
|
48
47
|
:amount => nil,
|
49
48
|
:number => "authorisationNumber",
|
50
|
-
:message =>
|
51
|
-
:return_code =>
|
52
|
-
:status =>
|
49
|
+
:message => 'message',
|
50
|
+
:return_code => 'returnCode',
|
51
|
+
:status => 'status',
|
53
52
|
:transaction_id => "transactionId"
|
54
53
|
})
|
55
54
|
end
|
@@ -70,9 +69,9 @@ module Braspag
|
|
70
69
|
Utils::convert_to_map(response.body, {
|
71
70
|
:amount => nil,
|
72
71
|
:number => "authorisationNumber",
|
73
|
-
:message =>
|
74
|
-
:return_code =>
|
75
|
-
:status =>
|
72
|
+
:message => 'message',
|
73
|
+
:return_code => 'returnCode',
|
74
|
+
:status => 'status',
|
76
75
|
:transaction_id => "transactionId"
|
77
76
|
})
|
78
77
|
end
|
@@ -94,9 +93,9 @@ module Braspag
|
|
94
93
|
Utils::convert_to_map(response.body, {
|
95
94
|
:amount => nil,
|
96
95
|
:number => "authorisationNumber",
|
97
|
-
:message =>
|
98
|
-
:return_code =>
|
99
|
-
:status =>
|
96
|
+
:message => 'message',
|
97
|
+
:return_code => 'returnCode',
|
98
|
+
:status => 'status',
|
100
99
|
:transaction_id => "transactionId"
|
101
100
|
})
|
102
101
|
end
|
@@ -117,33 +116,9 @@ module Braspag
|
|
117
116
|
Utils::convert_to_map(response.body, {
|
118
117
|
:amount => nil,
|
119
118
|
:number => "authorisationNumber",
|
120
|
-
:message =>
|
121
|
-
:return_code =>
|
122
|
-
:status =>
|
123
|
-
:transaction_id => "transactionId"
|
124
|
-
})
|
125
|
-
end
|
126
|
-
|
127
|
-
def self.partial_void(order_id, amount)
|
128
|
-
connection = Braspag::Connection.instance
|
129
|
-
merchant_id = connection.merchant_id
|
130
|
-
|
131
|
-
raise InvalidOrderId unless self.valid_order_id?(order_id)
|
132
|
-
|
133
|
-
data = {
|
134
|
-
MAPPING[:order] => order_id,
|
135
|
-
MAPPING[:merchant_id] => merchant_id,
|
136
|
-
"amount" => Utils.convert_decimal_to_string(amount)
|
137
|
-
}
|
138
|
-
|
139
|
-
response = Braspag::Poster.new(self.partial_cancellation_url).do_post(:partial_void, data)
|
140
|
-
|
141
|
-
Utils::convert_to_map(response.body, {
|
142
|
-
:amount => "amount",
|
143
|
-
:order_id => "orderId",
|
144
|
-
:message => "message",
|
145
|
-
:return_code => "returnCode",
|
146
|
-
:status => "status",
|
119
|
+
:message => 'message',
|
120
|
+
:return_code => 'returnCode',
|
121
|
+
:status => 'status',
|
147
122
|
:transaction_id => "transactionId"
|
148
123
|
})
|
149
124
|
end
|
@@ -177,7 +152,7 @@ module Braspag
|
|
177
152
|
|
178
153
|
raise InvalidHolder if params[:holder].to_s.size < 1 || params[:holder].to_s.size > 100
|
179
154
|
|
180
|
-
matches = params[:expiration].to_s.match
|
155
|
+
matches = params[:expiration].to_s.match /^(\d{2})\/(\d{2,4})$/
|
181
156
|
raise InvalidExpirationDate unless matches
|
182
157
|
begin
|
183
158
|
year = matches[2].to_i
|
@@ -231,9 +206,5 @@ module Braspag
|
|
231
206
|
def self.cancellation_url
|
232
207
|
Braspag::Connection.instance.braspag_url + CANCELLATION_URI
|
233
208
|
end
|
234
|
-
|
235
|
-
def self.partial_cancellation_url
|
236
|
-
Braspag::Connection.instance.braspag_url + PARTIAL_CANCELLATION_URI
|
237
|
-
end
|
238
209
|
end
|
239
210
|
end
|
data/lib/baby-braspag/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -120,6 +120,46 @@ describe Braspag::Connection do
|
|
120
120
|
its(:protected_card_url) { should == protected_card_url }
|
121
121
|
end
|
122
122
|
|
123
|
+
describe "#production?" do
|
124
|
+
it "should return true when environment is production" do
|
125
|
+
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "production"
|
126
|
+
|
127
|
+
YAML.should_receive(:load_file)
|
128
|
+
.and_return(braspag_config)
|
129
|
+
|
130
|
+
Braspag::Connection.clone.instance.production?.should be_true
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should return false when environment is not production" do
|
134
|
+
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "homologation"
|
135
|
+
|
136
|
+
YAML.should_receive(:load_file)
|
137
|
+
.and_return(braspag_config)
|
138
|
+
|
139
|
+
Braspag::Connection.clone.instance.production?.should be_false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#homologation?" do
|
144
|
+
it "should return true when environment is homologation" do
|
145
|
+
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "homologation"
|
146
|
+
|
147
|
+
YAML.should_receive(:load_file)
|
148
|
+
.and_return(braspag_config)
|
149
|
+
|
150
|
+
Braspag::Connection.clone.instance.homologation?.should be_true
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should return false when environment is not homologation" do
|
154
|
+
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "production"
|
155
|
+
|
156
|
+
YAML.should_receive(:load_file)
|
157
|
+
.and_return(braspag_config)
|
158
|
+
|
159
|
+
Braspag::Connection.clone.instance.homologation?.should be_false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
123
163
|
describe "#braspag_url" do
|
124
164
|
context "when environment is homologation" do
|
125
165
|
it "should return the Braspag homologation url" do
|
data/spec/credit_card_spec.rb
CHANGED
@@ -296,73 +296,6 @@ describe Braspag::CreditCard do
|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
299
|
-
describe ".partial_void" do
|
300
|
-
let(:partial_cancellation_url) { "http://foo.bar/bar/baz" }
|
301
|
-
let(:order_id) { "um id qualquer" }
|
302
|
-
|
303
|
-
before do
|
304
|
-
@connection.should_receive(:merchant_id)
|
305
|
-
end
|
306
|
-
|
307
|
-
context "invalid order id" do
|
308
|
-
it "should raise an error" do
|
309
|
-
Braspag::CreditCard.should_receive(:valid_order_id?)
|
310
|
-
.with(order_id)
|
311
|
-
.and_return(false)
|
312
|
-
|
313
|
-
expect {
|
314
|
-
Braspag::CreditCard.partial_void(order_id, 2.0)
|
315
|
-
}.to raise_error(Braspag::InvalidOrderId)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
context "valid order id" do
|
320
|
-
let(:valid_xml) do
|
321
|
-
<<-EOXML
|
322
|
-
<?xml version="1.0" encoding="utf-8"?>
|
323
|
-
<PagadorReturn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
324
|
-
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
325
|
-
xmlns="https://www.pagador.com.br/webservice/pagador">
|
326
|
-
<amount>2</amount>
|
327
|
-
<orderId>1</orderId>
|
328
|
-
<message>Approved</message>
|
329
|
-
<returnCode>0</returnCode>
|
330
|
-
<status>0</status>
|
331
|
-
<transactionId>123</transactionId>
|
332
|
-
</PagadorReturn>
|
333
|
-
EOXML
|
334
|
-
end
|
335
|
-
|
336
|
-
let(:request) { OpenStruct.new :url => partial_cancellation_url }
|
337
|
-
|
338
|
-
before do
|
339
|
-
Braspag::CreditCard.should_receive(:partial_cancellation_url)
|
340
|
-
.and_return(partial_cancellation_url)
|
341
|
-
|
342
|
-
::HTTPI::Request.should_receive(:new).with(partial_cancellation_url).and_return(request)
|
343
|
-
::HTTPI.should_receive(:post).with(request).and_return(mock(:body => valid_xml))
|
344
|
-
end
|
345
|
-
|
346
|
-
it "should return a Hash" do
|
347
|
-
response = Braspag::CreditCard.partial_void("order id qualquer", 2.0)
|
348
|
-
response.should be_kind_of Hash
|
349
|
-
response.should == {
|
350
|
-
:amount => "2",
|
351
|
-
:order_id => "1",
|
352
|
-
:message => "Approved",
|
353
|
-
:return_code => "0",
|
354
|
-
:status => "0",
|
355
|
-
:transaction_id => "123"
|
356
|
-
}
|
357
|
-
end
|
358
|
-
|
359
|
-
it "should post void info" do
|
360
|
-
Braspag::CreditCard.partial_void("order id qualquer", 2.0)
|
361
|
-
request.body.should == {"order"=>"order id qualquer", "merchantId"=>"um id qualquer", "amount" =>"2,00"}
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
299
|
describe ".info" do
|
367
300
|
let(:info_url) { "http://braspag/bla" }
|
368
301
|
|