stripe/model/invoice.rs
1use serde::{Serialize, Deserialize};
2use super::{
3 AutomaticTax, DiscountsResourceDiscountAmount, InvoiceLinesList,
4 InvoiceSettingCustomField, InvoiceTaxAmount, InvoiceThresholdReason,
5 InvoicesPaymentSettings, InvoicesResourceInvoiceTaxId, InvoicesStatusTransitions,
6 TaxRate,
7};
8/**Invoices are statements of amounts owed by a customer, and are either
9generated one-off, or generated periodically from a subscription.
10
11They contain [invoice items](https://stripe.com/docs/api#invoiceitems), and proration adjustments
12that may be caused by subscription upgrades/downgrades (if necessary).
13
14If your invoice is configured to be billed through automatic charges,
15Stripe automatically finalizes your invoice and attempts payment. Note
16that finalizing the invoice,
17[when automatic](https://stripe.com/docs/invoicing/integration/automatic-advancement-collection), does
18not happen immediately as the invoice is created. Stripe waits
19until one hour after the last webhook was successfully sent (or the last
20webhook timed out after failing). If you (and the platforms you may have
21connected to) have no webhooks configured, Stripe waits one hour after
22creation to finalize the invoice.
23
24If your invoice is configured to be billed by sending an email, then based on your
25[email settings](https://dashboard.stripe.com/account/billing/automatic),
26Stripe will email the invoice to your customer and await payment. These
27emails can contain a link to a hosted page to pay the invoice.
28
29Stripe applies any customer credit on the account before determining the
30amount due for the invoice (i.e., the amount that will be actually
31charged). If the amount due for the invoice is less than Stripe's [minimum allowed charge
32per currency](/docs/currencies#minimum-and-maximum-charge-amounts), the
33invoice is automatically marked paid, and we add the amount due to the
34customer's credit balance which is applied to the next invoice.
35
36More details on the customer's credit balance are
37[here](https://stripe.com/docs/billing/customer/balance).
38
39Related guide: [Send invoices to customers](https://stripe.com/docs/billing/invoices/sending)*/
40#[derive(Debug, Clone, Serialize, Deserialize, Default)]
41pub struct Invoice {
42 ///The country of the business associated with this invoice, most often the business creating the invoice.
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub account_country: Option<String>,
45 ///The public name of the business associated with this invoice, most often the business creating the invoice.
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub account_name: Option<String>,
48 ///The account tax IDs associated with the invoice. Only editable when the invoice is a draft.
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub account_tax_ids: Option<Vec<serde_json::Value>>,
51 ///Final amount due at this time for this invoice. If the invoice's total is smaller than the minimum charge amount, for example, or if there is account credit that can be applied to the invoice, the `amount_due` may be 0. If there is a positive `starting_balance` for the invoice (the customer owes money), the `amount_due` will also take that into account. The charge that gets generated for the invoice will be for the amount specified in `amount_due`.
52 pub amount_due: i64,
53 ///The amount, in cents (or local equivalent), that was paid.
54 pub amount_paid: i64,
55 ///The difference between amount_due and amount_paid, in cents (or local equivalent).
56 pub amount_remaining: i64,
57 ///This is the sum of all the shipping amounts.
58 pub amount_shipping: i64,
59 ///ID of the Connect Application that created the invoice.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub application: Option<serde_json::Value>,
62 ///The fee in cents (or local equivalent) that will be applied to the invoice and transferred to the application owner's Stripe account when the invoice is paid.
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub application_fee_amount: Option<i64>,
65 ///Number of payment attempts made for this invoice, from the perspective of the payment retry schedule. Any payment attempt counts as the first attempt, and subsequently only automatic retries increment the attempt count. In other words, manual payment attempts after the first attempt do not affect the retry schedule.
66 pub attempt_count: i64,
67 ///Whether an attempt has been made to pay the invoice. An invoice is not attempted until 1 hour after the `invoice.created` webhook, for example, so you might not want to display that invoice as unpaid to your users.
68 pub attempted: bool,
69 ///Controls whether Stripe performs [automatic collection](https://stripe.com/docs/invoicing/integration/automatic-advancement-collection) of the invoice. If `false`, the invoice's state doesn't automatically advance without an explicit action.
70 #[serde(skip_serializing_if = "Option::is_none")]
71 pub auto_advance: Option<bool>,
72 ///
73 pub automatic_tax: AutomaticTax,
74 /**Indicates the reason why the invoice was created.
75
76* `manual`: Unrelated to a subscription, for example, created via the invoice editor.
77* `subscription`: No longer in use. Applies to subscriptions from before May 2018 where no distinction was made between updates, cycles, and thresholds.
78* `subscription_create`: A new subscription was created.
79* `subscription_cycle`: A subscription advanced into a new period.
80* `subscription_threshold`: A subscription reached a billing threshold.
81* `subscription_update`: A subscription was updated.
82* `upcoming`: Reserved for simulated invoices, per the upcoming invoice endpoint.*/
83 #[serde(skip_serializing_if = "Option::is_none")]
84 pub billing_reason: Option<String>,
85 ///ID of the latest charge generated for this invoice, if any.
86 #[serde(skip_serializing_if = "Option::is_none")]
87 pub charge: Option<serde_json::Value>,
88 ///Either `charge_automatically`, or `send_invoice`. When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer. When sending an invoice, Stripe will email this invoice to the customer with payment instructions.
89 pub collection_method: String,
90 ///Time at which the object was created. Measured in seconds since the Unix epoch.
91 pub created: i64,
92 ///Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
93 pub currency: String,
94 ///Custom fields displayed on the invoice.
95 #[serde(skip_serializing_if = "Option::is_none")]
96 pub custom_fields: Option<Vec<InvoiceSettingCustomField>>,
97 ///The ID of the customer who will be billed.
98 #[serde(skip_serializing_if = "Option::is_none")]
99 pub customer: Option<serde_json::Value>,
100 ///The customer's address. Until the invoice is finalized, this field will equal `customer.address`. Once the invoice is finalized, this field will no longer be updated.
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub customer_address: Option<serde_json::Value>,
103 ///The customer's email. Until the invoice is finalized, this field will equal `customer.email`. Once the invoice is finalized, this field will no longer be updated.
104 #[serde(skip_serializing_if = "Option::is_none")]
105 pub customer_email: Option<String>,
106 ///The customer's name. Until the invoice is finalized, this field will equal `customer.name`. Once the invoice is finalized, this field will no longer be updated.
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub customer_name: Option<String>,
109 ///The customer's phone number. Until the invoice is finalized, this field will equal `customer.phone`. Once the invoice is finalized, this field will no longer be updated.
110 #[serde(skip_serializing_if = "Option::is_none")]
111 pub customer_phone: Option<String>,
112 ///The customer's shipping information. Until the invoice is finalized, this field will equal `customer.shipping`. Once the invoice is finalized, this field will no longer be updated.
113 #[serde(skip_serializing_if = "Option::is_none")]
114 pub customer_shipping: Option<serde_json::Value>,
115 ///The customer's tax exempt status. Until the invoice is finalized, this field will equal `customer.tax_exempt`. Once the invoice is finalized, this field will no longer be updated.
116 #[serde(skip_serializing_if = "Option::is_none")]
117 pub customer_tax_exempt: Option<String>,
118 ///The customer's tax IDs. Until the invoice is finalized, this field will contain the same tax IDs as `customer.tax_ids`. Once the invoice is finalized, this field will no longer be updated.
119 #[serde(skip_serializing_if = "Option::is_none")]
120 pub customer_tax_ids: Option<Vec<InvoicesResourceInvoiceTaxId>>,
121 ///ID of the default payment method for the invoice. It must belong to the customer associated with the invoice. If not set, defaults to the subscription's default payment method, if any, or to the default payment method in the customer's invoice settings.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub default_payment_method: Option<serde_json::Value>,
124 ///ID of the default payment source for the invoice. It must belong to the customer associated with the invoice and be in a chargeable state. If not set, defaults to the subscription's default source, if any, or to the customer's default source.
125 #[serde(skip_serializing_if = "Option::is_none")]
126 pub default_source: Option<serde_json::Value>,
127 ///The tax rates applied to this invoice, if any.
128 pub default_tax_rates: Vec<TaxRate>,
129 ///An arbitrary string attached to the object. Often useful for displaying to users. Referenced as 'memo' in the Dashboard.
130 #[serde(skip_serializing_if = "Option::is_none")]
131 pub description: Option<String>,
132 ///Describes the current discount applied to this invoice, if there is one. Not populated if there are multiple discounts.
133 #[serde(skip_serializing_if = "Option::is_none")]
134 pub discount: Option<serde_json::Value>,
135 ///The discounts applied to the invoice. Line item discounts are applied before invoice discounts. Use `expand[]=discounts` to expand each discount.
136 #[serde(skip_serializing_if = "Option::is_none")]
137 pub discounts: Option<Vec<serde_json::Value>>,
138 ///The date on which payment for this invoice is due. This value will be `null` for invoices where `collection_method=charge_automatically`.
139 #[serde(skip_serializing_if = "Option::is_none")]
140 pub due_date: Option<i64>,
141 ///The date when this invoice is in effect. Same as `finalized_at` unless overwritten. When defined, this value replaces the system-generated 'Date of issue' printed on the invoice PDF and receipt.
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub effective_at: Option<i64>,
144 ///Ending customer balance after the invoice is finalized. Invoices are finalized approximately an hour after successful webhook delivery or when payment collection is attempted for the invoice. If the invoice has not been finalized yet, this will be null.
145 #[serde(skip_serializing_if = "Option::is_none")]
146 pub ending_balance: Option<i64>,
147 ///Footer displayed on the invoice.
148 #[serde(skip_serializing_if = "Option::is_none")]
149 pub footer: Option<String>,
150 ///Details of the invoice that was cloned. See the [revision documentation](https://stripe.com/docs/invoicing/invoice-revisions) for more details.
151 #[serde(skip_serializing_if = "Option::is_none")]
152 pub from_invoice: Option<serde_json::Value>,
153 ///The URL for the hosted invoice page, which allows customers to view and pay an invoice. If the invoice has not been finalized yet, this will be null.
154 #[serde(skip_serializing_if = "Option::is_none")]
155 pub hosted_invoice_url: Option<String>,
156 ///Unique identifier for the object. This property is always present unless the invoice is an upcoming invoice. See [Retrieve an upcoming invoice](https://stripe.com/docs/api/invoices/upcoming) for more details.
157 #[serde(skip_serializing_if = "Option::is_none")]
158 pub id: Option<String>,
159 ///The link to download the PDF for the invoice. If the invoice has not been finalized yet, this will be null.
160 #[serde(skip_serializing_if = "Option::is_none")]
161 pub invoice_pdf: Option<String>,
162 ///The error encountered during the previous attempt to finalize the invoice. This field is cleared when the invoice is successfully finalized.
163 #[serde(skip_serializing_if = "Option::is_none")]
164 pub last_finalization_error: Option<serde_json::Value>,
165 ///The ID of the most recent non-draft revision of this invoice
166 #[serde(skip_serializing_if = "Option::is_none")]
167 pub latest_revision: Option<serde_json::Value>,
168 ///The individual line items that make up the invoice. `lines` is sorted as follows: (1) pending invoice items (including prorations) in reverse chronological order, (2) subscription items in reverse chronological order, and (3) invoice items added after invoice creation in chronological order.
169 pub lines: InvoiceLinesList,
170 ///Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
171 pub livemode: bool,
172 ///Set of [key-value pairs](https://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.
173 #[serde(skip_serializing_if = "Option::is_none")]
174 pub metadata: Option<serde_json::Value>,
175 ///The time at which payment will next be attempted. This value will be `null` for invoices where `collection_method=send_invoice`.
176 #[serde(skip_serializing_if = "Option::is_none")]
177 pub next_payment_attempt: Option<i64>,
178 ///A unique, identifying string that appears on emails sent to the customer for this invoice. This starts with the customer's unique invoice_prefix if it is specified.
179 #[serde(skip_serializing_if = "Option::is_none")]
180 pub number: Option<String>,
181 ///String representing the object's type. Objects of the same type share the same value.
182 pub object: String,
183 ///The account (if any) for which the funds of the invoice payment are intended. If set, the invoice will be presented with the branding and support information of the specified account. See the [Invoices with Connect](https://stripe.com/docs/billing/invoices/connect) documentation for details.
184 #[serde(skip_serializing_if = "Option::is_none")]
185 pub on_behalf_of: Option<serde_json::Value>,
186 ///Whether payment was successfully collected for this invoice. An invoice can be paid (most commonly) with a charge or with credit from the customer's account balance.
187 pub paid: bool,
188 ///Returns true if the invoice was manually marked paid, returns false if the invoice hasn't been paid yet or was paid on Stripe.
189 pub paid_out_of_band: bool,
190 ///The PaymentIntent associated with this invoice. The PaymentIntent is generated when the invoice is finalized, and can then be used to pay the invoice. Note that voiding an invoice will cancel the PaymentIntent.
191 #[serde(skip_serializing_if = "Option::is_none")]
192 pub payment_intent: Option<serde_json::Value>,
193 ///
194 pub payment_settings: InvoicesPaymentSettings,
195 ///End of the usage period during which invoice items were added to this invoice.
196 pub period_end: i64,
197 ///Start of the usage period during which invoice items were added to this invoice.
198 pub period_start: i64,
199 ///Total amount of all post-payment credit notes issued for this invoice.
200 pub post_payment_credit_notes_amount: i64,
201 ///Total amount of all pre-payment credit notes issued for this invoice.
202 pub pre_payment_credit_notes_amount: i64,
203 ///The quote this invoice was generated from.
204 #[serde(skip_serializing_if = "Option::is_none")]
205 pub quote: Option<serde_json::Value>,
206 ///This is the transaction number that appears on email receipts sent for this invoice.
207 #[serde(skip_serializing_if = "Option::is_none")]
208 pub receipt_number: Option<String>,
209 ///The rendering-related settings that control how the invoice is displayed on customer-facing surfaces such as PDF and Hosted Invoice Page.
210 #[serde(skip_serializing_if = "Option::is_none")]
211 pub rendering: Option<serde_json::Value>,
212 ///The details of the cost of shipping, including the ShippingRate applied on the invoice.
213 #[serde(skip_serializing_if = "Option::is_none")]
214 pub shipping_cost: Option<serde_json::Value>,
215 ///Shipping details for the invoice. The Invoice PDF will use the `shipping_details` value if it is set, otherwise the PDF will render the shipping address from the customer.
216 #[serde(skip_serializing_if = "Option::is_none")]
217 pub shipping_details: Option<serde_json::Value>,
218 ///Starting customer balance before the invoice is finalized. If the invoice has not been finalized yet, this will be the current customer balance. For revision invoices, this also includes any customer balance that was applied to the original invoice.
219 pub starting_balance: i64,
220 ///Extra information about an invoice for the customer's credit card statement.
221 #[serde(skip_serializing_if = "Option::is_none")]
222 pub statement_descriptor: Option<String>,
223 ///The status of the invoice, one of `draft`, `open`, `paid`, `uncollectible`, or `void`. [Learn more](https://stripe.com/docs/billing/invoices/workflow#workflow-overview)
224 #[serde(skip_serializing_if = "Option::is_none")]
225 pub status: Option<String>,
226 ///
227 pub status_transitions: InvoicesStatusTransitions,
228 ///The subscription that this invoice was prepared for, if any.
229 #[serde(skip_serializing_if = "Option::is_none")]
230 pub subscription: Option<serde_json::Value>,
231 ///Details about the subscription that created this invoice.
232 #[serde(skip_serializing_if = "Option::is_none")]
233 pub subscription_details: Option<serde_json::Value>,
234 ///Only set for upcoming invoices that preview prorations. The time used to calculate prorations.
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub subscription_proration_date: Option<i64>,
237 ///Total of all subscriptions, invoice items, and prorations on the invoice before any invoice level discount or exclusive tax is applied. Item discounts are already incorporated
238 pub subtotal: i64,
239 ///The integer amount in cents (or local equivalent) representing the subtotal of the invoice before any invoice level discount or tax is applied. Item discounts are already incorporated
240 #[serde(skip_serializing_if = "Option::is_none")]
241 pub subtotal_excluding_tax: Option<i64>,
242 ///The amount of tax on this invoice. This is the sum of all the tax amounts on this invoice.
243 #[serde(skip_serializing_if = "Option::is_none")]
244 pub tax: Option<i64>,
245 ///ID of the test clock this invoice belongs to.
246 #[serde(skip_serializing_if = "Option::is_none")]
247 pub test_clock: Option<serde_json::Value>,
248 ///
249 #[serde(skip_serializing_if = "Option::is_none")]
250 pub threshold_reason: Option<InvoiceThresholdReason>,
251 ///Total after discounts and taxes.
252 pub total: i64,
253 ///The aggregate amounts calculated per discount across all line items.
254 #[serde(skip_serializing_if = "Option::is_none")]
255 pub total_discount_amounts: Option<Vec<DiscountsResourceDiscountAmount>>,
256 ///The integer amount in cents (or local equivalent) representing the total amount of the invoice including all discounts but excluding all tax.
257 #[serde(skip_serializing_if = "Option::is_none")]
258 pub total_excluding_tax: Option<i64>,
259 ///The aggregate amounts calculated per tax rate for all line items.
260 pub total_tax_amounts: Vec<InvoiceTaxAmount>,
261 ///The account (if any) the payment will be attributed to for tax reporting, and where funds from the payment will be transferred to for the invoice.
262 #[serde(skip_serializing_if = "Option::is_none")]
263 pub transfer_data: Option<serde_json::Value>,
264 ///Invoices are automatically paid or sent 1 hour after webhooks are delivered, or until all webhook delivery attempts have [been exhausted](https://stripe.com/docs/billing/webhooks#understand). This field tracks the time when webhooks for this invoice were successfully delivered. If the invoice had no webhooks to deliver, this will be set while the invoice is being created.
265 #[serde(skip_serializing_if = "Option::is_none")]
266 pub webhooks_delivered_at: Option<i64>,
267}
268impl std::fmt::Display for Invoice {
269 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
270 write!(f, "{}", serde_json::to_string(self).unwrap())
271 }
272}