Skip to main content

stripe_shared/
account_capability_requirements.rs

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