class Reji::SubscriptionItem
Public Instance Methods
as_stripe_subscription_item(expand = {})
click to toggle source
Get the subscription as a Stripe subscription item object.
# File lib/reji/subscription_item.rb, line 90 def as_stripe_subscription_item(expand = {}) Stripe::SubscriptionItem.retrieve( { id: stripe_id, expand: expand }, subscription.owner.stripe_options ) end
decrement_quantity(count = 1)
click to toggle source
Decrement the quantity of the subscription item.
# File lib/reji/subscription_item.rb, line 27 def decrement_quantity(count = 1) update_quantity([1, quantity - count].max) self end
increment_and_invoice(count = 1)
click to toggle source
Increment the quantity of the subscription item, and invoice immediately.
# File lib/reji/subscription_item.rb, line 18 def increment_and_invoice(count = 1) always_invoice increment_quantity(count) self end
increment_quantity(count = 1)
click to toggle source
Increment the quantity of the subscription item.
# File lib/reji/subscription_item.rb, line 11 def increment_quantity(count = 1) update_quantity(quantity + count) self end
swap(plan, options = {})
click to toggle source
Swap the subscription item to a new Stripe plan.
# File lib/reji/subscription_item.rb, line 51 def swap(plan, options = {}) subscription.guard_against_incomplete options = { plan: plan, quantity: quantity, payment_behavior: payment_behavior, proration_behavior: proration_behavior, tax_rates: subscription.get_plan_tax_rates_for_payload(plan), }.merge(options) item = Stripe::SubscriptionItem.update( stripe_id, options, subscription.owner.stripe_options ) update(stripe_plan: plan, quantity: item.quantity) subscription.update(stripe_plan: plan, quantity: item.quantity) if subscription.single_plan? self end
swap_and_invoice(plan, options = {})
click to toggle source
Swap the subscription item to a new Stripe plan, and invoice immediately.
# File lib/reji/subscription_item.rb, line 76 def swap_and_invoice(plan, options = {}) always_invoice swap(plan, options) end
update_quantity(quantity)
click to toggle source
Update the quantity of the subscription item.
# File lib/reji/subscription_item.rb, line 34 def update_quantity(quantity) subscription.guard_against_incomplete stripe_subscription_item = as_stripe_subscription_item stripe_subscription_item.quantity = quantity stripe_subscription_item.payment_behavior = payment_behavior stripe_subscription_item.proration_behavior = proration_behavior stripe_subscription_item.save update(quantity: quantity) subscription.update(quantity: quantity) if subscription.single_plan? self end
update_stripe_subscription_item(options = {})
click to toggle source
Update the underlying Stripe subscription item information for the model.
# File lib/reji/subscription_item.rb, line 83 def update_stripe_subscription_item(options = {}) Stripe::SubscriptionItem.update( stripe_id, options, subscription.owner.stripe_options ) end