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