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
|
|
|
|
|
|
|
|
|
|
def create
|
2016-07-05 16:39:38 +05:30
|
|
|
TicketPurchase.destroy_all(user_id: current_user.id, conference_id: @conference.id, paid: false)
|
2014-08-28 15:21:05 +02:00
|
|
|
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
|
|
|
|
|
if message.blank?
|
2016-07-08 23:07:17 +05:30
|
|
|
if current_user.ticket_purchases.unpaid.any?
|
2016-06-18 18:25:20 +05:30
|
|
|
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
|
2014-12-05 16:04:34 +01:00
|
|
|
else
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title)
|
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
|
|
|
|
|
|
|
|
|
|
def destroy
|
2014-12-05 16:04:34 +01:00
|
|
|
@ticket_purchases = current_user.ticket_purchases.find(params[:id])
|
2014-08-28 15:21:05 +02:00
|
|
|
if @ticket_purchases.destroy
|
2016-07-05 00:10:18 +05:30
|
|
|
redirect_to conference_conference_registration_path(@conference.short_title),
|
2014-09-02 23:28:23 +03:00
|
|
|
notice: 'Ticket successfully deleted.'
|
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: 'An error prohibited deleting your purchase! '\
|
2014-08-28 15:21:05 +02:00
|
|
|
"#{@ticket_purchases.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
|
|
|
|
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
|