Skip to main content

stripe_shared/
balance_transaction.rs

1/// Balance transactions represent funds moving through your Stripe account.
2/// Stripe creates them for every type of transaction that enters or leaves your Stripe account balance.
3///
4/// Related guide: [Balance transaction types](https://docs.stripe.com/reports/balance-transaction-types).
5///
6/// For more details see <<https://stripe.com/docs/api/balance_transactions/object>>.
7#[derive(Clone)]
8#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
9#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
10pub struct BalanceTransaction {
11    /// Gross amount of this transaction (in cents (or local equivalent)).
12    /// A positive value represents funds charged to another party, and a negative value represents funds sent to another party.
13    pub amount: i64,
14    /// The date that the transaction's net funds become available in the Stripe balance.
15    pub available_on: stripe_types::Timestamp,
16    /// The balance that this transaction impacts.
17    pub balance_type: BalanceTransactionBalanceType,
18    /// Time at which the object was created. Measured in seconds since the Unix epoch.
19    pub created: stripe_types::Timestamp,
20    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
21    /// Must be a [supported currency](https://stripe.com/docs/currencies).
22    pub currency: stripe_types::Currency,
23    /// An arbitrary string attached to the object. Often useful for displaying to users.
24    pub description: Option<String>,
25    /// If applicable, this transaction uses an exchange rate.
26    /// If money converts from currency A to currency B, then the `amount` in currency A, multipled by the `exchange_rate`, equals the `amount` in currency B.
27    /// For example, if you charge a customer 10.00 EUR, the PaymentIntent's `amount` is `1000` and `currency` is `eur`.
28    /// If this converts to 12.34 USD in your Stripe account, the BalanceTransaction's `amount` is `1234`, its `currency` is `usd`, and the `exchange_rate` is `1.234`.
29    pub exchange_rate: Option<f64>,
30    /// Fees (in cents (or local equivalent)) paid for this transaction.
31    /// Represented as a positive integer when assessed.
32    pub fee: i64,
33    /// Detailed breakdown of fees (in cents (or local equivalent)) paid for this transaction.
34    pub fee_details: Vec<stripe_shared::Fee>,
35    /// Unique identifier for the object.
36    pub id: stripe_shared::BalanceTransactionId,
37    /// Net impact to a Stripe balance (in cents (or local equivalent)).
38    /// A positive value represents incrementing a Stripe balance, and a negative value decrementing a Stripe balance.
39    /// You can calculate the net impact of a transaction on a balance by `amount` - `fee`.
40    pub net: i64,
41    /// Learn more about how [reporting categories](https://stripe.com/docs/reports/reporting-categories) can help you understand balance transactions from an accounting perspective.
42    pub reporting_category: String,
43    /// This transaction relates to the Stripe object.
44    pub source: Option<stripe_types::Expandable<stripe_shared::BalanceTransactionSource>>,
45    /// The transaction's net funds status in the Stripe balance, which are either `available` or `pending`.
46    pub status: String,
47    /// Transaction type: `adjustment`, `advance`, `advance_funding`, `anticipation_repayment`, `application_fee`, `application_fee_refund`, `charge`, `climate_order_purchase`, `climate_order_refund`, `connect_collection_transfer`, `contribution`, `inbound_transfer`, `inbound_transfer_reversal`, `issuing_authorization_hold`, `issuing_authorization_release`, `issuing_dispute`, `issuing_transaction`, `obligation_outbound`, `obligation_reversal_inbound`, `payment`, `payment_failure_refund`, `payment_network_reserve_hold`, `payment_network_reserve_release`, `payment_refund`, `payment_reversal`, `payment_unreconciled`, `payout`, `payout_cancel`, `payout_failure`, `payout_minimum_balance_hold`, `payout_minimum_balance_release`, `refund`, `refund_failure`, `reserve_transaction`, `reserved_funds`, `reserve_hold`, `reserve_release`, `stripe_fee`, `stripe_fx_fee`, `stripe_balance_payment_debit`, `stripe_balance_payment_debit_reversal`, `tax_fee`, `topup`, `topup_reversal`, `transfer`, `transfer_cancel`, `transfer_failure`, `transfer_refund`, or `fee_credit_funding`.
48    /// Learn more about [balance transaction types and what they represent](https://stripe.com/docs/reports/balance-transaction-types).
49    /// To classify transactions for accounting purposes, consider `reporting_category` instead.
50    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
51    pub type_: BalanceTransactionType,
52}
53#[cfg(feature = "redact-generated-debug")]
54impl std::fmt::Debug for BalanceTransaction {
55    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
56        f.debug_struct("BalanceTransaction").finish_non_exhaustive()
57    }
58}
59#[doc(hidden)]
60pub struct BalanceTransactionBuilder {
61    amount: Option<i64>,
62    available_on: Option<stripe_types::Timestamp>,
63    balance_type: Option<BalanceTransactionBalanceType>,
64    created: Option<stripe_types::Timestamp>,
65    currency: Option<stripe_types::Currency>,
66    description: Option<Option<String>>,
67    exchange_rate: Option<Option<f64>>,
68    fee: Option<i64>,
69    fee_details: Option<Vec<stripe_shared::Fee>>,
70    id: Option<stripe_shared::BalanceTransactionId>,
71    net: Option<i64>,
72    reporting_category: Option<String>,
73    source: Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransactionSource>>>,
74    status: Option<String>,
75    type_: Option<BalanceTransactionType>,
76}
77
78#[allow(
79    unused_variables,
80    irrefutable_let_patterns,
81    clippy::let_unit_value,
82    clippy::match_single_binding,
83    clippy::single_match
84)]
85const _: () = {
86    use miniserde::de::{Map, Visitor};
87    use miniserde::json::Value;
88    use miniserde::{Deserialize, Result, make_place};
89    use stripe_types::miniserde_helpers::FromValueOpt;
90    use stripe_types::{MapBuilder, ObjectDeser};
91
92    make_place!(Place);
93
94    impl Deserialize for BalanceTransaction {
95        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
96            Place::new(out)
97        }
98    }
99
100    struct Builder<'a> {
101        out: &'a mut Option<BalanceTransaction>,
102        builder: BalanceTransactionBuilder,
103    }
104
105    impl Visitor for Place<BalanceTransaction> {
106        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
107            Ok(Box::new(Builder {
108                out: &mut self.out,
109                builder: BalanceTransactionBuilder::deser_default(),
110            }))
111        }
112    }
113
114    impl MapBuilder for BalanceTransactionBuilder {
115        type Out = BalanceTransaction;
116        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
117            Ok(match k {
118                "amount" => Deserialize::begin(&mut self.amount),
119                "available_on" => Deserialize::begin(&mut self.available_on),
120                "balance_type" => Deserialize::begin(&mut self.balance_type),
121                "created" => Deserialize::begin(&mut self.created),
122                "currency" => Deserialize::begin(&mut self.currency),
123                "description" => Deserialize::begin(&mut self.description),
124                "exchange_rate" => Deserialize::begin(&mut self.exchange_rate),
125                "fee" => Deserialize::begin(&mut self.fee),
126                "fee_details" => Deserialize::begin(&mut self.fee_details),
127                "id" => Deserialize::begin(&mut self.id),
128                "net" => Deserialize::begin(&mut self.net),
129                "reporting_category" => Deserialize::begin(&mut self.reporting_category),
130                "source" => Deserialize::begin(&mut self.source),
131                "status" => Deserialize::begin(&mut self.status),
132                "type" => Deserialize::begin(&mut self.type_),
133                _ => <dyn Visitor>::ignore(),
134            })
135        }
136
137        fn deser_default() -> Self {
138            Self {
139                amount: None,
140                available_on: None,
141                balance_type: None,
142                created: None,
143                currency: None,
144                description: Some(None),
145                exchange_rate: Some(None),
146                fee: None,
147                fee_details: None,
148                id: None,
149                net: None,
150                reporting_category: None,
151                source: Some(None),
152                status: None,
153                type_: None,
154            }
155        }
156
157        fn take_out(&mut self) -> Option<Self::Out> {
158            let (
159                Some(amount),
160                Some(available_on),
161                Some(balance_type),
162                Some(created),
163                Some(currency),
164                Some(description),
165                Some(exchange_rate),
166                Some(fee),
167                Some(fee_details),
168                Some(id),
169                Some(net),
170                Some(reporting_category),
171                Some(source),
172                Some(status),
173                Some(type_),
174            ) = (
175                self.amount,
176                self.available_on,
177                self.balance_type.take(),
178                self.created,
179                self.currency.take(),
180                self.description.take(),
181                self.exchange_rate,
182                self.fee,
183                self.fee_details.take(),
184                self.id.take(),
185                self.net,
186                self.reporting_category.take(),
187                self.source.take(),
188                self.status.take(),
189                self.type_.take(),
190            )
191            else {
192                return None;
193            };
194            Some(Self::Out {
195                amount,
196                available_on,
197                balance_type,
198                created,
199                currency,
200                description,
201                exchange_rate,
202                fee,
203                fee_details,
204                id,
205                net,
206                reporting_category,
207                source,
208                status,
209                type_,
210            })
211        }
212    }
213
214    impl Map for Builder<'_> {
215        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
216            self.builder.key(k)
217        }
218
219        fn finish(&mut self) -> Result<()> {
220            *self.out = self.builder.take_out();
221            Ok(())
222        }
223    }
224
225    impl ObjectDeser for BalanceTransaction {
226        type Builder = BalanceTransactionBuilder;
227    }
228
229    impl FromValueOpt for BalanceTransaction {
230        fn from_value(v: Value) -> Option<Self> {
231            let Value::Object(obj) = v else {
232                return None;
233            };
234            let mut b = BalanceTransactionBuilder::deser_default();
235            for (k, v) in obj {
236                match k.as_str() {
237                    "amount" => b.amount = FromValueOpt::from_value(v),
238                    "available_on" => b.available_on = FromValueOpt::from_value(v),
239                    "balance_type" => b.balance_type = FromValueOpt::from_value(v),
240                    "created" => b.created = FromValueOpt::from_value(v),
241                    "currency" => b.currency = FromValueOpt::from_value(v),
242                    "description" => b.description = FromValueOpt::from_value(v),
243                    "exchange_rate" => b.exchange_rate = FromValueOpt::from_value(v),
244                    "fee" => b.fee = FromValueOpt::from_value(v),
245                    "fee_details" => b.fee_details = FromValueOpt::from_value(v),
246                    "id" => b.id = FromValueOpt::from_value(v),
247                    "net" => b.net = FromValueOpt::from_value(v),
248                    "reporting_category" => b.reporting_category = FromValueOpt::from_value(v),
249                    "source" => b.source = FromValueOpt::from_value(v),
250                    "status" => b.status = FromValueOpt::from_value(v),
251                    "type" => b.type_ = FromValueOpt::from_value(v),
252                    _ => {}
253                }
254            }
255            b.take_out()
256        }
257    }
258};
259#[cfg(feature = "serialize")]
260impl serde::Serialize for BalanceTransaction {
261    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
262        use serde::ser::SerializeStruct;
263        let mut s = s.serialize_struct("BalanceTransaction", 16)?;
264        s.serialize_field("amount", &self.amount)?;
265        s.serialize_field("available_on", &self.available_on)?;
266        s.serialize_field("balance_type", &self.balance_type)?;
267        s.serialize_field("created", &self.created)?;
268        s.serialize_field("currency", &self.currency)?;
269        s.serialize_field("description", &self.description)?;
270        s.serialize_field("exchange_rate", &self.exchange_rate)?;
271        s.serialize_field("fee", &self.fee)?;
272        s.serialize_field("fee_details", &self.fee_details)?;
273        s.serialize_field("id", &self.id)?;
274        s.serialize_field("net", &self.net)?;
275        s.serialize_field("reporting_category", &self.reporting_category)?;
276        s.serialize_field("source", &self.source)?;
277        s.serialize_field("status", &self.status)?;
278        s.serialize_field("type", &self.type_)?;
279
280        s.serialize_field("object", "balance_transaction")?;
281        s.end()
282    }
283}
284/// The balance that this transaction impacts.
285#[derive(Clone, Eq, PartialEq)]
286#[non_exhaustive]
287pub enum BalanceTransactionBalanceType {
288    Issuing,
289    Payments,
290    RefundAndDisputePrefunding,
291    RiskReserved,
292    /// An unrecognized value from Stripe. Should not be used as a request parameter.
293    Unknown(String),
294}
295impl BalanceTransactionBalanceType {
296    pub fn as_str(&self) -> &str {
297        use BalanceTransactionBalanceType::*;
298        match self {
299            Issuing => "issuing",
300            Payments => "payments",
301            RefundAndDisputePrefunding => "refund_and_dispute_prefunding",
302            RiskReserved => "risk_reserved",
303            Unknown(v) => v,
304        }
305    }
306}
307
308impl std::str::FromStr for BalanceTransactionBalanceType {
309    type Err = std::convert::Infallible;
310    fn from_str(s: &str) -> Result<Self, Self::Err> {
311        use BalanceTransactionBalanceType::*;
312        match s {
313            "issuing" => Ok(Issuing),
314            "payments" => Ok(Payments),
315            "refund_and_dispute_prefunding" => Ok(RefundAndDisputePrefunding),
316            "risk_reserved" => Ok(RiskReserved),
317            v => {
318                tracing::warn!(
319                    "Unknown value '{}' for enum '{}'",
320                    v,
321                    "BalanceTransactionBalanceType"
322                );
323                Ok(Unknown(v.to_owned()))
324            }
325        }
326    }
327}
328impl std::fmt::Display for BalanceTransactionBalanceType {
329    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
330        f.write_str(self.as_str())
331    }
332}
333
334#[cfg(not(feature = "redact-generated-debug"))]
335impl std::fmt::Debug for BalanceTransactionBalanceType {
336    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
337        f.write_str(self.as_str())
338    }
339}
340#[cfg(feature = "redact-generated-debug")]
341impl std::fmt::Debug for BalanceTransactionBalanceType {
342    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
343        f.debug_struct(stringify!(BalanceTransactionBalanceType)).finish_non_exhaustive()
344    }
345}
346#[cfg(feature = "serialize")]
347impl serde::Serialize for BalanceTransactionBalanceType {
348    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
349    where
350        S: serde::Serializer,
351    {
352        serializer.serialize_str(self.as_str())
353    }
354}
355impl miniserde::Deserialize for BalanceTransactionBalanceType {
356    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
357        crate::Place::new(out)
358    }
359}
360
361impl miniserde::de::Visitor for crate::Place<BalanceTransactionBalanceType> {
362    fn string(&mut self, s: &str) -> miniserde::Result<()> {
363        use std::str::FromStr;
364        self.out = Some(BalanceTransactionBalanceType::from_str(s).expect("infallible"));
365        Ok(())
366    }
367}
368
369stripe_types::impl_from_val_with_from_str!(BalanceTransactionBalanceType);
370#[cfg(feature = "deserialize")]
371impl<'de> serde::Deserialize<'de> for BalanceTransactionBalanceType {
372    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
373        use std::str::FromStr;
374        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
375        Ok(Self::from_str(&s).expect("infallible"))
376    }
377}
378/// Transaction type: `adjustment`, `advance`, `advance_funding`, `anticipation_repayment`, `application_fee`, `application_fee_refund`, `charge`, `climate_order_purchase`, `climate_order_refund`, `connect_collection_transfer`, `contribution`, `inbound_transfer`, `inbound_transfer_reversal`, `issuing_authorization_hold`, `issuing_authorization_release`, `issuing_dispute`, `issuing_transaction`, `obligation_outbound`, `obligation_reversal_inbound`, `payment`, `payment_failure_refund`, `payment_network_reserve_hold`, `payment_network_reserve_release`, `payment_refund`, `payment_reversal`, `payment_unreconciled`, `payout`, `payout_cancel`, `payout_failure`, `payout_minimum_balance_hold`, `payout_minimum_balance_release`, `refund`, `refund_failure`, `reserve_transaction`, `reserved_funds`, `reserve_hold`, `reserve_release`, `stripe_fee`, `stripe_fx_fee`, `stripe_balance_payment_debit`, `stripe_balance_payment_debit_reversal`, `tax_fee`, `topup`, `topup_reversal`, `transfer`, `transfer_cancel`, `transfer_failure`, `transfer_refund`, or `fee_credit_funding`.
379/// Learn more about [balance transaction types and what they represent](https://stripe.com/docs/reports/balance-transaction-types).
380/// To classify transactions for accounting purposes, consider `reporting_category` instead.
381#[derive(Clone, Eq, PartialEq)]
382#[non_exhaustive]
383pub enum BalanceTransactionType {
384    Adjustment,
385    Advance,
386    AdvanceFunding,
387    AnticipationRepayment,
388    ApplicationFee,
389    ApplicationFeeRefund,
390    Charge,
391    ClimateOrderPurchase,
392    ClimateOrderRefund,
393    ConnectCollectionTransfer,
394    Contribution,
395    FeeCreditFunding,
396    InboundTransfer,
397    InboundTransferReversal,
398    IssuingAuthorizationHold,
399    IssuingAuthorizationRelease,
400    IssuingDispute,
401    IssuingTransaction,
402    ObligationOutbound,
403    ObligationReversalInbound,
404    Payment,
405    PaymentFailureRefund,
406    PaymentNetworkReserveHold,
407    PaymentNetworkReserveRelease,
408    PaymentRefund,
409    PaymentReversal,
410    PaymentUnreconciled,
411    Payout,
412    PayoutCancel,
413    PayoutFailure,
414    PayoutMinimumBalanceHold,
415    PayoutMinimumBalanceRelease,
416    Refund,
417    RefundFailure,
418    ReserveHold,
419    ReserveRelease,
420    ReserveTransaction,
421    ReservedFunds,
422    StripeBalancePaymentDebit,
423    StripeBalancePaymentDebitReversal,
424    StripeFee,
425    StripeFxFee,
426    TaxFee,
427    Topup,
428    TopupReversal,
429    Transfer,
430    TransferCancel,
431    TransferFailure,
432    TransferRefund,
433    /// An unrecognized value from Stripe. Should not be used as a request parameter.
434    Unknown(String),
435}
436impl BalanceTransactionType {
437    pub fn as_str(&self) -> &str {
438        use BalanceTransactionType::*;
439        match self {
440            Adjustment => "adjustment",
441            Advance => "advance",
442            AdvanceFunding => "advance_funding",
443            AnticipationRepayment => "anticipation_repayment",
444            ApplicationFee => "application_fee",
445            ApplicationFeeRefund => "application_fee_refund",
446            Charge => "charge",
447            ClimateOrderPurchase => "climate_order_purchase",
448            ClimateOrderRefund => "climate_order_refund",
449            ConnectCollectionTransfer => "connect_collection_transfer",
450            Contribution => "contribution",
451            FeeCreditFunding => "fee_credit_funding",
452            InboundTransfer => "inbound_transfer",
453            InboundTransferReversal => "inbound_transfer_reversal",
454            IssuingAuthorizationHold => "issuing_authorization_hold",
455            IssuingAuthorizationRelease => "issuing_authorization_release",
456            IssuingDispute => "issuing_dispute",
457            IssuingTransaction => "issuing_transaction",
458            ObligationOutbound => "obligation_outbound",
459            ObligationReversalInbound => "obligation_reversal_inbound",
460            Payment => "payment",
461            PaymentFailureRefund => "payment_failure_refund",
462            PaymentNetworkReserveHold => "payment_network_reserve_hold",
463            PaymentNetworkReserveRelease => "payment_network_reserve_release",
464            PaymentRefund => "payment_refund",
465            PaymentReversal => "payment_reversal",
466            PaymentUnreconciled => "payment_unreconciled",
467            Payout => "payout",
468            PayoutCancel => "payout_cancel",
469            PayoutFailure => "payout_failure",
470            PayoutMinimumBalanceHold => "payout_minimum_balance_hold",
471            PayoutMinimumBalanceRelease => "payout_minimum_balance_release",
472            Refund => "refund",
473            RefundFailure => "refund_failure",
474            ReserveHold => "reserve_hold",
475            ReserveRelease => "reserve_release",
476            ReserveTransaction => "reserve_transaction",
477            ReservedFunds => "reserved_funds",
478            StripeBalancePaymentDebit => "stripe_balance_payment_debit",
479            StripeBalancePaymentDebitReversal => "stripe_balance_payment_debit_reversal",
480            StripeFee => "stripe_fee",
481            StripeFxFee => "stripe_fx_fee",
482            TaxFee => "tax_fee",
483            Topup => "topup",
484            TopupReversal => "topup_reversal",
485            Transfer => "transfer",
486            TransferCancel => "transfer_cancel",
487            TransferFailure => "transfer_failure",
488            TransferRefund => "transfer_refund",
489            Unknown(v) => v,
490        }
491    }
492}
493
494impl std::str::FromStr for BalanceTransactionType {
495    type Err = std::convert::Infallible;
496    fn from_str(s: &str) -> Result<Self, Self::Err> {
497        use BalanceTransactionType::*;
498        match s {
499            "adjustment" => Ok(Adjustment),
500            "advance" => Ok(Advance),
501            "advance_funding" => Ok(AdvanceFunding),
502            "anticipation_repayment" => Ok(AnticipationRepayment),
503            "application_fee" => Ok(ApplicationFee),
504            "application_fee_refund" => Ok(ApplicationFeeRefund),
505            "charge" => Ok(Charge),
506            "climate_order_purchase" => Ok(ClimateOrderPurchase),
507            "climate_order_refund" => Ok(ClimateOrderRefund),
508            "connect_collection_transfer" => Ok(ConnectCollectionTransfer),
509            "contribution" => Ok(Contribution),
510            "fee_credit_funding" => Ok(FeeCreditFunding),
511            "inbound_transfer" => Ok(InboundTransfer),
512            "inbound_transfer_reversal" => Ok(InboundTransferReversal),
513            "issuing_authorization_hold" => Ok(IssuingAuthorizationHold),
514            "issuing_authorization_release" => Ok(IssuingAuthorizationRelease),
515            "issuing_dispute" => Ok(IssuingDispute),
516            "issuing_transaction" => Ok(IssuingTransaction),
517            "obligation_outbound" => Ok(ObligationOutbound),
518            "obligation_reversal_inbound" => Ok(ObligationReversalInbound),
519            "payment" => Ok(Payment),
520            "payment_failure_refund" => Ok(PaymentFailureRefund),
521            "payment_network_reserve_hold" => Ok(PaymentNetworkReserveHold),
522            "payment_network_reserve_release" => Ok(PaymentNetworkReserveRelease),
523            "payment_refund" => Ok(PaymentRefund),
524            "payment_reversal" => Ok(PaymentReversal),
525            "payment_unreconciled" => Ok(PaymentUnreconciled),
526            "payout" => Ok(Payout),
527            "payout_cancel" => Ok(PayoutCancel),
528            "payout_failure" => Ok(PayoutFailure),
529            "payout_minimum_balance_hold" => Ok(PayoutMinimumBalanceHold),
530            "payout_minimum_balance_release" => Ok(PayoutMinimumBalanceRelease),
531            "refund" => Ok(Refund),
532            "refund_failure" => Ok(RefundFailure),
533            "reserve_hold" => Ok(ReserveHold),
534            "reserve_release" => Ok(ReserveRelease),
535            "reserve_transaction" => Ok(ReserveTransaction),
536            "reserved_funds" => Ok(ReservedFunds),
537            "stripe_balance_payment_debit" => Ok(StripeBalancePaymentDebit),
538            "stripe_balance_payment_debit_reversal" => Ok(StripeBalancePaymentDebitReversal),
539            "stripe_fee" => Ok(StripeFee),
540            "stripe_fx_fee" => Ok(StripeFxFee),
541            "tax_fee" => Ok(TaxFee),
542            "topup" => Ok(Topup),
543            "topup_reversal" => Ok(TopupReversal),
544            "transfer" => Ok(Transfer),
545            "transfer_cancel" => Ok(TransferCancel),
546            "transfer_failure" => Ok(TransferFailure),
547            "transfer_refund" => Ok(TransferRefund),
548            v => {
549                tracing::warn!("Unknown value '{}' for enum '{}'", v, "BalanceTransactionType");
550                Ok(Unknown(v.to_owned()))
551            }
552        }
553    }
554}
555impl std::fmt::Display for BalanceTransactionType {
556    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
557        f.write_str(self.as_str())
558    }
559}
560
561#[cfg(not(feature = "redact-generated-debug"))]
562impl std::fmt::Debug for BalanceTransactionType {
563    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
564        f.write_str(self.as_str())
565    }
566}
567#[cfg(feature = "redact-generated-debug")]
568impl std::fmt::Debug for BalanceTransactionType {
569    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
570        f.debug_struct(stringify!(BalanceTransactionType)).finish_non_exhaustive()
571    }
572}
573#[cfg(feature = "serialize")]
574impl serde::Serialize for BalanceTransactionType {
575    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
576    where
577        S: serde::Serializer,
578    {
579        serializer.serialize_str(self.as_str())
580    }
581}
582impl miniserde::Deserialize for BalanceTransactionType {
583    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
584        crate::Place::new(out)
585    }
586}
587
588impl miniserde::de::Visitor for crate::Place<BalanceTransactionType> {
589    fn string(&mut self, s: &str) -> miniserde::Result<()> {
590        use std::str::FromStr;
591        self.out = Some(BalanceTransactionType::from_str(s).expect("infallible"));
592        Ok(())
593    }
594}
595
596stripe_types::impl_from_val_with_from_str!(BalanceTransactionType);
597#[cfg(feature = "deserialize")]
598impl<'de> serde::Deserialize<'de> for BalanceTransactionType {
599    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
600        use std::str::FromStr;
601        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
602        Ok(Self::from_str(&s).expect("infallible"))
603    }
604}
605impl stripe_types::Object for BalanceTransaction {
606    type Id = stripe_shared::BalanceTransactionId;
607    fn id(&self) -> &Self::Id {
608        &self.id
609    }
610
611    fn into_id(self) -> Self::Id {
612        self.id
613    }
614}
615stripe_types::def_id!(BalanceTransactionId);