Class: Pay::FakeProcessor::Subscription
Constant Summary
Constants inherited
from Subscription
Subscription::STATUSES
Class Method Summary
collapse
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?
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, **options)
end
|
Instance Method Details
#api_record(**options) ⇒ Object
8
9
10
|
# File 'app/models/pay/fake_processor/subscription.rb', line 8
def api_record(**options)
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(**options)
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!(**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
58
59
60
|
# File 'app/models/pay/fake_processor/subscription.rb', line 58
def change_quantity(quantity, **options)
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, **options)
update(processor_plan: plan, ends_at: nil, status: :active)
end
|