solve code reviews, resolve rebase conflicts

This commit is contained in:
Rishabh Saxena 2016-07-14 19:10:33 +05:30
parent 9b704e483e
commit ae44abc7e6
10 changed files with 32 additions and 45 deletions

View file

@ -16,9 +16,9 @@ class PaymentsController < ApplicationController
@payment = Payment.new(payment_params)
@total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false)
if @payment.valid? && @payment.purchase(current_user, @conference, price_in_cents) && @payment.save
update_paid_ticket_purchases(@conference, current_user, @payment)
redirect_to conference_conference_registrations_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
if @payment.purchase(current_user, @conference, price_in_cents) && @payment.save
update_purchased_ticket_purchases(@conference, current_user, @payment)
redirect_to conference_conference_registration_path(@conference.short_title), flash: { success: 'Thanks! You have purchased your tickets successfully.' }
else
render 'new'
end
@ -30,10 +30,8 @@ class PaymentsController < ApplicationController
(@payment.amount * 100).round
end
def update_paid_ticket_purchases(conference, user, payment)
paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id,
user_id: user.id,
paid: false)
def update_purchased_ticket_purchases(conference, user, payment)
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