feat: implement payout system database schema and models
This commit is contained in:
@@ -16,16 +16,26 @@ class Event < ApplicationRecord
|
||||
sold_out: 3
|
||||
}, default: :draft
|
||||
|
||||
enum :payout_status, {
|
||||
not_requested: 0,
|
||||
requested: 1,
|
||||
processing: 2,
|
||||
completed: 3,
|
||||
failed: 4
|
||||
}, default: :not_requested
|
||||
|
||||
# === Relations ===
|
||||
belongs_to :user
|
||||
has_many :ticket_types
|
||||
has_many :tickets, through: :ticket_types
|
||||
has_many :orders
|
||||
has_many :earnings, dependent: :destroy
|
||||
|
||||
# === Callbacks ===
|
||||
before_validation :geocode_address, if: :should_geocode_address?
|
||||
|
||||
# Validations for Event attributes
|
||||
# === Validations ===
|
||||
|
||||
# Basic information
|
||||
validates :name, presence: true, length: { minimum: 3, maximum: 100 }
|
||||
validates :slug, presence: true, length: { minimum: 3, maximum: 100 }
|
||||
@@ -57,6 +67,32 @@ class Event < ApplicationRecord
|
||||
|
||||
# === Instance Methods ===
|
||||
|
||||
# Payout status enum
|
||||
enum :payout_status, {
|
||||
not_requested: 0,
|
||||
requested: 1,
|
||||
processing: 2,
|
||||
completed: 3,
|
||||
failed: 4
|
||||
}, default: :not_requested
|
||||
|
||||
# Payout methods
|
||||
def can_request_payout?
|
||||
event_ended? && earnings.pending.any? && user.can_receive_payouts?
|
||||
end
|
||||
|
||||
def total_earnings_cents
|
||||
earnings.pending.sum(:amount_cents)
|
||||
end
|
||||
|
||||
def total_fees_cents
|
||||
(total_earnings_cents * 0.1).to_i # 10% platform fee
|
||||
end
|
||||
|
||||
def net_earnings_cents
|
||||
total_earnings_cents - total_fees_cents
|
||||
end
|
||||
|
||||
# Check if coordinates were successfully geocoded or are fallback coordinates
|
||||
def geocoding_successful?
|
||||
coordinates_look_valid?
|
||||
|
||||
Reference in New Issue
Block a user