rbraspag 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -3
- data/config/braspag.yml +12 -0
- data/lib/rbraspag/bill.rb +79 -79
- data/lib/rbraspag/connection.rb +15 -5
- data/lib/rbraspag/credit_card.rb +52 -42
- data/lib/rbraspag/crypto/jar_webservice.rb +12 -14
- data/lib/rbraspag/crypto/webservice.rb +14 -17
- data/lib/rbraspag/eft.rb +32 -48
- data/lib/rbraspag/order.rb +7 -37
- data/lib/rbraspag/utils.rb +27 -3
- data/lib/rbraspag/version.rb +1 -1
- data/lib/rbraspag.rb +0 -7
- data/rbraspag-0.0.11.gem +0 -0
- data/spec/bill_spec.rb +399 -314
- data/spec/connection_spec.rb +101 -26
- data/spec/credit_card_spec.rb +117 -48
- data/spec/crypto/jar_webservice_spec.rb +3 -6
- data/spec/crypto/webservice_spec.rb +9 -31
- data/spec/eft_spec.rb +137 -156
- data/spec/order_spec.rb +10 -24
- data/spec/utils_spec.rb +2 -0
- metadata +22 -20
data/lib/rbraspag/eft.rb
CHANGED
@@ -20,70 +20,59 @@ module Braspag
|
|
20
20
|
:has_interest => "TIPOPARCELADO"
|
21
21
|
}
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if @params[:amount] && !@params[:amount].is_a?(BigDecimal)
|
32
|
-
@params[:amount] = BigDecimal.new(@params[:amount].to_s)
|
23
|
+
def self.generate(params, crypto_strategy = nil)
|
24
|
+
connection = Braspag::Connection.instance
|
25
|
+
|
26
|
+
params[:merchant_id] = connection.merchant_id
|
27
|
+
|
28
|
+
if params[:amount] && !params[:amount].is_a?(BigDecimal)
|
29
|
+
params[:amount] = BigDecimal.new(params[:amount].to_s)
|
33
30
|
end
|
34
|
-
|
35
|
-
ok?
|
36
|
-
end
|
37
31
|
|
38
|
-
|
39
|
-
raise IncompleteParams if @params[:order_id].nil? || @params[:amount].nil? || @params[:payment_method].nil?
|
32
|
+
raise IncompleteParams if params[:order_id].nil? || params[:amount].nil? || params[:payment_method].nil?
|
40
33
|
|
41
|
-
raise InvalidOrderId unless
|
42
|
-
raise InvalidOrderId unless (1..50).include?(
|
34
|
+
raise InvalidOrderId unless params[:order_id].is_a?(String) || params[:order_id].is_a?(Fixnum)
|
35
|
+
raise InvalidOrderId unless (1..50).include?(params[:order_id].to_s.size)
|
43
36
|
|
44
|
-
unless
|
45
|
-
raise InvalidCustomerName unless (1..255).include?(
|
37
|
+
unless params[:customer_name].nil?
|
38
|
+
raise InvalidCustomerName unless (1..255).include?(params[:customer_name].to_s.size)
|
46
39
|
end
|
47
40
|
|
48
|
-
unless
|
49
|
-
raise InvalidCustomerId unless (11..18).include?(
|
41
|
+
unless params[:customer_id].nil?
|
42
|
+
raise InvalidCustomerId unless (11..18).include?(params[:customer_id].to_s.size)
|
50
43
|
end
|
51
44
|
|
52
|
-
unless
|
53
|
-
raise InvalidInstallments unless (1..2).include?(
|
45
|
+
unless params[:installments].nil?
|
46
|
+
raise InvalidInstallments unless (1..2).include?(params[:installments].to_s.size)
|
54
47
|
begin
|
55
|
-
|
48
|
+
params[:installments] = Integer(params[:installments]) unless params[:installments].is_a?(Integer)
|
56
49
|
rescue Exception => e
|
57
50
|
raise InvalidInstallments
|
58
51
|
end
|
59
52
|
end
|
60
53
|
|
61
|
-
unless
|
62
|
-
raise InvalidHasInterest unless (
|
54
|
+
unless params[:has_interest].nil?
|
55
|
+
raise InvalidHasInterest unless (params[:has_interest].is_a?(TrueClass) || params[:has_interest].is_a?(FalseClass))
|
63
56
|
end
|
64
57
|
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
def generate
|
69
|
-
data = create_data_from_params
|
58
|
+
data = create_data(params)
|
70
59
|
|
71
|
-
html = "<form id=\"form_tef_#{
|
60
|
+
html = "<form id=\"form_tef_#{params[:order_id]}\" name=\"form_tef_#{params[:order_id]}\" action=\"#{self.uri}\" method=\"post\">\n"
|
72
61
|
|
73
|
-
if
|
62
|
+
if crypto_strategy.nil?
|
74
63
|
data.each do |key, value|
|
75
64
|
html.concat " <input type=\"text\" name=\"#{key}\" value=\"#{value}\" />\n"
|
76
65
|
end
|
77
66
|
else
|
78
67
|
data.delete("Id_Loja")
|
79
|
-
html.concat " <input type=\"text\" name=\"crypt\" value=\"#{
|
80
|
-
html.concat " <input type=\"text\" name=\"Id_Loja\" value=\"#{
|
68
|
+
html.concat " <input type=\"text\" name=\"crypt\" value=\"#{crypto_strategy.encrypt(data)}\" />\n"
|
69
|
+
html.concat " <input type=\"text\" name=\"Id_Loja\" value=\"#{params[:merchant_id]}\" />\n"
|
81
70
|
end
|
82
71
|
|
83
72
|
html.concat <<-EOHTML
|
84
73
|
</form>
|
85
74
|
<script type="text/javascript" charset="utf-8">
|
86
|
-
document.forms["form_tef_#{
|
75
|
+
document.forms["form_tef_#{params[:order_id]}"].submit();
|
87
76
|
</script>
|
88
77
|
EOHTML
|
89
78
|
|
@@ -91,28 +80,23 @@ module Braspag
|
|
91
80
|
end
|
92
81
|
|
93
82
|
protected
|
94
|
-
def
|
83
|
+
def self.create_data(params)
|
95
84
|
MAPPING.inject({}) do |memo, k|
|
96
85
|
if k[0] == :payment_method
|
97
|
-
memo[k[1]] = PAYMENT_METHODS[
|
86
|
+
memo[k[1]] = PAYMENT_METHODS[params[:payment_method]]
|
98
87
|
elsif k[0] == :amount
|
99
|
-
memo[k[1]] = convert_decimal_to_string(
|
88
|
+
memo[k[1]] = Utils.convert_decimal_to_string(params[:amount])
|
100
89
|
else
|
101
|
-
memo[k[1]] =
|
90
|
+
memo[k[1]] = params[k[0]] || "";
|
102
91
|
end
|
103
92
|
|
104
93
|
memo
|
105
94
|
end
|
106
95
|
end
|
107
96
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
111
|
-
"#{integer},#{cents}"
|
112
|
-
end
|
113
|
-
|
114
|
-
def uri
|
115
|
-
"#{@connection.base_url}/pagador/passthru.asp"
|
97
|
+
def self.uri
|
98
|
+
connection = Braspag::Connection.instance
|
99
|
+
"#{connection.braspag_url}/pagador/passthru.asp"
|
116
100
|
end
|
117
101
|
end
|
118
102
|
end
|
data/lib/rbraspag/order.rb
CHANGED
@@ -1,30 +1,19 @@
|
|
1
1
|
module Braspag
|
2
2
|
class Order
|
3
|
-
|
4
3
|
class InvalidData < Exception; end
|
5
4
|
|
6
|
-
def self.status(
|
7
|
-
|
5
|
+
def self.status(order_id)
|
6
|
+
connection = Braspag::Connection.instance
|
8
7
|
|
9
8
|
raise InvalidOrderId unless order_id.is_a?(String) || order_id.is_a?(Fixnum)
|
10
9
|
raise InvalidOrderId unless (1..50).include?(order_id.to_s.size)
|
11
10
|
|
12
|
-
request = ::HTTPI::Request.new("#{connection.
|
11
|
+
request = ::HTTPI::Request.new("#{connection.braspag_url}/pagador/webservice/pedido.asmx/GetDadosPedido")
|
13
12
|
request.body = {:loja => connection.merchant_id, :numeroPedido => order_id.to_s}
|
14
13
|
|
15
14
|
response = ::HTTPI.post(request)
|
16
15
|
|
17
|
-
response = convert_to_map
|
18
|
-
|
19
|
-
raise InvalidData if response[:authorization].nil?
|
20
|
-
response
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.convert_to_map(document)
|
25
|
-
document = Nokogiri::XML(document)
|
26
|
-
|
27
|
-
map = {
|
16
|
+
response = Utils::convert_to_map(response.body, {
|
28
17
|
:authorization => "CodigoAutorizacao",
|
29
18
|
:error_code => "CodigoErro",
|
30
19
|
:error_message => "MensagemErro",
|
@@ -38,30 +27,11 @@ module Braspag
|
|
38
27
|
:order_date => "DataPedido",
|
39
28
|
:transaction_id => "TransId",
|
40
29
|
:tid => "BraspagTid"
|
41
|
-
}
|
42
|
-
|
43
|
-
map.each do |keyForMap , keyValue|
|
44
|
-
if keyValue.is_a?(String) || keyValue.nil?
|
45
|
-
keyValue = keyForMap if keyValue.nil?
|
46
|
-
|
47
|
-
value = document.search(keyValue).first
|
48
|
-
if !value.nil?
|
49
|
-
value = value.content.to_s
|
50
|
-
map[keyForMap] = value unless value == ""
|
51
|
-
map[keyForMap] = nil if value == ""
|
52
|
-
else
|
53
|
-
map[keyForMap] = nil
|
54
|
-
end
|
55
|
-
|
56
|
-
elsif keyValue.is_a?(Proc)
|
57
|
-
map[keyForMap] = keyValue.call
|
58
|
-
end
|
30
|
+
})
|
59
31
|
|
60
|
-
|
61
|
-
|
32
|
+
raise InvalidData if response[:authorization].nil?
|
33
|
+
response
|
62
34
|
|
63
|
-
map
|
64
35
|
end
|
65
|
-
|
66
36
|
end
|
67
37
|
end
|
data/lib/rbraspag/utils.rb
CHANGED
@@ -1,11 +1,35 @@
|
|
1
1
|
module Braspag
|
2
|
-
|
3
2
|
class Utils
|
4
3
|
def self.convert_decimal_to_string(value)
|
5
4
|
cents = "0#{((value - value.to_i) * 100).to_i}".slice(-2,2)
|
6
5
|
integer = (value - (value - value.to_i)).to_i
|
7
6
|
"#{integer},#{cents}"
|
8
7
|
end
|
8
|
+
|
9
|
+
def self.convert_to_map(document, map = {})
|
10
|
+
document = Nokogiri::XML(document)
|
11
|
+
|
12
|
+
map.each do |keyForMap , keyValue|
|
13
|
+
if keyValue.is_a?(String) || keyValue.nil?
|
14
|
+
keyValue = keyForMap if keyValue.nil?
|
15
|
+
|
16
|
+
value = document.search(keyValue).first
|
17
|
+
if !value.nil?
|
18
|
+
value = value.content.to_s
|
19
|
+
map[keyForMap] = value unless value == ""
|
20
|
+
map[keyForMap] = nil if value == ""
|
21
|
+
else
|
22
|
+
map[keyForMap] = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
elsif keyValue.is_a?(Proc)
|
26
|
+
map[keyForMap] = keyValue.call(document)
|
27
|
+
end
|
28
|
+
|
29
|
+
map[keyForMap]
|
30
|
+
end
|
31
|
+
|
32
|
+
map
|
33
|
+
end
|
9
34
|
end
|
10
|
-
|
11
|
-
end
|
35
|
+
end
|
data/lib/rbraspag/version.rb
CHANGED
data/lib/rbraspag.rb
CHANGED
data/rbraspag-0.0.11.gem
ADDED
Binary file
|