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

Included in:
DnbNordLtu::Helper, SampoEst::Helper, SebEst::Helper, SebLtu::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



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

def add_charset_field
  add_field vk_charset_param, vk_charset
end

#add_field(name, value) ⇒ Object



54
55
56
57
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 54

def add_field(name, value)
  return if name.blank?
  @fields[name.to_s] = value.to_s
end

#add_required_paramsObject



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

def add_required_params
  required_params = 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



79
80
81
82
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 79

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.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 60

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

  amount = Money.new(amount) unless amount.is_a?(Money)
  amount = "%0.2f" % amount

  add_field('VK_AMOUNT', 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))
  #end
end

#default_service_msg_numberObject

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



115
116
117
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 115

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
50
51
52
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 25

def initialize(order, , options = {})
  @options = options
  @fields = ActiveSupport::OrderedHash.new
  @raw_html_fields = []

  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

  self.order = order
  self. = 
  self.amount = options[:amount]
  self.currency = options[:currency]
  self.description = options[:description]
  self.reference = options[:reference]

  old_valid_keys = [:amount, :currency, :test]
  new_valid_keys = [:description, :reference]
  valid_keys = (old_valid_keys + new_valid_keys + required_service_params[@service_msg_number] << :service_msg_number).uniq
  options.assert_valid_keys(valid_keys)

  add_charset_field
  add_vk_mac
end

#vk_charsetObject

Default parameters



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

def vk_charset
  'ISO-8859-1'
end

#vk_charset_paramObject



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

def vk_charset_param
  'VK_CHARSET'
end

#vk_serviceObject



105
106
107
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 105

def vk_service
  @service_msg_number
end

#vk_versionObject



109
110
111
# File 'lib/active_merchant/billing/integrations/banklink/helper.rb', line 109

def vk_version
  '008'
end