Sha256: 172badce9a1df82cf422dcf8be636dbcfaa3f5b5bab808e0331c36add97693a6

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

module Spree
  class Check < Spree::Base

    attr_accessor :imported

    belongs_to :payment_method
    belongs_to :user, class_name: Spree.user_class.to_s, foreign_key: 'user_id',
               optional: true
    has_many :payments, as: :source

    scope :with_payment_profile, -> { where.not(gateway_customer_profile_id: nil) }

    validates :account_holder_name, presence: true
    validates :account_holder_type, presence: true, inclusion: { in: %w[Individual Company] }
    validates :account_number, presence: true, numericality: { only_integer: true }
    validates :routing_number, presence: true, numericality: { only_integer: true }

    def has_payment_profile?
      gateway_customer_profile_id.present? || gateway_payment_profile_id.present?
    end

    def actions
      %w[capture void credit]
    end

    def can_capture?(payment)
      payment.pending? || payment.checkout?
    end

    # Indicates whether its possible to void the payment.
    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.
    def can_credit?(payment)
      payment.completed? && payment.credit_allowed > 0
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
spree_gateway-3.11.0 app/models/spree/check.rb
spree_gateway-3.10.0 app/models/spree/check.rb
archetype_spree_gateway-3.9.5.1 app/models/spree/check.rb
archetype_spree_gateway-3.9.5 app/models/spree/check.rb
spree_gateway-3.9.4 app/models/spree/check.rb
spree_gateway-3.9.3 app/models/spree/check.rb
spree_gateway-3.9.2 app/models/spree/check.rb
spree_gateway-3.9.0 app/models/spree/check.rb
spree_gateway-3.8.0 app/models/spree/check.rb