Class: OffsitePayments::Integrations::Quickpay::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/quickpay.rb

Constant Summary collapse

MD5_CHECK_FIELDS =
[
  :protocol,
  :msgtype,
  :merchant,
  :language,
  :ordernumber,
  :amount,
  :currency,
  :continueurl,
  :cancelurl,
  :callbackurl,
  :autocapture,
  :autofee,
  :cardtypelock,
  :description,
  :group,
  :testmode,
  :splitpayment,
  :forcemobile,
  :deadline,
  :cardhash
]

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_method, inherited, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

#initialize(order, account, options = {}) ⇒ Helper

Returns a new instance of Helper


16
17
18
19
20
21
22
23
24
25
# File 'lib/offsite_payments/integrations/quickpay.rb', line 16

def initialize(order, , options = {})
  md5secret options.delete(:credential2)
  super
  add_field('protocol', '7')
  add_field('msgtype', 'authorize')
  add_field('language', 'da')
  add_field('autocapture', 0)
  add_field('testmode', test? ? 1 : 0)
  add_field('ordernumber', format_order_number(order))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Method Details

#form_fieldsObject


31
32
33
# File 'lib/offsite_payments/integrations/quickpay.rb', line 31

def form_fields
  @fields.merge('md5check' => generate_md5check)
end

#format_order_number(number) ⇒ Object

Limited to 20 digits max


44
45
46
# File 'lib/offsite_payments/integrations/quickpay.rb', line 44

def format_order_number(number)
  number.to_s.gsub(/[^\w]/, '').rjust(4, "0")[0...20]
end

#generate_md5checkObject


39
40
41
# File 'lib/offsite_payments/integrations/quickpay.rb', line 39

def generate_md5check
  Digest::MD5.hexdigest(generate_md5string)
end

#generate_md5stringObject


35
36
37
# File 'lib/offsite_payments/integrations/quickpay.rb', line 35

def generate_md5string
  MD5_CHECK_FIELDS.map {|key| @fields[key.to_s]} * "" + @md5secret
end

#md5secret(value) ⇒ Object


27
28
29
# File 'lib/offsite_payments/integrations/quickpay.rb', line 27

def md5secret(value)
  @md5secret = value
end