Class: Pay::FakeProcessor::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/fake_processor/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pay_subscription) ⇒ Subscription

Returns a new instance of Subscription.


18
19
20
# File 'lib/pay/fake_processor/subscription.rb', line 18

def initialize(pay_subscription)
  @pay_subscription = pay_subscription
end

Instance Attribute Details

#pay_subscriptionObject (readonly)

Returns the value of attribute pay_subscription.


4
5
6
# File 'lib/pay/fake_processor/subscription.rb', line 4

def pay_subscription
  @pay_subscription
end

Instance Method Details

#cancel(**options) ⇒ Object

With trial, sets end to trial end (mimicing Stripe) Without trial, sets can ends_at to end of month


28
29
30
31
32
33
34
# File 'lib/pay/fake_processor/subscription.rb', line 28

def cancel(**options)
  if pay_subscription.on_trial?
    pay_subscription.update(ends_at: pay_subscription.trial_ends_at)
  else
    pay_subscription.update(ends_at: Time.current.end_of_month)
  end
end

#cancel_now!(**options) ⇒ Object


36
37
38
39
40
41
42
43
# File 'lib/pay/fake_processor/subscription.rb', line 36

def cancel_now!(**options)
  ends_at = Time.current
  pay_subscription.update(
    status: :canceled,
    trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
    ends_at: ends_at
  )
end

#change_quantity(quantity) ⇒ Object


66
67
# File 'lib/pay/fake_processor/subscription.rb', line 66

def change_quantity(quantity)
end

#on_grace_period?Boolean

Returns:

  • (Boolean)

45
46
47
# File 'lib/pay/fake_processor/subscription.rb', line 45

def on_grace_period?
  canceled? && Time.current < ends_at
end

#pauseObject


53
54
55
# File 'lib/pay/fake_processor/subscription.rb', line 53

def pause
  pay_subscription.update(status: :paused, trial_ends_at: Time.current)
end

#paused?Boolean

Returns:

  • (Boolean)

49
50
51
# File 'lib/pay/fake_processor/subscription.rb', line 49

def paused?
  pay_subscription.status == "paused"
end

#resumeObject


57
58
59
60
61
# File 'lib/pay/fake_processor/subscription.rb', line 57

def resume
  unless on_grace_period? || paused?
    raise StandardError, "You can only resume subscriptions within their grace period."
  end
end

#subscription(**options) ⇒ Object


22
23
24
# File 'lib/pay/fake_processor/subscription.rb', line 22

def subscription(**options)
  pay_subscription
end

#swap(plan) ⇒ Object


63
64
# File 'lib/pay/fake_processor/subscription.rb', line 63

def swap(plan)
end