class Xdelivery::Callback

Constants

PARAM_KEYS

Attributes

access_key[RW]
check_code[RW]
merchant_no[RW]
params[RW]

Public Class Methods

new(merchant_no, access_key, params) click to toggle source
# File lib/xdelivery/callback.rb, line 7
def initialize(merchant_no, access_key, params)
  self.params = PARAM_KEYS.map do |key|
    [ key, params[key] ]
  end.to_h

  self.check_code = params[:check_code]
  self.merchant_no = merchant_no
  self.access_key = access_key
end

Public Instance Methods

action() click to toggle source
# File lib/xdelivery/callback.rb, line 21
def action
  params[:action]
end
created_at() click to toggle source
# File lib/xdelivery/callback.rb, line 37
def created_at
  if params[:created_at] == ''
    nil
  elsif Time.respond_to?(:zone)
    Time.zone.parse(params[:created_at])
  else
    Time.parse(params[:created_at])
  end
end
desc() click to toggle source
# File lib/xdelivery/callback.rb, line 29
def desc
  params[:desc]
end
provider() click to toggle source
# File lib/xdelivery/callback.rb, line 33
def provider
  params[:provider]
end
title() click to toggle source
# File lib/xdelivery/callback.rb, line 25
def title
  params[:title]
end
valid?() click to toggle source
# File lib/xdelivery/callback.rb, line 17
def valid?
  check_code == check_code!
end

Protected Instance Methods

check_code!() click to toggle source
# File lib/xdelivery/callback.rb, line 53
def check_code!
  query_string_with_salt = "merchant_no=#{merchant_no}&#{query_string}&access_key=#{access_key}"
  Digest::SHA256.hexdigest(query_string_with_salt).upcase
end
query_string() click to toggle source
# File lib/xdelivery/callback.rb, line 49
def query_string
  URI.encode_www_form(params.sort.to_h)
end