1use stripe_client_core::{
2 RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListRefundBuilder {
7 #[serde(skip_serializing_if = "Option::is_none")]
8 charge: Option<String>,
9 #[serde(skip_serializing_if = "Option::is_none")]
10 created: Option<stripe_types::RangeQueryTs>,
11 #[serde(skip_serializing_if = "Option::is_none")]
12 ending_before: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 expand: Option<Vec<String>>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 limit: Option<i64>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 payment_intent: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 starting_after: Option<String>,
21}
22impl ListRefundBuilder {
23 fn new() -> Self {
24 Self {
25 charge: None,
26 created: None,
27 ending_before: None,
28 expand: None,
29 limit: None,
30 payment_intent: None,
31 starting_after: None,
32 }
33 }
34}
35#[derive(Clone, Debug, serde::Serialize)]
39pub struct ListRefund {
40 inner: ListRefundBuilder,
41}
42impl ListRefund {
43 pub fn new() -> Self {
45 Self { inner: ListRefundBuilder::new() }
46 }
47 pub fn charge(mut self, charge: impl Into<String>) -> Self {
49 self.inner.charge = Some(charge.into());
50 self
51 }
52 pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
54 self.inner.created = Some(created.into());
55 self
56 }
57 pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
61 self.inner.ending_before = Some(ending_before.into());
62 self
63 }
64 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
66 self.inner.expand = Some(expand.into());
67 self
68 }
69 pub fn limit(mut self, limit: impl Into<i64>) -> Self {
72 self.inner.limit = Some(limit.into());
73 self
74 }
75 pub fn payment_intent(mut self, payment_intent: impl Into<String>) -> Self {
77 self.inner.payment_intent = Some(payment_intent.into());
78 self
79 }
80 pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
84 self.inner.starting_after = Some(starting_after.into());
85 self
86 }
87}
88impl Default for ListRefund {
89 fn default() -> Self {
90 Self::new()
91 }
92}
93impl ListRefund {
94 pub async fn send<C: StripeClient>(
96 &self,
97 client: &C,
98 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
99 self.customize().send(client).await
100 }
101
102 pub fn send_blocking<C: StripeBlockingClient>(
104 &self,
105 client: &C,
106 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
107 self.customize().send_blocking(client)
108 }
109
110 pub fn paginate(
111 &self,
112 ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::Refund>> {
113 stripe_client_core::ListPaginator::new_list("/refunds", &self.inner)
114 }
115}
116
117impl StripeRequest for ListRefund {
118 type Output = stripe_types::List<stripe_shared::Refund>;
119
120 fn build(&self) -> RequestBuilder {
121 RequestBuilder::new(StripeMethod::Get, "/refunds").query(&self.inner)
122 }
123}
124#[derive(Clone, Debug, serde::Serialize)]
125struct RetrieveRefundBuilder {
126 #[serde(skip_serializing_if = "Option::is_none")]
127 expand: Option<Vec<String>>,
128}
129impl RetrieveRefundBuilder {
130 fn new() -> Self {
131 Self { expand: None }
132 }
133}
134#[derive(Clone, Debug, serde::Serialize)]
136pub struct RetrieveRefund {
137 inner: RetrieveRefundBuilder,
138 refund: stripe_shared::RefundId,
139}
140impl RetrieveRefund {
141 pub fn new(refund: impl Into<stripe_shared::RefundId>) -> Self {
143 Self { refund: refund.into(), inner: RetrieveRefundBuilder::new() }
144 }
145 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
147 self.inner.expand = Some(expand.into());
148 self
149 }
150}
151impl RetrieveRefund {
152 pub async fn send<C: StripeClient>(
154 &self,
155 client: &C,
156 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
157 self.customize().send(client).await
158 }
159
160 pub fn send_blocking<C: StripeBlockingClient>(
162 &self,
163 client: &C,
164 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
165 self.customize().send_blocking(client)
166 }
167}
168
169impl StripeRequest for RetrieveRefund {
170 type Output = stripe_shared::Refund;
171
172 fn build(&self) -> RequestBuilder {
173 let refund = &self.refund;
174 RequestBuilder::new(StripeMethod::Get, format!("/refunds/{refund}")).query(&self.inner)
175 }
176}
177#[derive(Clone, Debug, serde::Serialize)]
178struct CreateRefundBuilder {
179 #[serde(skip_serializing_if = "Option::is_none")]
180 amount: Option<i64>,
181 #[serde(skip_serializing_if = "Option::is_none")]
182 charge: Option<String>,
183 #[serde(skip_serializing_if = "Option::is_none")]
184 currency: Option<stripe_types::Currency>,
185 #[serde(skip_serializing_if = "Option::is_none")]
186 customer: Option<String>,
187 #[serde(skip_serializing_if = "Option::is_none")]
188 expand: Option<Vec<String>>,
189 #[serde(skip_serializing_if = "Option::is_none")]
190 instructions_email: Option<String>,
191 #[serde(skip_serializing_if = "Option::is_none")]
192 metadata: Option<std::collections::HashMap<String, String>>,
193 #[serde(skip_serializing_if = "Option::is_none")]
194 origin: Option<CreateRefundOrigin>,
195 #[serde(skip_serializing_if = "Option::is_none")]
196 payment_intent: Option<String>,
197 #[serde(skip_serializing_if = "Option::is_none")]
198 reason: Option<CreateRefundReason>,
199 #[serde(skip_serializing_if = "Option::is_none")]
200 refund_application_fee: Option<bool>,
201 #[serde(skip_serializing_if = "Option::is_none")]
202 reverse_transfer: Option<bool>,
203}
204impl CreateRefundBuilder {
205 fn new() -> Self {
206 Self {
207 amount: None,
208 charge: None,
209 currency: None,
210 customer: None,
211 expand: None,
212 instructions_email: None,
213 metadata: None,
214 origin: None,
215 payment_intent: None,
216 reason: None,
217 refund_application_fee: None,
218 reverse_transfer: None,
219 }
220 }
221}
222#[derive(Copy, Clone, Eq, PartialEq)]
224pub enum CreateRefundOrigin {
225 CustomerBalance,
226}
227impl CreateRefundOrigin {
228 pub fn as_str(self) -> &'static str {
229 use CreateRefundOrigin::*;
230 match self {
231 CustomerBalance => "customer_balance",
232 }
233 }
234}
235
236impl std::str::FromStr for CreateRefundOrigin {
237 type Err = stripe_types::StripeParseError;
238 fn from_str(s: &str) -> Result<Self, Self::Err> {
239 use CreateRefundOrigin::*;
240 match s {
241 "customer_balance" => Ok(CustomerBalance),
242 _ => Err(stripe_types::StripeParseError),
243 }
244 }
245}
246impl std::fmt::Display for CreateRefundOrigin {
247 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
248 f.write_str(self.as_str())
249 }
250}
251
252impl std::fmt::Debug for CreateRefundOrigin {
253 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
254 f.write_str(self.as_str())
255 }
256}
257impl serde::Serialize for CreateRefundOrigin {
258 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
259 where
260 S: serde::Serializer,
261 {
262 serializer.serialize_str(self.as_str())
263 }
264}
265#[cfg(feature = "deserialize")]
266impl<'de> serde::Deserialize<'de> for CreateRefundOrigin {
267 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
268 use std::str::FromStr;
269 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
270 Self::from_str(&s)
271 .map_err(|_| serde::de::Error::custom("Unknown value for CreateRefundOrigin"))
272 }
273}
274#[derive(Copy, Clone, Eq, PartialEq)]
278pub enum CreateRefundReason {
279 Duplicate,
280 Fraudulent,
281 RequestedByCustomer,
282}
283impl CreateRefundReason {
284 pub fn as_str(self) -> &'static str {
285 use CreateRefundReason::*;
286 match self {
287 Duplicate => "duplicate",
288 Fraudulent => "fraudulent",
289 RequestedByCustomer => "requested_by_customer",
290 }
291 }
292}
293
294impl std::str::FromStr for CreateRefundReason {
295 type Err = stripe_types::StripeParseError;
296 fn from_str(s: &str) -> Result<Self, Self::Err> {
297 use CreateRefundReason::*;
298 match s {
299 "duplicate" => Ok(Duplicate),
300 "fraudulent" => Ok(Fraudulent),
301 "requested_by_customer" => Ok(RequestedByCustomer),
302 _ => Err(stripe_types::StripeParseError),
303 }
304 }
305}
306impl std::fmt::Display for CreateRefundReason {
307 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
308 f.write_str(self.as_str())
309 }
310}
311
312impl std::fmt::Debug for CreateRefundReason {
313 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
314 f.write_str(self.as_str())
315 }
316}
317impl serde::Serialize for CreateRefundReason {
318 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
319 where
320 S: serde::Serializer,
321 {
322 serializer.serialize_str(self.as_str())
323 }
324}
325#[cfg(feature = "deserialize")]
326impl<'de> serde::Deserialize<'de> for CreateRefundReason {
327 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
328 use std::str::FromStr;
329 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
330 Self::from_str(&s)
331 .map_err(|_| serde::de::Error::custom("Unknown value for CreateRefundReason"))
332 }
333}
334#[derive(Clone, Debug, serde::Serialize)]
346pub struct CreateRefund {
347 inner: CreateRefundBuilder,
348}
349impl CreateRefund {
350 pub fn new() -> Self {
352 Self { inner: CreateRefundBuilder::new() }
353 }
354 pub fn amount(mut self, amount: impl Into<i64>) -> Self {
355 self.inner.amount = Some(amount.into());
356 self
357 }
358 pub fn charge(mut self, charge: impl Into<String>) -> Self {
360 self.inner.charge = Some(charge.into());
361 self
362 }
363 pub fn currency(mut self, currency: impl Into<stripe_types::Currency>) -> Self {
366 self.inner.currency = Some(currency.into());
367 self
368 }
369 pub fn customer(mut self, customer: impl Into<String>) -> Self {
371 self.inner.customer = Some(customer.into());
372 self
373 }
374 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
376 self.inner.expand = Some(expand.into());
377 self
378 }
379 pub fn instructions_email(mut self, instructions_email: impl Into<String>) -> Self {
381 self.inner.instructions_email = Some(instructions_email.into());
382 self
383 }
384 pub fn metadata(
389 mut self,
390 metadata: impl Into<std::collections::HashMap<String, String>>,
391 ) -> Self {
392 self.inner.metadata = Some(metadata.into());
393 self
394 }
395 pub fn origin(mut self, origin: impl Into<CreateRefundOrigin>) -> Self {
397 self.inner.origin = Some(origin.into());
398 self
399 }
400 pub fn payment_intent(mut self, payment_intent: impl Into<String>) -> Self {
402 self.inner.payment_intent = Some(payment_intent.into());
403 self
404 }
405 pub fn reason(mut self, reason: impl Into<CreateRefundReason>) -> Self {
409 self.inner.reason = Some(reason.into());
410 self
411 }
412 pub fn refund_application_fee(mut self, refund_application_fee: impl Into<bool>) -> Self {
417 self.inner.refund_application_fee = Some(refund_application_fee.into());
418 self
419 }
420 pub fn reverse_transfer(mut self, reverse_transfer: impl Into<bool>) -> Self {
425 self.inner.reverse_transfer = Some(reverse_transfer.into());
426 self
427 }
428}
429impl Default for CreateRefund {
430 fn default() -> Self {
431 Self::new()
432 }
433}
434impl CreateRefund {
435 pub async fn send<C: StripeClient>(
437 &self,
438 client: &C,
439 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
440 self.customize().send(client).await
441 }
442
443 pub fn send_blocking<C: StripeBlockingClient>(
445 &self,
446 client: &C,
447 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
448 self.customize().send_blocking(client)
449 }
450}
451
452impl StripeRequest for CreateRefund {
453 type Output = stripe_shared::Refund;
454
455 fn build(&self) -> RequestBuilder {
456 RequestBuilder::new(StripeMethod::Post, "/refunds").form(&self.inner)
457 }
458}
459#[derive(Clone, Debug, serde::Serialize)]
460struct UpdateRefundBuilder {
461 #[serde(skip_serializing_if = "Option::is_none")]
462 expand: Option<Vec<String>>,
463 #[serde(skip_serializing_if = "Option::is_none")]
464 metadata: Option<std::collections::HashMap<String, String>>,
465}
466impl UpdateRefundBuilder {
467 fn new() -> Self {
468 Self { expand: None, metadata: None }
469 }
470}
471#[derive(Clone, Debug, serde::Serialize)]
476pub struct UpdateRefund {
477 inner: UpdateRefundBuilder,
478 refund: stripe_shared::RefundId,
479}
480impl UpdateRefund {
481 pub fn new(refund: impl Into<stripe_shared::RefundId>) -> Self {
483 Self { refund: refund.into(), inner: UpdateRefundBuilder::new() }
484 }
485 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
487 self.inner.expand = Some(expand.into());
488 self
489 }
490 pub fn metadata(
495 mut self,
496 metadata: impl Into<std::collections::HashMap<String, String>>,
497 ) -> Self {
498 self.inner.metadata = Some(metadata.into());
499 self
500 }
501}
502impl UpdateRefund {
503 pub async fn send<C: StripeClient>(
505 &self,
506 client: &C,
507 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
508 self.customize().send(client).await
509 }
510
511 pub fn send_blocking<C: StripeBlockingClient>(
513 &self,
514 client: &C,
515 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
516 self.customize().send_blocking(client)
517 }
518}
519
520impl StripeRequest for UpdateRefund {
521 type Output = stripe_shared::Refund;
522
523 fn build(&self) -> RequestBuilder {
524 let refund = &self.refund;
525 RequestBuilder::new(StripeMethod::Post, format!("/refunds/{refund}")).form(&self.inner)
526 }
527}
528#[derive(Clone, Debug, serde::Serialize)]
529struct CancelRefundBuilder {
530 #[serde(skip_serializing_if = "Option::is_none")]
531 expand: Option<Vec<String>>,
532}
533impl CancelRefundBuilder {
534 fn new() -> Self {
535 Self { expand: None }
536 }
537}
538#[derive(Clone, Debug, serde::Serialize)]
543pub struct CancelRefund {
544 inner: CancelRefundBuilder,
545 refund: stripe_shared::RefundId,
546}
547impl CancelRefund {
548 pub fn new(refund: impl Into<stripe_shared::RefundId>) -> Self {
550 Self { refund: refund.into(), inner: CancelRefundBuilder::new() }
551 }
552 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
554 self.inner.expand = Some(expand.into());
555 self
556 }
557}
558impl CancelRefund {
559 pub async fn send<C: StripeClient>(
561 &self,
562 client: &C,
563 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
564 self.customize().send(client).await
565 }
566
567 pub fn send_blocking<C: StripeBlockingClient>(
569 &self,
570 client: &C,
571 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
572 self.customize().send_blocking(client)
573 }
574}
575
576impl StripeRequest for CancelRefund {
577 type Output = stripe_shared::Refund;
578
579 fn build(&self) -> RequestBuilder {
580 let refund = &self.refund;
581 RequestBuilder::new(StripeMethod::Post, format!("/refunds/{refund}/cancel"))
582 .form(&self.inner)
583 }
584}
585#[derive(Clone, Debug, serde::Serialize)]
586struct ExpireRefundBuilder {
587 #[serde(skip_serializing_if = "Option::is_none")]
588 expand: Option<Vec<String>>,
589}
590impl ExpireRefundBuilder {
591 fn new() -> Self {
592 Self { expand: None }
593 }
594}
595#[derive(Clone, Debug, serde::Serialize)]
597pub struct ExpireRefund {
598 inner: ExpireRefundBuilder,
599 refund: String,
600}
601impl ExpireRefund {
602 pub fn new(refund: impl Into<String>) -> Self {
604 Self { refund: refund.into(), inner: ExpireRefundBuilder::new() }
605 }
606 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
608 self.inner.expand = Some(expand.into());
609 self
610 }
611}
612impl ExpireRefund {
613 pub async fn send<C: StripeClient>(
615 &self,
616 client: &C,
617 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
618 self.customize().send(client).await
619 }
620
621 pub fn send_blocking<C: StripeBlockingClient>(
623 &self,
624 client: &C,
625 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
626 self.customize().send_blocking(client)
627 }
628}
629
630impl StripeRequest for ExpireRefund {
631 type Output = stripe_shared::Refund;
632
633 fn build(&self) -> RequestBuilder {
634 let refund = &self.refund;
635 RequestBuilder::new(StripeMethod::Post, format!("/test_helpers/refunds/{refund}/expire"))
636 .form(&self.inner)
637 }
638}