stripe/resources/generated/
line_item.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::ids::InvoiceLineItemId;
6use crate::params::{Expandable, Metadata, Object};
7use crate::resources::{
8    Currency, Discount, InvoiceItem, Period, Plan, Price, Subscription, SubscriptionItem, TaxRate,
9};
10use serde::{Deserialize, Serialize};
11
12/// The resource representing a Stripe "InvoiceLineItem".
13#[derive(Clone, Debug, Default, Deserialize, Serialize)]
14pub struct InvoiceLineItem {
15    /// Unique identifier for the object.
16    pub id: InvoiceLineItemId,
17
18    /// The amount, in cents (or local equivalent).
19    pub amount: i64,
20
21    /// The integer amount in cents (or local equivalent) representing the amount for this line item, excluding all tax and discounts.
22    pub amount_excluding_tax: Option<i64>,
23
24    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
25    ///
26    /// Must be a [supported currency](https://stripe.com/docs/currencies).
27    pub currency: Currency,
28
29    /// An arbitrary string attached to the object.
30    ///
31    /// Often useful for displaying to users.
32    pub description: Option<String>,
33
34    /// The amount of discount calculated per discount for this line item.
35    pub discount_amounts: Option<Vec<DiscountsResourceDiscountAmount>>,
36
37    /// If true, discounts will apply to this line item.
38    ///
39    /// Always false for prorations.
40    pub discountable: bool,
41
42    /// The discounts applied to the invoice line item.
43    ///
44    /// Line item discounts are applied before invoice discounts.
45    /// Use `expand[]=discounts` to expand each discount.
46    pub discounts: Option<Vec<Expandable<Discount>>>,
47
48    /// The ID of the [invoice item](https://stripe.com/docs/api/invoiceitems) associated with this line item if any.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub invoice_item: Option<Expandable<InvoiceItem>>,
51
52    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
53    pub livemode: bool,
54
55    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
56    ///
57    /// This can be useful for storing additional information about the object in a structured format.
58    /// Note that for line items with `type=subscription` this will reflect the metadata of the subscription that caused the line item to be created.
59    pub metadata: Metadata,
60
61    pub period: Option<Period>,
62
63    /// The plan of the subscription, if the line item is a subscription or a proration.
64    pub plan: Option<Plan>,
65
66    /// The price of the line item.
67    pub price: Option<Price>,
68
69    /// Whether this is a proration.
70    pub proration: bool,
71
72    /// Additional details for proration line items.
73    pub proration_details: Option<InvoicesResourceLineItemsProrationDetails>,
74
75    /// The quantity of the subscription, if the line item is a subscription or a proration.
76    pub quantity: Option<u64>,
77
78    /// The subscription that the invoice item pertains to, if any.
79    pub subscription: Option<Expandable<Subscription>>,
80
81    /// The subscription item that generated this line item.
82    ///
83    /// Left empty if the line item is not an explicit result of a subscription.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub subscription_item: Option<Expandable<SubscriptionItem>>,
86
87    /// The amount of tax calculated per tax rate for this line item.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub tax_amounts: Option<Vec<TaxAmount>>,
90
91    /// The tax rates which apply to the line item.
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub tax_rates: Option<Vec<TaxRate>>,
94
95    /// A string identifying the type of the source of this line item, either an `invoiceitem` or a `subscription`.
96    #[serde(rename = "type")]
97    pub type_: InvoiceLineItemType,
98
99    /// The amount in cents (or local equivalent) representing the unit amount for this line item, excluding all tax and discounts.
100    pub unit_amount_excluding_tax: Option<String>,
101}
102
103impl Object for InvoiceLineItem {
104    type Id = InvoiceLineItemId;
105    fn id(&self) -> Self::Id {
106        self.id.clone()
107    }
108    fn object(&self) -> &'static str {
109        "line_item"
110    }
111}
112
113#[derive(Clone, Debug, Default, Deserialize, Serialize)]
114pub struct DiscountsResourceDiscountAmount {
115    /// The amount, in cents (or local equivalent), of the discount.
116    pub amount: i64,
117
118    /// The discount that was applied to get this discount amount.
119    pub discount: Expandable<Discount>,
120}
121
122#[derive(Clone, Debug, Default, Deserialize, Serialize)]
123pub struct TaxAmount {
124    /// The amount, in cents (or local equivalent), of the tax.
125    pub amount: i64,
126
127    /// Whether this tax amount is inclusive or exclusive.
128    pub inclusive: bool,
129
130    /// The tax rate that was applied to get this tax amount.
131    pub tax_rate: Expandable<TaxRate>,
132
133    /// The reasoning behind this tax, for example, if the product is tax exempt.
134    ///
135    /// The possible values for this field may be extended as new tax rules are supported.
136    pub taxability_reason: Option<TaxAmountTaxabilityReason>,
137
138    /// The amount on which tax is calculated, in cents (or local equivalent).
139    pub taxable_amount: Option<i64>,
140}
141
142#[derive(Clone, Debug, Default, Deserialize, Serialize)]
143pub struct InvoicesResourceLineItemsProrationDetails {
144    /// For a credit proration `line_item`, the original debit line_items to which the credit proration applies.
145    pub credited_items: Option<InvoicesResourceLineItemsCreditedItems>,
146}
147
148#[derive(Clone, Debug, Default, Deserialize, Serialize)]
149pub struct InvoicesResourceLineItemsCreditedItems {
150    /// Invoice containing the credited invoice line items.
151    pub invoice: String,
152
153    /// Credited invoice line items.
154    pub invoice_line_items: Vec<String>,
155}
156
157/// An enum representing the possible values of an `InvoiceLineItem`'s `type` field.
158#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
159#[serde(rename_all = "snake_case")]
160pub enum InvoiceLineItemType {
161    #[serde(rename = "invoiceitem")]
162    InvoiceItem,
163    Subscription,
164}
165
166impl InvoiceLineItemType {
167    pub fn as_str(self) -> &'static str {
168        match self {
169            InvoiceLineItemType::InvoiceItem => "invoiceitem",
170            InvoiceLineItemType::Subscription => "subscription",
171        }
172    }
173}
174
175impl AsRef<str> for InvoiceLineItemType {
176    fn as_ref(&self) -> &str {
177        self.as_str()
178    }
179}
180
181impl std::fmt::Display for InvoiceLineItemType {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        self.as_str().fmt(f)
184    }
185}
186impl std::default::Default for InvoiceLineItemType {
187    fn default() -> Self {
188        Self::InvoiceItem
189    }
190}
191
192/// An enum representing the possible values of an `TaxAmount`'s `taxability_reason` field.
193#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
194#[serde(rename_all = "snake_case")]
195pub enum TaxAmountTaxabilityReason {
196    CustomerExempt,
197    NotCollecting,
198    NotSubjectToTax,
199    NotSupported,
200    PortionProductExempt,
201    PortionReducedRated,
202    PortionStandardRated,
203    ProductExempt,
204    ProductExemptHoliday,
205    ProportionallyRated,
206    ReducedRated,
207    ReverseCharge,
208    StandardRated,
209    TaxableBasisReduced,
210    ZeroRated,
211}
212
213impl TaxAmountTaxabilityReason {
214    pub fn as_str(self) -> &'static str {
215        match self {
216            TaxAmountTaxabilityReason::CustomerExempt => "customer_exempt",
217            TaxAmountTaxabilityReason::NotCollecting => "not_collecting",
218            TaxAmountTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
219            TaxAmountTaxabilityReason::NotSupported => "not_supported",
220            TaxAmountTaxabilityReason::PortionProductExempt => "portion_product_exempt",
221            TaxAmountTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
222            TaxAmountTaxabilityReason::PortionStandardRated => "portion_standard_rated",
223            TaxAmountTaxabilityReason::ProductExempt => "product_exempt",
224            TaxAmountTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
225            TaxAmountTaxabilityReason::ProportionallyRated => "proportionally_rated",
226            TaxAmountTaxabilityReason::ReducedRated => "reduced_rated",
227            TaxAmountTaxabilityReason::ReverseCharge => "reverse_charge",
228            TaxAmountTaxabilityReason::StandardRated => "standard_rated",
229            TaxAmountTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
230            TaxAmountTaxabilityReason::ZeroRated => "zero_rated",
231        }
232    }
233}
234
235impl AsRef<str> for TaxAmountTaxabilityReason {
236    fn as_ref(&self) -> &str {
237        self.as_str()
238    }
239}
240
241impl std::fmt::Display for TaxAmountTaxabilityReason {
242    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
243        self.as_str().fmt(f)
244    }
245}
246impl std::default::Default for TaxAmountTaxabilityReason {
247    fn default() -> Self {
248        Self::CustomerExempt
249    }
250}