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.take(),
148                self.tax_code.take(),
149                self.type_.take(),
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(Clone, Eq, PartialEq)]
238#[non_exhaustive]
239pub enum TaxTransactionLineItemTaxBehavior {
240    Exclusive,
241    Inclusive,
242    /// An unrecognized value from Stripe. Should not be used as a request parameter.
243    Unknown(String),
244}
245impl TaxTransactionLineItemTaxBehavior {
246    pub fn as_str(&self) -> &str {
247        use TaxTransactionLineItemTaxBehavior::*;
248        match self {
249            Exclusive => "exclusive",
250            Inclusive => "inclusive",
251            Unknown(v) => v,
252        }
253    }
254}
255
256impl std::str::FromStr for TaxTransactionLineItemTaxBehavior {
257    type Err = std::convert::Infallible;
258    fn from_str(s: &str) -> Result<Self, Self::Err> {
259        use TaxTransactionLineItemTaxBehavior::*;
260        match s {
261            "exclusive" => Ok(Exclusive),
262            "inclusive" => Ok(Inclusive),
263            v => {
264                tracing::warn!(
265                    "Unknown value '{}' for enum '{}'",
266                    v,
267                    "TaxTransactionLineItemTaxBehavior"
268                );
269                Ok(Unknown(v.to_owned()))
270            }
271        }
272    }
273}
274impl std::fmt::Display for TaxTransactionLineItemTaxBehavior {
275    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
276        f.write_str(self.as_str())
277    }
278}
279
280impl std::fmt::Debug for TaxTransactionLineItemTaxBehavior {
281    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
282        f.write_str(self.as_str())
283    }
284}
285#[cfg(feature = "serialize")]
286impl serde::Serialize for TaxTransactionLineItemTaxBehavior {
287    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
288    where
289        S: serde::Serializer,
290    {
291        serializer.serialize_str(self.as_str())
292    }
293}
294impl miniserde::Deserialize for TaxTransactionLineItemTaxBehavior {
295    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
296        crate::Place::new(out)
297    }
298}
299
300impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemTaxBehavior> {
301    fn string(&mut self, s: &str) -> miniserde::Result<()> {
302        use std::str::FromStr;
303        self.out = Some(TaxTransactionLineItemTaxBehavior::from_str(s).expect("infallible"));
304        Ok(())
305    }
306}
307
308stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemTaxBehavior);
309#[cfg(feature = "deserialize")]
310impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemTaxBehavior {
311    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
312        use std::str::FromStr;
313        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
314        Ok(Self::from_str(&s).expect("infallible"))
315    }
316}
317/// If `reversal`, this line item reverses an earlier transaction.
318#[derive(Clone, Eq, PartialEq)]
319#[non_exhaustive]
320pub enum TaxTransactionLineItemType {
321    Reversal,
322    Transaction,
323    /// An unrecognized value from Stripe. Should not be used as a request parameter.
324    Unknown(String),
325}
326impl TaxTransactionLineItemType {
327    pub fn as_str(&self) -> &str {
328        use TaxTransactionLineItemType::*;
329        match self {
330            Reversal => "reversal",
331            Transaction => "transaction",
332            Unknown(v) => v,
333        }
334    }
335}
336
337impl std::str::FromStr for TaxTransactionLineItemType {
338    type Err = std::convert::Infallible;
339    fn from_str(s: &str) -> Result<Self, Self::Err> {
340        use TaxTransactionLineItemType::*;
341        match s {
342            "reversal" => Ok(Reversal),
343            "transaction" => Ok(Transaction),
344            v => {
345                tracing::warn!("Unknown value '{}' for enum '{}'", v, "TaxTransactionLineItemType");
346                Ok(Unknown(v.to_owned()))
347            }
348        }
349    }
350}
351impl std::fmt::Display for TaxTransactionLineItemType {
352    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
353        f.write_str(self.as_str())
354    }
355}
356
357impl std::fmt::Debug for TaxTransactionLineItemType {
358    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
359        f.write_str(self.as_str())
360    }
361}
362#[cfg(feature = "serialize")]
363impl serde::Serialize for TaxTransactionLineItemType {
364    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
365    where
366        S: serde::Serializer,
367    {
368        serializer.serialize_str(self.as_str())
369    }
370}
371impl miniserde::Deserialize for TaxTransactionLineItemType {
372    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
373        crate::Place::new(out)
374    }
375}
376
377impl miniserde::de::Visitor for crate::Place<TaxTransactionLineItemType> {
378    fn string(&mut self, s: &str) -> miniserde::Result<()> {
379        use std::str::FromStr;
380        self.out = Some(TaxTransactionLineItemType::from_str(s).expect("infallible"));
381        Ok(())
382    }
383}
384
385stripe_types::impl_from_val_with_from_str!(TaxTransactionLineItemType);
386#[cfg(feature = "deserialize")]
387impl<'de> serde::Deserialize<'de> for TaxTransactionLineItemType {
388    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
389        use std::str::FromStr;
390        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
391        Ok(Self::from_str(&s).expect("infallible"))
392    }
393}
394impl stripe_types::Object for TaxTransactionLineItem {
395    type Id = stripe_misc::TaxTransactionLineItemId;
396    fn id(&self) -> &Self::Id {
397        &self.id
398    }
399
400    fn into_id(self) -> Self::Id {
401        self.id
402    }
403}
404stripe_types::def_id!(TaxTransactionLineItemId);