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,
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_,
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(Copy, Clone, Eq, PartialEq)]
403pub enum PayoutReconciliationStatus {
404    Completed,
405    InProgress,
406    NotApplicable,
407}
408impl PayoutReconciliationStatus {
409    pub fn as_str(self) -> &'static str {
410        use PayoutReconciliationStatus::*;
411        match self {
412            Completed => "completed",
413            InProgress => "in_progress",
414            NotApplicable => "not_applicable",
415        }
416    }
417}
418
419impl std::str::FromStr for PayoutReconciliationStatus {
420    type Err = stripe_types::StripeParseError;
421    fn from_str(s: &str) -> Result<Self, Self::Err> {
422        use PayoutReconciliationStatus::*;
423        match s {
424            "completed" => Ok(Completed),
425            "in_progress" => Ok(InProgress),
426            "not_applicable" => Ok(NotApplicable),
427            _ => Err(stripe_types::StripeParseError),
428        }
429    }
430}
431impl std::fmt::Display for PayoutReconciliationStatus {
432    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
433        f.write_str(self.as_str())
434    }
435}
436
437impl std::fmt::Debug for PayoutReconciliationStatus {
438    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
439        f.write_str(self.as_str())
440    }
441}
442#[cfg(feature = "serialize")]
443impl serde::Serialize for PayoutReconciliationStatus {
444    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
445    where
446        S: serde::Serializer,
447    {
448        serializer.serialize_str(self.as_str())
449    }
450}
451impl miniserde::Deserialize for PayoutReconciliationStatus {
452    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
453        crate::Place::new(out)
454    }
455}
456
457impl miniserde::de::Visitor for crate::Place<PayoutReconciliationStatus> {
458    fn string(&mut self, s: &str) -> miniserde::Result<()> {
459        use std::str::FromStr;
460        self.out = Some(PayoutReconciliationStatus::from_str(s).map_err(|_| miniserde::Error)?);
461        Ok(())
462    }
463}
464
465stripe_types::impl_from_val_with_from_str!(PayoutReconciliationStatus);
466#[cfg(feature = "deserialize")]
467impl<'de> serde::Deserialize<'de> for PayoutReconciliationStatus {
468    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
469        use std::str::FromStr;
470        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
471        Self::from_str(&s)
472            .map_err(|_| serde::de::Error::custom("Unknown value for PayoutReconciliationStatus"))
473    }
474}
475/// Can be `bank_account` or `card`.
476#[derive(Copy, Clone, Eq, PartialEq)]
477pub enum PayoutType {
478    BankAccount,
479    Card,
480}
481impl PayoutType {
482    pub fn as_str(self) -> &'static str {
483        use PayoutType::*;
484        match self {
485            BankAccount => "bank_account",
486            Card => "card",
487        }
488    }
489}
490
491impl std::str::FromStr for PayoutType {
492    type Err = stripe_types::StripeParseError;
493    fn from_str(s: &str) -> Result<Self, Self::Err> {
494        use PayoutType::*;
495        match s {
496            "bank_account" => Ok(BankAccount),
497            "card" => Ok(Card),
498            _ => Err(stripe_types::StripeParseError),
499        }
500    }
501}
502impl std::fmt::Display for PayoutType {
503    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
504        f.write_str(self.as_str())
505    }
506}
507
508impl std::fmt::Debug for PayoutType {
509    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
510        f.write_str(self.as_str())
511    }
512}
513#[cfg(feature = "serialize")]
514impl serde::Serialize for PayoutType {
515    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
516    where
517        S: serde::Serializer,
518    {
519        serializer.serialize_str(self.as_str())
520    }
521}
522impl miniserde::Deserialize for PayoutType {
523    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
524        crate::Place::new(out)
525    }
526}
527
528impl miniserde::de::Visitor for crate::Place<PayoutType> {
529    fn string(&mut self, s: &str) -> miniserde::Result<()> {
530        use std::str::FromStr;
531        self.out = Some(PayoutType::from_str(s).map_err(|_| miniserde::Error)?);
532        Ok(())
533    }
534}
535
536stripe_types::impl_from_val_with_from_str!(PayoutType);
537#[cfg(feature = "deserialize")]
538impl<'de> serde::Deserialize<'de> for PayoutType {
539    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
540        use std::str::FromStr;
541        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
542        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for PayoutType"))
543    }
544}
545impl stripe_types::Object for Payout {
546    type Id = stripe_shared::PayoutId;
547    fn id(&self) -> &Self::Id {
548        &self.id
549    }
550
551    fn into_id(self) -> Self::Id {
552        self.id
553    }
554}
555stripe_types::def_id!(PayoutId);