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