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

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

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_merchant/billing/integrations/helper.rb', line 16

def initialize(order, , options = {})
  options.assert_valid_keys([:amount, :currency, :test, :credential2, :credential3, :credential4, :country, :account_name, :transaction_type, :authcode])
  @fields          = {}
  @raw_html_fields = []
  @test            = options[:test]
  self.order       = order
  self.     = 
  self.amount      = options[:amount]
  self.currency    = options[:currency]
  self.credential2 = options[:credential2]
  self.credential3 = options[:credential3]
  self.credential4 = options[:credential4]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args) ⇒ Object (private)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/active_merchant/billing/integrations/helper.rb', line 95

def method_missing(method_id, *args)
  method_id = method_id.to_s.gsub(/=$/, '').to_sym
  # Return and do nothing if the mapping was not found. This allows 
  # For easy substitution of the different integrations
  return if mappings[method_id].nil?

  mapping = mappings[method_id]

  case mapping
  when Array
    mapping.each{ |field| add_field(field, args.last) }
  when Hash
    options = args.last.is_a?(Hash) ? args.pop : {}

    mapping.each{ |key, field| add_field(field, options[key]) }
  else
    add_field(mapping, args.last)
  end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields



5
6
7
# File 'lib/active_merchant/billing/integrations/helper.rb', line 5

def fields
  @fields
end

Class Method Details

.mapping(attribute, options = {}) ⇒ Object



30
31
32
33
# File 'lib/active_merchant/billing/integrations/helper.rb', line 30

def self.mapping(attribute, options = {})
  self.mappings ||= {}
  self.mappings[attribute] = options
end

Instance Method Details

#add_field(name, value) ⇒ Object



35
36
37
38
# File 'lib/active_merchant/billing/integrations/helper.rb', line 35

def add_field(name, value)
  return if name.blank? || value.blank?
  @fields[name.to_s] = value.to_s
end

#add_fields(subkey, params = {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/active_merchant/billing/integrations/helper.rb', line 40

def add_fields(subkey, params = {})
  params.each do |k, v|
    field = mappings[subkey][k]
    add_field(field, v) unless field.blank?
  end
end

#add_raw_html_field(name, value) ⇒ Object

Add a field that has characters that CGI::escape would mangle. Allows for multiple fields with the same name (e.g., to support line items).



49
50
51
52
# File 'lib/active_merchant/billing/integrations/helper.rb', line 49

def add_raw_html_field(name, value)
  return if name.blank? || value.blank?
  @raw_html_fields << [name, value]
end

#billing_address(params = {}) ⇒ Object



58
59
60
# File 'lib/active_merchant/billing/integrations/helper.rb', line 58

def billing_address(params = {})
  add_address(:billing_address, params)
end

#form_fieldsObject



66
67
68
# File 'lib/active_merchant/billing/integrations/helper.rb', line 66

def form_fields
  @fields
end

#form_methodObject



74
75
76
# File 'lib/active_merchant/billing/integrations/helper.rb', line 74

def form_method
  "POST"
end

#raw_html_fieldsObject



54
55
56
# File 'lib/active_merchant/billing/integrations/helper.rb', line 54

def raw_html_fields
  @raw_html_fields
end

#shipping_address(params = {}) ⇒ Object



62
63
64
# File 'lib/active_merchant/billing/integrations/helper.rb', line 62

def shipping_address(params = {})
  add_address(:shipping_address, params)
end

#test?Boolean



70
71
72
# File 'lib/active_merchant/billing/integrations/helper.rb', line 70

def test?
  @test_mode ||= ActiveMerchant::Billing::Base.integration_mode == :test || @test
end