stripe_shared/
account_invoices_settings.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct AccountInvoicesSettings {
5    /// The list of default Account Tax IDs to automatically include on invoices.
6    /// Account Tax IDs get added when an invoice is finalized.
7    pub default_account_tax_ids: Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>,
8    /// Whether payment methods should be saved when a payment is completed for a one-time invoices on a hosted invoice page.
9    pub hosted_payment_method_save: Option<AccountInvoicesSettingsHostedPaymentMethodSave>,
10}
11#[doc(hidden)]
12pub struct AccountInvoicesSettingsBuilder {
13    default_account_tax_ids: Option<Option<Vec<stripe_types::Expandable<stripe_shared::TaxId>>>>,
14    hosted_payment_method_save: Option<Option<AccountInvoicesSettingsHostedPaymentMethodSave>>,
15}
16
17#[allow(
18    unused_variables,
19    irrefutable_let_patterns,
20    clippy::let_unit_value,
21    clippy::match_single_binding,
22    clippy::single_match
23)]
24const _: () = {
25    use miniserde::de::{Map, Visitor};
26    use miniserde::json::Value;
27    use miniserde::{Deserialize, Result, make_place};
28    use stripe_types::miniserde_helpers::FromValueOpt;
29    use stripe_types::{MapBuilder, ObjectDeser};
30
31    make_place!(Place);
32
33    impl Deserialize for AccountInvoicesSettings {
34        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
35            Place::new(out)
36        }
37    }
38
39    struct Builder<'a> {
40        out: &'a mut Option<AccountInvoicesSettings>,
41        builder: AccountInvoicesSettingsBuilder,
42    }
43
44    impl Visitor for Place<AccountInvoicesSettings> {
45        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
46            Ok(Box::new(Builder {
47                out: &mut self.out,
48                builder: AccountInvoicesSettingsBuilder::deser_default(),
49            }))
50        }
51    }
52
53    impl MapBuilder for AccountInvoicesSettingsBuilder {
54        type Out = AccountInvoicesSettings;
55        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
56            Ok(match k {
57                "default_account_tax_ids" => Deserialize::begin(&mut self.default_account_tax_ids),
58                "hosted_payment_method_save" => {
59                    Deserialize::begin(&mut self.hosted_payment_method_save)
60                }
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self {
67                default_account_tax_ids: Deserialize::default(),
68                hosted_payment_method_save: Deserialize::default(),
69            }
70        }
71
72        fn take_out(&mut self) -> Option<Self::Out> {
73            let (Some(default_account_tax_ids), Some(hosted_payment_method_save)) =
74                (self.default_account_tax_ids.take(), self.hosted_payment_method_save)
75            else {
76                return None;
77            };
78            Some(Self::Out { default_account_tax_ids, hosted_payment_method_save })
79        }
80    }
81
82    impl Map for Builder<'_> {
83        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84            self.builder.key(k)
85        }
86
87        fn finish(&mut self) -> Result<()> {
88            *self.out = self.builder.take_out();
89            Ok(())
90        }
91    }
92
93    impl ObjectDeser for AccountInvoicesSettings {
94        type Builder = AccountInvoicesSettingsBuilder;
95    }
96
97    impl FromValueOpt for AccountInvoicesSettings {
98        fn from_value(v: Value) -> Option<Self> {
99            let Value::Object(obj) = v else {
100                return None;
101            };
102            let mut b = AccountInvoicesSettingsBuilder::deser_default();
103            for (k, v) in obj {
104                match k.as_str() {
105                    "default_account_tax_ids" => {
106                        b.default_account_tax_ids = FromValueOpt::from_value(v)
107                    }
108                    "hosted_payment_method_save" => {
109                        b.hosted_payment_method_save = FromValueOpt::from_value(v)
110                    }
111                    _ => {}
112                }
113            }
114            b.take_out()
115        }
116    }
117};
118/// Whether payment methods should be saved when a payment is completed for a one-time invoices on a hosted invoice page.
119#[derive(Copy, Clone, Eq, PartialEq)]
120pub enum AccountInvoicesSettingsHostedPaymentMethodSave {
121    Always,
122    Never,
123    Offer,
124}
125impl AccountInvoicesSettingsHostedPaymentMethodSave {
126    pub fn as_str(self) -> &'static str {
127        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
128        match self {
129            Always => "always",
130            Never => "never",
131            Offer => "offer",
132        }
133    }
134}
135
136impl std::str::FromStr for AccountInvoicesSettingsHostedPaymentMethodSave {
137    type Err = stripe_types::StripeParseError;
138    fn from_str(s: &str) -> Result<Self, Self::Err> {
139        use AccountInvoicesSettingsHostedPaymentMethodSave::*;
140        match s {
141            "always" => Ok(Always),
142            "never" => Ok(Never),
143            "offer" => Ok(Offer),
144            _ => Err(stripe_types::StripeParseError),
145        }
146    }
147}
148impl std::fmt::Display for AccountInvoicesSettingsHostedPaymentMethodSave {
149    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
150        f.write_str(self.as_str())
151    }
152}
153
154impl std::fmt::Debug for AccountInvoicesSettingsHostedPaymentMethodSave {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159#[cfg(feature = "serialize")]
160impl serde::Serialize for AccountInvoicesSettingsHostedPaymentMethodSave {
161    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
162    where
163        S: serde::Serializer,
164    {
165        serializer.serialize_str(self.as_str())
166    }
167}
168impl miniserde::Deserialize for AccountInvoicesSettingsHostedPaymentMethodSave {
169    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
170        crate::Place::new(out)
171    }
172}
173
174impl miniserde::de::Visitor for crate::Place<AccountInvoicesSettingsHostedPaymentMethodSave> {
175    fn string(&mut self, s: &str) -> miniserde::Result<()> {
176        use std::str::FromStr;
177        self.out = Some(
178            AccountInvoicesSettingsHostedPaymentMethodSave::from_str(s)
179                .map_err(|_| miniserde::Error)?,
180        );
181        Ok(())
182    }
183}
184
185stripe_types::impl_from_val_with_from_str!(AccountInvoicesSettingsHostedPaymentMethodSave);
186#[cfg(feature = "deserialize")]
187impl<'de> serde::Deserialize<'de> for AccountInvoicesSettingsHostedPaymentMethodSave {
188    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
189        use std::str::FromStr;
190        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
191        Self::from_str(&s).map_err(|_| {
192            serde::de::Error::custom(
193                "Unknown value for AccountInvoicesSettingsHostedPaymentMethodSave",
194            )
195        })
196    }
197}