stripe_shared/
subscription_billing_thresholds.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SubscriptionBillingThresholds {
5    /// Monetary threshold that triggers the subscription to create an invoice
6    pub amount_gte: Option<i64>,
7    /// Indicates if the `billing_cycle_anchor` should be reset when a threshold is reached.
8    /// If true, `billing_cycle_anchor` will be updated to the date/time the threshold was last reached; otherwise, the value will remain unchanged.
9    /// This value may not be `true` if the subscription contains items with plans that have `aggregate_usage=last_ever`.
10    pub reset_billing_cycle_anchor: Option<bool>,
11}
12#[doc(hidden)]
13pub struct SubscriptionBillingThresholdsBuilder {
14    amount_gte: Option<Option<i64>>,
15    reset_billing_cycle_anchor: Option<Option<bool>>,
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::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for SubscriptionBillingThresholds {
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<SubscriptionBillingThresholds>,
42        builder: SubscriptionBillingThresholdsBuilder,
43    }
44
45    impl Visitor for Place<SubscriptionBillingThresholds> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: SubscriptionBillingThresholdsBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for SubscriptionBillingThresholdsBuilder {
55        type Out = SubscriptionBillingThresholds;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "amount_gte" => Deserialize::begin(&mut self.amount_gte),
59                "reset_billing_cycle_anchor" => {
60                    Deserialize::begin(&mut self.reset_billing_cycle_anchor)
61                }
62
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self {
69                amount_gte: Deserialize::default(),
70                reset_billing_cycle_anchor: Deserialize::default(),
71            }
72        }
73
74        fn take_out(&mut self) -> Option<Self::Out> {
75            let (Some(amount_gte), Some(reset_billing_cycle_anchor)) =
76                (self.amount_gte, self.reset_billing_cycle_anchor)
77            else {
78                return None;
79            };
80            Some(Self::Out { amount_gte, reset_billing_cycle_anchor })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for SubscriptionBillingThresholds {
96        type Builder = SubscriptionBillingThresholdsBuilder;
97    }
98
99    impl FromValueOpt for SubscriptionBillingThresholds {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = SubscriptionBillingThresholdsBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "amount_gte" => b.amount_gte = FromValueOpt::from_value(v),
108                    "reset_billing_cycle_anchor" => {
109                        b.reset_billing_cycle_anchor = FromValueOpt::from_value(v)
110                    }
111
112                    _ => {}
113                }
114            }
115            b.take_out()
116        }
117    }
118};