Module: Pay::Stripe::Subscription
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/stripe/subscription.rb
Instance Method Summary collapse
- #stripe_cancel ⇒ Object
- #stripe_cancel_now! ⇒ Object
- #stripe_on_grace_period? ⇒ Boolean
- #stripe_pause ⇒ Object
- #stripe_paused? ⇒ Boolean
- #stripe_resume ⇒ Object
- #stripe_swap(plan) ⇒ Object
Instance Method Details
#stripe_cancel ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/pay/stripe/subscription.rb', line 6 def stripe_cancel subscription = processor_subscription subscription.cancel_at_period_end = true subscription.save new_ends_at = on_trial? ? trial_ends_at : Time.at(subscription.current_period_end) update(ends_at: new_ends_at) rescue ::Stripe::StripeError => e raise Pay::Stripe::Error, e end |
#stripe_cancel_now! ⇒ Object
17 18 19 20 21 22 |
# File 'lib/pay/stripe/subscription.rb', line 17 def stripe_cancel_now! processor_subscription.delete update(ends_at: Time.zone.now, status: :canceled) rescue ::Stripe::StripeError => e raise Pay::Stripe::Error, e end |
#stripe_on_grace_period? ⇒ Boolean
24 25 26 |
# File 'lib/pay/stripe/subscription.rb', line 24 def stripe_on_grace_period? canceled? && Time.zone.now < ends_at end |
#stripe_pause ⇒ Object
32 33 34 |
# File 'lib/pay/stripe/subscription.rb', line 32 def stripe_pause raise NotImplementedError, "Stripe does not support pausing subscriptions" end |
#stripe_paused? ⇒ Boolean
28 29 30 |
# File 'lib/pay/stripe/subscription.rb', line 28 def stripe_paused? false end |
#stripe_resume ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pay/stripe/subscription.rb', line 36 def stripe_resume unless on_grace_period? raise StandardError, "You can only resume subscriptions within their grace period." end subscription = processor_subscription subscription.plan = processor_plan subscription.trial_end = on_trial? ? trial_ends_at.to_i : "now" subscription.cancel_at_period_end = false subscription.save rescue ::Stripe::StripeError => e raise Pay::Stripe::Error, e end |
#stripe_swap(plan) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pay/stripe/subscription.rb', line 50 def stripe_swap(plan) subscription = processor_subscription subscription.cancel_at_period_end = false subscription.plan = plan subscription.proration_behavior = (prorate ? "create_prorations" : "none") subscription.trial_end = on_trial? ? trial_ends_at.to_i : "now" subscription.quantity = quantity if quantity? subscription.save rescue ::Stripe::StripeError => e raise Pay::Stripe::Error, e end |