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