Class: Stripe::InvoiceItem
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::InvoiceItem
- Extended by:
- APIOperations::Create, APIOperations::List
- Includes:
- APIOperations::Delete, APIOperations::Save
- Defined in:
- lib/stripe/resources/invoice_item.rb
Overview
Invoice Items represent the component lines of an [invoice](stripe.com/docs/api/invoices). When you create an invoice item with an ‘invoice` field, it is attached to the specified invoice and included as [an invoice line item](stripe.com/docs/api/invoices/line_item) within [invoice.lines](stripe.com/docs/api/invoices/object#invoice_object-lines).
Invoice Items can be created before you are ready to actually send the invoice. This can be particularly useful when combined with a [subscription](stripe.com/docs/api/subscriptions). Sometimes you want to add a charge or credit to a customer, but actually charge or credit the customer’s card only at the end of a regular billing cycle. This is useful for combining several charges (to minimize per-transaction fees), or for having Stripe tabulate your usage-based billing totals.
Related guides: [Integrate with the Invoicing API](stripe.com/docs/invoicing/integration), [Subscription Invoices](stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items).
Defined Under Namespace
Classes: Parent, Period, Pricing, ProrationDetails
Constant Summary collapse
- OBJECT_NAME =
"invoiceitem"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Amount (in the ‘currency` specified) of the invoice item.
-
#currency ⇒ Object
readonly
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase.
-
#customer ⇒ Object
readonly
The ID of the customer who will be billed when this invoice item is billed.
-
#date ⇒ Object
readonly
Time at which the object was created.
-
#deleted ⇒ Object
readonly
Always true for a deleted object.
-
#description ⇒ Object
readonly
An arbitrary string attached to the object.
-
#discountable ⇒ Object
readonly
If true, discounts will apply to this invoice item.
-
#discounts ⇒ Object
readonly
The discounts which apply to the invoice item.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#invoice ⇒ Object
readonly
The ID of the invoice this invoice item belongs to.
-
#livemode ⇒ Object
readonly
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#net_amount ⇒ Object
readonly
The amount after discounts, but before credits and taxes.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#parent ⇒ Object
readonly
The parent that generated this invoice item.
-
#period ⇒ Object
readonly
Attribute for field period.
-
#pricing ⇒ Object
readonly
The pricing information of the invoice item.
-
#proration ⇒ Object
readonly
Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.
-
#proration_details ⇒ Object
readonly
Attribute for field proration_details.
-
#quantity ⇒ Object
readonly
Quantity of units for the invoice item.
-
#tax_rates ⇒ Object
readonly
The tax rates which apply to the invoice item.
-
#test_clock ⇒ Object
readonly
ID of the test clock this invoice item belongs to.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.create(params = {}, opts = {}) ⇒ Object
Creates an item to be added to a draft invoice (up to 250 items per invoice).
-
.delete(invoiceitem, params = {}, opts = {}) ⇒ Object
Deletes an invoice item, removing it from an invoice.
- .field_remappings ⇒ Object
- .inner_class_types ⇒ Object
-
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your invoice items.
- .object_name ⇒ Object
-
.update(invoiceitem, params = {}, opts = {}) ⇒ Object
Updates the amount or description of an invoice item on an upcoming invoice.
Instance Method Summary collapse
-
#delete(params = {}, opts = {}) ⇒ Object
Deletes an invoice item, removing it from an invoice.
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?, #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
#amount ⇒ Object (readonly)
Amount (in the ‘currency` specified) of the invoice item. This should always be equal to `unit_amount * quantity`.
126 127 128 |
# File 'lib/stripe/resources/invoice_item.rb', line 126 def amount @amount end |
#currency ⇒ Object (readonly)
Three-letter [ISO currency code](www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](stripe.com/docs/currencies).
128 129 130 |
# File 'lib/stripe/resources/invoice_item.rb', line 128 def currency @currency end |
#customer ⇒ Object (readonly)
The ID of the customer who will be billed when this invoice item is billed.
130 131 132 |
# File 'lib/stripe/resources/invoice_item.rb', line 130 def customer @customer end |
#date ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
132 133 134 |
# File 'lib/stripe/resources/invoice_item.rb', line 132 def date @date end |
#deleted ⇒ Object (readonly)
Always true for a deleted object
168 169 170 |
# File 'lib/stripe/resources/invoice_item.rb', line 168 def deleted @deleted end |
#description ⇒ Object (readonly)
An arbitrary string attached to the object. Often useful for displaying to users.
134 135 136 |
# File 'lib/stripe/resources/invoice_item.rb', line 134 def description @description end |
#discountable ⇒ Object (readonly)
If true, discounts will apply to this invoice item. Always false for prorations.
136 137 138 |
# File 'lib/stripe/resources/invoice_item.rb', line 136 def discountable @discountable end |
#discounts ⇒ Object (readonly)
The discounts which apply to the invoice item. Item discounts are applied before invoice discounts. Use ‘expand[]=discounts` to expand each discount.
138 139 140 |
# File 'lib/stripe/resources/invoice_item.rb', line 138 def discounts @discounts end |
#id ⇒ Object (readonly)
Unique identifier for the object.
140 141 142 |
# File 'lib/stripe/resources/invoice_item.rb', line 140 def id @id end |
#invoice ⇒ Object (readonly)
The ID of the invoice this invoice item belongs to.
142 143 144 |
# File 'lib/stripe/resources/invoice_item.rb', line 142 def invoice @invoice end |
#livemode ⇒ Object (readonly)
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
144 145 146 |
# File 'lib/stripe/resources/invoice_item.rb', line 144 def livemode @livemode end |
#metadata ⇒ Object (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.
146 147 148 |
# File 'lib/stripe/resources/invoice_item.rb', line 146 def @metadata end |
#net_amount ⇒ Object (readonly)
The amount after discounts, but before credits and taxes. This field is ‘null` for `discountable=true` items.
148 149 150 |
# File 'lib/stripe/resources/invoice_item.rb', line 148 def net_amount @net_amount end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
150 151 152 |
# File 'lib/stripe/resources/invoice_item.rb', line 150 def object @object end |
#parent ⇒ Object (readonly)
The parent that generated this invoice item.
152 153 154 |
# File 'lib/stripe/resources/invoice_item.rb', line 152 def parent @parent end |
#period ⇒ Object (readonly)
Attribute for field period
154 155 156 |
# File 'lib/stripe/resources/invoice_item.rb', line 154 def period @period end |
#pricing ⇒ Object (readonly)
The pricing information of the invoice item.
156 157 158 |
# File 'lib/stripe/resources/invoice_item.rb', line 156 def pricing @pricing end |
#proration ⇒ Object (readonly)
Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.
158 159 160 |
# File 'lib/stripe/resources/invoice_item.rb', line 158 def proration @proration end |
#proration_details ⇒ Object (readonly)
Attribute for field proration_details
160 161 162 |
# File 'lib/stripe/resources/invoice_item.rb', line 160 def proration_details @proration_details end |
#quantity ⇒ Object (readonly)
Quantity of units for the invoice item. If the invoice item is a proration, the quantity of the subscription that the proration was computed for.
162 163 164 |
# File 'lib/stripe/resources/invoice_item.rb', line 162 def quantity @quantity end |
#tax_rates ⇒ Object (readonly)
The tax rates which apply to the invoice item. When set, the ‘default_tax_rates` on the invoice do not apply to this invoice item.
164 165 166 |
# File 'lib/stripe/resources/invoice_item.rb', line 164 def tax_rates @tax_rates end |
#test_clock ⇒ Object (readonly)
ID of the test clock this invoice item belongs to.
166 167 168 |
# File 'lib/stripe/resources/invoice_item.rb', line 166 def test_clock @test_clock end |
Class Method Details
.create(params = {}, opts = {}) ⇒ Object
Creates an item to be added to a draft invoice (up to 250 items per invoice). If no invoice is specified, the item will be on the next invoice created for the customer specified.
171 172 173 |
# File 'lib/stripe/resources/invoice_item.rb', line 171 def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/invoiceitems", params: params, opts: opts) end |
.delete(invoiceitem, params = {}, opts = {}) ⇒ Object
Deletes an invoice item, removing it from an invoice. Deleting invoice items is only possible when they’re not attached to invoices, or if it’s attached to a draft invoice.
176 177 178 179 180 181 182 183 |
# File 'lib/stripe/resources/invoice_item.rb', line 176 def self.delete(invoiceitem, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/invoiceitems/%<invoiceitem>s", { invoiceitem: CGI.escape(invoiceitem) }), params: params, opts: opts ) end |
.field_remappings ⇒ Object
219 220 221 |
# File 'lib/stripe/resources/invoice_item.rb', line 219 def self.field_remappings @field_remappings = {} end |
.inner_class_types ⇒ Object
210 211 212 213 214 215 216 217 |
# File 'lib/stripe/resources/invoice_item.rb', line 210 def self.inner_class_types @inner_class_types = { parent: Parent, period: Period, pricing: Pricing, proration_details: ProrationDetails, } end |
.list(params = {}, opts = {}) ⇒ Object
Returns a list of your invoice items. Invoice items are returned sorted by creation date, with the most recently created invoice items appearing first.
196 197 198 |
# File 'lib/stripe/resources/invoice_item.rb', line 196 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/invoiceitems", params: params, opts: opts) end |
.object_name ⇒ Object
20 21 22 |
# File 'lib/stripe/resources/invoice_item.rb', line 20 def self.object_name "invoiceitem" end |
.update(invoiceitem, params = {}, opts = {}) ⇒ Object
Updates the amount or description of an invoice item on an upcoming invoice. Updating an invoice item is only possible before the invoice it’s attached to is closed.
201 202 203 204 205 206 207 208 |
# File 'lib/stripe/resources/invoice_item.rb', line 201 def self.update(invoiceitem, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoiceitems/%<invoiceitem>s", { invoiceitem: CGI.escape(invoiceitem) }), params: params, opts: opts ) end |
Instance Method Details
#delete(params = {}, opts = {}) ⇒ Object
Deletes an invoice item, removing it from an invoice. Deleting invoice items is only possible when they’re not attached to invoices, or if it’s attached to a draft invoice.
186 187 188 189 190 191 192 193 |
# File 'lib/stripe/resources/invoice_item.rb', line 186 def delete(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/invoiceitems/%<invoiceitem>s", { invoiceitem: CGI.escape(self["id"]) }), params: params, opts: opts ) end |