stripe_shared/
invoice.rs

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