use full_name instead of first and last name, test changes, schema improvements

This commit is contained in:
Rishabh Saxena 2016-07-21 22:43:43 +05:30
parent f00e051eff
commit 6d8605073f
10 changed files with 25 additions and 81 deletions

View file

@ -14,12 +14,12 @@ class PaymentsController < ApplicationController
def create
@payment = Payment.new(payment_params)
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
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
@ -27,17 +27,12 @@ class PaymentsController < ApplicationController
private
def update_purchased_ticket_purchases
paid_ticket_purchases = current_user.ticket_purchases.by_conference(@conference).unpaid
paid_ticket_purchases.each do |ticket|
ticket.paid = true
ticket.payment_id = @payment.id
ticket.save
end
current_user.ticket_purchases.by_conference(@conference).unpaid.update_all(paid: true, payment_id: @payment.id)
end
def payment_params
params.require(:payment)
.permit(:first_name, :last_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
.permit(:full_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
.merge(user: current_user, conference: @conference)
end
end