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, multiplied 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: `tax_fund`, `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: `tax_fund`, `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    TaxFund,
428    Topup,
429    TopupReversal,
430    Transfer,
431    TransferCancel,
432    TransferFailure,
433    TransferRefund,
434    /// An unrecognized value from Stripe. Should not be used as a request parameter.
435    Unknown(String),
436}
437impl BalanceTransactionType {
438    pub fn as_str(&self) -> &str {
439        use BalanceTransactionType::*;
440        match self {
441            Adjustment => "adjustment",
442            Advance => "advance",
443            AdvanceFunding => "advance_funding",
444            AnticipationRepayment => "anticipation_repayment",
445            ApplicationFee => "application_fee",
446            ApplicationFeeRefund => "application_fee_refund",
447            Charge => "charge",
448            ClimateOrderPurchase => "climate_order_purchase",
449            ClimateOrderRefund => "climate_order_refund",
450            ConnectCollectionTransfer => "connect_collection_transfer",
451            Contribution => "contribution",
452            FeeCreditFunding => "fee_credit_funding",
453            InboundTransfer => "inbound_transfer",
454            InboundTransferReversal => "inbound_transfer_reversal",
455            IssuingAuthorizationHold => "issuing_authorization_hold",
456            IssuingAuthorizationRelease => "issuing_authorization_release",
457            IssuingDispute => "issuing_dispute",
458            IssuingTransaction => "issuing_transaction",
459            ObligationOutbound => "obligation_outbound",
460            ObligationReversalInbound => "obligation_reversal_inbound",
461            Payment => "payment",
462            PaymentFailureRefund => "payment_failure_refund",
463            PaymentNetworkReserveHold => "payment_network_reserve_hold",
464            PaymentNetworkReserveRelease => "payment_network_reserve_release",
465            PaymentRefund => "payment_refund",
466            PaymentReversal => "payment_reversal",
467            PaymentUnreconciled => "payment_unreconciled",
468            Payout => "payout",
469            PayoutCancel => "payout_cancel",
470            PayoutFailure => "payout_failure",
471            PayoutMinimumBalanceHold => "payout_minimum_balance_hold",
472            PayoutMinimumBalanceRelease => "payout_minimum_balance_release",
473            Refund => "refund",
474            RefundFailure => "refund_failure",
475            ReserveHold => "reserve_hold",
476            ReserveRelease => "reserve_release",
477            ReserveTransaction => "reserve_transaction",
478            ReservedFunds => "reserved_funds",
479            StripeBalancePaymentDebit => "stripe_balance_payment_debit",
480            StripeBalancePaymentDebitReversal => "stripe_balance_payment_debit_reversal",
481            StripeFee => "stripe_fee",
482            StripeFxFee => "stripe_fx_fee",
483            TaxFee => "tax_fee",
484            TaxFund => "tax_fund",
485            Topup => "topup",
486            TopupReversal => "topup_reversal",
487            Transfer => "transfer",
488            TransferCancel => "transfer_cancel",
489            TransferFailure => "transfer_failure",
490            TransferRefund => "transfer_refund",
491            Unknown(v) => v,
492        }
493    }
494}
495
496impl std::str::FromStr for BalanceTransactionType {
497    type Err = std::convert::Infallible;
498    fn from_str(s: &str) -> Result<Self, Self::Err> {
499        use BalanceTransactionType::*;
500        match s {
501            "adjustment" => Ok(Adjustment),
502            "advance" => Ok(Advance),
503            "advance_funding" => Ok(AdvanceFunding),
504            "anticipation_repayment" => Ok(AnticipationRepayment),
505            "application_fee" => Ok(ApplicationFee),
506            "application_fee_refund" => Ok(ApplicationFeeRefund),
507            "charge" => Ok(Charge),
508            "climate_order_purchase" => Ok(ClimateOrderPurchase),
509            "climate_order_refund" => Ok(ClimateOrderRefund),
510            "connect_collection_transfer" => Ok(ConnectCollectionTransfer),
511            "contribution" => Ok(Contribution),
512            "fee_credit_funding" => Ok(FeeCreditFunding),
513            "inbound_transfer" => Ok(InboundTransfer),
514            "inbound_transfer_reversal" => Ok(InboundTransferReversal),
515            "issuing_authorization_hold" => Ok(IssuingAuthorizationHold),
516            "issuing_authorization_release" => Ok(IssuingAuthorizationRelease),
517            "issuing_dispute" => Ok(IssuingDispute),
518            "issuing_transaction" => Ok(IssuingTransaction),
519            "obligation_outbound" => Ok(ObligationOutbound),
520            "obligation_reversal_inbound" => Ok(ObligationReversalInbound),
521            "payment" => Ok(Payment),
522            "payment_failure_refund" => Ok(PaymentFailureRefund),
523            "payment_network_reserve_hold" => Ok(PaymentNetworkReserveHold),
524            "payment_network_reserve_release" => Ok(PaymentNetworkReserveRelease),
525            "payment_refund" => Ok(PaymentRefund),
526            "payment_reversal" => Ok(PaymentReversal),
527            "payment_unreconciled" => Ok(PaymentUnreconciled),
528            "payout" => Ok(Payout),
529            "payout_cancel" => Ok(PayoutCancel),
530            "payout_failure" => Ok(PayoutFailure),
531            "payout_minimum_balance_hold" => Ok(PayoutMinimumBalanceHold),
532            "payout_minimum_balance_release" => Ok(PayoutMinimumBalanceRelease),
533            "refund" => Ok(Refund),
534            "refund_failure" => Ok(RefundFailure),
535            "reserve_hold" => Ok(ReserveHold),
536            "reserve_release" => Ok(ReserveRelease),
537            "reserve_transaction" => Ok(ReserveTransaction),
538            "reserved_funds" => Ok(ReservedFunds),
539            "stripe_balance_payment_debit" => Ok(StripeBalancePaymentDebit),
540            "stripe_balance_payment_debit_reversal" => Ok(StripeBalancePaymentDebitReversal),
541            "stripe_fee" => Ok(StripeFee),
542            "stripe_fx_fee" => Ok(StripeFxFee),
543            "tax_fee" => Ok(TaxFee),
544            "tax_fund" => Ok(TaxFund),
545            "topup" => Ok(Topup),
546            "topup_reversal" => Ok(TopupReversal),
547            "transfer" => Ok(Transfer),
548            "transfer_cancel" => Ok(TransferCancel),
549            "transfer_failure" => Ok(TransferFailure),
550            "transfer_refund" => Ok(TransferRefund),
551            v => {
552                tracing::warn!("Unknown value '{}' for enum '{}'", v, "BalanceTransactionType");
553                Ok(Unknown(v.to_owned()))
554            }
555        }
556    }
557}
558impl std::fmt::Display for BalanceTransactionType {
559    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
560        f.write_str(self.as_str())
561    }
562}
563
564#[cfg(not(feature = "redact-generated-debug"))]
565impl std::fmt::Debug for BalanceTransactionType {
566    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
567        f.write_str(self.as_str())
568    }
569}
570#[cfg(feature = "redact-generated-debug")]
571impl std::fmt::Debug for BalanceTransactionType {
572    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
573        f.debug_struct(stringify!(BalanceTransactionType)).finish_non_exhaustive()
574    }
575}
576#[cfg(feature = "serialize")]
577impl serde::Serialize for BalanceTransactionType {
578    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
579    where
580        S: serde::Serializer,
581    {
582        serializer.serialize_str(self.as_str())
583    }
584}
585impl miniserde::Deserialize for BalanceTransactionType {
586    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
587        crate::Place::new(out)
588    }
589}
590
591impl miniserde::de::Visitor for crate::Place<BalanceTransactionType> {
592    fn string(&mut self, s: &str) -> miniserde::Result<()> {
593        use std::str::FromStr;
594        self.out = Some(BalanceTransactionType::from_str(s).expect("infallible"));
595        Ok(())
596    }
597}
598
599stripe_types::impl_from_val_with_from_str!(BalanceTransactionType);
600#[cfg(feature = "deserialize")]
601impl<'de> serde::Deserialize<'de> for BalanceTransactionType {
602    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
603        use std::str::FromStr;
604        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
605        Ok(Self::from_str(&s).expect("infallible"))
606    }
607}
608impl stripe_types::Object for BalanceTransaction {
609    type Id = stripe_shared::BalanceTransactionId;
610    fn id(&self) -> &Self::Id {
611        &self.id
612    }
613
614    fn into_id(self) -> Self::Id {
615        self.id
616    }
617}
618stripe_types::def_id!(BalanceTransactionId);