stripe_misc/
tax_transaction_line_item.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
3pub struct TaxTransactionLineItem {
4    /// The line item amount in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
5    /// If `tax_behavior=inclusive`, then this amount includes taxes.
6    /// Otherwise, taxes were calculated on top of this amount.
7    pub amount: i64,
8    /// The amount of tax calculated for this line item, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
9    pub amount_tax: i64,
10    /// Unique identifier for the object.
11    pub id: stripe_misc::TaxTransactionLineItemId,
12    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
13    pub livemode: bool,
14    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
15    /// This can be useful for storing additional information about the object in a structured format.
16    pub metadata: Option<std::collections::HashMap<String, String>>,
17    /// The ID of an existing [Product](https://stripe.com/docs/api/products/object).
18    pub product: Option<String>,
19    /// The number of units of the item being purchased. For reversals, this is the quantity reversed.
20    pub quantity: u64,
21    /// A custom identifier for this line item in the transaction.
22    pub reference: String,
23    /// If `type=reversal`, contains information about what was reversed.
24    pub reversal: Option<stripe_misc::TaxProductResourceTaxTransactionLineItemResourceReversal>,
25    /// Specifies whether the `amount` includes taxes.
26    /// If `tax_behavior=inclusive`, then the amount includes taxes.
27    pub tax_behavior: TaxTransactionLineItemTaxBehavior,
28    /// The [tax code](https://stripe.com/docs/tax/tax-categories) ID used for this resource.
29    pub tax_code: String,
30    /// If `reversal`, this line item reverses an earlier transaction.
31    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
32    pub type_: TaxTransactionLineItemType,
33}
34#[doc(hidden)]
35pub struct TaxTransactionLineItemBuilder {
36    amount: Option<i64>,
37    amount_tax: Option<i64>,
38    id: Option<stripe_misc::TaxTransactionLineItemId>,
39    livemode: Option<bool>,
40    metadata: Option<Option<std::collections::HashMap<String, String>>>,
41    product: Option<Option<String>>,
42    quantity: Option<u64>,
43    reference: Option<String>,
44    reversal: Option<Option<stripe_misc::TaxProductResourceTaxTransactionLineItemResourceReversal>>,
45    tax_behavior: Option<TaxTransactionLineItemTaxBehavior>,
46    tax_code: Option<String>,
47    type_: Option<TaxTransactionLineItemType>,
48}
49
50#[allow(
51    unused_variables,
52    irrefutable_let_patterns,
53    clippy::let_unit_value,
54    clippy::match_single_binding,
55    clippy::single_match
56)]
57const _: () = {
58    use miniserde::de::{Map, Visitor};
59    use miniserde::json::Value;
60    use miniserde::{Deserialize, Result, make_place};
61    use stripe_types::miniserde_helpers::FromValueOpt;
62    use stripe_types::{MapBuilder, ObjectDeser};
63
64    make_place!(Place);
65
66    impl Deserialize for TaxTransactionLineItem {
67        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
68            Place::new(out)
69        }
70    }
71
72    struct Builder<'a> {
73        out: &'a mut Option<TaxTransactionLineItem>,
74        builder: TaxTransactionLineItemBuilder,
75    }
76
77    impl Visitor for Place<TaxTransactionLineItem> {
78        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
79            Ok(Box::new(Builder {
80                out: &mut self.out,
81                builder: TaxTransactionLineItemBuilder::deser_default(),
82            }))
83        }
84    }
85
86    impl MapBuilder for TaxTransactionLineItemBuilder {
87        type Out = TaxTransactionLineItem;
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            Ok(match k {
90                "amount" => Deserialize::begin(&mut self.amount),
91                "amount_tax" => Deserialize::begin(&mut self.amount_tax),
92                "id" => Deserialize::begin(&mut self.id),
93                "livemode" => Deserialize::begin(&mut self.livemode),
94                "metadata" => Deserialize::begin(&mut self.metadata),
95                "product" => Deserialize::begin(&mut self.product),
96                "quantity" => Deserialize::begin(&mut self.quantity),
97                "reference" => Deserialize::begin(&mut self.reference),
98                "reversal" => Deserialize::begin(&mut self.reversal),
99                "tax_behavior" => Deserialize::begin(&mut self.tax_behavior),
100                "tax_code" => Deserialize::begin(&mut self.tax_code),
101                "type" => Deserialize::begin(&mut self.type_),
102                _ => <dyn Visitor>::ignore(),
103            })
104        }
105
106        fn deser_default() -> Self {
107            Self {
108                amount: Deserialize::default(),
109                amount_tax: Deserialize::default(),
110                id: Deserialize::default(),
111                livemode: Deserialize::default(),
112                metadata: Deserialize::default(),
113                product: Deserialize::default(),
114                quantity: Deserialize::default(),
115                reference: Deserialize::default(),
116                reversal: Deserialize::default(),
117                tax_behavior: Deserialize::default(),
118                tax_code: Deserialize::default(),
119                type_: Deserialize::default(),
120            }
121        }
122
123        fn take_out(&mut self) -> Option<Self::Out> {
124            let (
125                Some(amount),
126                Some(amount_tax),
127                Some(id),
128                Some(livemode),
129                Some(metadata),
130                Some(product),
131                Some(quantity),
132                Some(reference),
133                Some(reversal),
134                Some(tax_behavior),
135                Some(tax_code),
136                Some(type_),
137            ) = (
138                self.amount,
139                self.amount_tax,
140                self.id.take(),
141                self.livemode,
142                self.metadata.take(),
143                self.product.take(),
144                self.quantity,
145                self.reference.take(),
146                self.reversal.take(),
147                self.tax_behavior,
148                self.tax_code.take(),
149                self.type_,
150            )
151            else {
152                return None;
153            };
154            Some(Self::Out {
155                amount,
156                amount_tax,
157                id,
158                livemode,
159                metadata,
160                product,
161                quantity,
162                reference,
163                reversal,
164                tax_behavior,
165                tax_code,
166                type_,
167            })
168        }
169    }
170
171    impl Map for Builder<'_> {
172        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
173            self.builder.key(k)
174        }
175
176        fn finish(&mut self) -> Result<()> {
177            *self.out = self.builder.take_out();
178            Ok(())
179        }
180    }
181
182    impl ObjectDeser for TaxTransactionLineItem {
183        type Builder = TaxTransactionLineItemBuilder;
184    }
185
186    impl FromValueOpt for TaxTransactionLineItem {
187        fn from_value(v: Value) -> Option<Self> {
188            let Value::Object(obj) = v else {
189                return None;
190            };
191            let mut b = TaxTransactionLineItemBuilder::deser_default();
192            for (k, v) in obj {
193                match k.as_str() {
194                    "amount" => b.amount = FromValueOpt::from_value(v),
195                    "amount_tax" => b.amount_tax = FromValueOpt::from_value(v),
196                    "id" => b.id = FromValueOpt::from_value(v),
197                    "livemode" => b.livemode = FromValueOpt::from_value(v),
198                    "metadata" => b.metadata = FromValueOpt::from_value(v),
199                    "product" => b.product = FromValueOpt::from_value(v),
200                    "quantity" => b.quantity = FromValueOpt::from_value(v),
201                    "reference" => b.reference = FromValueOpt::from_value(v),
202                    "reversal" => b.reversal = FromValueOpt::from_value(v),
203                    "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
204                    "tax_code" => b.tax_code = FromValueOpt::from_value(v),
205                    "type" => b.type_ = FromValueOpt::from_value(v),
206                    _ => {}
207                }
208            }
209            b.take_out()
210        }
211    }
212};
213#[cfg(feature = "serialize")]
214impl serde::Serialize for TaxTransactionLineItem {
215    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
216        use serde::ser::SerializeStruct;
217        let mut s = s.serialize_struct("TaxTransactionLineItem", 13)?;
218        s.serialize_field("amount", &self.amount)?;
219        s.serialize_field("amount_tax", &self.amount_tax)?;
220        s.serialize_field("id", &self.id)?;
221        s.serialize_field("livemode", &self.livemode)?;
222        s.serialize_field("metadata", &self.metadata)?;
223        s.serialize_field("product", &self.product)?;
224        s.serialize_field("quantity", &self.quantity)?;
225        s.serialize_field("reference", &self.reference)?;
226        s.serialize_field("reversal", &self.reversal)?;
227        s.serialize_field("tax_behavior", &self.tax_behavior)?;
228        s.serialize_field("tax_code", &self.tax_code)?;
229        s.serialize_field("type", &self.type_)?;
230
231        s.serialize_field("object", "tax.transaction_line_item")?;
232        s.end()
233    }
234}
235/// Specifies whether the `amount` includes taxes.
236/// If `tax_behavior=inclusive`, then the amount includes taxes.
237#[derive(Copy, Clone, Eq, PartialEq)]
238pub enum TaxTransactionLineItemTaxBehavior {
239    Exclusive,
240    Inclusive,
241}
242impl TaxTransactionLineItemTaxBehavior {
243    pub fn as_str(self) -> &'static str {
244        use TaxTransactionLineItemTaxBehavior::*;
245        match self {
246            Exclusive => "exclusive",
247            Inclusive => "inclusive",
248        }
249    }
250}
251
252impl std::str::FromStr for TaxTransactionLineItemTaxBehavior {
253    type Err = stripe_types::StripeParseError;
254    fn from_str(s: &str) -> Result<Self, Self::Err> {
255        use TaxTransactionLineItemTaxBehavior::*;
256        match s {
257            "exclusive" => Ok(Exclusive),
258            "inclusive" => Ok(Inclusive),
259            _ => Err(stripe_types::StripeParseError),
260        }
261    }
262}
263impl std::fmt::Display for TaxTransactionLineItemTaxBehavior {
264    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
265        f.write_str(self.as_str())
266    }
267}
268
269impl std::fmt::Debug for TaxTransactionLineItemTaxBehavior {
270    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271        f.write_str(self.as_str())
272    }
273}
274#[cfg(feature = "serialize")]
275impl serde::Serialize for TaxTransactionLineItemTaxBehavior {
276    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
277    where
278        S: serde::Serializer,
279    {
280        serializer.serialize_str(self.as_str())
281    }
282}
283impl miniserde::Deserialize for TaxTransactionLineItemTaxBehavior {
284    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
285        crate::Place::new(out)
286    }
287}
288
289impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemTaxBehavior> {
290    fn string(&mut self, s: &str) -> miniserde::Result<()> {
291        use std::str::FromStr;
292        self.out =
293            Some(TaxTransactionLineItemTaxBehavior::from_str(s).map_err(|_| miniserde::Error)?);
294        Ok(())
295    }
296}
297
298stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemTaxBehavior);
299#[cfg(feature = "deserialize")]
300impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemTaxBehavior {
301    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
302        use std::str::FromStr;
303        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
304        Self::from_str(&s).map_err(|_| {
305            serde::de::Error::custom("Unknown value for TaxTransactionLineItemTaxBehavior")
306        })
307    }
308}
309/// If `reversal`, this line item reverses an earlier transaction.
310#[derive(Copy, Clone, Eq, PartialEq)]
311pub enum TaxTransactionLineItemType {
312    Reversal,
313    Transaction,
314}
315impl TaxTransactionLineItemType {
316    pub fn as_str(self) -> &'static str {
317        use TaxTransactionLineItemType::*;
318        match self {
319            Reversal => "reversal",
320            Transaction => "transaction",
321        }
322    }
323}
324
325impl std::str::FromStr for TaxTransactionLineItemType {
326    type Err = stripe_types::StripeParseError;
327    fn from_str(s: &str) -> Result<Self, Self::Err> {
328        use TaxTransactionLineItemType::*;
329        match s {
330            "reversal" => Ok(Reversal),
331            "transaction" => Ok(Transaction),
332            _ => Err(stripe_types::StripeParseError),
333        }
334    }
335}
336impl std::fmt::Display for TaxTransactionLineItemType {
337    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
338        f.write_str(self.as_str())
339    }
340}
341
342impl std::fmt::Debug for TaxTransactionLineItemType {
343    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
344        f.write_str(self.as_str())
345    }
346}
347#[cfg(feature = "serialize")]
348impl serde::Serialize for TaxTransactionLineItemType {
349    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
350    where
351        S: serde::Serializer,
352    {
353        serializer.serialize_str(self.as_str())
354    }
355}
356impl miniserde::Deserialize for TaxTransactionLineItemType {
357    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
358        crate::Place::new(out)
359    }
360}
361
362impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemType> {
363    fn string(&mut self, s: &str) -> miniserde::Result<()> {
364        use std::str::FromStr;
365        self.out = Some(TaxTransactionLineItemType::from_str(s).map_err(|_| miniserde::Error)?);
366        Ok(())
367    }
368}
369
370stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemType);
371#[cfg(feature = "deserialize")]
372impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemType {
373    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
374        use std::str::FromStr;
375        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
376        Self::from_str(&s)
377            .map_err(|_| serde::de::Error::custom("Unknown value for TaxTransactionLineItemType"))
378    }
379}
380impl stripe_types::Object for TaxTransactionLineItem {
381    type Id = stripe_misc::TaxTransactionLineItemId;
382    fn id(&self) -> &Self::Id {
383        &self.id
384    }
385
386    fn into_id(self) -> Self::Id {
387        self.id
388    }
389}
390stripe_types::def_id!(TaxTransactionLineItemId);