Class: Pay::FakeProcessor::Subscription

Inherits:
Subscription show all
Defined in:
app/models/pay/fake_processor/subscription.rb

Constant Summary

Constants inherited from Subscription

Subscription::STATUSES

Instance Method Summary collapse

Methods inherited from Subscription

#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



54
55
56
# File 'app/models/pay/fake_processor/subscription.rb', line 54

def change_quantity(quantity, **options)
  update(quantity: quantity)
end

#pauseObject



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

Returns:

  • (Boolean)


26
27
28
# File 'app/models/pay/fake_processor/subscription.rb', line 26

def paused?
  status == "paused"
end

#resumable?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'app/models/pay/fake_processor/subscription.rb', line 34

def resumable?
  if data&.has_key?("resumable")
    data["resumable"]
  else
    on_grace_period? || paused?
  end
end

#resumeObject



42
43
44
45
46
47
48
# File 'app/models/pay/fake_processor/subscription.rb', line 42

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_paymentObject

Retries the latest invoice for a Past Due subscription



59
60
61
# File 'app/models/pay/fake_processor/subscription.rb', line 59

def retry_failed_payment
  update(status: :active)
end

#swap(plan, **options) ⇒ Object



50
51
52
# File 'app/models/pay/fake_processor/subscription.rb', line 50

def swap(plan, **options)
  update(processor_plan: plan, ends_at: nil, status: :active)
end