Class: Stripe::Invoice
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::Invoice
- Extended by:
- APIOperations::Create, APIOperations::List, APIOperations::Search
- Includes:
- APIOperations::Delete, APIOperations::Save
- Defined in:
- lib/stripe/resources/invoice.rb
Overview
Invoices are statements of amounts owed by a customer, and are either generated one-off, or generated periodically from a subscription.
They contain [invoice items](stripe.com/docs/api#invoiceitems), and proration adjustments that may be caused by subscription upgrades/downgrades (if necessary).
If your invoice is configured to be billed through automatic charges, Stripe automatically finalizes your invoice and attempts payment. Note that finalizing the invoice, [when automatic](stripe.com/docs/invoicing/integration/automatic-advancement-collection), does not happen immediately as the invoice is created. Stripe waits until one hour after the last webhook was successfully sent (or the last webhook timed out after failing). If you (and the platforms you may have connected to) have no webhooks configured, Stripe waits one hour after creation to finalize the invoice.
If your invoice is configured to be billed by sending an email, then based on your [email settings](dashboard.stripe.com/account/billing/automatic), Stripe will email the invoice to your customer and await payment. These emails can contain a link to a hosted page to pay the invoice.
Stripe applies any customer credit on the account before determining the amount due for the invoice (i.e., the amount that will be actually charged). If the amount due for the invoice is less than Stripe’s [minimum allowed charge per currency](stripe.com/docs/currencies#minimum-and-maximum-charge-amounts), the invoice is automatically marked paid, and we add the amount due to the customer’s credit balance which is applied to the next invoice.
More details on the customer’s credit balance are [here](stripe.com/docs/billing/customer/balance).
Related guide: [Send invoices to customers](stripe.com/docs/billing/invoices/sending)
Constant Summary collapse
- OBJECT_NAME =
"invoice"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary
Attributes inherited from APIResource
Class Method Summary collapse
-
.finalize_invoice(invoice, params = {}, opts = {}) ⇒ Object
Stripe automatically finalizes drafts before sending and attempting payment on invoices.
-
.list_upcoming_line_items(params = {}, opts = {}) ⇒ Object
When retrieving an upcoming invoice, you’ll get a lines property containing the total count of line items and the first handful of those items.
-
.mark_uncollectible(invoice, params = {}, opts = {}) ⇒ Object
Marking an invoice as uncollectible is useful for keeping track of bad debts that can be written off for accounting purposes.
-
.pay(invoice, params = {}, opts = {}) ⇒ Object
Stripe automatically creates and then attempts to collect payment on invoices for customers on subscriptions according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic).
- .search(params = {}, opts = {}) ⇒ Object
- .search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
-
.send_invoice(invoice, params = {}, opts = {}) ⇒ Object
Stripe will automatically send invoices to customers according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic).
-
.upcoming(params = {}, opts = {}) ⇒ Object
At any time, you can preview the upcoming invoice for a customer.
-
.void_invoice(invoice, params = {}, opts = {}) ⇒ Object
Mark a finalized invoice as void.
Instance Method Summary collapse
-
#finalize_invoice(params = {}, opts = {}) ⇒ Object
Stripe automatically finalizes drafts before sending and attempting payment on invoices.
-
#mark_uncollectible(params = {}, opts = {}) ⇒ Object
Marking an invoice as uncollectible is useful for keeping track of bad debts that can be written off for accounting purposes.
-
#pay(params = {}, opts = {}) ⇒ Object
Stripe automatically creates and then attempts to collect payment on invoices for customers on subscriptions according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic).
-
#send_invoice(params = {}, opts = {}) ⇒ Object
Stripe will automatically send invoices to customers according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic).
-
#void_invoice(params = {}, opts = {}) ⇒ Object
Mark a finalized invoice as void.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Search
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
Class Method Details
.finalize_invoice(invoice, params = {}, opts = {}) ⇒ Object
Stripe automatically finalizes drafts before sending and attempting payment on invoices. However, if you’d like to finalize a draft invoice manually, you can do so using this method.
99 100 101 102 103 104 105 106 |
# File 'lib/stripe/resources/invoice.rb', line 99 def self.finalize_invoice(invoice, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/finalize", { invoice: CGI.escape(invoice) }), params: params, opts: opts ) end |
.list_upcoming_line_items(params = {}, opts = {}) ⇒ Object
When retrieving an upcoming invoice, you’ll get a lines property containing the total count of line items and the first handful of those items. There is also a URL where you can retrieve the full (paginated) list of line items.
109 110 111 112 113 114 115 116 |
# File 'lib/stripe/resources/invoice.rb', line 109 def self.list_upcoming_line_items(params = {}, opts = {}) request_stripe_object( method: :get, path: "/v1/invoices/upcoming/lines", params: params, opts: opts ) end |
.mark_uncollectible(invoice, params = {}, opts = {}) ⇒ Object
Marking an invoice as uncollectible is useful for keeping track of bad debts that can be written off for accounting purposes.
119 120 121 122 123 124 125 126 |
# File 'lib/stripe/resources/invoice.rb', line 119 def self.mark_uncollectible(invoice, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/mark_uncollectible", { invoice: CGI.escape(invoice) }), params: params, opts: opts ) end |
.pay(invoice, params = {}, opts = {}) ⇒ Object
Stripe automatically creates and then attempts to collect payment on invoices for customers on subscriptions according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic). However, if you’d like to attempt payment on an invoice out of the normal collection schedule or for some other reason, you can do so.
129 130 131 132 133 134 135 136 |
# File 'lib/stripe/resources/invoice.rb', line 129 def self.pay(invoice, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/pay", { invoice: CGI.escape(invoice) }), params: params, opts: opts ) end |
.search(params = {}, opts = {}) ⇒ Object
169 170 171 |
# File 'lib/stripe/resources/invoice.rb', line 169 def self.search(params = {}, opts = {}) _search("/v1/invoices/search", params, opts) end |
.search_auto_paging_each(params = {}, opts = {}, &blk) ⇒ Object
173 174 175 |
# File 'lib/stripe/resources/invoice.rb', line 173 def self.search_auto_paging_each(params = {}, opts = {}, &blk) search(params, opts).auto_paging_each(&blk) end |
.send_invoice(invoice, params = {}, opts = {}) ⇒ Object
Stripe will automatically send invoices to customers according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic). However, if you’d like to manually send an invoice to your customer out of the normal schedule, you can do so. When sending invoices that have already been paid, there will be no reference to the payment in the email.
Requests made in test-mode result in no emails being sent, despite sending an invoice.sent event.
141 142 143 144 145 146 147 148 |
# File 'lib/stripe/resources/invoice.rb', line 141 def self.send_invoice(invoice, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/send", { invoice: CGI.escape(invoice) }), params: params, opts: opts ) end |
.upcoming(params = {}, opts = {}) ⇒ Object
At any time, you can preview the upcoming invoice for a customer. This will show you all the charges that are pending, including subscription renewal charges, invoice item charges, etc. It will also show you any discounts that are applicable to the invoice.
Note that when you are viewing an upcoming invoice, you are simply viewing a preview – the invoice has not yet been created. As such, the upcoming invoice will not show up in invoice listing calls, and you cannot use the API to pay or edit the invoice. If you want to change the amount that your customer will be billed, you can add, remove, or update pending invoice items, or update the customer’s discount.
You can preview the effects of updating a subscription, including a preview of what proration will take place. To ensure that the actual proration is calculated exactly the same as the previewed proration, you should pass a proration_date parameter when doing the actual subscription update. The value passed in should be the same as the subscription_proration_date returned on the upcoming invoice resource. The recommended way to get only the prorations being previewed is to consider only proration line items where period is equal to the subscription_proration_date on the upcoming invoice resource.
155 156 157 |
# File 'lib/stripe/resources/invoice.rb', line 155 def self.upcoming(params = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/invoices/upcoming", params: params, opts: opts) end |
.void_invoice(invoice, params = {}, opts = {}) ⇒ Object
Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is similar to [deletion](stripe.com/docs/api#delete_invoice), however it only applies to finalized invoices and maintains a papertrail where the invoice can still be found.
160 161 162 163 164 165 166 167 |
# File 'lib/stripe/resources/invoice.rb', line 160 def self.void_invoice(invoice, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/void", { invoice: CGI.escape(invoice) }), params: params, opts: opts ) end |
Instance Method Details
#finalize_invoice(params = {}, opts = {}) ⇒ Object
Stripe automatically finalizes drafts before sending and attempting payment on invoices. However, if you’d like to finalize a draft invoice manually, you can do so using this method.
47 48 49 50 51 52 53 54 |
# File 'lib/stripe/resources/invoice.rb', line 47 def finalize_invoice(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/finalize", { invoice: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#mark_uncollectible(params = {}, opts = {}) ⇒ Object
Marking an invoice as uncollectible is useful for keeping track of bad debts that can be written off for accounting purposes.
57 58 59 60 61 62 63 64 |
# File 'lib/stripe/resources/invoice.rb', line 57 def mark_uncollectible(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/mark_uncollectible", { invoice: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#pay(params = {}, opts = {}) ⇒ Object
Stripe automatically creates and then attempts to collect payment on invoices for customers on subscriptions according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic). However, if you’d like to attempt payment on an invoice out of the normal collection schedule or for some other reason, you can do so.
67 68 69 70 71 72 73 74 |
# File 'lib/stripe/resources/invoice.rb', line 67 def pay(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/pay", { invoice: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#send_invoice(params = {}, opts = {}) ⇒ Object
Stripe will automatically send invoices to customers according to your [subscriptions settings](dashboard.stripe.com/account/billing/automatic). However, if you’d like to manually send an invoice to your customer out of the normal schedule, you can do so. When sending invoices that have already been paid, there will be no reference to the payment in the email.
Requests made in test-mode result in no emails being sent, despite sending an invoice.sent event.
79 80 81 82 83 84 85 86 |
# File 'lib/stripe/resources/invoice.rb', line 79 def send_invoice(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/send", { invoice: CGI.escape(self["id"]) }), params: params, opts: opts ) end |
#void_invoice(params = {}, opts = {}) ⇒ Object
Mark a finalized invoice as void. This cannot be undone. Voiding an invoice is similar to [deletion](stripe.com/docs/api#delete_invoice), however it only applies to finalized invoices and maintains a papertrail where the invoice can still be found.
89 90 91 92 93 94 95 96 |
# File 'lib/stripe/resources/invoice.rb', line 89 def void_invoice(params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/invoices/%<invoice>s/void", { invoice: CGI.escape(self["id"]) }), params: params, opts: opts ) end |