stripe_shared/
account_capability_requirements.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountCapabilityRequirements {
5    /// Fields that are due and can be resolved by providing the corresponding alternative fields instead.
6    /// Multiple alternatives can reference the same `original_fields_due`.
7    /// When this happens, any of these alternatives can serve as a pathway for attempting to resolve the fields.
8    /// Additionally, providing `original_fields_due` again also serves as a pathway for attempting to resolve the fields.
9    pub alternatives: Option<Vec<stripe_shared::AccountRequirementsAlternative>>,
10    /// The date by which all required account information must be both submitted and verified.
11    /// This includes fields listed in `currently_due` as well as those in `pending_verification`.
12    /// If any required information is missing or unverified by this date, the account may be disabled.
13    /// Note that `current_deadline` may change if additional `currently_due` requirements are requested.
14    pub current_deadline: Option<stripe_types::Timestamp>,
15    /// Fields that need to be resolved to keep the capability enabled.
16    /// If not resolved by `current_deadline`, these fields will appear in `past_due` as well, and the capability is disabled.
17    pub currently_due: Vec<String>,
18    /// Description of why the capability is disabled.
19    /// [Learn more about handling verification issues](https://docs.stripe.com/connect/handling-api-verification).
20    pub disabled_reason: Option<AccountCapabilityRequirementsDisabledReason>,
21    /// Details about validation and verification failures for `due` requirements that must be resolved.
22    pub errors: Vec<stripe_shared::AccountRequirementsError>,
23    /// Fields you must collect when all thresholds are reached.
24    /// As they become required, they appear in `currently_due` as well, and `current_deadline` becomes set.
25    pub eventually_due: Vec<String>,
26    /// Fields that haven't been resolved by `current_deadline`.
27    /// These fields need to be resolved to enable the capability on the account.
28    pub past_due: Vec<String>,
29    /// Fields that are being reviewed, or might become required depending on the results of a review.
30    /// If the review fails, these fields can move to `eventually_due`, `currently_due`, `past_due` or `alternatives`.
31    /// Fields might appear in `eventually_due`, `currently_due`, `past_due` or `alternatives` and in `pending_verification` if one verification fails but another is still pending.
32    pub pending_verification: Vec<String>,
33}
34#[doc(hidden)]
35pub struct AccountCapabilityRequirementsBuilder {
36    alternatives: Option<Option<Vec<stripe_shared::AccountRequirementsAlternative>>>,
37    current_deadline: Option<Option<stripe_types::Timestamp>>,
38    currently_due: Option<Vec<String>>,
39    disabled_reason: Option<Option<AccountCapabilityRequirementsDisabledReason>>,
40    errors: Option<Vec<stripe_shared::AccountRequirementsError>>,
41    eventually_due: Option<Vec<String>>,
42    past_due: Option<Vec<String>>,
43    pending_verification: Option<Vec<String>>,
44}
45
46#[allow(
47    unused_variables,
48    irrefutable_let_patterns,
49    clippy::let_unit_value,
50    clippy::match_single_binding,
51    clippy::single_match
52)]
53const _: () = {
54    use miniserde::de::{Map, Visitor};
55    use miniserde::json::Value;
56    use miniserde::{Deserialize, Result, make_place};
57    use stripe_types::miniserde_helpers::FromValueOpt;
58    use stripe_types::{MapBuilder, ObjectDeser};
59
60    make_place!(Place);
61
62    impl Deserialize for AccountCapabilityRequirements {
63        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
64            Place::new(out)
65        }
66    }
67
68    struct Builder<'a> {
69        out: &'a mut Option<AccountCapabilityRequirements>,
70        builder: AccountCapabilityRequirementsBuilder,
71    }
72
73    impl Visitor for Place<AccountCapabilityRequirements> {
74        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
75            Ok(Box::new(Builder {
76                out: &mut self.out,
77                builder: AccountCapabilityRequirementsBuilder::deser_default(),
78            }))
79        }
80    }
81
82    impl MapBuilder for AccountCapabilityRequirementsBuilder {
83        type Out = AccountCapabilityRequirements;
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            Ok(match k {
86                "alternatives" => Deserialize::begin(&mut self.alternatives),
87                "current_deadline" => Deserialize::begin(&mut self.current_deadline),
88                "currently_due" => Deserialize::begin(&mut self.currently_due),
89                "disabled_reason" => Deserialize::begin(&mut self.disabled_reason),
90                "errors" => Deserialize::begin(&mut self.errors),
91                "eventually_due" => Deserialize::begin(&mut self.eventually_due),
92                "past_due" => Deserialize::begin(&mut self.past_due),
93                "pending_verification" => Deserialize::begin(&mut self.pending_verification),
94                _ => <dyn Visitor>::ignore(),
95            })
96        }
97
98        fn deser_default() -> Self {
99            Self {
100                alternatives: Deserialize::default(),
101                current_deadline: Deserialize::default(),
102                currently_due: Deserialize::default(),
103                disabled_reason: Deserialize::default(),
104                errors: Deserialize::default(),
105                eventually_due: Deserialize::default(),
106                past_due: Deserialize::default(),
107                pending_verification: Deserialize::default(),
108            }
109        }
110
111        fn take_out(&mut self) -> Option<Self::Out> {
112            let (
113                Some(alternatives),
114                Some(current_deadline),
115                Some(currently_due),
116                Some(disabled_reason),
117                Some(errors),
118                Some(eventually_due),
119                Some(past_due),
120                Some(pending_verification),
121            ) = (
122                self.alternatives.take(),
123                self.current_deadline,
124                self.currently_due.take(),
125                self.disabled_reason.take(),
126                self.errors.take(),
127                self.eventually_due.take(),
128                self.past_due.take(),
129                self.pending_verification.take(),
130            )
131            else {
132                return None;
133            };
134            Some(Self::Out {
135                alternatives,
136                current_deadline,
137                currently_due,
138                disabled_reason,
139                errors,
140                eventually_due,
141                past_due,
142                pending_verification,
143            })
144        }
145    }
146
147    impl Map for Builder<'_> {
148        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
149            self.builder.key(k)
150        }
151
152        fn finish(&mut self) -> Result<()> {
153            *self.out = self.builder.take_out();
154            Ok(())
155        }
156    }
157
158    impl ObjectDeser for AccountCapabilityRequirements {
159        type Builder = AccountCapabilityRequirementsBuilder;
160    }
161
162    impl FromValueOpt for AccountCapabilityRequirements {
163        fn from_value(v: Value) -> Option<Self> {
164            let Value::Object(obj) = v else {
165                return None;
166            };
167            let mut b = AccountCapabilityRequirementsBuilder::deser_default();
168            for (k, v) in obj {
169                match k.as_str() {
170                    "alternatives" => b.alternatives = FromValueOpt::from_value(v),
171                    "current_deadline" => b.current_deadline = FromValueOpt::from_value(v),
172                    "currently_due" => b.currently_due = FromValueOpt::from_value(v),
173                    "disabled_reason" => b.disabled_reason = FromValueOpt::from_value(v),
174                    "errors" => b.errors = FromValueOpt::from_value(v),
175                    "eventually_due" => b.eventually_due = FromValueOpt::from_value(v),
176                    "past_due" => b.past_due = FromValueOpt::from_value(v),
177                    "pending_verification" => b.pending_verification = FromValueOpt::from_value(v),
178                    _ => {}
179                }
180            }
181            b.take_out()
182        }
183    }
184};
185/// Description of why the capability is disabled.
186/// [Learn more about handling verification issues](https://docs.stripe.com/connect/handling-api-verification).
187#[derive(Clone, Eq, PartialEq)]
188#[non_exhaustive]
189pub enum AccountCapabilityRequirementsDisabledReason {
190    Other,
191    PausedInactivity,
192    PendingOnboarding,
193    PendingReview,
194    PlatformDisabled,
195    PlatformPaused,
196    RejectedInactivity,
197    RejectedOther,
198    RejectedUnsupportedBusiness,
199    RequirementsFieldsNeeded,
200    /// An unrecognized value from Stripe. Should not be used as a request parameter.
201    Unknown(String),
202}
203impl AccountCapabilityRequirementsDisabledReason {
204    pub fn as_str(&self) -> &str {
205        use AccountCapabilityRequirementsDisabledReason::*;
206        match self {
207            Other => "other",
208            PausedInactivity => "paused.inactivity",
209            PendingOnboarding => "pending.onboarding",
210            PendingReview => "pending.review",
211            PlatformDisabled => "platform_disabled",
212            PlatformPaused => "platform_paused",
213            RejectedInactivity => "rejected.inactivity",
214            RejectedOther => "rejected.other",
215            RejectedUnsupportedBusiness => "rejected.unsupported_business",
216            RequirementsFieldsNeeded => "requirements.fields_needed",
217            Unknown(v) => v,
218        }
219    }
220}
221
222impl std::str::FromStr for AccountCapabilityRequirementsDisabledReason {
223    type Err = std::convert::Infallible;
224    fn from_str(s: &str) -> Result<Self, Self::Err> {
225        use AccountCapabilityRequirementsDisabledReason::*;
226        match s {
227            "other" => Ok(Other),
228            "paused.inactivity" => Ok(PausedInactivity),
229            "pending.onboarding" => Ok(PendingOnboarding),
230            "pending.review" => Ok(PendingReview),
231            "platform_disabled" => Ok(PlatformDisabled),
232            "platform_paused" => Ok(PlatformPaused),
233            "rejected.inactivity" => Ok(RejectedInactivity),
234            "rejected.other" => Ok(RejectedOther),
235            "rejected.unsupported_business" => Ok(RejectedUnsupportedBusiness),
236            "requirements.fields_needed" => Ok(RequirementsFieldsNeeded),
237            v => {
238                tracing::warn!(
239                    "Unknown value '{}' for enum '{}'",
240                    v,
241                    "AccountCapabilityRequirementsDisabledReason"
242                );
243                Ok(Unknown(v.to_owned()))
244            }
245        }
246    }
247}
248impl std::fmt::Display for AccountCapabilityRequirementsDisabledReason {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        f.write_str(self.as_str())
251    }
252}
253
254impl std::fmt::Debug for AccountCapabilityRequirementsDisabledReason {
255    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
256        f.write_str(self.as_str())
257    }
258}
259#[cfg(feature = "serialize")]
260impl serde::Serialize for AccountCapabilityRequirementsDisabledReason {
261    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
262    where
263        S: serde::Serializer,
264    {
265        serializer.serialize_str(self.as_str())
266    }
267}
268impl miniserde::Deserialize for AccountCapabilityRequirementsDisabledReason {
269    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
270        crate::Place::new(out)
271    }
272}
273
274impl miniserde::de::Visitor for crate::Place<AccountCapabilityRequirementsDisabledReason> {
275    fn string(&mut self, s: &str) -> miniserde::Result<()> {
276        use std::str::FromStr;
277        self.out =
278            Some(AccountCapabilityRequirementsDisabledReason::from_str(s).expect("infallible"));
279        Ok(())
280    }
281}
282
283stripe_types::impl_from_val_with_from_str!(AccountCapabilityRequirementsDisabledReason);
284#[cfg(feature = "deserialize")]
285impl<'de> serde::Deserialize<'de> for AccountCapabilityRequirementsDisabledReason {
286    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
287        use std::str::FromStr;
288        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
289        Ok(Self::from_str(&s).expect("infallible"))
290    }
291}