Class: Pay::FakeProcessor::Subscription
Constant Summary
Constants inherited
from Subscription
Subscription::STATUSES
Instance Method Summary
collapse
#active?, #canceled?, #cancelled?, #ended?, find_by_processor_and_id, #generic_trial?, #has_incomplete_payment?, #has_trial?, #incomplete?, #no_prorate, #on_grace_period?, #on_trial?, #past_due?, #skip_trial, #swap_and_invoice, #sync!, #trial_ended?, #unpaid?
Instance Method Details
#api_record(**options) ⇒ Object
4
5
6
|
# File 'app/models/pay/fake_processor/subscription.rb', line 4
def api_record(**options)
self
end
|
#cancel(**options) ⇒ Object
With trial, sets end to trial end (mimicing Stripe) Without trial, sets can ends_at to end of month
10
11
12
13
|
# File 'app/models/pay/fake_processor/subscription.rb', line 10
def cancel(**options)
return if canceled?
update(ends_at: (on_trial? ? trial_ends_at : Time.current.end_of_month))
end
|
#cancel_now!(**options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'app/models/pay/fake_processor/subscription.rb', line 15
def cancel_now!(**options)
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
50
51
52
|
# File 'app/models/pay/fake_processor/subscription.rb', line 50
def change_quantity(quantity, **options)
update(quantity: quantity)
end
|
#pause ⇒ Object
30
31
32
|
# File 'app/models/pay/fake_processor/subscription.rb', line 30
def pause
update(status: :paused, trial_ends_at: Time.current)
end
|
#paused? ⇒ Boolean
26
27
28
|
# File 'app/models/pay/fake_processor/subscription.rb', line 26
def paused?
status == "paused"
end
|
#resumable? ⇒ Boolean
34
35
36
|
# File 'app/models/pay/fake_processor/subscription.rb', line 34
def resumable?
on_grace_period? || paused?
end
|
#resume ⇒ Object
38
39
40
41
42
43
44
|
# File 'app/models/pay/fake_processor/subscription.rb', line 38
def resume
unless resumable?
raise StandardError, "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
55
56
57
|
# File 'app/models/pay/fake_processor/subscription.rb', line 55
def retry_failed_payment
update(status: :active)
end
|
#swap(plan, **options) ⇒ Object
46
47
48
|
# File 'app/models/pay/fake_processor/subscription.rb', line 46
def swap(plan, **options)
update(processor_plan: plan, ends_at: nil, status: :active)
end
|