Class: Stripe::SubscriptionItem
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::SubscriptionItem
- Extended by:
- APIOperations::Create, APIOperations::List
- Includes:
- APIOperations::Delete, APIOperations::Save
- Defined in:
- lib/stripe/resources/subscription_item.rb
Overview
Subscription items allow you to create customer subscriptions with more than one plan, making it easy to represent complex billing relationships.
Defined Under Namespace
Classes: BillingThresholds, CurrentTrial, Trial
Constant Summary collapse
- OBJECT_NAME =
"subscription_item"
Constants inherited from StripeObject
Stripe::StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#billed_until ⇒ Object
readonly
The time period the subscription item has been billed for.
-
#billing_thresholds ⇒ Object
readonly
Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#current_period_end ⇒ Object
readonly
The end time of this subscription item’s current billing period.
-
#current_period_start ⇒ Object
readonly
The start time of this subscription item’s current billing period.
-
#current_trial ⇒ Object
readonly
The current trial that is applied to this subscription item.
-
#deleted ⇒ Object
readonly
Always true for a deleted object.
-
#discounts ⇒ Object
readonly
The discounts applied to the subscription item.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](docs.stripe.com/api/metadata) that you can attach to an object.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#plan ⇒ Object
readonly
You can now model subscriptions more flexibly using the [Prices API](api.stripe.com#prices).
-
#price ⇒ Object
readonly
Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products.
-
#quantity ⇒ Object
readonly
The [quantity](docs.stripe.com/subscriptions/quantities) of the plan to which the customer should be subscribed.
-
#subscription ⇒ Object
readonly
The ‘subscription` this `subscription_item` belongs to.
-
#tax_rates ⇒ Object
readonly
The tax rates which apply to this ‘subscription_item`.
-
#trial ⇒ Object
readonly
Options that configure the trial on the subscription item.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.create(params = {}, opts = {}) ⇒ Object
Adds a new item to an existing subscription.
-
.delete(item, params = {}, opts = {}) ⇒ Object
Deletes an item from the subscription.
- .field_remappings ⇒ Object
- .inner_class_types ⇒ Object
-
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your subscription items for a given subscription.
- .object_name ⇒ Object
-
.update(item, params = {}, opts = {}) ⇒ Object
Updates the plan or quantity of an item on a current subscription.
Instance Method Summary collapse
-
#delete(params = {}, opts = {}) ⇒ Object
Deletes an item from the subscription.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Save
Methods included from APIOperations::Delete
Methods inherited from APIResource
class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource
Methods included from APIOperations::Request
Methods inherited from StripeObject
#==, #[], #[]=, #_get_inner_class_type, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, field_encodings, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values
Constructor Details
This class inherits a constructor from Stripe::StripeObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject
Instance Attribute Details
#billed_until ⇒ Object (readonly)
The time period the subscription item has been billed for.
63 64 65 |
# File 'lib/stripe/resources/subscription_item.rb', line 63 def billed_until @billed_until end |
#billing_thresholds ⇒ Object (readonly)
Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period
65 66 67 |
# File 'lib/stripe/resources/subscription_item.rb', line 65 def billing_thresholds @billing_thresholds end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
67 68 69 |
# File 'lib/stripe/resources/subscription_item.rb', line 67 def created @created end |
#current_period_end ⇒ Object (readonly)
The end time of this subscription item’s current billing period.
69 70 71 |
# File 'lib/stripe/resources/subscription_item.rb', line 69 def current_period_end @current_period_end end |
#current_period_start ⇒ Object (readonly)
The start time of this subscription item’s current billing period.
71 72 73 |
# File 'lib/stripe/resources/subscription_item.rb', line 71 def current_period_start @current_period_start end |
#current_trial ⇒ Object (readonly)
The current trial that is applied to this subscription item.
73 74 75 |
# File 'lib/stripe/resources/subscription_item.rb', line 73 def current_trial @current_trial end |
#deleted ⇒ Object (readonly)
Always true for a deleted object
75 76 77 |
# File 'lib/stripe/resources/subscription_item.rb', line 75 def deleted @deleted end |
#discounts ⇒ Object (readonly)
The discounts applied to the subscription item. Subscription item discounts are applied before subscription discounts. Use ‘expand[]=discounts` to expand each discount.
77 78 79 |
# File 'lib/stripe/resources/subscription_item.rb', line 77 def discounts @discounts end |
#id ⇒ Object (readonly)
Unique identifier for the object.
79 80 81 |
# File 'lib/stripe/resources/subscription_item.rb', line 79 def id @id end |
#metadata ⇒ Object (readonly)
Set of [key-value pairs](docs.stripe.com/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
81 82 83 |
# File 'lib/stripe/resources/subscription_item.rb', line 81 def @metadata end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
83 84 85 |
# File 'lib/stripe/resources/subscription_item.rb', line 83 def object @object end |
#plan ⇒ Object (readonly)
You can now model subscriptions more flexibly using the [Prices API](api.stripe.com#prices). It replaces the Plans API and is backwards compatible to simplify your migration.
Plans define the base price, currency, and billing cycle for recurring purchases of products. [Products](api.stripe.com#products) help you track inventory or provisioning, and plans help you track pricing. Different physical goods or levels of service should be represented by products, and pricing options should be represented by plans. This approach lets you change prices without having to change your provisioning scheme.
For example, you might have a single “gold” product that has plans for $10/month, $100/year, €9/month, and €90/year.
Related guides: [Set up a subscription](docs.stripe.com/billing/subscriptions/set-up-subscription) and more about [products and prices](docs.stripe.com/products-prices/overview).
92 93 94 |
# File 'lib/stripe/resources/subscription_item.rb', line 92 def plan @plan end |
#price ⇒ Object (readonly)
Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. [Products](api.stripe.com#products) help you track inventory or provisioning, and prices help you track payment terms. Different physical goods or levels of service should be represented by products, and pricing options should be represented by prices. This approach lets you change prices without having to change your provisioning scheme.
For example, you might have a single “gold” product that has prices for $10/month, $100/year, and €9 once.
Related guides: [Set up a subscription](docs.stripe.com/billing/subscriptions/set-up-subscription), [create an invoice](docs.stripe.com/billing/invoices/create), and more about [products and prices](docs.stripe.com/products-prices/overview).
99 100 101 |
# File 'lib/stripe/resources/subscription_item.rb', line 99 def price @price end |
#quantity ⇒ Object (readonly)
The [quantity](docs.stripe.com/subscriptions/quantities) of the plan to which the customer should be subscribed.
101 102 103 |
# File 'lib/stripe/resources/subscription_item.rb', line 101 def quantity @quantity end |
#subscription ⇒ Object (readonly)
The ‘subscription` this `subscription_item` belongs to.
103 104 105 |
# File 'lib/stripe/resources/subscription_item.rb', line 103 def subscription @subscription end |
#tax_rates ⇒ Object (readonly)
The tax rates which apply to this ‘subscription_item`. When set, the `default_tax_rates` on the subscription do not apply to this `subscription_item`.
105 106 107 |
# File 'lib/stripe/resources/subscription_item.rb', line 105 def tax_rates @tax_rates end |
#trial ⇒ Object (readonly)
Options that configure the trial on the subscription item.
107 108 109 |
# File 'lib/stripe/resources/subscription_item.rb', line 107 def trial @trial end |
Class Method Details
.create(params = {}, opts = {}) ⇒ Object
Adds a new item to an existing subscription. No existing items will be changed or replaced.
110 111 112 113 114 115 116 117 |
# File 'lib/stripe/resources/subscription_item.rb', line 110 def self.create(params = {}, opts = {}) request_stripe_object( method: :post, path: "/v1/subscription_items", params: params, opts: opts ) end |
.delete(item, params = {}, opts = {}) ⇒ Object
Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription.
120 121 122 123 124 125 126 127 |
# File 'lib/stripe/resources/subscription_item.rb', line 120 def self.delete(item, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(item) }), params: params, opts: opts ) end |
.field_remappings ⇒ Object
167 168 169 |
# File 'lib/stripe/resources/subscription_item.rb', line 167 def self.field_remappings @field_remappings = {} end |
.inner_class_types ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/stripe/resources/subscription_item.rb', line 159 def self.inner_class_types @inner_class_types = { billing_thresholds: BillingThresholds, current_trial: CurrentTrial, trial: Trial, } end |
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your subscription items for a given subscription.
140 141 142 143 144 145 146 147 |
# File 'lib/stripe/resources/subscription_item.rb', line 140 def self.list(params = {}, opts = {}) request_stripe_object( method: :get, path: "/v1/subscription_items", params: params, opts: opts ) end |
.object_name ⇒ Object
14 15 16 |
# File 'lib/stripe/resources/subscription_item.rb', line 14 def self.object_name "subscription_item" end |
.update(item, params = {}, opts = {}) ⇒ Object
Updates the plan or quantity of an item on a current subscription.
150 151 152 153 154 155 156 157 |
# File 'lib/stripe/resources/subscription_item.rb', line 150 def self.update(item, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(item) }), params: params, opts: opts ) end |
Instance Method Details
#delete(params = {}, opts = {}) ⇒ Object
Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription.
130 131 132 133 134 135 136 137 |
# File 'lib/stripe/resources/subscription_item.rb', line 130 def delete(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/subscription_items/%<item>s", { item: CGI.escape(self["id"]) }), params: params, opts: opts ) end |