stripe_shared/
payment_links_resource_automatic_tax.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentLinksResourceAutomaticTax {
5    /// If `true`, tax will be calculated automatically using the customer's location.
6    pub enabled: bool,
7    /// The account that's liable for tax.
8    /// If set, the business address and tax registrations required to perform the tax calculation are loaded from this account.
9    /// The tax transaction is returned in the report of the connected account.
10    pub liability: Option<stripe_shared::ConnectAccountReference>,
11}
12#[doc(hidden)]
13pub struct PaymentLinksResourceAutomaticTaxBuilder {
14    enabled: Option<bool>,
15    liability: Option<Option<stripe_shared::ConnectAccountReference>>,
16}
17
18#[allow(
19    unused_variables,
20    irrefutable_let_patterns,
21    clippy::let_unit_value,
22    clippy::match_single_binding,
23    clippy::single_match
24)]
25const _: () = {
26    use miniserde::de::{Map, Visitor};
27    use miniserde::json::Value;
28    use miniserde::{Deserialize, Result, make_place};
29    use stripe_types::miniserde_helpers::FromValueOpt;
30    use stripe_types::{MapBuilder, ObjectDeser};
31
32    make_place!(Place);
33
34    impl Deserialize for PaymentLinksResourceAutomaticTax {
35        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
36            Place::new(out)
37        }
38    }
39
40    struct Builder<'a> {
41        out: &'a mut Option<PaymentLinksResourceAutomaticTax>,
42        builder: PaymentLinksResourceAutomaticTaxBuilder,
43    }
44
45    impl Visitor for Place<PaymentLinksResourceAutomaticTax> {
46        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
47            Ok(Box::new(Builder {
48                out: &mut self.out,
49                builder: PaymentLinksResourceAutomaticTaxBuilder::deser_default(),
50            }))
51        }
52    }
53
54    impl MapBuilder for PaymentLinksResourceAutomaticTaxBuilder {
55        type Out = PaymentLinksResourceAutomaticTax;
56        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
57            Ok(match k {
58                "enabled" => Deserialize::begin(&mut self.enabled),
59                "liability" => Deserialize::begin(&mut self.liability),
60                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self { enabled: Deserialize::default(), liability: Deserialize::default() }
66        }
67
68        fn take_out(&mut self) -> Option<Self::Out> {
69            let (Some(enabled), Some(liability)) = (self.enabled, self.liability.take()) else {
70                return None;
71            };
72            Some(Self::Out { enabled, liability })
73        }
74    }
75
76    impl Map for Builder<'_> {
77        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
78            self.builder.key(k)
79        }
80
81        fn finish(&mut self) -> Result<()> {
82            *self.out = self.builder.take_out();
83            Ok(())
84        }
85    }
86
87    impl ObjectDeser for PaymentLinksResourceAutomaticTax {
88        type Builder = PaymentLinksResourceAutomaticTaxBuilder;
89    }
90
91    impl FromValueOpt for PaymentLinksResourceAutomaticTax {
92        fn from_value(v: Value) -> Option<Self> {
93            let Value::Object(obj) = v else {
94                return None;
95            };
96            let mut b = PaymentLinksResourceAutomaticTaxBuilder::deser_default();
97            for (k, v) in obj {
98                match k.as_str() {
99                    "enabled" => b.enabled = FromValueOpt::from_value(v),
100                    "liability" => b.liability = FromValueOpt::from_value(v),
101                    _ => {}
102                }
103            }
104            b.take_out()
105        }
106    }
107};