stripe_shared/
subscriptions_resource_billing_mode.rs

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