Class: DiscoApp::SubscriptionService

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shop, plan, plan_code = nil, source_name = nil) ⇒ SubscriptionService

Returns a new instance of SubscriptionService.



11
12
13
14
15
16
# File 'app/services/disco_app/subscription_service.rb', line 11

def initialize(shop, plan, plan_code = nil, source_name = nil)
  @shop = shop
  @plan = plan
  @plan_code = plan_code
  @source_name = source_name
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



9
10
11
# File 'app/services/disco_app/subscription_service.rb', line 9

def plan
  @plan
end

#plan_codeObject (readonly)

Returns the value of attribute plan_code.



9
10
11
# File 'app/services/disco_app/subscription_service.rb', line 9

def plan_code
  @plan_code
end

#shopObject (readonly)

Returns the value of attribute shop.



9
10
11
# File 'app/services/disco_app/subscription_service.rb', line 9

def shop
  @shop
end

#source_nameObject (readonly)

Returns the value of attribute source_name.



9
10
11
# File 'app/services/disco_app/subscription_service.rb', line 9

def source_name
  @source_name
end

Class Method Details

.subscribe(shop, plan, plan_code = nil, source_name = nil) ⇒ Object

Subscribe the given shop to the given plan, optionally using the given plan code and optionally tracking the subscription source.



5
6
7
# File 'app/services/disco_app/subscription_service.rb', line 5

def self.subscribe(shop, plan, plan_code = nil, source_name = nil)
  new(shop, plan, plan_code, source_name).subscribe
end

Instance Method Details

#subscribeObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/disco_app/subscription_service.rb', line 18

def subscribe
  cancel_existing_subscriptions

  # Create the new subscription.
  new_subscription = create_new_subscription

  # Enqueue the subscription changed background job.
  DiscoApp::SubscriptionChangedJob.perform_later(shop, new_subscription)

  # Return the new subscription.
  new_subscription
end