Sha256: f781bc9583d596ee1c2ffdc6f59e0e4bb5c7563f8ebe6f642b7aabaa356e66e9

Contents?: true

Size: 1.96 KB

Versions: 19

Compression:

Stored size: 1.96 KB

Contents

module Spree
  class PaymentMethod < Spree::Base
    acts_as_paranoid
    acts_as_list

    DISPLAY = [:both, :front_end, :back_end].freeze

    scope :active,                 -> { where(active: true) }
    scope :available,              -> { active.where(display_on: [:front_end, :back_end, :both]) }
    scope :available_on_front_end, -> { active.where(display_on: [:front_end, :both]) }
    scope :available_on_back_end,  -> { active.where(display_on: [:back_end, :both]) }

    validates :name, presence: true

    has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method
    has_many :credit_cards, class_name: "Spree::CreditCard"

    def self.providers
      Rails.application.config.spree.payment_methods
    end

    def provider_class
      raise ::NotImplementedError, 'You must implement provider_class method for this gateway.'
    end

    # The class that will process payments for this payment type, used for @payment.source
    # e.g. CreditCard in the case of a the Gateway payment type
    # nil means the payment method doesn't require a source e.g. check
    def payment_source_class
      raise ::NotImplementedError, 'You must implement payment_source_class method for this gateway.'
    end

    def method_type
      type.demodulize.downcase
    end

    def self.find_with_destroyed *args
      unscoped { find(*args) }
    end

    def payment_profiles_supported?
      false
    end

    def source_required?
      true
    end

    # Custom gateways should redefine this method. See Gateway implementation
    # as an example
    def reusable_sources(order)
      []
    end

    def auto_capture?
      self.auto_capture.nil? ? Spree::Config[:auto_capture] : self.auto_capture
    end

    def supports?(source)
      true
    end

    def cancel(response)
      raise ::NotImplementedError, 'You must implement cancel method for this payment method.'
    end

    def store_credit?
      self.class == Spree::PaymentMethod::StoreCredit
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
spree_core-3.1.14 app/models/spree/payment_method.rb
spree_core-3.1.13 app/models/spree/payment_method.rb
spree_core-3.1.12 app/models/spree/payment_method.rb
spree_core-3.1.11 app/models/spree/payment_method.rb
spree_core-3.1.10 app/models/spree/payment_method.rb
spree_core-3.1.9 app/models/spree/payment_method.rb
spree_core-3.1.8 app/models/spree/payment_method.rb
spree_core-3.1.7 app/models/spree/payment_method.rb
spree_core-3.1.6 app/models/spree/payment_method.rb
spree_core-3.1.5 app/models/spree/payment_method.rb
spree_core-3.1.4 app/models/spree/payment_method.rb
spree_core-3.1.3 app/models/spree/payment_method.rb
spree_core-3.1.2 app/models/spree/payment_method.rb
spree_core-3.1.1 app/models/spree/payment_method.rb
spree_core-3.1.0 app/models/spree/payment_method.rb
spree_core-3.1.0.rc4 app/models/spree/payment_method.rb
spree_core-3.1.0.rc3 app/models/spree/payment_method.rb
spree_core-3.1.0.rc2 app/models/spree/payment_method.rb
spree_core-3.1.0.rc1 app/models/spree/payment_method.rb