Class: ActiveMerchant::Billing::Integrations::Directebanking::Helper

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

Constant Summary collapse

SIGNATURE_FIELDS =
[
  :user_id,
  :project_id,
  :sender_holder,
  :sender_account_number,
  :sender_bank_code,
  :sender_country_id,
  :amount,
  :currency_id,
  :reason_1,
  :reason_2,
  :user_variable_0,
  :user_variable_1,
  :user_variable_2,
  :user_variable_3,
  :user_variable_4,
  :user_variable_5
]
SIGNATURE_IGNORE_AT_METHOD_CREATION_FIELDS =
[
  :user_id,
  :amount,
  :project_id,
  :currency_id,
  :user_variable_0,
  :user_variable_1,
  :user_variable_2,
  :user_variable_3
]

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

All credentials are mandatory and need to be set

credential1: User ID credential2: Project ID credential3: Project Password (Algorithm: SH1) credential4: Notification Password (Algorithm: SH1)



13
14
15
16
17
18
# File 'lib/active_merchant/billing/integrations/directebanking/helper.rb', line 13

def initialize(order, , options = {})
  super
  add_field('user_variable_0', order)
  add_field('project_id', options[:credential2])
  @project_password = options[:credential3]
end

Dynamic Method Handling

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

Instance Method Details

#amount=(money) ⇒ Object

Need to format the amount to have 2 decimal places



57
58
59
60
61
62
63
# File 'lib/active_merchant/billing/integrations/directebanking/helper.rb', line 57

def amount=(money)
  cents = money.respond_to?(:cents) ? money.cents : money
  if money.is_a?(String) or cents.to_i <= 0
    raise ArgumentError, 'money amount must be either a Money object or a positive integer in cents.'
  end
  add_field mappings[:amount], sprintf("%.2f", cents.to_f/100)
end

#form_fieldsObject



74
75
76
# File 'lib/active_merchant/billing/integrations/directebanking/helper.rb', line 74

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

#generate_signatureObject



70
71
72
# File 'lib/active_merchant/billing/integrations/directebanking/helper.rb', line 70

def generate_signature
  Digest::SHA1.hexdigest(generate_signature_string)
end

#generate_signature_stringObject



65
66
67
68
# File 'lib/active_merchant/billing/integrations/directebanking/helper.rb', line 65

def generate_signature_string
  # format of signature: user_id|project_id|sender_holder|sender_account_number|sender_bank_code| sender_country_id|amount|currency_id|reason_1|reason_2|user_variable_0|user_variable_1|user_variable_2|user_variable_3|user_variable_4|user_variable_5|project_password
  SIGNATURE_FIELDS.map {|key| @fields[key.to_s]} * "|" + "|#{@project_password}"
end