lib/active_merchant/billing/integrations/banklink/helper.rb in activemerchant_banklink-0.0.5 vs lib/active_merchant/billing/integrations/banklink/helper.rb in activemerchant_banklink-0.0.6

- old
+ new

@@ -21,48 +21,61 @@ mapping :description, 'VK_MSG' end end def initialize(order, account, 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.account = account - self.amount = options[:amount] - self.currency = options[:currency] - self.description = options[:description] - self.reference = options[:reference] + @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.account = account + 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 + def add_field(name, value) + return if name.blank? + @fields[name.to_s] = value.to_s + end + # Amount can be supplied with a optional dot separator for cents. 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).to_s) - end + #if amount.is_a?(String) || amount.is_a?(Money) + # add_field('VK_AMOUNT', amount) + #else + # add_field('VK_AMOUNT', Money.new(amount)) + #end end def add_vk_mac # Signature used to validate previous parameters add_field('VK_MAC', generate_mac(@service_msg_number, form_fields)) @@ -71,10 +84,10 @@ def add_charset_field add_field vk_charset_param, vk_charset end def add_required_params - required_params = Banklink.required_service_params[@service_msg_number] + 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