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(Clone, Eq, PartialEq)]
224#[non_exhaustive]
225pub enum CreateRefundOrigin {
226 CustomerBalance,
227 Unknown(String),
229}
230impl CreateRefundOrigin {
231 pub fn as_str(&self) -> &str {
232 use CreateRefundOrigin::*;
233 match self {
234 CustomerBalance => "customer_balance",
235 Unknown(v) => v,
236 }
237 }
238}
239
240impl std::str::FromStr for CreateRefundOrigin {
241 type Err = std::convert::Infallible;
242 fn from_str(s: &str) -> Result<Self, Self::Err> {
243 use CreateRefundOrigin::*;
244 match s {
245 "customer_balance" => Ok(CustomerBalance),
246 v => {
247 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreateRefundOrigin");
248 Ok(Unknown(v.to_owned()))
249 }
250 }
251 }
252}
253impl std::fmt::Display for CreateRefundOrigin {
254 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
255 f.write_str(self.as_str())
256 }
257}
258
259impl std::fmt::Debug for CreateRefundOrigin {
260 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261 f.write_str(self.as_str())
262 }
263}
264impl serde::Serialize for CreateRefundOrigin {
265 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
266 where
267 S: serde::Serializer,
268 {
269 serializer.serialize_str(self.as_str())
270 }
271}
272#[cfg(feature = "deserialize")]
273impl<'de> serde::Deserialize<'de> for CreateRefundOrigin {
274 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
275 use std::str::FromStr;
276 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
277 Ok(Self::from_str(&s).expect("infallible"))
278 }
279}
280#[derive(Clone, Eq, PartialEq)]
284#[non_exhaustive]
285pub enum CreateRefundReason {
286 Duplicate,
287 Fraudulent,
288 RequestedByCustomer,
289 Unknown(String),
291}
292impl CreateRefundReason {
293 pub fn as_str(&self) -> &str {
294 use CreateRefundReason::*;
295 match self {
296 Duplicate => "duplicate",
297 Fraudulent => "fraudulent",
298 RequestedByCustomer => "requested_by_customer",
299 Unknown(v) => v,
300 }
301 }
302}
303
304impl std::str::FromStr for CreateRefundReason {
305 type Err = std::convert::Infallible;
306 fn from_str(s: &str) -> Result<Self, Self::Err> {
307 use CreateRefundReason::*;
308 match s {
309 "duplicate" => Ok(Duplicate),
310 "fraudulent" => Ok(Fraudulent),
311 "requested_by_customer" => Ok(RequestedByCustomer),
312 v => {
313 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreateRefundReason");
314 Ok(Unknown(v.to_owned()))
315 }
316 }
317 }
318}
319impl std::fmt::Display for CreateRefundReason {
320 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
321 f.write_str(self.as_str())
322 }
323}
324
325impl std::fmt::Debug for CreateRefundReason {
326 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
327 f.write_str(self.as_str())
328 }
329}
330impl serde::Serialize for CreateRefundReason {
331 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
332 where
333 S: serde::Serializer,
334 {
335 serializer.serialize_str(self.as_str())
336 }
337}
338#[cfg(feature = "deserialize")]
339impl<'de> serde::Deserialize<'de> for CreateRefundReason {
340 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
341 use std::str::FromStr;
342 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
343 Ok(Self::from_str(&s).expect("infallible"))
344 }
345}
346#[derive(Clone, Debug, serde::Serialize)]
358pub struct CreateRefund {
359 inner: CreateRefundBuilder,
360}
361impl CreateRefund {
362 pub fn new() -> Self {
364 Self { inner: CreateRefundBuilder::new() }
365 }
366 pub fn amount(mut self, amount: impl Into<i64>) -> Self {
367 self.inner.amount = Some(amount.into());
368 self
369 }
370 pub fn charge(mut self, charge: impl Into<String>) -> Self {
372 self.inner.charge = Some(charge.into());
373 self
374 }
375 pub fn currency(mut self, currency: impl Into<stripe_types::Currency>) -> Self {
378 self.inner.currency = Some(currency.into());
379 self
380 }
381 pub fn customer(mut self, customer: impl Into<String>) -> Self {
383 self.inner.customer = Some(customer.into());
384 self
385 }
386 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
388 self.inner.expand = Some(expand.into());
389 self
390 }
391 pub fn instructions_email(mut self, instructions_email: impl Into<String>) -> Self {
393 self.inner.instructions_email = Some(instructions_email.into());
394 self
395 }
396 pub fn metadata(
401 mut self,
402 metadata: impl Into<std::collections::HashMap<String, String>>,
403 ) -> Self {
404 self.inner.metadata = Some(metadata.into());
405 self
406 }
407 pub fn origin(mut self, origin: impl Into<CreateRefundOrigin>) -> Self {
409 self.inner.origin = Some(origin.into());
410 self
411 }
412 pub fn payment_intent(mut self, payment_intent: impl Into<String>) -> Self {
414 self.inner.payment_intent = Some(payment_intent.into());
415 self
416 }
417 pub fn reason(mut self, reason: impl Into<CreateRefundReason>) -> Self {
421 self.inner.reason = Some(reason.into());
422 self
423 }
424 pub fn refund_application_fee(mut self, refund_application_fee: impl Into<bool>) -> Self {
429 self.inner.refund_application_fee = Some(refund_application_fee.into());
430 self
431 }
432 pub fn reverse_transfer(mut self, reverse_transfer: impl Into<bool>) -> Self {
437 self.inner.reverse_transfer = Some(reverse_transfer.into());
438 self
439 }
440}
441impl Default for CreateRefund {
442 fn default() -> Self {
443 Self::new()
444 }
445}
446impl CreateRefund {
447 pub async fn send<C: StripeClient>(
449 &self,
450 client: &C,
451 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
452 self.customize().send(client).await
453 }
454
455 pub fn send_blocking<C: StripeBlockingClient>(
457 &self,
458 client: &C,
459 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
460 self.customize().send_blocking(client)
461 }
462}
463
464impl StripeRequest for CreateRefund {
465 type Output = stripe_shared::Refund;
466
467 fn build(&self) -> RequestBuilder {
468 RequestBuilder::new(StripeMethod::Post, "/refunds").form(&self.inner)
469 }
470}
471#[derive(Clone, Debug, serde::Serialize)]
472struct UpdateRefundBuilder {
473 #[serde(skip_serializing_if = "Option::is_none")]
474 expand: Option<Vec<String>>,
475 #[serde(skip_serializing_if = "Option::is_none")]
476 metadata: Option<std::collections::HashMap<String, String>>,
477}
478impl UpdateRefundBuilder {
479 fn new() -> Self {
480 Self { expand: None, metadata: None }
481 }
482}
483#[derive(Clone, Debug, serde::Serialize)]
488pub struct UpdateRefund {
489 inner: UpdateRefundBuilder,
490 refund: stripe_shared::RefundId,
491}
492impl UpdateRefund {
493 pub fn new(refund: impl Into<stripe_shared::RefundId>) -> Self {
495 Self { refund: refund.into(), inner: UpdateRefundBuilder::new() }
496 }
497 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
499 self.inner.expand = Some(expand.into());
500 self
501 }
502 pub fn metadata(
507 mut self,
508 metadata: impl Into<std::collections::HashMap<String, String>>,
509 ) -> Self {
510 self.inner.metadata = Some(metadata.into());
511 self
512 }
513}
514impl UpdateRefund {
515 pub async fn send<C: StripeClient>(
517 &self,
518 client: &C,
519 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
520 self.customize().send(client).await
521 }
522
523 pub fn send_blocking<C: StripeBlockingClient>(
525 &self,
526 client: &C,
527 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
528 self.customize().send_blocking(client)
529 }
530}
531
532impl StripeRequest for UpdateRefund {
533 type Output = stripe_shared::Refund;
534
535 fn build(&self) -> RequestBuilder {
536 let refund = &self.refund;
537 RequestBuilder::new(StripeMethod::Post, format!("/refunds/{refund}")).form(&self.inner)
538 }
539}
540#[derive(Clone, Debug, serde::Serialize)]
541struct CancelRefundBuilder {
542 #[serde(skip_serializing_if = "Option::is_none")]
543 expand: Option<Vec<String>>,
544}
545impl CancelRefundBuilder {
546 fn new() -> Self {
547 Self { expand: None }
548 }
549}
550#[derive(Clone, Debug, serde::Serialize)]
555pub struct CancelRefund {
556 inner: CancelRefundBuilder,
557 refund: stripe_shared::RefundId,
558}
559impl CancelRefund {
560 pub fn new(refund: impl Into<stripe_shared::RefundId>) -> Self {
562 Self { refund: refund.into(), inner: CancelRefundBuilder::new() }
563 }
564 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
566 self.inner.expand = Some(expand.into());
567 self
568 }
569}
570impl CancelRefund {
571 pub async fn send<C: StripeClient>(
573 &self,
574 client: &C,
575 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
576 self.customize().send(client).await
577 }
578
579 pub fn send_blocking<C: StripeBlockingClient>(
581 &self,
582 client: &C,
583 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
584 self.customize().send_blocking(client)
585 }
586}
587
588impl StripeRequest for CancelRefund {
589 type Output = stripe_shared::Refund;
590
591 fn build(&self) -> RequestBuilder {
592 let refund = &self.refund;
593 RequestBuilder::new(StripeMethod::Post, format!("/refunds/{refund}/cancel"))
594 .form(&self.inner)
595 }
596}
597#[derive(Clone, Debug, serde::Serialize)]
598struct ExpireRefundBuilder {
599 #[serde(skip_serializing_if = "Option::is_none")]
600 expand: Option<Vec<String>>,
601}
602impl ExpireRefundBuilder {
603 fn new() -> Self {
604 Self { expand: None }
605 }
606}
607#[derive(Clone, Debug, serde::Serialize)]
609pub struct ExpireRefund {
610 inner: ExpireRefundBuilder,
611 refund: String,
612}
613impl ExpireRefund {
614 pub fn new(refund: impl Into<String>) -> Self {
616 Self { refund: refund.into(), inner: ExpireRefundBuilder::new() }
617 }
618 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
620 self.inner.expand = Some(expand.into());
621 self
622 }
623}
624impl ExpireRefund {
625 pub async fn send<C: StripeClient>(
627 &self,
628 client: &C,
629 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
630 self.customize().send(client).await
631 }
632
633 pub fn send_blocking<C: StripeBlockingClient>(
635 &self,
636 client: &C,
637 ) -> Result<<Self as StripeRequest>::Output, C::Err> {
638 self.customize().send_blocking(client)
639 }
640}
641
642impl StripeRequest for ExpireRefund {
643 type Output = stripe_shared::Refund;
644
645 fn build(&self) -> RequestBuilder {
646 let refund = &self.refund;
647 RequestBuilder::new(StripeMethod::Post, format!("/test_helpers/refunds/{refund}/expire"))
648 .form(&self.inner)
649 }
650}