fix : ticket order new
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user