Sha256: 6cc7e9a10b1684287aa4cdee4fed949d8d73c59e88394ce5a4b2579d713e66fe

Contents?: true

Size: 1.55 KB

Versions: 42

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Spree
  class PaymentSource < Spree::Base
    self.abstract_class = true

    belongs_to :payment_method

    has_many :payments, as: :source
    has_many :wallet_payment_sources, class_name: 'Spree::WalletPaymentSource', as: :payment_source, inverse_of: :payment_source

    attr_accessor :imported

    # @return [Array<String>] the actions available on this payment source
    def actions
      %w(capture void credit)
    end

    # @param payment [Spree::Payment] the payment we want to know if can be captured
    # @return [Boolean] true when the payment is in the pending or checkout states
    def can_capture?(payment)
      payment.pending? || payment.checkout?
    end

    # @param payment [Spree::Payment] the payment we want to know if can be voided
    # @return [Boolean] true when the payment is not failed or voided
    def can_void?(payment)
      !payment.failed? && !payment.void?
    end

    # Indicates whether its possible to credit the payment.  Note that most
    # gateways require that the payment be settled first which generally
    # happens within 12-24 hours of the transaction.
    #
    # @param payment [Spree::Payment] the payment we want to know if can be credited
    # @return [Boolean] true when the payment is completed and can be credited
    def can_credit?(payment)
      payment.completed? && payment.credit_allowed > 0
    end

    # Indicates whether this payment source can be used more than once. E.g. a
    # credit card with a 'payment profile'.
    def reusable?
      false
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_core-2.9.6 app/models/spree/payment_source.rb
solidus_core-2.8.6 app/models/spree/payment_source.rb
solidus_core-2.9.5 app/models/spree/payment_source.rb
solidus_core-2.9.4 app/models/spree/payment_source.rb
solidus_core-2.6.6 app/models/spree/payment_source.rb
solidus_core-2.7.4 app/models/spree/payment_source.rb
solidus_core-2.8.5 app/models/spree/payment_source.rb
solidus_core-2.9.3 app/models/spree/payment_source.rb
solidus_core-2.9.2 app/models/spree/payment_source.rb
solidus_core-2.7.3 app/models/spree/payment_source.rb
solidus_core-2.6.5 app/models/spree/payment_source.rb
solidus_core-2.9.1 app/models/spree/payment_source.rb
solidus_core-2.9.0 app/models/spree/payment_source.rb
solidus_core-2.9.0.rc.1 app/models/spree/payment_source.rb
solidus_core-2.8.4 app/models/spree/payment_source.rb
solidus_core-2.8.3 app/models/spree/payment_source.rb
solidus_core-2.7.2 app/models/spree/payment_source.rb
solidus_core-2.6.4 app/models/spree/payment_source.rb
solidus_core-2.8.2 app/models/spree/payment_source.rb
solidus_core-2.8.1 app/models/spree/payment_source.rb