Module: Pay::Paddle::Subscription
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/paddle/subscription.rb
Instance Method Summary collapse
- #paddle_cancel ⇒ Object
- #paddle_cancel_now! ⇒ Object
- #paddle_on_grace_period? ⇒ Boolean
- #paddle_pause ⇒ Object
- #paddle_paused? ⇒ Boolean
- #paddle_resume ⇒ Object
- #paddle_swap(plan) ⇒ Object
Instance Method Details
#paddle_cancel ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/pay/paddle/subscription.rb', line 12 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
24 25 26 27 28 29 |
# File 'lib/pay/paddle/subscription.rb', line 24 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
31 32 33 |
# File 'lib/pay/paddle/subscription.rb', line 31 def paddle_on_grace_period? canceled? && Time.zone.now < ends_at || paused? && Time.zone.now < paddle_paused_from end |
#paddle_pause ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/pay/paddle/subscription.rb', line 39 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
35 36 37 |
# File 'lib/pay/paddle/subscription.rb', line 35 def paddle_paused? paddle_paused_from.present? end |
#paddle_resume ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pay/paddle/subscription.rb', line 47 def paddle_resume unless paused? raise StandardError, "You can only resume paused subscriptions." end 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
59 60 61 62 63 64 65 |
# File 'lib/pay/paddle/subscription.rb', line 59 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 |