Class: MerbMerchant::Billing::Integrations::Helper
- Inherits:
-
Object
- Object
- MerbMerchant::Billing::Integrations::Helper
show all
- Defined in:
- lib/merb_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.
16
17
18
19
20
21
22
23
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 16
def initialize(order, account, options = {})
options.assert_valid_keys([:amount, :currency, :test])
@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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 71
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/merb_merchant/billing/integrations/helper.rb', line 5
def fields
@fields
end
|
Class Method Details
.mapping(attribute, options = {}) ⇒ Object
25
26
27
28
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 25
def self.mapping(attribute, options = {})
self.mappings ||= {}
self.mappings[attribute] = options
end
|
Instance Method Details
#add_field(name, value) ⇒ Object
30
31
32
33
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 30
def add_field(name, value)
return if name.blank? || value.blank?
@fields[name.to_s] = value.to_s
end
|
#add_fields(subkey, params = {}) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 35
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
42
43
44
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 42
def billing_address(params = {})
add_address(:billing_address, params)
end
|
50
51
52
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 50
def form_fields
@fields
end
|
#shipping_address(params = {}) ⇒ Object
46
47
48
|
# File 'lib/merb_merchant/billing/integrations/helper.rb', line 46
def shipping_address(params = {})
add_address(:shipping_address, params)
end
|