1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/models/cart_item/free_extension.rb

39 lines
922 B
Ruby
Raw Normal View History

2021-10-12 14:07:35 +02:00
# frozen_string_literal: true
# A subscription extended for free, added to the shopping cart
class CartItem::FreeExtension < CartItem::BaseItem
def initialize(customer, subscription, new_expiration_date)
raise TypeError unless subscription.is_a? Subscription
@customer = customer
@new_expiration_date = new_expiration_date
@subscription = subscription
super
end
def start_at
raise InvalidSubscriptionError if @subscription.nil?
raise InvalidSubscriptionError if @new_expiration_date <= @subscription.expired_at
@subscription.expired_at
end
def price
elements = { OfferDay: 0 }
{ elements: elements, amount: 0 }
end
def name
I18n.t('cart_items.free_extension', DATE: I18n.l(@new_expiration_date))
end
def to_object
::OfferDay.new(
subscription_id: @subscription.id,
start_at: start_at,
end_at: @new_expiration_date
)
end
end