Sha256: 55686fabe85f4768e4520705137c7342028f684900687b9925b2702f5092ebb8

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'bigdecimal'
require 'time'

module Tikkie
  module Api
    module V1
      module Responses
        # Response for a payment request.
        class PaymentRequest < Base
          def payment_request_token
            data[:paymentRequestToken]
          end

          def amount
            decimal = BigDecimal(data[:amountInCents])
            decimal /= 100.0
            decimal
          end

          def currency
            data[:currency]
          end

          def created_at
            Time.parse(data[:created]) if data[:created]
          end

          def expired_at
            Time.parse(data[:expired]) if data[:expired]
          end

          # see PaymentRequestStatus
          def status
            data[:status]
          end

          def expired?
            status == Tikkie::Api::V1::Types::PaymentRequestStatus::EXPIRED
          end

          def bank_account_yielded_too_fast?
            data[:bankAccountYieldedTooFast]
          end

          def external_id
            data[:externalId]
          end

          def payments
            @payments ||= begin
              payments = []

              if data[:payments]
                data[:payments].each do |data|
                  payments << Tikkie::Api::V1::Responses::Payment.new(data)
                end
              end

              payments
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tikkie-api-2.0.0 lib/tikkie/api/v1/responses/payment_request.rb