Class: Pay::FakeProcessor::Subscription
- Inherits:
-
Object
- Object
- Pay::FakeProcessor::Subscription
- Defined in:
- lib/pay/fake_processor/subscription.rb
Instance Attribute Summary collapse
-
#pay_subscription ⇒ Object
readonly
Returns the value of attribute pay_subscription.
Instance Method Summary collapse
-
#cancel ⇒ Object
With trial, sets end to trial end (mimicing Stripe) Without trial, sets can ends_at to end of month.
- #cancel_now! ⇒ Object
- #change_quantity(quantity) ⇒ Object
-
#initialize(pay_subscription) ⇒ Subscription
constructor
A new instance of Subscription.
- #on_grace_period? ⇒ Boolean
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resume ⇒ Object
- #subscription(**options) ⇒ Object
- #swap(plan) ⇒ Object
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_subscription ⇒ Object (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 ⇒ 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 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! ⇒ Object
36 37 38 |
# File 'lib/pay/fake_processor/subscription.rb', line 36 def cancel_now! pay_subscription.update(ends_at: Time.current, status: :canceled) end |
#change_quantity(quantity) ⇒ Object
61 62 |
# File 'lib/pay/fake_processor/subscription.rb', line 61 def change_quantity(quantity) end |
#on_grace_period? ⇒ Boolean
40 41 42 |
# File 'lib/pay/fake_processor/subscription.rb', line 40 def on_grace_period? canceled? && Time.current < ends_at end |
#pause ⇒ Object
48 49 50 |
# File 'lib/pay/fake_processor/subscription.rb', line 48 def pause pay_subscription.update(status: :paused, trial_ends_at: Time.current) end |
#paused? ⇒ Boolean
44 45 46 |
# File 'lib/pay/fake_processor/subscription.rb', line 44 def paused? pay_subscription.status == "paused" end |
#resume ⇒ Object
52 53 54 55 56 |
# File 'lib/pay/fake_processor/subscription.rb', line 52 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(**) pay_subscription end |
#swap(plan) ⇒ Object
58 59 |
# File 'lib/pay/fake_processor/subscription.rb', line 58 def swap(plan) end |