Skip to main content

stripe_shared/
subscriptions_resource_pending_update.rs

1/// Pending Updates store the changes pending from a previous update that will be applied
2/// to the Subscription upon successful payment.
3#[derive(Clone)]
4#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
5#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
6#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
7pub struct SubscriptionsResourcePendingUpdate {
8    /// If the update is applied, determines the date of the first full invoice, and, for plans with `month` or `year` intervals, the day of the month for subsequent invoices.
9    /// The timestamp is in UTC format.
10    pub billing_cycle_anchor: Option<stripe_types::Timestamp>,
11    /// The point after which the changes reflected by this update will be discarded and no longer applied.
12    pub expires_at: stripe_types::Timestamp,
13    /// List of subscription items, each with an attached plan, that will be set if the update is applied.
14    pub subscription_items: Option<Vec<stripe_shared::SubscriptionItem>>,
15    /// Unix timestamp representing the end of the trial period the customer will get before being charged for the first time, if the update is applied.
16    pub trial_end: Option<stripe_types::Timestamp>,
17    /// Indicates if a plan's `trial_period_days` should be applied to the subscription.
18    /// Setting `trial_end` per subscription is preferred, and this defaults to `false`.
19    /// Setting this flag to `true` together with `trial_end` is not allowed.
20    /// See [Using trial periods on subscriptions](https://docs.stripe.com/billing/subscriptions/trials) to learn more.
21    pub trial_from_plan: Option<bool>,
22}
23#[cfg(feature = "redact-generated-debug")]
24impl std::fmt::Debug for SubscriptionsResourcePendingUpdate {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        f.debug_struct("SubscriptionsResourcePendingUpdate").finish_non_exhaustive()
27    }
28}
29#[doc(hidden)]
30pub struct SubscriptionsResourcePendingUpdateBuilder {
31    billing_cycle_anchor: Option<Option<stripe_types::Timestamp>>,
32    expires_at: Option<stripe_types::Timestamp>,
33    subscription_items: Option<Option<Vec<stripe_shared::SubscriptionItem>>>,
34    trial_end: Option<Option<stripe_types::Timestamp>>,
35    trial_from_plan: Option<Option<bool>>,
36}
37
38#[allow(
39    unused_variables,
40    irrefutable_let_patterns,
41    clippy::let_unit_value,
42    clippy::match_single_binding,
43    clippy::single_match
44)]
45const _: () = {
46    use miniserde::de::{Map, Visitor};
47    use miniserde::json::Value;
48    use miniserde::{Deserialize, Result, make_place};
49    use stripe_types::miniserde_helpers::FromValueOpt;
50    use stripe_types::{MapBuilder, ObjectDeser};
51
52    make_place!(Place);
53
54    impl Deserialize for SubscriptionsResourcePendingUpdate {
55        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
56            Place::new(out)
57        }
58    }
59
60    struct Builder<'a> {
61        out: &'a mut Option<SubscriptionsResourcePendingUpdate>,
62        builder: SubscriptionsResourcePendingUpdateBuilder,
63    }
64
65    impl Visitor for Place<SubscriptionsResourcePendingUpdate> {
66        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
67            Ok(Box::new(Builder {
68                out: &mut self.out,
69                builder: SubscriptionsResourcePendingUpdateBuilder::deser_default(),
70            }))
71        }
72    }
73
74    impl MapBuilder for SubscriptionsResourcePendingUpdateBuilder {
75        type Out = SubscriptionsResourcePendingUpdate;
76        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
77            Ok(match k {
78                "billing_cycle_anchor" => Deserialize::begin(&mut self.billing_cycle_anchor),
79                "expires_at" => Deserialize::begin(&mut self.expires_at),
80                "subscription_items" => Deserialize::begin(&mut self.subscription_items),
81                "trial_end" => Deserialize::begin(&mut self.trial_end),
82                "trial_from_plan" => Deserialize::begin(&mut self.trial_from_plan),
83                _ => <dyn Visitor>::ignore(),
84            })
85        }
86
87        fn deser_default() -> Self {
88            Self {
89                billing_cycle_anchor: Some(None),
90                expires_at: None,
91                subscription_items: Some(None),
92                trial_end: Some(None),
93                trial_from_plan: Some(None),
94            }
95        }
96
97        fn take_out(&mut self) -> Option<Self::Out> {
98            let (
99                Some(billing_cycle_anchor),
100                Some(expires_at),
101                Some(subscription_items),
102                Some(trial_end),
103                Some(trial_from_plan),
104            ) = (
105                self.billing_cycle_anchor,
106                self.expires_at,
107                self.subscription_items.take(),
108                self.trial_end,
109                self.trial_from_plan,
110            )
111            else {
112                return None;
113            };
114            Some(Self::Out {
115                billing_cycle_anchor,
116                expires_at,
117                subscription_items,
118                trial_end,
119                trial_from_plan,
120            })
121        }
122    }
123
124    impl Map for Builder<'_> {
125        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
126            self.builder.key(k)
127        }
128
129        fn finish(&mut self) -> Result<()> {
130            *self.out = self.builder.take_out();
131            Ok(())
132        }
133    }
134
135    impl ObjectDeser for SubscriptionsResourcePendingUpdate {
136        type Builder = SubscriptionsResourcePendingUpdateBuilder;
137    }
138
139    impl FromValueOpt for SubscriptionsResourcePendingUpdate {
140        fn from_value(v: Value) -> Option<Self> {
141            let Value::Object(obj) = v else {
142                return None;
143            };
144            let mut b = SubscriptionsResourcePendingUpdateBuilder::deser_default();
145            for (k, v) in obj {
146                match k.as_str() {
147                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
148                    "expires_at" => b.expires_at = FromValueOpt::from_value(v),
149                    "subscription_items" => b.subscription_items = FromValueOpt::from_value(v),
150                    "trial_end" => b.trial_end = FromValueOpt::from_value(v),
151                    "trial_from_plan" => b.trial_from_plan = FromValueOpt::from_value(v),
152                    _ => {}
153                }
154            }
155            b.take_out()
156        }
157    }
158};