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::{make_place, Deserialize, Result};
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
78                _ => <dyn Visitor>::ignore(),
79            })
80        }
81
82        fn deser_default() -> Self {
83            Self {
84                fees: Deserialize::default(),
85                is_controller: Deserialize::default(),
86                losses: Deserialize::default(),
87                requirement_collection: Deserialize::default(),
88                stripe_dashboard: Deserialize::default(),
89                type_: Deserialize::default(),
90            }
91        }
92
93        fn take_out(&mut self) -> Option<Self::Out> {
94            let (
95                Some(fees),
96                Some(is_controller),
97                Some(losses),
98                Some(requirement_collection),
99                Some(stripe_dashboard),
100                Some(type_),
101            ) = (
102                self.fees,
103                self.is_controller,
104                self.losses,
105                self.requirement_collection,
106                self.stripe_dashboard,
107                self.type_,
108            )
109            else {
110                return None;
111            };
112            Some(Self::Out {
113                fees,
114                is_controller,
115                losses,
116                requirement_collection,
117                stripe_dashboard,
118                type_,
119            })
120        }
121    }
122
123    impl<'a> Map for Builder<'a> {
124        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
125            self.builder.key(k)
126        }
127
128        fn finish(&mut self) -> Result<()> {
129            *self.out = self.builder.take_out();
130            Ok(())
131        }
132    }
133
134    impl ObjectDeser for AccountUnificationAccountController {
135        type Builder = AccountUnificationAccountControllerBuilder;
136    }
137
138    impl FromValueOpt for AccountUnificationAccountController {
139        fn from_value(v: Value) -> Option<Self> {
140            let Value::Object(obj) = v else {
141                return None;
142            };
143            let mut b = AccountUnificationAccountControllerBuilder::deser_default();
144            for (k, v) in obj {
145                match k.as_str() {
146                    "fees" => b.fees = FromValueOpt::from_value(v),
147                    "is_controller" => b.is_controller = FromValueOpt::from_value(v),
148                    "losses" => b.losses = FromValueOpt::from_value(v),
149                    "requirement_collection" => {
150                        b.requirement_collection = FromValueOpt::from_value(v)
151                    }
152                    "stripe_dashboard" => b.stripe_dashboard = FromValueOpt::from_value(v),
153                    "type" => b.type_ = FromValueOpt::from_value(v),
154
155                    _ => {}
156                }
157            }
158            b.take_out()
159        }
160    }
161};
162/// A value indicating responsibility for collecting requirements on this account.
163/// Only returned when the Connect application retrieving the resource controls the account.
164#[derive(Copy, Clone, Eq, PartialEq)]
165pub enum AccountUnificationAccountControllerRequirementCollection {
166    Application,
167    Stripe,
168}
169impl AccountUnificationAccountControllerRequirementCollection {
170    pub fn as_str(self) -> &'static str {
171        use AccountUnificationAccountControllerRequirementCollection::*;
172        match self {
173            Application => "application",
174            Stripe => "stripe",
175        }
176    }
177}
178
179impl std::str::FromStr for AccountUnificationAccountControllerRequirementCollection {
180    type Err = stripe_types::StripeParseError;
181    fn from_str(s: &str) -> Result<Self, Self::Err> {
182        use AccountUnificationAccountControllerRequirementCollection::*;
183        match s {
184            "application" => Ok(Application),
185            "stripe" => Ok(Stripe),
186            _ => Err(stripe_types::StripeParseError),
187        }
188    }
189}
190impl std::fmt::Display for AccountUnificationAccountControllerRequirementCollection {
191    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
192        f.write_str(self.as_str())
193    }
194}
195
196impl std::fmt::Debug for AccountUnificationAccountControllerRequirementCollection {
197    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
198        f.write_str(self.as_str())
199    }
200}
201#[cfg(feature = "serialize")]
202impl serde::Serialize for AccountUnificationAccountControllerRequirementCollection {
203    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
204    where
205        S: serde::Serializer,
206    {
207        serializer.serialize_str(self.as_str())
208    }
209}
210impl miniserde::Deserialize for AccountUnificationAccountControllerRequirementCollection {
211    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
212        crate::Place::new(out)
213    }
214}
215
216impl miniserde::de::Visitor
217    for crate::Place<AccountUnificationAccountControllerRequirementCollection>
218{
219    fn string(&mut self, s: &str) -> miniserde::Result<()> {
220        use std::str::FromStr;
221        self.out = Some(
222            AccountUnificationAccountControllerRequirementCollection::from_str(s)
223                .map_err(|_| miniserde::Error)?,
224        );
225        Ok(())
226    }
227}
228
229stripe_types::impl_from_val_with_from_str!(
230    AccountUnificationAccountControllerRequirementCollection
231);
232#[cfg(feature = "deserialize")]
233impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerRequirementCollection {
234    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
235        use std::str::FromStr;
236        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
237        Self::from_str(&s).map_err(|_| {
238            serde::de::Error::custom(
239                "Unknown value for AccountUnificationAccountControllerRequirementCollection",
240            )
241        })
242    }
243}
244/// The controller type.
245/// Can be `application`, if a Connect application controls the account, or `account`, if the account controls itself.
246#[derive(Copy, Clone, Eq, PartialEq)]
247pub enum AccountUnificationAccountControllerType {
248    Account,
249    Application,
250}
251impl AccountUnificationAccountControllerType {
252    pub fn as_str(self) -> &'static str {
253        use AccountUnificationAccountControllerType::*;
254        match self {
255            Account => "account",
256            Application => "application",
257        }
258    }
259}
260
261impl std::str::FromStr for AccountUnificationAccountControllerType {
262    type Err = stripe_types::StripeParseError;
263    fn from_str(s: &str) -> Result<Self, Self::Err> {
264        use AccountUnificationAccountControllerType::*;
265        match s {
266            "account" => Ok(Account),
267            "application" => Ok(Application),
268            _ => Err(stripe_types::StripeParseError),
269        }
270    }
271}
272impl std::fmt::Display for AccountUnificationAccountControllerType {
273    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274        f.write_str(self.as_str())
275    }
276}
277
278impl std::fmt::Debug for AccountUnificationAccountControllerType {
279    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
280        f.write_str(self.as_str())
281    }
282}
283#[cfg(feature = "serialize")]
284impl serde::Serialize for AccountUnificationAccountControllerType {
285    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
286    where
287        S: serde::Serializer,
288    {
289        serializer.serialize_str(self.as_str())
290    }
291}
292impl miniserde::Deserialize for AccountUnificationAccountControllerType {
293    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
294        crate::Place::new(out)
295    }
296}
297
298impl miniserde::de::Visitor for crate::Place<AccountUnificationAccountControllerType> {
299    fn string(&mut self, s: &str) -> miniserde::Result<()> {
300        use std::str::FromStr;
301        self.out = Some(
302            AccountUnificationAccountControllerType::from_str(s).map_err(|_| miniserde::Error)?,
303        );
304        Ok(())
305    }
306}
307
308stripe_types::impl_from_val_with_from_str!(AccountUnificationAccountControllerType);
309#[cfg(feature = "deserialize")]
310impl<'de> serde::Deserialize<'de> for AccountUnificationAccountControllerType {
311    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
312        use std::str::FromStr;
313        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
314        Self::from_str(&s).map_err(|_| {
315            serde::de::Error::custom("Unknown value for AccountUnificationAccountControllerType")
316        })
317    }
318}