stripe_shared/
payment_intent_amount_details_line_item.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
3pub struct PaymentIntentAmountDetailsLineItem {
4        /// The discount applied on this line item represented in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
5    /// An integer greater than 0.
6    ///
7    /// This field is mutually exclusive with the `amount_details[discount_amount]` field.
8pub discount_amount: Option<i64>,
9    /// Unique identifier for the object.
10pub id: stripe_shared::PaymentIntentAmountDetailsLineItemId,
11    /// Payment method-specific information for line items.
12pub payment_method_options: Option<stripe_shared::PaymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourcePaymentMethodOptions>,
13        /// The product code of the line item, such as an SKU.
14    /// Required for L3 rates.
15    /// At most 12 characters long.
16pub product_code: Option<String>,
17    /// The product name of the line item. Required for L3 rates. At most 1024 characters long.
18    ///
19        /// For Cards, this field is truncated to 26 alphanumeric characters before being sent to the card networks.
20    /// For Paypal, this field is truncated to 127 characters.
21pub product_name: String,
22    /// The quantity of items. Required for L3 rates. An integer greater than 0.
23pub quantity: u64,
24    /// Contains information about the tax on the item.
25pub tax: Option<stripe_shared::PaymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourceTax>,
26        /// The unit cost of the line item represented in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
27    /// Required for L3 rates.
28    /// An integer greater than or equal to 0.
29pub unit_cost: i64,
30        /// A unit of measure for the line item, such as gallons, feet, meters, etc.
31    /// Required for L3 rates.
32    /// At most 12 alphanumeric characters long.
33pub unit_of_measure: Option<String>,
34
35}
36#[doc(hidden)]
37pub struct PaymentIntentAmountDetailsLineItemBuilder {
38    discount_amount: Option<Option<i64>>,
39id: Option<stripe_shared::PaymentIntentAmountDetailsLineItemId>,
40payment_method_options: Option<Option<stripe_shared::PaymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourcePaymentMethodOptions>>,
41product_code: Option<Option<String>>,
42product_name: Option<String>,
43quantity: Option<u64>,
44tax: Option<Option<stripe_shared::PaymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourceTax>>,
45unit_cost: Option<i64>,
46unit_of_measure: Option<Option<String>>,
47
48}
49
50#[allow(
51    unused_variables,
52    irrefutable_let_patterns,
53    clippy::let_unit_value,
54    clippy::match_single_binding,
55    clippy::single_match
56)]
57const _: () = {
58    use miniserde::de::{Map, Visitor};
59    use miniserde::json::Value;
60    use miniserde::{Deserialize, Result, make_place};
61    use stripe_types::miniserde_helpers::FromValueOpt;
62    use stripe_types::{MapBuilder, ObjectDeser};
63
64    make_place!(Place);
65
66    impl Deserialize for PaymentIntentAmountDetailsLineItem {
67        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
68            Place::new(out)
69        }
70    }
71
72    struct Builder<'a> {
73        out: &'a mut Option<PaymentIntentAmountDetailsLineItem>,
74        builder: PaymentIntentAmountDetailsLineItemBuilder,
75    }
76
77    impl Visitor for Place<PaymentIntentAmountDetailsLineItem> {
78        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
79            Ok(Box::new(Builder {
80                out: &mut self.out,
81                builder: PaymentIntentAmountDetailsLineItemBuilder::deser_default(),
82            }))
83        }
84    }
85
86    impl MapBuilder for PaymentIntentAmountDetailsLineItemBuilder {
87        type Out = PaymentIntentAmountDetailsLineItem;
88        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
89            Ok(match k {
90                "discount_amount" => Deserialize::begin(&mut self.discount_amount),
91                "id" => Deserialize::begin(&mut self.id),
92                "payment_method_options" => Deserialize::begin(&mut self.payment_method_options),
93                "product_code" => Deserialize::begin(&mut self.product_code),
94                "product_name" => Deserialize::begin(&mut self.product_name),
95                "quantity" => Deserialize::begin(&mut self.quantity),
96                "tax" => Deserialize::begin(&mut self.tax),
97                "unit_cost" => Deserialize::begin(&mut self.unit_cost),
98                "unit_of_measure" => Deserialize::begin(&mut self.unit_of_measure),
99                _ => <dyn Visitor>::ignore(),
100            })
101        }
102
103        fn deser_default() -> Self {
104            Self {
105                discount_amount: Deserialize::default(),
106                id: Deserialize::default(),
107                payment_method_options: Deserialize::default(),
108                product_code: Deserialize::default(),
109                product_name: Deserialize::default(),
110                quantity: Deserialize::default(),
111                tax: Deserialize::default(),
112                unit_cost: Deserialize::default(),
113                unit_of_measure: Deserialize::default(),
114            }
115        }
116
117        fn take_out(&mut self) -> Option<Self::Out> {
118            let (
119                Some(discount_amount),
120                Some(id),
121                Some(payment_method_options),
122                Some(product_code),
123                Some(product_name),
124                Some(quantity),
125                Some(tax),
126                Some(unit_cost),
127                Some(unit_of_measure),
128            ) = (
129                self.discount_amount,
130                self.id.take(),
131                self.payment_method_options.take(),
132                self.product_code.take(),
133                self.product_name.take(),
134                self.quantity,
135                self.tax,
136                self.unit_cost,
137                self.unit_of_measure.take(),
138            )
139            else {
140                return None;
141            };
142            Some(Self::Out {
143                discount_amount,
144                id,
145                payment_method_options,
146                product_code,
147                product_name,
148                quantity,
149                tax,
150                unit_cost,
151                unit_of_measure,
152            })
153        }
154    }
155
156    impl Map for Builder<'_> {
157        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
158            self.builder.key(k)
159        }
160
161        fn finish(&mut self) -> Result<()> {
162            *self.out = self.builder.take_out();
163            Ok(())
164        }
165    }
166
167    impl ObjectDeser for PaymentIntentAmountDetailsLineItem {
168        type Builder = PaymentIntentAmountDetailsLineItemBuilder;
169    }
170
171    impl FromValueOpt for PaymentIntentAmountDetailsLineItem {
172        fn from_value(v: Value) -> Option<Self> {
173            let Value::Object(obj) = v else {
174                return None;
175            };
176            let mut b = PaymentIntentAmountDetailsLineItemBuilder::deser_default();
177            for (k, v) in obj {
178                match k.as_str() {
179                    "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
180                    "id" => b.id = FromValueOpt::from_value(v),
181                    "payment_method_options" => {
182                        b.payment_method_options = FromValueOpt::from_value(v)
183                    }
184                    "product_code" => b.product_code = FromValueOpt::from_value(v),
185                    "product_name" => b.product_name = FromValueOpt::from_value(v),
186                    "quantity" => b.quantity = FromValueOpt::from_value(v),
187                    "tax" => b.tax = FromValueOpt::from_value(v),
188                    "unit_cost" => b.unit_cost = FromValueOpt::from_value(v),
189                    "unit_of_measure" => b.unit_of_measure = FromValueOpt::from_value(v),
190                    _ => {}
191                }
192            }
193            b.take_out()
194        }
195    }
196};
197#[cfg(feature = "serialize")]
198impl serde::Serialize for PaymentIntentAmountDetailsLineItem {
199    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
200        use serde::ser::SerializeStruct;
201        let mut s = s.serialize_struct("PaymentIntentAmountDetailsLineItem", 10)?;
202        s.serialize_field("discount_amount", &self.discount_amount)?;
203        s.serialize_field("id", &self.id)?;
204        s.serialize_field("payment_method_options", &self.payment_method_options)?;
205        s.serialize_field("product_code", &self.product_code)?;
206        s.serialize_field("product_name", &self.product_name)?;
207        s.serialize_field("quantity", &self.quantity)?;
208        s.serialize_field("tax", &self.tax)?;
209        s.serialize_field("unit_cost", &self.unit_cost)?;
210        s.serialize_field("unit_of_measure", &self.unit_of_measure)?;
211
212        s.serialize_field("object", "payment_intent_amount_details_line_item")?;
213        s.end()
214    }
215}
216impl stripe_types::Object for PaymentIntentAmountDetailsLineItem {
217    type Id = stripe_shared::PaymentIntentAmountDetailsLineItemId;
218    fn id(&self) -> &Self::Id {
219        &self.id
220    }
221
222    fn into_id(self) -> Self::Id {
223        self.id
224    }
225}
226stripe_types::def_id!(PaymentIntentAmountDetailsLineItemId);