Sha256: 95530f1a6affffb4a22f017205f59a21795f32ae65f0ffa9c6daa26e01313c27

Contents?: true

Size: 1.56 KB

Versions: 10

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

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

    belongs_to :payment_method, optional: true

    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

10 entries across 10 versions & 1 rubygems

Version Path
solidus_core-2.10.5 app/models/spree/payment_source.rb
solidus_core-2.11.3 app/models/spree/payment_source.rb
solidus_core-2.11.2 app/models/spree/payment_source.rb
solidus_core-2.11.1 app/models/spree/payment_source.rb
solidus_core-2.10.3 app/models/spree/payment_source.rb
solidus_core-2.11.0 app/models/spree/payment_source.rb
solidus_core-2.10.2 app/models/spree/payment_source.rb
solidus_core-2.10.1 app/models/spree/payment_source.rb
solidus_core-2.10.0 app/models/spree/payment_source.rb
solidus_core-2.10.0.beta1 app/models/spree/payment_source.rb