Skip to main content

stripe_shared/
subscription_schedule_add_invoice_item.rs

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