Skip to main content

stripe_shared/
invoice.rs

1/// Invoices are statements of amounts owed by a customer, and are either
2/// generated one-off, or generated periodically from a subscription.
3///
4/// They contain [invoice items](https://api.stripe.com#invoiceitems), and proration adjustments
5/// that may be caused by subscription upgrades/downgrades (if necessary).
6///
7/// If your invoice is configured to be billed through automatic charges,
8/// Stripe automatically finalizes your invoice and attempts payment. Note
9/// that finalizing the invoice,
10/// [when automatic](https://docs.stripe.com/invoicing/integration/automatic-advancement-collection), does.
11/// not happen immediately as the invoice is created. Stripe waits
12/// until one hour after the last webhook was successfully sent (or the last
13/// webhook timed out after failing). If you (and the platforms you may have
14/// connected to) have no webhooks configured, Stripe waits one hour after
15/// creation to finalize the invoice.
16///
17/// If your invoice is configured to be billed by sending an email, then based on your
18/// [email settings](https://dashboard.stripe.com/account/billing/automatic),
19/// Stripe will email the invoice to your customer and await payment. These
20/// emails can contain a link to a hosted page to pay the invoice.
21///
22/// Stripe applies any customer credit on the account before determining the
23/// amount due for the invoice (i.e., the amount that will be actually
24/// charged). If the amount due for the invoice is less than Stripe's [minimum allowed charge
25/// per currency](/docs/currencies#minimum-and-maximum-charge-amounts), the
26/// invoice is automatically marked paid, and we add the amount due to the
27/// customer's credit balance which is applied to the next invoice.
28///
29/// More details on the customer's credit balance are
30/// [here](https://docs.stripe.com/billing/customer/balance).
31///
32/// Related guide: [Send invoices to customers](https://docs.stripe.com/billing/invoices/sending)
33///
34/// For more details see <<https://stripe.com/docs/api/invoices/object>>.
35#[derive(Clone)]
36#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
37#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
38pub struct Invoice {
39    /// The country of the business associated with this invoice, most often the business creating the invoice.
40    pub account_country: Option<String>,
41    /// The public name of the business associated with this invoice, most often the business creating the invoice.
42    pub account_name: Option<String>,
43    /// The account tax IDs associated with the invoice. Only editable when the invoice is a draft.
44    pub account_tax_ids: Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>,
45    /// Final amount due at this time for this invoice.
46    /// 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.
47    /// If there is a positive `starting_balance` for the invoice (the customer owes money), the `amount_due` will also take that into account.
48    /// The charge that gets generated for the invoice will be for the amount specified in `amount_due`.
49    pub amount_due: i64,
50    /// Amount that was overpaid on the invoice.
51    /// The amount overpaid is credited to the customer's credit balance.
52    pub amount_overpaid: 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    pub application: Option<stripe_types::Expandable<stripe_shared::Application>>,
61    /// Number of payment attempts made for this invoice, from the perspective of the payment retry schedule.
62    /// Any payment attempt counts as the first attempt, and subsequently only automatic retries increment the attempt count.
63    /// In other words, manual payment attempts after the first attempt do not affect the retry schedule.
64    /// If a failure is returned with a non-retryable return code, the invoice can no longer be retried unless a new payment method is obtained.
65    /// Retries will continue to be scheduled, and attempt_count will continue to increment, but retries will only be executed if a new payment method is obtained.
66    pub attempt_count: u64,
67    /// Whether an attempt has been made to pay the invoice.
68    /// 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.
69    pub attempted: bool,
70    /// Controls whether Stripe performs [automatic collection](https://docs.stripe.com/invoicing/integration/automatic-advancement-collection) of the invoice.
71    /// If `false`, the invoice's state doesn't automatically advance without an explicit action.
72    pub auto_advance: Option<bool>,
73    pub automatic_tax: stripe_shared::AutomaticTax,
74    /// The time when this invoice is currently scheduled to be automatically finalized.
75    /// The field will be `null` if the invoice is not scheduled to finalize in the future.
76    /// If the invoice is not in the draft state, this field will always be `null` - see `finalized_at` for the time when an already-finalized invoice was finalized.
77    pub automatically_finalizes_at: Option<stripe_types::Timestamp>,
78    /// Indicates the reason why the invoice was created.
79    ///
80    /// * `manual`: Unrelated to a subscription, for example, created via the invoice editor.
81    /// * `subscription`: No longer in use.
82    ///   Applies to subscriptions from before May 2018 where no distinction was made between updates, cycles, and thresholds.
83    /// * `subscription_create`: A new subscription was created.
84    /// * `subscription_cycle`: A subscription advanced into a new period.
85    /// * `subscription_threshold`: A subscription reached a billing threshold.
86    /// * `subscription_update`: A subscription was updated.
87    /// * `upcoming`: Reserved for upcoming invoices created through the Create Preview Invoice API or when an `invoice.upcoming` event is generated for an upcoming invoice on a subscription.
88    pub billing_reason: Option<InvoiceBillingReason>,
89    /// Either `charge_automatically`, or `send_invoice`.
90    /// When charging automatically, Stripe will attempt to pay this invoice using the default source attached to the customer.
91    /// When sending an invoice, Stripe will email this invoice to the customer with payment instructions.
92    pub collection_method: stripe_shared::InvoiceCollectionMethod,
93    /// The confirmation secret associated with this invoice.
94    /// Currently, this contains the client_secret of the PaymentIntent that Stripe creates during invoice finalization.
95    pub confirmation_secret: Option<stripe_shared::InvoicesResourceConfirmationSecret>,
96    /// Time at which the object was created. Measured in seconds since the Unix epoch.
97    pub created: stripe_types::Timestamp,
98    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
99    /// Must be a [supported currency](https://stripe.com/docs/currencies).
100    pub currency: stripe_types::Currency,
101    /// Custom fields displayed on the invoice.
102    pub custom_fields: Option<Vec<stripe_shared::InvoiceSettingCustomField>>,
103    /// The ID of the customer to bill.
104    pub customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
105    /// The ID of the account representing the customer to bill.
106    pub customer_account: Option<String>,
107    /// The customer's address.
108    /// Until the invoice is finalized, this field will equal `customer.address`.
109    /// Once the invoice is finalized, this field will no longer be updated.
110    pub customer_address: Option<stripe_shared::Address>,
111    /// The customer's email.
112    /// Until the invoice is finalized, this field will equal `customer.email`.
113    /// Once the invoice is finalized, this field will no longer be updated.
114    pub customer_email: Option<String>,
115    /// The customer's name.
116    /// Until the invoice is finalized, this field will equal `customer.name`.
117    /// Once the invoice is finalized, this field will no longer be updated.
118    pub customer_name: Option<String>,
119    /// The customer's phone number.
120    /// Until the invoice is finalized, this field will equal `customer.phone`.
121    /// Once the invoice is finalized, this field will no longer be updated.
122    pub customer_phone: Option<String>,
123    /// The customer's shipping information.
124    /// Until the invoice is finalized, this field will equal `customer.shipping`.
125    /// Once the invoice is finalized, this field will no longer be updated.
126    pub customer_shipping: Option<stripe_shared::Shipping>,
127    /// The customer's tax exempt status.
128    /// Until the invoice is finalized, this field will equal `customer.tax_exempt`.
129    /// Once the invoice is finalized, this field will no longer be updated.
130    pub customer_tax_exempt: Option<InvoiceCustomerTaxExempt>,
131    /// The customer's tax IDs.
132    /// Until the invoice is finalized, this field will contain the same tax IDs as `customer.tax_ids`.
133    /// Once the invoice is finalized, this field will no longer be updated.
134    pub customer_tax_ids: Option<Vec<stripe_shared::InvoicesResourceInvoiceTaxId>>,
135    /// ID of the default payment method for the invoice.
136    /// It must belong to the customer associated with the invoice.
137    /// 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.
138    pub default_payment_method: Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>,
139    /// ID of the default payment source for the invoice.
140    /// It must belong to the customer associated with the invoice and be in a chargeable state.
141    /// If not set, defaults to the subscription's default source, if any, or to the customer's default source.
142    pub default_source: Option<stripe_types::Expandable<stripe_shared::PaymentSource>>,
143    /// The tax rates applied to this invoice, if any.
144    pub default_tax_rates: Vec<stripe_shared::TaxRate>,
145    /// An arbitrary string attached to the object.
146    /// Often useful for displaying to users.
147    /// Referenced as 'memo' in the Dashboard.
148    pub description: Option<String>,
149    /// The discounts applied to the invoice.
150    /// Line item discounts are applied before invoice discounts.
151    /// Use `expand[]=discounts` to expand each discount.
152    pub discounts: Vec<stripe_types::Expandable<stripe_shared::Discount>>,
153    /// The date on which payment for this invoice is due.
154    /// This value will be `null` for invoices where `collection_method=charge_automatically`.
155    pub due_date: Option<stripe_types::Timestamp>,
156    /// The date when this invoice is in effect.
157    /// Same as `finalized_at` unless overwritten.
158    /// When defined, this value replaces the system-generated 'Date of issue' printed on the invoice PDF and receipt.
159    pub effective_at: Option<stripe_types::Timestamp>,
160    /// Ending customer balance after the invoice is finalized.
161    /// Invoices are finalized approximately an hour after successful webhook delivery or when payment collection is attempted for the invoice.
162    /// If the invoice has not been finalized yet, this will be null.
163    pub ending_balance: Option<i64>,
164    /// Footer displayed on the invoice.
165    pub footer: Option<String>,
166    /// Details of the invoice that was cloned.
167    /// See the [revision documentation](https://docs.stripe.com/invoicing/invoice-revisions) for more details.
168    pub from_invoice: Option<stripe_shared::InvoicesResourceFromInvoice>,
169    /// The URL for the hosted invoice page, which allows customers to view and pay an invoice.
170    /// If the invoice has not been finalized yet, this will be null.
171    pub hosted_invoice_url: Option<String>,
172    /// Unique identifier for the object.
173    /// For preview invoices created using the [create preview](https://stripe.com/docs/api/invoices/create_preview) endpoint, this id will be prefixed with `upcoming_in`.
174    pub id: Option<stripe_shared::InvoiceId>,
175    /// The link to download the PDF for the invoice.
176    /// If the invoice has not been finalized yet, this will be null.
177    pub invoice_pdf: Option<String>,
178    pub issuer: stripe_shared::ConnectAccountReference,
179    /// The error encountered during the previous attempt to finalize the invoice.
180    /// This field is cleared when the invoice is successfully finalized.
181    pub last_finalization_error: Option<Box<stripe_shared::ApiErrors>>,
182    /// The ID of the most recent non-draft revision of this invoice
183    pub latest_revision: Option<stripe_types::Expandable<stripe_shared::Invoice>>,
184    /// The individual line items that make up the invoice.
185    /// `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.
186    pub lines: stripe_types::List<stripe_shared::InvoiceLineItem>,
187    /// If the object exists in live mode, the value is `true`.
188    /// If the object exists in test mode, the value is `false`.
189    pub livemode: bool,
190    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
191    /// This can be useful for storing additional information about the object in a structured format.
192    pub metadata: Option<std::collections::HashMap<String, String>>,
193    /// The time at which payment will next be attempted.
194    /// This value will be `null` for invoices where `collection_method=send_invoice`.
195    pub next_payment_attempt: Option<stripe_types::Timestamp>,
196    /// A unique, identifying string that appears on emails sent to the customer for this invoice.
197    /// This starts with the customer's unique invoice_prefix if it is specified.
198    pub number: Option<String>,
199    /// The account (if any) for which the funds of the invoice payment are intended.
200    /// If set, the invoice will be presented with the branding and support information of the specified account.
201    /// See the [Invoices with Connect](https://docs.stripe.com/billing/invoices/connect) documentation for details.
202    pub on_behalf_of: Option<stripe_types::Expandable<stripe_shared::Account>>,
203    /// The parent that generated this invoice
204    pub parent: Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceParent>,
205    pub payment_settings: stripe_shared::InvoicesPaymentSettings,
206    /// Payments for this invoice. Use [invoice payment](/api/invoice-payment) to get more details.
207    pub payments: Option<stripe_types::List<stripe_shared::InvoicePayment>>,
208    /// The latest timestamp at which invoice items can be associated with this invoice.
209    /// Use the [line item period](/api/invoices/line_item#invoice_line_item_object-period) to get the service period for each price.
210    pub period_end: stripe_types::Timestamp,
211    /// The earliest timestamp at which invoice items can be associated with this invoice.
212    /// Use the [line item period](/api/invoices/line_item#invoice_line_item_object-period) to get the service period for each price.
213    pub period_start: stripe_types::Timestamp,
214    /// Total amount of all post-payment credit notes issued for this invoice.
215    pub post_payment_credit_notes_amount: i64,
216    /// Total amount of all pre-payment credit notes issued for this invoice.
217    pub pre_payment_credit_notes_amount: i64,
218    /// This is the transaction number that appears on email receipts sent for this invoice.
219    pub receipt_number: Option<String>,
220    /// The rendering-related settings that control how the invoice is displayed on customer-facing surfaces such as PDF and Hosted Invoice Page.
221    pub rendering: Option<stripe_shared::InvoicesResourceInvoiceRendering>,
222    /// The details of the cost of shipping, including the ShippingRate applied on the invoice.
223    pub shipping_cost: Option<stripe_shared::InvoicesResourceShippingCost>,
224    /// Shipping details for the invoice.
225    /// The Invoice PDF will use the `shipping_details` value if it is set, otherwise the PDF will render the shipping address from the customer.
226    pub shipping_details: Option<stripe_shared::Shipping>,
227    /// Starting customer balance before the invoice is finalized.
228    /// If the invoice has not been finalized yet, this will be the current customer balance.
229    /// For revision invoices, this also includes any customer balance that was applied to the original invoice.
230    pub starting_balance: i64,
231    /// Extra information about an invoice for the customer's credit card statement.
232    pub statement_descriptor: Option<String>,
233    /// The status of the invoice, one of `draft`, `open`, `paid`, `uncollectible`, or `void`.
234    /// [Learn more](https://docs.stripe.com/billing/invoices/workflow#workflow-overview).
235    pub status: Option<stripe_shared::InvoiceStatus>,
236    pub status_transitions: stripe_shared::InvoicesResourceStatusTransitions,
237    pub subscription: Option<stripe_types::Expandable<stripe_shared::Subscription>>,
238    /// Total of all subscriptions, invoice items, and prorations on the invoice before any invoice level discount or exclusive tax is applied.
239    /// Item discounts are already incorporated.
240    pub subtotal: i64,
241    /// The integer amount in cents (or local equivalent) representing the subtotal of the invoice before any invoice level discount or tax is applied.
242    /// Item discounts are already incorporated.
243    pub subtotal_excluding_tax: Option<i64>,
244    /// ID of the test clock this invoice belongs to.
245    pub test_clock: Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>,
246    pub threshold_reason: Option<stripe_shared::InvoiceThresholdReason>,
247    /// Total after discounts and taxes.
248    pub total: i64,
249    /// The aggregate amounts calculated per discount across all line items.
250    pub total_discount_amounts: Option<Vec<stripe_shared::DiscountsResourceDiscountAmount>>,
251    /// The integer amount in cents (or local equivalent) representing the total amount of the invoice including all discounts but excluding all tax.
252    pub total_excluding_tax: Option<i64>,
253    /// Contains pretax credit amounts (ex: discount, credit grants, etc) that apply to this invoice.
254    /// This is a combined list of total_pretax_credit_amounts across all invoice line items.
255    pub total_pretax_credit_amounts: Option<Vec<stripe_shared::InvoicesResourcePretaxCreditAmount>>,
256    /// The aggregate tax information of all line items.
257    pub total_taxes: Option<Vec<stripe_shared::BillingBillResourceInvoicingTaxesTax>>,
258    /// Invoices are automatically paid or sent 1 hour after webhooks are delivered, or until all webhook delivery attempts have [been exhausted](https://docs.stripe.com/billing/webhooks#understand).
259    /// This field tracks the time when webhooks for this invoice were successfully delivered.
260    /// If the invoice had no webhooks to deliver, this will be set while the invoice is being created.
261    pub webhooks_delivered_at: Option<stripe_types::Timestamp>,
262}
263#[cfg(feature = "redact-generated-debug")]
264impl std::fmt::Debug for Invoice {
265    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
266        f.debug_struct("Invoice").finish_non_exhaustive()
267    }
268}
269#[doc(hidden)]
270pub struct InvoiceBuilder {
271    account_country: Option<Option<String>>,
272    account_name: Option<Option<String>>,
273    account_tax_ids: Option<Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>>,
274    amount_due: Option<i64>,
275    amount_overpaid: Option<i64>,
276    amount_paid: Option<i64>,
277    amount_remaining: Option<i64>,
278    amount_shipping: Option<i64>,
279    application: Option<Option<stripe_types::Expandable<stripe_shared::Application>>>,
280    attempt_count: Option<u64>,
281    attempted: Option<bool>,
282    auto_advance: Option<Option<bool>>,
283    automatic_tax: Option<stripe_shared::AutomaticTax>,
284    automatically_finalizes_at: Option<Option<stripe_types::Timestamp>>,
285    billing_reason: Option<Option<InvoiceBillingReason>>,
286    collection_method: Option<stripe_shared::InvoiceCollectionMethod>,
287    confirmation_secret: Option<Option<stripe_shared::InvoicesResourceConfirmationSecret>>,
288    created: Option<stripe_types::Timestamp>,
289    currency: Option<stripe_types::Currency>,
290    custom_fields: Option<Option<Vec<stripe_shared::InvoiceSettingCustomField>>>,
291    customer: Option<Option<stripe_types::Expandable<stripe_shared::Customer>>>,
292    customer_account: Option<Option<String>>,
293    customer_address: Option<Option<stripe_shared::Address>>,
294    customer_email: Option<Option<String>>,
295    customer_name: Option<Option<String>>,
296    customer_phone: Option<Option<String>>,
297    customer_shipping: Option<Option<stripe_shared::Shipping>>,
298    customer_tax_exempt: Option<Option<InvoiceCustomerTaxExempt>>,
299    customer_tax_ids: Option<Option<Vec<stripe_shared::InvoicesResourceInvoiceTaxId>>>,
300    default_payment_method: Option<Option<stripe_types::Expandable<stripe_shared::PaymentMethod>>>,
301    default_source: Option<Option<stripe_types::Expandable<stripe_shared::PaymentSource>>>,
302    default_tax_rates: Option<Vec<stripe_shared::TaxRate>>,
303    description: Option<Option<String>>,
304    discounts: Option<Vec<stripe_types::Expandable<stripe_shared::Discount>>>,
305    due_date: Option<Option<stripe_types::Timestamp>>,
306    effective_at: Option<Option<stripe_types::Timestamp>>,
307    ending_balance: Option<Option<i64>>,
308    footer: Option<Option<String>>,
309    from_invoice: Option<Option<stripe_shared::InvoicesResourceFromInvoice>>,
310    hosted_invoice_url: Option<Option<String>>,
311    id: Option<Option<stripe_shared::InvoiceId>>,
312    invoice_pdf: Option<Option<String>>,
313    issuer: Option<stripe_shared::ConnectAccountReference>,
314    last_finalization_error: Option<Option<Box<stripe_shared::ApiErrors>>>,
315    latest_revision: Option<Option<stripe_types::Expandable<stripe_shared::Invoice>>>,
316    lines: Option<stripe_types::List<stripe_shared::InvoiceLineItem>>,
317    livemode: Option<bool>,
318    metadata: Option<Option<std::collections::HashMap<String, String>>>,
319    next_payment_attempt: Option<Option<stripe_types::Timestamp>>,
320    number: Option<Option<String>>,
321    on_behalf_of: Option<Option<stripe_types::Expandable<stripe_shared::Account>>>,
322    parent: Option<Option<stripe_shared::BillingBillResourceInvoicingParentsInvoiceParent>>,
323    payment_settings: Option<stripe_shared::InvoicesPaymentSettings>,
324    payments: Option<Option<stripe_types::List<stripe_shared::InvoicePayment>>>,
325    period_end: Option<stripe_types::Timestamp>,
326    period_start: Option<stripe_types::Timestamp>,
327    post_payment_credit_notes_amount: Option<i64>,
328    pre_payment_credit_notes_amount: Option<i64>,
329    receipt_number: Option<Option<String>>,
330    rendering: Option<Option<stripe_shared::InvoicesResourceInvoiceRendering>>,
331    shipping_cost: Option<Option<stripe_shared::InvoicesResourceShippingCost>>,
332    shipping_details: Option<Option<stripe_shared::Shipping>>,
333    starting_balance: Option<i64>,
334    statement_descriptor: Option<Option<String>>,
335    status: Option<Option<stripe_shared::InvoiceStatus>>,
336    status_transitions: Option<stripe_shared::InvoicesResourceStatusTransitions>,
337    subscription: Option<Option<stripe_types::Expandable<stripe_shared::Subscription>>>,
338    subtotal: Option<i64>,
339    subtotal_excluding_tax: Option<Option<i64>>,
340    test_clock: Option<Option<stripe_types::Expandable<stripe_shared::TestHelpersTestClock>>>,
341    threshold_reason: Option<Option<stripe_shared::InvoiceThresholdReason>>,
342    total: Option<i64>,
343    total_discount_amounts: Option<Option<Vec<stripe_shared::DiscountsResourceDiscountAmount>>>,
344    total_excluding_tax: Option<Option<i64>>,
345    total_pretax_credit_amounts:
346        Option<Option<Vec<stripe_shared::InvoicesResourcePretaxCreditAmount>>>,
347    total_taxes: Option<Option<Vec<stripe_shared::BillingBillResourceInvoicingTaxesTax>>>,
348    webhooks_delivered_at: Option<Option<stripe_types::Timestamp>>,
349}
350
351#[allow(
352    unused_variables,
353    irrefutable_let_patterns,
354    clippy::let_unit_value,
355    clippy::match_single_binding,
356    clippy::single_match
357)]
358const _: () = {
359    use miniserde::de::{Map, Visitor};
360    use miniserde::json::Value;
361    use miniserde::{Deserialize, Result, make_place};
362    use stripe_types::miniserde_helpers::FromValueOpt;
363    use stripe_types::{MapBuilder, ObjectDeser};
364
365    make_place!(Place);
366
367    impl Deserialize for Invoice {
368        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
369            Place::new(out)
370        }
371    }
372
373    struct Builder<'a> {
374        out: &'a mut Option<Invoice>,
375        builder: InvoiceBuilder,
376    }
377
378    impl Visitor for Place<Invoice> {
379        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
380            Ok(Box::new(Builder { out: &mut self.out, builder: InvoiceBuilder::deser_default() }))
381        }
382    }
383
384    impl MapBuilder for InvoiceBuilder {
385        type Out = Invoice;
386        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
387            Ok(match k {
388                "account_country" => Deserialize::begin(&mut self.account_country),
389                "account_name" => Deserialize::begin(&mut self.account_name),
390                "account_tax_ids" => Deserialize::begin(&mut self.account_tax_ids),
391                "amount_due" => Deserialize::begin(&mut self.amount_due),
392                "amount_overpaid" => Deserialize::begin(&mut self.amount_overpaid),
393                "amount_paid" => Deserialize::begin(&mut self.amount_paid),
394                "amount_remaining" => Deserialize::begin(&mut self.amount_remaining),
395                "amount_shipping" => Deserialize::begin(&mut self.amount_shipping),
396                "application" => Deserialize::begin(&mut self.application),
397                "attempt_count" => Deserialize::begin(&mut self.attempt_count),
398                "attempted" => Deserialize::begin(&mut self.attempted),
399                "auto_advance" => Deserialize::begin(&mut self.auto_advance),
400                "automatic_tax" => Deserialize::begin(&mut self.automatic_tax),
401                "automatically_finalizes_at" => {
402                    Deserialize::begin(&mut self.automatically_finalizes_at)
403                }
404                "billing_reason" => Deserialize::begin(&mut self.billing_reason),
405                "collection_method" => Deserialize::begin(&mut self.collection_method),
406                "confirmation_secret" => Deserialize::begin(&mut self.confirmation_secret),
407                "created" => Deserialize::begin(&mut self.created),
408                "currency" => Deserialize::begin(&mut self.currency),
409                "custom_fields" => Deserialize::begin(&mut self.custom_fields),
410                "customer" => Deserialize::begin(&mut self.customer),
411                "customer_account" => Deserialize::begin(&mut self.customer_account),
412                "customer_address" => Deserialize::begin(&mut self.customer_address),
413                "customer_email" => Deserialize::begin(&mut self.customer_email),
414                "customer_name" => Deserialize::begin(&mut self.customer_name),
415                "customer_phone" => Deserialize::begin(&mut self.customer_phone),
416                "customer_shipping" => Deserialize::begin(&mut self.customer_shipping),
417                "customer_tax_exempt" => Deserialize::begin(&mut self.customer_tax_exempt),
418                "customer_tax_ids" => Deserialize::begin(&mut self.customer_tax_ids),
419                "default_payment_method" => Deserialize::begin(&mut self.default_payment_method),
420                "default_source" => Deserialize::begin(&mut self.default_source),
421                "default_tax_rates" => Deserialize::begin(&mut self.default_tax_rates),
422                "description" => Deserialize::begin(&mut self.description),
423                "discounts" => Deserialize::begin(&mut self.discounts),
424                "due_date" => Deserialize::begin(&mut self.due_date),
425                "effective_at" => Deserialize::begin(&mut self.effective_at),
426                "ending_balance" => Deserialize::begin(&mut self.ending_balance),
427                "footer" => Deserialize::begin(&mut self.footer),
428                "from_invoice" => Deserialize::begin(&mut self.from_invoice),
429                "hosted_invoice_url" => Deserialize::begin(&mut self.hosted_invoice_url),
430                "id" => Deserialize::begin(&mut self.id),
431                "invoice_pdf" => Deserialize::begin(&mut self.invoice_pdf),
432                "issuer" => Deserialize::begin(&mut self.issuer),
433                "last_finalization_error" => Deserialize::begin(&mut self.last_finalization_error),
434                "latest_revision" => Deserialize::begin(&mut self.latest_revision),
435                "lines" => Deserialize::begin(&mut self.lines),
436                "livemode" => Deserialize::begin(&mut self.livemode),
437                "metadata" => Deserialize::begin(&mut self.metadata),
438                "next_payment_attempt" => Deserialize::begin(&mut self.next_payment_attempt),
439                "number" => Deserialize::begin(&mut self.number),
440                "on_behalf_of" => Deserialize::begin(&mut self.on_behalf_of),
441                "parent" => Deserialize::begin(&mut self.parent),
442                "payment_settings" => Deserialize::begin(&mut self.payment_settings),
443                "payments" => Deserialize::begin(&mut self.payments),
444                "period_end" => Deserialize::begin(&mut self.period_end),
445                "period_start" => Deserialize::begin(&mut self.period_start),
446                "post_payment_credit_notes_amount" => {
447                    Deserialize::begin(&mut self.post_payment_credit_notes_amount)
448                }
449                "pre_payment_credit_notes_amount" => {
450                    Deserialize::begin(&mut self.pre_payment_credit_notes_amount)
451                }
452                "receipt_number" => Deserialize::begin(&mut self.receipt_number),
453                "rendering" => Deserialize::begin(&mut self.rendering),
454                "shipping_cost" => Deserialize::begin(&mut self.shipping_cost),
455                "shipping_details" => Deserialize::begin(&mut self.shipping_details),
456                "starting_balance" => Deserialize::begin(&mut self.starting_balance),
457                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
458                "status" => Deserialize::begin(&mut self.status),
459                "status_transitions" => Deserialize::begin(&mut self.status_transitions),
460                "subscription" => Deserialize::begin(&mut self.subscription),
461                "subtotal" => Deserialize::begin(&mut self.subtotal),
462                "subtotal_excluding_tax" => Deserialize::begin(&mut self.subtotal_excluding_tax),
463                "test_clock" => Deserialize::begin(&mut self.test_clock),
464                "threshold_reason" => Deserialize::begin(&mut self.threshold_reason),
465                "total" => Deserialize::begin(&mut self.total),
466                "total_discount_amounts" => Deserialize::begin(&mut self.total_discount_amounts),
467                "total_excluding_tax" => Deserialize::begin(&mut self.total_excluding_tax),
468                "total_pretax_credit_amounts" => {
469                    Deserialize::begin(&mut self.total_pretax_credit_amounts)
470                }
471                "total_taxes" => Deserialize::begin(&mut self.total_taxes),
472                "webhooks_delivered_at" => Deserialize::begin(&mut self.webhooks_delivered_at),
473                _ => <dyn Visitor>::ignore(),
474            })
475        }
476
477        fn deser_default() -> Self {
478            Self {
479                account_country: Some(None),
480                account_name: Some(None),
481                account_tax_ids: Some(None),
482                amount_due: None,
483                amount_overpaid: None,
484                amount_paid: None,
485                amount_remaining: None,
486                amount_shipping: None,
487                application: Some(None),
488                attempt_count: None,
489                attempted: None,
490                auto_advance: Some(None),
491                automatic_tax: None,
492                automatically_finalizes_at: Some(None),
493                billing_reason: Some(None),
494                collection_method: None,
495                confirmation_secret: Some(None),
496                created: None,
497                currency: None,
498                custom_fields: Some(None),
499                customer: Some(None),
500                customer_account: Some(None),
501                customer_address: Some(None),
502                customer_email: Some(None),
503                customer_name: Some(None),
504                customer_phone: Some(None),
505                customer_shipping: Some(None),
506                customer_tax_exempt: Some(None),
507                customer_tax_ids: Some(None),
508                default_payment_method: Some(None),
509                default_source: Some(None),
510                default_tax_rates: None,
511                description: Some(None),
512                discounts: None,
513                due_date: Some(None),
514                effective_at: Some(None),
515                ending_balance: Some(None),
516                footer: Some(None),
517                from_invoice: Some(None),
518                hosted_invoice_url: Some(None),
519                id: Some(None),
520                invoice_pdf: Some(None),
521                issuer: None,
522                last_finalization_error: Some(None),
523                latest_revision: Some(None),
524                lines: None,
525                livemode: None,
526                metadata: Some(None),
527                next_payment_attempt: Some(None),
528                number: Some(None),
529                on_behalf_of: Some(None),
530                parent: Some(None),
531                payment_settings: None,
532                payments: Some(None),
533                period_end: None,
534                period_start: None,
535                post_payment_credit_notes_amount: None,
536                pre_payment_credit_notes_amount: None,
537                receipt_number: Some(None),
538                rendering: Some(None),
539                shipping_cost: Some(None),
540                shipping_details: Some(None),
541                starting_balance: None,
542                statement_descriptor: Some(None),
543                status: Some(None),
544                status_transitions: None,
545                subscription: Some(None),
546                subtotal: None,
547                subtotal_excluding_tax: Some(None),
548                test_clock: Some(None),
549                threshold_reason: Some(None),
550                total: None,
551                total_discount_amounts: Some(None),
552                total_excluding_tax: Some(None),
553                total_pretax_credit_amounts: Some(None),
554                total_taxes: Some(None),
555                webhooks_delivered_at: Some(None),
556            }
557        }
558
559        fn take_out(&mut self) -> Option<Self::Out> {
560            let (
561                Some(account_country),
562                Some(account_name),
563                Some(account_tax_ids),
564                Some(amount_due),
565                Some(amount_overpaid),
566                Some(amount_paid),
567                Some(amount_remaining),
568                Some(amount_shipping),
569                Some(application),
570                Some(attempt_count),
571                Some(attempted),
572                Some(auto_advance),
573                Some(automatic_tax),
574                Some(automatically_finalizes_at),
575                Some(billing_reason),
576                Some(collection_method),
577                Some(confirmation_secret),
578                Some(created),
579                Some(currency),
580                Some(custom_fields),
581                Some(customer),
582                Some(customer_account),
583                Some(customer_address),
584                Some(customer_email),
585                Some(customer_name),
586                Some(customer_phone),
587                Some(customer_shipping),
588                Some(customer_tax_exempt),
589                Some(customer_tax_ids),
590                Some(default_payment_method),
591                Some(default_source),
592                Some(default_tax_rates),
593                Some(description),
594                Some(discounts),
595                Some(due_date),
596                Some(effective_at),
597                Some(ending_balance),
598                Some(footer),
599                Some(from_invoice),
600                Some(hosted_invoice_url),
601                Some(id),
602                Some(invoice_pdf),
603                Some(issuer),
604                Some(last_finalization_error),
605                Some(latest_revision),
606                Some(lines),
607                Some(livemode),
608                Some(metadata),
609                Some(next_payment_attempt),
610                Some(number),
611                Some(on_behalf_of),
612                Some(parent),
613                Some(payment_settings),
614                Some(payments),
615                Some(period_end),
616                Some(period_start),
617                Some(post_payment_credit_notes_amount),
618                Some(pre_payment_credit_notes_amount),
619                Some(receipt_number),
620                Some(rendering),
621                Some(shipping_cost),
622                Some(shipping_details),
623                Some(starting_balance),
624                Some(statement_descriptor),
625                Some(status),
626                Some(status_transitions),
627                Some(subscription),
628                Some(subtotal),
629                Some(subtotal_excluding_tax),
630                Some(test_clock),
631                Some(threshold_reason),
632                Some(total),
633                Some(total_discount_amounts),
634                Some(total_excluding_tax),
635                Some(total_pretax_credit_amounts),
636                Some(total_taxes),
637                Some(webhooks_delivered_at),
638            ) = (
639                self.account_country.take(),
640                self.account_name.take(),
641                self.account_tax_ids.take(),
642                self.amount_due,
643                self.amount_overpaid,
644                self.amount_paid,
645                self.amount_remaining,
646                self.amount_shipping,
647                self.application.take(),
648                self.attempt_count,
649                self.attempted,
650                self.auto_advance,
651                self.automatic_tax.take(),
652                self.automatically_finalizes_at,
653                self.billing_reason.take(),
654                self.collection_method.take(),
655                self.confirmation_secret.take(),
656                self.created,
657                self.currency.take(),
658                self.custom_fields.take(),
659                self.customer.take(),
660                self.customer_account.take(),
661                self.customer_address.take(),
662                self.customer_email.take(),
663                self.customer_name.take(),
664                self.customer_phone.take(),
665                self.customer_shipping.take(),
666                self.customer_tax_exempt.take(),
667                self.customer_tax_ids.take(),
668                self.default_payment_method.take(),
669                self.default_source.take(),
670                self.default_tax_rates.take(),
671                self.description.take(),
672                self.discounts.take(),
673                self.due_date,
674                self.effective_at,
675                self.ending_balance,
676                self.footer.take(),
677                self.from_invoice.take(),
678                self.hosted_invoice_url.take(),
679                self.id.take(),
680                self.invoice_pdf.take(),
681                self.issuer.take(),
682                self.last_finalization_error.take(),
683                self.latest_revision.take(),
684                self.lines.take(),
685                self.livemode,
686                self.metadata.take(),
687                self.next_payment_attempt,
688                self.number.take(),
689                self.on_behalf_of.take(),
690                self.parent.take(),
691                self.payment_settings.take(),
692                self.payments.take(),
693                self.period_end,
694                self.period_start,
695                self.post_payment_credit_notes_amount,
696                self.pre_payment_credit_notes_amount,
697                self.receipt_number.take(),
698                self.rendering.take(),
699                self.shipping_cost.take(),
700                self.shipping_details.take(),
701                self.starting_balance,
702                self.statement_descriptor.take(),
703                self.status.take(),
704                self.status_transitions,
705                self.subscription.take(),
706                self.subtotal,
707                self.subtotal_excluding_tax,
708                self.test_clock.take(),
709                self.threshold_reason.take(),
710                self.total,
711                self.total_discount_amounts.take(),
712                self.total_excluding_tax,
713                self.total_pretax_credit_amounts.take(),
714                self.total_taxes.take(),
715                self.webhooks_delivered_at,
716            )
717            else {
718                return None;
719            };
720            Some(Self::Out {
721                account_country,
722                account_name,
723                account_tax_ids,
724                amount_due,
725                amount_overpaid,
726                amount_paid,
727                amount_remaining,
728                amount_shipping,
729                application,
730                attempt_count,
731                attempted,
732                auto_advance,
733                automatic_tax,
734                automatically_finalizes_at,
735                billing_reason,
736                collection_method,
737                confirmation_secret,
738                created,
739                currency,
740                custom_fields,
741                customer,
742                customer_account,
743                customer_address,
744                customer_email,
745                customer_name,
746                customer_phone,
747                customer_shipping,
748                customer_tax_exempt,
749                customer_tax_ids,
750                default_payment_method,
751                default_source,
752                default_tax_rates,
753                description,
754                discounts,
755                due_date,
756                effective_at,
757                ending_balance,
758                footer,
759                from_invoice,
760                hosted_invoice_url,
761                id,
762                invoice_pdf,
763                issuer,
764                last_finalization_error,
765                latest_revision,
766                lines,
767                livemode,
768                metadata,
769                next_payment_attempt,
770                number,
771                on_behalf_of,
772                parent,
773                payment_settings,
774                payments,
775                period_end,
776                period_start,
777                post_payment_credit_notes_amount,
778                pre_payment_credit_notes_amount,
779                receipt_number,
780                rendering,
781                shipping_cost,
782                shipping_details,
783                starting_balance,
784                statement_descriptor,
785                status,
786                status_transitions,
787                subscription,
788                subtotal,
789                subtotal_excluding_tax,
790                test_clock,
791                threshold_reason,
792                total,
793                total_discount_amounts,
794                total_excluding_tax,
795                total_pretax_credit_amounts,
796                total_taxes,
797                webhooks_delivered_at,
798            })
799        }
800    }
801
802    impl Map for Builder<'_> {
803        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
804            self.builder.key(k)
805        }
806
807        fn finish(&mut self) -> Result<()> {
808            *self.out = self.builder.take_out();
809            Ok(())
810        }
811    }
812
813    impl ObjectDeser for Invoice {
814        type Builder = InvoiceBuilder;
815    }
816
817    impl FromValueOpt for Invoice {
818        fn from_value(v: Value) -> Option<Self> {
819            let Value::Object(obj) = v else {
820                return None;
821            };
822            let mut b = InvoiceBuilder::deser_default();
823            for (k, v) in obj {
824                match k.as_str() {
825                    "account_country" => b.account_country = FromValueOpt::from_value(v),
826                    "account_name" => b.account_name = FromValueOpt::from_value(v),
827                    "account_tax_ids" => b.account_tax_ids = FromValueOpt::from_value(v),
828                    "amount_due" => b.amount_due = FromValueOpt::from_value(v),
829                    "amount_overpaid" => b.amount_overpaid = FromValueOpt::from_value(v),
830                    "amount_paid" => b.amount_paid = FromValueOpt::from_value(v),
831                    "amount_remaining" => b.amount_remaining = FromValueOpt::from_value(v),
832                    "amount_shipping" => b.amount_shipping = FromValueOpt::from_value(v),
833                    "application" => b.application = FromValueOpt::from_value(v),
834                    "attempt_count" => b.attempt_count = FromValueOpt::from_value(v),
835                    "attempted" => b.attempted = FromValueOpt::from_value(v),
836                    "auto_advance" => b.auto_advance = FromValueOpt::from_value(v),
837                    "automatic_tax" => b.automatic_tax = FromValueOpt::from_value(v),
838                    "automatically_finalizes_at" => {
839                        b.automatically_finalizes_at = FromValueOpt::from_value(v)
840                    }
841                    "billing_reason" => b.billing_reason = FromValueOpt::from_value(v),
842                    "collection_method" => b.collection_method = FromValueOpt::from_value(v),
843                    "confirmation_secret" => b.confirmation_secret = FromValueOpt::from_value(v),
844                    "created" => b.created = FromValueOpt::from_value(v),
845                    "currency" => b.currency = FromValueOpt::from_value(v),
846                    "custom_fields" => b.custom_fields = FromValueOpt::from_value(v),
847                    "customer" => b.customer = FromValueOpt::from_value(v),
848                    "customer_account" => b.customer_account = FromValueOpt::from_value(v),
849                    "customer_address" => b.customer_address = FromValueOpt::from_value(v),
850                    "customer_email" => b.customer_email = FromValueOpt::from_value(v),
851                    "customer_name" => b.customer_name = FromValueOpt::from_value(v),
852                    "customer_phone" => b.customer_phone = FromValueOpt::from_value(v),
853                    "customer_shipping" => b.customer_shipping = FromValueOpt::from_value(v),
854                    "customer_tax_exempt" => b.customer_tax_exempt = FromValueOpt::from_value(v),
855                    "customer_tax_ids" => b.customer_tax_ids = FromValueOpt::from_value(v),
856                    "default_payment_method" => {
857                        b.default_payment_method = FromValueOpt::from_value(v)
858                    }
859                    "default_source" => b.default_source = FromValueOpt::from_value(v),
860                    "default_tax_rates" => b.default_tax_rates = FromValueOpt::from_value(v),
861                    "description" => b.description = FromValueOpt::from_value(v),
862                    "discounts" => b.discounts = FromValueOpt::from_value(v),
863                    "due_date" => b.due_date = FromValueOpt::from_value(v),
864                    "effective_at" => b.effective_at = FromValueOpt::from_value(v),
865                    "ending_balance" => b.ending_balance = FromValueOpt::from_value(v),
866                    "footer" => b.footer = FromValueOpt::from_value(v),
867                    "from_invoice" => b.from_invoice = FromValueOpt::from_value(v),
868                    "hosted_invoice_url" => b.hosted_invoice_url = FromValueOpt::from_value(v),
869                    "id" => b.id = FromValueOpt::from_value(v),
870                    "invoice_pdf" => b.invoice_pdf = FromValueOpt::from_value(v),
871                    "issuer" => b.issuer = FromValueOpt::from_value(v),
872                    "last_finalization_error" => {
873                        b.last_finalization_error = FromValueOpt::from_value(v)
874                    }
875                    "latest_revision" => b.latest_revision = FromValueOpt::from_value(v),
876                    "lines" => b.lines = FromValueOpt::from_value(v),
877                    "livemode" => b.livemode = FromValueOpt::from_value(v),
878                    "metadata" => b.metadata = FromValueOpt::from_value(v),
879                    "next_payment_attempt" => b.next_payment_attempt = FromValueOpt::from_value(v),
880                    "number" => b.number = FromValueOpt::from_value(v),
881                    "on_behalf_of" => b.on_behalf_of = FromValueOpt::from_value(v),
882                    "parent" => b.parent = FromValueOpt::from_value(v),
883                    "payment_settings" => b.payment_settings = FromValueOpt::from_value(v),
884                    "payments" => b.payments = FromValueOpt::from_value(v),
885                    "period_end" => b.period_end = FromValueOpt::from_value(v),
886                    "period_start" => b.period_start = FromValueOpt::from_value(v),
887                    "post_payment_credit_notes_amount" => {
888                        b.post_payment_credit_notes_amount = FromValueOpt::from_value(v)
889                    }
890                    "pre_payment_credit_notes_amount" => {
891                        b.pre_payment_credit_notes_amount = FromValueOpt::from_value(v)
892                    }
893                    "receipt_number" => b.receipt_number = FromValueOpt::from_value(v),
894                    "rendering" => b.rendering = FromValueOpt::from_value(v),
895                    "shipping_cost" => b.shipping_cost = FromValueOpt::from_value(v),
896                    "shipping_details" => b.shipping_details = FromValueOpt::from_value(v),
897                    "starting_balance" => b.starting_balance = FromValueOpt::from_value(v),
898                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
899                    "status" => b.status = FromValueOpt::from_value(v),
900                    "status_transitions" => b.status_transitions = FromValueOpt::from_value(v),
901                    "subscription" => b.subscription = FromValueOpt::from_value(v),
902                    "subtotal" => b.subtotal = FromValueOpt::from_value(v),
903                    "subtotal_excluding_tax" => {
904                        b.subtotal_excluding_tax = FromValueOpt::from_value(v)
905                    }
906                    "test_clock" => b.test_clock = FromValueOpt::from_value(v),
907                    "threshold_reason" => b.threshold_reason = FromValueOpt::from_value(v),
908                    "total" => b.total = FromValueOpt::from_value(v),
909                    "total_discount_amounts" => {
910                        b.total_discount_amounts = FromValueOpt::from_value(v)
911                    }
912                    "total_excluding_tax" => b.total_excluding_tax = FromValueOpt::from_value(v),
913                    "total_pretax_credit_amounts" => {
914                        b.total_pretax_credit_amounts = FromValueOpt::from_value(v)
915                    }
916                    "total_taxes" => b.total_taxes = FromValueOpt::from_value(v),
917                    "webhooks_delivered_at" => {
918                        b.webhooks_delivered_at = FromValueOpt::from_value(v)
919                    }
920                    _ => {}
921                }
922            }
923            b.take_out()
924        }
925    }
926};
927#[cfg(feature = "serialize")]
928impl serde::Serialize for Invoice {
929    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
930        use serde::ser::SerializeStruct;
931        let mut s = s.serialize_struct("Invoice", 78)?;
932        s.serialize_field("account_country", &self.account_country)?;
933        s.serialize_field("account_name", &self.account_name)?;
934        s.serialize_field("account_tax_ids", &self.account_tax_ids)?;
935        s.serialize_field("amount_due", &self.amount_due)?;
936        s.serialize_field("amount_overpaid", &self.amount_overpaid)?;
937        s.serialize_field("amount_paid", &self.amount_paid)?;
938        s.serialize_field("amount_remaining", &self.amount_remaining)?;
939        s.serialize_field("amount_shipping", &self.amount_shipping)?;
940        s.serialize_field("application", &self.application)?;
941        s.serialize_field("attempt_count", &self.attempt_count)?;
942        s.serialize_field("attempted", &self.attempted)?;
943        s.serialize_field("auto_advance", &self.auto_advance)?;
944        s.serialize_field("automatic_tax", &self.automatic_tax)?;
945        s.serialize_field("automatically_finalizes_at", &self.automatically_finalizes_at)?;
946        s.serialize_field("billing_reason", &self.billing_reason)?;
947        s.serialize_field("collection_method", &self.collection_method)?;
948        s.serialize_field("confirmation_secret", &self.confirmation_secret)?;
949        s.serialize_field("created", &self.created)?;
950        s.serialize_field("currency", &self.currency)?;
951        s.serialize_field("custom_fields", &self.custom_fields)?;
952        s.serialize_field("customer", &self.customer)?;
953        s.serialize_field("customer_account", &self.customer_account)?;
954        s.serialize_field("customer_address", &self.customer_address)?;
955        s.serialize_field("customer_email", &self.customer_email)?;
956        s.serialize_field("customer_name", &self.customer_name)?;
957        s.serialize_field("customer_phone", &self.customer_phone)?;
958        s.serialize_field("customer_shipping", &self.customer_shipping)?;
959        s.serialize_field("customer_tax_exempt", &self.customer_tax_exempt)?;
960        s.serialize_field("customer_tax_ids", &self.customer_tax_ids)?;
961        s.serialize_field("default_payment_method", &self.default_payment_method)?;
962        s.serialize_field("default_source", &self.default_source)?;
963        s.serialize_field("default_tax_rates", &self.default_tax_rates)?;
964        s.serialize_field("description", &self.description)?;
965        s.serialize_field("discounts", &self.discounts)?;
966        s.serialize_field("due_date", &self.due_date)?;
967        s.serialize_field("effective_at", &self.effective_at)?;
968        s.serialize_field("ending_balance", &self.ending_balance)?;
969        s.serialize_field("footer", &self.footer)?;
970        s.serialize_field("from_invoice", &self.from_invoice)?;
971        s.serialize_field("hosted_invoice_url", &self.hosted_invoice_url)?;
972        s.serialize_field("id", &self.id)?;
973        s.serialize_field("invoice_pdf", &self.invoice_pdf)?;
974        s.serialize_field("issuer", &self.issuer)?;
975        s.serialize_field("last_finalization_error", &self.last_finalization_error)?;
976        s.serialize_field("latest_revision", &self.latest_revision)?;
977        s.serialize_field("lines", &self.lines)?;
978        s.serialize_field("livemode", &self.livemode)?;
979        s.serialize_field("metadata", &self.metadata)?;
980        s.serialize_field("next_payment_attempt", &self.next_payment_attempt)?;
981        s.serialize_field("number", &self.number)?;
982        s.serialize_field("on_behalf_of", &self.on_behalf_of)?;
983        s.serialize_field("parent", &self.parent)?;
984        s.serialize_field("payment_settings", &self.payment_settings)?;
985        s.serialize_field("payments", &self.payments)?;
986        s.serialize_field("period_end", &self.period_end)?;
987        s.serialize_field("period_start", &self.period_start)?;
988        s.serialize_field(
989            "post_payment_credit_notes_amount",
990            &self.post_payment_credit_notes_amount,
991        )?;
992        s.serialize_field(
993            "pre_payment_credit_notes_amount",
994            &self.pre_payment_credit_notes_amount,
995        )?;
996        s.serialize_field("receipt_number", &self.receipt_number)?;
997        s.serialize_field("rendering", &self.rendering)?;
998        s.serialize_field("shipping_cost", &self.shipping_cost)?;
999        s.serialize_field("shipping_details", &self.shipping_details)?;
1000        s.serialize_field("starting_balance", &self.starting_balance)?;
1001        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
1002        s.serialize_field("status", &self.status)?;
1003        s.serialize_field("status_transitions", &self.status_transitions)?;
1004        s.serialize_field("subscription", &self.subscription)?;
1005        s.serialize_field("subtotal", &self.subtotal)?;
1006        s.serialize_field("subtotal_excluding_tax", &self.subtotal_excluding_tax)?;
1007        s.serialize_field("test_clock", &self.test_clock)?;
1008        s.serialize_field("threshold_reason", &self.threshold_reason)?;
1009        s.serialize_field("total", &self.total)?;
1010        s.serialize_field("total_discount_amounts", &self.total_discount_amounts)?;
1011        s.serialize_field("total_excluding_tax", &self.total_excluding_tax)?;
1012        s.serialize_field("total_pretax_credit_amounts", &self.total_pretax_credit_amounts)?;
1013        s.serialize_field("total_taxes", &self.total_taxes)?;
1014        s.serialize_field("webhooks_delivered_at", &self.webhooks_delivered_at)?;
1015
1016        s.serialize_field("object", "invoice")?;
1017        s.end()
1018    }
1019}
1020/// Indicates the reason why the invoice was created.
1021///
1022/// * `manual`: Unrelated to a subscription, for example, created via the invoice editor.
1023/// * `subscription`: No longer in use.
1024///   Applies to subscriptions from before May 2018 where no distinction was made between updates, cycles, and thresholds.
1025/// * `subscription_create`: A new subscription was created.
1026/// * `subscription_cycle`: A subscription advanced into a new period.
1027/// * `subscription_threshold`: A subscription reached a billing threshold.
1028/// * `subscription_update`: A subscription was updated.
1029/// * `upcoming`: Reserved for upcoming invoices created through the Create Preview Invoice API or when an `invoice.upcoming` event is generated for an upcoming invoice on a subscription.
1030#[derive(Clone, Eq, PartialEq)]
1031#[non_exhaustive]
1032pub enum InvoiceBillingReason {
1033    AutomaticPendingInvoiceItemInvoice,
1034    Manual,
1035    QuoteAccept,
1036    Subscription,
1037    SubscriptionCreate,
1038    SubscriptionCycle,
1039    SubscriptionThreshold,
1040    SubscriptionUpdate,
1041    Upcoming,
1042    /// An unrecognized value from Stripe. Should not be used as a request parameter.
1043    Unknown(String),
1044}
1045impl InvoiceBillingReason {
1046    pub fn as_str(&self) -> &str {
1047        use InvoiceBillingReason::*;
1048        match self {
1049            AutomaticPendingInvoiceItemInvoice => "automatic_pending_invoice_item_invoice",
1050            Manual => "manual",
1051            QuoteAccept => "quote_accept",
1052            Subscription => "subscription",
1053            SubscriptionCreate => "subscription_create",
1054            SubscriptionCycle => "subscription_cycle",
1055            SubscriptionThreshold => "subscription_threshold",
1056            SubscriptionUpdate => "subscription_update",
1057            Upcoming => "upcoming",
1058            Unknown(v) => v,
1059        }
1060    }
1061}
1062
1063impl std::str::FromStr for InvoiceBillingReason {
1064    type Err = std::convert::Infallible;
1065    fn from_str(s: &str) -> Result<Self, Self::Err> {
1066        use InvoiceBillingReason::*;
1067        match s {
1068            "automatic_pending_invoice_item_invoice" => Ok(AutomaticPendingInvoiceItemInvoice),
1069            "manual" => Ok(Manual),
1070            "quote_accept" => Ok(QuoteAccept),
1071            "subscription" => Ok(Subscription),
1072            "subscription_create" => Ok(SubscriptionCreate),
1073            "subscription_cycle" => Ok(SubscriptionCycle),
1074            "subscription_threshold" => Ok(SubscriptionThreshold),
1075            "subscription_update" => Ok(SubscriptionUpdate),
1076            "upcoming" => Ok(Upcoming),
1077            v => {
1078                tracing::warn!("Unknown value '{}' for enum '{}'", v, "InvoiceBillingReason");
1079                Ok(Unknown(v.to_owned()))
1080            }
1081        }
1082    }
1083}
1084impl std::fmt::Display for InvoiceBillingReason {
1085    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1086        f.write_str(self.as_str())
1087    }
1088}
1089
1090#[cfg(not(feature = "redact-generated-debug"))]
1091impl std::fmt::Debug for InvoiceBillingReason {
1092    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1093        f.write_str(self.as_str())
1094    }
1095}
1096#[cfg(feature = "redact-generated-debug")]
1097impl std::fmt::Debug for InvoiceBillingReason {
1098    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1099        f.debug_struct(stringify!(InvoiceBillingReason)).finish_non_exhaustive()
1100    }
1101}
1102#[cfg(feature = "serialize")]
1103impl serde::Serialize for InvoiceBillingReason {
1104    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1105    where
1106        S: serde::Serializer,
1107    {
1108        serializer.serialize_str(self.as_str())
1109    }
1110}
1111impl miniserde::Deserialize for InvoiceBillingReason {
1112    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
1113        crate::Place::new(out)
1114    }
1115}
1116
1117impl miniserde::de::Visitor for crate::Place<InvoiceBillingReason> {
1118    fn string(&mut self, s: &str) -> miniserde::Result<()> {
1119        use std::str::FromStr;
1120        self.out = Some(InvoiceBillingReason::from_str(s).expect("infallible"));
1121        Ok(())
1122    }
1123}
1124
1125stripe_types::impl_from_val_with_from_str!(InvoiceBillingReason);
1126#[cfg(feature = "deserialize")]
1127impl<'de> serde::Deserialize<'de> for InvoiceBillingReason {
1128    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1129        use std::str::FromStr;
1130        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
1131        Ok(Self::from_str(&s).expect("infallible"))
1132    }
1133}
1134/// The customer's tax exempt status.
1135/// Until the invoice is finalized, this field will equal `customer.tax_exempt`.
1136/// Once the invoice is finalized, this field will no longer be updated.
1137#[derive(Clone, Eq, PartialEq)]
1138#[non_exhaustive]
1139pub enum InvoiceCustomerTaxExempt {
1140    Exempt,
1141    None,
1142    Reverse,
1143    /// An unrecognized value from Stripe. Should not be used as a request parameter.
1144    Unknown(String),
1145}
1146impl InvoiceCustomerTaxExempt {
1147    pub fn as_str(&self) -> &str {
1148        use InvoiceCustomerTaxExempt::*;
1149        match self {
1150            Exempt => "exempt",
1151            None => "none",
1152            Reverse => "reverse",
1153            Unknown(v) => v,
1154        }
1155    }
1156}
1157
1158impl std::str::FromStr for InvoiceCustomerTaxExempt {
1159    type Err = std::convert::Infallible;
1160    fn from_str(s: &str) -> Result<Self, Self::Err> {
1161        use InvoiceCustomerTaxExempt::*;
1162        match s {
1163            "exempt" => Ok(Exempt),
1164            "none" => Ok(None),
1165            "reverse" => Ok(Reverse),
1166            v => {
1167                tracing::warn!("Unknown value '{}' for enum '{}'", v, "InvoiceCustomerTaxExempt");
1168                Ok(Unknown(v.to_owned()))
1169            }
1170        }
1171    }
1172}
1173impl std::fmt::Display for InvoiceCustomerTaxExempt {
1174    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1175        f.write_str(self.as_str())
1176    }
1177}
1178
1179#[cfg(not(feature = "redact-generated-debug"))]
1180impl std::fmt::Debug for InvoiceCustomerTaxExempt {
1181    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1182        f.write_str(self.as_str())
1183    }
1184}
1185#[cfg(feature = "redact-generated-debug")]
1186impl std::fmt::Debug for InvoiceCustomerTaxExempt {
1187    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1188        f.debug_struct(stringify!(InvoiceCustomerTaxExempt)).finish_non_exhaustive()
1189    }
1190}
1191#[cfg(feature = "serialize")]
1192impl serde::Serialize for InvoiceCustomerTaxExempt {
1193    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1194    where
1195        S: serde::Serializer,
1196    {
1197        serializer.serialize_str(self.as_str())
1198    }
1199}
1200impl miniserde::Deserialize for InvoiceCustomerTaxExempt {
1201    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
1202        crate::Place::new(out)
1203    }
1204}
1205
1206impl miniserde::de::Visitor for crate::Place<InvoiceCustomerTaxExempt> {
1207    fn string(&mut self, s: &str) -> miniserde::Result<()> {
1208        use std::str::FromStr;
1209        self.out = Some(InvoiceCustomerTaxExempt::from_str(s).expect("infallible"));
1210        Ok(())
1211    }
1212}
1213
1214stripe_types::impl_from_val_with_from_str!(InvoiceCustomerTaxExempt);
1215#[cfg(feature = "deserialize")]
1216impl<'de> serde::Deserialize<'de> for InvoiceCustomerTaxExempt {
1217    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1218        use std::str::FromStr;
1219        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
1220        Ok(Self::from_str(&s).expect("infallible"))
1221    }
1222}
1223impl stripe_types::Object for Invoice {
1224    type Id = Option<stripe_shared::InvoiceId>;
1225    fn id(&self) -> &Self::Id {
1226        &self.id
1227    }
1228
1229    fn into_id(self) -> Self::Id {
1230        self.id
1231    }
1232}
1233stripe_types::def_id!(InvoiceId);
1234#[derive(Clone, Eq, PartialEq)]
1235#[non_exhaustive]
1236pub enum InvoiceCollectionMethod {
1237    ChargeAutomatically,
1238    SendInvoice,
1239    /// An unrecognized value from Stripe. Should not be used as a request parameter.
1240    Unknown(String),
1241}
1242impl InvoiceCollectionMethod {
1243    pub fn as_str(&self) -> &str {
1244        use InvoiceCollectionMethod::*;
1245        match self {
1246            ChargeAutomatically => "charge_automatically",
1247            SendInvoice => "send_invoice",
1248            Unknown(v) => v,
1249        }
1250    }
1251}
1252
1253impl std::str::FromStr for InvoiceCollectionMethod {
1254    type Err = std::convert::Infallible;
1255    fn from_str(s: &str) -> Result<Self, Self::Err> {
1256        use InvoiceCollectionMethod::*;
1257        match s {
1258            "charge_automatically" => Ok(ChargeAutomatically),
1259            "send_invoice" => Ok(SendInvoice),
1260            v => {
1261                tracing::warn!("Unknown value '{}' for enum '{}'", v, "InvoiceCollectionMethod");
1262                Ok(Unknown(v.to_owned()))
1263            }
1264        }
1265    }
1266}
1267impl std::fmt::Display for InvoiceCollectionMethod {
1268    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1269        f.write_str(self.as_str())
1270    }
1271}
1272
1273#[cfg(not(feature = "redact-generated-debug"))]
1274impl std::fmt::Debug for InvoiceCollectionMethod {
1275    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1276        f.write_str(self.as_str())
1277    }
1278}
1279#[cfg(feature = "redact-generated-debug")]
1280impl std::fmt::Debug for InvoiceCollectionMethod {
1281    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1282        f.debug_struct(stringify!(InvoiceCollectionMethod)).finish_non_exhaustive()
1283    }
1284}
1285impl serde::Serialize for InvoiceCollectionMethod {
1286    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1287    where
1288        S: serde::Serializer,
1289    {
1290        serializer.serialize_str(self.as_str())
1291    }
1292}
1293impl miniserde::Deserialize for InvoiceCollectionMethod {
1294    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
1295        crate::Place::new(out)
1296    }
1297}
1298
1299impl miniserde::de::Visitor for crate::Place<InvoiceCollectionMethod> {
1300    fn string(&mut self, s: &str) -> miniserde::Result<()> {
1301        use std::str::FromStr;
1302        self.out = Some(InvoiceCollectionMethod::from_str(s).expect("infallible"));
1303        Ok(())
1304    }
1305}
1306
1307stripe_types::impl_from_val_with_from_str!(InvoiceCollectionMethod);
1308#[cfg(feature = "deserialize")]
1309impl<'de> serde::Deserialize<'de> for InvoiceCollectionMethod {
1310    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1311        use std::str::FromStr;
1312        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
1313        Ok(Self::from_str(&s).expect("infallible"))
1314    }
1315}
1316#[derive(Clone, Eq, PartialEq)]
1317#[non_exhaustive]
1318pub enum InvoiceStatus {
1319    Draft,
1320    Open,
1321    Paid,
1322    Uncollectible,
1323    Void,
1324    /// An unrecognized value from Stripe. Should not be used as a request parameter.
1325    Unknown(String),
1326}
1327impl InvoiceStatus {
1328    pub fn as_str(&self) -> &str {
1329        use InvoiceStatus::*;
1330        match self {
1331            Draft => "draft",
1332            Open => "open",
1333            Paid => "paid",
1334            Uncollectible => "uncollectible",
1335            Void => "void",
1336            Unknown(v) => v,
1337        }
1338    }
1339}
1340
1341impl std::str::FromStr for InvoiceStatus {
1342    type Err = std::convert::Infallible;
1343    fn from_str(s: &str) -> Result<Self, Self::Err> {
1344        use InvoiceStatus::*;
1345        match s {
1346            "draft" => Ok(Draft),
1347            "open" => Ok(Open),
1348            "paid" => Ok(Paid),
1349            "uncollectible" => Ok(Uncollectible),
1350            "void" => Ok(Void),
1351            v => {
1352                tracing::warn!("Unknown value '{}' for enum '{}'", v, "InvoiceStatus");
1353                Ok(Unknown(v.to_owned()))
1354            }
1355        }
1356    }
1357}
1358impl std::fmt::Display for InvoiceStatus {
1359    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1360        f.write_str(self.as_str())
1361    }
1362}
1363
1364#[cfg(not(feature = "redact-generated-debug"))]
1365impl std::fmt::Debug for InvoiceStatus {
1366    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1367        f.write_str(self.as_str())
1368    }
1369}
1370#[cfg(feature = "redact-generated-debug")]
1371impl std::fmt::Debug for InvoiceStatus {
1372    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
1373        f.debug_struct(stringify!(InvoiceStatus)).finish_non_exhaustive()
1374    }
1375}
1376impl serde::Serialize for InvoiceStatus {
1377    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1378    where
1379        S: serde::Serializer,
1380    {
1381        serializer.serialize_str(self.as_str())
1382    }
1383}
1384impl miniserde::Deserialize for InvoiceStatus {
1385    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
1386        crate::Place::new(out)
1387    }
1388}
1389
1390impl miniserde::de::Visitor for crate::Place<InvoiceStatus> {
1391    fn string(&mut self, s: &str) -> miniserde::Result<()> {
1392        use std::str::FromStr;
1393        self.out = Some(InvoiceStatus::from_str(s).expect("infallible"));
1394        Ok(())
1395    }
1396}
1397
1398stripe_types::impl_from_val_with_from_str!(InvoiceStatus);
1399#[cfg(feature = "deserialize")]
1400impl<'de> serde::Deserialize<'de> for InvoiceStatus {
1401    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
1402        use std::str::FromStr;
1403        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
1404        Ok(Self::from_str(&s).expect("infallible"))
1405    }
1406}