class OmniKassa::Response

Constants

RESPONSE_CODES

Attributes

amount[RW]
data[RW]
order_id[RW]
response_code[RW]
seal[RW]

Public Class Methods

new(params) click to toggle source
# File lib/omni_kassa/response.rb, line 13
def initialize(params)
  self.data = params[:Data]
  self.seal = params[:Seal]

  verify_seal!
end

Public Instance Methods

data=(data) click to toggle source
# File lib/omni_kassa/response.rb, line 32
def data=(data)
  @data = data
  parse_data_hash
end
pending?() click to toggle source
# File lib/omni_kassa/response.rb, line 20
def pending?
  response == :pending
end
response() click to toggle source
# File lib/omni_kassa/response.rb, line 28
def response
  RESPONSE_CODES[response_code] || :unknown_failure
end
response_code=(response_code) click to toggle source
# File lib/omni_kassa/response.rb, line 37
def response_code=(response_code)
  raise ResponseCodeError if response_code.to_s.scan(/\D/).present?
  @response_code = Integer(response_code)
end
successful?() click to toggle source
# File lib/omni_kassa/response.rb, line 24
def successful?
  response == :success
end

Protected Instance Methods

data_hash() click to toggle source
# File lib/omni_kassa/response.rb, line 56
def data_hash
  Hash[data.split('|').map { |a| a.split('=') }]
end
parse_data_hash() click to toggle source
# File lib/omni_kassa/response.rb, line 49
def parse_data_hash
  data_hash.each do |key, value|
    key = key.underscore + '='
    send key, value if respond_to? key
  end
end
verify_seal!() click to toggle source
# File lib/omni_kassa/response.rb, line 44
def verify_seal!
  seal = Digest::SHA2.new.update(data + OmniKassa.secret_key)
  raise SealMismatchError if seal != self.seal
end