Class: Stripe::SubscriptionItem

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::NestedResource
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, CreateParams, DeleteParams, ListParams, RetrieveParams, Trial, UpdateParams

Constant Summary collapse

OBJECT_NAME =
"subscription_item"

Constants inherited from StripeObject

Stripe::StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::NestedResource

nested_resource_class_methods

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

included

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

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #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

#billing_thresholdsObject (readonly)

Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period



476
477
478
# File 'lib/stripe/resources/subscription_item.rb', line 476

def billing_thresholds
  @billing_thresholds
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



479
480
481
# File 'lib/stripe/resources/subscription_item.rb', line 479

def created
  @created
end

#deletedObject (readonly)

Always true for a deleted object



524
525
526
# File 'lib/stripe/resources/subscription_item.rb', line 524

def deleted
  @deleted
end

#discountsObject (readonly)

The discounts applied to the subscription item. Subscription item discounts are applied before subscription discounts. Use ‘expand[]=discounts` to expand each discount.



482
483
484
# File 'lib/stripe/resources/subscription_item.rb', line 482

def discounts
  @discounts
end

#idObject (readonly)

Unique identifier for the object.



485
486
487
# File 'lib/stripe/resources/subscription_item.rb', line 485

def id
  @id
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



488
489
490
# File 'lib/stripe/resources/subscription_item.rb', line 488

def 
  @metadata
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



491
492
493
# File 'lib/stripe/resources/subscription_item.rb', line 491

def object
  @object
end

#planObject (readonly)

You can now model subscriptions more flexibly using the [Prices API](stripe.com/docs/api#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](stripe.com/docs/api#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](stripe.com/docs/billing/subscriptions/set-up-subscription) and more about [products and prices](stripe.com/docs/products-prices/overview).



501
502
503
# File 'lib/stripe/resources/subscription_item.rb', line 501

def plan
  @plan
end

#priceObject (readonly)

Prices define the unit cost, currency, and (optional) billing cycle for both recurring and one-time purchases of products. [Products](stripe.com/docs/api#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](stripe.com/docs/billing/subscriptions/set-up-subscription), [create an invoice](stripe.com/docs/billing/invoices/create), and more about [products and prices](stripe.com/docs/products-prices/overview).



509
510
511
# File 'lib/stripe/resources/subscription_item.rb', line 509

def price
  @price
end

#quantityObject (readonly)

The [quantity](stripe.com/docs/subscriptions/quantities) of the plan to which the customer should be subscribed.



512
513
514
# File 'lib/stripe/resources/subscription_item.rb', line 512

def quantity
  @quantity
end

#subscriptionObject (readonly)

The ‘subscription` this `subscription_item` belongs to.



515
516
517
# File 'lib/stripe/resources/subscription_item.rb', line 515

def subscription
  @subscription
end

#tax_ratesObject (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`.



518
519
520
# File 'lib/stripe/resources/subscription_item.rb', line 518

def tax_rates
  @tax_rates
end

#trialObject (readonly)

Options that configure the trial on the subscription item.



521
522
523
# File 'lib/stripe/resources/subscription_item.rb', line 521

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.



527
528
529
530
531
532
533
534
# File 'lib/stripe/resources/subscription_item.rb', line 527

def self.create(params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: "/v1/subscription_items",
    params: params,
    opts: opts
  )
end

.delete(id, params = {}, opts = {}) ⇒ Object

Deletes an item from the subscription. Removing a subscription item from a subscription will not cancel the subscription.



537
538
539
540
541
542
543
544
# File 'lib/stripe/resources/subscription_item.rb', line 537

def self.delete(id, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/subscription_items/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of your subscription items for a given subscription.



557
558
559
560
561
562
563
564
# File 'lib/stripe/resources/subscription_item.rb', line 557

def self.list(params = {}, opts = {})
  request_stripe_object(
    method: :get,
    path: "/v1/subscription_items",
    params: params,
    opts: opts
  )
end

.object_nameObject



15
16
17
# File 'lib/stripe/resources/subscription_item.rb', line 15

def self.object_name
  "subscription_item"
end

.update(id, params = {}, opts = {}) ⇒ Object

Updates the plan or quantity of an item on a current subscription.



567
568
569
570
571
572
573
574
# File 'lib/stripe/resources/subscription_item.rb', line 567

def self.update(id, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/subscription_items/%<id>s", { id: CGI.escape(id) }),
    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.



547
548
549
550
551
552
553
554
# File 'lib/stripe/resources/subscription_item.rb', line 547

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