rbraspag 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/rbraspag/eft.rb +58 -41
- data/lib/rbraspag/version.rb +1 -1
- data/spec/bill_spec.rb +1 -1
- data/spec/eft_spec.rb +54 -50
- metadata +19 -19
data/Gemfile.lock
CHANGED
data/lib/rbraspag/eft.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Braspag
|
2
2
|
class Eft
|
3
|
+
PAYMENT_METHOD = {
|
4
|
+
:bradesco => "11",
|
5
|
+
}
|
6
|
+
|
3
7
|
MAPPING = {
|
4
8
|
:merchant_id => "Id_Loja",
|
5
9
|
:order_id => "VendaId",
|
@@ -18,6 +22,11 @@ module Braspag
|
|
18
22
|
@params = params
|
19
23
|
@params[:merchant_id] = connection.merchant_id
|
20
24
|
@crypto_strategy = crypto_strategy
|
25
|
+
|
26
|
+
if @params[:amount] && !@params[:amount].is_a?(BigDecimal)
|
27
|
+
@params[:amount] = BigDecimal.new(@params[:amount].to_s)
|
28
|
+
end
|
29
|
+
|
21
30
|
ok?
|
22
31
|
end
|
23
32
|
|
@@ -48,49 +57,57 @@ module Braspag
|
|
48
57
|
raise InvalidHasInterest unless (@params[:has_interest].is_a?(TrueClass) || @params[:has_interest].is_a?(FalseClass))
|
49
58
|
end
|
50
59
|
|
51
|
-
|
52
60
|
true
|
53
61
|
end
|
54
|
-
|
55
|
-
def generate
|
56
|
-
data = {}
|
57
|
-
@params.each {|name, value|
|
58
|
-
if MAPPING[name].nil?
|
59
|
-
data[name] = value
|
60
|
-
else
|
61
|
-
data[MAPPING[name]] = value
|
62
|
-
end
|
63
|
-
}
|
64
|
-
|
65
|
-
html = "<form id=\"form_tef_#{@params[:order_id]}\" name=\"form_tef_#{@params[:order_id]}\" action=\"#{self.uri}\" method=\"post\">\n"
|
66
|
-
|
67
|
-
if @crypto_strategy.nil?
|
68
|
-
data.each do |key, value|
|
69
|
-
html.concat "<input type=\"text\" name=\"#{key}\" value=\"#{value}\" />\n"
|
70
|
-
end
|
71
|
-
else
|
72
|
-
data.delete("Id_Loja")
|
73
|
-
html.concat "<input type=\"text\" name=\"crypt\" value=\"#{@crypto_strategy.encrypt(data)}\" />\n"
|
74
|
-
html.concat "<input type=\"text\" name=\"Id_Loja\" value=\"#{@params[:merchant_id]}\" />\n"
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
html.concat <<-EOHTML
|
79
|
-
</form>
|
80
|
-
<script type="text/javascript" charset="utf-8">
|
81
|
-
document.forms["form_tef_#{@params[:order_id]}"].submit();
|
82
|
-
</script>
|
83
|
-
EOHTML
|
84
|
-
|
85
|
-
html
|
86
|
-
end
|
87
|
-
|
88
|
-
protected
|
89
|
-
|
90
|
-
def uri
|
91
|
-
"#{@connection.base_url}/pagador/passthru.asp"
|
92
|
-
end
|
93
|
-
|
94
62
|
|
63
|
+
def generate
|
64
|
+
data = create_data_from_params
|
65
|
+
|
66
|
+
html = "<form id=\"form_tef_#{@params[:order_id]}\" name=\"form_tef_#{@params[:order_id]}\" action=\"#{self.uri}\" method=\"post\">\n"
|
67
|
+
|
68
|
+
if @crypto_strategy.nil?
|
69
|
+
data.each do |key, value|
|
70
|
+
html.concat " <input type=\"text\" name=\"#{key}\" value=\"#{value}\" />\n"
|
71
|
+
end
|
72
|
+
else
|
73
|
+
data.delete("Id_Loja")
|
74
|
+
html.concat " <input type=\"text\" name=\"crypt\" value=\"#{@crypto_strategy.encrypt(data)}\" />\n"
|
75
|
+
html.concat " <input type=\"text\" name=\"Id_Loja\" value=\"#{@params[:merchant_id]}\" />\n"
|
76
|
+
end
|
77
|
+
|
78
|
+
html.concat <<-EOHTML
|
79
|
+
</form>
|
80
|
+
<script type="text/javascript" charset="utf-8">
|
81
|
+
document.forms["form_tef_#{@params[:order_id]}"].submit();
|
82
|
+
</script>
|
83
|
+
EOHTML
|
84
|
+
|
85
|
+
html
|
86
|
+
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
def create_data_from_params
|
90
|
+
MAPPING.inject({}) do |memo, k|
|
91
|
+
if k[0] == :payment_method
|
92
|
+
memo[k[1]] = PAYMENT_METHOD[@params[:payment_method]]
|
93
|
+
elsif k[0] == :amount
|
94
|
+
memo[k[1]] = convert_decimal_to_string(@params[:amount])
|
95
|
+
else
|
96
|
+
memo[k[1]] = @params[k[0]] || "";
|
97
|
+
end
|
98
|
+
|
99
|
+
memo
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def convert_decimal_to_string(value)
|
104
|
+
cents = "0#{((value - value.to_i) * 100).to_i}".slice(-2,2)
|
105
|
+
integer = (value - (value - value.to_i)).to_i
|
106
|
+
"#{integer},#{cents}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def uri
|
110
|
+
"#{@connection.base_url}/pagador/passthru.asp"
|
111
|
+
end
|
95
112
|
end
|
96
113
|
end
|
data/lib/rbraspag/version.rb
CHANGED
data/spec/bill_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe Braspag::Bill do
|
|
17
17
|
it "should raise an error when :order_id is not present" do
|
18
18
|
expect {
|
19
19
|
Braspag::Bill.new(connection, {
|
20
|
-
:amount => "
|
20
|
+
:amount => "100.00",
|
21
21
|
:payment_method => :bradesco
|
22
22
|
})
|
23
23
|
}.to raise_error(Braspag::IncompleteParams)
|
data/spec/eft_spec.rb
CHANGED
@@ -18,8 +18,8 @@ describe Braspag::Eft do
|
|
18
18
|
it "should raise an error when :order_id is not present" do
|
19
19
|
expect {
|
20
20
|
Braspag::Eft.new(connection, {
|
21
|
-
:amount => "
|
22
|
-
:payment_method =>
|
21
|
+
:amount => "100.00",
|
22
|
+
:payment_method => :bradesco
|
23
23
|
})
|
24
24
|
}.to raise_error(Braspag::IncompleteParams)
|
25
25
|
end
|
@@ -28,7 +28,7 @@ describe Braspag::Eft do
|
|
28
28
|
expect {
|
29
29
|
Braspag::Eft.new(connection, {
|
30
30
|
:order_id => "12",
|
31
|
-
:payment_method =>
|
31
|
+
:payment_method => :bradesco
|
32
32
|
})
|
33
33
|
}.to raise_error(Braspag::IncompleteParams)
|
34
34
|
end
|
@@ -37,7 +37,7 @@ describe Braspag::Eft do
|
|
37
37
|
expect {
|
38
38
|
Braspag::Eft.new(connection, {
|
39
39
|
:order_id => "13",
|
40
|
-
:amount => "
|
40
|
+
:amount => "120.00"
|
41
41
|
})
|
42
42
|
}.to raise_error(Braspag::IncompleteParams)
|
43
43
|
end
|
@@ -46,8 +46,8 @@ describe Braspag::Eft do
|
|
46
46
|
expect {
|
47
47
|
Braspag::Eft.new(connection, {
|
48
48
|
:order_id => "",
|
49
|
-
:amount => "
|
50
|
-
:payment_method =>
|
49
|
+
:amount => "123.00",
|
50
|
+
:payment_method => :bradesco
|
51
51
|
})
|
52
52
|
}.to raise_error(Braspag::InvalidOrderId)
|
53
53
|
end
|
@@ -56,8 +56,8 @@ describe Braspag::Eft do
|
|
56
56
|
expect {
|
57
57
|
Braspag::Eft.new(connection, {
|
58
58
|
:order_id => "1" * 51,
|
59
|
-
:amount => "
|
60
|
-
:payment_method =>
|
59
|
+
:amount => "12.00",
|
60
|
+
:payment_method => :bradesco
|
61
61
|
})
|
62
62
|
}.to raise_error(Braspag::InvalidOrderId)
|
63
63
|
end
|
@@ -66,8 +66,8 @@ describe Braspag::Eft do
|
|
66
66
|
expect {
|
67
67
|
Braspag::Eft.new(connection, {
|
68
68
|
:order_id => "102",
|
69
|
-
:amount => "
|
70
|
-
:payment_method =>
|
69
|
+
:amount => "42.00",
|
70
|
+
:payment_method => :bradesco,
|
71
71
|
:customer_name => ""
|
72
72
|
})
|
73
73
|
}.to raise_error(Braspag::InvalidCustomerName)
|
@@ -77,8 +77,8 @@ describe Braspag::Eft do
|
|
77
77
|
expect {
|
78
78
|
Braspag::Eft.new(connection, {
|
79
79
|
:order_id => "112",
|
80
|
-
:amount => "
|
81
|
-
:payment_method =>
|
80
|
+
:amount => "121.00",
|
81
|
+
:payment_method => :bradesco,
|
82
82
|
:customer_name => "A" * 256
|
83
83
|
})
|
84
84
|
}.to raise_error(Braspag::InvalidCustomerName)
|
@@ -88,8 +88,8 @@ describe Braspag::Eft do
|
|
88
88
|
expect {
|
89
89
|
Braspag::Eft.new(connection, {
|
90
90
|
:order_id => "23",
|
91
|
-
:amount => "
|
92
|
-
:payment_method =>
|
91
|
+
:amount => "251.00",
|
92
|
+
:payment_method => :bradesco,
|
93
93
|
:customer_id => "2" * 10
|
94
94
|
})
|
95
95
|
}.to raise_error(Braspag::InvalidCustomerId)
|
@@ -99,8 +99,8 @@ describe Braspag::Eft do
|
|
99
99
|
expect {
|
100
100
|
Braspag::Eft.new(connection, {
|
101
101
|
:order_id => "90",
|
102
|
-
:amount => "
|
103
|
-
:payment_method =>
|
102
|
+
:amount => "90.00",
|
103
|
+
:payment_method => :bradesco,
|
104
104
|
:customer_id => "3" * 19
|
105
105
|
})
|
106
106
|
}.to raise_error(Braspag::InvalidCustomerId)
|
@@ -110,8 +110,8 @@ describe Braspag::Eft do
|
|
110
110
|
expect {
|
111
111
|
Braspag::Eft.new(connection, {
|
112
112
|
:order_id => "900",
|
113
|
-
:amount => "
|
114
|
-
:payment_method =>
|
113
|
+
:amount => "92.00",
|
114
|
+
:payment_method => :bradesco,
|
115
115
|
:installments => ""
|
116
116
|
})
|
117
117
|
}.to raise_error(Braspag::InvalidInstallments)
|
@@ -121,8 +121,8 @@ describe Braspag::Eft do
|
|
121
121
|
expect {
|
122
122
|
Braspag::Eft.new(connection, {
|
123
123
|
:order_id => "91",
|
124
|
-
:amount => "
|
125
|
-
:payment_method =>
|
124
|
+
:amount => "80.00",
|
125
|
+
:payment_method => :bradesco,
|
126
126
|
:installments => "5" * 3
|
127
127
|
})
|
128
128
|
}.to raise_error(Braspag::InvalidInstallments)
|
@@ -132,8 +132,8 @@ describe Braspag::Eft do
|
|
132
132
|
expect {
|
133
133
|
Braspag::Eft.new(connection, {
|
134
134
|
:order_id => "91",
|
135
|
-
:amount => "
|
136
|
-
:payment_method =>
|
135
|
+
:amount => "80.00",
|
136
|
+
:payment_method => :bradesco,
|
137
137
|
:installments => "A" * 2
|
138
138
|
})
|
139
139
|
}.to raise_error(Braspag::InvalidInstallments)
|
@@ -143,8 +143,8 @@ describe Braspag::Eft do
|
|
143
143
|
expect {
|
144
144
|
Braspag::Eft.new(connection, {
|
145
145
|
:order_id => "76",
|
146
|
-
:amount => "
|
147
|
-
:payment_method =>
|
146
|
+
:amount => "50.00",
|
147
|
+
:payment_method => :bradesco,
|
148
148
|
:has_interest => []
|
149
149
|
})
|
150
150
|
}.to raise_error(Braspag::InvalidHasInterest)
|
@@ -160,20 +160,24 @@ describe Braspag::Eft do
|
|
160
160
|
it "should return form fields in strategy without crypto" do
|
161
161
|
html = <<-EOHTML
|
162
162
|
<form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
|
163
|
-
<input type="text" name="
|
164
|
-
<input type="text" name="
|
165
|
-
<input type="text" name="
|
166
|
-
<input type="text" name="
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
163
|
+
<input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
|
164
|
+
<input type="text" name="VendaId" value="1234123125" />
|
165
|
+
<input type="text" name="Nome" value="" />
|
166
|
+
<input type="text" name="Cpf" value="" />
|
167
|
+
<input type="text" name="Valor" value="123,00" />
|
168
|
+
<input type="text" name="codpagamento" value="11" />
|
169
|
+
<input type="text" name="PARCELAS" value="" />
|
170
|
+
<input type="text" name="TIPOPARCELADO" value="" />
|
171
|
+
</form>
|
172
|
+
<script type="text/javascript" charset="utf-8">
|
173
|
+
document.forms["form_tef_1234123125"].submit();
|
174
|
+
</script>
|
171
175
|
EOHTML
|
172
176
|
|
173
177
|
Braspag::Eft.new(connection , {
|
174
178
|
:order_id => "1234123125",
|
175
|
-
:amount => "
|
176
|
-
:payment_method =>
|
179
|
+
:amount => "123.00",
|
180
|
+
:payment_method => :bradesco
|
177
181
|
}).generate.should == html
|
178
182
|
end
|
179
183
|
|
@@ -187,18 +191,18 @@ describe Braspag::Eft do
|
|
187
191
|
|
188
192
|
html = <<-EOHTML
|
189
193
|
<form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
|
190
|
-
<input type="text" name="crypt" value="5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7" />
|
191
|
-
<input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
194
|
+
<input type="text" name="crypt" value="5u0ZN5qk8eQNuuGPHrcsk0rfi7YclF6s+ZXCE+G4uG4ztfRJrrOALlf81ra7k7p7" />
|
195
|
+
<input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
|
196
|
+
</form>
|
197
|
+
<script type="text/javascript" charset="utf-8">
|
198
|
+
document.forms["form_tef_1234123125"].submit();
|
199
|
+
</script>
|
196
200
|
EOHTML
|
197
201
|
|
198
202
|
Braspag::Eft.new(connection , {
|
199
203
|
:order_id => "1234123125",
|
200
|
-
:amount => "
|
201
|
-
:payment_method =>
|
204
|
+
:amount => "123.00",
|
205
|
+
:payment_method => :bradesco
|
202
206
|
} , braspag_crypto_jar_webservice ).generate.should == html
|
203
207
|
|
204
208
|
FakeWeb.clean_registry
|
@@ -214,18 +218,18 @@ describe Braspag::Eft do
|
|
214
218
|
|
215
219
|
html = <<-EOHTML
|
216
220
|
<form id="form_tef_1234123125" name="form_tef_1234123125" action="https://homologacao.pagador.com.br/pagador/passthru.asp" method="post">
|
217
|
-
<input type="text" name="crypt" value="#{key}" />
|
218
|
-
<input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
221
|
+
<input type="text" name="crypt" value="#{key}" />
|
222
|
+
<input type="text" name="Id_Loja" value="{84BE7E7F-698A-6C74-F820-AE359C2A07C2}" />
|
223
|
+
</form>
|
224
|
+
<script type="text/javascript" charset="utf-8">
|
225
|
+
document.forms["form_tef_1234123125"].submit();
|
226
|
+
</script>
|
223
227
|
EOHTML
|
224
228
|
|
225
229
|
Braspag::Eft.new(connection , {
|
226
230
|
:order_id => "1234123125",
|
227
|
-
:amount => "
|
228
|
-
:payment_method =>
|
231
|
+
:amount => "123.00",
|
232
|
+
:payment_method => :bradesco
|
229
233
|
} , braspag_crypto_webservice ).generate.should == html
|
230
234
|
|
231
235
|
FakeWeb.clean_registry
|
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.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -17,7 +17,7 @@ date: 2011-07-06 00:00:00.000000000Z
|
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: cs-httpi
|
20
|
-
requirement: &
|
20
|
+
requirement: &15019380 !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
23
23
|
- - ! '>='
|
@@ -25,10 +25,10 @@ dependencies:
|
|
25
25
|
version: 0.9.5.2
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
|
-
version_requirements: *
|
28
|
+
version_requirements: *15019380
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: json
|
31
|
-
requirement: &
|
31
|
+
requirement: &15018960 !ruby/object:Gem::Requirement
|
32
32
|
none: false
|
33
33
|
requirements:
|
34
34
|
- - ! '>='
|
@@ -36,10 +36,10 @@ dependencies:
|
|
36
36
|
version: '0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
|
-
version_requirements: *
|
39
|
+
version_requirements: *15018960
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: nokogiri
|
42
|
-
requirement: &
|
42
|
+
requirement: &15018500 !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
45
45
|
- - ! '>='
|
@@ -47,10 +47,10 @@ dependencies:
|
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
|
-
version_requirements: *
|
50
|
+
version_requirements: *15018500
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
52
|
name: rspec
|
53
|
-
requirement: &
|
53
|
+
requirement: &15018080 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
56
|
- - ! '>='
|
@@ -58,10 +58,10 @@ dependencies:
|
|
58
58
|
version: '0'
|
59
59
|
type: :development
|
60
60
|
prerelease: false
|
61
|
-
version_requirements: *
|
61
|
+
version_requirements: *15018080
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: fakeweb
|
64
|
-
requirement: &
|
64
|
+
requirement: &15017660 !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
@@ -69,10 +69,10 @@ dependencies:
|
|
69
69
|
version: '0'
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
|
-
version_requirements: *
|
72
|
+
version_requirements: *15017660
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: shoulda-matchers
|
75
|
-
requirement: &
|
75
|
+
requirement: &15017240 !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
77
77
|
requirements:
|
78
78
|
- - ! '>='
|
@@ -80,10 +80,10 @@ dependencies:
|
|
80
80
|
version: '0'
|
81
81
|
type: :development
|
82
82
|
prerelease: false
|
83
|
-
version_requirements: *
|
83
|
+
version_requirements: *15017240
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: guard-rspec
|
86
|
-
requirement: &
|
86
|
+
requirement: &15048380 !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
89
89
|
- - ! '>='
|
@@ -91,10 +91,10 @@ dependencies:
|
|
91
91
|
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
|
-
version_requirements: *
|
94
|
+
version_requirements: *15048380
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: guard-bundler
|
97
|
-
requirement: &
|
97
|
+
requirement: &15047960 !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|
100
100
|
- - ! '>='
|
@@ -102,10 +102,10 @@ dependencies:
|
|
102
102
|
version: '0'
|
103
103
|
type: :development
|
104
104
|
prerelease: false
|
105
|
-
version_requirements: *
|
105
|
+
version_requirements: *15047960
|
106
106
|
- !ruby/object:Gem::Dependency
|
107
107
|
name: ruby-debug19
|
108
|
-
requirement: &
|
108
|
+
requirement: &15047540 !ruby/object:Gem::Requirement
|
109
109
|
none: false
|
110
110
|
requirements:
|
111
111
|
- - ! '>='
|
@@ -113,7 +113,7 @@ dependencies:
|
|
113
113
|
version: '0'
|
114
114
|
type: :development
|
115
115
|
prerelease: false
|
116
|
-
version_requirements: *
|
116
|
+
version_requirements: *15047540
|
117
117
|
description: rbraspag gem to use Braspag gateway
|
118
118
|
email:
|
119
119
|
- tinorj@gmail.com
|