solve code reviews, resolve rebase conflicts
This commit is contained in:
parent
9b704e483e
commit
ae44abc7e6
10 changed files with 32 additions and 45 deletions
|
|
@ -36,30 +36,25 @@ class Payment < ActiveRecord::Base
|
|||
|
||||
def purchase(user, conference, price_in_cents)
|
||||
begin
|
||||
response = GATEWAY.purchase(price_in_cents, credit_card, currency: conference.tickets.first.price_currency)
|
||||
recieve = GATEWAY.purchase(price_in_cents, credit_card, currency: conference.tickets.first.price_currency)
|
||||
rescue
|
||||
false
|
||||
end
|
||||
|
||||
unless response
|
||||
unless recieve
|
||||
errors.add(:base, 'Unable to recieve any response')
|
||||
return false
|
||||
end
|
||||
unless response.success?
|
||||
errors.add(:base, response.message)
|
||||
unless recieve.success?
|
||||
errors.add(:base, recieve.message)
|
||||
self.status = 'failure'
|
||||
return false
|
||||
end
|
||||
self.user_id = user.id
|
||||
self.conference_id = conference.id
|
||||
self.last4 = credit_card.display_number
|
||||
self.authorization_code = response.authorization
|
||||
self.authorization_code = recieve.authorization
|
||||
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)
|
||||
recieve.success?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,18 +18,12 @@ class Ticket < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def paid?(user)
|
||||
ticket_purchases.find_by(user: user, paid: true).present?
|
||||
ticket_purchases.paid.by_user(user).present?
|
||||
end
|
||||
|
||||
def quantity_bought_by(user, paid: false)
|
||||
purchased_tickets = ticket_purchases.where(user_id: user.id, paid: paid)
|
||||
quantity = 0
|
||||
if purchased_tickets
|
||||
purchased_tickets.each do |ticket|
|
||||
quantity += ticket.quantity
|
||||
end
|
||||
end
|
||||
quantity
|
||||
purchased_tickets = ticket_purchases.paid.by_user(user)
|
||||
quantity = purchased_tickets.sum(:quantity)
|
||||
end
|
||||
|
||||
def unpaid?(user)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ class TicketPurchase < ActiveRecord::Base
|
|||
delegate :price_cents, to: :ticket
|
||||
delegate :price_currency, to: :ticket
|
||||
|
||||
scope :paid, -> { where(paid: true) }
|
||||
scope :unpaid, -> { where(paid: false) }
|
||||
scope :by_conference, -> (conference) { where(conference_id: conference.id) }
|
||||
scope :by_user, -> (user) { where(user_id: user.id) }
|
||||
|
||||
def self.purchase(conference, user, purchases)
|
||||
errors = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue