Class: OffsitePayments::Integrations::Epay::Helper

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

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, merchantnumber, options = {}) ⇒ Helper



16
17
18
19
20
21
22
# File 'lib/offsite_payments/integrations/epay.rb', line 16

def initialize(order, merchantnumber, options = {})
  super
  add_field('windowstate', 3)
  add_field('language', '0')
  add_field('orderid', format_order_number(order))
  @fields = Hash[@fields.sort]
end

Dynamic Method Handling

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

Instance Method Details

#form_fieldsObject



28
29
30
# File 'lib/offsite_payments/integrations/epay.rb', line 28

def form_fields
  @fields.merge('hash' => generate_md5hash)
end

#format_order_number(number) ⇒ Object

Limited to 20 digits max



41
42
43
# File 'lib/offsite_payments/integrations/epay.rb', line 41

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

#generate_md5hashObject



36
37
38
# File 'lib/offsite_payments/integrations/epay.rb', line 36

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

#generate_md5stringObject



32
33
34
# File 'lib/offsite_payments/integrations/epay.rb', line 32

def generate_md5string
  @fields.sort.each.map { |key, value| key != 'hash' ? value.to_s : ''} * "" + @md5secret
end

#md5secret(value) ⇒ Object



24
25
26
# File 'lib/offsite_payments/integrations/epay.rb', line 24

def md5secret(value)
  @md5secret = value
end