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    /// 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.
60    pub reconciliation_status: PayoutReconciliationStatus,
61    /// If the payout reverses, this is the ID of the payout that reverses this payout.
62    pub reversed_by: Option<stripe_types::Expandable<stripe_shared::Payout>>,
63    /// The source balance this payout came from, which can be one of the following: `card`, `fpx`, or `bank_account`.
64    pub source_type: String,
65    /// Extra information about a payout that displays on the user's bank statement.
66    pub statement_descriptor: Option<String>,
67    /// Current status of the payout: `paid`, `pending`, `in_transit`, `canceled` or `failed`.
68    /// A payout is `pending` until it's submitted to the bank, when it becomes `in_transit`.
69    /// The status changes to `paid` if the transaction succeeds, or to `failed` or `canceled` (within 5 business days).
70    /// Some payouts that fail might initially show as `paid`, then change to `failed`.
71    pub status: String,
72    /// A value that generates from the beneficiary's bank that allows users to track payouts with their bank.
73    /// Banks might call this a "reference number" or something similar.
74    pub trace_id: Option<stripe_shared::PayoutsTraceId>,
75    /// Can be `bank_account` or `card`.
76    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
77    pub type_: PayoutType,
78}
79#[doc(hidden)]
80pub struct PayoutBuilder {
81    amount: Option<i64>,
82    application_fee: Option<Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>>,
83    application_fee_amount: Option<Option<i64>>,
84    arrival_date: Option<stripe_types::Timestamp>,
85    automatic: Option<bool>,
86    balance_transaction:
87        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
88    created: Option<stripe_types::Timestamp>,
89    currency: Option<stripe_types::Currency>,
90    description: Option<Option<String>>,
91    destination: Option<Option<stripe_types::Expandable<stripe_shared::ExternalAccount>>>,
92    failure_balance_transaction:
93        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
94    failure_code: Option<Option<String>>,
95    failure_message: Option<Option<String>>,
96    id: Option<stripe_shared::PayoutId>,
97    livemode: Option<bool>,
98    metadata: Option<Option<std::collections::HashMap<String, String>>>,
99    method: Option<String>,
100    original_payout: Option<Option<stripe_types::Expandable<stripe_shared::Payout>>>,
101    reconciliation_status: Option<PayoutReconciliationStatus>,
102    reversed_by: Option<Option<stripe_types::Expandable<stripe_shared::Payout>>>,
103    source_type: Option<String>,
104    statement_descriptor: Option<Option<String>>,
105    status: Option<String>,
106    trace_id: Option<Option<stripe_shared::PayoutsTraceId>>,
107    type_: Option<PayoutType>,
108}
109
110#[allow(
111    unused_variables,
112    irrefutable_let_patterns,
113    clippy::let_unit_value,
114    clippy::match_single_binding,
115    clippy::single_match
116)]
117const _: () = {
118    use miniserde::de::{Map, Visitor};
119    use miniserde::json::Value;
120    use miniserde::{make_place, Deserialize, Result};
121    use stripe_types::miniserde_helpers::FromValueOpt;
122    use stripe_types::{MapBuilder, ObjectDeser};
123
124    make_place!(Place);
125
126    impl Deserialize for Payout {
127        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
128            Place::new(out)
129        }
130    }
131
132    struct Builder<'a> {
133        out: &'a mut Option<Payout>,
134        builder: PayoutBuilder,
135    }
136
137    impl Visitor for Place<Payout> {
138        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
139            Ok(Box::new(Builder { out: &mut self.out, builder: PayoutBuilder::deser_default() }))
140        }
141    }
142
143    impl MapBuilder for PayoutBuilder {
144        type Out = Payout;
145        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
146            Ok(match k {
147                "amount" => Deserialize::begin(&mut self.amount),
148                "application_fee" => Deserialize::begin(&mut self.application_fee),
149                "application_fee_amount" => Deserialize::begin(&mut self.application_fee_amount),
150                "arrival_date" => Deserialize::begin(&mut self.arrival_date),
151                "automatic" => Deserialize::begin(&mut self.automatic),
152                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
153                "created" => Deserialize::begin(&mut self.created),
154                "currency" => Deserialize::begin(&mut self.currency),
155                "description" => Deserialize::begin(&mut self.description),
156                "destination" => Deserialize::begin(&mut self.destination),
157                "failure_balance_transaction" => {
158                    Deserialize::begin(&mut self.failure_balance_transaction)
159                }
160                "failure_code" => Deserialize::begin(&mut self.failure_code),
161                "failure_message" => Deserialize::begin(&mut self.failure_message),
162                "id" => Deserialize::begin(&mut self.id),
163                "livemode" => Deserialize::begin(&mut self.livemode),
164                "metadata" => Deserialize::begin(&mut self.metadata),
165                "method" => Deserialize::begin(&mut self.method),
166                "original_payout" => Deserialize::begin(&mut self.original_payout),
167                "reconciliation_status" => Deserialize::begin(&mut self.reconciliation_status),
168                "reversed_by" => Deserialize::begin(&mut self.reversed_by),
169                "source_type" => Deserialize::begin(&mut self.source_type),
170                "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
171                "status" => Deserialize::begin(&mut self.status),
172                "trace_id" => Deserialize::begin(&mut self.trace_id),
173                "type" => Deserialize::begin(&mut self.type_),
174
175                _ => <dyn Visitor>::ignore(),
176            })
177        }
178
179        fn deser_default() -> Self {
180            Self {
181                amount: Deserialize::default(),
182                application_fee: Deserialize::default(),
183                application_fee_amount: Deserialize::default(),
184                arrival_date: Deserialize::default(),
185                automatic: Deserialize::default(),
186                balance_transaction: Deserialize::default(),
187                created: Deserialize::default(),
188                currency: Deserialize::default(),
189                description: Deserialize::default(),
190                destination: Deserialize::default(),
191                failure_balance_transaction: Deserialize::default(),
192                failure_code: Deserialize::default(),
193                failure_message: Deserialize::default(),
194                id: Deserialize::default(),
195                livemode: Deserialize::default(),
196                metadata: Deserialize::default(),
197                method: Deserialize::default(),
198                original_payout: Deserialize::default(),
199                reconciliation_status: Deserialize::default(),
200                reversed_by: Deserialize::default(),
201                source_type: Deserialize::default(),
202                statement_descriptor: Deserialize::default(),
203                status: Deserialize::default(),
204                trace_id: Deserialize::default(),
205                type_: Deserialize::default(),
206            }
207        }
208
209        fn take_out(&mut self) -> Option<Self::Out> {
210            let (
211                Some(amount),
212                Some(application_fee),
213                Some(application_fee_amount),
214                Some(arrival_date),
215                Some(automatic),
216                Some(balance_transaction),
217                Some(created),
218                Some(currency),
219                Some(description),
220                Some(destination),
221                Some(failure_balance_transaction),
222                Some(failure_code),
223                Some(failure_message),
224                Some(id),
225                Some(livemode),
226                Some(metadata),
227                Some(method),
228                Some(original_payout),
229                Some(reconciliation_status),
230                Some(reversed_by),
231                Some(source_type),
232                Some(statement_descriptor),
233                Some(status),
234                Some(trace_id),
235                Some(type_),
236            ) = (
237                self.amount,
238                self.application_fee.take(),
239                self.application_fee_amount,
240                self.arrival_date,
241                self.automatic,
242                self.balance_transaction.take(),
243                self.created,
244                self.currency,
245                self.description.take(),
246                self.destination.take(),
247                self.failure_balance_transaction.take(),
248                self.failure_code.take(),
249                self.failure_message.take(),
250                self.id.take(),
251                self.livemode,
252                self.metadata.take(),
253                self.method.take(),
254                self.original_payout.take(),
255                self.reconciliation_status,
256                self.reversed_by.take(),
257                self.source_type.take(),
258                self.statement_descriptor.take(),
259                self.status.take(),
260                self.trace_id.take(),
261                self.type_,
262            )
263            else {
264                return None;
265            };
266            Some(Self::Out {
267                amount,
268                application_fee,
269                application_fee_amount,
270                arrival_date,
271                automatic,
272                balance_transaction,
273                created,
274                currency,
275                description,
276                destination,
277                failure_balance_transaction,
278                failure_code,
279                failure_message,
280                id,
281                livemode,
282                metadata,
283                method,
284                original_payout,
285                reconciliation_status,
286                reversed_by,
287                source_type,
288                statement_descriptor,
289                status,
290                trace_id,
291                type_,
292            })
293        }
294    }
295
296    impl<'a> Map for Builder<'a> {
297        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
298            self.builder.key(k)
299        }
300
301        fn finish(&mut self) -> Result<()> {
302            *self.out = self.builder.take_out();
303            Ok(())
304        }
305    }
306
307    impl ObjectDeser for Payout {
308        type Builder = PayoutBuilder;
309    }
310
311    impl FromValueOpt for Payout {
312        fn from_value(v: Value) -> Option<Self> {
313            let Value::Object(obj) = v else {
314                return None;
315            };
316            let mut b = PayoutBuilder::deser_default();
317            for (k, v) in obj {
318                match k.as_str() {
319                    "amount" => b.amount = FromValueOpt::from_value(v),
320                    "application_fee" => b.application_fee = FromValueOpt::from_value(v),
321                    "application_fee_amount" => {
322                        b.application_fee_amount = FromValueOpt::from_value(v)
323                    }
324                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
325                    "automatic" => b.automatic = FromValueOpt::from_value(v),
326                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
327                    "created" => b.created = FromValueOpt::from_value(v),
328                    "currency" => b.currency = FromValueOpt::from_value(v),
329                    "description" => b.description = FromValueOpt::from_value(v),
330                    "destination" => b.destination = FromValueOpt::from_value(v),
331                    "failure_balance_transaction" => {
332                        b.failure_balance_transaction = FromValueOpt::from_value(v)
333                    }
334                    "failure_code" => b.failure_code = FromValueOpt::from_value(v),
335                    "failure_message" => b.failure_message = FromValueOpt::from_value(v),
336                    "id" => b.id = FromValueOpt::from_value(v),
337                    "livemode" => b.livemode = FromValueOpt::from_value(v),
338                    "metadata" => b.metadata = FromValueOpt::from_value(v),
339                    "method" => b.method = FromValueOpt::from_value(v),
340                    "original_payout" => b.original_payout = FromValueOpt::from_value(v),
341                    "reconciliation_status" => {
342                        b.reconciliation_status = FromValueOpt::from_value(v)
343                    }
344                    "reversed_by" => b.reversed_by = FromValueOpt::from_value(v),
345                    "source_type" => b.source_type = FromValueOpt::from_value(v),
346                    "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
347                    "status" => b.status = FromValueOpt::from_value(v),
348                    "trace_id" => b.trace_id = FromValueOpt::from_value(v),
349                    "type" => b.type_ = FromValueOpt::from_value(v),
350
351                    _ => {}
352                }
353            }
354            b.take_out()
355        }
356    }
357};
358#[cfg(feature = "serialize")]
359impl serde::Serialize for Payout {
360    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
361        use serde::ser::SerializeStruct;
362        let mut s = s.serialize_struct("Payout", 26)?;
363        s.serialize_field("amount", &self.amount)?;
364        s.serialize_field("application_fee", &self.application_fee)?;
365        s.serialize_field("application_fee_amount", &self.application_fee_amount)?;
366        s.serialize_field("arrival_date", &self.arrival_date)?;
367        s.serialize_field("automatic", &self.automatic)?;
368        s.serialize_field("balance_transaction", &self.balance_transaction)?;
369        s.serialize_field("created", &self.created)?;
370        s.serialize_field("currency", &self.currency)?;
371        s.serialize_field("description", &self.description)?;
372        s.serialize_field("destination", &self.destination)?;
373        s.serialize_field("failure_balance_transaction", &self.failure_balance_transaction)?;
374        s.serialize_field("failure_code", &self.failure_code)?;
375        s.serialize_field("failure_message", &self.failure_message)?;
376        s.serialize_field("id", &self.id)?;
377        s.serialize_field("livemode", &self.livemode)?;
378        s.serialize_field("metadata", &self.metadata)?;
379        s.serialize_field("method", &self.method)?;
380        s.serialize_field("original_payout", &self.original_payout)?;
381        s.serialize_field("reconciliation_status", &self.reconciliation_status)?;
382        s.serialize_field("reversed_by", &self.reversed_by)?;
383        s.serialize_field("source_type", &self.source_type)?;
384        s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
385        s.serialize_field("status", &self.status)?;
386        s.serialize_field("trace_id", &self.trace_id)?;
387        s.serialize_field("type", &self.type_)?;
388
389        s.serialize_field("object", "payout")?;
390        s.end()
391    }
392}
393/// 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.
394#[derive(Copy, Clone, Eq, PartialEq)]
395pub enum PayoutReconciliationStatus {
396    Completed,
397    InProgress,
398    NotApplicable,
399}
400impl PayoutReconciliationStatus {
401    pub fn as_str(self) -> &'static str {
402        use PayoutReconciliationStatus::*;
403        match self {
404            Completed => "completed",
405            InProgress => "in_progress",
406            NotApplicable => "not_applicable",
407        }
408    }
409}
410
411impl std::str::FromStr for PayoutReconciliationStatus {
412    type Err = stripe_types::StripeParseError;
413    fn from_str(s: &str) -> Result<Self, Self::Err> {
414        use PayoutReconciliationStatus::*;
415        match s {
416            "completed" => Ok(Completed),
417            "in_progress" => Ok(InProgress),
418            "not_applicable" => Ok(NotApplicable),
419            _ => Err(stripe_types::StripeParseError),
420        }
421    }
422}
423impl std::fmt::Display for PayoutReconciliationStatus {
424    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
425        f.write_str(self.as_str())
426    }
427}
428
429impl std::fmt::Debug for PayoutReconciliationStatus {
430    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
431        f.write_str(self.as_str())
432    }
433}
434#[cfg(feature = "serialize")]
435impl serde::Serialize for PayoutReconciliationStatus {
436    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
437    where
438        S: serde::Serializer,
439    {
440        serializer.serialize_str(self.as_str())
441    }
442}
443impl miniserde::Deserialize for PayoutReconciliationStatus {
444    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
445        crate::Place::new(out)
446    }
447}
448
449impl miniserde::de::Visitor for crate::Place<PayoutReconciliationStatus> {
450    fn string(&mut self, s: &str) -> miniserde::Result<()> {
451        use std::str::FromStr;
452        self.out = Some(PayoutReconciliationStatus::from_str(s).map_err(|_| miniserde::Error)?);
453        Ok(())
454    }
455}
456
457stripe_types::impl_from_val_with_from_str!(PayoutReconciliationStatus);
458#[cfg(feature = "deserialize")]
459impl<'de> serde::Deserialize<'de> for PayoutReconciliationStatus {
460    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
461        use std::str::FromStr;
462        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
463        Self::from_str(&s)
464            .map_err(|_| serde::de::Error::custom("Unknown value for PayoutReconciliationStatus"))
465    }
466}
467/// Can be `bank_account` or `card`.
468#[derive(Copy, Clone, Eq, PartialEq)]
469pub enum PayoutType {
470    BankAccount,
471    Card,
472}
473impl PayoutType {
474    pub fn as_str(self) -> &'static str {
475        use PayoutType::*;
476        match self {
477            BankAccount => "bank_account",
478            Card => "card",
479        }
480    }
481}
482
483impl std::str::FromStr for PayoutType {
484    type Err = stripe_types::StripeParseError;
485    fn from_str(s: &str) -> Result<Self, Self::Err> {
486        use PayoutType::*;
487        match s {
488            "bank_account" => Ok(BankAccount),
489            "card" => Ok(Card),
490            _ => Err(stripe_types::StripeParseError),
491        }
492    }
493}
494impl std::fmt::Display for PayoutType {
495    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
496        f.write_str(self.as_str())
497    }
498}
499
500impl std::fmt::Debug for PayoutType {
501    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
502        f.write_str(self.as_str())
503    }
504}
505#[cfg(feature = "serialize")]
506impl serde::Serialize for PayoutType {
507    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
508    where
509        S: serde::Serializer,
510    {
511        serializer.serialize_str(self.as_str())
512    }
513}
514impl miniserde::Deserialize for PayoutType {
515    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
516        crate::Place::new(out)
517    }
518}
519
520impl miniserde::de::Visitor for crate::Place<PayoutType> {
521    fn string(&mut self, s: &str) -> miniserde::Result<()> {
522        use std::str::FromStr;
523        self.out = Some(PayoutType::from_str(s).map_err(|_| miniserde::Error)?);
524        Ok(())
525    }
526}
527
528stripe_types::impl_from_val_with_from_str!(PayoutType);
529#[cfg(feature = "deserialize")]
530impl<'de> serde::Deserialize<'de> for PayoutType {
531    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
532        use std::str::FromStr;
533        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
534        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for PayoutType"))
535    }
536}
537impl stripe_types::Object for Payout {
538    type Id = stripe_shared::PayoutId;
539    fn id(&self) -> &Self::Id {
540        &self.id
541    }
542
543    fn into_id(self) -> Self::Id {
544        self.id
545    }
546}
547stripe_types::def_id!(PayoutId);