stripe_shared/
payout.rs

1/// A `Payout` object is created when you receive funds from Stripe, or when you
2/// initiate a payout to either a bank account or debit card of a [connected
3/// Stripe account](/docs/connect/bank-debit-card-payouts). You can retrieve individual payouts,
4/// and list all payouts. Payouts are made on [varying
5/// schedules](/docs/connect/manage-payout-schedule), depending on your country and
6/// industry.
7///
8/// Related guide: [Receiving payouts](https://stripe.com/docs/payouts)
9///
10/// For more details see <<https://stripe.com/docs/api/payouts/object>>.
11#[derive(Clone, Debug)]
12#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
13pub struct Payout {
14    /// The amount (in cents (or local equivalent)) that transfers to your bank account or debit card.
15    pub amount: i64,
16    /// The application fee (if any) for the payout.
17    /// [See the Connect documentation](https://stripe.com/docs/connect/instant-payouts#monetization-and-fees) for details.
18    pub application_fee: Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>,
19    /// The amount of the application fee (if any) requested for the payout.
20    /// [See the Connect documentation](https://stripe.com/docs/connect/instant-payouts#monetization-and-fees) for details.
21    pub application_fee_amount: Option<i64>,
22    /// Date that you can expect the payout to arrive in the bank.
23    /// This factors in delays to account for weekends or bank holidays.
24    pub arrival_date: stripe_types::Timestamp,
25    /// Returns `true` if the payout is created by an [automated payout schedule](https://stripe.com/docs/payouts#payout-schedule) and `false` if it's [requested manually](https://stripe.com/docs/payouts#manual-payouts).
26    pub automatic: bool,
27    /// ID of the balance transaction that describes the impact of this payout on your account balance.
28    pub balance_transaction: Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
29    /// Time at which the object was created. Measured in seconds since the Unix epoch.
30    pub created: stripe_types::Timestamp,
31    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
32    /// Must be a [supported currency](https://stripe.com/docs/currencies).
33    pub currency: stripe_types::Currency,
34    /// An arbitrary string attached to the object. Often useful for displaying to users.
35    pub description: Option<String>,
36    /// ID of the bank account or card the payout is sent to.
37    pub destination: Option<stripe_types::Expandable<stripe_shared::ExternalAccount>>,
38    /// If the payout fails or cancels, this is the ID of the balance transaction that reverses the initial balance transaction and returns the funds from the failed payout back in your balance.
39    pub failure_balance_transaction:
40        Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
41    /// Error code that provides a reason for a payout failure, if available.
42    /// View our [list of failure codes](https://stripe.com/docs/api#payout_failures).
43    pub failure_code: Option<String>,
44    /// Message that provides the reason for a payout failure, if available.
45    pub failure_message: Option<String>,
46    /// Unique identifier for the object.
47    pub id: stripe_shared::PayoutId,
48    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
49    pub livemode: bool,
50    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
51    /// This can be useful for storing additional information about the object in a structured format.
52    pub metadata: Option<std::collections::HashMap<String, String>>,
53    /// The method used to send this payout, which can be `standard` or `instant`.
54    /// `instant` is supported for payouts to debit cards and bank accounts in certain countries.
55    /// Learn more about [bank support for Instant Payouts](https://stripe.com/docs/payouts/instant-payouts-banks).
56    pub method: String,
57    /// If the payout reverses another, this is the ID of the original payout.
58    pub original_payout: Option<stripe_types::Expandable<stripe_shared::Payout>>,
59    /// ID of the v2 FinancialAccount the funds are sent to.
60    pub payout_method: Option<String>,
61    /// If `completed`, you can use the [Balance Transactions API](https://stripe.com/docs/api/balance_transactions/list#balance_transaction_list-payout) to list all balance transactions that are paid out in this payout.
62    pub reconciliation_status: PayoutReconciliationStatus,
63    /// If the payout reverses, this is the ID of the payout that reverses this payout.
64    pub reversed_by: Option<stripe_types::Expandable<stripe_shared::Payout>>,
65    /// The source balance this payout came from, which can be one of the following: `card`, `fpx`, or `bank_account`.
66    pub source_type: String,
67    /// Extra information about a payout that displays on the user's bank statement.
68    pub statement_descriptor: Option<String>,
69    /// Current status of the payout: `paid`, `pending`, `in_transit`, `canceled` or `failed`.
70    /// A payout is `pending` until it's submitted to the bank, when it becomes `in_transit`.
71    /// The status changes to `paid` if the transaction succeeds, or to `failed` or `canceled` (within 5 business days).
72    /// Some payouts that fail might initially show as `paid`, then change to `failed`.
73    pub status: String,
74    /// A value that generates from the beneficiary's bank that allows users to track payouts with their bank.
75    /// Banks might call this a "reference number" or something similar.
76    pub trace_id: Option<stripe_shared::PayoutsTraceId>,
77    /// Can be `bank_account` or `card`.
78    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
79    pub type_: PayoutType,
80}
81#[doc(hidden)]
82pub struct PayoutBuilder {
83    amount: Option<i64>,
84    application_fee: Option<Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>>,
85    application_fee_amount: Option<Option<i64>>,
86    arrival_date: Option<stripe_types::Timestamp>,
87    automatic: Option<bool>,
88    balance_transaction:
89        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
90    created: Option<stripe_types::Timestamp>,
91    currency: Option<stripe_types::Currency>,
92    description: Option<Option<String>>,
93    destination: Option<Option<stripe_types::Expandable<stripe_shared::ExternalAccount>>>,
94    failure_balance_transaction:
95        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
96    failure_code: Option<Option<String>>,
97    failure_message: Option<Option<String>>,
98    id: Option<stripe_shared::PayoutId>,
99    livemode: Option<bool>,
100    metadata: Option<Option<std::collections::HashMap<String, String>>>,
101    method: Option<String>,
102    original_payout: Option<Option<stripe_types::Expandable<stripe_shared::Payout>>>,
103    payout_method: Option<Option<String>>,
104    reconciliation_status: Option<PayoutReconciliationStatus>,
105    reversed_by: Option<Option<stripe_types::Expandable<stripe_shared::Payout>>>,
106    source_type: Option<String>,
107    statement_descriptor: Option<Option<String>>,
108    status: Option<String>,
109    trace_id: Option<Option<stripe_shared::PayoutsTraceId>>,
110    type_: Option<PayoutType>,
111}
112
113#[allow(
114    unused_variables,
115    irrefutable_let_patterns,
116    clippy::let_unit_value,
117    clippy::match_single_binding,
118    clippy::single_match
119)]
120const _: () = {
121    use miniserde::de::{Map, Visitor};
122    use miniserde::json::Value;
123    use miniserde::{Deserialize, Result, make_place};
124    use stripe_types::miniserde_helpers::FromValueOpt;
125    use stripe_types::{MapBuilder, ObjectDeser};
126
127    make_place!(Place);
128
129    impl Deserialize for Payout {
130        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
131            Place::new(out)
132        }
133    }
134
135    struct Builder<'a> {
136        out: &'a mut Option<Payout>,
137        builder: PayoutBuilder,
138    }
139
140    impl Visitor for Place<Payout> {
141        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
142            Ok(Box::new(Builder { out: &mut self.out, builder: PayoutBuilder::deser_default() }))
143        }
144    }
145
146    impl MapBuilder for PayoutBuilder {
147        type Out = Payout;
148        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
149            Ok(match k {
150                "amount" => Deserialize::begin(&mut self.amount),
151                "application_fee" => Deserialize::begin(&mut self.application_fee),
152                "application_fee_amount" => Deserialize::begin(&mut self.application_fee_amount),
153                "arrival_date" => Deserialize::begin(&mut self.arrival_date),
154                "automatic" => Deserialize::begin(&mut self.automatic),
155                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
156                "created" => Deserialize::begin(&mut self.created),
157                "currency" => Deserialize::begin(&mut self.currency),
158                "description" => Deserialize::begin(&mut self.description),
159                "destination" => Deserialize::begin(&mut self.destination),
160                "failure_balance_transaction" => {
161                    Deserialize::begin(&mut self.failure_balance_transaction)
162                }
163                "failure_code" => Deserialize::begin(&mut self.failure_code),
164                "failure_message" => Deserialize::begin(&mut self.failure_message),
165                "id" => Deserialize::begin(&mut self.id),
166                "livemode" => Deserialize::begin(&mut self.livemode),
167                "metadata" => Deserialize::begin(&mut self.metadata),
168                "method" => Deserialize::begin(&mut self.method),
169                "original_payout" => Deserialize::begin(&mut self.original_payout),
170                "payout_method" => Deserialize::begin(&mut self.payout_method),
171                "reconciliation_status" => Deserialize::begin(&mut self.reconciliation_status),
172                "reversed_by" => Deserialize::begin(&mut self.reversed_by),
173                "source_type" => Deserialize::begin(&mut self.source_type),
174                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
175                "status" => Deserialize::begin(&mut self.status),
176                "trace_id" => Deserialize::begin(&mut self.trace_id),
177                "type" => Deserialize::begin(&mut self.type_),
178                _ => <dyn Visitor>::ignore(),
179            })
180        }
181
182        fn deser_default() -> Self {
183            Self {
184                amount: Deserialize::default(),
185                application_fee: Deserialize::default(),
186                application_fee_amount: Deserialize::default(),
187                arrival_date: Deserialize::default(),
188                automatic: Deserialize::default(),
189                balance_transaction: Deserialize::default(),
190                created: Deserialize::default(),
191                currency: Deserialize::default(),
192                description: Deserialize::default(),
193                destination: Deserialize::default(),
194                failure_balance_transaction: Deserialize::default(),
195                failure_code: Deserialize::default(),
196                failure_message: Deserialize::default(),
197                id: Deserialize::default(),
198                livemode: Deserialize::default(),
199                metadata: Deserialize::default(),
200                method: Deserialize::default(),
201                original_payout: Deserialize::default(),
202                payout_method: Deserialize::default(),
203                reconciliation_status: Deserialize::default(),
204                reversed_by: Deserialize::default(),
205                source_type: Deserialize::default(),
206                statement_descriptor: Deserialize::default(),
207                status: Deserialize::default(),
208                trace_id: Deserialize::default(),
209                type_: Deserialize::default(),
210            }
211        }
212
213        fn take_out(&mut self) -> Option<Self::Out> {
214            let (
215                Some(amount),
216                Some(application_fee),
217                Some(application_fee_amount),
218                Some(arrival_date),
219                Some(automatic),
220                Some(balance_transaction),
221                Some(created),
222                Some(currency),
223                Some(description),
224                Some(destination),
225                Some(failure_balance_transaction),
226                Some(failure_code),
227                Some(failure_message),
228                Some(id),
229                Some(livemode),
230                Some(metadata),
231                Some(method),
232                Some(original_payout),
233                Some(payout_method),
234                Some(reconciliation_status),
235                Some(reversed_by),
236                Some(source_type),
237                Some(statement_descriptor),
238                Some(status),
239                Some(trace_id),
240                Some(type_),
241            ) = (
242                self.amount,
243                self.application_fee.take(),
244                self.application_fee_amount,
245                self.arrival_date,
246                self.automatic,
247                self.balance_transaction.take(),
248                self.created,
249                self.currency.take(),
250                self.description.take(),
251                self.destination.take(),
252                self.failure_balance_transaction.take(),
253                self.failure_code.take(),
254                self.failure_message.take(),
255                self.id.take(),
256                self.livemode,
257                self.metadata.take(),
258                self.method.take(),
259                self.original_payout.take(),
260                self.payout_method.take(),
261                self.reconciliation_status.take(),
262                self.reversed_by.take(),
263                self.source_type.take(),
264                self.statement_descriptor.take(),
265                self.status.take(),
266                self.trace_id.take(),
267                self.type_.take(),
268            )
269            else {
270                return None;
271            };
272            Some(Self::Out {
273                amount,
274                application_fee,
275                application_fee_amount,
276                arrival_date,
277                automatic,
278                balance_transaction,
279                created,
280                currency,
281                description,
282                destination,
283                failure_balance_transaction,
284                failure_code,
285                failure_message,
286                id,
287                livemode,
288                metadata,
289                method,
290                original_payout,
291                payout_method,
292                reconciliation_status,
293                reversed_by,
294                source_type,
295                statement_descriptor,
296                status,
297                trace_id,
298                type_,
299            })
300        }
301    }
302
303    impl Map for Builder<'_> {
304        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
305            self.builder.key(k)
306        }
307
308        fn finish(&mut self) -> Result<()> {
309            *self.out = self.builder.take_out();
310            Ok(())
311        }
312    }
313
314    impl ObjectDeser for Payout {
315        type Builder = PayoutBuilder;
316    }
317
318    impl FromValueOpt for Payout {
319        fn from_value(v: Value) -> Option<Self> {
320            let Value::Object(obj) = v else {
321                return None;
322            };
323            let mut b = PayoutBuilder::deser_default();
324            for (k, v) in obj {
325                match k.as_str() {
326                    "amount" => b.amount = FromValueOpt::from_value(v),
327                    "application_fee" => b.application_fee = FromValueOpt::from_value(v),
328                    "application_fee_amount" => {
329                        b.application_fee_amount = FromValueOpt::from_value(v)
330                    }
331                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
332                    "automatic" => b.automatic = FromValueOpt::from_value(v),
333                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
334                    "created" => b.created = FromValueOpt::from_value(v),
335                    "currency" => b.currency = FromValueOpt::from_value(v),
336                    "description" => b.description = FromValueOpt::from_value(v),
337                    "destination" => b.destination = FromValueOpt::from_value(v),
338                    "failure_balance_transaction" => {
339                        b.failure_balance_transaction = FromValueOpt::from_value(v)
340                    }
341                    "failure_code" => b.failure_code = FromValueOpt::from_value(v),
342                    "failure_message" => b.failure_message = FromValueOpt::from_value(v),
343                    "id" => b.id = FromValueOpt::from_value(v),
344                    "livemode" => b.livemode = FromValueOpt::from_value(v),
345                    "metadata" => b.metadata = FromValueOpt::from_value(v),
346                    "method" => b.method = FromValueOpt::from_value(v),
347                    "original_payout" => b.original_payout = FromValueOpt::from_value(v),
348                    "payout_method" => b.payout_method = FromValueOpt::from_value(v),
349                    "reconciliation_status" => {
350                        b.reconciliation_status = FromValueOpt::from_value(v)
351                    }
352                    "reversed_by" => b.reversed_by = FromValueOpt::from_value(v),
353                    "source_type" => b.source_type = FromValueOpt::from_value(v),
354                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
355                    "status" => b.status = FromValueOpt::from_value(v),
356                    "trace_id" => b.trace_id = FromValueOpt::from_value(v),
357                    "type" => b.type_ = FromValueOpt::from_value(v),
358                    _ => {}
359                }
360            }
361            b.take_out()
362        }
363    }
364};
365#[cfg(feature = "serialize")]
366impl serde::Serialize for Payout {
367    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
368        use serde::ser::SerializeStruct;
369        let mut s = s.serialize_struct("Payout", 27)?;
370        s.serialize_field("amount", &self.amount)?;
371        s.serialize_field("application_fee", &self.application_fee)?;
372        s.serialize_field("application_fee_amount", &self.application_fee_amount)?;
373        s.serialize_field("arrival_date", &self.arrival_date)?;
374        s.serialize_field("automatic", &self.automatic)?;
375        s.serialize_field("balance_transaction", &self.balance_transaction)?;
376        s.serialize_field("created", &self.created)?;
377        s.serialize_field("currency", &self.currency)?;
378        s.serialize_field("description", &self.description)?;
379        s.serialize_field("destination", &self.destination)?;
380        s.serialize_field("failure_balance_transaction", &self.failure_balance_transaction)?;
381        s.serialize_field("failure_code", &self.failure_code)?;
382        s.serialize_field("failure_message", &self.failure_message)?;
383        s.serialize_field("id", &self.id)?;
384        s.serialize_field("livemode", &self.livemode)?;
385        s.serialize_field("metadata", &self.metadata)?;
386        s.serialize_field("method", &self.method)?;
387        s.serialize_field("original_payout", &self.original_payout)?;
388        s.serialize_field("payout_method", &self.payout_method)?;
389        s.serialize_field("reconciliation_status", &self.reconciliation_status)?;
390        s.serialize_field("reversed_by", &self.reversed_by)?;
391        s.serialize_field("source_type", &self.source_type)?;
392        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
393        s.serialize_field("status", &self.status)?;
394        s.serialize_field("trace_id", &self.trace_id)?;
395        s.serialize_field("type", &self.type_)?;
396
397        s.serialize_field("object", "payout")?;
398        s.end()
399    }
400}
401/// If `completed`, you can use the [Balance Transactions API](https://stripe.com/docs/api/balance_transactions/list#balance_transaction_list-payout) to list all balance transactions that are paid out in this payout.
402#[derive(Clone, Eq, PartialEq)]
403#[non_exhaustive]
404pub enum PayoutReconciliationStatus {
405    Completed,
406    InProgress,
407    NotApplicable,
408    /// An unrecognized value from Stripe. Should not be used as a request parameter.
409    Unknown(String),
410}
411impl PayoutReconciliationStatus {
412    pub fn as_str(&self) -> &str {
413        use PayoutReconciliationStatus::*;
414        match self {
415            Completed => "completed",
416            InProgress => "in_progress",
417            NotApplicable => "not_applicable",
418            Unknown(v) => v,
419        }
420    }
421}
422
423impl std::str::FromStr for PayoutReconciliationStatus {
424    type Err = std::convert::Infallible;
425    fn from_str(s: &str) -> Result<Self, Self::Err> {
426        use PayoutReconciliationStatus::*;
427        match s {
428            "completed" => Ok(Completed),
429            "in_progress" => Ok(InProgress),
430            "not_applicable" => Ok(NotApplicable),
431            v => {
432                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PayoutReconciliationStatus");
433                Ok(Unknown(v.to_owned()))
434            }
435        }
436    }
437}
438impl std::fmt::Display for PayoutReconciliationStatus {
439    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
440        f.write_str(self.as_str())
441    }
442}
443
444impl std::fmt::Debug for PayoutReconciliationStatus {
445    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
446        f.write_str(self.as_str())
447    }
448}
449#[cfg(feature = "serialize")]
450impl serde::Serialize for PayoutReconciliationStatus {
451    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
452    where
453        S: serde::Serializer,
454    {
455        serializer.serialize_str(self.as_str())
456    }
457}
458impl miniserde::Deserialize for PayoutReconciliationStatus {
459    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
460        crate::Place::new(out)
461    }
462}
463
464impl miniserde::de::Visitor for crate::Place<PayoutReconciliationStatus> {
465    fn string(&mut self, s: &str) -> miniserde::Result<()> {
466        use std::str::FromStr;
467        self.out = Some(PayoutReconciliationStatus::from_str(s).expect("infallible"));
468        Ok(())
469    }
470}
471
472stripe_types::impl_from_val_with_from_str!(PayoutReconciliationStatus);
473#[cfg(feature = "deserialize")]
474impl<'de> serde::Deserialize<'de> for PayoutReconciliationStatus {
475    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
476        use std::str::FromStr;
477        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
478        Ok(Self::from_str(&s).expect("infallible"))
479    }
480}
481/// Can be `bank_account` or `card`.
482#[derive(Clone, Eq, PartialEq)]
483#[non_exhaustive]
484pub enum PayoutType {
485    BankAccount,
486    Card,
487    /// An unrecognized value from Stripe. Should not be used as a request parameter.
488    Unknown(String),
489}
490impl PayoutType {
491    pub fn as_str(&self) -> &str {
492        use PayoutType::*;
493        match self {
494            BankAccount => "bank_account",
495            Card => "card",
496            Unknown(v) => v,
497        }
498    }
499}
500
501impl std::str::FromStr for PayoutType {
502    type Err = std::convert::Infallible;
503    fn from_str(s: &str) -> Result<Self, Self::Err> {
504        use PayoutType::*;
505        match s {
506            "bank_account" => Ok(BankAccount),
507            "card" => Ok(Card),
508            v => {
509                tracing::warn!("Unknown value '{}' for enum '{}'", v, "PayoutType");
510                Ok(Unknown(v.to_owned()))
511            }
512        }
513    }
514}
515impl std::fmt::Display for PayoutType {
516    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
517        f.write_str(self.as_str())
518    }
519}
520
521impl std::fmt::Debug for PayoutType {
522    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
523        f.write_str(self.as_str())
524    }
525}
526#[cfg(feature = "serialize")]
527impl serde::Serialize for PayoutType {
528    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
529    where
530        S: serde::Serializer,
531    {
532        serializer.serialize_str(self.as_str())
533    }
534}
535impl miniserde::Deserialize for PayoutType {
536    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
537        crate::Place::new(out)
538    }
539}
540
541impl miniserde::de::Visitor for crate::Place<PayoutType> {
542    fn string(&mut self, s: &str) -> miniserde::Result<()> {
543        use std::str::FromStr;
544        self.out = Some(PayoutType::from_str(s).expect("infallible"));
545        Ok(())
546    }
547}
548
549stripe_types::impl_from_val_with_from_str!(PayoutType);
550#[cfg(feature = "deserialize")]
551impl<'de> serde::Deserialize<'de> for PayoutType {
552    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
553        use std::str::FromStr;
554        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
555        Ok(Self::from_str(&s).expect("infallible"))
556    }
557}
558impl stripe_types::Object for Payout {
559    type Id = stripe_shared::PayoutId;
560    fn id(&self) -> &Self::Id {
561        &self.id
562    }
563
564    fn into_id(self) -> Self::Id {
565        self.id
566    }
567}
568stripe_types::def_id!(PayoutId);