stripe_shared/
subscription_schedule_configuration_item.rs

1/// A phase item describes the price and quantity of a phase.
2#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct SubscriptionScheduleConfigurationItem {
6    /// Define thresholds at which an invoice will be sent, and the related subscription advanced to a new billing period.
7    pub billing_thresholds: Option<stripe_shared::SubscriptionItemBillingThresholds>,
8    /// The discounts applied to the subscription item.
9    /// Subscription item discounts are applied before subscription discounts.
10    /// Use `expand[]=discounts` to expand each discount.
11    pub discounts: Vec<stripe_shared::DiscountsResourceStackableDiscount>,
12    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an item.
13    /// Metadata on this item will update the underlying subscription item's `metadata` when the phase is entered.
14    pub metadata: Option<std::collections::HashMap<String, String>>,
15    /// ID of the plan to which the customer should be subscribed.
16    pub plan: stripe_types::Expandable<stripe_shared::Plan>,
17    /// ID of the price to which the customer should be subscribed.
18    pub price: stripe_types::Expandable<stripe_shared::Price>,
19    /// Quantity of the plan to which the customer should be subscribed.
20    pub quantity: Option<u64>,
21    /// The tax rates which apply to this `phase_item`.
22    /// When set, the `default_tax_rates` on the phase do not apply to this `phase_item`.
23    pub tax_rates: Option<Vec<stripe_shared::TaxRate>>,
24}
25#[doc(hidden)]
26pub struct SubscriptionScheduleConfigurationItemBuilder {
27    billing_thresholds: Option<Option<stripe_shared::SubscriptionItemBillingThresholds>>,
28    discounts: Option<Vec<stripe_shared::DiscountsResourceStackableDiscount>>,
29    metadata: Option<Option<std::collections::HashMap<String, String>>>,
30    plan: Option<stripe_types::Expandable<stripe_shared::Plan>>,
31    price: Option<stripe_types::Expandable<stripe_shared::Price>>,
32    quantity: Option<Option<u64>>,
33    tax_rates: Option<Option<Vec<stripe_shared::TaxRate>>>,
34}
35
36#[allow(
37    unused_variables,
38    irrefutable_let_patterns,
39    clippy::let_unit_value,
40    clippy::match_single_binding,
41    clippy::single_match
42)]
43const _: () = {
44    use miniserde::de::{Map, Visitor};
45    use miniserde::json::Value;
46    use miniserde::{Deserialize, Result, make_place};
47    use stripe_types::miniserde_helpers::FromValueOpt;
48    use stripe_types::{MapBuilder, ObjectDeser};
49
50    make_place!(Place);
51
52    impl Deserialize for SubscriptionScheduleConfigurationItem {
53        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
54            Place::new(out)
55        }
56    }
57
58    struct Builder<'a> {
59        out: &'a mut Option<SubscriptionScheduleConfigurationItem>,
60        builder: SubscriptionScheduleConfigurationItemBuilder,
61    }
62
63    impl Visitor for Place<SubscriptionScheduleConfigurationItem> {
64        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
65            Ok(Box::new(Builder {
66                out: &mut self.out,
67                builder: SubscriptionScheduleConfigurationItemBuilder::deser_default(),
68            }))
69        }
70    }
71
72    impl MapBuilder for SubscriptionScheduleConfigurationItemBuilder {
73        type Out = SubscriptionScheduleConfigurationItem;
74        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
75            Ok(match k {
76                "billing_thresholds" => Deserialize::begin(&mut self.billing_thresholds),
77                "discounts" => Deserialize::begin(&mut self.discounts),
78                "metadata" => Deserialize::begin(&mut self.metadata),
79                "plan" => Deserialize::begin(&mut self.plan),
80                "price" => Deserialize::begin(&mut self.price),
81                "quantity" => Deserialize::begin(&mut self.quantity),
82                "tax_rates" => Deserialize::begin(&mut self.tax_rates),
83
84                _ => <dyn Visitor>::ignore(),
85            })
86        }
87
88        fn deser_default() -> Self {
89            Self {
90                billing_thresholds: Deserialize::default(),
91                discounts: Deserialize::default(),
92                metadata: Deserialize::default(),
93                plan: Deserialize::default(),
94                price: Deserialize::default(),
95                quantity: Deserialize::default(),
96                tax_rates: Deserialize::default(),
97            }
98        }
99
100        fn take_out(&mut self) -> Option<Self::Out> {
101            let (
102                Some(billing_thresholds),
103                Some(discounts),
104                Some(metadata),
105                Some(plan),
106                Some(price),
107                Some(quantity),
108                Some(tax_rates),
109            ) = (
110                self.billing_thresholds,
111                self.discounts.take(),
112                self.metadata.take(),
113                self.plan.take(),
114                self.price.take(),
115                self.quantity,
116                self.tax_rates.take(),
117            )
118            else {
119                return None;
120            };
121            Some(Self::Out {
122                billing_thresholds,
123                discounts,
124                metadata,
125                plan,
126                price,
127                quantity,
128                tax_rates,
129            })
130        }
131    }
132
133    impl Map for Builder<'_> {
134        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
135            self.builder.key(k)
136        }
137
138        fn finish(&mut self) -> Result<()> {
139            *self.out = self.builder.take_out();
140            Ok(())
141        }
142    }
143
144    impl ObjectDeser for SubscriptionScheduleConfigurationItem {
145        type Builder = SubscriptionScheduleConfigurationItemBuilder;
146    }
147
148    impl FromValueOpt for SubscriptionScheduleConfigurationItem {
149        fn from_value(v: Value) -> Option<Self> {
150            let Value::Object(obj) = v else {
151                return None;
152            };
153            let mut b = SubscriptionScheduleConfigurationItemBuilder::deser_default();
154            for (k, v) in obj {
155                match k.as_str() {
156                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
157                    "discounts" => b.discounts = FromValueOpt::from_value(v),
158                    "metadata" => b.metadata = FromValueOpt::from_value(v),
159                    "plan" => b.plan = FromValueOpt::from_value(v),
160                    "price" => b.price = FromValueOpt::from_value(v),
161                    "quantity" => b.quantity = FromValueOpt::from_value(v),
162                    "tax_rates" => b.tax_rates = FromValueOpt::from_value(v),
163
164                    _ => {}
165                }
166            }
167            b.take_out()
168        }
169    }
170};