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).

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

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

Instance Attribute Details

#amountObject (readonly)

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



489
490
491
# File 'lib/stripe/resources/invoice_item.rb', line 489

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).



492
493
494
# File 'lib/stripe/resources/invoice_item.rb', line 492

def currency
  @currency
end

#customerObject (readonly)

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



495
496
497
# File 'lib/stripe/resources/invoice_item.rb', line 495

def customer
  @customer
end

#dateObject (readonly)

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



498
499
500
# File 'lib/stripe/resources/invoice_item.rb', line 498

def date
  @date
end

#deletedObject (readonly)

Always true for a deleted object



561
562
563
# File 'lib/stripe/resources/invoice_item.rb', line 561

def deleted
  @deleted
end

#descriptionObject (readonly)

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



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

def description
  @description
end

#discountableObject (readonly)

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



504
505
506
# File 'lib/stripe/resources/invoice_item.rb', line 504

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.



507
508
509
# File 'lib/stripe/resources/invoice_item.rb', line 507

def discounts
  @discounts
end

#idObject (readonly)

Unique identifier for the object.



510
511
512
# File 'lib/stripe/resources/invoice_item.rb', line 510

def id
  @id
end

#invoiceObject (readonly)

The ID of the invoice this invoice item belongs to.



513
514
515
# File 'lib/stripe/resources/invoice_item.rb', line 513

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.



516
517
518
# File 'lib/stripe/resources/invoice_item.rb', line 516

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.



519
520
521
# File 'lib/stripe/resources/invoice_item.rb', line 519

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.



522
523
524
# File 'lib/stripe/resources/invoice_item.rb', line 522

def 
  @metadata
end

#objectObject (readonly)

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



525
526
527
# File 'lib/stripe/resources/invoice_item.rb', line 525

def object
  @object
end

#periodObject (readonly)

Attribute for field period



528
529
530
# File 'lib/stripe/resources/invoice_item.rb', line 528

def period
  @period
end

#planObject (readonly)

If the invoice item is a proration, the plan of the subscription that the proration was computed for.



531
532
533
# File 'lib/stripe/resources/invoice_item.rb', line 531

def plan
  @plan
end

#priceObject (readonly)

The price of the invoice item.



534
535
536
# File 'lib/stripe/resources/invoice_item.rb', line 534

def price
  @price
end

#prorationObject (readonly)

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



537
538
539
# File 'lib/stripe/resources/invoice_item.rb', line 537

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



540
541
542
# File 'lib/stripe/resources/invoice_item.rb', line 540

def quantity
  @quantity
end

#subscriptionObject (readonly)

The subscription that this invoice item has been created for, if any.



543
544
545
# File 'lib/stripe/resources/invoice_item.rb', line 543

def subscription
  @subscription
end

#subscription_itemObject (readonly)

The subscription item that this invoice item has been created for, if any.



546
547
548
# File 'lib/stripe/resources/invoice_item.rb', line 546

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



549
550
551
# File 'lib/stripe/resources/invoice_item.rb', line 549

def tax_rates
  @tax_rates
end

#test_clockObject (readonly)

ID of the test clock this invoice item belongs to.



552
553
554
# File 'lib/stripe/resources/invoice_item.rb', line 552

def test_clock
  @test_clock
end

#unit_amountObject (readonly)

Unit amount (in the ‘currency` specified) of the invoice item.



555
556
557
# File 'lib/stripe/resources/invoice_item.rb', line 555

def unit_amount
  @unit_amount
end

#unit_amount_decimalObject (readonly)

Same as ‘unit_amount`, but contains a decimal value with at most 12 decimal places.



558
559
560
# File 'lib/stripe/resources/invoice_item.rb', line 558

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.



564
565
566
# File 'lib/stripe/resources/invoice_item.rb', line 564

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.



569
570
571
572
573
574
575
576
# File 'lib/stripe/resources/invoice_item.rb', line 569

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



589
590
591
# File 'lib/stripe/resources/invoice_item.rb', line 589

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/invoiceitems", params: params, 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.



594
595
596
597
598
599
600
601
# File 'lib/stripe/resources/invoice_item.rb', line 594

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.



579
580
581
582
583
584
585
586
# File 'lib/stripe/resources/invoice_item.rb', line 579

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