Sha256: 02ffb88396b29c9ab96a8f910edbdaae334da16214c003c4247c0d898a7faf4d

Contents?: true

Size: 762 Bytes

Versions: 21

Compression:

Stored size: 762 Bytes

Contents

class DiscoApp::SubscriptionService

  # Subscribe the given shop to the given plan.
  def self.subscribe(shop, plan)
    # Mark all existing active subscriptions as replaced.
    shop.subscriptions.active.update_all(status: DiscoApp::Subscription.statuses[:replaced])

    # Add the new subscription.
    DiscoApp::Subscription.create!(
      shop: shop,
      plan: plan,
      status: DiscoApp::Subscription.statuses[:active],
      name: plan.name,
      charge_type: plan.charge_type,
      price: plan.default_price,
      trial_days: plan.default_trial_days
    )
  end

  # Cancel any active subscription for the given shop.
  def self.cancel(shop)
    shop.subscriptions.active.update_all(status: DiscoApp::Subscription.statuses[:cancelled])
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
disco_app-0.6.0 app/services/disco_app/subscription_service.rb
disco_app-0.6.1 app/services/disco_app/subscription_service.rb
disco_app-0.6.2 app/services/disco_app/subscription_service.rb
disco_app-0.6.3 app/services/disco_app/subscription_service.rb
disco_app-0.6.4 app/services/disco_app/subscription_service.rb
disco_app-0.6.5 app/services/disco_app/subscription_service.rb
disco_app-0.6.6 app/services/disco_app/subscription_service.rb
disco_app-0.6.7 app/services/disco_app/subscription_service.rb
disco_app-0.6.8 app/services/disco_app/subscription_service.rb
disco_app-0.6.9 app/services/disco_app/subscription_service.rb
disco_app-0.7.0 app/services/disco_app/subscription_service.rb
disco_app-0.7.1 app/services/disco_app/subscription_service.rb
disco_app-0.7.2 app/services/disco_app/subscription_service.rb
disco_app-0.8.0 app/services/disco_app/subscription_service.rb
disco_app-0.8.1 app/services/disco_app/subscription_service.rb
disco_app-0.8.2 app/services/disco_app/subscription_service.rb
disco_app-0.8.3 app/services/disco_app/subscription_service.rb
disco_app-0.8.4 app/services/disco_app/subscription_service.rb
disco_app-0.8.5 app/services/disco_app/subscription_service.rb
disco_app-0.8.6 app/services/disco_app/subscription_service.rb