Class: OffsitePayments::Integrations::Verkkomaksut::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/verkkomaksut.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, account, options = {}) ⇒ Helper

Fetches the md5secret and adds MERCHANT_ID and API TYPE to the form



14
15
16
17
18
19
# File 'lib/offsite_payments/integrations/verkkomaksut.rb', line 14

def initialize(order, , options = {})
  md5secret options.delete(:credential2)
  super
  add_field("MERCHANT_ID", )
  add_field("TYPE", "E1")
end

Dynamic Method Handling

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

Instance Method Details

#form_fieldsObject

Adds the AUTHCODE to the form



26
27
28
# File 'lib/offsite_payments/integrations/verkkomaksut.rb', line 26

def form_fields
  @fields.merge("AUTHCODE" => generate_md5string)
end

#generate_md5stringObject

Calculates the AUTHCODE



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/offsite_payments/integrations/verkkomaksut.rb', line 31

def generate_md5string
  fields = [@md5secret, @fields["MERCHANT_ID"], @fields["ORDER_NUMBER"], @fields["REFERENCE_NUMBER"], @fields["ORDER_DESCRIPTION"], @fields["CURRENCY"], @fields["RETURN_ADDRESS"], @fields["CANCEL_ADDRESS"], @fields["PENDING_ADDRESS"],
            @fields["NOTIFY_ADDRESS"], @fields["TYPE"], @fields["CULTURE"], @fields["PRESELECTED_METHOD"], @fields["MODE"], @fields["VISIBLE_METHODS"], @fields["GROUP"], @fields["CONTACT_TELNO"], @fields["CONTACT_CELLNO"],
            @fields["CONTACT_EMAIL"], @fields["CONTACT_FIRSTNAME"], @fields["CONTACT_LASTNAME"], @fields["CONTACT_COMPANY"], @fields["CONTACT_ADDR_STREET"], @fields["CONTACT_ADDR_ZIP"], @fields["CONTACT_ADDR_CITY"], @fields["CONTACT_ADDR_COUNTRY"], @fields["INCLUDE_VAT"],
            @fields["ITEMS"]]

  (0..@fields["ITEMS"].to_i-1).each do |i|
    fields += [@fields["ITEM_TITLE[#{i}]"], @fields["ITEM_NO[#{i}]"], @fields["ITEM_AMOUNT[#{i}]"], @fields["ITEM_PRICE[#{i}]"], @fields["ITEM_TAX[#{i}]"], @fields["ITEM_DISCOUNT[#{i}]"], @fields["ITEM_TYPE[#{i}]"]]
  end

  fields = fields.join("|")

  return Digest::MD5.hexdigest(fields).upcase
end

#md5secret(value) ⇒ Object



21
22
23
# File 'lib/offsite_payments/integrations/verkkomaksut.rb', line 21

def md5secret(value)
  @md5secret = value
end