class Microbilt::Customer

Constants

VALID_ACCOUNT_TYPES

Attributes

account_type[RW]
address1[RW]
address2[RW]
bank_account[RW]
bank_transit[RW]
city[RW]
completion_email[RW]
country[RW]
date_of_birth[RW]
direct_deposit_amount[RW]
direct_deposit_pay_cycle[RW]
email[RW]
first_name[RW]
home_phone[RW]
last_name[RW]
mobile_phone[RW]
sin[RW]
state[RW]
work_phone[RW]
zip_code[RW]

Public Class Methods

new(options = nil) click to toggle source
# File lib/microbilt/customer.rb, line 18
def initialize(options = nil)
  options.keys.each do |k|
    self.send("#{k}=", options[k])
  end if options
end

Public Instance Methods

to_params() click to toggle source
# File lib/microbilt/customer.rb, line 24
def to_params
  {
    'Customer.FirstName' => first_name,
    'Customer.LastName' => last_name,
    'Customer.SSN' => formatted_sin,
    'Customer.DOB' => formatted_date(date_of_birth),
    'Customer.Address' => formatted_address,
    'Customer.City' => city,
    'Customer.State' => state,
    'Customer.ZIP' => formatted_zip,
    'Customer.Country' => formatted_country,
    'Customer.Phone' => formatted_phone(home_phone),
    'Customer.WorkPhone' => formatted_phone(work_phone),
    'Customer.CellPhone' => formatted_phone(mobile_phone),
    'Customer.Email' => formatted_email,
    'Customer.ABAnumber' => bank_transit,
    'Customer.AccountNumber' => bank_account,
    'Customer.DirectDepositAmount' => direct_deposit_amount,
    'Customer.DirectDepositPayCycle' => formatted_direct_deposit_pay_cycle,
    'Customer.CompletionEmail' => completion_email,
    'Customer.AccountType' => formatted_account_type
  }
end

Private Instance Methods

formatted_account_type() click to toggle source
# File lib/microbilt/customer.rb, line 98
def formatted_account_type
  account_type_code = VALID_ACCOUNT_TYPES[account_type]

  if !account_type_code.nil?
    account_type_code
  elsif !account_type.nil?
    raise ArgumentError.new "Invalid account type: #{account_type}"
  else
    nil
  end
end
formatted_address() click to toggle source
# File lib/microbilt/customer.rb, line 54
def formatted_address
  address = address1
  address += "\n, " + address2 unless address2.to_s.empty?
  address
end
formatted_country() click to toggle source
# File lib/microbilt/customer.rb, line 72
def formatted_country
  case country.upcase
  when 'CA'
    'CAN'
  when 'US'
    'USA'
  else
    raise ArgumentError.new "Unknown country '#{country}'"
  end
end
formatted_date(d) click to toggle source
# File lib/microbilt/customer.rb, line 50
def formatted_date(d)
  d.strftime('%m%d%Y')
end
formatted_direct_deposit_pay_cycle() click to toggle source
# File lib/microbilt/customer.rb, line 83
def formatted_direct_deposit_pay_cycle
  case direct_deposit_pay_cycle.to_s
  when 'weekly'
    'Every week'
  when 'biweekly'
    'Every other week'
  when 'twicemonthly'
    'Two times a month'
  when 'monthly'
    'Once a month'
  else
    direct_deposit_pay_cycle.to_s
  end
end
formatted_email(address = email) click to toggle source
# File lib/microbilt/customer.rb, line 68
def formatted_email(address = email)
  address.downcase.strip
end
formatted_phone(phone) click to toggle source
# File lib/microbilt/customer.rb, line 64
def formatted_phone(phone)
  phone.to_s.gsub(/[^0-9]/i, '')[0..9]
end
formatted_sin() click to toggle source
# File lib/microbilt/customer.rb, line 110
def formatted_sin
  sin.to_s.gsub(/[^0-9]/i, '')
end
formatted_zip() click to toggle source
# File lib/microbilt/customer.rb, line 60
def formatted_zip
  zip_code.to_s.gsub(/[^0-9a-z]/i, '')
end