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::{make_place, Deserialize, Result};
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
179                _ => <dyn Visitor>::ignore(),
180            })
181        }
182
183        fn deser_default() -> Self {
184            Self {
185                amount: Deserialize::default(),
186                application_fee: Deserialize::default(),
187                application_fee_amount: Deserialize::default(),
188                arrival_date: Deserialize::default(),
189                automatic: Deserialize::default(),
190                balance_transaction: Deserialize::default(),
191                created: Deserialize::default(),
192                currency: Deserialize::default(),
193                description: Deserialize::default(),
194                destination: Deserialize::default(),
195                failure_balance_transaction: Deserialize::default(),
196                failure_code: Deserialize::default(),
197                failure_message: Deserialize::default(),
198                id: Deserialize::default(),
199                livemode: Deserialize::default(),
200                metadata: Deserialize::default(),
201                method: Deserialize::default(),
202                original_payout: Deserialize::default(),
203                payout_method: Deserialize::default(),
204                reconciliation_status: Deserialize::default(),
205                reversed_by: Deserialize::default(),
206                source_type: Deserialize::default(),
207                statement_descriptor: Deserialize::default(),
208                status: Deserialize::default(),
209                trace_id: Deserialize::default(),
210                type_: Deserialize::default(),
211            }
212        }
213
214        fn take_out(&mut self) -> Option<Self::Out> {
215            let (
216                Some(amount),
217                Some(application_fee),
218                Some(application_fee_amount),
219                Some(arrival_date),
220                Some(automatic),
221                Some(balance_transaction),
222                Some(created),
223                Some(currency),
224                Some(description),
225                Some(destination),
226                Some(failure_balance_transaction),
227                Some(failure_code),
228                Some(failure_message),
229                Some(id),
230                Some(livemode),
231                Some(metadata),
232                Some(method),
233                Some(original_payout),
234                Some(payout_method),
235                Some(reconciliation_status),
236                Some(reversed_by),
237                Some(source_type),
238                Some(statement_descriptor),
239                Some(status),
240                Some(trace_id),
241                Some(type_),
242            ) = (
243                self.amount,
244                self.application_fee.take(),
245                self.application_fee_amount,
246                self.arrival_date,
247                self.automatic,
248                self.balance_transaction.take(),
249                self.created,
250                self.currency.take(),
251                self.description.take(),
252                self.destination.take(),
253                self.failure_balance_transaction.take(),
254                self.failure_code.take(),
255                self.failure_message.take(),
256                self.id.take(),
257                self.livemode,
258                self.metadata.take(),
259                self.method.take(),
260                self.original_payout.take(),
261                self.payout_method.take(),
262                self.reconciliation_status,
263                self.reversed_by.take(),
264                self.source_type.take(),
265                self.statement_descriptor.take(),
266                self.status.take(),
267                self.trace_id.take(),
268                self.type_,
269            )
270            else {
271                return None;
272            };
273            Some(Self::Out {
274                amount,
275                application_fee,
276                application_fee_amount,
277                arrival_date,
278                automatic,
279                balance_transaction,
280                created,
281                currency,
282                description,
283                destination,
284                failure_balance_transaction,
285                failure_code,
286                failure_message,
287                id,
288                livemode,
289                metadata,
290                method,
291                original_payout,
292                payout_method,
293                reconciliation_status,
294                reversed_by,
295                source_type,
296                statement_descriptor,
297                status,
298                trace_id,
299                type_,
300            })
301        }
302    }
303
304    impl Map for Builder<'_> {
305        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
306            self.builder.key(k)
307        }
308
309        fn finish(&mut self) -> Result<()> {
310            *self.out = self.builder.take_out();
311            Ok(())
312        }
313    }
314
315    impl ObjectDeser for Payout {
316        type Builder = PayoutBuilder;
317    }
318
319    impl FromValueOpt for Payout {
320        fn from_value(v: Value) -> Option<Self> {
321            let Value::Object(obj) = v else {
322                return None;
323            };
324            let mut b = PayoutBuilder::deser_default();
325            for (k, v) in obj {
326                match k.as_str() {
327                    "amount" => b.amount = FromValueOpt::from_value(v),
328                    "application_fee" => b.application_fee = FromValueOpt::from_value(v),
329                    "application_fee_amount" => {
330                        b.application_fee_amount = FromValueOpt::from_value(v)
331                    }
332                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
333                    "automatic" => b.automatic = FromValueOpt::from_value(v),
334                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
335                    "created" => b.created = FromValueOpt::from_value(v),
336                    "currency" => b.currency = FromValueOpt::from_value(v),
337                    "description" => b.description = FromValueOpt::from_value(v),
338                    "destination" => b.destination = FromValueOpt::from_value(v),
339                    "failure_balance_transaction" => {
340                        b.failure_balance_transaction = FromValueOpt::from_value(v)
341                    }
342                    "failure_code" => b.failure_code = FromValueOpt::from_value(v),
343                    "failure_message" => b.failure_message = FromValueOpt::from_value(v),
344                    "id" => b.id = FromValueOpt::from_value(v),
345                    "livemode" => b.livemode = FromValueOpt::from_value(v),
346                    "metadata" => b.metadata = FromValueOpt::from_value(v),
347                    "method" => b.method = FromValueOpt::from_value(v),
348                    "original_payout" => b.original_payout = FromValueOpt::from_value(v),
349                    "payout_method" => b.payout_method = FromValueOpt::from_value(v),
350                    "reconciliation_status" => {
351                        b.reconciliation_status = FromValueOpt::from_value(v)
352                    }
353                    "reversed_by" => b.reversed_by = FromValueOpt::from_value(v),
354                    "source_type" => b.source_type = FromValueOpt::from_value(v),
355                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
356                    "status" => b.status = FromValueOpt::from_value(v),
357                    "trace_id" => b.trace_id = FromValueOpt::from_value(v),
358                    "type" => b.type_ = FromValueOpt::from_value(v),
359
360                    _ => {}
361                }
362            }
363            b.take_out()
364        }
365    }
366};
367#[cfg(feature = "serialize")]
368impl serde::Serialize for Payout {
369    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
370        use serde::ser::SerializeStruct;
371        let mut s = s.serialize_struct("Payout", 27)?;
372        s.serialize_field("amount", &self.amount)?;
373        s.serialize_field("application_fee", &self.application_fee)?;
374        s.serialize_field("application_fee_amount", &self.application_fee_amount)?;
375        s.serialize_field("arrival_date", &self.arrival_date)?;
376        s.serialize_field("automatic", &self.automatic)?;
377        s.serialize_field("balance_transaction", &self.balance_transaction)?;
378        s.serialize_field("created", &self.created)?;
379        s.serialize_field("currency", &self.currency)?;
380        s.serialize_field("description", &self.description)?;
381        s.serialize_field("destination", &self.destination)?;
382        s.serialize_field("failure_balance_transaction", &self.failure_balance_transaction)?;
383        s.serialize_field("failure_code", &self.failure_code)?;
384        s.serialize_field("failure_message", &self.failure_message)?;
385        s.serialize_field("id", &self.id)?;
386        s.serialize_field("livemode", &self.livemode)?;
387        s.serialize_field("metadata", &self.metadata)?;
388        s.serialize_field("method", &self.method)?;
389        s.serialize_field("original_payout", &self.original_payout)?;
390        s.serialize_field("payout_method", &self.payout_method)?;
391        s.serialize_field("reconciliation_status", &self.reconciliation_status)?;
392        s.serialize_field("reversed_by", &self.reversed_by)?;
393        s.serialize_field("source_type", &self.source_type)?;
394        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
395        s.serialize_field("status", &self.status)?;
396        s.serialize_field("trace_id", &self.trace_id)?;
397        s.serialize_field("type", &self.type_)?;
398
399        s.serialize_field("object", "payout")?;
400        s.end()
401    }
402}
403/// 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.
404#[derive(Copy, Clone, Eq, PartialEq)]
405pub enum PayoutReconciliationStatus {
406    Completed,
407    InProgress,
408    NotApplicable,
409}
410impl PayoutReconciliationStatus {
411    pub fn as_str(self) -> &'static str {
412        use PayoutReconciliationStatus::*;
413        match self {
414            Completed => "completed",
415            InProgress => "in_progress",
416            NotApplicable => "not_applicable",
417        }
418    }
419}
420
421impl std::str::FromStr for PayoutReconciliationStatus {
422    type Err = stripe_types::StripeParseError;
423    fn from_str(s: &str) -> Result<Self, Self::Err> {
424        use PayoutReconciliationStatus::*;
425        match s {
426            "completed" => Ok(Completed),
427            "in_progress" => Ok(InProgress),
428            "not_applicable" => Ok(NotApplicable),
429            _ => Err(stripe_types::StripeParseError),
430        }
431    }
432}
433impl std::fmt::Display for PayoutReconciliationStatus {
434    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
435        f.write_str(self.as_str())
436    }
437}
438
439impl std::fmt::Debug for PayoutReconciliationStatus {
440    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
441        f.write_str(self.as_str())
442    }
443}
444#[cfg(feature = "serialize")]
445impl serde::Serialize for PayoutReconciliationStatus {
446    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
447    where
448        S: serde::Serializer,
449    {
450        serializer.serialize_str(self.as_str())
451    }
452}
453impl miniserde::Deserialize for PayoutReconciliationStatus {
454    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
455        crate::Place::new(out)
456    }
457}
458
459impl miniserde::de::Visitor for crate::Place<PayoutReconciliationStatus> {
460    fn string(&mut self, s: &str) -> miniserde::Result<()> {
461        use std::str::FromStr;
462        self.out = Some(PayoutReconciliationStatus::from_str(s).map_err(|_| miniserde::Error)?);
463        Ok(())
464    }
465}
466
467stripe_types::impl_from_val_with_from_str!(PayoutReconciliationStatus);
468#[cfg(feature = "deserialize")]
469impl<'de> serde::Deserialize<'de> for PayoutReconciliationStatus {
470    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
471        use std::str::FromStr;
472        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
473        Self::from_str(&s)
474            .map_err(|_| serde::de::Error::custom("Unknown value for PayoutReconciliationStatus"))
475    }
476}
477/// Can be `bank_account` or `card`.
478#[derive(Copy, Clone, Eq, PartialEq)]
479pub enum PayoutType {
480    BankAccount,
481    Card,
482}
483impl PayoutType {
484    pub fn as_str(self) -> &'static str {
485        use PayoutType::*;
486        match self {
487            BankAccount => "bank_account",
488            Card => "card",
489        }
490    }
491}
492
493impl std::str::FromStr for PayoutType {
494    type Err = stripe_types::StripeParseError;
495    fn from_str(s: &str) -> Result<Self, Self::Err> {
496        use PayoutType::*;
497        match s {
498            "bank_account" => Ok(BankAccount),
499            "card" => Ok(Card),
500            _ => Err(stripe_types::StripeParseError),
501        }
502    }
503}
504impl std::fmt::Display for PayoutType {
505    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
506        f.write_str(self.as_str())
507    }
508}
509
510impl std::fmt::Debug for PayoutType {
511    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
512        f.write_str(self.as_str())
513    }
514}
515#[cfg(feature = "serialize")]
516impl serde::Serialize for PayoutType {
517    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
518    where
519        S: serde::Serializer,
520    {
521        serializer.serialize_str(self.as_str())
522    }
523}
524impl miniserde::Deserialize for PayoutType {
525    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
526        crate::Place::new(out)
527    }
528}
529
530impl miniserde::de::Visitor for crate::Place<PayoutType> {
531    fn string(&mut self, s: &str) -> miniserde::Result<()> {
532        use std::str::FromStr;
533        self.out = Some(PayoutType::from_str(s).map_err(|_| miniserde::Error)?);
534        Ok(())
535    }
536}
537
538stripe_types::impl_from_val_with_from_str!(PayoutType);
539#[cfg(feature = "deserialize")]
540impl<'de> serde::Deserialize<'de> for PayoutType {
541    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
542        use std::str::FromStr;
543        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
544        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for PayoutType"))
545    }
546}
547impl stripe_types::Object for Payout {
548    type Id = stripe_shared::PayoutId;
549    fn id(&self) -> &Self::Id {
550        &self.id
551    }
552
553    fn into_id(self) -> Self::Id {
554        self.id
555    }
556}
557stripe_types::def_id!(PayoutId);