Class: Banklink::Seb::Helper

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/banklink/seb/helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#encode_to_utf8, #func_p, #generate_data_string, #generate_mac, #generate_signature, #parse

Constructor Details

#initialize(transaction, account, options = {}) ⇒ Helper

Returns a new instance of Helper.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/banklink/seb/helper.rb', line 7

def initialize(transaction, , options = {})

  @options = options
  @fields = {}

  @options['IB_SND_ID'] = 
  @options['IB_PAYMENT_ID'] = transaction
  @options['IB_AMOUNT'] = options[:amount]
  @options['IB_CURR'] = options[:currency] || "EUR"
  @options['IB_FEEDBACK'] = options[:return]
  @options['IB_NAME'] = options[:name] || "Company"
  @options['IB_PAYMENT_DESC'] = options[:message]
  @options['IB_LANG'] = options[:lang] if options[:lang]

  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_ib_crc

  add_lang_field
  add_return_url_field
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



4
5
6
# File 'lib/banklink/seb/helper.rb', line 4

def fields
  @fields
end

Class Method Details

.mapping(attribute, options = {}) ⇒ Object



39
40
41
42
# File 'lib/banklink/seb/helper.rb', line 39

def self.mapping(attribute, options = {})
  self.mappings ||= {}
  self.mappings[attribute] = options
end

Instance Method Details

#add_field(name, value) ⇒ Object



44
45
46
47
# File 'lib/banklink/seb/helper.rb', line 44

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

#add_ib_crcObject



49
50
51
52
# File 'lib/banklink/seb/helper.rb', line 49

def add_ib_crc
  # Signature used to validate previous parameters
  add_field('IB_CRC', generate_mac(@service_msg_number, form_fields, Seb.required_service_params))
end

#add_lang_fieldObject



58
59
60
61
62
63
64
# File 'lib/banklink/seb/helper.rb', line 58

def add_lang_field
  if @options['IB_LANG']
    add_field(ib_lang_param, @options['IB_LANG'])
  else
    add_field ib_lang_param, ib_lang
  end
end

#add_required_paramsObject



66
67
68
69
70
71
72
# File 'lib/banklink/seb/helper.rb', line 66

def add_required_params
  required_params = Seb.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, encode_to_utf8(param_value)
  end
end

#add_return_url_fieldObject



54
55
56
# File 'lib/banklink/seb/helper.rb', line 54

def add_return_url_field
  add_field('IB_FEEDBACK', @options['IB_FEEDBACK'])
end

#default_service_msg_numberObject

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



96
97
98
# File 'lib/banklink/seb/helper.rb', line 96

def default_service_msg_number
  "0002"
end

#form_fieldsObject



35
36
37
# File 'lib/banklink/seb/helper.rb', line 35

def form_fields
  @fields
end

#ib_langObject



74
75
76
# File 'lib/banklink/seb/helper.rb', line 74

def ib_lang
  'LAT'
end

#ib_lang_paramObject



78
79
80
# File 'lib/banklink/seb/helper.rb', line 78

def ib_lang_param
  'IB_LANG'
end

#ib_serviceObject



82
83
84
# File 'lib/banklink/seb/helper.rb', line 82

def ib_service
  @service_msg_number
end

#ib_versionObject



86
87
88
# File 'lib/banklink/seb/helper.rb', line 86

def ib_version
  '001'
end

#redirect_urlObject



90
91
92
# File 'lib/banklink/seb/helper.rb', line 90

def redirect_url
  Seb.service_url
end