class OffsitePayments::Integrations::QuickpayV10::Helper

credential2: Payment window API key

Public Class Methods

new(order, account, options = {}) click to toggle source
Calls superclass method
# File lib/offsite_payments/integrations/quickpay_v10.rb, line 19
def initialize(order, account, options = {})
  payment_window_api_key options.delete(:credential2)
  super
  add_field('version', 'v10')
  add_field('type', 'payment')
  add_field('language', 'da')
  add_field('autocapture', 0)
  add_field('order_id', format_order_number(order))
end

Public Instance Methods

flatten_params(obj, result = {}, path = []) click to toggle source
# File lib/offsite_payments/integrations/quickpay_v10.rb, line 37
def flatten_params(obj, result = {}, path = [])
  case obj
  when Hash
    obj.each do |k, v|
      flatten_params(v, result, [*path, k])
    end
  when Array
    obj.each_with_index do |v, i|
      flatten_params(v, result, [*path, i])
    end
  else
    result[path.map{|p| "[#{p}]"}.join.to_sym] = obj
  end
  result
end
form_fields() click to toggle source
# File lib/offsite_payments/integrations/quickpay_v10.rb, line 33
def form_fields
  @fields.merge('checksum' => generate_checksum)
end
format_order_number(number) click to toggle source

Limited to 20 digits max

# File lib/offsite_payments/integrations/quickpay_v10.rb, line 61
def format_order_number(number)
  number.to_s.gsub(/[^\w]/, '').rjust(4, "0")[0...20]
end
generate_checksum() click to toggle source
# File lib/offsite_payments/integrations/quickpay_v10.rb, line 53
def generate_checksum
  flattened_params = flatten_params(@fields)
  values = flattened_params.sort.map { |_, value| value }
  base = values.join(' ')
  OpenSSL::HMAC.hexdigest('sha256', @payment_window_api_key, base)
end
payment_window_api_key(value) click to toggle source
# File lib/offsite_payments/integrations/quickpay_v10.rb, line 29
def payment_window_api_key(value)
  @payment_window_api_key = value
end