Skip to main content

stripe_shared/
subscriptions_resource_billing_schedules_bill_until.rs

1/// Specifies the end of billing period.
2#[derive(Clone, Eq, PartialEq)]
3#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
4#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
5#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
6pub struct SubscriptionsResourceBillingSchedulesBillUntil {
7    /// The timestamp the billing schedule will apply until.
8    pub computed_timestamp: stripe_types::Timestamp,
9    /// Specifies the billing period.
10    pub duration: Option<stripe_shared::SubscriptionsResourceBillingSchedulesBillUntilDuration>,
11    /// If specified, the billing schedule will apply until the specified timestamp.
12    pub timestamp: Option<stripe_types::Timestamp>,
13    /// Describes how the billing schedule will determine the end date. Either `duration` or `timestamp`.
14    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
15    pub type_: SubscriptionsResourceBillingSchedulesBillUntilType,
16}
17#[cfg(feature = "redact-generated-debug")]
18impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntil {
19    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
20        f.debug_struct("SubscriptionsResourceBillingSchedulesBillUntil").finish_non_exhaustive()
21    }
22}
23#[doc(hidden)]
24pub struct SubscriptionsResourceBillingSchedulesBillUntilBuilder {
25    computed_timestamp: Option<stripe_types::Timestamp>,
26    duration: Option<Option<stripe_shared::SubscriptionsResourceBillingSchedulesBillUntilDuration>>,
27    timestamp: Option<Option<stripe_types::Timestamp>>,
28    type_: Option<SubscriptionsResourceBillingSchedulesBillUntilType>,
29}
30
31#[allow(
32    unused_variables,
33    irrefutable_let_patterns,
34    clippy::let_unit_value,
35    clippy::match_single_binding,
36    clippy::single_match
37)]
38const _: () = {
39    use miniserde::de::{Map, Visitor};
40    use miniserde::json::Value;
41    use miniserde::{Deserialize, Result, make_place};
42    use stripe_types::miniserde_helpers::FromValueOpt;
43    use stripe_types::{MapBuilder, ObjectDeser};
44
45    make_place!(Place);
46
47    impl Deserialize for SubscriptionsResourceBillingSchedulesBillUntil {
48        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
49            Place::new(out)
50        }
51    }
52
53    struct Builder<'a> {
54        out: &'a mut Option<SubscriptionsResourceBillingSchedulesBillUntil>,
55        builder: SubscriptionsResourceBillingSchedulesBillUntilBuilder,
56    }
57
58    impl Visitor for Place<SubscriptionsResourceBillingSchedulesBillUntil> {
59        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
60            Ok(Box::new(Builder {
61                out: &mut self.out,
62                builder: SubscriptionsResourceBillingSchedulesBillUntilBuilder::deser_default(),
63            }))
64        }
65    }
66
67    impl MapBuilder for SubscriptionsResourceBillingSchedulesBillUntilBuilder {
68        type Out = SubscriptionsResourceBillingSchedulesBillUntil;
69        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
70            Ok(match k {
71                "computed_timestamp" => Deserialize::begin(&mut self.computed_timestamp),
72                "duration" => Deserialize::begin(&mut self.duration),
73                "timestamp" => Deserialize::begin(&mut self.timestamp),
74                "type" => Deserialize::begin(&mut self.type_),
75                _ => <dyn Visitor>::ignore(),
76            })
77        }
78
79        fn deser_default() -> Self {
80            Self {
81                computed_timestamp: None,
82                duration: Some(None),
83                timestamp: Some(None),
84                type_: None,
85            }
86        }
87
88        fn take_out(&mut self) -> Option<Self::Out> {
89            let (Some(computed_timestamp), Some(duration), Some(timestamp), Some(type_)) =
90                (self.computed_timestamp, self.duration.take(), self.timestamp, self.type_.take())
91            else {
92                return None;
93            };
94            Some(Self::Out { computed_timestamp, duration, timestamp, type_ })
95        }
96    }
97
98    impl Map for Builder<'_> {
99        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
100            self.builder.key(k)
101        }
102
103        fn finish(&mut self) -> Result<()> {
104            *self.out = self.builder.take_out();
105            Ok(())
106        }
107    }
108
109    impl ObjectDeser for SubscriptionsResourceBillingSchedulesBillUntil {
110        type Builder = SubscriptionsResourceBillingSchedulesBillUntilBuilder;
111    }
112
113    impl FromValueOpt for SubscriptionsResourceBillingSchedulesBillUntil {
114        fn from_value(v: Value) -> Option<Self> {
115            let Value::Object(obj) = v else {
116                return None;
117            };
118            let mut b = SubscriptionsResourceBillingSchedulesBillUntilBuilder::deser_default();
119            for (k, v) in obj {
120                match k.as_str() {
121                    "computed_timestamp" => b.computed_timestamp = FromValueOpt::from_value(v),
122                    "duration" => b.duration = FromValueOpt::from_value(v),
123                    "timestamp" => b.timestamp = FromValueOpt::from_value(v),
124                    "type" => b.type_ = FromValueOpt::from_value(v),
125                    _ => {}
126                }
127            }
128            b.take_out()
129        }
130    }
131};
132/// Describes how the billing schedule will determine the end date. Either `duration` or `timestamp`.
133#[derive(Clone, Eq, PartialEq)]
134#[non_exhaustive]
135pub enum SubscriptionsResourceBillingSchedulesBillUntilType {
136    Duration,
137    Timestamp,
138    /// An unrecognized value from Stripe. Should not be used as a request parameter.
139    Unknown(String),
140}
141impl SubscriptionsResourceBillingSchedulesBillUntilType {
142    pub fn as_str(&self) -> &str {
143        use SubscriptionsResourceBillingSchedulesBillUntilType::*;
144        match self {
145            Duration => "duration",
146            Timestamp => "timestamp",
147            Unknown(v) => v,
148        }
149    }
150}
151
152impl std::str::FromStr for SubscriptionsResourceBillingSchedulesBillUntilType {
153    type Err = std::convert::Infallible;
154    fn from_str(s: &str) -> Result<Self, Self::Err> {
155        use SubscriptionsResourceBillingSchedulesBillUntilType::*;
156        match s {
157            "duration" => Ok(Duration),
158            "timestamp" => Ok(Timestamp),
159            v => {
160                tracing::warn!(
161                    "Unknown value '{}' for enum '{}'",
162                    v,
163                    "SubscriptionsResourceBillingSchedulesBillUntilType"
164                );
165                Ok(Unknown(v.to_owned()))
166            }
167        }
168    }
169}
170impl std::fmt::Display for SubscriptionsResourceBillingSchedulesBillUntilType {
171    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172        f.write_str(self.as_str())
173    }
174}
175
176#[cfg(not(feature = "redact-generated-debug"))]
177impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntilType {
178    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179        f.write_str(self.as_str())
180    }
181}
182#[cfg(feature = "redact-generated-debug")]
183impl std::fmt::Debug for SubscriptionsResourceBillingSchedulesBillUntilType {
184    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185        f.debug_struct(stringify!(SubscriptionsResourceBillingSchedulesBillUntilType))
186            .finish_non_exhaustive()
187    }
188}
189#[cfg(feature = "serialize")]
190impl serde::Serialize for SubscriptionsResourceBillingSchedulesBillUntilType {
191    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
192    where
193        S: serde::Serializer,
194    {
195        serializer.serialize_str(self.as_str())
196    }
197}
198impl miniserde::Deserialize for SubscriptionsResourceBillingSchedulesBillUntilType {
199    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
200        crate::Place::new(out)
201    }
202}
203
204impl miniserde::de::Visitor for crate::Place<SubscriptionsResourceBillingSchedulesBillUntilType> {
205    fn string(&mut self, s: &str) -> miniserde::Result<()> {
206        use std::str::FromStr;
207        self.out = Some(
208            SubscriptionsResourceBillingSchedulesBillUntilType::from_str(s).expect("infallible"),
209        );
210        Ok(())
211    }
212}
213
214stripe_types::impl_from_val_with_from_str!(SubscriptionsResourceBillingSchedulesBillUntilType);
215#[cfg(feature = "deserialize")]
216impl<'de> serde::Deserialize<'de> for SubscriptionsResourceBillingSchedulesBillUntilType {
217    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
218        use std::str::FromStr;
219        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
220        Ok(Self::from_str(&s).expect("infallible"))
221    }
222}