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). 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).
Defined Under Namespace
Classes: CreateParams, DeleteParams, ListParams, Period, RetrieveParams, UpdateParams
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.
-
#margins ⇒ Object
readonly
The margins which apply to the invoice item.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#period ⇒ Object
readonly
Attribute for field period.
-
#plan ⇒ Object
readonly
If the invoice item is a proration, the plan of the subscription that the proration was computed for.
-
#price ⇒ Object
readonly
The price of the invoice item.
-
#proration ⇒ Object
readonly
Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.
-
#quantity ⇒ Object
readonly
Quantity of units for the invoice item.
-
#subscription ⇒ Object
readonly
The subscription that this invoice item has been created for, if any.
-
#subscription_item ⇒ Object
readonly
The subscription item that this invoice item has been created for, if any.
-
#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.
-
#unit_amount ⇒ Object
readonly
Unit amount (in the ‘currency` specified) of the invoice item.
-
#unit_amount_decimal ⇒ Object
readonly
Same as ‘unit_amount`, but contains a decimal value with at most 12 decimal places.
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.
-
.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
#==, #[], #[]=, 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`.
422 423 424 |
# File 'lib/stripe/resources/invoice_item.rb', line 422 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).
424 425 426 |
# File 'lib/stripe/resources/invoice_item.rb', line 424 def currency @currency end |
#customer ⇒ Object (readonly)
The ID of the customer who will be billed when this invoice item is billed.
426 427 428 |
# File 'lib/stripe/resources/invoice_item.rb', line 426 def customer @customer end |
#date ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
428 429 430 |
# File 'lib/stripe/resources/invoice_item.rb', line 428 def date @date end |
#deleted ⇒ Object (readonly)
Always true for a deleted object
470 471 472 |
# File 'lib/stripe/resources/invoice_item.rb', line 470 def deleted @deleted end |
#description ⇒ Object (readonly)
An arbitrary string attached to the object. Often useful for displaying to users.
430 431 432 |
# File 'lib/stripe/resources/invoice_item.rb', line 430 def description @description end |
#discountable ⇒ Object (readonly)
If true, discounts will apply to this invoice item. Always false for prorations.
432 433 434 |
# File 'lib/stripe/resources/invoice_item.rb', line 432 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.
434 435 436 |
# File 'lib/stripe/resources/invoice_item.rb', line 434 def discounts @discounts end |
#id ⇒ Object (readonly)
Unique identifier for the object.
436 437 438 |
# File 'lib/stripe/resources/invoice_item.rb', line 436 def id @id end |
#invoice ⇒ Object (readonly)
The ID of the invoice this invoice item belongs to.
438 439 440 |
# File 'lib/stripe/resources/invoice_item.rb', line 438 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.
440 441 442 |
# File 'lib/stripe/resources/invoice_item.rb', line 440 def livemode @livemode end |
#margins ⇒ Object (readonly)
The margins which apply to the invoice item. When set, the ‘default_margins` on the invoice do not apply to this invoice item.
442 443 444 |
# File 'lib/stripe/resources/invoice_item.rb', line 442 def margins @margins 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.
444 445 446 |
# File 'lib/stripe/resources/invoice_item.rb', line 444 def @metadata end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
446 447 448 |
# File 'lib/stripe/resources/invoice_item.rb', line 446 def object @object end |
#period ⇒ Object (readonly)
Attribute for field period
448 449 450 |
# File 'lib/stripe/resources/invoice_item.rb', line 448 def period @period end |
#plan ⇒ Object (readonly)
If the invoice item is a proration, the plan of the subscription that the proration was computed for.
450 451 452 |
# File 'lib/stripe/resources/invoice_item.rb', line 450 def plan @plan end |
#price ⇒ Object (readonly)
The price of the invoice item.
452 453 454 |
# File 'lib/stripe/resources/invoice_item.rb', line 452 def price @price end |
#proration ⇒ Object (readonly)
Whether the invoice item was created automatically as a proration adjustment when the customer switched plans.
454 455 456 |
# File 'lib/stripe/resources/invoice_item.rb', line 454 def proration @proration 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.
456 457 458 |
# File 'lib/stripe/resources/invoice_item.rb', line 456 def quantity @quantity end |
#subscription ⇒ Object (readonly)
The subscription that this invoice item has been created for, if any.
458 459 460 |
# File 'lib/stripe/resources/invoice_item.rb', line 458 def subscription @subscription end |
#subscription_item ⇒ Object (readonly)
The subscription item that this invoice item has been created for, if any.
460 461 462 |
# File 'lib/stripe/resources/invoice_item.rb', line 460 def subscription_item @subscription_item 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.
462 463 464 |
# File 'lib/stripe/resources/invoice_item.rb', line 462 def tax_rates @tax_rates end |
#test_clock ⇒ Object (readonly)
ID of the test clock this invoice item belongs to.
464 465 466 |
# File 'lib/stripe/resources/invoice_item.rb', line 464 def test_clock @test_clock end |
#unit_amount ⇒ Object (readonly)
Unit amount (in the ‘currency` specified) of the invoice item.
466 467 468 |
# File 'lib/stripe/resources/invoice_item.rb', line 466 def unit_amount @unit_amount end |
#unit_amount_decimal ⇒ Object (readonly)
Same as ‘unit_amount`, but contains a decimal value with at most 12 decimal places.
468 469 470 |
# File 'lib/stripe/resources/invoice_item.rb', line 468 def unit_amount_decimal @unit_amount_decimal 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.
473 474 475 |
# File 'lib/stripe/resources/invoice_item.rb', line 473 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.
478 479 480 481 482 483 484 485 |
# File 'lib/stripe/resources/invoice_item.rb', line 478 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 |
.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.
498 499 500 |
# File 'lib/stripe/resources/invoice_item.rb', line 498 def self.list(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/invoiceitems", params: params, opts: opts) end |
.object_name ⇒ Object
23 24 25 |
# File 'lib/stripe/resources/invoice_item.rb', line 23 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.
503 504 505 506 507 508 509 510 |
# File 'lib/stripe/resources/invoice_item.rb', line 503 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.
488 489 490 491 492 493 494 495 |
# File 'lib/stripe/resources/invoice_item.rb', line 488 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 |