stripe-ruby/lib/stripe/resources/invoice_item.rb
2024-02-05 20:32:27 +00:00

65 lines
3.3 KiB
Ruby

# File generated from our OpenAPI spec
# frozen_string_literal: true
module Stripe
# Invoice Items represent the component lines of an [invoice](https://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](https://stripe.com/docs/api/invoices/line_item) within
# [invoice.lines](https://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](https://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](https://stripe.com/docs/invoicing/integration), [Subscription Invoices](https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items).
class InvoiceItem < APIResource
extend Stripe::APIOperations::Create
include Stripe::APIOperations::Delete
extend Stripe::APIOperations::List
include Stripe::APIOperations::Save
OBJECT_NAME = "invoiceitem"
# 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.
def self.create(params = {}, opts = {})
request_stripe_object(method: :post, path: "/v1/invoiceitems", params: params, opts: opts)
end
# 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.
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
# 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.
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
# Returns a list of your invoice items. Invoice items are returned sorted by creation date, with the most recently created invoice items appearing first.
def self.list(filters = {}, opts = {})
request_stripe_object(method: :get, path: "/v1/invoiceitems", params: filters, opts: opts)
end
# 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.
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
end
end