stripe_shared/
checkout_session_item.rs

1/// A line item.
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct CheckoutSessionItem {
5    /// Total discount amount applied. If no discounts were applied, defaults to 0.
6    pub amount_discount: i64,
7    /// Total before any discounts or taxes are applied.
8    pub amount_subtotal: i64,
9    /// Total tax amount applied. If no tax was applied, defaults to 0.
10    pub amount_tax: i64,
11    /// Total after discounts and taxes.
12    pub amount_total: i64,
13    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
14    /// Must be a [supported currency](https://stripe.com/docs/currencies).
15    pub currency: stripe_types::Currency,
16    /// An arbitrary string attached to the object.
17    /// Often useful for displaying to users.
18    /// Defaults to product name.
19    pub description: Option<String>,
20    /// The discounts applied to the line item.
21    pub discounts: Option<Vec<stripe_shared::LineItemsDiscountAmount>>,
22    /// Unique identifier for the object.
23    pub id: stripe_shared::CheckoutSessionItemId,
24    /// The price used to generate the line item.
25    pub price: Option<stripe_shared::Price>,
26    /// The quantity of products being purchased.
27    pub quantity: Option<u64>,
28    /// The taxes applied to the line item.
29    pub taxes: Option<Vec<stripe_shared::LineItemsTaxAmount>>,
30}
31#[doc(hidden)]
32pub struct CheckoutSessionItemBuilder {
33    amount_discount: Option<i64>,
34    amount_subtotal: Option<i64>,
35    amount_tax: Option<i64>,
36    amount_total: Option<i64>,
37    currency: Option<stripe_types::Currency>,
38    description: Option<Option<String>>,
39    discounts: Option<Option<Vec<stripe_shared::LineItemsDiscountAmount>>>,
40    id: Option<stripe_shared::CheckoutSessionItemId>,
41    price: Option<Option<stripe_shared::Price>>,
42    quantity: Option<Option<u64>>,
43    taxes: Option<Option<Vec<stripe_shared::LineItemsTaxAmount>>>,
44}
45
46#[allow(
47    unused_variables,
48    irrefutable_let_patterns,
49    clippy::let_unit_value,
50    clippy::match_single_binding,
51    clippy::single_match
52)]
53const _: () = {
54    use miniserde::de::{Map, Visitor};
55    use miniserde::json::Value;
56    use miniserde::{Deserialize, Result, make_place};
57    use stripe_types::miniserde_helpers::FromValueOpt;
58    use stripe_types::{MapBuilder, ObjectDeser};
59
60    make_place!(Place);
61
62    impl Deserialize for CheckoutSessionItem {
63        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
64            Place::new(out)
65        }
66    }
67
68    struct Builder<'a> {
69        out: &'a mut Option<CheckoutSessionItem>,
70        builder: CheckoutSessionItemBuilder,
71    }
72
73    impl Visitor for Place<CheckoutSessionItem> {
74        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
75            Ok(Box::new(Builder {
76                out: &mut self.out,
77                builder: CheckoutSessionItemBuilder::deser_default(),
78            }))
79        }
80    }
81
82    impl MapBuilder for CheckoutSessionItemBuilder {
83        type Out = CheckoutSessionItem;
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            Ok(match k {
86                "amount_discount" => Deserialize::begin(&mut self.amount_discount),
87                "amount_subtotal" => Deserialize::begin(&mut self.amount_subtotal),
88                "amount_tax" => Deserialize::begin(&mut self.amount_tax),
89                "amount_total" => Deserialize::begin(&mut self.amount_total),
90                "currency" => Deserialize::begin(&mut self.currency),
91                "description" => Deserialize::begin(&mut self.description),
92                "discounts" => Deserialize::begin(&mut self.discounts),
93                "id" => Deserialize::begin(&mut self.id),
94                "price" => Deserialize::begin(&mut self.price),
95                "quantity" => Deserialize::begin(&mut self.quantity),
96                "taxes" => Deserialize::begin(&mut self.taxes),
97
98                _ => <dyn Visitor>::ignore(),
99            })
100        }
101
102        fn deser_default() -> Self {
103            Self {
104                amount_discount: Deserialize::default(),
105                amount_subtotal: Deserialize::default(),
106                amount_tax: Deserialize::default(),
107                amount_total: Deserialize::default(),
108                currency: Deserialize::default(),
109                description: Deserialize::default(),
110                discounts: Deserialize::default(),
111                id: Deserialize::default(),
112                price: Deserialize::default(),
113                quantity: Deserialize::default(),
114                taxes: Deserialize::default(),
115            }
116        }
117
118        fn take_out(&mut self) -> Option<Self::Out> {
119            let (
120                Some(amount_discount),
121                Some(amount_subtotal),
122                Some(amount_tax),
123                Some(amount_total),
124                Some(currency),
125                Some(description),
126                Some(discounts),
127                Some(id),
128                Some(price),
129                Some(quantity),
130                Some(taxes),
131            ) = (
132                self.amount_discount,
133                self.amount_subtotal,
134                self.amount_tax,
135                self.amount_total,
136                self.currency.take(),
137                self.description.take(),
138                self.discounts.take(),
139                self.id.take(),
140                self.price.take(),
141                self.quantity,
142                self.taxes.take(),
143            )
144            else {
145                return None;
146            };
147            Some(Self::Out {
148                amount_discount,
149                amount_subtotal,
150                amount_tax,
151                amount_total,
152                currency,
153                description,
154                discounts,
155                id,
156                price,
157                quantity,
158                taxes,
159            })
160        }
161    }
162
163    impl Map for Builder<'_> {
164        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
165            self.builder.key(k)
166        }
167
168        fn finish(&mut self) -> Result<()> {
169            *self.out = self.builder.take_out();
170            Ok(())
171        }
172    }
173
174    impl ObjectDeser for CheckoutSessionItem {
175        type Builder = CheckoutSessionItemBuilder;
176    }
177
178    impl FromValueOpt for CheckoutSessionItem {
179        fn from_value(v: Value) -> Option<Self> {
180            let Value::Object(obj) = v else {
181                return None;
182            };
183            let mut b = CheckoutSessionItemBuilder::deser_default();
184            for (k, v) in obj {
185                match k.as_str() {
186                    "amount_discount" => b.amount_discount = FromValueOpt::from_value(v),
187                    "amount_subtotal" => b.amount_subtotal = FromValueOpt::from_value(v),
188                    "amount_tax" => b.amount_tax = FromValueOpt::from_value(v),
189                    "amount_total" => b.amount_total = FromValueOpt::from_value(v),
190                    "currency" => b.currency = FromValueOpt::from_value(v),
191                    "description" => b.description = FromValueOpt::from_value(v),
192                    "discounts" => b.discounts = FromValueOpt::from_value(v),
193                    "id" => b.id = FromValueOpt::from_value(v),
194                    "price" => b.price = FromValueOpt::from_value(v),
195                    "quantity" => b.quantity = FromValueOpt::from_value(v),
196                    "taxes" => b.taxes = FromValueOpt::from_value(v),
197
198                    _ => {}
199                }
200            }
201            b.take_out()
202        }
203    }
204};
205#[cfg(feature = "serialize")]
206impl serde::Serialize for CheckoutSessionItem {
207    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
208        use serde::ser::SerializeStruct;
209        let mut s = s.serialize_struct("CheckoutSessionItem", 12)?;
210        s.serialize_field("amount_discount", &self.amount_discount)?;
211        s.serialize_field("amount_subtotal", &self.amount_subtotal)?;
212        s.serialize_field("amount_tax", &self.amount_tax)?;
213        s.serialize_field("amount_total", &self.amount_total)?;
214        s.serialize_field("currency", &self.currency)?;
215        s.serialize_field("description", &self.description)?;
216        s.serialize_field("discounts", &self.discounts)?;
217        s.serialize_field("id", &self.id)?;
218        s.serialize_field("price", &self.price)?;
219        s.serialize_field("quantity", &self.quantity)?;
220        s.serialize_field("taxes", &self.taxes)?;
221
222        s.serialize_field("object", "item")?;
223        s.end()
224    }
225}
226impl stripe_types::Object for CheckoutSessionItem {
227    type Id = stripe_shared::CheckoutSessionItemId;
228    fn id(&self) -> &Self::Id {
229        &self.id
230    }
231
232    fn into_id(self) -> Self::Id {
233        self.id
234    }
235}
236stripe_types::def_id!(CheckoutSessionItemId);