Class: DiscoApp::SubscriptionService

Inherits:
Object
  • Object
show all
Defined in:
app/services/disco_app/subscription_service.rb

Class Method Summary collapse

Class Method Details

.cancel(shop) ⇒ Object

Cancel any active subscription for the given shop.



21
22
23
# File 'app/services/disco_app/subscription_service.rb', line 21

def self.cancel(shop)
  shop.subscriptions.active.update_all(status: DiscoApp::Subscription.statuses[:cancelled])
end

.subscribe(shop, plan) ⇒ Object

Subscribe the given shop to the given plan.



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

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