Class: BGS::PaymentService

Inherits:
Object
  • Object
show all
Includes:
SentryLogging
Defined in:
app/services/bgs/payment_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(user) ⇒ PaymentService

Returns a new instance of PaymentService.



9
10
11
12
13
# File 'app/services/bgs/payment_service.rb', line 9

def initialize(user)
  @common_name = user.common_name
  @email = user.email
  @icn = user.icn
end

Instance Attribute Details

#common_nameObject (readonly)

Returns the value of attribute common_name.



7
8
9
# File 'app/services/bgs/payment_service.rb', line 7

def common_name
  @common_name
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'app/services/bgs/payment_service.rb', line 7

def email
  @email
end

#icnObject (readonly)

Returns the value of attribute icn.



7
8
9
# File 'app/services/bgs/payment_service.rb', line 7

def icn
  @icn
end

Instance Method Details

#empty_responseObject (private)



43
44
45
# File 'app/services/bgs/payment_service.rb', line 43

def empty_response
  { payments: { payment: [] } }
end

#external_keyObject (private)



36
37
38
39
40
41
# File 'app/services/bgs/payment_service.rb', line 36

def external_key
  @external_key ||= begin
    key = common_name.presence || email
    key.first(Constants::EXTERNAL_KEY_MAX_LENGTH)
  end
end

#payment_history(person) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/bgs/payment_service.rb', line 15

def payment_history(person)
  response = service.payment_information.retrieve_payment_summary_with_bdn(
    person.participant_id,
    person.file_number,
    '00', # payee code
    person.ssn_number
  )
  return empty_response if response[:payments].nil?

  response
rescue => e
  log_exception_to_sentry(e, { icn: }, { team: Constants::SENTRY_REPORTING_TEAM })
  empty_response if e.message.include?('No Data Found')
end

#serviceObject (private)



32
33
34
# File 'app/services/bgs/payment_service.rb', line 32

def service
  @service ||= BGS::Services.new(external_uid: icn, external_key:)
end