class OffsitePayments::Integrations::Chronopay::Helper

def billing_address(mapping = {})

def billing_address(mapping = {})
  # Gets the country code in the appropriate format or returns what we were given
  # The appropriate format for Chronopay is the alpha 3 country code
  country_code = lookup_country_code(mapping.delete(:country))
  add_field(mappings[:billing_address][:country], country_code)
  countries_with_supported_states = ['USA', 'CAN']
  if !countries_with_supported_states.include?(country_code)
    mapping.delete(:state)
    add_field(mappings[:billing_address][:state], 'XX')
  end
  mapping.each do |k, v|
    field = mappings[:billing_address][k]
    add_field(field, v) unless field.nil?
  end
  add_field('language', checkout_language_from_country(country_code))
end

def checkout_language_from_country(country_code)

def checkout_language_from_country(country_code)
  country    = ActiveUtils::Country.find(country_code)
  short_code = country.code(:alpha2).to_s
  LANG_FOR_COUNTRY[short_code]
rescue ActiveUtils::InvalidCountryCodeError
  'EN'
end

def initialize(order, account, options = {})

def initialize(order, account, options = {})
  super
  add_field('cb_type', 'p')
end