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