1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-07 01:54:16 +01:00
fab-manager/app/models/cart_item/subscription.rb
Sylvain c7a59c8cb7 WIP: refactoring to singularize the booking process
We need to achieve only one process for all booking, not one for subscription, one for reservations, etc.
Moreover we must store one object per invoice_item/payment_schedule_object and stop using Invoice.invoiced or PaymentSchedule.scheduled
2021-05-21 18:25:18 +02:00

32 lines
578 B
Ruby

# frozen_string_literal: true
# A subscription added to the shopping cart
class CartItem::Subscription < CartItem::BaseItem
attr_reader :plan
def initialize(plan, customer)
raise TypeError unless plan.is_a? Plan
@plan = plan
@customer = customer
end
def price
amount = @plan.amount
elements = { plan: amount }
{ elements: elements, amount: amount }
end
def name
@plan.name
end
def to_object
Subscription.new(
plan_id: @plan.id,
statistic_profile_id: StatisticProfile.find_by(user: @customer).id
)
end
end