stripe_misc/tax_transaction/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct RetrieveTaxTransactionBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    expand: Option<Vec<String>>,
9}
10impl RetrieveTaxTransactionBuilder {
11    fn new() -> Self {
12        Self { expand: None }
13    }
14}
15/// Retrieves a Tax `Transaction` object.
16#[derive(Clone, Debug, serde::Serialize)]
17pub struct RetrieveTaxTransaction {
18    inner: RetrieveTaxTransactionBuilder,
19    transaction: stripe_misc::TaxTransactionId,
20}
21impl RetrieveTaxTransaction {
22    /// Construct a new `RetrieveTaxTransaction`.
23    pub fn new(transaction: impl Into<stripe_misc::TaxTransactionId>) -> Self {
24        Self { transaction: transaction.into(), inner: RetrieveTaxTransactionBuilder::new() }
25    }
26    /// Specifies which fields in the response should be expanded.
27    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
28        self.inner.expand = Some(expand.into());
29        self
30    }
31}
32impl RetrieveTaxTransaction {
33    /// Send the request and return the deserialized response.
34    pub async fn send<C: StripeClient>(
35        &self,
36        client: &C,
37    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
38        self.customize().send(client).await
39    }
40
41    /// Send the request and return the deserialized response, blocking until completion.
42    pub fn send_blocking<C: StripeBlockingClient>(
43        &self,
44        client: &C,
45    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
46        self.customize().send_blocking(client)
47    }
48}
49
50impl StripeRequest for RetrieveTaxTransaction {
51    type Output = stripe_misc::TaxTransaction;
52
53    fn build(&self) -> RequestBuilder {
54        let transaction = &self.transaction;
55        RequestBuilder::new(StripeMethod::Get, format!("/tax/transactions/{transaction}"))
56            .query(&self.inner)
57    }
58}
59#[derive(Clone, Debug, serde::Serialize)]
60struct ListLineItemsTaxTransactionBuilder {
61    #[serde(skip_serializing_if = "Option::is_none")]
62    ending_before: Option<String>,
63    #[serde(skip_serializing_if = "Option::is_none")]
64    expand: Option<Vec<String>>,
65    #[serde(skip_serializing_if = "Option::is_none")]
66    limit: Option<i64>,
67    #[serde(skip_serializing_if = "Option::is_none")]
68    starting_after: Option<String>,
69}
70impl ListLineItemsTaxTransactionBuilder {
71    fn new() -> Self {
72        Self { ending_before: None, expand: None, limit: None, starting_after: None }
73    }
74}
75/// Retrieves the line items of a committed standalone transaction as a collection.
76#[derive(Clone, Debug, serde::Serialize)]
77pub struct ListLineItemsTaxTransaction {
78    inner: ListLineItemsTaxTransactionBuilder,
79    transaction: stripe_misc::TaxTransactionId,
80}
81impl ListLineItemsTaxTransaction {
82    /// Construct a new `ListLineItemsTaxTransaction`.
83    pub fn new(transaction: impl Into<stripe_misc::TaxTransactionId>) -> Self {
84        Self { transaction: transaction.into(), inner: ListLineItemsTaxTransactionBuilder::new() }
85    }
86    /// A cursor for use in pagination.
87    /// `ending_before` is an object ID that defines your place in the list.
88    /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list.
89    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
90        self.inner.ending_before = Some(ending_before.into());
91        self
92    }
93    /// Specifies which fields in the response should be expanded.
94    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
95        self.inner.expand = Some(expand.into());
96        self
97    }
98    /// A limit on the number of objects to be returned.
99    /// Limit can range between 1 and 100, and the default is 10.
100    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
101        self.inner.limit = Some(limit.into());
102        self
103    }
104    /// A cursor for use in pagination.
105    /// `starting_after` is an object ID that defines your place in the list.
106    /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list.
107    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
108        self.inner.starting_after = Some(starting_after.into());
109        self
110    }
111}
112impl ListLineItemsTaxTransaction {
113    /// Send the request and return the deserialized response.
114    pub async fn send<C: StripeClient>(
115        &self,
116        client: &C,
117    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
118        self.customize().send(client).await
119    }
120
121    /// Send the request and return the deserialized response, blocking until completion.
122    pub fn send_blocking<C: StripeBlockingClient>(
123        &self,
124        client: &C,
125    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
126        self.customize().send_blocking(client)
127    }
128
129    pub fn paginate(
130        &self,
131    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_misc::TaxTransactionLineItem>>
132    {
133        let transaction = &self.transaction;
134
135        stripe_client_core::ListPaginator::new_list(
136            format!("/tax/transactions/{transaction}/line_items"),
137            &self.inner,
138        )
139    }
140}
141
142impl StripeRequest for ListLineItemsTaxTransaction {
143    type Output = stripe_types::List<stripe_misc::TaxTransactionLineItem>;
144
145    fn build(&self) -> RequestBuilder {
146        let transaction = &self.transaction;
147        RequestBuilder::new(
148            StripeMethod::Get,
149            format!("/tax/transactions/{transaction}/line_items"),
150        )
151        .query(&self.inner)
152    }
153}
154#[derive(Clone, Debug, serde::Serialize)]
155struct CreateFromCalculationTaxTransactionBuilder {
156    calculation: String,
157    #[serde(skip_serializing_if = "Option::is_none")]
158    expand: Option<Vec<String>>,
159    #[serde(skip_serializing_if = "Option::is_none")]
160    metadata: Option<std::collections::HashMap<String, String>>,
161    #[serde(skip_serializing_if = "Option::is_none")]
162    posted_at: Option<stripe_types::Timestamp>,
163    reference: String,
164}
165impl CreateFromCalculationTaxTransactionBuilder {
166    fn new(calculation: impl Into<String>, reference: impl Into<String>) -> Self {
167        Self {
168            calculation: calculation.into(),
169            expand: None,
170            metadata: None,
171            posted_at: None,
172            reference: reference.into(),
173        }
174    }
175}
176/// Creates a Tax Transaction from a calculation, if that calculation hasn’t expired.
177/// Calculations expire after 90 days.
178#[derive(Clone, Debug, serde::Serialize)]
179pub struct CreateFromCalculationTaxTransaction {
180    inner: CreateFromCalculationTaxTransactionBuilder,
181}
182impl CreateFromCalculationTaxTransaction {
183    /// Construct a new `CreateFromCalculationTaxTransaction`.
184    pub fn new(calculation: impl Into<String>, reference: impl Into<String>) -> Self {
185        Self {
186            inner: CreateFromCalculationTaxTransactionBuilder::new(
187                calculation.into(),
188                reference.into(),
189            ),
190        }
191    }
192    /// Specifies which fields in the response should be expanded.
193    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
194        self.inner.expand = Some(expand.into());
195        self
196    }
197    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
198    /// This can be useful for storing additional information about the object in a structured format.
199    /// Individual keys can be unset by posting an empty value to them.
200    /// All keys can be unset by posting an empty value to `metadata`.
201    pub fn metadata(
202        mut self,
203        metadata: impl Into<std::collections::HashMap<String, String>>,
204    ) -> Self {
205        self.inner.metadata = Some(metadata.into());
206        self
207    }
208    /// The Unix timestamp representing when the tax liability is assumed or reduced, which determines the liability posting period and handling in tax liability reports.
209    /// The timestamp must fall within the `tax_date` and the current time, unless the `tax_date` is scheduled in advance.
210    /// Defaults to the current time.
211    pub fn posted_at(mut self, posted_at: impl Into<stripe_types::Timestamp>) -> Self {
212        self.inner.posted_at = Some(posted_at.into());
213        self
214    }
215}
216impl CreateFromCalculationTaxTransaction {
217    /// Send the request and return the deserialized response.
218    pub async fn send<C: StripeClient>(
219        &self,
220        client: &C,
221    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
222        self.customize().send(client).await
223    }
224
225    /// Send the request and return the deserialized response, blocking until completion.
226    pub fn send_blocking<C: StripeBlockingClient>(
227        &self,
228        client: &C,
229    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
230        self.customize().send_blocking(client)
231    }
232}
233
234impl StripeRequest for CreateFromCalculationTaxTransaction {
235    type Output = stripe_misc::TaxTransaction;
236
237    fn build(&self) -> RequestBuilder {
238        RequestBuilder::new(StripeMethod::Post, "/tax/transactions/create_from_calculation")
239            .form(&self.inner)
240    }
241}
242#[derive(Clone, Debug, serde::Serialize)]
243struct CreateReversalTaxTransactionBuilder {
244    #[serde(skip_serializing_if = "Option::is_none")]
245    expand: Option<Vec<String>>,
246    #[serde(skip_serializing_if = "Option::is_none")]
247    flat_amount: Option<i64>,
248    #[serde(skip_serializing_if = "Option::is_none")]
249    line_items: Option<Vec<CreateReversalTaxTransactionLineItems>>,
250    #[serde(skip_serializing_if = "Option::is_none")]
251    metadata: Option<std::collections::HashMap<String, String>>,
252    mode: CreateReversalTaxTransactionMode,
253    original_transaction: String,
254    reference: String,
255    #[serde(skip_serializing_if = "Option::is_none")]
256    shipping_cost: Option<CreateReversalTaxTransactionShippingCost>,
257}
258impl CreateReversalTaxTransactionBuilder {
259    fn new(
260        mode: impl Into<CreateReversalTaxTransactionMode>,
261        original_transaction: impl Into<String>,
262        reference: impl Into<String>,
263    ) -> Self {
264        Self {
265            expand: None,
266            flat_amount: None,
267            line_items: None,
268            metadata: None,
269            mode: mode.into(),
270            original_transaction: original_transaction.into(),
271            reference: reference.into(),
272            shipping_cost: None,
273        }
274    }
275}
276/// The line item amounts to reverse.
277#[derive(Clone, Debug, serde::Serialize)]
278pub struct CreateReversalTaxTransactionLineItems {
279    /// The amount to reverse, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) in negative.
280    pub amount: i64,
281    /// The amount of tax to reverse, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) in negative.
282    pub amount_tax: i64,
283    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
284    /// This can be useful for storing additional information about the object in a structured format.
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub metadata: Option<std::collections::HashMap<String, String>>,
287    /// The `id` of the line item to reverse in the original transaction.
288    pub original_line_item: String,
289    /// The quantity reversed.
290    /// Appears in [tax exports](https://stripe.com/docs/tax/reports), but does not affect the amount of tax reversed.
291    #[serde(skip_serializing_if = "Option::is_none")]
292    pub quantity: Option<u64>,
293    /// A custom identifier for this line item in the reversal transaction, such as 'L1-refund'.
294    pub reference: String,
295}
296impl CreateReversalTaxTransactionLineItems {
297    pub fn new(
298        amount: impl Into<i64>,
299        amount_tax: impl Into<i64>,
300        original_line_item: impl Into<String>,
301        reference: impl Into<String>,
302    ) -> Self {
303        Self {
304            amount: amount.into(),
305            amount_tax: amount_tax.into(),
306            metadata: None,
307            original_line_item: original_line_item.into(),
308            quantity: None,
309            reference: reference.into(),
310        }
311    }
312}
313/// If `partial`, the provided line item or shipping cost amounts are reversed.
314/// If `full`, the original transaction is fully reversed.
315#[derive(Copy, Clone, Eq, PartialEq)]
316pub enum CreateReversalTaxTransactionMode {
317    Full,
318    Partial,
319}
320impl CreateReversalTaxTransactionMode {
321    pub fn as_str(self) -> &'static str {
322        use CreateReversalTaxTransactionMode::*;
323        match self {
324            Full => "full",
325            Partial => "partial",
326        }
327    }
328}
329
330impl std::str::FromStr for CreateReversalTaxTransactionMode {
331    type Err = stripe_types::StripeParseError;
332    fn from_str(s: &str) -> Result<Self, Self::Err> {
333        use CreateReversalTaxTransactionMode::*;
334        match s {
335            "full" => Ok(Full),
336            "partial" => Ok(Partial),
337            _ => Err(stripe_types::StripeParseError),
338        }
339    }
340}
341impl std::fmt::Display for CreateReversalTaxTransactionMode {
342    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
343        f.write_str(self.as_str())
344    }
345}
346
347impl std::fmt::Debug for CreateReversalTaxTransactionMode {
348    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
349        f.write_str(self.as_str())
350    }
351}
352impl serde::Serialize for CreateReversalTaxTransactionMode {
353    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
354    where
355        S: serde::Serializer,
356    {
357        serializer.serialize_str(self.as_str())
358    }
359}
360#[cfg(feature = "deserialize")]
361impl<'de> serde::Deserialize<'de> for CreateReversalTaxTransactionMode {
362    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
363        use std::str::FromStr;
364        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
365        Self::from_str(&s).map_err(|_| {
366            serde::de::Error::custom("Unknown value for CreateReversalTaxTransactionMode")
367        })
368    }
369}
370/// The shipping cost to reverse.
371#[derive(Copy, Clone, Debug, serde::Serialize)]
372pub struct CreateReversalTaxTransactionShippingCost {
373    /// The amount to reverse, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) in negative.
374    pub amount: i64,
375    /// The amount of tax to reverse, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) in negative.
376    pub amount_tax: i64,
377}
378impl CreateReversalTaxTransactionShippingCost {
379    pub fn new(amount: impl Into<i64>, amount_tax: impl Into<i64>) -> Self {
380        Self { amount: amount.into(), amount_tax: amount_tax.into() }
381    }
382}
383/// Partially or fully reverses a previously created `Transaction`.
384#[derive(Clone, Debug, serde::Serialize)]
385pub struct CreateReversalTaxTransaction {
386    inner: CreateReversalTaxTransactionBuilder,
387}
388impl CreateReversalTaxTransaction {
389    /// Construct a new `CreateReversalTaxTransaction`.
390    pub fn new(
391        mode: impl Into<CreateReversalTaxTransactionMode>,
392        original_transaction: impl Into<String>,
393        reference: impl Into<String>,
394    ) -> Self {
395        Self {
396            inner: CreateReversalTaxTransactionBuilder::new(
397                mode.into(),
398                original_transaction.into(),
399                reference.into(),
400            ),
401        }
402    }
403    /// Specifies which fields in the response should be expanded.
404    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
405        self.inner.expand = Some(expand.into());
406        self
407    }
408    /// A flat amount to reverse across the entire transaction, in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) in negative.
409    /// This value represents the total amount to refund from the transaction, including taxes.
410    pub fn flat_amount(mut self, flat_amount: impl Into<i64>) -> Self {
411        self.inner.flat_amount = Some(flat_amount.into());
412        self
413    }
414    /// The line item amounts to reverse.
415    pub fn line_items(
416        mut self,
417        line_items: impl Into<Vec<CreateReversalTaxTransactionLineItems>>,
418    ) -> Self {
419        self.inner.line_items = Some(line_items.into());
420        self
421    }
422    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
423    /// This can be useful for storing additional information about the object in a structured format.
424    /// Individual keys can be unset by posting an empty value to them.
425    /// All keys can be unset by posting an empty value to `metadata`.
426    pub fn metadata(
427        mut self,
428        metadata: impl Into<std::collections::HashMap<String, String>>,
429    ) -> Self {
430        self.inner.metadata = Some(metadata.into());
431        self
432    }
433    /// The shipping cost to reverse.
434    pub fn shipping_cost(
435        mut self,
436        shipping_cost: impl Into<CreateReversalTaxTransactionShippingCost>,
437    ) -> Self {
438        self.inner.shipping_cost = Some(shipping_cost.into());
439        self
440    }
441}
442impl CreateReversalTaxTransaction {
443    /// Send the request and return the deserialized response.
444    pub async fn send<C: StripeClient>(
445        &self,
446        client: &C,
447    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
448        self.customize().send(client).await
449    }
450
451    /// Send the request and return the deserialized response, blocking until completion.
452    pub fn send_blocking<C: StripeBlockingClient>(
453        &self,
454        client: &C,
455    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
456        self.customize().send_blocking(client)
457    }
458}
459
460impl StripeRequest for CreateReversalTaxTransaction {
461    type Output = stripe_misc::TaxTransaction;
462
463    fn build(&self) -> RequestBuilder {
464        RequestBuilder::new(StripeMethod::Post, "/tax/transactions/create_reversal")
465            .form(&self.inner)
466    }
467}