Assert that a user has a paid ticket before registering for a conference.

This commit is contained in:
Michael Ball 2020-07-11 00:57:08 -07:00
parent 69b18a97e1
commit 5bef4b7004
2 changed files with 18 additions and 0 deletions

View file

@ -32,6 +32,8 @@ class Registration < ApplicationRecord
if: -> { conference.try(:code_of_conduct).present? }
}
validate :user_has_registration_ticket, if: -> { conference.registration_ticket_required? }
after_create :set_week, :subscribe_to_conference, :send_registration_mail
##
@ -65,4 +67,12 @@ class Registration < ApplicationRecord
errors.add(:base, 'Registration limit exceeded')
end
end
def user_has_registration_ticket
return if TicketPurchase.where(user: user, ticket: conference.registration_tickets).paid.any?
errors.add(:base, 'You must purchase a registration ticket before registering')
if TicketPurchase.where(user: user, ticket: conference.registration_tickets).unpaid.any?
errors.add(:base, 'You currently have a ticket with an unfinished purchase')
end
end
end