stripe_misc/tax_settings/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct RetrieveForMyAccountTaxSettingsBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    expand: Option<Vec<String>>,
9}
10impl RetrieveForMyAccountTaxSettingsBuilder {
11    fn new() -> Self {
12        Self { expand: None }
13    }
14}
15/// Retrieves Tax `Settings` for a merchant.
16#[derive(Clone, Debug, serde::Serialize)]
17pub struct RetrieveForMyAccountTaxSettings {
18    inner: RetrieveForMyAccountTaxSettingsBuilder,
19}
20impl RetrieveForMyAccountTaxSettings {
21    /// Construct a new `RetrieveForMyAccountTaxSettings`.
22    pub fn new() -> Self {
23        Self { inner: RetrieveForMyAccountTaxSettingsBuilder::new() }
24    }
25    /// Specifies which fields in the response should be expanded.
26    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
27        self.inner.expand = Some(expand.into());
28        self
29    }
30}
31impl Default for RetrieveForMyAccountTaxSettings {
32    fn default() -> Self {
33        Self::new()
34    }
35}
36impl RetrieveForMyAccountTaxSettings {
37    /// Send the request and return the deserialized response.
38    pub async fn send<C: StripeClient>(
39        &self,
40        client: &C,
41    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
42        self.customize().send(client).await
43    }
44
45    /// Send the request and return the deserialized response, blocking until completion.
46    pub fn send_blocking<C: StripeBlockingClient>(
47        &self,
48        client: &C,
49    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
50        self.customize().send_blocking(client)
51    }
52}
53
54impl StripeRequest for RetrieveForMyAccountTaxSettings {
55    type Output = stripe_misc::TaxSettings;
56
57    fn build(&self) -> RequestBuilder {
58        RequestBuilder::new(StripeMethod::Get, "/tax/settings").query(&self.inner)
59    }
60}
61#[derive(Clone, Debug, serde::Serialize)]
62struct UpdateTaxSettingsBuilder {
63    #[serde(skip_serializing_if = "Option::is_none")]
64    defaults: Option<UpdateTaxSettingsDefaults>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    expand: Option<Vec<String>>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    head_office: Option<UpdateTaxSettingsHeadOffice>,
69}
70impl UpdateTaxSettingsBuilder {
71    fn new() -> Self {
72        Self { defaults: None, expand: None, head_office: None }
73    }
74}
75/// Default configuration to be used on Stripe Tax calculations.
76#[derive(Clone, Debug, serde::Serialize)]
77pub struct UpdateTaxSettingsDefaults {
78    /// Specifies the default [tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#tax-behavior) to be used when the item's price has unspecified tax behavior.
79    /// One of inclusive, exclusive, or inferred_by_currency.
80    /// Once specified, it cannot be changed back to null.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub tax_behavior: Option<UpdateTaxSettingsDefaultsTaxBehavior>,
83    /// A [tax code](https://stripe.com/docs/tax/tax-categories) ID.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub tax_code: Option<String>,
86}
87impl UpdateTaxSettingsDefaults {
88    pub fn new() -> Self {
89        Self { tax_behavior: None, tax_code: None }
90    }
91}
92impl Default for UpdateTaxSettingsDefaults {
93    fn default() -> Self {
94        Self::new()
95    }
96}
97/// Specifies the default [tax behavior](https://stripe.com/docs/tax/products-prices-tax-categories-tax-behavior#tax-behavior) to be used when the item's price has unspecified tax behavior.
98/// One of inclusive, exclusive, or inferred_by_currency.
99/// Once specified, it cannot be changed back to null.
100#[derive(Clone, Eq, PartialEq)]
101#[non_exhaustive]
102pub enum UpdateTaxSettingsDefaultsTaxBehavior {
103    Exclusive,
104    Inclusive,
105    InferredByCurrency,
106    /// An unrecognized value from Stripe. Should not be used as a request parameter.
107    Unknown(String),
108}
109impl UpdateTaxSettingsDefaultsTaxBehavior {
110    pub fn as_str(&self) -> &str {
111        use UpdateTaxSettingsDefaultsTaxBehavior::*;
112        match self {
113            Exclusive => "exclusive",
114            Inclusive => "inclusive",
115            InferredByCurrency => "inferred_by_currency",
116            Unknown(v) => v,
117        }
118    }
119}
120
121impl std::str::FromStr for UpdateTaxSettingsDefaultsTaxBehavior {
122    type Err = std::convert::Infallible;
123    fn from_str(s: &str) -> Result<Self, Self::Err> {
124        use UpdateTaxSettingsDefaultsTaxBehavior::*;
125        match s {
126            "exclusive" => Ok(Exclusive),
127            "inclusive" => Ok(Inclusive),
128            "inferred_by_currency" => Ok(InferredByCurrency),
129            v => {
130                tracing::warn!(
131                    "Unknown value '{}' for enum '{}'",
132                    v,
133                    "UpdateTaxSettingsDefaultsTaxBehavior"
134                );
135                Ok(Unknown(v.to_owned()))
136            }
137        }
138    }
139}
140impl std::fmt::Display for UpdateTaxSettingsDefaultsTaxBehavior {
141    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
142        f.write_str(self.as_str())
143    }
144}
145
146impl std::fmt::Debug for UpdateTaxSettingsDefaultsTaxBehavior {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        f.write_str(self.as_str())
149    }
150}
151impl serde::Serialize for UpdateTaxSettingsDefaultsTaxBehavior {
152    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
153    where
154        S: serde::Serializer,
155    {
156        serializer.serialize_str(self.as_str())
157    }
158}
159#[cfg(feature = "deserialize")]
160impl<'de> serde::Deserialize<'de> for UpdateTaxSettingsDefaultsTaxBehavior {
161    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
162        use std::str::FromStr;
163        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
164        Ok(Self::from_str(&s).expect("infallible"))
165    }
166}
167/// The place where your business is located.
168#[derive(Clone, Debug, serde::Serialize)]
169pub struct UpdateTaxSettingsHeadOffice {
170    /// The location of the business for tax purposes.
171    pub address: UpdateTaxSettingsHeadOfficeAddress,
172}
173impl UpdateTaxSettingsHeadOffice {
174    pub fn new(address: impl Into<UpdateTaxSettingsHeadOfficeAddress>) -> Self {
175        Self { address: address.into() }
176    }
177}
178/// The location of the business for tax purposes.
179#[derive(Clone, Debug, serde::Serialize)]
180pub struct UpdateTaxSettingsHeadOfficeAddress {
181    /// City, district, suburb, town, or village.
182    #[serde(skip_serializing_if = "Option::is_none")]
183    pub city: Option<String>,
184    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
185    #[serde(skip_serializing_if = "Option::is_none")]
186    pub country: Option<String>,
187    /// Address line 1, such as the street, PO Box, or company name.
188    #[serde(skip_serializing_if = "Option::is_none")]
189    pub line1: Option<String>,
190    /// Address line 2, such as the apartment, suite, unit, or building.
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub line2: Option<String>,
193    /// ZIP or postal code.
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub postal_code: Option<String>,
196    /// State/province as an [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) subdivision code, without country prefix, such as "NY" or "TX".
197    #[serde(skip_serializing_if = "Option::is_none")]
198    pub state: Option<String>,
199}
200impl UpdateTaxSettingsHeadOfficeAddress {
201    pub fn new() -> Self {
202        Self { city: None, country: None, line1: None, line2: None, postal_code: None, state: None }
203    }
204}
205impl Default for UpdateTaxSettingsHeadOfficeAddress {
206    fn default() -> Self {
207        Self::new()
208    }
209}
210/// Updates Tax `Settings` parameters used in tax calculations.
211/// All parameters are editable but none can be removed once set.
212#[derive(Clone, Debug, serde::Serialize)]
213pub struct UpdateTaxSettings {
214    inner: UpdateTaxSettingsBuilder,
215}
216impl UpdateTaxSettings {
217    /// Construct a new `UpdateTaxSettings`.
218    pub fn new() -> Self {
219        Self { inner: UpdateTaxSettingsBuilder::new() }
220    }
221    /// Default configuration to be used on Stripe Tax calculations.
222    pub fn defaults(mut self, defaults: impl Into<UpdateTaxSettingsDefaults>) -> Self {
223        self.inner.defaults = Some(defaults.into());
224        self
225    }
226    /// Specifies which fields in the response should be expanded.
227    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
228        self.inner.expand = Some(expand.into());
229        self
230    }
231    /// The place where your business is located.
232    pub fn head_office(mut self, head_office: impl Into<UpdateTaxSettingsHeadOffice>) -> Self {
233        self.inner.head_office = Some(head_office.into());
234        self
235    }
236}
237impl Default for UpdateTaxSettings {
238    fn default() -> Self {
239        Self::new()
240    }
241}
242impl UpdateTaxSettings {
243    /// Send the request and return the deserialized response.
244    pub async fn send<C: StripeClient>(
245        &self,
246        client: &C,
247    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
248        self.customize().send(client).await
249    }
250
251    /// Send the request and return the deserialized response, blocking until completion.
252    pub fn send_blocking<C: StripeBlockingClient>(
253        &self,
254        client: &C,
255    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
256        self.customize().send_blocking(client)
257    }
258}
259
260impl StripeRequest for UpdateTaxSettings {
261    type Output = stripe_misc::TaxSettings;
262
263    fn build(&self) -> RequestBuilder {
264        RequestBuilder::new(StripeMethod::Post, "/tax/settings").form(&self.inner)
265    }
266}