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