Class: Paysio::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/paysio/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Form

Returns a new instance of Form.



5
6
7
8
9
10
# File 'lib/paysio/form.rb', line 5

def initialize(params = {})
  @params = params
  @values = {}
  @errors = {}
  @html_options = {}
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/paysio/form.rb', line 3

def errors
  @errors
end

#html_optionsObject

Returns the value of attribute html_options.



3
4
5
# File 'lib/paysio/form.rb', line 3

def html_options
  @html_options
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/paysio/form.rb', line 3

def params
  @params
end

#valuesObject

Returns the value of attribute values.



3
4
5
# File 'lib/paysio/form.rb', line 3

def values
  @values
end

Instance Method Details

#add_params(params = {}) ⇒ Object



12
13
14
# File 'lib/paysio/form.rb', line 12

def add_params(params = {})
  self.params.merge!(params)
end

#renderObject



16
17
18
# File 'lib/paysio/form.rb', line 16

def render
  "#{render_html} #{render_javascript}".html_safe
end

#render_htmlObject



30
31
32
33
34
35
36
37
38
# File 'lib/paysio/form.rb', line 30

def render_html
  html = <<-TEXT
    <form id="#{html_options[:id] || 'paysio'}"
          class="#{html_options[:class]}"
          action="#{html_options[:action] || '#'}"
          method="#{(html_options[:method] || 'post').upcase}"
    ></form>
  TEXT
end

#render_javascriptObject



20
21
22
23
24
25
26
27
28
# File 'lib/paysio/form.rb', line 20

def render_javascript
  html = <<-TEXT
    <script type="text/javascript">
      Paysio.setEndpoint('#{Paysio.api_url}');
      Paysio.setPublishableKey("#{Paysio.publishable_key}");
      Paysio.form.build(#{javascript_form_params});
    </script>
  TEXT
end