lib/active_merchant/billing/integrations/helper.rb in activemerchant-1.0.3 vs lib/active_merchant/billing/integrations/helper.rb in activemerchant-1.1.0
- old
+ new
@@ -7,12 +7,11 @@
class_inheritable_hash :mappings
class_inheritable_accessor :country_format
self.country_format = :alpha2
def initialize(order, account, options = {})
- valid_keys = [:amount, :currency]
- options.assert_valid_keys(valid_keys)
+ options.assert_valid_keys([:amount, :currency, :test])
@fields = {}
self.order = order
self.account = account
self.amount = options[:amount]
self.currency = options[:currency]
@@ -34,20 +33,28 @@
add_field(field, v) unless field.blank?
end
end
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)
+ add_address(:billing_address, params)
end
+ def shipping_address(params = {})
+ add_address(:shipping_address, params)
+ end
+
def form_fields
@fields
end
private
-
+
+ def add_address(key, params)
+ code = lookup_country_code(params.delete(:country))
+ add_field(mappings[key][:country], code) if mappings[key]
+ add_fields(key, params)
+ end
+
def lookup_country_code(name_or_code)
country = Country.find(name_or_code)
country.code(country_format).to_s
rescue InvalidCountryCodeError
name_or_code