Class: ActiveMerchant::Billing::Integrations::Verkkomaksut::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/verkkomaksut/helper.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, 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



8
9
10
11
12
13
# File 'lib/active_merchant/billing/integrations/verkkomaksut/helper.rb', line 8

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 ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#form_fieldsObject

Adds the AUTHCODE to the form



20
21
22
# File 'lib/active_merchant/billing/integrations/verkkomaksut/helper.rb', line 20

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

#generate_md5stringObject

Calculates the AUTHCODE



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_merchant/billing/integrations/verkkomaksut/helper.rb', line 25

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



15
16
17
# File 'lib/active_merchant/billing/integrations/verkkomaksut/helper.rb', line 15

def md5secret(value)
  @md5secret = value
end