stripe_shared/
account_unification_account_controller.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountUnificationAccountController {
5    pub fees: Option<stripe_shared::AccountUnificationAccountControllerFees>,
6    /// `true` if the Connect application retrieving the resource controls the account and can therefore exercise [platform controls](https://stripe.com/docs/connect/platform-controls-for-standard-accounts).
7    /// Otherwise, this field is null.
8    pub is_controller: Option<bool>,
9    pub losses: Option<stripe_shared::AccountUnificationAccountControllerLosses>,
10    /// A value indicating responsibility for collecting requirements on this account.
11    /// Only returned when the Connect application retrieving the resource controls the account.
12    pub requirement_collection: Option<AccountUnificationAccountControllerRequirementCollection>,
13    pub stripe_dashboard: Option<stripe_shared::AccountUnificationAccountControllerStripeDashboard>,
14    /// The controller type.
15    /// Can be `application`, if a Connect application controls the account, or `account`, if the account controls itself.
16    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
17    pub type_: AccountUnificationAccountControllerType,
18}
19#[doc(hidden)]
20pub struct AccountUnificationAccountControllerBuilder {
21    fees: Option<Option<stripe_shared::AccountUnificationAccountControllerFees>>,
22    is_controller: Option<Option<bool>>,
23    losses: Option<Option<stripe_shared::AccountUnificationAccountControllerLosses>>,
24    requirement_collection:
25        Option<Option<AccountUnificationAccountControllerRequirementCollection>>,
26    stripe_dashboard:
27        Option<Option<stripe_shared::AccountUnificationAccountControllerStripeDashboard>>,
28    type_: Option<AccountUnificationAccountControllerType>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for AccountUnificationAccountController {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<AccountUnificationAccountController>,
55        builder: AccountUnificationAccountControllerBuilder,
56    }
57
58    impl Visitor for Place<AccountUnificationAccountController> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: AccountUnificationAccountControllerBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for AccountUnificationAccountControllerBuilder {
68        type Out = AccountUnificationAccountController;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "fees" => Deserialize::begin(&mut self.fees),
72                "is_controller" => Deserialize::begin(&mut self.is_controller),
73                "losses" => Deserialize::begin(&mut self.losses),
74                "requirement_collection" => Deserialize::begin(&mut self.requirement_collection),
75                "stripe_dashboard" => Deserialize::begin(&mut self.stripe_dashboard),
76                "type" => Deserialize::begin(&mut self.type_),
77                _ => <dyn Visitor>::ignore(),
78            })
79        }
80
81        fn deser_default() -> Self {
82            Self {
83                fees: Deserialize::default(),
84                is_controller: Deserialize::default(),
85                losses: Deserialize::default(),
86                requirement_collection: Deserialize::default(),
87                stripe_dashboard: Deserialize::default(),
88                type_: Deserialize::default(),
89            }
90        }
91
92        fn take_out(&mut self) -> Option<Self::Out> {
93            let (
94                Some(fees),
95                Some(is_controller),
96                Some(losses),
97                Some(requirement_collection),
98                Some(stripe_dashboard),
99                Some(type_),
100            ) = (
101                self.fees.take(),
102                self.is_controller,
103                self.losses.take(),
104                self.requirement_collection.take(),
105                self.stripe_dashboard.take(),
106                self.type_.take(),
107            )
108            else {
109                return None;
110            };
111            Some(Self::Out {
112                fees,
113                is_controller,
114                losses,
115                requirement_collection,
116                stripe_dashboard,
117                type_,
118            })
119        }
120    }
121
122    impl Map for Builder<'_> {
123        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
124            self.builder.key(k)
125        }
126
127        fn finish(&mut self) -> Result<()> {
128            *self.out = self.builder.take_out();
129            Ok(())
130        }
131    }
132
133    impl ObjectDeser for AccountUnificationAccountController {
134        type Builder = AccountUnificationAccountControllerBuilder;
135    }
136
137    impl FromValueOpt for AccountUnificationAccountController {
138        fn from_value(v: Value) -> Option<Self> {
139            let Value::Object(obj) = v else {
140                return None;
141            };
142            let mut b = AccountUnificationAccountControllerBuilder::deser_default();
143            for (k, v) in obj {
144                match k.as_str() {
145                    "fees" => b.fees = FromValueOpt::from_value(v),
146                    "is_controller" => b.is_controller = FromValueOpt::from_value(v),
147                    "losses" => b.losses = FromValueOpt::from_value(v),
148                    "requirement_collection" => {
149                        b.requirement_collection = FromValueOpt::from_value(v)
150                    }
151                    "stripe_dashboard" => b.stripe_dashboard = FromValueOpt::from_value(v),
152                    "type" => b.type_ = FromValueOpt::from_value(v),
153                    _ => {}
154                }
155            }
156            b.take_out()
157        }
158    }
159};
160/// A value indicating responsibility for collecting requirements on this account.
161/// Only returned when the Connect application retrieving the resource controls the account.
162#[derive(Clone, Eq, PartialEq)]
163#[non_exhaustive]
164pub enum AccountUnificationAccountControllerRequirementCollection {
165    Application,
166    Stripe,
167    /// An unrecognized value from Stripe. Should not be used as a request parameter.
168    Unknown(String),
169}
170impl AccountUnificationAccountControllerRequirementCollection {
171    pub fn as_str(&self) -> &str {
172        use AccountUnificationAccountControllerRequirementCollection::*;
173        match self {
174            Application => "application",
175            Stripe => "stripe",
176            Unknown(v) => v,
177        }
178    }
179}
180
181impl std::str::FromStr for AccountUnificationAccountControllerRequirementCollection {
182    type Err = std::convert::Infallible;
183    fn from_str(s: &str) -> Result<Self, Self::Err> {
184        use AccountUnificationAccountControllerRequirementCollection::*;
185        match s {
186            "application" => Ok(Application),
187            "stripe" => Ok(Stripe),
188            v => {
189                tracing::warn!(
190                    "Unknown value '{}' for enum '{}'",
191                    v,
192                    "AccountUnificationAccountControllerRequirementCollection"
193                );
194                Ok(Unknown(v.to_owned()))
195            }
196        }
197    }
198}
199impl std::fmt::Display for AccountUnificationAccountControllerRequirementCollection {
200    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
201        f.write_str(self.as_str())
202    }
203}
204
205impl std::fmt::Debug for AccountUnificationAccountControllerRequirementCollection {
206    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
207        f.write_str(self.as_str())
208    }
209}
210#[cfg(feature = "serialize")]
211impl serde::Serialize for AccountUnificationAccountControllerRequirementCollection {
212    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
213    where
214        S: serde::Serializer,
215    {
216        serializer.serialize_str(self.as_str())
217    }
218}
219impl miniserde::Deserialize for AccountUnificationAccountControllerRequirementCollection {
220    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
221        crate::Place::new(out)
222    }
223}
224
225impl miniserde::de::Visitor
226    for crate::Place<AccountUnificationAccountControllerRequirementCollection>
227{
228    fn string(&mut self, s: &str) -> miniserde::Result<()> {
229        use std::str::FromStr;
230        self.out = Some(
231            AccountUnificationAccountControllerRequirementCollection::from_str(s)
232                .expect("infallible"),
233        );
234        Ok(())
235    }
236}
237
238stripe_types::impl_from_val_with_from_str!(
239    AccountUnificationAccountControllerRequirementCollection
240);
241#[cfg(feature = "deserialize")]
242impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerRequirementCollection {
243    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
244        use std::str::FromStr;
245        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
246        Ok(Self::from_str(&s).expect("infallible"))
247    }
248}
249/// The controller type.
250/// Can be `application`, if a Connect application controls the account, or `account`, if the account controls itself.
251#[derive(Clone, Eq, PartialEq)]
252#[non_exhaustive]
253pub enum AccountUnificationAccountControllerType {
254    Account,
255    Application,
256    /// An unrecognized value from Stripe. Should not be used as a request parameter.
257    Unknown(String),
258}
259impl AccountUnificationAccountControllerType {
260    pub fn as_str(&self) -> &str {
261        use AccountUnificationAccountControllerType::*;
262        match self {
263            Account => "account",
264            Application => "application",
265            Unknown(v) => v,
266        }
267    }
268}
269
270impl std::str::FromStr for AccountUnificationAccountControllerType {
271    type Err = std::convert::Infallible;
272    fn from_str(s: &str) -> Result<Self, Self::Err> {
273        use AccountUnificationAccountControllerType::*;
274        match s {
275            "account" => Ok(Account),
276            "application" => Ok(Application),
277            v => {
278                tracing::warn!(
279                    "Unknown value '{}' for enum '{}'",
280                    v,
281                    "AccountUnificationAccountControllerType"
282                );
283                Ok(Unknown(v.to_owned()))
284            }
285        }
286    }
287}
288impl std::fmt::Display for AccountUnificationAccountControllerType {
289    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
290        f.write_str(self.as_str())
291    }
292}
293
294impl std::fmt::Debug for AccountUnificationAccountControllerType {
295    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
296        f.write_str(self.as_str())
297    }
298}
299#[cfg(feature = "serialize")]
300impl serde::Serialize for AccountUnificationAccountControllerType {
301    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
302    where
303        S: serde::Serializer,
304    {
305        serializer.serialize_str(self.as_str())
306    }
307}
308impl miniserde::Deserialize for AccountUnificationAccountControllerType {
309    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
310        crate::Place::new(out)
311    }
312}
313
314impl miniserde::de::Visitor for crate::Place<AccountUnificationAccountControllerType> {
315    fn string(&mut self, s: &str) -> miniserde::Result<()> {
316        use std::str::FromStr;
317        self.out = Some(AccountUnificationAccountControllerType::from_str(s).expect("infallible"));
318        Ok(())
319    }
320}
321
322stripe_types::impl_from_val_with_from_str!(AccountUnificationAccountControllerType);
323#[cfg(feature = "deserialize")]
324impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerType {
325    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
326        use std::str::FromStr;
327        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
328        Ok(Self::from_str(&s).expect("infallible"))
329    }
330}