Introduced Physical Ticket
Added PhysicalTicket model and controller. It holds the information about each physical ticket bought at the purchase. Physical Tickets are created after every successfull payment.
This commit is contained in:
parent
1c38b091cc
commit
5c56683ae8
17 changed files with 115 additions and 12 deletions
|
|
@ -87,6 +87,7 @@ class Ability
|
|||
can :index, Ticket
|
||||
can :manage, TicketPurchase, user_id: user.id
|
||||
can [:new, :create], Payment, user_id: user.id
|
||||
can [:index, :show], PhysicalTicket, user_id: user.id
|
||||
|
||||
can [:create, :destroy], Subscription, user_id: user.id
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class Conference < ActiveRecord::Base
|
|||
has_one :email_settings, dependent: :destroy
|
||||
has_one :program, dependent: :destroy
|
||||
has_one :venue, dependent: :destroy
|
||||
has_many :physical_tickets, through: :ticket_purchases
|
||||
has_many :ticket_purchases, dependent: :destroy
|
||||
has_many :payments, dependent: :destroy
|
||||
has_many :supporters, through: :ticket_purchases, source: :user
|
||||
|
|
|
|||
6
app/models/physical_ticket.rb
Normal file
6
app/models/physical_ticket.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class PhysicalTicket < ActiveRecord::Base
|
||||
belongs_to :ticket_purchase
|
||||
has_one :ticket, through: :ticket_purchase
|
||||
has_one :conference, through: :ticket_purchase
|
||||
has_one :user, through: :ticket_purchase
|
||||
end
|
||||
|
|
@ -13,6 +13,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
delegate :price_cents, to: :ticket
|
||||
delegate :price_currency, to: :ticket
|
||||
|
||||
has_many :physical_tickets
|
||||
|
||||
scope :paid, -> { where(paid: true) }
|
||||
scope :unpaid, -> { where(paid: false) }
|
||||
scope :by_conference, ->(conference) { where(conference_id: conference.id) }
|
||||
|
|
@ -45,8 +47,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase = new(ticket_id: ticket.id,
|
||||
conference_id: conference.id,
|
||||
user_id: user.id,
|
||||
quantity: quantity,
|
||||
paid: ticket.price_cents.zero?)
|
||||
quantity: quantity)
|
||||
purchase.pay(nil) if ticket.price_cents.zero?
|
||||
end
|
||||
purchase
|
||||
end
|
||||
|
|
@ -60,6 +62,13 @@ class TicketPurchase < ActiveRecord::Base
|
|||
purchase.quantity = quantity if quantity > 0
|
||||
purchase
|
||||
end
|
||||
|
||||
def pay(payment)
|
||||
update_attributes(paid: true, payment: payment)
|
||||
PhysicalTicket.transaction do
|
||||
quantity.times { physical_tickets.create }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ end
|
|||
|
||||
class User < ActiveRecord::Base
|
||||
rolify
|
||||
has_many :physical_tickets, through: :ticket_purchases do
|
||||
def by_conference(conference)
|
||||
where('ticket_purchases.conference_id = ?', conference)
|
||||
end
|
||||
end
|
||||
has_many :users_roles
|
||||
has_many :roles, through: :users_roles, dependent: :destroy
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue