Module: Pay::Paddle::Subscription

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

Instance Method Summary collapse

Instance Method Details

#paddle?Boolean



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

def paddle?
  processor == "paddle"
end

#paddle_cancelObject



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

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: DateTime.parse(subscription.next_payment[:date]))
  end
rescue ::PaddlePay::PaddlePayError => e
  raise Error, e.message
end

#paddle_cancel_now!Object



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

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

#paddle_pauseObject



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

def paddle_pause
  attributes = {pause: true}
  response = PaddlePay::Subscription::User.update(processor_id, attributes)
  update(status: :paused, ends_at: DateTime.parse(response[:next_payment][:date]))
end

#paddle_resumeObject



42
43
44
45
46
47
48
# File 'lib/pay/paddle/subscription.rb', line 42

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

#paddle_swap(plan) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/pay/paddle/subscription.rb', line 50

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 Error, e.message
end