class RailsOgone::Form

Attributes

hash[R]

Public Class Methods

new(environment = 'test') click to toggle source
# File lib/rails-ogone/form.rb, line 5
def initialize(environment = 'test')
  @environment = environment == 'production' ? 'prod' : 'test'
  @form_fields = {}
  @hash = RailsOgone::Hash.new
end

Public Instance Methods

action_url(options = {}) click to toggle source
# File lib/rails-ogone/form.rb, line 11
def action_url(options = {})
  options.reverse_merge!(utf8: false)
  page = options[:utf8] ? 'orderstandard_utf8' : 'orderstandard'
  "https://secure.ogone.com/ncol/#{@environment}/#{page}.asp"
end
hidden_field(name, value) click to toggle source
# File lib/rails-ogone/form.rb, line 41
def hidden_field(name, value)
  input 'hidden', name, value
end
input(type, name, value) click to toggle source
# File lib/rails-ogone/form.rb, line 17
def input(type, name, value)
  value = (value.to_f * 100).to_i if name.downcase == 'amount'
  @form_fields[name] = value
  @hash.add_parameter name, value
  html_string = "<input type=\"%s\" name=\"%s\" value=\"%s\" />" % [type, name.upcase, value]
  ActiveSupport::SafeBuffer.new html_string
end
radio_button(name, value) click to toggle source
# File lib/rails-ogone/form.rb, line 25
def radio_button(name, value)
  input 'radio', name, value
end
tag(options = {}) click to toggle source
# File lib/rails-ogone/form.rb, line 29
def tag(options = {})
  options.reverse_merge!(utf8: false)
  options[:action] = action_url(utf8: options[:utf8])

  form_attributes = options.except(:utf8).inject('') do |attributes, pair|
    attributes << " #{pair[0]}=\"#{pair[1]}\""
  end

  output = "<form method=\"post\"#{form_attributes}>"
  ActiveSupport::SafeBuffer.new output
end