Sha256: 5dfaea18c5b629399e0bc60ef41cb5269f10139169fa3ec8757f4673602d4e32

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Kaui
  module PaymentState
    def refundable?
      transactions.each do |transaction|
        return true if transaction.status == 'SUCCESS' && %w[CAPTURE PURCHASE].include?(transaction.transaction_type)
      end
      false
    end

    def amount_refundable
      captured_amount + purchased_amount - refunded_amount
    end

    def amount_capturable
      auth_amount - captured_amount
    end

    def capturable?
      maybe = false
      transactions.each do |transaction|
        next unless transaction.status == 'SUCCESS'
        return false if transaction.transaction_type == 'VOID'

        maybe = true if transaction.transaction_type == 'AUTHORIZE'
      end
      maybe && refunded_amount.zero?
    end

    def voidable?
      transactions.each do |transaction|
        return false if transaction.status == 'SUCCESS' && transaction.transaction_type == 'VOID'
      end
      capturable? && captured_amount.zero?
    end

    def chargebackable?
      refundable?
    end

    def total_authed_amount_to_money
      auth_amount_to_money + purchased_amount_to_money
    end

    def paid_amount_to_money
      captured_amount_to_money + purchased_amount_to_money
    end

    # TODO: Better name?
    def returned_amount_to_money
      refunded_amount_to_money + credited_amount_to_money
    end

    def fully_refunded?
      refunded_amount == captured_amount || refunded_amount == purchased_amount
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kaui-3.0.5 app/models/kaui/payment_state.rb
kaui-3.0.4 app/models/kaui/payment_state.rb
kaui-3.0.2 app/models/kaui/payment_state.rb
kaui-2.2.1 app/models/kaui/payment_state.rb
kaui-3.0.1 app/models/kaui/payment_state.rb