Class: OpenPayU::Document
- Inherits:
-
Object
- Object
- OpenPayU::Document
show all
- Defined in:
- lib/openpayu/document.rb
Instance Method Summary
(collapse)
Instance Method Details
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/openpayu/document.rb', line 54
def deep_transform_keys(hash, &block)
result = {}
hash.each do |key, value|
result[yield(key)] =
if value.is_a?(Hash)
deep_transform_keys(value, &block)
else
value
end
end
result
end
|
- (Object) generate_signature(data, algorithm, signature_key)
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/openpayu/document.rb', line 21
def generate_signature(data, algorithm, signature_key)
data = data + signature_key.to_s
if algorithm == 'MD5'
signature = Digest::MD5.hexdigest(data)
elsif %w(SHA SHA1 SHA-1).include? algorithm
signature = Digest::SHA1.hexdigest data
elsif %w(SHA-256 SHA256 SHA_256).include? algorithm
signature = Digest::SHA256.hexdigest data
else
signature = ''
end
signature
end
|
- (Object) generate_signature_structure(data, algorithm, pos_id = '', key = '')
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/openpayu/document.rb', line 8
def generate_signature_structure(data, algorithm, pos_id = '', key = '')
if key.empty?
raise WrongConfigurationError,
'Merchant Signature Key (signature_key)
should not be null or empty.'
end
raise WrongConfigurationError,
'Merchant Pos Id (merchant_pos_id) should
not be null or empty.' if pos_id.blank?
signature = generate_signature(data, algorithm, key)
"sender=#{pos_id};signature=#{signature};algorithm=#{algorithm}"
end
|
- (Object) underscore_keys(hash)
50
51
52
|
# File 'lib/openpayu/document.rb', line 50
def underscore_keys(hash)
deep_transform_keys(hash) { |key| key.underscore }
end
|
- (Object) verify_response
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/openpayu/document.rb', line 35
def verify_response
unless @response
raise EmptyResponseError,
"Got empty response from request: #{@request.try(:body)}"
end
if ( response.is_a?(OpenPayU::Documents::Request) ||
%w(200 201 422 302).include?(response.code))
true
else
raise HttpStatusException,
"Invalid HTTP response code (#{@response.code}).
Response body: #{@body}."
end
end
|