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/order_spec.rb
CHANGED
@@ -1,105 +1,118 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
describe Braspag::Order do
|
5
|
-
let
|
6
|
-
let
|
7
|
-
|
8
|
-
describe "#status" do
|
9
|
-
it "should raise an error when no order_id is given" do
|
10
|
-
expect {
|
11
|
-
Braspag::Order.status(nil)
|
12
|
-
}.to raise_error(Braspag::InvalidOrderId)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should raise an error when order_id is empty" do
|
16
|
-
expect {
|
17
|
-
Braspag::Order.status("")
|
18
|
-
}.to raise_error(Braspag::InvalidOrderId)
|
19
|
-
end
|
5
|
+
let(:braspag_homologation_url) { "https://homologacao.pagador.com.br" }
|
6
|
+
let(:braspag_production_url) { "https://transaction.pagador.com.br" }
|
7
|
+
let(:merchant_id) { "um id qualquer" }
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
9
|
+
before do
|
10
|
+
@connection = mock(:merchant_id => merchant_id)
|
11
|
+
Braspag::Connection.stub(:instance => @connection)
|
12
|
+
end
|
26
13
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
14
|
+
describe ".status" do
|
15
|
+
let(:order_id) { "um order id qualquer" }
|
16
|
+
let(:status_url) { "http://foo.com/bar/baz/assererre" }
|
17
|
+
|
18
|
+
context "with invalid order id" do
|
19
|
+
let(:invalid_xml) do
|
20
|
+
<<-EOXML
|
21
|
+
<?xml version="1.0" encoding="utf-8"?>
|
22
|
+
<DadosBoleto xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
23
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
24
|
+
xsi:nil="true"
|
25
|
+
xmlns="http://www.pagador.com.br/" />
|
26
|
+
EOXML
|
27
|
+
end
|
35
28
|
|
36
|
-
|
37
|
-
:
|
29
|
+
it "should raise an error when order id is not valid" do
|
30
|
+
Braspag::PaymentMethod.should_receive(:valid_order_id?)
|
31
|
+
.with(order_id)
|
32
|
+
.and_return(false)
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
expect {
|
35
|
+
Braspag::Order.status(order_id)
|
36
|
+
}.to raise_error(Braspag::InvalidOrderId)
|
37
|
+
end
|
42
38
|
|
39
|
+
it "should raise an error when Braspag returns an invalid xml" do
|
40
|
+
FakeWeb.register_uri(:post, status_url, :body => invalid_xml)
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
}.to raise_error(Braspag::Order::InvalidData)
|
42
|
+
Braspag::Order.should_receive(:status_url)
|
43
|
+
.and_return(status_url)
|
47
44
|
|
48
|
-
|
45
|
+
expect {
|
46
|
+
Braspag::Order.status(order_id)
|
47
|
+
}.to raise_error(Braspag::Order::InvalidData)
|
48
|
+
end
|
49
49
|
end
|
50
50
|
|
51
|
-
context "with
|
52
|
-
|
53
|
-
|
54
|
-
xml =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
</DadosPedido>
|
51
|
+
context "with valid order id" do
|
52
|
+
let(:valid_xml) do
|
53
|
+
<<-EOXML
|
54
|
+
<?xml version="1.0" encoding="utf-8"?>
|
55
|
+
<DadosPedido xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
56
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
57
|
+
xmlns="http://www.pagador.com.br/">
|
58
|
+
<CodigoAutorizacao>885796</CodigoAutorizacao>
|
59
|
+
<CodigoPagamento>18</CodigoPagamento>
|
60
|
+
<FormaPagamento>American Express 2P</FormaPagamento>
|
61
|
+
<NumeroParcelas>1</NumeroParcelas>
|
62
|
+
<Status>3</Status>
|
63
|
+
<Valor>0.01</Valor>
|
64
|
+
<DataPagamento>7/8/2011 1:19:38 PM</DataPagamento>
|
65
|
+
<DataPedido>7/8/2011 1:06:06 PM</DataPedido>
|
66
|
+
<TransId>398591</TransId>
|
67
|
+
<BraspagTid>5a1d4463-1d11-4571-a877-763aba0ef7ff</BraspagTid>
|
68
|
+
</DadosPedido>
|
70
69
|
EOXML
|
70
|
+
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
FakeWeb.clean_registry
|
76
|
-
order_info
|
77
|
-
}
|
72
|
+
before do
|
73
|
+
Braspag::Order.should_receive(:status_url)
|
74
|
+
.and_return(status_url)
|
78
75
|
|
79
|
-
|
80
|
-
|
76
|
+
FakeWeb.register_uri(:post, status_url, :body => valid_xml)
|
77
|
+
@response = Braspag::Order.status(order_id)
|
81
78
|
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
order_info[key].should == value
|
101
|
-
end
|
80
|
+
it "should return a Hash" do
|
81
|
+
@response.should be_kind_of Hash
|
82
|
+
@response.should == {
|
83
|
+
:authorization => "885796",
|
84
|
+
:error_code => nil,
|
85
|
+
:error_message => nil,
|
86
|
+
:payment_method => "18",
|
87
|
+
:payment_method_name => "American Express 2P",
|
88
|
+
:installments => "1",
|
89
|
+
:status => "3",
|
90
|
+
:amount => "0.01",
|
91
|
+
:cancelled_at => nil,
|
92
|
+
:paid_at => "7/8/2011 1:19:38 PM",
|
93
|
+
:order_date => "7/8/2011 1:06:06 PM",
|
94
|
+
:transaction_id => "398591",
|
95
|
+
:tid => "5a1d4463-1d11-4571-a877-763aba0ef7ff"
|
96
|
+
}
|
102
97
|
end
|
103
98
|
end
|
104
99
|
end
|
100
|
+
|
101
|
+
describe ".status_url" do
|
102
|
+
it "should return the correct info url when connection environment is homologation" do
|
103
|
+
@connection.stub(:braspag_url => braspag_homologation_url)
|
104
|
+
@connection.should_receive(:production?)
|
105
|
+
.and_return(false)
|
106
|
+
|
107
|
+
Braspag::Order.status_url.should == "#{braspag_homologation_url}/pagador/webservice/pedido.asmx/GetDadosPedido"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return the correct info url when connection environment is production" do
|
111
|
+
@connection.stub(:braspag_url => braspag_production_url)
|
112
|
+
@connection.should_receive(:production?)
|
113
|
+
.and_return(true)
|
114
|
+
|
115
|
+
Braspag::Order.status_url.should == "#{braspag_production_url}/webservices/pagador/pedido.asmx/GetDadosPedido"
|
116
|
+
end
|
117
|
+
end
|
105
118
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/utils_spec.rb
CHANGED
@@ -1,26 +1,47 @@
|
|
1
|
-
#encoding: utf-8
|
2
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
2
|
|
4
3
|
describe Braspag::Utils do
|
5
|
-
|
6
|
-
|
4
|
+
describe ".convert_decimal_to_string" do
|
5
|
+
it "should convert decimal to string with comma as decimal separator" do
|
6
|
+
Braspag::Utils.convert_decimal_to_string(10).should == "10,00"
|
7
|
+
Braspag::Utils.convert_decimal_to_string(1).should == "1,00"
|
8
|
+
Braspag::Utils.convert_decimal_to_string(0.1).should == "0,10"
|
9
|
+
Braspag::Utils.convert_decimal_to_string(0.01).should == "0,01"
|
10
|
+
Braspag::Utils.convert_decimal_to_string(9.99999).should == "10,00" # round up
|
11
|
+
Braspag::Utils.convert_decimal_to_string(10.9).should == "10,90"
|
12
|
+
Braspag::Utils.convert_decimal_to_string(9.1111).should == "9,11"
|
13
|
+
end
|
7
14
|
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
describe ".convert_to_map" do
|
17
|
+
let(:document) do
|
18
|
+
<<-XML
|
19
|
+
<root>
|
20
|
+
<foo>blabla</foo>
|
21
|
+
<bar>bleble</bar>
|
22
|
+
<baz></baz>
|
23
|
+
</root>
|
24
|
+
XML
|
25
|
+
end
|
26
|
+
|
27
|
+
context "basic document and keys" do
|
28
|
+
it "should return a Hash" do
|
29
|
+
keys = { :foo => nil, :meu_elemento => "bar", :outro_elemento => "baz" }
|
30
|
+
expected = { :foo => "blabla", :meu_elemento => "bleble", :outro_elemento => nil }
|
31
|
+
|
32
|
+
Braspag::Utils::convert_to_map(document, keys).should == expected
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "keys with a Proc" do
|
37
|
+
it "should return a Hash" do
|
38
|
+
proc = Proc.new { "value returned by Proc" }
|
39
|
+
|
40
|
+
keys = { :foo => proc, :meu_elemento => "bar", :outro_elemento => "baz" }
|
41
|
+
expected = { :foo => "value returned by Proc", :meu_elemento => "bleble", :outro_elemento => nil }
|
20
42
|
|
21
|
-
|
22
|
-
|
43
|
+
Braspag::Utils::convert_to_map(document, keys).should == expected
|
44
|
+
end
|
45
|
+
end
|
23
46
|
end
|
24
|
-
|
25
|
-
pending "convert_to_map"
|
26
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbraspag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,11 +14,11 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2012-01-
|
17
|
+
date: 2012-01-09 00:00:00.000000000Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: cs-httpi
|
21
|
-
requirement: &
|
21
|
+
requirement: &70228358717520 !ruby/object:Gem::Requirement
|
22
22
|
none: false
|
23
23
|
requirements:
|
24
24
|
- - ! '>='
|
@@ -26,10 +26,10 @@ dependencies:
|
|
26
26
|
version: 0.9.5.2
|
27
27
|
type: :runtime
|
28
28
|
prerelease: false
|
29
|
-
version_requirements: *
|
29
|
+
version_requirements: *70228358717520
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: json
|
32
|
-
requirement: &
|
32
|
+
requirement: &70228358716620 !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
@@ -37,21 +37,21 @@ dependencies:
|
|
37
37
|
version: 1.6.1
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
|
-
version_requirements: *
|
40
|
+
version_requirements: *70228358716620
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nokogiri
|
43
|
-
requirement: &
|
43
|
+
requirement: &70228358715680 !ruby/object:Gem::Requirement
|
44
44
|
none: false
|
45
45
|
requirements:
|
46
46
|
- - ! '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.
|
48
|
+
version: 1.4.7
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
|
-
version_requirements: *
|
51
|
+
version_requirements: *70228358715680
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
53
|
name: rake
|
54
|
-
requirement: &
|
54
|
+
requirement: &70228358715120 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
57
|
- - ! '>='
|
@@ -59,10 +59,10 @@ dependencies:
|
|
59
59
|
version: '0'
|
60
60
|
type: :development
|
61
61
|
prerelease: false
|
62
|
-
version_requirements: *
|
62
|
+
version_requirements: *70228358715120
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: rspec
|
65
|
-
requirement: &
|
65
|
+
requirement: &70228358714000 !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
67
67
|
requirements:
|
68
68
|
- - ! '>='
|
@@ -70,10 +70,10 @@ dependencies:
|
|
70
70
|
version: '0'
|
71
71
|
type: :development
|
72
72
|
prerelease: false
|
73
|
-
version_requirements: *
|
73
|
+
version_requirements: *70228358714000
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: fakeweb
|
76
|
-
requirement: &
|
76
|
+
requirement: &70228358713380 !ruby/object:Gem::Requirement
|
77
77
|
none: false
|
78
78
|
requirements:
|
79
79
|
- - ! '>='
|
@@ -81,10 +81,10 @@ dependencies:
|
|
81
81
|
version: '0'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
|
-
version_requirements: *
|
84
|
+
version_requirements: *70228358713380
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: shoulda-matchers
|
87
|
-
requirement: &
|
87
|
+
requirement: &70228358712540 !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
90
90
|
- - ! '>='
|
@@ -92,10 +92,10 @@ dependencies:
|
|
92
92
|
version: '0'
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
|
-
version_requirements: *
|
95
|
+
version_requirements: *70228358712540
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: guard-rspec
|
98
|
-
requirement: &
|
98
|
+
requirement: &70228358711900 !ruby/object:Gem::Requirement
|
99
99
|
none: false
|
100
100
|
requirements:
|
101
101
|
- - ! '>='
|
@@ -103,10 +103,10 @@ dependencies:
|
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
|
-
version_requirements: *
|
106
|
+
version_requirements: *70228358711900
|
107
107
|
- !ruby/object:Gem::Dependency
|
108
108
|
name: guard-bundler
|
109
|
-
requirement: &
|
109
|
+
requirement: &70228358711220 !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
112
112
|
- - ! '>='
|
@@ -114,10 +114,10 @@ dependencies:
|
|
114
114
|
version: '0'
|
115
115
|
type: :development
|
116
116
|
prerelease: false
|
117
|
-
version_requirements: *
|
117
|
+
version_requirements: *70228358711220
|
118
118
|
- !ruby/object:Gem::Dependency
|
119
119
|
name: ruby-debug19
|
120
|
-
requirement: &
|
120
|
+
requirement: &70228358710580 !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
123
|
- - ! '>='
|
@@ -125,7 +125,7 @@ dependencies:
|
|
125
125
|
version: '0'
|
126
126
|
type: :development
|
127
127
|
prerelease: false
|
128
|
-
version_requirements: *
|
128
|
+
version_requirements: *70228358710580
|
129
129
|
description: rbraspag gem to use Braspag gateway
|
130
130
|
email:
|
131
131
|
- tinorj@gmail.com
|
@@ -141,7 +141,6 @@ files:
|
|
141
141
|
- .gitignore
|
142
142
|
- .rspec
|
143
143
|
- Gemfile
|
144
|
-
- Gemfile.lock
|
145
144
|
- Guardfile
|
146
145
|
- README.md
|
147
146
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rbraspag (0.0.18)
|
5
|
-
cs-httpi (>= 0.9.5.2)
|
6
|
-
json (>= 1.6.1)
|
7
|
-
nokogiri (>= 1.5.0)
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: http://rubygems.org/
|
11
|
-
specs:
|
12
|
-
archive-tar-minitar (0.5.2)
|
13
|
-
columnize (0.3.3)
|
14
|
-
cs-httpi (0.9.5.2)
|
15
|
-
rack
|
16
|
-
diff-lcs (1.1.2)
|
17
|
-
fakeweb (1.3.0)
|
18
|
-
guard (0.4.2)
|
19
|
-
thor (~> 0.14.6)
|
20
|
-
guard-bundler (0.1.3)
|
21
|
-
bundler (>= 1.0.0)
|
22
|
-
guard (>= 0.2.2)
|
23
|
-
guard-rspec (0.4.0)
|
24
|
-
guard (>= 0.4.0)
|
25
|
-
json (1.6.4)
|
26
|
-
linecache19 (0.5.12)
|
27
|
-
ruby_core_source (>= 0.1.4)
|
28
|
-
nokogiri (1.5.0)
|
29
|
-
rack (1.4.0)
|
30
|
-
rake (0.9.2)
|
31
|
-
rspec (2.6.0)
|
32
|
-
rspec-core (~> 2.6.0)
|
33
|
-
rspec-expectations (~> 2.6.0)
|
34
|
-
rspec-mocks (~> 2.6.0)
|
35
|
-
rspec-core (2.6.4)
|
36
|
-
rspec-expectations (2.6.0)
|
37
|
-
diff-lcs (~> 1.1.2)
|
38
|
-
rspec-mocks (2.6.0)
|
39
|
-
ruby-debug-base19 (0.11.25)
|
40
|
-
columnize (>= 0.3.1)
|
41
|
-
linecache19 (>= 0.5.11)
|
42
|
-
ruby_core_source (>= 0.1.4)
|
43
|
-
ruby-debug19 (0.11.6)
|
44
|
-
columnize (>= 0.3.1)
|
45
|
-
linecache19 (>= 0.5.11)
|
46
|
-
ruby-debug-base19 (>= 0.11.19)
|
47
|
-
ruby_core_source (0.1.5)
|
48
|
-
archive-tar-minitar (>= 0.5.2)
|
49
|
-
shoulda-matchers (1.0.0.beta2)
|
50
|
-
thor (0.14.6)
|
51
|
-
|
52
|
-
PLATFORMS
|
53
|
-
ruby
|
54
|
-
|
55
|
-
DEPENDENCIES
|
56
|
-
fakeweb
|
57
|
-
guard-bundler
|
58
|
-
guard-rspec
|
59
|
-
rake
|
60
|
-
rbraspag!
|
61
|
-
rspec
|
62
|
-
ruby-debug19
|
63
|
-
shoulda-matchers
|