Class: ActiveMerchant::Billing::Integrations::Migs::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/migs/helper.rb

Constant Summary collapse

VERSION =
'1'
COMMAND =
'pay'
LOCALE =
'en'

Instance Attribute Summary

Attributes inherited from Helper

#fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Helper

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

Constructor Details

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

Returns a new instance of Helper.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_merchant/billing/integrations/migs/helper.rb', line 23

def initialize(order, , options = {})
  super

  add_field mappings[:version], VERSION
  add_field mappings[:command], COMMAND
  add_field mappings[:locale], LOCALE

  @secret_code = options[:credential2]
  add_field mappings[:merchant], options[:credential3]
  add_field mappings[:access_code], options[:credential4]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Class Method Details

.sign(prefix, params) ⇒ Object



54
55
56
57
58
59
# File 'lib/active_merchant/billing/integrations/migs/helper.rb', line 54

def self.sign(prefix, params)
  hash_input = prefix
  params.reject { |k,v| k == mappings[:secure_hash] }.sort.each { |p| hash_input += p.last }
  
  return Digest::MD5.hexdigest(hash_input).upcase
end

Instance Method Details

#amount=(money) ⇒ Object

Convert to cents



36
37
38
39
40
41
42
43
44
# File 'lib/active_merchant/billing/integrations/migs/helper.rb', line 36

def amount=(money)
  amount = money.to_f
  if amount <= 0
    raise ArgumentError, 'amount must be positive'
  end

  amount = (amount * 100).to_i
  add_field mappings[:amount], amount
end

#form_fieldsObject



46
47
48
# File 'lib/active_merchant/billing/integrations/migs/helper.rb', line 46

def form_fields
  @fields.merge(mappings[:secure_hash] => signature)
end

#signatureObject



50
51
52
# File 'lib/active_merchant/billing/integrations/migs/helper.rb', line 50

def signature
  self.class.sign(@secret_code, @fields)
end