Class: OffsitePayments::Integrations::Directebanking::Helper

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


47
48
49
50
51
52
# File 'lib/offsite_payments/integrations/directebanking.rb', line 47

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 OffsitePayments::Helper

Instance Method Details

#amount=(money) ⇒ Object

Need to format the amount to have 2 decimal places

Raises:

  • (ArgumentError)

91
92
93
94
95
96
97
# File 'lib/offsite_payments/integrations/directebanking.rb', line 91

def amount=(money)
  cents = money.respond_to?(:cents) ? money.cents : money
  raise ArgumentError, "amount must be a Money object or an integer" if money.is_a?(String)
  raise ActionViewHelperError, "amount must be greater than $0.00" if cents.to_i <= 0

  add_field mappings[:amount], sprintf("%.2f", cents.to_f/100)
end

#form_fieldsObject


108
109
110
# File 'lib/offsite_payments/integrations/directebanking.rb', line 108

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

#generate_signatureObject


104
105
106
# File 'lib/offsite_payments/integrations/directebanking.rb', line 104

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

#generate_signature_stringObject


99
100
101
102
# File 'lib/offsite_payments/integrations/directebanking.rb', line 99

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