Module: Pay::Paddle::Subscription

Extended by:
ActiveSupport::Concern
Defined in:
lib/pay/paddle/subscription.rb

Instance Method Summary collapse

Instance Method Details

#paddle?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/pay/paddle/subscription.rb', line 14

def paddle?
  processor == "paddle"
end

#paddle_cancelObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pay/paddle/subscription.rb', line 18

def paddle_cancel
  subscription = processor_subscription
  PaddlePay::Subscription::User.cancel(processor_id)
  if on_trial?
    update(status: :canceled, ends_at: trial_ends_at)
  else
    update(status: :canceled, ends_at: Time.zone.parse(subscription.next_payment[:date]))
  end
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end

#paddle_cancel_now!Object



30
31
32
33
34
35
# File 'lib/pay/paddle/subscription.rb', line 30

def paddle_cancel_now!
  PaddlePay::Subscription::User.cancel(processor_id)
  update(status: :canceled, ends_at: Time.zone.now)
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end

#paddle_on_grace_period?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/pay/paddle/subscription.rb', line 37

def paddle_on_grace_period?
  canceled? && Time.zone.now < ends_at || paused? && Time.zone.now < paddle_paused_from
end

#paddle_pauseObject



45
46
47
48
49
50
51
# File 'lib/pay/paddle/subscription.rb', line 45

def paddle_pause
  attributes = {pause: true}
  response = PaddlePay::Subscription::User.update(processor_id, attributes)
  update(paddle_paused_from: Time.zone.parse(response[:next_payment][:date]))
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end

#paddle_paused?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/pay/paddle/subscription.rb', line 41

def paddle_paused?
  paddle_paused_from.present?
end

#paddle_resumeObject



53
54
55
56
57
58
59
# File 'lib/pay/paddle/subscription.rb', line 53

def paddle_resume
  attributes = {pause: false}
  PaddlePay::Subscription::User.update(processor_id, attributes)
  update(status: :active, paddle_paused_from: nil)
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end

#paddle_swap(plan) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/pay/paddle/subscription.rb', line 61

def paddle_swap(plan)
  attributes = {plan_id: plan, prorate: prorate}
  attributes[:quantity] = quantity if quantity?
  PaddlePay::Subscription::User.update(processor_id, attributes)
rescue ::PaddlePay::PaddlePayError => e
  raise Pay::Paddle::Error, e
end