Merge 4d4736f042 into 424b1302cb
This commit is contained in:
commit
211410b6f0
33 changed files with 621 additions and 91 deletions
|
|
@ -28,8 +28,10 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@total_price = Ticket.total_price(@conference, current_user)
|
||||
@tickets = current_user.ticket_purchases.where(conference_id: @conference.id)
|
||||
@total_price = Ticket.total_price(@conference, current_user, paid: true)
|
||||
@tickets = current_user.ticket_purchases.by_conference(@conference).paid
|
||||
@ticket_payments = @tickets.group_by(&:ticket_id)
|
||||
@total_quantity = @tickets.group(:ticket_id).sum(:quantity)
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
|
|
|||
38
app/controllers/payments_controller.rb
Normal file
38
app/controllers/payments_controller.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
class PaymentsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
load_and_authorize_resource
|
||||
load_resource :conference, find_by: :short_title
|
||||
authorize_resource :conference_registrations, class: Registration
|
||||
|
||||
def index
|
||||
@payments = current_user.payments
|
||||
end
|
||||
|
||||
def new
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||
end
|
||||
|
||||
def create
|
||||
@payment = Payment.new(payment_params)
|
||||
|
||||
if @payment.purchase && @payment.save
|
||||
update_purchased_ticket_purchases
|
||||
redirect_to conference_conference_registration_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
|
||||
else
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_purchased_ticket_purchases
|
||||
current_user.ticket_purchases.by_conference(@conference).unpaid.update_all(paid: true, payment_id: @payment.id)
|
||||
end
|
||||
|
||||
def payment_params
|
||||
params.require(:payment)
|
||||
.permit(:full_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
|
||||
.merge(user: current_user, conference: @conference)
|
||||
end
|
||||
end
|
||||
|
|
@ -4,11 +4,11 @@ class TicketPurchasesController < ApplicationController
|
|||
authorize_resource :conference_registrations, class: Registration
|
||||
|
||||
def create
|
||||
TicketPurchase.by_conference(@conference).unpaid.by_user(current_user).destroy_all
|
||||
message = TicketPurchase.purchase(@conference, current_user, params[:tickets][0])
|
||||
if message.blank?
|
||||
if current_user.ticket_purchases.any?
|
||||
redirect_to conference_conference_registration_path(@conference.short_title),
|
||||
notice: "Thank you for supporting #{@conference.title} by purchasing a ticket."
|
||||
if current_user.ticket_purchases.by_conference(@conference).unpaid.any?
|
||||
redirect_to new_conference_payment_path, notice: 'Please pay here to purchase tickets.'
|
||||
else
|
||||
redirect_to conference_conference_registration_path(@conference.short_title)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue