Module: Pay::Stripe::Subscription
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/pay/stripe/subscription.rb
Instance Method Summary collapse
- #stripe? ⇒ Boolean
- #stripe_cancel ⇒ Object
- #stripe_cancel_now! ⇒ Object
- #stripe_resume ⇒ Object
- #stripe_swap(plan) ⇒ Object
Instance Method Details
#stripe? ⇒ Boolean
10 11 12 |
# File 'lib/pay/stripe/subscription.rb', line 10 def stripe? processor == "stripe" end |
#stripe_cancel ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pay/stripe/subscription.rb', line 14 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 Error, e. end |
#stripe_cancel_now! ⇒ Object
25 26 27 28 29 30 |
# File 'lib/pay/stripe/subscription.rb', line 25 def stripe_cancel_now! processor_subscription.delete update(ends_at: Time.zone.now, status: :canceled) rescue ::Stripe::StripeError => e raise Error, e. end |
#stripe_resume ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/pay/stripe/subscription.rb', line 32 def stripe_resume 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 Error, e. end |
#stripe_swap(plan) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pay/stripe/subscription.rb', line 42 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 Error, e. end |