Class: FeeStrategy

Inherits:
Object
  • Object
show all
Defined in:
app/models/fee_strategy.rb

Direct Known Subclasses

ConsoleSale::FeeStrategy

Instance Method Summary collapse

Instance Method Details

#apply_to_cart(cart) ⇒ Object



6
7
8
9
10
11
12
# File 'app/models/fee_strategy.rb', line 6

def apply_to_cart(cart)
  return if cart.is_a? BoxOffice::Cart

  handle_tickets(cart)
  handle_memberships(cart)
  handle_passes(cart)
end

#handle_memberships(cart) ⇒ Object



30
31
32
33
34
35
# File 'app/models/fee_strategy.rb', line 30

def handle_memberships(cart)
  cart.memberships.each do |membership|
    membership.service_fee = membership.membership_type.hide_fee? ? 0 : (membership.cart_price || membership.price) * MembershipType::SERVICE_FEE
    membership.save
  end
end

#handle_passes(cart) ⇒ Object



37
38
39
40
41
42
# File 'app/models/fee_strategy.rb', line 37

def handle_passes(cart)
  cart.passes.each do |pass|
    pass.service_fee = pass.pass_type.hide_fee? ? 0 : pass.price * PassType::SERVICE_FEE
    pass.save
  end
end

#handle_tickets(cart) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/fee_strategy.rb', line 14

def handle_tickets(cart)
  cart.tickets.each do |ticket|
    if ticket.price > 0
      ticket.service_fee = ticket_fee
    elsif ticket.price == 0
      ticket.service_fee = 0
    end

    if ticket.cart_price == 0 && waive_fee_for?(ticket)
      ticket.service_fee = 0
    end

    ticket.save
  end
end

#ticket_feeObject



2
3
4
# File 'app/models/fee_strategy.rb', line 2

def ticket_fee
  ARTFULLY_CONFIG[:ticket_fee] || 0
end

#waive_fee_for?(ticket) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'app/models/fee_strategy.rb', line 44

def waive_fee_for?(ticket)
  # 
  # This match is too tightly coupled to discount. Also, horrible.
  # Check needs to be made because cart_price == 0 && BOGO means fee is applied
  #
  (ticket.discount.try(:promotion_type) == "DollarsOffTickets") || ticket.pass.present?
end