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::{make_place, Deserialize, Result};
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
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self {
77                amount: Deserialize::default(),
78                currency: Deserialize::default(),
79                email: Deserialize::default(),
80                items: Deserialize::default(),
81                shipping: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (Some(amount), Some(currency), Some(email), Some(items), Some(shipping)) = (
87                self.amount,
88                self.currency,
89                self.email.take(),
90                self.items.take(),
91                self.shipping.take(),
92            ) else {
93                return None;
94            };
95            Some(Self::Out { amount, currency, email, items, shipping })
96        }
97    }
98
99    impl<'a> Map for Builder<'a> {
100        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
101            self.builder.key(k)
102        }
103
104        fn finish(&mut self) -> Result<()> {
105            *self.out = self.builder.take_out();
106            Ok(())
107        }
108    }
109
110    impl ObjectDeser for SourceOrder {
111        type Builder = SourceOrderBuilder;
112    }
113
114    impl FromValueOpt for SourceOrder {
115        fn from_value(v: Value) -> Option<Self> {
116            let Value::Object(obj) = v else {
117                return None;
118            };
119            let mut b = SourceOrderBuilder::deser_default();
120            for (k, v) in obj {
121                match k.as_str() {
122                    "amount" => b.amount = FromValueOpt::from_value(v),
123                    "currency" => b.currency = FromValueOpt::from_value(v),
124                    "email" => b.email = FromValueOpt::from_value(v),
125                    "items" => b.items = FromValueOpt::from_value(v),
126                    "shipping" => b.shipping = FromValueOpt::from_value(v),
127
128                    _ => {}
129                }
130            }
131            b.take_out()
132        }
133    }
134};