Sha256: f4a20b88c472000c87380ab180cf535b212980c433fc9f25f150d4089b914f74

Contents?: true

Size: 485 Bytes

Versions: 3

Compression:

Stored size: 485 Bytes

Contents

module Susply
  class CreateSubscription
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
susply-1.0.0 app/services/susply/create_subscription.rb
susply-0.0.2 app/services/susply/create_subscription.rb
susply-0.0.1 app/services/susply/create_subscription.rb