2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
# A Charge represents a potential debit to a nonprofit's account on a credit card donation action.
|
|
|
|
|
2019-02-01 19:40:24 +00:00
|
|
|
class Charge < ApplicationRecord
|
2019-08-06 12:49:40 +00:00
|
|
|
# :amount,
|
|
|
|
# :fee,
|
|
|
|
# :stripe_charge_id,
|
|
|
|
# :status
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
has_one :campaign, through: :donation
|
|
|
|
has_one :recurring_donation, through: :donation
|
|
|
|
has_many :tickets
|
|
|
|
has_many :events, through: :tickets
|
|
|
|
has_many :refunds
|
|
|
|
has_many :disputes
|
|
|
|
belongs_to :supporter
|
|
|
|
belongs_to :card
|
|
|
|
belongs_to :direct_debit_detail
|
|
|
|
belongs_to :nonprofit
|
|
|
|
belongs_to :donation
|
|
|
|
belongs_to :payment
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
scope :paid, -> { where(status: %w[available pending disbursed]) }
|
|
|
|
scope :not_paid, -> { where(status: [nil, 'failed']) }
|
|
|
|
scope :available, -> { where(status: 'available') }
|
|
|
|
scope :pending, -> { where(status: 'pending') }
|
|
|
|
scope :disbursed, -> { where(status: 'disbursed') }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
def paid?
|
|
|
|
status.in?(%w[available pending disbursed])
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|