Skip to main content

stripe_connect/transfer/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Eq, PartialEq)]
6#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
7#[derive(serde::Serialize)]
8struct ListTransferBuilder {
9    #[serde(skip_serializing_if = "Option::is_none")]
10    created: Option<stripe_types::RangeQueryTs>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    destination: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    ending_before: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    expand: Option<Vec<String>>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    limit: Option<i64>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    starting_after: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    transfer_group: Option<String>,
23}
24#[cfg(feature = "redact-generated-debug")]
25impl std::fmt::Debug for ListTransferBuilder {
26    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27        f.debug_struct("ListTransferBuilder").finish_non_exhaustive()
28    }
29}
30impl ListTransferBuilder {
31    fn new() -> Self {
32        Self {
33            created: None,
34            destination: None,
35            ending_before: None,
36            expand: None,
37            limit: None,
38            starting_after: None,
39            transfer_group: None,
40        }
41    }
42}
43/// Returns a list of existing transfers sent to connected accounts.
44/// The transfers are returned in sorted order, with the most recently created transfers appearing first.
45#[derive(Clone)]
46#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
47#[derive(serde::Serialize)]
48pub struct ListTransfer {
49    inner: ListTransferBuilder,
50}
51#[cfg(feature = "redact-generated-debug")]
52impl std::fmt::Debug for ListTransfer {
53    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
54        f.debug_struct("ListTransfer").finish_non_exhaustive()
55    }
56}
57impl ListTransfer {
58    /// Construct a new `ListTransfer`.
59    pub fn new() -> Self {
60        Self { inner: ListTransferBuilder::new() }
61    }
62    /// Only return transfers that were created during the given date interval.
63    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
64        self.inner.created = Some(created.into());
65        self
66    }
67    /// Only return transfers for the destination specified by this account ID.
68    pub fn destination(mut self, destination: impl Into<String>) -> Self {
69        self.inner.destination = Some(destination.into());
70        self
71    }
72    /// A cursor for use in pagination.
73    /// `ending_before` is an object ID that defines your place in the list.
74    /// 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.
75    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
76        self.inner.ending_before = Some(ending_before.into());
77        self
78    }
79    /// Specifies which fields in the response should be expanded.
80    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
81        self.inner.expand = Some(expand.into());
82        self
83    }
84    /// A limit on the number of objects to be returned.
85    /// Limit can range between 1 and 100, and the default is 10.
86    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
87        self.inner.limit = Some(limit.into());
88        self
89    }
90    /// A cursor for use in pagination.
91    /// `starting_after` is an object ID that defines your place in the list.
92    /// 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.
93    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
94        self.inner.starting_after = Some(starting_after.into());
95        self
96    }
97    /// Only return transfers with the specified transfer group.
98    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
99        self.inner.transfer_group = Some(transfer_group.into());
100        self
101    }
102}
103impl Default for ListTransfer {
104    fn default() -> Self {
105        Self::new()
106    }
107}
108impl ListTransfer {
109    /// Send the request and return the deserialized response.
110    pub async fn send<C: StripeClient>(
111        &self,
112        client: &C,
113    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
114        self.customize().send(client).await
115    }
116
117    /// Send the request and return the deserialized response, blocking until completion.
118    pub fn send_blocking<C: StripeBlockingClient>(
119        &self,
120        client: &C,
121    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
122        self.customize().send_blocking(client)
123    }
124
125    pub fn paginate(
126        &self,
127    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::Transfer>> {
128        stripe_client_core::ListPaginator::new_list("/transfers", &self.inner)
129    }
130}
131
132impl StripeRequest for ListTransfer {
133    type Output = stripe_types::List<stripe_shared::Transfer>;
134
135    fn build(&self) -> RequestBuilder {
136        RequestBuilder::new(StripeMethod::Get, "/transfers").query(&self.inner)
137    }
138}
139#[derive(Clone, Eq, PartialEq)]
140#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
141#[derive(serde::Serialize)]
142struct RetrieveTransferBuilder {
143    #[serde(skip_serializing_if = "Option::is_none")]
144    expand: Option<Vec<String>>,
145}
146#[cfg(feature = "redact-generated-debug")]
147impl std::fmt::Debug for RetrieveTransferBuilder {
148    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
149        f.debug_struct("RetrieveTransferBuilder").finish_non_exhaustive()
150    }
151}
152impl RetrieveTransferBuilder {
153    fn new() -> Self {
154        Self { expand: None }
155    }
156}
157/// Retrieves the details of an existing transfer.
158/// Supply the unique transfer ID from either a transfer creation request or the transfer list, and Stripe will return the corresponding transfer information.
159#[derive(Clone)]
160#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
161#[derive(serde::Serialize)]
162pub struct RetrieveTransfer {
163    inner: RetrieveTransferBuilder,
164    transfer: stripe_shared::TransferId,
165}
166#[cfg(feature = "redact-generated-debug")]
167impl std::fmt::Debug for RetrieveTransfer {
168    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169        f.debug_struct("RetrieveTransfer").finish_non_exhaustive()
170    }
171}
172impl RetrieveTransfer {
173    /// Construct a new `RetrieveTransfer`.
174    pub fn new(transfer: impl Into<stripe_shared::TransferId>) -> Self {
175        Self { transfer: transfer.into(), inner: RetrieveTransferBuilder::new() }
176    }
177    /// Specifies which fields in the response should be expanded.
178    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
179        self.inner.expand = Some(expand.into());
180        self
181    }
182}
183impl RetrieveTransfer {
184    /// Send the request and return the deserialized response.
185    pub async fn send<C: StripeClient>(
186        &self,
187        client: &C,
188    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
189        self.customize().send(client).await
190    }
191
192    /// Send the request and return the deserialized response, blocking until completion.
193    pub fn send_blocking<C: StripeBlockingClient>(
194        &self,
195        client: &C,
196    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
197        self.customize().send_blocking(client)
198    }
199}
200
201impl StripeRequest for RetrieveTransfer {
202    type Output = stripe_shared::Transfer;
203
204    fn build(&self) -> RequestBuilder {
205        let transfer = &self.transfer;
206        RequestBuilder::new(StripeMethod::Get, format!("/transfers/{transfer}")).query(&self.inner)
207    }
208}
209#[derive(Clone)]
210#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
211#[derive(serde::Serialize)]
212struct CreateTransferBuilder {
213    #[serde(skip_serializing_if = "Option::is_none")]
214    amount: Option<i64>,
215    currency: stripe_types::Currency,
216    #[serde(skip_serializing_if = "Option::is_none")]
217    description: Option<String>,
218    destination: String,
219    #[serde(skip_serializing_if = "Option::is_none")]
220    expand: Option<Vec<String>>,
221    #[serde(skip_serializing_if = "Option::is_none")]
222    metadata: Option<std::collections::HashMap<String, String>>,
223    #[serde(skip_serializing_if = "Option::is_none")]
224    source_transaction: Option<String>,
225    #[serde(skip_serializing_if = "Option::is_none")]
226    source_type: Option<CreateTransferSourceType>,
227    #[serde(skip_serializing_if = "Option::is_none")]
228    transfer_group: Option<String>,
229}
230#[cfg(feature = "redact-generated-debug")]
231impl std::fmt::Debug for CreateTransferBuilder {
232    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233        f.debug_struct("CreateTransferBuilder").finish_non_exhaustive()
234    }
235}
236impl CreateTransferBuilder {
237    fn new(currency: impl Into<stripe_types::Currency>, destination: impl Into<String>) -> Self {
238        Self {
239            amount: None,
240            currency: currency.into(),
241            description: None,
242            destination: destination.into(),
243            expand: None,
244            metadata: None,
245            source_transaction: None,
246            source_type: None,
247            transfer_group: None,
248        }
249    }
250}
251/// The source balance to use for this transfer.
252/// One of `bank_account`, `card`, or `fpx`.
253/// For most users, this will default to `card`.
254#[derive(Clone, Eq, PartialEq)]
255#[non_exhaustive]
256pub enum CreateTransferSourceType {
257    BankAccount,
258    Card,
259    Fpx,
260    /// An unrecognized value from Stripe. Should not be used as a request parameter.
261    Unknown(String),
262}
263impl CreateTransferSourceType {
264    pub fn as_str(&self) -> &str {
265        use CreateTransferSourceType::*;
266        match self {
267            BankAccount => "bank_account",
268            Card => "card",
269            Fpx => "fpx",
270            Unknown(v) => v,
271        }
272    }
273}
274
275impl std::str::FromStr for CreateTransferSourceType {
276    type Err = std::convert::Infallible;
277    fn from_str(s: &str) -> Result<Self, Self::Err> {
278        use CreateTransferSourceType::*;
279        match s {
280            "bank_account" => Ok(BankAccount),
281            "card" => Ok(Card),
282            "fpx" => Ok(Fpx),
283            v => {
284                tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreateTransferSourceType");
285                Ok(Unknown(v.to_owned()))
286            }
287        }
288    }
289}
290impl std::fmt::Display for CreateTransferSourceType {
291    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
292        f.write_str(self.as_str())
293    }
294}
295
296#[cfg(not(feature = "redact-generated-debug"))]
297impl std::fmt::Debug for CreateTransferSourceType {
298    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
299        f.write_str(self.as_str())
300    }
301}
302#[cfg(feature = "redact-generated-debug")]
303impl std::fmt::Debug for CreateTransferSourceType {
304    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
305        f.debug_struct(stringify!(CreateTransferSourceType)).finish_non_exhaustive()
306    }
307}
308impl serde::Serialize for CreateTransferSourceType {
309    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
310    where
311        S: serde::Serializer,
312    {
313        serializer.serialize_str(self.as_str())
314    }
315}
316#[cfg(feature = "deserialize")]
317impl<'de> serde::Deserialize<'de> for CreateTransferSourceType {
318    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
319        use std::str::FromStr;
320        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
321        Ok(Self::from_str(&s).expect("infallible"))
322    }
323}
324/// To send funds from your Stripe account to a connected account, you create a new transfer object.
325/// Your [Stripe balance](https://stripe.com/docs/api#balance) must be able to cover the transfer amount, or you’ll receive an “Insufficient Funds” error.
326#[derive(Clone)]
327#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
328#[derive(serde::Serialize)]
329pub struct CreateTransfer {
330    inner: CreateTransferBuilder,
331}
332#[cfg(feature = "redact-generated-debug")]
333impl std::fmt::Debug for CreateTransfer {
334    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
335        f.debug_struct("CreateTransfer").finish_non_exhaustive()
336    }
337}
338impl CreateTransfer {
339    /// Construct a new `CreateTransfer`.
340    pub fn new(
341        currency: impl Into<stripe_types::Currency>,
342        destination: impl Into<String>,
343    ) -> Self {
344        Self { inner: CreateTransferBuilder::new(currency.into(), destination.into()) }
345    }
346    /// A positive integer in cents (or local equivalent) representing how much to transfer.
347    pub fn amount(mut self, amount: impl Into<i64>) -> Self {
348        self.inner.amount = Some(amount.into());
349        self
350    }
351    /// An arbitrary string attached to the object. Often useful for displaying to users.
352    pub fn description(mut self, description: impl Into<String>) -> Self {
353        self.inner.description = Some(description.into());
354        self
355    }
356    /// Specifies which fields in the response should be expanded.
357    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
358        self.inner.expand = Some(expand.into());
359        self
360    }
361    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
362    /// This can be useful for storing additional information about the object in a structured format.
363    /// Individual keys can be unset by posting an empty value to them.
364    /// All keys can be unset by posting an empty value to `metadata`.
365    pub fn metadata(
366        mut self,
367        metadata: impl Into<std::collections::HashMap<String, String>>,
368    ) -> Self {
369        self.inner.metadata = Some(metadata.into());
370        self
371    }
372    /// You can use this parameter to transfer funds from a charge before they are added to your available balance.
373    /// A pending balance will transfer immediately but the funds will not become available until the original charge becomes available.
374    /// [See the Connect documentation](https://docs.stripe.com/connect/separate-charges-and-transfers#transfer-availability) for details.
375    pub fn source_transaction(mut self, source_transaction: impl Into<String>) -> Self {
376        self.inner.source_transaction = Some(source_transaction.into());
377        self
378    }
379    /// The source balance to use for this transfer.
380    /// One of `bank_account`, `card`, or `fpx`.
381    /// For most users, this will default to `card`.
382    pub fn source_type(mut self, source_type: impl Into<CreateTransferSourceType>) -> Self {
383        self.inner.source_type = Some(source_type.into());
384        self
385    }
386    /// A string that identifies this transaction as part of a group.
387    /// See the [Connect documentation](https://docs.stripe.com/connect/separate-charges-and-transfers#transfer-options) for details.
388    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
389        self.inner.transfer_group = Some(transfer_group.into());
390        self
391    }
392}
393impl CreateTransfer {
394    /// Send the request and return the deserialized response.
395    pub async fn send<C: StripeClient>(
396        &self,
397        client: &C,
398    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
399        self.customize().send(client).await
400    }
401
402    /// Send the request and return the deserialized response, blocking until completion.
403    pub fn send_blocking<C: StripeBlockingClient>(
404        &self,
405        client: &C,
406    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
407        self.customize().send_blocking(client)
408    }
409}
410
411impl StripeRequest for CreateTransfer {
412    type Output = stripe_shared::Transfer;
413
414    fn build(&self) -> RequestBuilder {
415        RequestBuilder::new(StripeMethod::Post, "/transfers").form(&self.inner)
416    }
417}
418#[derive(Clone)]
419#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
420#[derive(serde::Serialize)]
421struct UpdateTransferBuilder {
422    #[serde(skip_serializing_if = "Option::is_none")]
423    description: Option<String>,
424    #[serde(skip_serializing_if = "Option::is_none")]
425    expand: Option<Vec<String>>,
426    #[serde(skip_serializing_if = "Option::is_none")]
427    metadata: Option<std::collections::HashMap<String, String>>,
428}
429#[cfg(feature = "redact-generated-debug")]
430impl std::fmt::Debug for UpdateTransferBuilder {
431    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
432        f.debug_struct("UpdateTransferBuilder").finish_non_exhaustive()
433    }
434}
435impl UpdateTransferBuilder {
436    fn new() -> Self {
437        Self { description: None, expand: None, metadata: None }
438    }
439}
440/// Updates the specified transfer by setting the values of the parameters passed.
441/// Any parameters not provided will be left unchanged.
442///
443/// This request accepts only metadata as an argument.
444#[derive(Clone)]
445#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
446#[derive(serde::Serialize)]
447pub struct UpdateTransfer {
448    inner: UpdateTransferBuilder,
449    transfer: stripe_shared::TransferId,
450}
451#[cfg(feature = "redact-generated-debug")]
452impl std::fmt::Debug for UpdateTransfer {
453    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
454        f.debug_struct("UpdateTransfer").finish_non_exhaustive()
455    }
456}
457impl UpdateTransfer {
458    /// Construct a new `UpdateTransfer`.
459    pub fn new(transfer: impl Into<stripe_shared::TransferId>) -> Self {
460        Self { transfer: transfer.into(), inner: UpdateTransferBuilder::new() }
461    }
462    /// An arbitrary string attached to the object. Often useful for displaying to users.
463    pub fn description(mut self, description: impl Into<String>) -> Self {
464        self.inner.description = Some(description.into());
465        self
466    }
467    /// Specifies which fields in the response should be expanded.
468    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
469        self.inner.expand = Some(expand.into());
470        self
471    }
472    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
473    /// This can be useful for storing additional information about the object in a structured format.
474    /// Individual keys can be unset by posting an empty value to them.
475    /// All keys can be unset by posting an empty value to `metadata`.
476    pub fn metadata(
477        mut self,
478        metadata: impl Into<std::collections::HashMap<String, String>>,
479    ) -> Self {
480        self.inner.metadata = Some(metadata.into());
481        self
482    }
483}
484impl UpdateTransfer {
485    /// Send the request and return the deserialized response.
486    pub async fn send<C: StripeClient>(
487        &self,
488        client: &C,
489    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
490        self.customize().send(client).await
491    }
492
493    /// Send the request and return the deserialized response, blocking until completion.
494    pub fn send_blocking<C: StripeBlockingClient>(
495        &self,
496        client: &C,
497    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
498        self.customize().send_blocking(client)
499    }
500}
501
502impl StripeRequest for UpdateTransfer {
503    type Output = stripe_shared::Transfer;
504
505    fn build(&self) -> RequestBuilder {
506        let transfer = &self.transfer;
507        RequestBuilder::new(StripeMethod::Post, format!("/transfers/{transfer}")).form(&self.inner)
508    }
509}