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#[derive(Clone, Debug, serde::Serialize)]
17pub struct RetrieveTaxTransaction {
18 inner: RetrieveTaxTransactionBuilder,
19 transaction: stripe_misc::TaxTransactionId,
20}
21impl RetrieveTaxTransaction {
22 pub fn new(transaction: impl Into<stripe_misc::TaxTransactionId>) -> Self {
24 Self { transaction: transaction.into(), inner: RetrieveTaxTransactionBuilder::new() }
25 }
26 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 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 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#[derive(Clone, Debug, serde::Serialize)]
77pub struct ListLineItemsTaxTransaction {
78 inner: ListLineItemsTaxTransactionBuilder,
79 transaction: stripe_misc::TaxTransactionId,
80}
81impl ListLineItemsTaxTransaction {
82 pub fn new(transaction: impl Into<stripe_misc::TaxTransactionId>) -> Self {
84 Self { transaction: transaction.into(), inner: ListLineItemsTaxTransactionBuilder::new() }
85 }
86 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 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
95 self.inner.expand = Some(expand.into());
96 self
97 }
98 pub fn limit(mut self, limit: impl Into<i64>) -> Self {
101 self.inner.limit = Some(limit.into());
102 self
103 }
104 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 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 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#[derive(Clone, Debug, serde::Serialize)]
179pub struct CreateFromCalculationTaxTransaction {
180 inner: CreateFromCalculationTaxTransactionBuilder,
181}
182impl CreateFromCalculationTaxTransaction {
183 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 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
194 self.inner.expand = Some(expand.into());
195 self
196 }
197 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 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 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 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#[derive(Clone, Debug, serde::Serialize)]
278pub struct CreateReversalTaxTransactionLineItems {
279 pub amount: i64,
281 pub amount_tax: i64,
283 #[serde(skip_serializing_if = "Option::is_none")]
286 pub metadata: Option<std::collections::HashMap<String, String>>,
287 pub original_line_item: String,
289 #[serde(skip_serializing_if = "Option::is_none")]
292 pub quantity: Option<u64>,
293 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#[derive(Clone, Eq, PartialEq)]
316#[non_exhaustive]
317pub enum CreateReversalTaxTransactionMode {
318 Full,
319 Partial,
320 Unknown(String),
322}
323impl CreateReversalTaxTransactionMode {
324 pub fn as_str(&self) -> &str {
325 use CreateReversalTaxTransactionMode::*;
326 match self {
327 Full => "full",
328 Partial => "partial",
329 Unknown(v) => v,
330 }
331 }
332}
333
334impl std::str::FromStr for CreateReversalTaxTransactionMode {
335 type Err = std::convert::Infallible;
336 fn from_str(s: &str) -> Result<Self, Self::Err> {
337 use CreateReversalTaxTransactionMode::*;
338 match s {
339 "full" => Ok(Full),
340 "partial" => Ok(Partial),
341 v => {
342 tracing::warn!(
343 "Unknown value '{}' for enum '{}'",
344 v,
345 "CreateReversalTaxTransactionMode"
346 );
347 Ok(Unknown(v.to_owned()))
348 }
349 }
350 }
351}
352impl std::fmt::Display for CreateReversalTaxTransactionMode {
353 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
354 f.write_str(self.as_str())
355 }
356}
357
358impl std::fmt::Debug for CreateReversalTaxTransactionMode {
359 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
360 f.write_str(self.as_str())
361 }
362}
363impl serde::Serialize for CreateReversalTaxTransactionMode {
364 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
365 where
366 S: serde::Serializer,
367 {
368 serializer.serialize_str(self.as_str())
369 }
370}
371#[cfg(feature = "deserialize")]
372impl<'de> serde::Deserialize<'de> for CreateReversalTaxTransactionMode {
373 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
374 use std::str::FromStr;
375 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
376 Ok(Self::from_str(&s).expect("infallible"))
377 }
378}
379#[derive(Copy, Clone, Debug, serde::Serialize)]
381pub struct CreateReversalTaxTransactionShippingCost {
382 pub amount: i64,
384 pub amount_tax: i64,
386}
387impl CreateReversalTaxTransactionShippingCost {
388 pub fn new(amount: impl Into<i64>, amount_tax: impl Into<i64>) -> Self {
389 Self { amount: amount.into(), amount_tax: amount_tax.into() }
390 }
391}
392#[derive(Clone, Debug, serde::Serialize)]
394pub struct CreateReversalTaxTransaction {
395 inner: CreateReversalTaxTransactionBuilder,
396}
397impl CreateReversalTaxTransaction {
398 pub fn new(
400 mode: impl Into<CreateReversalTaxTransactionMode>,
401 original_transaction: impl Into<String>,
402 reference: impl Into<String>,
403 ) -> Self {
404 Self {
405 inner: CreateReversalTaxTransactionBuilder::new(
406 mode.into(),
407 original_transaction.into(),
408 reference.into(),
409 ),
410 }
411 }
412 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
414 self.inner.expand = Some(expand.into());
415 self
416 }
417 pub fn flat_amount(mut self, flat_amount: impl Into<i64>) -> Self {
420 self.inner.flat_amount = Some(flat_amount.into());
421 self
422 }
423 pub fn line_items(
425 mut self,
426 line_items: impl Into<Vec<CreateReversalTaxTransactionLineItems>>,
427 ) -> Self {
428 self.inner.line_items = Some(line_items.into());
429 self
430 }
431 pub fn metadata(
436 mut self,
437 metadata: impl Into<std::collections::HashMap<String, String>>,
438 ) -> Self {
439 self.inner.metadata = Some(metadata.into());
440 self
441 }
442 pub fn shipping_cost(
444 mut self,
445 shipping_cost: impl Into<CreateReversalTaxTransactionShippingCost>,
446 ) -> Self {
447 self.inner.shipping_cost = Some(shipping_cost.into());
448 self
449 }
450}
451impl CreateReversalTaxTransaction {
452 pub async fn send<C: StripeClient>(
454 &self,
455 client: &C,
456 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
457 self.customize().send(client).await
458 }
459
460 pub fn send_blocking<C: StripeBlockingClient>(
462 &self,
463 client: &C,
464 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
465 self.customize().send_blocking(client)
466 }
467}
468
469impl StripeRequest for CreateReversalTaxTransaction {
470 type Output = stripe_misc::TaxTransaction;
471
472 fn build(&self) -> RequestBuilder {
473 RequestBuilder::new(StripeMethod::Post, "/tax/transactions/create_reversal")
474 .form(&self.inner)
475 }
476}