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 pending subscription-level discount that will be applied when the pending update is applied.
12    pub discount: Option<stripe_shared::Discount>,
13    /// The discounts that will be applied to the subscription when the pending update is applied.
14    /// Use `expand[]=discounts` to expand each discount.
15    pub discounts: Option<Vec<stripe_types::Expandable<stripe_shared::Discount>>>,
16    /// The point after which the changes reflected by this update will be discarded and no longer applied.
17    pub expires_at: stripe_types::Timestamp,
18    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
19    /// This can be useful for storing additional information about the object in a structured format.
20    pub metadata: Option<std::collections::HashMap<String, String>>,
21    /// List of subscription items, each with an attached plan, that will be set if the update is applied.
22    pub subscription_items: Option<Vec<stripe_shared::SubscriptionItem>>,
23    /// 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.
24    pub trial_end: Option<stripe_types::Timestamp>,
25    /// Indicates if a plan's `trial_period_days` should be applied to the subscription.
26    /// Setting `trial_end` per subscription is preferred, and this defaults to `false`.
27    /// Setting this flag to `true` together with `trial_end` is not allowed.
28    /// See [Using trial periods on subscriptions](https://docs.stripe.com/billing/subscriptions/trials) to learn more.
29    pub trial_from_plan: Option<bool>,
30}
31#[cfg(feature = "redact-generated-debug")]
32impl std::fmt::Debug for SubscriptionsResourcePendingUpdate {
33    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
34        f.debug_struct("SubscriptionsResourcePendingUpdate").finish_non_exhaustive()
35    }
36}
37#[doc(hidden)]
38pub struct SubscriptionsResourcePendingUpdateBuilder {
39    billing_cycle_anchor: Option<Option<stripe_types::Timestamp>>,
40    discount: Option<Option<stripe_shared::Discount>>,
41    discounts: Option<Option<Vec<stripe_types::Expandable<stripe_shared::Discount>>>>,
42    expires_at: Option<stripe_types::Timestamp>,
43    metadata: Option<Option<std::collections::HashMap<String, String>>>,
44    subscription_items: Option<Option<Vec<stripe_shared::SubscriptionItem>>>,
45    trial_end: Option<Option<stripe_types::Timestamp>>,
46    trial_from_plan: Option<Option<bool>>,
47}
48
49#[allow(
50    unused_variables,
51    irrefutable_let_patterns,
52    clippy::let_unit_value,
53    clippy::match_single_binding,
54    clippy::single_match
55)]
56const _: () = {
57    use miniserde::de::{Map, Visitor};
58    use miniserde::json::Value;
59    use miniserde::{Deserialize, Result, make_place};
60    use stripe_types::miniserde_helpers::FromValueOpt;
61    use stripe_types::{MapBuilder, ObjectDeser};
62
63    make_place!(Place);
64
65    impl Deserialize for SubscriptionsResourcePendingUpdate {
66        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
67            Place::new(out)
68        }
69    }
70
71    struct Builder<'a> {
72        out: &'a mut Option<SubscriptionsResourcePendingUpdate>,
73        builder: SubscriptionsResourcePendingUpdateBuilder,
74    }
75
76    impl Visitor for Place<SubscriptionsResourcePendingUpdate> {
77        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
78            Ok(Box::new(Builder {
79                out: &mut self.out,
80                builder: SubscriptionsResourcePendingUpdateBuilder::deser_default(),
81            }))
82        }
83    }
84
85    impl MapBuilder for SubscriptionsResourcePendingUpdateBuilder {
86        type Out = SubscriptionsResourcePendingUpdate;
87        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
88            Ok(match k {
89                "billing_cycle_anchor" => Deserialize::begin(&mut self.billing_cycle_anchor),
90                "discount" => Deserialize::begin(&mut self.discount),
91                "discounts" => Deserialize::begin(&mut self.discounts),
92                "expires_at" => Deserialize::begin(&mut self.expires_at),
93                "metadata" => Deserialize::begin(&mut self.metadata),
94                "subscription_items" => Deserialize::begin(&mut self.subscription_items),
95                "trial_end" => Deserialize::begin(&mut self.trial_end),
96                "trial_from_plan" => Deserialize::begin(&mut self.trial_from_plan),
97                _ => <dyn Visitor>::ignore(),
98            })
99        }
100
101        fn deser_default() -> Self {
102            Self {
103                billing_cycle_anchor: Some(None),
104                discount: Some(None),
105                discounts: Some(None),
106                expires_at: None,
107                metadata: Some(None),
108                subscription_items: Some(None),
109                trial_end: Some(None),
110                trial_from_plan: Some(None),
111            }
112        }
113
114        fn take_out(&mut self) -> Option<Self::Out> {
115            let (
116                Some(billing_cycle_anchor),
117                Some(discount),
118                Some(discounts),
119                Some(expires_at),
120                Some(metadata),
121                Some(subscription_items),
122                Some(trial_end),
123                Some(trial_from_plan),
124            ) = (
125                self.billing_cycle_anchor,
126                self.discount.take(),
127                self.discounts.take(),
128                self.expires_at,
129                self.metadata.take(),
130                self.subscription_items.take(),
131                self.trial_end,
132                self.trial_from_plan,
133            )
134            else {
135                return None;
136            };
137            Some(Self::Out {
138                billing_cycle_anchor,
139                discount,
140                discounts,
141                expires_at,
142                metadata,
143                subscription_items,
144                trial_end,
145                trial_from_plan,
146            })
147        }
148    }
149
150    impl Map for Builder<'_> {
151        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
152            self.builder.key(k)
153        }
154
155        fn finish(&mut self) -> Result<()> {
156            *self.out = self.builder.take_out();
157            Ok(())
158        }
159    }
160
161    impl ObjectDeser for SubscriptionsResourcePendingUpdate {
162        type Builder = SubscriptionsResourcePendingUpdateBuilder;
163    }
164
165    impl FromValueOpt for SubscriptionsResourcePendingUpdate {
166        fn from_value(v: Value) -> Option<Self> {
167            let Value::Object(obj) = v else {
168                return None;
169            };
170            let mut b = SubscriptionsResourcePendingUpdateBuilder::deser_default();
171            for (k, v) in obj {
172                match k.as_str() {
173                    "billing_cycle_anchor" => b.billing_cycle_anchor = FromValueOpt::from_value(v),
174                    "discount" => b.discount = FromValueOpt::from_value(v),
175                    "discounts" => b.discounts = FromValueOpt::from_value(v),
176                    "expires_at" => b.expires_at = FromValueOpt::from_value(v),
177                    "metadata" => b.metadata = FromValueOpt::from_value(v),
178                    "subscription_items" => b.subscription_items = FromValueOpt::from_value(v),
179                    "trial_end" => b.trial_end = FromValueOpt::from_value(v),
180                    "trial_from_plan" => b.trial_from_plan = FromValueOpt::from_value(v),
181                    _ => {}
182                }
183            }
184            b.take_out()
185        }
186    }
187};