Sha256: 1f4dd22df44db4c38fd0c9111947bdb333f223f099ec03ae3f1f168404b4a1c7

Contents?: true

Size: 707 Bytes

Versions: 8

Compression:

Stored size: 707 Bytes

Contents

# frozen_string_literal: true

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

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

    def paid?
      @success
    end

    def has_payment_error?
      !paid?
    end

    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

    def error_message
      @response unless paid?
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alma-0.6.2 lib/alma/payment_response.rb
alma-0.6.1 lib/alma/payment_response.rb
alma-0.6.0 lib/alma/payment_response.rb
alma-0.5.1 lib/alma/payment_response.rb
alma-0.5.0 lib/alma/payment_response.rb
alma-0.4.2 lib/alma/payment_response.rb
alma-0.4.1 lib/alma/payment_response.rb
alma-0.4.0 lib/alma/payment_response.rb