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