stripe_shared/
payment_pages_checkout_session_shipping_cost.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentPagesCheckoutSessionShippingCost {
5    /// Total shipping cost before any discounts or taxes are applied.
6    pub amount_subtotal: i64,
7    /// Total tax amount applied due to shipping costs. If no tax was applied, defaults to 0.
8    pub amount_tax: i64,
9    /// Total shipping cost after discounts and taxes are applied.
10    pub amount_total: i64,
11    /// The ID of the ShippingRate for this order.
12    pub shipping_rate: Option<stripe_types::Expandable<stripe_shared::ShippingRate>>,
13    /// The taxes applied to the shipping rate.
14    pub taxes: Option<Vec<stripe_shared::LineItemsTaxAmount>>,
15}
16#[doc(hidden)]
17pub struct PaymentPagesCheckoutSessionShippingCostBuilder {
18    amount_subtotal: Option<i64>,
19    amount_tax: Option<i64>,
20    amount_total: Option<i64>,
21    shipping_rate: Option<Option<stripe_types::Expandable<stripe_shared::ShippingRate>>>,
22    taxes: Option<Option<Vec<stripe_shared::LineItemsTaxAmount>>>,
23}
24
25#[allow(
26    unused_variables,
27    irrefutable_let_patterns,
28    clippy::let_unit_value,
29    clippy::match_single_binding,
30    clippy::single_match
31)]
32const _: () = {
33    use miniserde::de::{Map, Visitor};
34    use miniserde::json::Value;
35    use miniserde::{Deserialize, Result, make_place};
36    use stripe_types::miniserde_helpers::FromValueOpt;
37    use stripe_types::{MapBuilder, ObjectDeser};
38
39    make_place!(Place);
40
41    impl Deserialize for PaymentPagesCheckoutSessionShippingCost {
42        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
43            Place::new(out)
44        }
45    }
46
47    struct Builder<'a> {
48        out: &'a mut Option<PaymentPagesCheckoutSessionShippingCost>,
49        builder: PaymentPagesCheckoutSessionShippingCostBuilder,
50    }
51
52    impl Visitor for Place<PaymentPagesCheckoutSessionShippingCost> {
53        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
54            Ok(Box::new(Builder {
55                out: &mut self.out,
56                builder: PaymentPagesCheckoutSessionShippingCostBuilder::deser_default(),
57            }))
58        }
59    }
60
61    impl MapBuilder for PaymentPagesCheckoutSessionShippingCostBuilder {
62        type Out = PaymentPagesCheckoutSessionShippingCost;
63        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
64            Ok(match k {
65                "amount_subtotal" => Deserialize::begin(&mut self.amount_subtotal),
66                "amount_tax" => Deserialize::begin(&mut self.amount_tax),
67                "amount_total" => Deserialize::begin(&mut self.amount_total),
68                "shipping_rate" => Deserialize::begin(&mut self.shipping_rate),
69                "taxes" => Deserialize::begin(&mut self.taxes),
70
71                _ => <dyn Visitor>::ignore(),
72            })
73        }
74
75        fn deser_default() -> Self {
76            Self {
77                amount_subtotal: Deserialize::default(),
78                amount_tax: Deserialize::default(),
79                amount_total: Deserialize::default(),
80                shipping_rate: Deserialize::default(),
81                taxes: Deserialize::default(),
82            }
83        }
84
85        fn take_out(&mut self) -> Option<Self::Out> {
86            let (
87                Some(amount_subtotal),
88                Some(amount_tax),
89                Some(amount_total),
90                Some(shipping_rate),
91                Some(taxes),
92            ) = (
93                self.amount_subtotal,
94                self.amount_tax,
95                self.amount_total,
96                self.shipping_rate.take(),
97                self.taxes.take(),
98            )
99            else {
100                return None;
101            };
102            Some(Self::Out { amount_subtotal, amount_tax, amount_total, shipping_rate, taxes })
103        }
104    }
105
106    impl Map for Builder<'_> {
107        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
108            self.builder.key(k)
109        }
110
111        fn finish(&mut self) -> Result<()> {
112            *self.out = self.builder.take_out();
113            Ok(())
114        }
115    }
116
117    impl ObjectDeser for PaymentPagesCheckoutSessionShippingCost {
118        type Builder = PaymentPagesCheckoutSessionShippingCostBuilder;
119    }
120
121    impl FromValueOpt for PaymentPagesCheckoutSessionShippingCost {
122        fn from_value(v: Value) -> Option<Self> {
123            let Value::Object(obj) = v else {
124                return None;
125            };
126            let mut b = PaymentPagesCheckoutSessionShippingCostBuilder::deser_default();
127            for (k, v) in obj {
128                match k.as_str() {
129                    "amount_subtotal" => b.amount_subtotal = FromValueOpt::from_value(v),
130                    "amount_tax" => b.amount_tax = FromValueOpt::from_value(v),
131                    "amount_total" => b.amount_total = FromValueOpt::from_value(v),
132                    "shipping_rate" => b.shipping_rate = FromValueOpt::from_value(v),
133                    "taxes" => b.taxes = FromValueOpt::from_value(v),
134
135                    _ => {}
136                }
137            }
138            b.take_out()
139        }
140    }
141};