Skip to main content

stripe_shared/
transfer_schedule.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 TransferSchedule {
6    /// The number of days charges for the account will be held before being paid out.
7    pub delay_days: u32,
8    /// How frequently funds will be paid out.
9    /// One of `manual` (payouts only created via API call), `daily`, `weekly`, or `monthly`.
10    pub interval: String,
11    /// The day of the month funds will be paid out.
12    /// Only shown if `interval` is monthly.
13    /// Payouts scheduled between the 29th and 31st of the month are sent on the last day of shorter months.
14    pub monthly_anchor: Option<u8>,
15    /// The days of the month funds will be paid out.
16    /// Only shown if `interval` is monthly.
17    /// Payouts scheduled between the 29th and 31st of the month are sent on the last day of shorter months.
18    pub monthly_payout_days: Option<Vec<u32>>,
19    /// The day of the week funds will be paid out, of the style 'monday', 'tuesday', etc.
20    /// Only shown if `interval` is weekly.
21    pub weekly_anchor: Option<String>,
22    /// The days of the week when available funds are paid out, specified as an array, for example, [`monday`, `tuesday`].
23    /// Only shown if `interval` is weekly.
24    pub weekly_payout_days: Option<Vec<TransferScheduleWeeklyPayoutDays>>,
25}
26#[cfg(feature = "redact-generated-debug")]
27impl std::fmt::Debug for TransferSchedule {
28    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
29        f.debug_struct("TransferSchedule").finish_non_exhaustive()
30    }
31}
32#[doc(hidden)]
33pub struct TransferScheduleBuilder {
34    delay_days: Option<u32>,
35    interval: Option<String>,
36    monthly_anchor: Option<Option<u8>>,
37    monthly_payout_days: Option<Option<Vec<u32>>>,
38    weekly_anchor: Option<Option<String>>,
39    weekly_payout_days: Option<Option<Vec<TransferScheduleWeeklyPayoutDays>>>,
40}
41
42#[allow(
43    unused_variables,
44    irrefutable_let_patterns,
45    clippy::let_unit_value,
46    clippy::match_single_binding,
47    clippy::single_match
48)]
49const _: () = {
50    use miniserde::de::{Map, Visitor};
51    use miniserde::json::Value;
52    use miniserde::{Deserialize, Result, make_place};
53    use stripe_types::miniserde_helpers::FromValueOpt;
54    use stripe_types::{MapBuilder, ObjectDeser};
55
56    make_place!(Place);
57
58    impl Deserialize for TransferSchedule {
59        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
60            Place::new(out)
61        }
62    }
63
64    struct Builder<'a> {
65        out: &'a mut Option<TransferSchedule>,
66        builder: TransferScheduleBuilder,
67    }
68
69    impl Visitor for Place<TransferSchedule> {
70        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
71            Ok(Box::new(Builder {
72                out: &mut self.out,
73                builder: TransferScheduleBuilder::deser_default(),
74            }))
75        }
76    }
77
78    impl MapBuilder for TransferScheduleBuilder {
79        type Out = TransferSchedule;
80        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81            Ok(match k {
82                "delay_days" => Deserialize::begin(&mut self.delay_days),
83                "interval" => Deserialize::begin(&mut self.interval),
84                "monthly_anchor" => Deserialize::begin(&mut self.monthly_anchor),
85                "monthly_payout_days" => Deserialize::begin(&mut self.monthly_payout_days),
86                "weekly_anchor" => Deserialize::begin(&mut self.weekly_anchor),
87                "weekly_payout_days" => Deserialize::begin(&mut self.weekly_payout_days),
88                _ => <dyn Visitor>::ignore(),
89            })
90        }
91
92        fn deser_default() -> Self {
93            Self {
94                delay_days: None,
95                interval: None,
96                monthly_anchor: Some(None),
97                monthly_payout_days: Some(None),
98                weekly_anchor: Some(None),
99                weekly_payout_days: Some(None),
100            }
101        }
102
103        fn take_out(&mut self) -> Option<Self::Out> {
104            let (
105                Some(delay_days),
106                Some(interval),
107                Some(monthly_anchor),
108                Some(monthly_payout_days),
109                Some(weekly_anchor),
110                Some(weekly_payout_days),
111            ) = (
112                self.delay_days,
113                self.interval.take(),
114                self.monthly_anchor,
115                self.monthly_payout_days.take(),
116                self.weekly_anchor.take(),
117                self.weekly_payout_days.take(),
118            )
119            else {
120                return None;
121            };
122            Some(Self::Out {
123                delay_days,
124                interval,
125                monthly_anchor,
126                monthly_payout_days,
127                weekly_anchor,
128                weekly_payout_days,
129            })
130        }
131    }
132
133    impl Map for Builder<'_> {
134        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
135            self.builder.key(k)
136        }
137
138        fn finish(&mut self) -> Result<()> {
139            *self.out = self.builder.take_out();
140            Ok(())
141        }
142    }
143
144    impl ObjectDeser for TransferSchedule {
145        type Builder = TransferScheduleBuilder;
146    }
147
148    impl FromValueOpt for TransferSchedule {
149        fn from_value(v: Value) -> Option<Self> {
150            let Value::Object(obj) = v else {
151                return None;
152            };
153            let mut b = TransferScheduleBuilder::deser_default();
154            for (k, v) in obj {
155                match k.as_str() {
156                    "delay_days" => b.delay_days = FromValueOpt::from_value(v),
157                    "interval" => b.interval = FromValueOpt::from_value(v),
158                    "monthly_anchor" => b.monthly_anchor = FromValueOpt::from_value(v),
159                    "monthly_payout_days" => b.monthly_payout_days = FromValueOpt::from_value(v),
160                    "weekly_anchor" => b.weekly_anchor = FromValueOpt::from_value(v),
161                    "weekly_payout_days" => b.weekly_payout_days = FromValueOpt::from_value(v),
162                    _ => {}
163                }
164            }
165            b.take_out()
166        }
167    }
168};
169/// The days of the week when available funds are paid out, specified as an array, for example, [`monday`, `tuesday`].
170/// Only shown if `interval` is weekly.
171#[derive(Clone, Eq, PartialEq)]
172#[non_exhaustive]
173pub enum TransferScheduleWeeklyPayoutDays {
174    Friday,
175    Monday,
176    Thursday,
177    Tuesday,
178    Wednesday,
179    /// An unrecognized value from Stripe. Should not be used as a request parameter.
180    Unknown(String),
181}
182impl TransferScheduleWeeklyPayoutDays {
183    pub fn as_str(&self) -> &str {
184        use TransferScheduleWeeklyPayoutDays::*;
185        match self {
186            Friday => "friday",
187            Monday => "monday",
188            Thursday => "thursday",
189            Tuesday => "tuesday",
190            Wednesday => "wednesday",
191            Unknown(v) => v,
192        }
193    }
194}
195
196impl std::str::FromStr for TransferScheduleWeeklyPayoutDays {
197    type Err = std::convert::Infallible;
198    fn from_str(s: &str) -> Result<Self, Self::Err> {
199        use TransferScheduleWeeklyPayoutDays::*;
200        match s {
201            "friday" => Ok(Friday),
202            "monday" => Ok(Monday),
203            "thursday" => Ok(Thursday),
204            "tuesday" => Ok(Tuesday),
205            "wednesday" => Ok(Wednesday),
206            v => {
207                tracing::warn!(
208                    "Unknown value '{}' for enum '{}'",
209                    v,
210                    "TransferScheduleWeeklyPayoutDays"
211                );
212                Ok(Unknown(v.to_owned()))
213            }
214        }
215    }
216}
217impl std::fmt::Display for TransferScheduleWeeklyPayoutDays {
218    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
219        f.write_str(self.as_str())
220    }
221}
222
223#[cfg(not(feature = "redact-generated-debug"))]
224impl std::fmt::Debug for TransferScheduleWeeklyPayoutDays {
225    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
226        f.write_str(self.as_str())
227    }
228}
229#[cfg(feature = "redact-generated-debug")]
230impl std::fmt::Debug for TransferScheduleWeeklyPayoutDays {
231    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232        f.debug_struct(stringify!(TransferScheduleWeeklyPayoutDays)).finish_non_exhaustive()
233    }
234}
235#[cfg(feature = "serialize")]
236impl serde::Serialize for TransferScheduleWeeklyPayoutDays {
237    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
238    where
239        S: serde::Serializer,
240    {
241        serializer.serialize_str(self.as_str())
242    }
243}
244impl miniserde::Deserialize for TransferScheduleWeeklyPayoutDays {
245    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
246        crate::Place::new(out)
247    }
248}
249
250impl miniserde::de::Visitor for crate::Place<TransferScheduleWeeklyPayoutDays> {
251    fn string(&mut self, s: &str) -> miniserde::Result<()> {
252        use std::str::FromStr;
253        self.out = Some(TransferScheduleWeeklyPayoutDays::from_str(s).expect("infallible"));
254        Ok(())
255    }
256}
257
258stripe_types::impl_from_val_with_from_str!(TransferScheduleWeeklyPayoutDays);
259#[cfg(feature = "deserialize")]
260impl<'de> serde::Deserialize<'de> for TransferScheduleWeeklyPayoutDays {
261    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
262        use std::str::FromStr;
263        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
264        Ok(Self::from_str(&s).expect("infallible"))
265    }
266}