Class: OffsitePayments::Integrations::Megakassa::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/megakassa.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

Returns a new instance of Helper.



52
53
54
55
56
57
58
59
60
# File 'lib/offsite_payments/integrations/megakassa.rb', line 52

def initialize(order, , options = {})
  @md5secret = options.delete(:secret)

  super

  add_field :debug,       test? ? '1' : ''
  add_field :amount,      normalize_amount(options[:amount])
  add_field :description, options[:description]
end

Dynamic Method Handling

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

Instance Method Details

#form_fieldsObject



62
63
64
# File 'lib/offsite_payments/integrations/megakassa.rb', line 62

def form_fields
  @fields.merge(OffsitePayments::Integrations::Megakassa.signature_parameter_name => generate_signature)
end

#generate_signatureObject



43
44
45
# File 'lib/offsite_payments/integrations/megakassa.rb', line 43

def generate_signature
  Digest::MD5.hexdigest(secret + Digest::MD5.hexdigest(generate_signature_string))
end

#generate_signature_stringObject



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

def generate_signature_string
  "#{params['shop_id']}:#{params['amount']}:#{params['currency']}:#{params['description']}:#{params['order_id']}:#{params['method_id']}:#{params['client_email']}:#{params['debug']}:#{secret}"
end

#normalize_amount(amount) ⇒ Object



47
48
49
50
# File 'lib/offsite_payments/integrations/megakassa.rb', line 47

def normalize_amount(amount)
  int, float = amount.to_i, amount.to_f
  int == float ? int : float
end

#paramsObject



66
67
68
# File 'lib/offsite_payments/integrations/megakassa.rb', line 66

def params
  @fields
end

#secretObject



70
71
72
# File 'lib/offsite_payments/integrations/megakassa.rb', line 70

def secret
  @md5secret
end