Module: Pay::Paddle::Subscription
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/paddle/subscription.rb
Instance Method Summary collapse
- #paddle? ⇒ Boolean
- #paddle_cancel ⇒ Object
- #paddle_cancel_now! ⇒ Object
- #paddle_pause ⇒ Object
- #paddle_resume ⇒ Object
- #paddle_swap(plan) ⇒ Object
Instance Method Details
#paddle? ⇒ Boolean
13 14 15 |
# File 'lib/pay/paddle/subscription.rb', line 13 def paddle? processor == "paddle" end |
#paddle_cancel ⇒ Object
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. 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. end |
#paddle_pause ⇒ Object
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_resume ⇒ Object
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. 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. end |