stripe_shared/
account_unification_account_controller.rs

1#[derive(Copy, 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,
102                self.is_controller,
103                self.losses,
104                self.requirement_collection,
105                self.stripe_dashboard,
106                self.type_,
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(Copy, Clone, Eq, PartialEq)]
163pub enum AccountUnificationAccountControllerRequirementCollection {
164    Application,
165    Stripe,
166}
167impl AccountUnificationAccountControllerRequirementCollection {
168    pub fn as_str(self) -> &'static str {
169        use AccountUnificationAccountControllerRequirementCollection::*;
170        match self {
171            Application => "application",
172            Stripe => "stripe",
173        }
174    }
175}
176
177impl std::str::FromStr for AccountUnificationAccountControllerRequirementCollection {
178    type Err = stripe_types::StripeParseError;
179    fn from_str(s: &str) -> Result<Self, Self::Err> {
180        use AccountUnificationAccountControllerRequirementCollection::*;
181        match s {
182            "application" => Ok(Application),
183            "stripe" => Ok(Stripe),
184            _ => Err(stripe_types::StripeParseError),
185        }
186    }
187}
188impl std::fmt::Display for AccountUnificationAccountControllerRequirementCollection {
189    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
190        f.write_str(self.as_str())
191    }
192}
193
194impl std::fmt::Debug for AccountUnificationAccountControllerRequirementCollection {
195    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
196        f.write_str(self.as_str())
197    }
198}
199#[cfg(feature = "serialize")]
200impl serde::Serialize for AccountUnificationAccountControllerRequirementCollection {
201    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
202    where
203        S: serde::Serializer,
204    {
205        serializer.serialize_str(self.as_str())
206    }
207}
208impl miniserde::Deserialize for AccountUnificationAccountControllerRequirementCollection {
209    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
210        crate::Place::new(out)
211    }
212}
213
214impl miniserde::de::Visitor
215    for crate::Place<AccountUnificationAccountControllerRequirementCollection>
216{
217    fn string(&mut self, s: &str) -> miniserde::Result<()> {
218        use std::str::FromStr;
219        self.out = Some(
220            AccountUnificationAccountControllerRequirementCollection::from_str(s)
221                .map_err(|_| miniserde::Error)?,
222        );
223        Ok(())
224    }
225}
226
227stripe_types::impl_from_val_with_from_str!(
228    AccountUnificationAccountControllerRequirementCollection
229);
230#[cfg(feature = "deserialize")]
231impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerRequirementCollection {
232    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
233        use std::str::FromStr;
234        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
235        Self::from_str(&s).map_err(|_| {
236            serde::de::Error::custom(
237                "Unknown value for AccountUnificationAccountControllerRequirementCollection",
238            )
239        })
240    }
241}
242/// The controller type.
243/// Can be `application`, if a Connect application controls the account, or `account`, if the account controls itself.
244#[derive(Copy, Clone, Eq, PartialEq)]
245pub enum AccountUnificationAccountControllerType {
246    Account,
247    Application,
248}
249impl AccountUnificationAccountControllerType {
250    pub fn as_str(self) -> &'static str {
251        use AccountUnificationAccountControllerType::*;
252        match self {
253            Account => "account",
254            Application => "application",
255        }
256    }
257}
258
259impl std::str::FromStr for AccountUnificationAccountControllerType {
260    type Err = stripe_types::StripeParseError;
261    fn from_str(s: &str) -> Result<Self, Self::Err> {
262        use AccountUnificationAccountControllerType::*;
263        match s {
264            "account" => Ok(Account),
265            "application" => Ok(Application),
266            _ => Err(stripe_types::StripeParseError),
267        }
268    }
269}
270impl std::fmt::Display for AccountUnificationAccountControllerType {
271    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
272        f.write_str(self.as_str())
273    }
274}
275
276impl std::fmt::Debug for AccountUnificationAccountControllerType {
277    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
278        f.write_str(self.as_str())
279    }
280}
281#[cfg(feature = "serialize")]
282impl serde::Serialize for AccountUnificationAccountControllerType {
283    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
284    where
285        S: serde::Serializer,
286    {
287        serializer.serialize_str(self.as_str())
288    }
289}
290impl miniserde::Deserialize for AccountUnificationAccountControllerType {
291    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
292        crate::Place::new(out)
293    }
294}
295
296impl miniserde::de::Visitor for crate::Place<AccountUnificationAccountControllerType> {
297    fn string(&mut self, s: &str) -> miniserde::Result<()> {
298        use std::str::FromStr;
299        self.out = Some(
300            AccountUnificationAccountControllerType::from_str(s).map_err(|_| miniserde::Error)?,
301        );
302        Ok(())
303    }
304}
305
306stripe_types::impl_from_val_with_from_str!(AccountUnificationAccountControllerType);
307#[cfg(feature = "deserialize")]
308impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerType {
309    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
310        use std::str::FromStr;
311        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
312        Self::from_str(&s).map_err(|_| {
313            serde::de::Error::custom("Unknown value for AccountUnificationAccountControllerType")
314        })
315    }
316}