Class: Ogone::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/ogone/base.rb
Defined Under Namespace
Classes: ConfigurationError, MandatoryParameterMissing, OutboundSignatureMismatch
Constant Summary
collapse
- VALID_ENVIRONMENTS =
%w[test prod].freeze
- SIGNING_ALGORITHMS =
%w[SHA1 SHA256 SHA512].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
14
15
16
17
18
19
|
# File 'lib/ogone/base.rb', line 14
def initialize(options = {})
@parameters = {}
%i[sha_algo environment pspid sha_in sha_out].each do |config|
send :"#{config}=", options[config] unless options[config].nil?
end
end
|
Instance Attribute Details
#sha_in ⇒ Object
Returns the value of attribute sha_in.
12
13
14
|
# File 'lib/ogone/base.rb', line 12
def sha_in
@sha_in
end
|
#sha_out ⇒ Object
Returns the value of attribute sha_out.
12
13
14
|
# File 'lib/ogone/base.rb', line 12
def sha_out
@sha_out
end
|
Instance Method Details
#add_parameters(parameters) ⇒ Object
38
39
40
|
# File 'lib/ogone/base.rb', line 38
def add_parameters(parameters)
@parameters.merge! parameters
end
|
#add_single_return_url(return_url) ⇒ Object
58
59
60
61
62
|
# File 'lib/ogone/base.rb', line 58
def add_single_return_url(return_url)
%i[ACCEPTURL DECLINEURL EXCEPTIONURL CANCELURL].each do |field|
@parameters[field] = return_url
end
end
|
#check_shasign_out!(params) ⇒ Object
49
50
51
52
|
# File 'lib/ogone/base.rb', line 49
def check_shasign_out!(params)
params = upcase_keys(params)
raise OutboundSignatureMismatch if sha_out_sign(params) != params[:SHASIGN]
end
|
#environment=(environment) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/ogone/base.rb', line 26
def environment=(environment)
unless VALID_ENVIRONMENTS.include? environment.to_s
raise ArgumentError, "Unsupported Ogone environment: #{environment}"
end
@environment = environment
end
|
#fields_for_payment(parameters = {}, shasign_key = 'SHASIGN') ⇒ Object
42
43
44
45
46
47
|
# File 'lib/ogone/base.rb', line 42
def fields_for_payment(parameters = {}, shasign_key = 'SHASIGN')
add_parameters(parameters || {})
check_mandatory_parameters!
upcase_keys(@parameters).merge(shasign_key.to_sym => sha_in_sign)
end
|
#pspid=(pspid) ⇒ Object
33
34
35
36
|
# File 'lib/ogone/base.rb', line 33
def pspid=(pspid)
raise ArgumentError, 'PSPID cannot be empty' if pspid.nil? || pspid == ''
@pspid = pspid
end
|
#sha_algo=(sha_algo) ⇒ Object
21
22
23
24
|
# File 'lib/ogone/base.rb', line 21
def sha_algo=(sha_algo)
raise ArgumentError, "Unsupported signature algorithm: #{sha_algo}" unless SIGNING_ALGORITHMS.include?(sha_algo)
@sha_algo = sha_algo
end
|
#upcase_keys(hash) ⇒ Object
54
55
56
|
# File 'lib/ogone/base.rb', line 54
def upcase_keys(hash)
hash.each_with_object({}) { |(k, v), h| h[k.upcase.to_sym] = v; }
end
|