stripe/resources/generated/
item.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::ids::CheckoutSessionItemId;
6use crate::params::Object;
7use crate::resources::{Currency, Discount, Price, TaxRate};
8use serde::{Deserialize, Serialize};
9
10/// The resource representing a Stripe "LineItem".
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
12pub struct CheckoutSessionItem {
13    /// Unique identifier for the object.
14    pub id: CheckoutSessionItemId,
15
16    /// Total discount amount applied.
17    ///
18    /// If no discounts were applied, defaults to 0.
19    pub amount_discount: i64,
20
21    /// Total before any discounts or taxes are applied.
22    pub amount_subtotal: i64,
23
24    /// Total tax amount applied.
25    ///
26    /// If no tax was applied, defaults to 0.
27    pub amount_tax: i64,
28
29    /// Total after discounts and taxes.
30    pub amount_total: i64,
31
32    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
33    ///
34    /// Must be a [supported currency](https://stripe.com/docs/currencies).
35    pub currency: Currency,
36
37    /// An arbitrary string attached to the object.
38    ///
39    /// Often useful for displaying to users.
40    /// Defaults to product name.
41    pub description: String,
42
43    /// The discounts applied to the line item.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub discounts: Option<Vec<LineItemsDiscountAmount>>,
46
47    /// The price used to generate the line item.
48    pub price: Option<Price>,
49
50    /// The quantity of products being purchased.
51    pub quantity: Option<u64>,
52
53    /// The taxes applied to the line item.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub taxes: Option<Vec<LineItemsTaxAmount>>,
56}
57
58impl Object for CheckoutSessionItem {
59    type Id = CheckoutSessionItemId;
60    fn id(&self) -> Self::Id {
61        self.id.clone()
62    }
63    fn object(&self) -> &'static str {
64        "item"
65    }
66}
67
68#[derive(Clone, Debug, Default, Deserialize, Serialize)]
69pub struct LineItemsDiscountAmount {
70    /// The amount discounted.
71    pub amount: i64,
72
73    pub discount: Discount,
74}
75
76#[derive(Clone, Debug, Default, Deserialize, Serialize)]
77pub struct LineItemsTaxAmount {
78    /// Amount of tax applied for this rate.
79    pub amount: i64,
80
81    pub rate: TaxRate,
82
83    /// The reasoning behind this tax, for example, if the product is tax exempt.
84    ///
85    /// The possible values for this field may be extended as new tax rules are supported.
86    pub taxability_reason: Option<LineItemsTaxAmountTaxabilityReason>,
87
88    /// The amount on which tax is calculated, in cents (or local equivalent).
89    pub taxable_amount: Option<i64>,
90}
91
92/// An enum representing the possible values of an `LineItemsTaxAmount`'s `taxability_reason` field.
93#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
94#[serde(rename_all = "snake_case")]
95pub enum LineItemsTaxAmountTaxabilityReason {
96    CustomerExempt,
97    NotCollecting,
98    NotSubjectToTax,
99    NotSupported,
100    PortionProductExempt,
101    PortionReducedRated,
102    PortionStandardRated,
103    ProductExempt,
104    ProductExemptHoliday,
105    ProportionallyRated,
106    ReducedRated,
107    ReverseCharge,
108    StandardRated,
109    TaxableBasisReduced,
110    ZeroRated,
111}
112
113impl LineItemsTaxAmountTaxabilityReason {
114    pub fn as_str(self) -> &'static str {
115        match self {
116            LineItemsTaxAmountTaxabilityReason::CustomerExempt => "customer_exempt",
117            LineItemsTaxAmountTaxabilityReason::NotCollecting => "not_collecting",
118            LineItemsTaxAmountTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
119            LineItemsTaxAmountTaxabilityReason::NotSupported => "not_supported",
120            LineItemsTaxAmountTaxabilityReason::PortionProductExempt => "portion_product_exempt",
121            LineItemsTaxAmountTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
122            LineItemsTaxAmountTaxabilityReason::PortionStandardRated => "portion_standard_rated",
123            LineItemsTaxAmountTaxabilityReason::ProductExempt => "product_exempt",
124            LineItemsTaxAmountTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
125            LineItemsTaxAmountTaxabilityReason::ProportionallyRated => "proportionally_rated",
126            LineItemsTaxAmountTaxabilityReason::ReducedRated => "reduced_rated",
127            LineItemsTaxAmountTaxabilityReason::ReverseCharge => "reverse_charge",
128            LineItemsTaxAmountTaxabilityReason::StandardRated => "standard_rated",
129            LineItemsTaxAmountTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
130            LineItemsTaxAmountTaxabilityReason::ZeroRated => "zero_rated",
131        }
132    }
133}
134
135impl AsRef<str> for LineItemsTaxAmountTaxabilityReason {
136    fn as_ref(&self) -> &str {
137        self.as_str()
138    }
139}
140
141impl std::fmt::Display for LineItemsTaxAmountTaxabilityReason {
142    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
143        self.as_str().fmt(f)
144    }
145}
146impl std::default::Default for LineItemsTaxAmountTaxabilityReason {
147    fn default() -> Self {
148        Self::CustomerExempt
149    }
150}