Class: EpayTools::Calculator

Inherits:
ServicePattern::Service
  • Object
show all
Defined in:
lib/epay_tools/calculator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(epay_md5_key:, params:) ⇒ Calculator

Returns a new instance of Calculator.



4
5
6
7
# File 'lib/epay_tools/calculator.rb', line 4

def initialize(epay_md5_key:, params:)
  @epay_md5_key = epay_md5_key
  @params = params
end

Instance Attribute Details

#epay_md5_keyObject (readonly)

Returns the value of attribute epay_md5_key.



2
3
4
# File 'lib/epay_tools/calculator.rb', line 2

def epay_md5_key
  @epay_md5_key
end

#epay_merchant_numberObject (readonly)

Returns the value of attribute epay_merchant_number.



2
3
4
# File 'lib/epay_tools/calculator.rb', line 2

def epay_merchant_number
  @epay_merchant_number
end

#paramsObject (readonly)

Returns the value of attribute params.



2
3
4
# File 'lib/epay_tools/calculator.rb', line 2

def params
  @params
end

Instance Method Details

#execute!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/epay_tools/calculator.rb', line 9

def execute!
  epay_params = {}
  EpayTools::OrderedParameters::ORDERED_PARAMETERS.each do |ordered_parameter|
    epay_params[ordered_parameter] = params.fetch(ordered_parameter)
  end

  epay_hash = EpayTools::HashGenerator.execute!(epay_md5_key: epay_md5_key, params: epay_params).result
  epay_params_with_hash = epay_params.merge("hash" => epay_hash)

  ServicePattern::Response.new(
    result: {
      epay_params: epay_params,
      epay_hash: epay_hash,
      epay_params_with_hash: epay_params_with_hash
    }
  )
end