1#[derive(Clone, Debug)]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5#[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(tag = "object"))]
6pub enum BalanceTransactionSource {
7 #[cfg_attr(
8 any(feature = "deserialize", feature = "serialize"),
9 serde(rename = "application_fee")
10 )]
11 ApplicationFee(stripe_shared::ApplicationFee),
12 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "charge"))]
13 Charge(stripe_shared::Charge),
14 #[cfg_attr(
15 any(feature = "deserialize", feature = "serialize"),
16 serde(rename = "connect_collection_transfer")
17 )]
18 ConnectCollectionTransfer(stripe_shared::ConnectCollectionTransfer),
19 #[cfg_attr(
20 any(feature = "deserialize", feature = "serialize"),
21 serde(rename = "customer_cash_balance_transaction")
22 )]
23 CustomerCashBalanceTransaction(stripe_shared::CustomerCashBalanceTransaction),
24 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "dispute"))]
25 Dispute(stripe_shared::Dispute),
26 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "fee_refund"))]
27 ApplicationFeeRefund(stripe_shared::ApplicationFeeRefund),
28 #[cfg_attr(
29 any(feature = "deserialize", feature = "serialize"),
30 serde(rename = "issuing.authorization")
31 )]
32 IssuingAuthorization(stripe_shared::IssuingAuthorization),
33 #[cfg_attr(
34 any(feature = "deserialize", feature = "serialize"),
35 serde(rename = "issuing.dispute")
36 )]
37 IssuingDispute(stripe_shared::IssuingDispute),
38 #[cfg_attr(
39 any(feature = "deserialize", feature = "serialize"),
40 serde(rename = "issuing.transaction")
41 )]
42 IssuingTransaction(stripe_shared::IssuingTransaction),
43 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "payout"))]
44 Payout(stripe_shared::Payout),
45 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "refund"))]
46 Refund(stripe_shared::Refund),
47 #[cfg_attr(
48 any(feature = "deserialize", feature = "serialize"),
49 serde(rename = "reserve_transaction")
50 )]
51 ReserveTransaction(stripe_shared::ReserveTransaction),
52 #[cfg_attr(
53 any(feature = "deserialize", feature = "serialize"),
54 serde(rename = "tax_deducted_at_source")
55 )]
56 TaxDeductedAtSource(stripe_shared::TaxDeductedAtSource),
57 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "topup"))]
58 Topup(stripe_shared::Topup),
59 #[cfg_attr(any(feature = "deserialize", feature = "serialize"), serde(rename = "transfer"))]
60 Transfer(stripe_shared::Transfer),
61 #[cfg_attr(
62 any(feature = "deserialize", feature = "serialize"),
63 serde(rename = "transfer_reversal")
64 )]
65 TransferReversal(stripe_shared::TransferReversal),
66}
67
68#[derive(Default)]
69pub struct BalanceTransactionSourceBuilder {
70 inner: stripe_types::miniserde_helpers::ObjectBuilderInner,
71}
72
73const _: () = {
74 use miniserde::de::{Map, Visitor};
75 use miniserde::json::Value;
76 use miniserde::{Deserialize, Result, make_place};
77 use stripe_types::MapBuilder;
78 use stripe_types::miniserde_helpers::FromValueOpt;
79
80 use super::*;
81
82 make_place!(Place);
83
84 struct Builder<'a> {
85 out: &'a mut Option<BalanceTransactionSource>,
86 builder: BalanceTransactionSourceBuilder,
87 }
88
89 impl Deserialize for BalanceTransactionSource {
90 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
91 Place::new(out)
92 }
93 }
94
95 impl Visitor for Place<BalanceTransactionSource> {
96 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
97 Ok(Box::new(Builder { out: &mut self.out, builder: Default::default() }))
98 }
99 }
100
101 impl Map for Builder<'_> {
102 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103 self.builder.key(k)
104 }
105
106 fn finish(&mut self) -> Result<()> {
107 *self.out = self.builder.take_out();
108 Ok(())
109 }
110 }
111
112 impl MapBuilder for BalanceTransactionSourceBuilder {
113 type Out = BalanceTransactionSource;
114 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
115 self.inner.key_inner(k)
116 }
117
118 fn deser_default() -> Self {
119 Self::default()
120 }
121
122 fn take_out(&mut self) -> Option<Self::Out> {
123 let (k, o) = self.inner.finish_inner()?;
124 BalanceTransactionSource::construct(&k, o)
125 }
126 }
127
128 impl stripe_types::ObjectDeser for BalanceTransactionSource {
129 type Builder = BalanceTransactionSourceBuilder;
130 }
131 impl BalanceTransactionSource {
132 fn construct(key: &str, o: miniserde::json::Object) -> Option<Self> {
133 Some(match key {
134 "application_fee" => {
135 Self::ApplicationFee(FromValueOpt::from_value(Value::Object(o))?)
136 }
137 "charge" => Self::Charge(FromValueOpt::from_value(Value::Object(o))?),
138 "connect_collection_transfer" => {
139 Self::ConnectCollectionTransfer(FromValueOpt::from_value(Value::Object(o))?)
140 }
141 "customer_cash_balance_transaction" => Self::CustomerCashBalanceTransaction(
142 FromValueOpt::from_value(Value::Object(o))?,
143 ),
144 "dispute" => Self::Dispute(FromValueOpt::from_value(Value::Object(o))?),
145 "fee_refund" => {
146 Self::ApplicationFeeRefund(FromValueOpt::from_value(Value::Object(o))?)
147 }
148 "issuing.authorization" => {
149 Self::IssuingAuthorization(FromValueOpt::from_value(Value::Object(o))?)
150 }
151 "issuing.dispute" => {
152 Self::IssuingDispute(FromValueOpt::from_value(Value::Object(o))?)
153 }
154 "issuing.transaction" => {
155 Self::IssuingTransaction(FromValueOpt::from_value(Value::Object(o))?)
156 }
157 "payout" => Self::Payout(FromValueOpt::from_value(Value::Object(o))?),
158 "refund" => Self::Refund(FromValueOpt::from_value(Value::Object(o))?),
159 "reserve_transaction" => {
160 Self::ReserveTransaction(FromValueOpt::from_value(Value::Object(o))?)
161 }
162 "tax_deducted_at_source" => {
163 Self::TaxDeductedAtSource(FromValueOpt::from_value(Value::Object(o))?)
164 }
165 "topup" => Self::Topup(FromValueOpt::from_value(Value::Object(o))?),
166 "transfer" => Self::Transfer(FromValueOpt::from_value(Value::Object(o))?),
167 "transfer_reversal" => {
168 Self::TransferReversal(FromValueOpt::from_value(Value::Object(o))?)
169 }
170
171 _ => {
172 tracing::warn!(
173 "Unknown object type '{}' for enum '{}'",
174 key,
175 "BalanceTransactionSource"
176 );
177 return None;
178 }
179 })
180 }
181 }
182
183 impl FromValueOpt for BalanceTransactionSource {
184 fn from_value(v: Value) -> Option<Self> {
185 let (typ, obj) = stripe_types::miniserde_helpers::extract_object_discr(v)?;
186 Self::construct(&typ, obj)
187 }
188 }
189};
190
191impl stripe_types::Object for BalanceTransactionSource {
192 type Id = smol_str::SmolStr;
193 fn id(&self) -> &Self::Id {
194 match self {
195 Self::ApplicationFee(v) => v.id.inner(),
196 Self::Charge(v) => v.id.inner(),
197 Self::ConnectCollectionTransfer(v) => v.id.inner(),
198 Self::CustomerCashBalanceTransaction(v) => v.id.inner(),
199 Self::Dispute(v) => v.id.inner(),
200 Self::ApplicationFeeRefund(v) => v.id.inner(),
201 Self::IssuingAuthorization(v) => v.id.inner(),
202 Self::IssuingDispute(v) => v.id.inner(),
203 Self::IssuingTransaction(v) => v.id.inner(),
204 Self::Payout(v) => v.id.inner(),
205 Self::Refund(v) => v.id.inner(),
206 Self::ReserveTransaction(v) => v.id.inner(),
207 Self::TaxDeductedAtSource(v) => v.id.inner(),
208 Self::Topup(v) => v.id.inner(),
209 Self::Transfer(v) => v.id.inner(),
210 Self::TransferReversal(v) => v.id.inner(),
211 }
212 }
213
214 fn into_id(self) -> Self::Id {
215 match self {
216 Self::ApplicationFee(v) => v.id.into_inner(),
217 Self::Charge(v) => v.id.into_inner(),
218 Self::ConnectCollectionTransfer(v) => v.id.into_inner(),
219 Self::CustomerCashBalanceTransaction(v) => v.id.into_inner(),
220 Self::Dispute(v) => v.id.into_inner(),
221 Self::ApplicationFeeRefund(v) => v.id.into_inner(),
222 Self::IssuingAuthorization(v) => v.id.into_inner(),
223 Self::IssuingDispute(v) => v.id.into_inner(),
224 Self::IssuingTransaction(v) => v.id.into_inner(),
225 Self::Payout(v) => v.id.into_inner(),
226 Self::Refund(v) => v.id.into_inner(),
227 Self::ReserveTransaction(v) => v.id.into_inner(),
228 Self::TaxDeductedAtSource(v) => v.id.into_inner(),
229 Self::Topup(v) => v.id.into_inner(),
230 Self::Transfer(v) => v.id.into_inner(),
231 Self::TransferReversal(v) => v.id.into_inner(),
232 }
233 }
234}