Skip to main content

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