mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 19:48:28 +02:00
parent
640faaadb9
commit
42e8f86dae
51 changed files with 1619 additions and 53 deletions
63
app/models/auction.rb
Normal file
63
app/models/auction.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
class Auction < ActiveRecord::Base
|
||||
enum status: {
|
||||
started: 'started',
|
||||
awaiting_payment: 'awaiting_payment',
|
||||
no_bids: 'no_bids',
|
||||
payment_received: 'payment_received',
|
||||
payment_not_received: 'payment_not_received',
|
||||
domain_registered: 'domain_registered',
|
||||
}
|
||||
|
||||
PENDING_STATUSES = [statuses[:started],
|
||||
statuses[:awaiting_payment],
|
||||
statuses[:payment_received]].freeze
|
||||
private_constant :PENDING_STATUSES
|
||||
|
||||
def self.sell(domain_name)
|
||||
create!(domain: domain_name.to_s, status: statuses[:started])
|
||||
end
|
||||
|
||||
def self.pending(domain_name)
|
||||
find_by(domain: domain_name.to_s, status: PENDING_STATUSES)
|
||||
end
|
||||
|
||||
def mark_as_no_bids
|
||||
transaction do
|
||||
DNS::DomainName.new(domain).update_whois
|
||||
no_bids!
|
||||
end
|
||||
end
|
||||
|
||||
def mark_as_payment_received
|
||||
self.status = self.class.statuses[:payment_received]
|
||||
generate_registration_code
|
||||
save!
|
||||
end
|
||||
|
||||
def mark_as_payment_not_received
|
||||
self.status = self.class.statuses[:payment_not_received]
|
||||
|
||||
transaction do
|
||||
save!
|
||||
restart
|
||||
end
|
||||
end
|
||||
|
||||
def domain_registrable?(registration_code = nil)
|
||||
payment_received? && registration_code_matches?(registration_code)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_registration_code
|
||||
self.registration_code = SecureRandom.hex
|
||||
end
|
||||
|
||||
def restart
|
||||
self.class.create!(domain: domain, status: self.class.statuses[:started])
|
||||
end
|
||||
|
||||
def registration_code_matches?(code)
|
||||
registration_code == code
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue