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). An invoice item is added to an invoice by creating or updating it with an ‘invoice` field, at which point it will be 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).

Constant Summary collapse

OBJECT_NAME =
"invoiceitem"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

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

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

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.



28
29
30
# File 'lib/stripe/resources/invoice_item.rb', line 28

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

.delete(id, 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.



33
34
35
36
37
38
39
40
# File 'lib/stripe/resources/invoice_item.rb', line 33

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

.list(filters = {}, 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.



53
54
55
# File 'lib/stripe/resources/invoice_item.rb', line 53

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

.object_nameObject



23
24
25
# File 'lib/stripe/resources/invoice_item.rb', line 23

def self.object_name
  "invoiceitem"
end

.update(id, 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.



58
59
60
61
62
63
64
65
# File 'lib/stripe/resources/invoice_item.rb', line 58

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



43
44
45
46
47
48
49
50
# File 'lib/stripe/resources/invoice_item.rb', line 43

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