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                _ => <dyn Visitor>::ignore(),
84            })
85        }
86
87        fn deser_default() -> Self {
88            Self {
89                billing_thresholds: Deserialize::default(),
90                discounts: Deserialize::default(),
91                metadata: Deserialize::default(),
92                plan: Deserialize::default(),
93                price: Deserialize::default(),
94                quantity: Deserialize::default(),
95                tax_rates: Deserialize::default(),
96            }
97        }
98
99        fn take_out(&mut self) -> Option<Self::Out> {
100            let (
101                Some(billing_thresholds),
102                Some(discounts),
103                Some(metadata),
104                Some(plan),
105                Some(price),
106                Some(quantity),
107                Some(tax_rates),
108            ) = (
109                self.billing_thresholds,
110                self.discounts.take(),
111                self.metadata.take(),
112                self.plan.take(),
113                self.price.take(),
114                self.quantity,
115                self.tax_rates.take(),
116            )
117            else {
118                return None;
119            };
120            Some(Self::Out {
121                billing_thresholds,
122                discounts,
123                metadata,
124                plan,
125                price,
126                quantity,
127                tax_rates,
128            })
129        }
130    }
131
132    impl Map for Builder<'_> {
133        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
134            self.builder.key(k)
135        }
136
137        fn finish(&mut self) -> Result<()> {
138            *self.out = self.builder.take_out();
139            Ok(())
140        }
141    }
142
143    impl ObjectDeser for SubscriptionScheduleConfigurationItem {
144        type Builder = SubscriptionScheduleConfigurationItemBuilder;
145    }
146
147    impl FromValueOpt for SubscriptionScheduleConfigurationItem {
148        fn from_value(v: Value) -> Option<Self> {
149            let Value::Object(obj) = v else {
150                return None;
151            };
152            let mut b = SubscriptionScheduleConfigurationItemBuilder::deser_default();
153            for (k, v) in obj {
154                match k.as_str() {
155                    "billing_thresholds" => b.billing_thresholds = FromValueOpt::from_value(v),
156                    "discounts" => b.discounts = FromValueOpt::from_value(v),
157                    "metadata" => b.metadata = FromValueOpt::from_value(v),
158                    "plan" => b.plan = FromValueOpt::from_value(v),
159                    "price" => b.price = FromValueOpt::from_value(v),
160                    "quantity" => b.quantity = FromValueOpt::from_value(v),
161                    "tax_rates" => b.tax_rates = FromValueOpt::from_value(v),
162                    _ => {}
163                }
164            }
165            b.take_out()
166        }
167    }
168};