stripe_shared/
account_capability_future_requirements.rs

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