Module: ActiveMerchant::Billing::Integrations::Banklink::Helper

Included in:
SampoEst::Helper, SebEst::Helper, SwedbankEst::Helper, SwedbankLtu::Helper
Defined in:
lib/active_merchant/billing/integrations/banklink/helper.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 7

def self.included(base)
  base.class_eval do
    mapping :account, 'VK_SND_ID'
    # Amount paid, for example, "33.00"
    mapping :amount, 'VK_AMOUNT'
    # Unique order id
    mapping :order, 'VK_STAMP'
    # Currency used, 3-letter ISO 4217 code
    mapping :currency, 'VK_CURR'
    mapping :notify_url, 'VK_RETURN'
    mapping :return_url, 'VK_RETURN'
    mapping :cancel_return_url, 'VK_CANCEL'
    
    mapping :reference, 'VK_REF'
    mapping :description, 'VK_MSG'
  end
end

Instance Method Details

#add_charset_fieldObject



71
72
73
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 71

def add_charset_field
  add_field vk_charset_param, vk_charset
end

#add_required_paramsObject



75
76
77
78
79
80
81
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 75

def add_required_params
  required_params = Banklink.required_service_params[@service_msg_number]
  required_params.each do |param|
    param_value = (@options.delete(param) || send(param.to_s.downcase)).to_s
    add_field param, iconv.iconv(param_value)
  end
end

#add_vk_macObject



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

def add_vk_mac
  # Signature used to validate previous parameters
  add_field('VK_MAC', generate_mac(@service_msg_number, form_fields))
end

#amount=(amount) ⇒ Object

Amount can be supplied with a optional dot separator for cents.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 52

def amount=(amount)
  # TODO check this, sooner or later someone will get a wrong amount.

  # If a string is passed to us, don't do anything.
  # If a Money object is passed to us, don't do anything.
  # Otherwise delegate the handling to the money object
  # and free ourself from the responsibility, yay.
  if amount.is_a?(String) || amount.is_a?(Money)
    add_field('VK_AMOUNT', amount)
  else
    add_field('VK_AMOUNT', Money.new(amount).to_s)
  end
end

#default_service_msg_numberObject

Default service message number. Use ‘1002’ because it requires the least amount of parameters.



102
103
104
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 102

def default_service_msg_number
  1002
end

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 25

def initialize(order, , options = {})
  old_valid_keys = [:amount, :currency, :test]
  new_valid_keys = [:description, :reference]
  valid_keys = (old_valid_keys + new_valid_keys + Banklink.required_service_params.values << :service_msg_number).uniq
  options.assert_valid_keys(valid_keys)

  @options = options
  @fields = {}
  self.order = order
  self. = 
  self.amount = options[:amount]
  self.currency = options[:currency]
  self.description = options[:description]
  self.reference = options[:reference]

  if options[:service_msg_number]
    @service_msg_number = options.delete(:service_msg_number)
  else
    @service_msg_number = default_service_msg_number
  end

  add_required_params
  add_charset_field
  add_vk_mac
end

#vk_charsetObject

Default parameters



84
85
86
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 84

def vk_charset
  'ISO-8859-1'
end

#vk_charset_paramObject



88
89
90
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 88

def vk_charset_param
  'VK_CHARSET'
end

#vk_serviceObject



92
93
94
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 92

def vk_service
  @service_msg_number
end

#vk_versionObject



96
97
98
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 96

def vk_version
  '008'
end