stripe_misc/
bank_connections_resource_balance.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct BankConnectionsResourceBalance {
5    /// The time that the external institution calculated this balance.
6    /// Measured in seconds since the Unix epoch.
7    pub as_of: stripe_types::Timestamp,
8    pub cash: Option<stripe_misc::BankConnectionsResourceBalanceApiResourceCashBalance>,
9    pub credit: Option<stripe_misc::BankConnectionsResourceBalanceApiResourceCreditBalance>,
10    /// The balances owed to (or by) the account holder, before subtracting any outbound pending transactions or adding any inbound pending transactions.
11    ///
12    /// Each key is a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
13    ///
14    /// Each value is a integer amount.
15    /// A positive amount indicates money owed to the account holder.
16    /// A negative amount indicates money owed by the account holder.
17    pub current: std::collections::HashMap<String, i64>,
18    /// The `type` of the balance.
19    /// An additional hash is included on the balance with a name matching this value.
20    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
21    pub type_: BankConnectionsResourceBalanceType,
22}
23#[doc(hidden)]
24pub struct BankConnectionsResourceBalanceBuilder {
25    as_of: Option<stripe_types::Timestamp>,
26    cash: Option<Option<stripe_misc::BankConnectionsResourceBalanceApiResourceCashBalance>>,
27    credit: Option<Option<stripe_misc::BankConnectionsResourceBalanceApiResourceCreditBalance>>,
28    current: Option<std::collections::HashMap<String, i64>>,
29    type_: Option<BankConnectionsResourceBalanceType>,
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 BankConnectionsResourceBalance {
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<BankConnectionsResourceBalance>,
56        builder: BankConnectionsResourceBalanceBuilder,
57    }
58
59    impl Visitor for Place<BankConnectionsResourceBalance> {
60        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
61            Ok(Box::new(Builder {
62                out: &mut self.out,
63                builder: BankConnectionsResourceBalanceBuilder::deser_default(),
64            }))
65        }
66    }
67
68    impl MapBuilder for BankConnectionsResourceBalanceBuilder {
69        type Out = BankConnectionsResourceBalance;
70        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
71            Ok(match k {
72                "as_of" => Deserialize::begin(&mut self.as_of),
73                "cash" => Deserialize::begin(&mut self.cash),
74                "credit" => Deserialize::begin(&mut self.credit),
75                "current" => Deserialize::begin(&mut self.current),
76                "type" => Deserialize::begin(&mut self.type_),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                as_of: Deserialize::default(),
84                cash: Deserialize::default(),
85                credit: Deserialize::default(),
86                current: Deserialize::default(),
87                type_: Deserialize::default(),
88            }
89        }
90
91        fn take_out(&mut self) -> Option<Self::Out> {
92            let (Some(as_of), Some(cash), Some(credit), Some(current), Some(type_)) =
93                (self.as_of, self.cash.take(), self.credit.take(), self.current.take(), self.type_)
94            else {
95                return None;
96            };
97            Some(Self::Out { as_of, cash, credit, current, type_ })
98        }
99    }
100
101    impl Map for Builder<'_> {
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            self.builder.key(k)
104        }
105
106        fn finish(&mut self) -> Result<()> {
107            *self.out = self.builder.take_out();
108            Ok(())
109        }
110    }
111
112    impl ObjectDeser for BankConnectionsResourceBalance {
113        type Builder = BankConnectionsResourceBalanceBuilder;
114    }
115
116    impl FromValueOpt for BankConnectionsResourceBalance {
117        fn from_value(v: Value) -> Option<Self> {
118            let Value::Object(obj) = v else {
119                return None;
120            };
121            let mut b = BankConnectionsResourceBalanceBuilder::deser_default();
122            for (k, v) in obj {
123                match k.as_str() {
124                    "as_of" => b.as_of = FromValueOpt::from_value(v),
125                    "cash" => b.cash = FromValueOpt::from_value(v),
126                    "credit" => b.credit = FromValueOpt::from_value(v),
127                    "current" => b.current = FromValueOpt::from_value(v),
128                    "type" => b.type_ = FromValueOpt::from_value(v),
129                    _ => {}
130                }
131            }
132            b.take_out()
133        }
134    }
135};
136/// The `type` of the balance.
137/// An additional hash is included on the balance with a name matching this value.
138#[derive(Copy, Clone, Eq, PartialEq)]
139pub enum BankConnectionsResourceBalanceType {
140    Cash,
141    Credit,
142}
143impl BankConnectionsResourceBalanceType {
144    pub fn as_str(self) -> &'static str {
145        use BankConnectionsResourceBalanceType::*;
146        match self {
147            Cash => "cash",
148            Credit => "credit",
149        }
150    }
151}
152
153impl std::str::FromStr for BankConnectionsResourceBalanceType {
154    type Err = stripe_types::StripeParseError;
155    fn from_str(s: &str) -> Result<Self, Self::Err> {
156        use BankConnectionsResourceBalanceType::*;
157        match s {
158            "cash" => Ok(Cash),
159            "credit" => Ok(Credit),
160            _ => Err(stripe_types::StripeParseError),
161        }
162    }
163}
164impl std::fmt::Display for BankConnectionsResourceBalanceType {
165    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
166        f.write_str(self.as_str())
167    }
168}
169
170impl std::fmt::Debug for BankConnectionsResourceBalanceType {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175#[cfg(feature = "serialize")]
176impl serde::Serialize for BankConnectionsResourceBalanceType {
177    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
178    where
179        S: serde::Serializer,
180    {
181        serializer.serialize_str(self.as_str())
182    }
183}
184impl miniserde::Deserialize for BankConnectionsResourceBalanceType {
185    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
186        crate::Place::new(out)
187    }
188}
189
190impl miniserde::de::Visitor for crate::Place<BankConnectionsResourceBalanceType> {
191    fn string(&mut self, s: &str) -> miniserde::Result<()> {
192        use std::str::FromStr;
193        self.out =
194            Some(BankConnectionsResourceBalanceType::from_str(s).map_err(|_| miniserde::Error)?);
195        Ok(())
196    }
197}
198
199stripe_types::impl_from_val_with_from_str!(BankConnectionsResourceBalanceType);
200#[cfg(feature = "deserialize")]
201impl<'de> serde::Deserialize<'de> for BankConnectionsResourceBalanceType {
202    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
203        use std::str::FromStr;
204        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
205        Self::from_str(&s).map_err(|_| {
206            serde::de::Error::custom("Unknown value for BankConnectionsResourceBalanceType")
207        })
208    }
209}