feat: implement payout system database schema and models

This commit is contained in:
kbe
2025-09-16 23:52:26 +02:00
parent e5ed1a34dd
commit 0399761fb3
23 changed files with 421 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ class Order < ApplicationRecord
}
before_validation :set_expiry, on: :create
after_update :create_earnings_if_paid, if: -> { saved_change_to_status? && status == "paid" }
# === Instance Methods ===
@@ -159,7 +160,33 @@ class Order < ApplicationRecord
self.expires_at = DRAFT_EXPIRY_TIME.from_now if expires_at.blank?
end
def draft?
status == "draft"
def draft?
status == "draft"
end
def create_earnings_if_paid
return unless event.present? && user.present?
return if event.earnings.exists?(order_id: id)
event.earnings.create!(
user: user,
order: self,
amount_cents: promoter_payout_cents,
fee_cents: platform_fee_cents,
status: :pending
)
end
def create_earnings_if_paid
return unless event.present? && user.present?
return if event.earnings.exists?(order_id: id)
event.earnings.create!(
user: user,
order: self,
amount_cents: promoter_payout_cents,
fee_cents: platform_fee_cents,
status: :pending
)
end
end