repair tests and move method belonging to controller
This commit is contained in:
parent
38ae24c6b3
commit
c57a8a1d00
6 changed files with 26 additions and 49 deletions
|
|
@ -18,7 +18,7 @@ class PaymentsController < ApplicationController
|
|||
|
||||
if @payment.valid? && @payment.purchase(current_user, @conference, price_in_cents)
|
||||
if @payment.save
|
||||
@update_ticket_purchases = TicketPurchase.update_paid_ticket_purchases(@conference, current_user, @payment)
|
||||
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.' }
|
||||
else
|
||||
render 'new'
|
||||
|
|
@ -32,6 +32,19 @@ 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)
|
||||
begin
|
||||
paid_ticket_purchases.each do |ticket|
|
||||
ticket.paid = true
|
||||
ticket.payment_id = payment.id
|
||||
ticket.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def payment_params
|
||||
params.require(:payment).permit(:first_name, :last_name, :credit_card_number, :expiration_month, :expiration_year, :card_verification_value, :amount)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -57,4 +57,9 @@ class Payment < ActiveRecord::Base
|
|||
self.status = 'success'
|
||||
response.success?
|
||||
end
|
||||
|
||||
# method to test `purchase` method
|
||||
def self.make_payment(user, conference, price_in_cents, payment)
|
||||
payment.purchase(user, conference, price_in_cents)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,17 +50,4 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase.quantity = quantity if quantity > 0
|
||||
purchase
|
||||
end
|
||||
|
||||
def self.update_paid_ticket_purchases(conference, user, payment)
|
||||
paid_ticket_purchases = TicketPurchase.where(conference_id: conference.id,
|
||||
user_id: user.id,
|
||||
paid: false)
|
||||
begin
|
||||
paid_ticket_purchases.each do |ticket|
|
||||
ticket.paid = true
|
||||
ticket.payment_id = payment.id
|
||||
ticket.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue