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                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self {
68                amount_gte: Deserialize::default(),
69                reset_billing_cycle_anchor: Deserialize::default(),
70            }
71        }
72
73        fn take_out(&mut self) -> Option<Self::Out> {
74            let (Some(amount_gte), Some(reset_billing_cycle_anchor)) =
75                (self.amount_gte, self.reset_billing_cycle_anchor)
76            else {
77                return None;
78            };
79            Some(Self::Out { amount_gte, reset_billing_cycle_anchor })
80        }
81    }
82
83    impl Map for Builder<'_> {
84        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
85            self.builder.key(k)
86        }
87
88        fn finish(&mut self) -> Result<()> {
89            *self.out = self.builder.take_out();
90            Ok(())
91        }
92    }
93
94    impl ObjectDeser for SubscriptionBillingThresholds {
95        type Builder = SubscriptionBillingThresholdsBuilder;
96    }
97
98    impl FromValueOpt for SubscriptionBillingThresholds {
99        fn from_value(v: Value) -> Option<Self> {
100            let Value::Object(obj) = v else {
101                return None;
102            };
103            let mut b = SubscriptionBillingThresholdsBuilder::deser_default();
104            for (k, v) in obj {
105                match k.as_str() {
106                    "amount_gte" => b.amount_gte = FromValueOpt::from_value(v),
107                    "reset_billing_cycle_anchor" => {
108                        b.reset_billing_cycle_anchor = FromValueOpt::from_value(v)
109                    }
110                    _ => {}
111                }
112            }
113            b.take_out()
114        }
115    }
116};