fix : ticket order new

This commit is contained in:
kbe
2025-09-17 16:34:41 +02:00
parent 8103629370
commit 70aa9e9e2a
13 changed files with 96 additions and 90 deletions

View File

@@ -4,14 +4,7 @@ class Order < ApplicationRecord
MAX_PAYMENT_ATTEMPTS = 3
# === Enums ===
enum :status, {
draft: 0,
pending_payment: 1,
paid: 2,
completed: 3,
cancelled: 4,
expired: 5
}, default: :draft
# Note: using string values since the database column is a string
# === Associations ===
belongs_to :user
@@ -43,6 +36,7 @@ class Order < ApplicationRecord
}
before_validation :set_expiry, on: :create
before_validation :set_default_status, on: :create
after_update :create_earnings_if_paid, if: -> { saved_change_to_status? && status == "paid" }
# === Instance Methods ===
@@ -171,6 +165,12 @@ class Order < ApplicationRecord
self.expires_at = DRAFT_EXPIRY_TIME.from_now if expires_at.blank?
end
def set_default_status
self.status ||= "draft"
self.total_amount_cents ||= 0
self.payment_attempts ||= 0
end
def draft?
status == "draft"
end