Module: Inpay::Helpers::Common

Defined in:
lib/inpay/helpers/common.rb

Instance Method Summary collapse

Instance Method Details

#inpay_fields(fields = {}) ⇒ Object



37
38
39
40
41
# File 'lib/inpay/helpers/common.rb', line 37

def inpay_fields fields = {}
  fields.collect do |key, value|
    %Q{<input type="hidden" name="#{ key }" value="#{ value }" />}
  end.join("\n")
end

#inpay_flow_urlObject

nice option for form url



6
7
8
# File 'lib/inpay/helpers/common.rb', line 6

def inpay_flow_url
  Inpay::Config.flow_url
end

#inpay_setup(amount, options) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/inpay/helpers/common.rb', line 10

def inpay_setup amount, options
  misses = (options.keys - valid_invoice_options)
  misses.delete_if { |option| option.to_s.match(/^extra_/) }
  
  raise ArgumentError, "Unknown options #{ misses.inspect }" unless misses.empty?
  
  params = {
    :currency     => :EUR,
    :flow_layout  => :multi_page
  }.merge(options)
  
  # fetch currency from amount if a Money object is passed
  params[:currency] = amount.currency if amount.respond_to?(:currency)
  
  # accept both strings and Money objects as amount
  amount = amount.cents.to_f / 100.0 if amount.respond_to?(:cents)
  params[:amount] = sprintf('%.2f', amount)
  
  # add checksum
  params[:checksum] = Inpay.checksum(:create_invoice, params)
  
  params.delete(:secret_key)
  
  # build form
  inpay_fields(params)
end