Class: Fe::Payment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/fe/payment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def address
  @address
end

#card_numberObject

Returns the value of attribute card_number.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def card_number
  @card_number
end

#card_typeObject

Returns the value of attribute card_type.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def card_type
  @card_type
end

#cityObject

Returns the value of attribute city.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def city
  @city
end

#expiration_monthObject

Returns the value of attribute expiration_month.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def expiration_month
  @expiration_month
end

#expiration_yearObject

Returns the value of attribute expiration_year.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def expiration_year
  @expiration_year
end

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def first_name
  @first_name
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def last_name
  @last_name
end

#security_codeObject

Returns the value of attribute security_code.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def security_code
  @security_code
end

#staff_firstObject

Returns the value of attribute staff_first.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def staff_first
  @staff_first
end

#staff_lastObject

Returns the value of attribute staff_last.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def staff_last
  @staff_last
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def state
  @state
end

#zipObject

Returns the value of attribute zip.



5
6
7
# File 'app/models/fe/payment.rb', line 5

def zip
  @zip
end

Instance Method Details

#answer_sheetObject



17
# File 'app/models/fe/payment.rb', line 17

def answer_sheet() application; end

#approve!Object



64
65
66
67
68
# File 'app/models/fe/payment.rb', line 64

def approve!
  self.status = 'Approved'
  self.auth_code ||= card_number[-4..-1] if card_number.present?
  self.save!
end

#approved?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/fe/payment.rb', line 60

def approved?
  self.status == 'Approved'
end

#check_app_completeObject



46
47
48
49
50
# File 'app/models/fe/payment.rb', line 46

def check_app_complete
  if self.approved?
    self.answer_sheet.complete
  end
end

#credit?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/fe/payment.rb', line 52

def credit?
  self.payment_type == 'Credit Card'
end

#credit_card_validationObject



19
20
21
22
23
24
25
# File 'app/models/fe/payment.rb', line 19

def credit_card_validation
  if credit?
    errors.add_on_empty([:first_name, :last_name, :address, :city, :state, :zip, :card_number,
                         :expiration_month, :expiration_year, :security_code])
    errors.add(:card_number, "is invalid.") if get_card_type.nil?
  end
end

#get_card_typeObject



70
71
72
73
74
# File 'app/models/fe/payment.rb', line 70

def get_card_type
  card =  ActiveMerchant::Billing::CreditCard.new(:number => card_number)
  card.valid?
  card.brand
end

#staff?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/fe/payment.rb', line 56

def staff?
  self.payment_type == 'Staff'
end

#staff_email_present_if_staff_paymentObject

TODO move all staff methods to decorators as per instructions from Josh



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/fe/payment.rb', line 28

def staff_email_present_if_staff_payment
  if staff? && !.include?('/') # Don't try to validate chart fields
    staff = Staff.find_by(accountNo: )
    unless staff
      errors.add(:base, "We couldn't find a staff member with that account number")
      return false
    end

    unless staff.email.present?
      errors.add(:base, "The staff member you've picked doesn't have an address on file for us to send the request to.")
    end
  end
end

#to_sObject



42
43
44
# File 'app/models/fe/payment.rb', line 42

def to_s
  "#{payment_type}: #{amount} on #{created_at}"
end