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
103                _ => <dyn Visitor>::ignore(),
104            })
105        }
106
107        fn deser_default() -> Self {
108            Self {
109                amount: Deserialize::default(),
110                amount_tax: Deserialize::default(),
111                id: Deserialize::default(),
112                livemode: Deserialize::default(),
113                metadata: Deserialize::default(),
114                product: Deserialize::default(),
115                quantity: Deserialize::default(),
116                reference: Deserialize::default(),
117                reversal: Deserialize::default(),
118                tax_behavior: Deserialize::default(),
119                tax_code: Deserialize::default(),
120                type_: Deserialize::default(),
121            }
122        }
123
124        fn take_out(&mut self) -> Option<Self::Out> {
125            let (
126                Some(amount),
127                Some(amount_tax),
128                Some(id),
129                Some(livemode),
130                Some(metadata),
131                Some(product),
132                Some(quantity),
133                Some(reference),
134                Some(reversal),
135                Some(tax_behavior),
136                Some(tax_code),
137                Some(type_),
138            ) = (
139                self.amount,
140                self.amount_tax,
141                self.id.take(),
142                self.livemode,
143                self.metadata.take(),
144                self.product.take(),
145                self.quantity,
146                self.reference.take(),
147                self.reversal.take(),
148                self.tax_behavior,
149                self.tax_code.take(),
150                self.type_,
151            )
152            else {
153                return None;
154            };
155            Some(Self::Out {
156                amount,
157                amount_tax,
158                id,
159                livemode,
160                metadata,
161                product,
162                quantity,
163                reference,
164                reversal,
165                tax_behavior,
166                tax_code,
167                type_,
168            })
169        }
170    }
171
172    impl Map for Builder<'_> {
173        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
174            self.builder.key(k)
175        }
176
177        fn finish(&mut self) -> Result<()> {
178            *self.out = self.builder.take_out();
179            Ok(())
180        }
181    }
182
183    impl ObjectDeser for TaxTransactionLineItem {
184        type Builder = TaxTransactionLineItemBuilder;
185    }
186
187    impl FromValueOpt for TaxTransactionLineItem {
188        fn from_value(v: Value) -> Option<Self> {
189            let Value::Object(obj) = v else {
190                return None;
191            };
192            let mut b = TaxTransactionLineItemBuilder::deser_default();
193            for (k, v) in obj {
194                match k.as_str() {
195                    "amount" => b.amount = FromValueOpt::from_value(v),
196                    "amount_tax" => b.amount_tax = FromValueOpt::from_value(v),
197                    "id" => b.id = FromValueOpt::from_value(v),
198                    "livemode" => b.livemode = FromValueOpt::from_value(v),
199                    "metadata" => b.metadata = FromValueOpt::from_value(v),
200                    "product" => b.product = FromValueOpt::from_value(v),
201                    "quantity" => b.quantity = FromValueOpt::from_value(v),
202                    "reference" => b.reference = FromValueOpt::from_value(v),
203                    "reversal" => b.reversal = FromValueOpt::from_value(v),
204                    "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
205                    "tax_code" => b.tax_code = FromValueOpt::from_value(v),
206                    "type" => b.type_ = FromValueOpt::from_value(v),
207
208                    _ => {}
209                }
210            }
211            b.take_out()
212        }
213    }
214};
215#[cfg(feature = "serialize")]
216impl serde::Serialize for TaxTransactionLineItem {
217    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
218        use serde::ser::SerializeStruct;
219        let mut s = s.serialize_struct("TaxTransactionLineItem", 13)?;
220        s.serialize_field("amount", &self.amount)?;
221        s.serialize_field("amount_tax", &self.amount_tax)?;
222        s.serialize_field("id", &self.id)?;
223        s.serialize_field("livemode", &self.livemode)?;
224        s.serialize_field("metadata", &self.metadata)?;
225        s.serialize_field("product", &self.product)?;
226        s.serialize_field("quantity", &self.quantity)?;
227        s.serialize_field("reference", &self.reference)?;
228        s.serialize_field("reversal", &self.reversal)?;
229        s.serialize_field("tax_behavior", &self.tax_behavior)?;
230        s.serialize_field("tax_code", &self.tax_code)?;
231        s.serialize_field("type", &self.type_)?;
232
233        s.serialize_field("object", "tax.transaction_line_item")?;
234        s.end()
235    }
236}
237/// Specifies whether the `amount` includes taxes.
238/// If `tax_behavior=inclusive`, then the amount includes taxes.
239#[derive(Copy, Clone, Eq, PartialEq)]
240pub enum TaxTransactionLineItemTaxBehavior {
241    Exclusive,
242    Inclusive,
243}
244impl TaxTransactionLineItemTaxBehavior {
245    pub fn as_str(self) -> &'static str {
246        use TaxTransactionLineItemTaxBehavior::*;
247        match self {
248            Exclusive => "exclusive",
249            Inclusive => "inclusive",
250        }
251    }
252}
253
254impl std::str::FromStr for TaxTransactionLineItemTaxBehavior {
255    type Err = stripe_types::StripeParseError;
256    fn from_str(s: &str) -> Result<Self, Self::Err> {
257        use TaxTransactionLineItemTaxBehavior::*;
258        match s {
259            "exclusive" => Ok(Exclusive),
260            "inclusive" => Ok(Inclusive),
261            _ => Err(stripe_types::StripeParseError),
262        }
263    }
264}
265impl std::fmt::Display for TaxTransactionLineItemTaxBehavior {
266    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
267        f.write_str(self.as_str())
268    }
269}
270
271impl std::fmt::Debug for TaxTransactionLineItemTaxBehavior {
272    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
273        f.write_str(self.as_str())
274    }
275}
276#[cfg(feature = "serialize")]
277impl serde::Serialize for TaxTransactionLineItemTaxBehavior {
278    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
279    where
280        S: serde::Serializer,
281    {
282        serializer.serialize_str(self.as_str())
283    }
284}
285impl miniserde::Deserialize for TaxTransactionLineItemTaxBehavior {
286    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
287        crate::Place::new(out)
288    }
289}
290
291impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemTaxBehavior> {
292    fn string(&mut self, s: &str) -> miniserde::Result<()> {
293        use std::str::FromStr;
294        self.out =
295            Some(TaxTransactionLineItemTaxBehavior::from_str(s).map_err(|_| miniserde::Error)?);
296        Ok(())
297    }
298}
299
300stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemTaxBehavior);
301#[cfg(feature = "deserialize")]
302impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemTaxBehavior {
303    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
304        use std::str::FromStr;
305        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
306        Self::from_str(&s).map_err(|_| {
307            serde::de::Error::custom("Unknown value for TaxTransactionLineItemTaxBehavior")
308        })
309    }
310}
311/// If `reversal`, this line item reverses an earlier transaction.
312#[derive(Copy, Clone, Eq, PartialEq)]
313pub enum TaxTransactionLineItemType {
314    Reversal,
315    Transaction,
316}
317impl TaxTransactionLineItemType {
318    pub fn as_str(self) -> &'static str {
319        use TaxTransactionLineItemType::*;
320        match self {
321            Reversal => "reversal",
322            Transaction => "transaction",
323        }
324    }
325}
326
327impl std::str::FromStr for TaxTransactionLineItemType {
328    type Err = stripe_types::StripeParseError;
329    fn from_str(s: &str) -> Result<Self, Self::Err> {
330        use TaxTransactionLineItemType::*;
331        match s {
332            "reversal" => Ok(Reversal),
333            "transaction" => Ok(Transaction),
334            _ => Err(stripe_types::StripeParseError),
335        }
336    }
337}
338impl std::fmt::Display for TaxTransactionLineItemType {
339    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
340        f.write_str(self.as_str())
341    }
342}
343
344impl std::fmt::Debug for TaxTransactionLineItemType {
345    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
346        f.write_str(self.as_str())
347    }
348}
349#[cfg(feature = "serialize")]
350impl serde::Serialize for TaxTransactionLineItemType {
351    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
352    where
353        S: serde::Serializer,
354    {
355        serializer.serialize_str(self.as_str())
356    }
357}
358impl miniserde::Deserialize for TaxTransactionLineItemType {
359    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
360        crate::Place::new(out)
361    }
362}
363
364impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemType> {
365    fn string(&mut self, s: &str) -> miniserde::Result<()> {
366        use std::str::FromStr;
367        self.out = Some(TaxTransactionLineItemType::from_str(s).map_err(|_| miniserde::Error)?);
368        Ok(())
369    }
370}
371
372stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemType);
373#[cfg(feature = "deserialize")]
374impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemType {
375    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
376        use std::str::FromStr;
377        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
378        Self::from_str(&s)
379            .map_err(|_| serde::de::Error::custom("Unknown value for TaxTransactionLineItemType"))
380    }
381}
382impl stripe_types::Object for TaxTransactionLineItem {
383    type Id = stripe_misc::TaxTransactionLineItemId;
384    fn id(&self) -> &Self::Id {
385        &self.id
386    }
387
388    fn into_id(self) -> Self::Id {
389        self.id
390    }
391}
392stripe_types::def_id!(TaxTransactionLineItemId);