stripe_shared/
subscriptions_resource_billing_mode.rs

1/// The billing mode of the subscription.
2#[derive(Copy, Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct SubscriptionsResourceBillingMode {
6    /// Controls how prorations and invoices for subscriptions are calculated and orchestrated.
7    #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "type"))]
8    pub type_: SubscriptionsResourceBillingModeType,
9    /// Details on when the current billing_mode was adopted.
10    pub updated_at: Option<stripe_types::Timestamp>,
11}
12#[doc(hidden)]
13pub struct SubscriptionsResourceBillingModeBuilder {
14    type_: Option<SubscriptionsResourceBillingModeType>,
15    updated_at: Option<Option<stripe_types::Timestamp>>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{make_place, Deserialize, Result};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for SubscriptionsResourceBillingMode {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<SubscriptionsResourceBillingMode>,
42        builder: SubscriptionsResourceBillingModeBuilder,
43    }
44
45    impl Visitor for Place<SubscriptionsResourceBillingMode> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: SubscriptionsResourceBillingModeBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for SubscriptionsResourceBillingModeBuilder {
55        type Out = SubscriptionsResourceBillingMode;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "type" => Deserialize::begin(&mut self.type_),
59                "updated_at" => Deserialize::begin(&mut self.updated_at),
60
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self { type_: Deserialize::default(), updated_at: Deserialize::default() }
67        }
68
69        fn take_out(&mut self) -> Option<Self::Out> {
70            let (Some(type_), Some(updated_at)) = (self.type_, self.updated_at) else {
71                return None;
72            };
73            Some(Self::Out { type_, updated_at })
74        }
75    }
76
77    impl Map for Builder<'_> {
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            self.builder.key(k)
80        }
81
82        fn finish(&mut self) -> Result<()> {
83            *self.out = self.builder.take_out();
84            Ok(())
85        }
86    }
87
88    impl ObjectDeser for SubscriptionsResourceBillingMode {
89        type Builder = SubscriptionsResourceBillingModeBuilder;
90    }
91
92    impl FromValueOpt for SubscriptionsResourceBillingMode {
93        fn from_value(v: Value) -> Option<Self> {
94            let Value::Object(obj) = v else {
95                return None;
96            };
97            let mut b = SubscriptionsResourceBillingModeBuilder::deser_default();
98            for (k, v) in obj {
99                match k.as_str() {
100                    "type" => b.type_ = FromValueOpt::from_value(v),
101                    "updated_at" => b.updated_at = FromValueOpt::from_value(v),
102
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};
110/// Controls how prorations and invoices for subscriptions are calculated and orchestrated.
111#[derive(Copy, Clone, Eq, PartialEq)]
112pub enum SubscriptionsResourceBillingModeType {
113    Classic,
114    Flexible,
115}
116impl SubscriptionsResourceBillingModeType {
117    pub fn as_str(self) -> &'static str {
118        use SubscriptionsResourceBillingModeType::*;
119        match self {
120            Classic => "classic",
121            Flexible => "flexible",
122        }
123    }
124}
125
126impl std::str::FromStr for SubscriptionsResourceBillingModeType {
127    type Err = stripe_types::StripeParseError;
128    fn from_str(s: &str) -> Result<Self, Self::Err> {
129        use SubscriptionsResourceBillingModeType::*;
130        match s {
131            "classic" => Ok(Classic),
132            "flexible" => Ok(Flexible),
133            _ => Err(stripe_types::StripeParseError),
134        }
135    }
136}
137impl std::fmt::Display for SubscriptionsResourceBillingModeType {
138    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139        f.write_str(self.as_str())
140    }
141}
142
143impl std::fmt::Debug for SubscriptionsResourceBillingModeType {
144    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148#[cfg(feature = "serialize")]
149impl serde::Serialize for SubscriptionsResourceBillingModeType {
150    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
151    where
152        S: serde::Serializer,
153    {
154        serializer.serialize_str(self.as_str())
155    }
156}
157impl miniserde::Deserialize for SubscriptionsResourceBillingModeType {
158    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
159        crate::Place::new(out)
160    }
161}
162
163impl miniserde::de::Visitor for crate::Place<SubscriptionsResourceBillingModeType> {
164    fn string(&mut self, s: &str) -> miniserde::Result<()> {
165        use std::str::FromStr;
166        self.out =
167            Some(SubscriptionsResourceBillingModeType::from_str(s).map_err(|_| miniserde::Error)?);
168        Ok(())
169    }
170}
171
172stripe_types::impl_from_val_with_from_str!(SubscriptionsResourceBillingModeType);
173#[cfg(feature = "deserialize")]
174impl<'de> serde::Deserialize<'de> for SubscriptionsResourceBillingModeType {
175    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
176        use std::str::FromStr;
177        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
178        Self::from_str(&s).map_err(|_| {
179            serde::de::Error::custom("Unknown value for SubscriptionsResourceBillingModeType")
180        })
181    }
182}