stripe_shared/
payment_flows_amount_details.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentFlowsAmountDetails {
5    /// The total discount applied on the transaction represented in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal).
6    /// An integer greater than 0.
7    ///
8    /// This field is mutually exclusive with the `amount_details[line_items][#][discount_amount]` field.
9    pub discount_amount: Option<i64>,
10    /// A list of line items, each containing information about a product in the PaymentIntent.
11    /// There is a maximum of 100 line items.
12    pub line_items: Option<stripe_types::List<stripe_shared::PaymentIntentAmountDetailsLineItem>>,
13    pub shipping: Option<stripe_shared::PaymentFlowsAmountDetailsResourceShipping>,
14    pub tax: Option<stripe_shared::PaymentFlowsAmountDetailsResourceTax>,
15    pub tip: Option<stripe_shared::PaymentFlowsAmountDetailsClientResourceTip>,
16}
17#[doc(hidden)]
18pub struct PaymentFlowsAmountDetailsBuilder {
19    discount_amount: Option<Option<i64>>,
20    line_items:
21        Option<Option<stripe_types::List<stripe_shared::PaymentIntentAmountDetailsLineItem>>>,
22    shipping: Option<Option<stripe_shared::PaymentFlowsAmountDetailsResourceShipping>>,
23    tax: Option<Option<stripe_shared::PaymentFlowsAmountDetailsResourceTax>>,
24    tip: Option<Option<stripe_shared::PaymentFlowsAmountDetailsClientResourceTip>>,
25}
26
27#[allow(
28    unused_variables,
29    irrefutable_let_patterns,
30    clippy::let_unit_value,
31    clippy::match_single_binding,
32    clippy::single_match
33)]
34const _: () = {
35    use miniserde::de::{Map, Visitor};
36    use miniserde::json::Value;
37    use miniserde::{Deserialize, Result, make_place};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for PaymentFlowsAmountDetails {
44        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
45            Place::new(out)
46        }
47    }
48
49    struct Builder<'a> {
50        out: &'a mut Option<PaymentFlowsAmountDetails>,
51        builder: PaymentFlowsAmountDetailsBuilder,
52    }
53
54    impl Visitor for Place<PaymentFlowsAmountDetails> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: PaymentFlowsAmountDetailsBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for PaymentFlowsAmountDetailsBuilder {
64        type Out = PaymentFlowsAmountDetails;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "discount_amount" => Deserialize::begin(&mut self.discount_amount),
68                "line_items" => Deserialize::begin(&mut self.line_items),
69                "shipping" => Deserialize::begin(&mut self.shipping),
70                "tax" => Deserialize::begin(&mut self.tax),
71                "tip" => Deserialize::begin(&mut self.tip),
72                _ => <dyn Visitor>::ignore(),
73            })
74        }
75
76        fn deser_default() -> Self {
77            Self {
78                discount_amount: Deserialize::default(),
79                line_items: Deserialize::default(),
80                shipping: Deserialize::default(),
81                tax: Deserialize::default(),
82                tip: Deserialize::default(),
83            }
84        }
85
86        fn take_out(&mut self) -> Option<Self::Out> {
87            let (Some(discount_amount), Some(line_items), Some(shipping), Some(tax), Some(tip)) = (
88                self.discount_amount,
89                self.line_items.take(),
90                self.shipping.take(),
91                self.tax,
92                self.tip,
93            ) else {
94                return None;
95            };
96            Some(Self::Out { discount_amount, line_items, shipping, tax, tip })
97        }
98    }
99
100    impl Map for Builder<'_> {
101        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
102            self.builder.key(k)
103        }
104
105        fn finish(&mut self) -> Result<()> {
106            *self.out = self.builder.take_out();
107            Ok(())
108        }
109    }
110
111    impl ObjectDeser for PaymentFlowsAmountDetails {
112        type Builder = PaymentFlowsAmountDetailsBuilder;
113    }
114
115    impl FromValueOpt for PaymentFlowsAmountDetails {
116        fn from_value(v: Value) -> Option<Self> {
117            let Value::Object(obj) = v else {
118                return None;
119            };
120            let mut b = PaymentFlowsAmountDetailsBuilder::deser_default();
121            for (k, v) in obj {
122                match k.as_str() {
123                    "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
124                    "line_items" => b.line_items = FromValueOpt::from_value(v),
125                    "shipping" => b.shipping = FromValueOpt::from_value(v),
126                    "tax" => b.tax = FromValueOpt::from_value(v),
127                    "tip" => b.tip = FromValueOpt::from_value(v),
128                    _ => {}
129                }
130            }
131            b.take_out()
132        }
133    }
134};