Class: Susply::CreateSubscription

Inherits:
Object
  • Object
show all
Defined in:
app/services/susply/create_subscription.rb

Class Method Summary collapse

Class Method Details

.call(owner, plan) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/susply/create_subscription.rb', line 3

def self.call(owner, plan)
  now = Time.zone.now

  subscription = Susply::Subscription.new do |s|
    s.owner = owner
    s.plan = plan
    s.quantity = 1
    s.start = now
    s.current_period_start = now
    s.current_period_end = Susply::Calculations.
      end_period_calculation(s.current_period_start, plan.interval)
  end
  
  subscription.save!

  subscription
end