Class: Fe::Payment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Fe::Payment
- Defined in:
- app/models/fe/payment.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#card_number ⇒ Object
Returns the value of attribute card_number.
-
#card_type ⇒ Object
Returns the value of attribute card_type.
-
#city ⇒ Object
Returns the value of attribute city.
-
#expiration_month ⇒ Object
Returns the value of attribute expiration_month.
-
#expiration_year ⇒ Object
Returns the value of attribute expiration_year.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#security_code ⇒ Object
Returns the value of attribute security_code.
-
#staff_first ⇒ Object
Returns the value of attribute staff_first.
-
#staff_last ⇒ Object
Returns the value of attribute staff_last.
-
#state ⇒ Object
Returns the value of attribute state.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #answer_sheet ⇒ Object
- #approve! ⇒ Object
- #approved? ⇒ Boolean
- #check_app_complete ⇒ Object
- #credit? ⇒ Boolean
- #credit_card_validation ⇒ Object
- #get_card_type ⇒ Object
- #staff? ⇒ Boolean
-
#staff_email_present_if_staff_payment ⇒ Object
TODO move all staff methods to decorators as per instructions from Josh.
- #to_s ⇒ Object
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'app/models/fe/payment.rb', line 5 def address @address end |
#card_number ⇒ Object
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_type ⇒ Object
Returns the value of attribute card_type.
5 6 7 |
# File 'app/models/fe/payment.rb', line 5 def card_type @card_type end |
#city ⇒ Object
Returns the value of attribute city.
5 6 7 |
# File 'app/models/fe/payment.rb', line 5 def city @city end |
#expiration_month ⇒ Object
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_year ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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_code ⇒ Object
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_first ⇒ Object
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_last ⇒ Object
Returns the value of attribute staff_last.
5 6 7 |
# File 'app/models/fe/payment.rb', line 5 def staff_last @staff_last end |
#state ⇒ Object
Returns the value of attribute state.
5 6 7 |
# File 'app/models/fe/payment.rb', line 5 def state @state end |
#zip ⇒ Object
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_sheet ⇒ Object
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
60 61 62 |
# File 'app/models/fe/payment.rb', line 60 def approved? self.status == 'Approved' end |
#check_app_complete ⇒ Object
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
52 53 54 |
# File 'app/models/fe/payment.rb', line 52 def credit? self.payment_type == 'Credit Card' end |
#credit_card_validation ⇒ Object
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_type ⇒ Object
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
56 57 58 |
# File 'app/models/fe/payment.rb', line 56 def staff? self.payment_type == 'Staff' end |
#staff_email_present_if_staff_payment ⇒ Object
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? && !payment_account_no.include?('/') # Don't try to validate chart fields staff = Staff.find_by(accountNo: payment_account_no) 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_s ⇒ Object
42 43 44 |
# File 'app/models/fe/payment.rb', line 42 def to_s "#{payment_type}: #{amount} on #{created_at}" end |