Module: ActiveMerchant::Billing::Integrations::PayFast::Common

Included in:
Helper, Notification
Defined in:
lib/active_merchant/billing/integrations/pay_fast/common.rb

Instance Method Summary collapse

Instance Method Details

#generate_signature(type) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/active_merchant/billing/integrations/pay_fast/common.rb', line 6

def generate_signature(type)
  string = case type
  when :request
    request_signature_string
  when :notify
    notify_signature_string
  end

  Digest::MD5.hexdigest(string)
end

#notify_signature_stringObject



33
34
35
36
37
# File 'lib/active_merchant/billing/integrations/pay_fast/common.rb', line 33

def notify_signature_string
  params.map do |key, value|
    "#{key}=#{CGI.escape(value)}" unless key == PayFast.signature_parameter_name
  end.compact.join('&')
end

#request_attributesObject



17
18
19
20
21
22
23
24
25
# File 'lib/active_merchant/billing/integrations/pay_fast/common.rb', line 17

def request_attributes
  [:merchant_id, :merchant_key, :return_url, :cancel_url,
   :notify_url, :name_first, :name_last, :email_address,
   :payment_id, :amount, :item_name, :item_description,
   :custom_str1, :custom_str2, :custom_str3, :custom_str4,
   :custom_str5, :custom_int1, :custom_int2, :custom_int3,
   :custom_int4, :custom_int5, :email_confirmation,
   :confirmation_address]
end

#request_signature_stringObject



27
28
29
30
31
# File 'lib/active_merchant/billing/integrations/pay_fast/common.rb', line 27

def request_signature_string
  request_attributes.map do |attr|
    "#{mappings[attr]}=#{CGI.escape(@fields[mappings[attr]])}" if @fields[mappings[attr]].present?
  end.compact.join('&')
end