add payment resources, controllers and method for updating purchased ticket's parameters
This commit is contained in:
parent
36f2cf4373
commit
900a1b32a8
4 changed files with 47 additions and 0 deletions
34
app/controllers/payments_controller.rb
Normal file
34
app/controllers/payments_controller.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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 = Payment.where(user_id: current_user.id)
|
||||
end
|
||||
|
||||
def new
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, 'f')
|
||||
end
|
||||
|
||||
def create
|
||||
@payment = Payment.new(payment_params)
|
||||
@total_amount_to_pay = Ticket.total_price(@conference, current_user, 'f')
|
||||
|
||||
if @payment.valid?
|
||||
if @payment.purchase(current_user, @conference)
|
||||
@payment.save
|
||||
@update_ticket_purchases = TicketPurchase.update_paid_ticket_purchases(@conference, current_user, @payment)
|
||||
return redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
|
||||
end
|
||||
end
|
||||
render 'new'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def payment_params
|
||||
params.require(:payment).permit(:first_name, :last_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue