Class: ActiveMerchant::Billing::Integrations::WebPay::Helper

Inherits:
Helper
  • Object
show all
Includes:
Common
Defined in:
lib/active_merchant/billing/integrations/web_pay/helper.rb

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods included from Common

#generate_signature, #notify_signature_string, #request_signature_string

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_method, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

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

Returns a new instance of Helper.



8
9
10
11
12
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 8

def initialize(order, , options = {})
  @md5secret = options.delete(:secret)
  @line_item_count = 0
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveMerchant::Billing::Integrations::Helper

Instance Method Details

#add_line_item(options) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 26

def add_line_item(options)
  options.each do |key, value|
    add_field("wsb_invoice_item_#{key}[#{@line_item_count}]", value)
  end

  @line_item_count += 1
end

#calculate_totalObject



34
35
36
37
38
39
40
41
42
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 34

def calculate_total
  sum = 0

  @line_item_count.times do |i|
    sum += @fields["wsb_invoice_item_quantity[#{i}]"].to_i * @fields["wsb_invoice_item_price[#{i}]"].to_i
  end

  sum + @fields[mappings[:tax]].to_i + @fields[mappings[:shipping_price]].to_i - @fields[mappings[:discount_price]].to_i
end

#form_fieldsObject



14
15
16
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 14

def form_fields
  @fields.merge(ActiveMerchant::Billing::Integrations::WebPay.signature_parameter_name => generate_signature(:request))
end

#paramsObject



18
19
20
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 18

def params
  @fields
end

#secretObject



22
23
24
# File 'lib/active_merchant/billing/integrations/web_pay/helper.rb', line 22

def secret
  @md5secret
end