Class: Alma::PaymentResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/alma/payment_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ PaymentResponse

Returns a new instance of PaymentResponse.



5
6
7
8
9
# File 'lib/alma/payment_response.rb', line 5

def initialize(response)
  @raw_response = response
  @response = response.parsed_response
  @success  = response["total_sum"] == 0.0
end

Instance Method Details

#error_messageObject



32
33
34
# File 'lib/alma/payment_response.rb', line 32

def error_message
  @response unless paid?
end

#has_payment_error?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/alma/payment_response.rb', line 20

def has_payment_error?
  !paid?
end

#loggableObject



11
12
13
14
# File 'lib/alma/payment_response.rb', line 11

def loggable
  { uri: @raw_response&.request&.uri.to_s
  }.select { |k, v| !(v.nil? || v.empty?) }
end

#paid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/alma/payment_response.rb', line 16

def paid?
  @success
end

#payment_messageObject



24
25
26
27
28
29
30
# File 'lib/alma/payment_response.rb', line 24

def payment_message
  if paid?
    "Your balance has been paid."
  else
    "There was a problem processing your payment. Please contact the library for assistance."
  end
end