Class: DebtManagementCenter::PaymentsService
- Inherits:
-
Object
- Object
- DebtManagementCenter::PaymentsService
- Includes:
- SentryLogging
- Defined in:
- lib/debt_management_center/payments_service.rb
Instance Method Summary collapse
-
#compensation_and_pension ⇒ Array<Hash>?
Returns a list of BGS Payment Hashes filtered by :payment_type == ‘Compensation & Pension - Recurring’ and sorted by :payment_date, ascending.
-
#education ⇒ Array<Hash>?
Returns a list of BGS Payment Hashes filtered by :payment_type == ‘Post-9/11 GI Bill’ and sorted by :payment_date, ascending.
-
#initialize(current_user) ⇒ DebtManagementCenter::PaymentsService
constructor
Retrieves the person and payments data, from BGS, that relates to the provided user.
- #report_error(error) ⇒ Object private
- #select_payments(type) ⇒ Object private
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(current_user) ⇒ DebtManagementCenter::PaymentsService
Retrieves the person and payments data, from BGS, that relates to the provided user.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/debt_management_center/payments_service.rb', line 14 def initialize(current_user) @person = begin BGS::People::Request.new.find_person_by_participant_id(user: current_user) rescue => e report_error(e) {} end @payments = begin BGS::PaymentService.new(current_user).payment_history(@person)[:payments][:payment].presence || [] rescue => e report_error(e) [] end end |
Instance Method Details
#compensation_and_pension ⇒ Array<Hash>?
Returns a list of BGS Payment Hashes filtered by :payment_type == ‘Compensation & Pension - Recurring’ and sorted by :payment_date, ascending.
Pending payments (where :payment_date == nil) are not included in the result.
40 41 42 |
# File 'lib/debt_management_center/payments_service.rb', line 40 def compensation_and_pension select_payments :compensation end |
#education ⇒ Array<Hash>?
Returns a list of BGS Payment Hashes filtered by :payment_type == ‘Post-9/11 GI Bill’ and sorted by :payment_date, ascending.
Pending payments (where :payment_date == nil) are not included in the result.
52 53 54 |
# File 'lib/debt_management_center/payments_service.rb', line 52 def education select_payments :education end |
#report_error(error) ⇒ Object (private)
79 80 81 82 83 84 85 |
# File 'lib/debt_management_center/payments_service.rb', line 79 def report_error(error) log_exception_to_sentry( error, {}, { team: 'vfs-debt' } ) end |
#select_payments(type) ⇒ Object (private)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/debt_management_center/payments_service.rb', line 58 def select_payments(type) return nil if @payments.blank? type = case type when :compensation 'Compensation & Pension - Recurring' when :education 'Post-9/11 GI Bill' end selected_payments = @payments.select do |payment| payment[:payment_type] == type && payment[:payment_date].present? end if selected_payments.empty? nil else selected_payments.sort { |a, b| a[:payment_date] <=> b[:payment_date] } end end |