Class: Pay::FakeProcessor::Subscription
- Inherits:
-
Subscription
- Object
- Subscription
- Pay::FakeProcessor::Subscription
- Defined in:
- app/models/pay/fake_processor/subscription.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api_record(**options) ⇒ Object
-
#cancel(**options) ⇒ Object
With trial, sets end to trial end (mimicking Stripe) Without trial, sets can ends_at to end of month.
- #cancel_now!(**options) ⇒ Object
- #change_quantity(quantity, **options) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #resumable? ⇒ Boolean
- #resume ⇒ Object
-
#retry_failed_payment ⇒ Object
Retries the latest invoice for a Past Due subscription.
- #swap(plan, **options) ⇒ Object
Class Method Details
.sync(processor_id, **options) ⇒ Object
4 5 6 |
# File 'app/models/pay/fake_processor/subscription.rb', line 4 def self.sync(processor_id, **) # Bypass sync operation for FakeProcessor end |
Instance Method Details
#api_record(**options) ⇒ Object
8 9 10 |
# File 'app/models/pay/fake_processor/subscription.rb', line 8 def api_record(**) self end |
#cancel(**options) ⇒ Object
With trial, sets end to trial end (mimicking Stripe) Without trial, sets can ends_at to end of month
14 15 16 17 |
# File 'app/models/pay/fake_processor/subscription.rb', line 14 def cancel(**) return if canceled? update(ends_at: (on_trial? ? trial_ends_at : Time.current.end_of_month)) end |
#cancel_now!(**options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/pay/fake_processor/subscription.rb', line 19 def cancel_now!(**) return if canceled? ends_at = Time.current update( status: :canceled, trial_ends_at: (ends_at if trial_ends_at?), ends_at: ends_at ) end |
#change_quantity(quantity, **options) ⇒ Object
58 59 60 |
# File 'app/models/pay/fake_processor/subscription.rb', line 58 def change_quantity(quantity, **) update(quantity: quantity) end |
#pause ⇒ Object
34 35 36 |
# File 'app/models/pay/fake_processor/subscription.rb', line 34 def pause update(status: :paused, trial_ends_at: Time.current) end |
#paused? ⇒ Boolean
30 31 32 |
# File 'app/models/pay/fake_processor/subscription.rb', line 30 def paused? status == "paused" end |
#resumable? ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'app/models/pay/fake_processor/subscription.rb', line 38 def resumable? if data&.has_key?("resumable") data["resumable"] else on_grace_period? || paused? end end |
#resume ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/models/pay/fake_processor/subscription.rb', line 46 def resume unless resumable? raise Error, "You can only resume subscriptions within their grace period." end update(status: :active, trial_ends_at: nil, ends_at: nil) end |
#retry_failed_payment ⇒ Object
Retries the latest invoice for a Past Due subscription
63 64 65 |
# File 'app/models/pay/fake_processor/subscription.rb', line 63 def retry_failed_payment update(status: :active) end |
#swap(plan, **options) ⇒ Object
54 55 56 |
# File 'app/models/pay/fake_processor/subscription.rb', line 54 def swap(plan, **) update(processor_plan: plan, ends_at: nil, status: :active) end |