baby-braspag 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/baby-braspag/connection.rb +15 -10
- data/lib/baby-braspag/credit_card.rb +43 -14
- data/lib/baby-braspag/version.rb +1 -1
- data/spec/connection_spec.rb +11 -35
- data/spec/credit_card_spec.rb +67 -0
- metadata +4 -9
@@ -4,7 +4,7 @@ module Braspag
|
|
4
4
|
|
5
5
|
PRODUCTION_URL = "https://transaction.pagador.com.br"
|
6
6
|
HOMOLOGATION_URL = "https://homologacao.pagador.com.br"
|
7
|
-
|
7
|
+
|
8
8
|
PROTECTED_CARD_PRODUCTION_URL = "https://cartaoprotegido.braspag.com.br/Services"
|
9
9
|
PROTECTED_CARD_HOMOLOGATION_URL = "https://homologacao.braspag.com.br/services/testenvironment"
|
10
10
|
|
@@ -20,18 +20,23 @@ module Braspag
|
|
20
20
|
|
21
21
|
@crypto_key = @options["crypto_key"]
|
22
22
|
@crypto_url = @options["crypto_url"]
|
23
|
-
@environment = @options["environment"]
|
24
|
-
|
25
|
-
@braspag_url = self.production? ? PRODUCTION_URL : HOMOLOGATION_URL
|
26
|
-
@protected_card_url = self.production? ? PROTECTED_CARD_PRODUCTION_URL : PROTECTED_CARD_HOMOLOGATION_URL
|
27
|
-
end
|
23
|
+
@environment = @options["environment"]
|
28
24
|
|
29
|
-
|
30
|
-
@
|
25
|
+
@braspag_url = @options["pagador_url"] || default_env_configuration[:pagador][@environment]
|
26
|
+
@protected_card_url = @options["protected_card_url"] || default_env_configuration[:protected_card][@environment]
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
34
|
-
|
29
|
+
def default_env_configuration
|
30
|
+
{
|
31
|
+
:pagador => {
|
32
|
+
"production" => PRODUCTION_URL,
|
33
|
+
"homologation" => HOMOLOGATION_URL
|
34
|
+
},
|
35
|
+
:protected_card => {
|
36
|
+
"production" => PROTECTED_CARD_PRODUCTION_URL,
|
37
|
+
"homologation" => PROTECTED_CARD_HOMOLOGATION_URL
|
38
|
+
}
|
39
|
+
}
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
@@ -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,6 +20,7 @@ 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"
|
23
24
|
PRODUCTION_INFO_URI = "/webservices/pagador/pedido.asmx/GetDadosCartao"
|
24
25
|
HOMOLOGATION_INFO_URI = "/pagador/webservice/pedido.asmx/GetDadosCartao"
|
25
26
|
|
@@ -46,9 +47,9 @@ module Braspag
|
|
46
47
|
Utils::convert_to_map(response.body, {
|
47
48
|
:amount => nil,
|
48
49
|
:number => "authorisationNumber",
|
49
|
-
:message =>
|
50
|
-
:return_code =>
|
51
|
-
:status =>
|
50
|
+
:message => "message",
|
51
|
+
:return_code => "returnCode",
|
52
|
+
:status => "status",
|
52
53
|
:transaction_id => "transactionId"
|
53
54
|
})
|
54
55
|
end
|
@@ -69,9 +70,9 @@ module Braspag
|
|
69
70
|
Utils::convert_to_map(response.body, {
|
70
71
|
:amount => nil,
|
71
72
|
:number => "authorisationNumber",
|
72
|
-
:message =>
|
73
|
-
:return_code =>
|
74
|
-
:status =>
|
73
|
+
:message => "message",
|
74
|
+
:return_code => "returnCode",
|
75
|
+
:status => "status",
|
75
76
|
:transaction_id => "transactionId"
|
76
77
|
})
|
77
78
|
end
|
@@ -93,9 +94,9 @@ module Braspag
|
|
93
94
|
Utils::convert_to_map(response.body, {
|
94
95
|
:amount => nil,
|
95
96
|
:number => "authorisationNumber",
|
96
|
-
:message =>
|
97
|
-
:return_code =>
|
98
|
-
:status =>
|
97
|
+
:message => "message",
|
98
|
+
:return_code => "returnCode",
|
99
|
+
:status => "status",
|
99
100
|
:transaction_id => "transactionId"
|
100
101
|
})
|
101
102
|
end
|
@@ -116,9 +117,33 @@ module Braspag
|
|
116
117
|
Utils::convert_to_map(response.body, {
|
117
118
|
:amount => nil,
|
118
119
|
:number => "authorisationNumber",
|
119
|
-
:message =>
|
120
|
-
:return_code =>
|
121
|
-
:status =>
|
120
|
+
:message => "message",
|
121
|
+
:return_code => "returnCode",
|
122
|
+
:status => "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",
|
122
147
|
:transaction_id => "transactionId"
|
123
148
|
})
|
124
149
|
end
|
@@ -152,7 +177,7 @@ module Braspag
|
|
152
177
|
|
153
178
|
raise InvalidHolder if params[:holder].to_s.size < 1 || params[:holder].to_s.size > 100
|
154
179
|
|
155
|
-
matches = params[:expiration].to_s.match
|
180
|
+
matches = params[:expiration].to_s.match(/^(\d{2})\/(\d{2,4})$/)
|
156
181
|
raise InvalidExpirationDate unless matches
|
157
182
|
begin
|
158
183
|
year = matches[2].to_i
|
@@ -206,5 +231,9 @@ module Braspag
|
|
206
231
|
def self.cancellation_url
|
207
232
|
Braspag::Connection.instance.braspag_url + CANCELLATION_URI
|
208
233
|
end
|
234
|
+
|
235
|
+
def self.partial_cancellation_url
|
236
|
+
Braspag::Connection.instance.braspag_url + PARTIAL_CANCELLATION_URI
|
237
|
+
end
|
209
238
|
end
|
210
239
|
end
|
data/lib/baby-braspag/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -104,44 +104,20 @@ describe Braspag::Connection do
|
|
104
104
|
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
context "when there is pagador_url and protected_card_url on configuration" do
|
108
|
+
let(:pagador_url) { "http://foo.bar" }
|
109
|
+
let(:protected_card_url) { "http://bar.foo" }
|
110
|
+
|
111
|
+
before do
|
112
|
+
braspag_config[ENV["BRASPAG_ENV"]]["pagador_url"] = pagador_url
|
113
|
+
braspag_config[ENV["BRASPAG_ENV"]]["protected_card_url"] = protected_card_url
|
114
|
+
YAML.should_receive(:load_file).and_return(braspag_config)
|
115
115
|
end
|
116
116
|
|
117
|
-
|
118
|
-
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "homologation"
|
119
|
-
|
120
|
-
YAML.should_receive(:load_file)
|
121
|
-
.and_return(braspag_config)
|
122
|
-
|
123
|
-
Braspag::Connection.clone.instance.production?.should be_false
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#homologation?" do
|
128
|
-
it "should return true when environment is homologation" do
|
129
|
-
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "homologation"
|
117
|
+
subject { Braspag::Connection.clone.instance }
|
130
118
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
Braspag::Connection.clone.instance.homologation?.should be_true
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should return false when environment is not homologation" do
|
138
|
-
braspag_config[ENV["BRASPAG_ENV"]]["environment"] = "production"
|
139
|
-
|
140
|
-
YAML.should_receive(:load_file)
|
141
|
-
.and_return(braspag_config)
|
142
|
-
|
143
|
-
Braspag::Connection.clone.instance.homologation?.should be_false
|
144
|
-
end
|
119
|
+
its(:braspag_url) { should == pagador_url }
|
120
|
+
its(:protected_card_url) { should == protected_card_url }
|
145
121
|
end
|
146
122
|
|
147
123
|
describe "#braspag_url" do
|
data/spec/credit_card_spec.rb
CHANGED
@@ -296,6 +296,73 @@ 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
|
+
|
299
366
|
describe ".info" do
|
300
367
|
let(:info_url) { "http://braspag/bla" }
|
301
368
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baby-braspag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpi
|
@@ -242,21 +242,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
242
242
|
- - ! '>='
|
243
243
|
- !ruby/object:Gem::Version
|
244
244
|
version: '0'
|
245
|
-
segments:
|
246
|
-
- 0
|
247
|
-
hash: -959238660354841941
|
248
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
246
|
none: false
|
250
247
|
requirements:
|
251
248
|
- - ! '>='
|
252
249
|
- !ruby/object:Gem::Version
|
253
250
|
version: '0'
|
254
|
-
segments:
|
255
|
-
- 0
|
256
|
-
hash: -959238660354841941
|
257
251
|
requirements: []
|
258
252
|
rubyforge_project: baby-braspag
|
259
|
-
rubygems_version: 1.8.
|
253
|
+
rubygems_version: 1.8.25
|
260
254
|
signing_key:
|
261
255
|
specification_version: 3
|
262
256
|
summary: baby braspag gem to use Braspag gateway
|
@@ -272,3 +266,4 @@ test_files:
|
|
272
266
|
- spec/protected_credit_card_spec.rb
|
273
267
|
- spec/spec_helper.rb
|
274
268
|
- spec/utils_spec.rb
|
269
|
+
has_rdoc:
|