2022-08-19 19:59:13 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Order is a model for the user hold information of order
|
|
|
|
class Order < ApplicationRecord
|
|
|
|
belongs_to :statistic_profile
|
|
|
|
has_many :order_items, dependent: :destroy
|
|
|
|
|
2022-08-25 11:46:14 +02:00
|
|
|
ALL_STATES = %w[cart in_progress ready canceled return].freeze
|
2022-08-19 19:59:13 +02:00
|
|
|
enum state: ALL_STATES.zip(ALL_STATES).to_h
|
|
|
|
|
2022-08-25 11:46:14 +02:00
|
|
|
PAYMENT_STATES = %w[paid failed refunded].freeze
|
2022-08-25 08:52:17 +02:00
|
|
|
enum payment_state: PAYMENT_STATES.zip(PAYMENT_STATES).to_h
|
|
|
|
|
2022-08-19 19:59:13 +02:00
|
|
|
validates :token, :state, presence: true
|
2022-08-26 11:19:09 +02:00
|
|
|
|
|
|
|
def set_wallet_transaction(amount, transaction_id)
|
|
|
|
self.wallet_amount = amount
|
|
|
|
self.wallet_transaction_id = transaction_id
|
|
|
|
end
|
2022-08-19 19:59:13 +02:00
|
|
|
end
|