stripe_misc/
tax_product_resource_tax_transaction_shipping_cost.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TaxProductResourceTaxTransactionShippingCost {
5    /// The shipping amount in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
6    /// If `tax_behavior=inclusive`, then this amount includes taxes.
7    /// Otherwise, taxes were calculated on top of this amount.
8    pub amount: i64,
9    /// The amount of tax calculated for shipping, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
10    pub amount_tax: i64,
11    /// The ID of an existing [ShippingRate](https://stripe.com/docs/api/shipping_rates/object).
12    pub shipping_rate: Option<String>,
13    /// Specifies whether the `amount` includes taxes.
14    /// If `tax_behavior=inclusive`, then the amount includes taxes.
15    pub tax_behavior: TaxProductResourceTaxTransactionShippingCostTaxBehavior,
16    /// Detailed account of taxes relevant to shipping cost.
17    /// (It is not populated for the transaction resource object and will be removed in the next API version.).
18    pub tax_breakdown: Option<Vec<stripe_misc::TaxProductResourceLineItemTaxBreakdown>>,
19    /// The [tax code](https://stripe.com/docs/tax/tax-categories) ID used for shipping.
20    pub tax_code: String,
21}
22#[doc(hidden)]
23pub struct TaxProductResourceTaxTransactionShippingCostBuilder {
24    amount: Option<i64>,
25    amount_tax: Option<i64>,
26    shipping_rate: Option<Option<String>>,
27    tax_behavior: Option<TaxProductResourceTaxTransactionShippingCostTaxBehavior>,
28    tax_breakdown: Option<Option<Vec<stripe_misc::TaxProductResourceLineItemTaxBreakdown>>>,
29    tax_code: Option<String>,
30}
31
32#[allow(
33    unused_variables,
34    irrefutable_let_patterns,
35    clippy::let_unit_value,
36    clippy::match_single_binding,
37    clippy::single_match
38)]
39const _: () = {
40    use miniserde::de::{Map, Visitor};
41    use miniserde::json::Value;
42    use miniserde::{Deserialize, Result, make_place};
43    use stripe_types::miniserde_helpers::FromValueOpt;
44    use stripe_types::{MapBuilder, ObjectDeser};
45
46    make_place!(Place);
47
48    impl Deserialize for TaxProductResourceTaxTransactionShippingCost {
49        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
50            Place::new(out)
51        }
52    }
53
54    struct Builder<'a> {
55        out: &'a mut Option<TaxProductResourceTaxTransactionShippingCost>,
56        builder: TaxProductResourceTaxTransactionShippingCostBuilder,
57    }
58
59    impl Visitor for Place<TaxProductResourceTaxTransactionShippingCost> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: TaxProductResourceTaxTransactionShippingCostBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for TaxProductResourceTaxTransactionShippingCostBuilder {
69        type Out = TaxProductResourceTaxTransactionShippingCost;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "amount" => Deserialize::begin(&mut self.amount),
73                "amount_tax" => Deserialize::begin(&mut self.amount_tax),
74                "shipping_rate" => Deserialize::begin(&mut self.shipping_rate),
75                "tax_behavior" => Deserialize::begin(&mut self.tax_behavior),
76                "tax_breakdown" => Deserialize::begin(&mut self.tax_breakdown),
77                "tax_code" => Deserialize::begin(&mut self.tax_code),
78                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                amount: Deserialize::default(),
85                amount_tax: Deserialize::default(),
86                shipping_rate: Deserialize::default(),
87                tax_behavior: Deserialize::default(),
88                tax_breakdown: Deserialize::default(),
89                tax_code: Deserialize::default(),
90            }
91        }
92
93        fn take_out(&mut self) -> Option<Self::Out> {
94            let (
95                Some(amount),
96                Some(amount_tax),
97                Some(shipping_rate),
98                Some(tax_behavior),
99                Some(tax_breakdown),
100                Some(tax_code),
101            ) = (
102                self.amount,
103                self.amount_tax,
104                self.shipping_rate.take(),
105                self.tax_behavior,
106                self.tax_breakdown.take(),
107                self.tax_code.take(),
108            )
109            else {
110                return None;
111            };
112            Some(Self::Out {
113                amount,
114                amount_tax,
115                shipping_rate,
116                tax_behavior,
117                tax_breakdown,
118                tax_code,
119            })
120        }
121    }
122
123    impl Map for Builder<'_> {
124        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
125            self.builder.key(k)
126        }
127
128        fn finish(&mut self) -> Result<()> {
129            *self.out = self.builder.take_out();
130            Ok(())
131        }
132    }
133
134    impl ObjectDeser for TaxProductResourceTaxTransactionShippingCost {
135        type Builder = TaxProductResourceTaxTransactionShippingCostBuilder;
136    }
137
138    impl FromValueOpt for TaxProductResourceTaxTransactionShippingCost {
139        fn from_value(v: Value) -> Option<Self> {
140            let Value::Object(obj) = v else {
141                return None;
142            };
143            let mut b = TaxProductResourceTaxTransactionShippingCostBuilder::deser_default();
144            for (k, v) in obj {
145                match k.as_str() {
146                    "amount" => b.amount = FromValueOpt::from_value(v),
147                    "amount_tax" => b.amount_tax = FromValueOpt::from_value(v),
148                    "shipping_rate" => b.shipping_rate = FromValueOpt::from_value(v),
149                    "tax_behavior" => b.tax_behavior = FromValueOpt::from_value(v),
150                    "tax_breakdown" => b.tax_breakdown = FromValueOpt::from_value(v),
151                    "tax_code" => b.tax_code = FromValueOpt::from_value(v),
152                    _ => {}
153                }
154            }
155            b.take_out()
156        }
157    }
158};
159/// Specifies whether the `amount` includes taxes.
160/// If `tax_behavior=inclusive`, then the amount includes taxes.
161#[derive(Copy, Clone, Eq, PartialEq)]
162pub enum TaxProductResourceTaxTransactionShippingCostTaxBehavior {
163    Exclusive,
164    Inclusive,
165}
166impl TaxProductResourceTaxTransactionShippingCostTaxBehavior {
167    pub fn as_str(self) -> &'static str {
168        use TaxProductResourceTaxTransactionShippingCostTaxBehavior::*;
169        match self {
170            Exclusive => "exclusive",
171            Inclusive => "inclusive",
172        }
173    }
174}
175
176impl std::str::FromStr for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
177    type Err = stripe_types::StripeParseError;
178    fn from_str(s: &str) -> Result<Self, Self::Err> {
179        use TaxProductResourceTaxTransactionShippingCostTaxBehavior::*;
180        match s {
181            "exclusive" => Ok(Exclusive),
182            "inclusive" => Ok(Inclusive),
183            _ => Err(stripe_types::StripeParseError),
184        }
185    }
186}
187impl std::fmt::Display for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
188    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
189        f.write_str(self.as_str())
190    }
191}
192
193impl std::fmt::Debug for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
194    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
195        f.write_str(self.as_str())
196    }
197}
198#[cfg(feature = "serialize")]
199impl serde::Serialize for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
200    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
201    where
202        S: serde::Serializer,
203    {
204        serializer.serialize_str(self.as_str())
205    }
206}
207impl miniserde::Deserialize for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
208    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
209        crate::Place::new(out)
210    }
211}
212
213impl miniserde::de::Visitor
214    for crate::Place<TaxProductResourceTaxTransactionShippingCostTaxBehavior>
215{
216    fn string(&mut self, s: &str) -> miniserde::Result<()> {
217        use std::str::FromStr;
218        self.out = Some(
219            TaxProductResourceTaxTransactionShippingCostTaxBehavior::from_str(s)
220                .map_err(|_| miniserde::Error)?,
221        );
222        Ok(())
223    }
224}
225
226stripe_types::impl_from_val_with_from_str!(TaxProductResourceTaxTransactionShippingCostTaxBehavior);
227#[cfg(feature = "deserialize")]
228impl<'de> serde::Deserialize<'de> for TaxProductResourceTaxTransactionShippingCostTaxBehavior {
229    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
230        use std::str::FromStr;
231        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
232        Self::from_str(&s).map_err(|_| {
233            serde::de::Error::custom(
234                "Unknown value for TaxProductResourceTaxTransactionShippingCostTaxBehavior",
235            )
236        })
237    }
238}