stripe_shared/
source_order.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SourceOrder {
5    /// A positive integer in the smallest currency unit (that is, 100 cents for $1.00, or 1 for ¥1, Japanese Yen being a zero-decimal currency) representing the total amount for the order.
6    pub amount: i64,
7    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
8    /// Must be a [supported currency](https://stripe.com/docs/currencies).
9    pub currency: stripe_types::Currency,
10    /// The email address of the customer placing the order.
11    pub email: Option<String>,
12    /// List of items constituting the order.
13    pub items: Option<Vec<stripe_shared::SourceOrderItem>>,
14    pub shipping: Option<stripe_shared::Shipping>,
15}
16#[doc(hidden)]
17pub struct SourceOrderBuilder {
18    amount: Option<i64>,
19    currency: Option<stripe_types::Currency>,
20    email: Option<Option<String>>,
21    items: Option<Option<Vec<stripe_shared::SourceOrderItem>>>,
22    shipping: Option<Option<stripe_shared::Shipping>>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for SourceOrder {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<SourceOrder>,
49        builder: SourceOrderBuilder,
50    }
51
52    impl Visitor for Place<SourceOrder> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: SourceOrderBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for SourceOrderBuilder {
62        type Out = SourceOrder;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "amount" => Deserialize::begin(&mut self.amount),
66                "currency" => Deserialize::begin(&mut self.currency),
67                "email" => Deserialize::begin(&mut self.email),
68                "items" => Deserialize::begin(&mut self.items),
69                "shipping" => Deserialize::begin(&mut self.shipping),
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                amount: Deserialize::default(),
77                currency: Deserialize::default(),
78                email: Deserialize::default(),
79                items: Deserialize::default(),
80                shipping: Deserialize::default(),
81            }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (Some(amount), Some(currency), Some(email), Some(items), Some(shipping)) = (
86                self.amount,
87                self.currency.take(),
88                self.email.take(),
89                self.items.take(),
90                self.shipping.take(),
91            ) else {
92                return None;
93            };
94            Some(Self::Out { amount, currency, email, items, shipping })
95        }
96    }
97
98    impl Map for Builder<'_> {
99        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
100            self.builder.key(k)
101        }
102
103        fn finish(&mut self) -> Result<()> {
104            *self.out = self.builder.take_out();
105            Ok(())
106        }
107    }
108
109    impl ObjectDeser for SourceOrder {
110        type Builder = SourceOrderBuilder;
111    }
112
113    impl FromValueOpt for SourceOrder {
114        fn from_value(v: Value) -> Option<Self> {
115            let Value::Object(obj) = v else {
116                return None;
117            };
118            let mut b = SourceOrderBuilder::deser_default();
119            for (k, v) in obj {
120                match k.as_str() {
121                    "amount" => b.amount = FromValueOpt::from_value(v),
122                    "currency" => b.currency = FromValueOpt::from_value(v),
123                    "email" => b.email = FromValueOpt::from_value(v),
124                    "items" => b.items = FromValueOpt::from_value(v),
125                    "shipping" => b.shipping = FromValueOpt::from_value(v),
126                    _ => {}
127                }
128            }
129            b.take_out()
130        }
131    }
132};