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
78                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                as_of: Deserialize::default(),
85                cash: Deserialize::default(),
86                credit: Deserialize::default(),
87                current: Deserialize::default(),
88                type_: Deserialize::default(),
89            }
90        }
91
92        fn take_out(&mut self) -> Option<Self::Out> {
93            let (Some(as_of), Some(cash), Some(credit), Some(current), Some(type_)) =
94                (self.as_of, self.cash.take(), self.credit.take(), self.current.take(), self.type_)
95            else {
96                return None;
97            };
98            Some(Self::Out { as_of, cash, credit, current, type_ })
99        }
100    }
101
102    impl Map for Builder<'_> {
103        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
104            self.builder.key(k)
105        }
106
107        fn finish(&mut self) -> Result<()> {
108            *self.out = self.builder.take_out();
109            Ok(())
110        }
111    }
112
113    impl ObjectDeser for BankConnectionsResourceBalance {
114        type Builder = BankConnectionsResourceBalanceBuilder;
115    }
116
117    impl FromValueOpt for BankConnectionsResourceBalance {
118        fn from_value(v: Value) -> Option<Self> {
119            let Value::Object(obj) = v else {
120                return None;
121            };
122            let mut b = BankConnectionsResourceBalanceBuilder::deser_default();
123            for (k, v) in obj {
124                match k.as_str() {
125                    "as_of" => b.as_of = FromValueOpt::from_value(v),
126                    "cash" => b.cash = FromValueOpt::from_value(v),
127                    "credit" => b.credit = FromValueOpt::from_value(v),
128                    "current" => b.current = FromValueOpt::from_value(v),
129                    "type" => b.type_ = FromValueOpt::from_value(v),
130
131                    _ => {}
132                }
133            }
134            b.take_out()
135        }
136    }
137};
138/// The `type` of the balance.
139/// An additional hash is included on the balance with a name matching this value.
140#[derive(Copy, Clone, Eq, PartialEq)]
141pub enum BankConnectionsResourceBalanceType {
142    Cash,
143    Credit,
144}
145impl BankConnectionsResourceBalanceType {
146    pub fn as_str(self) -> &'static str {
147        use BankConnectionsResourceBalanceType::*;
148        match self {
149            Cash => "cash",
150            Credit => "credit",
151        }
152    }
153}
154
155impl std::str::FromStr for BankConnectionsResourceBalanceType {
156    type Err = stripe_types::StripeParseError;
157    fn from_str(s: &str) -> Result<Self, Self::Err> {
158        use BankConnectionsResourceBalanceType::*;
159        match s {
160            "cash" => Ok(Cash),
161            "credit" => Ok(Credit),
162            _ => Err(stripe_types::StripeParseError),
163        }
164    }
165}
166impl std::fmt::Display for BankConnectionsResourceBalanceType {
167    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
168        f.write_str(self.as_str())
169    }
170}
171
172impl std::fmt::Debug for BankConnectionsResourceBalanceType {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177#[cfg(feature = "serialize")]
178impl serde::Serialize for BankConnectionsResourceBalanceType {
179    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
180    where
181        S: serde::Serializer,
182    {
183        serializer.serialize_str(self.as_str())
184    }
185}
186impl miniserde::Deserialize for BankConnectionsResourceBalanceType {
187    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
188        crate::Place::new(out)
189    }
190}
191
192impl miniserde::de::Visitor for crate::Place<BankConnectionsResourceBalanceType> {
193    fn string(&mut self, s: &str) -> miniserde::Result<()> {
194        use std::str::FromStr;
195        self.out =
196            Some(BankConnectionsResourceBalanceType::from_str(s).map_err(|_| miniserde::Error)?);
197        Ok(())
198    }
199}
200
201stripe_types::impl_from_val_with_from_str!(BankConnectionsResourceBalanceType);
202#[cfg(feature = "deserialize")]
203impl<'de> serde::Deserialize<'de> for BankConnectionsResourceBalanceType {
204    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
205        use std::str::FromStr;
206        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
207        Self::from_str(&s).map_err(|_| {
208            serde::de::Error::custom("Unknown value for BankConnectionsResourceBalanceType")
209        })
210    }
211}