Class: ActiveMerchant::Billing::Integrations::Helper
- Inherits:
-
Object
- Object
- ActiveMerchant::Billing::Integrations::Helper
show all
- Defined in:
- lib/active_merchant/billing/integrations/helper.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(order, account, options = {}) ⇒ Helper
Returns a new instance of Helper.
11
12
13
14
15
16
17
18
19
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 11
def initialize(order, account, options = {})
valid_keys = [:amount, :currency]
options.assert_valid_keys(valid_keys)
@fields = {}
self.order = order
self.account = account
self.amount = options[:amount]
self.currency = options[:currency]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 57
def method_missing(method_id, *args)
method_id = method_id.to_s.gsub(/=$/, '').to_sym
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
#fields ⇒ Object
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
21
22
23
24
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 21
def self.mapping(attribute, options = {})
self.mappings ||= {}
self.mappings[attribute] = options
end
|
Instance Method Details
#add_field(name, value) ⇒ Object
26
27
28
29
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 26
def add_field(name, value)
return if name.blank? || value.blank?
@fields[name.to_s] = value.to_s
end
|
#add_fields(subkey, params = {}) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 31
def add_fields(subkey, params = {})
params.each do |k, v|
field = mappings[subkey][k]
add_field(field, v) unless field.blank?
end
end
|
#billing_address(params = {}) ⇒ Object
38
39
40
41
42
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 38
def billing_address(params = {})
code = lookup_country_code(params.delete(:country))
add_field(mappings[:billing_address][:country], code) if mappings[:billing_address]
add_fields(:billing_address, params)
end
|
44
45
46
|
# File 'lib/active_merchant/billing/integrations/helper.rb', line 44
def form_fields
@fields
end
|