29 lines
820 B
Ruby
29 lines
820 B
Ruby
class Donation < ApplicationRecord
|
|
# Relations
|
|
belongs_to :user
|
|
|
|
# Validations
|
|
validates_presence_of :user
|
|
validates_presence_of :donation_method,
|
|
inclusion: { in: %w[ custom btcpay lndhub ] }
|
|
validates_presence_of :payment_status, allow_nil: true,
|
|
inclusion: { in: %w[ processing settled ] }
|
|
validates_presence_of :paid_at, allow_nil: true
|
|
validates_presence_of :amount_sats, allow_nil: true
|
|
validates_presence_of :fiat_amount, allow_nil: true
|
|
validates_presence_of :fiat_currency, allow_nil: true,
|
|
inclusion: { in: %w[ EUR USD ] }
|
|
|
|
#Scopes
|
|
scope :processing, -> { where(payment_status: "processing") }
|
|
scope :completed, -> { where(payment_status: "settled") }
|
|
|
|
def processing?
|
|
payment_status == "processing"
|
|
end
|
|
|
|
def completed?
|
|
payment_status == "settled"
|
|
end
|
|
end
|