Class: Stripe::InvoiceItem

Inherits:
APIResource show all
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

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::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

#==, #[], #[]=, #_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

#amountObject (readonly)

Amount (in the ‘currency` specified) of the invoice item. This should always be equal to `unit_amount * quantity`.



214
215
216
# File 'lib/stripe/resources/invoice_item.rb', line 214

def amount
  @amount
end

#currencyObject (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).



216
217
218
# File 'lib/stripe/resources/invoice_item.rb', line 216

def currency
  @currency
end

#customerObject (readonly)

The ID of the customer who will be billed when this invoice item is billed.



218
219
220
# File 'lib/stripe/resources/invoice_item.rb', line 218

def customer
  @customer
end

#customer_accountObject (readonly)

The ID of the account who will be billed when this invoice item is billed.



220
221
222
# File 'lib/stripe/resources/invoice_item.rb', line 220

def 
  @customer_account
end

#dateObject (readonly)

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



222
223
224
# File 'lib/stripe/resources/invoice_item.rb', line 222

def date
  @date
end

#deletedObject (readonly)

Always true for a deleted object



260
261
262
# File 'lib/stripe/resources/invoice_item.rb', line 260

def deleted
  @deleted
end

#descriptionObject (readonly)

An arbitrary string attached to the object. Often useful for displaying to users.



224
225
226
# File 'lib/stripe/resources/invoice_item.rb', line 224

def description
  @description
end

#discountableObject (readonly)

If true, discounts will apply to this invoice item. Always false for prorations.



226
227
228
# File 'lib/stripe/resources/invoice_item.rb', line 226

def discountable
  @discountable
end

#discountsObject (readonly)

The discounts which apply to the invoice item. Item discounts are applied before invoice discounts. Use ‘expand[]=discounts` to expand each discount.



228
229
230
# File 'lib/stripe/resources/invoice_item.rb', line 228

def discounts
  @discounts
end

#idObject (readonly)

Unique identifier for the object.



230
231
232
# File 'lib/stripe/resources/invoice_item.rb', line 230

def id
  @id
end

#invoiceObject (readonly)

The ID of the invoice this invoice item belongs to.



232
233
234
# File 'lib/stripe/resources/invoice_item.rb', line 232

def invoice
  @invoice
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



234
235
236
# File 'lib/stripe/resources/invoice_item.rb', line 234

def livemode
  @livemode
end

#marginsObject (readonly)

The margins which apply to the invoice item. When set, the ‘default_margins` on the invoice do not apply to this invoice item.



236
237
238
# File 'lib/stripe/resources/invoice_item.rb', line 236

def margins
  @margins
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.



238
239
240
# File 'lib/stripe/resources/invoice_item.rb', line 238

def 
  @metadata
end

#net_amountObject (readonly)

The amount after discounts, but before credits and taxes. This field is ‘null` for `discountable=true` items.



240
241
242
# File 'lib/stripe/resources/invoice_item.rb', line 240

def net_amount
  @net_amount
end

#objectObject (readonly)

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



242
243
244
# File 'lib/stripe/resources/invoice_item.rb', line 242

def object
  @object
end

#parentObject (readonly)

The parent that generated this invoice item.



244
245
246
# File 'lib/stripe/resources/invoice_item.rb', line 244

def parent
  @parent
end

#periodObject (readonly)

Attribute for field period



246
247
248
# File 'lib/stripe/resources/invoice_item.rb', line 246

def period
  @period
end

#pricingObject (readonly)

The pricing information of the invoice item.



248
249
250
# File 'lib/stripe/resources/invoice_item.rb', line 248

def pricing
  @pricing
end

#prorationObject (readonly)

Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.



250
251
252
# File 'lib/stripe/resources/invoice_item.rb', line 250

def proration
  @proration
end

#proration_detailsObject (readonly)

Attribute for field proration_details



252
253
254
# File 'lib/stripe/resources/invoice_item.rb', line 252

def proration_details
  @proration_details
end

#quantityObject (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.



254
255
256
# File 'lib/stripe/resources/invoice_item.rb', line 254

def quantity
  @quantity
end

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



256
257
258
# File 'lib/stripe/resources/invoice_item.rb', line 256

def tax_rates
  @tax_rates
end

#test_clockObject (readonly)

ID of the test clock this invoice item belongs to.



258
259
260
# File 'lib/stripe/resources/invoice_item.rb', line 258

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.



263
264
265
# File 'lib/stripe/resources/invoice_item.rb', line 263

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.



268
269
270
271
272
273
274
275
# File 'lib/stripe/resources/invoice_item.rb', line 268

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_remappingsObject



311
312
313
# File 'lib/stripe/resources/invoice_item.rb', line 311

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



302
303
304
305
306
307
308
309
# File 'lib/stripe/resources/invoice_item.rb', line 302

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.



288
289
290
# File 'lib/stripe/resources/invoice_item.rb', line 288

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

.object_nameObject



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.



293
294
295
296
297
298
299
300
# File 'lib/stripe/resources/invoice_item.rb', line 293

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.



278
279
280
281
282
283
284
285
# File 'lib/stripe/resources/invoice_item.rb', line 278

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