2021-04-22 19:24:08 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# A subscription added to the shopping cart
|
|
|
|
class CartItem::Subscription < CartItem::BaseItem
|
2021-05-19 18:12:52 +02:00
|
|
|
attr_reader :plan
|
|
|
|
|
2021-04-22 19:24:08 +02:00
|
|
|
def initialize(plan)
|
2021-04-26 11:40:26 +02:00
|
|
|
raise TypeError unless plan.is_a? Plan
|
2021-04-22 19:24:08 +02:00
|
|
|
|
|
|
|
@plan = plan
|
|
|
|
end
|
|
|
|
|
|
|
|
def price
|
|
|
|
amount = @plan.amount
|
|
|
|
elements = { plan: amount }
|
|
|
|
|
|
|
|
{ elements: elements, amount: amount }
|
|
|
|
end
|
2021-04-23 12:52:06 +02:00
|
|
|
|
|
|
|
def name
|
|
|
|
@plan.name
|
|
|
|
end
|
2021-05-19 18:12:52 +02:00
|
|
|
|
|
|
|
def to_subscription
|
|
|
|
Subscription.new(
|
|
|
|
plan_id: @plan.id
|
|
|
|
)
|
|
|
|
end
|
2021-04-22 19:24:08 +02:00
|
|
|
end
|