2014-08-28 15:21:05 +02:00
|
|
|
class TicketPurchasesController < ApplicationController
|
2014-11-06 14:58:51 +01:00
|
|
|
before_filter :authenticate_user!
|
2014-08-28 15:21:05 +02:00
|
|
|
load_resource :conference, find_by: :short_title
|
|
|
|
|
authorize_resource :conference_registrations, class: Registration
|
2017-07-20 18:14:38 +05:30
|
|
|
authorize_resource
|
2014-08-28 15:21:05 +02:00
|
|
|
|
|
|
|
|
def create
|
2016-08-11 17:47:52 +05:30
|
|
|
current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all
|
2014-08-28 15:21:05 +02:00
|
|
|
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
|
|
|
|
|
if message.blank?
|
2016-07-27 19:40:21 +05:30
|
|
|
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
|
2016-08-05 20:17:27 +05:30
|
|
|
redirect_to new_conference_payment_path,
|
2016-08-12 13:21:47 +05:30
|
|
|
notice: 'Please pay here to get tickets.'
|
2016-08-22 13:09:02 +05:30
|
|
|
elsif current_user.ticket_purchases.by_conference(@conference).paid.any?
|
2017-06-03 16:05:59 +05:30
|
|
|
redirect_to conference_physical_ticket_index_path,
|
2016-08-22 13:09:02 +05:30
|
|
|
notice: 'You have free tickets for the conference.'
|
2014-12-05 16:04:34 +01:00
|
|
|
else
|
2016-08-22 13:09:02 +05:30
|
|
|
redirect_to conference_tickets_path(@conference.short_title),
|
|
|
|
|
error: 'Please get at least one ticket to continue.'
|
2014-12-05 16:04:34 +01:00
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
else
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2016-03-16 11:20:56 +05:30
|
|
|
error: "Oops, something went wrong with your purchase! #{message}"
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-26 06:07:52 +05:30
|
|
|
def index
|
|
|
|
|
@unpaid_ticket_purchases = current_user.ticket_purchases.by_conference(@conference).unpaid
|
|
|
|
|
end
|
|
|
|
|
|
2015-10-28 18:05:15 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def ticket_purchase_params
|
|
|
|
|
params.require(:ticket_purchase).permit(:ticket_id, :user_id, :conference_id, :quantity)
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|