Skip to main content

stripe_shared/
application_fee.rs

1/// For more details see <<https://stripe.com/docs/api/application_fees/object>>.
2#[derive(Clone)]
3#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct ApplicationFee {
6    /// ID of the Stripe account this fee was taken from.
7    pub account: stripe_types::Expandable<stripe_shared::Account>,
8    /// Amount earned, in cents (or local equivalent).
9    pub amount: i64,
10    /// Amount in cents (or local equivalent) refunded (can be less than the amount attribute on the fee if a partial refund was issued).
11    pub amount_refunded: i64,
12    /// ID of the Connect application that earned the fee.
13    pub application: stripe_types::Expandable<stripe_shared::Application>,
14    /// Balance transaction that describes the impact of this collected application fee on your account balance (not including refunds).
15    pub balance_transaction: Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
16    /// ID of the charge that the application fee was taken from.
17    pub charge: stripe_types::Expandable<stripe_shared::Charge>,
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    /// Polymorphic source of the application fee.
24    /// Includes the ID of the object the application fee was created from.
25    pub fee_source: Option<stripe_shared::PlatformEarningFeeSource>,
26    /// Unique identifier for the object.
27    pub id: stripe_shared::ApplicationFeeId,
28    /// If the object exists in live mode, the value is `true`.
29    /// If the object exists in test mode, the value is `false`.
30    pub livemode: bool,
31    /// ID of the corresponding charge on the platform account, if this fee was the result of a charge using the `destination` parameter.
32    pub originating_transaction: Option<stripe_types::Expandable<stripe_shared::Charge>>,
33    /// Whether the fee has been fully refunded.
34    /// If the fee is only partially refunded, this attribute will still be false.
35    pub refunded: bool,
36    /// A list of refunds that have been applied to the fee.
37    pub refunds: stripe_types::List<stripe_shared::ApplicationFeeRefund>,
38}
39#[cfg(feature = "redact-generated-debug")]
40impl std::fmt::Debug for ApplicationFee {
41    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
42        f.debug_struct("ApplicationFee").finish_non_exhaustive()
43    }
44}
45#[doc(hidden)]
46pub struct ApplicationFeeBuilder {
47    account: Option<stripe_types::Expandable<stripe_shared::Account>>,
48    amount: Option<i64>,
49    amount_refunded: Option<i64>,
50    application: Option<stripe_types::Expandable<stripe_shared::Application>>,
51    balance_transaction:
52        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
53    charge: Option<stripe_types::Expandable<stripe_shared::Charge>>,
54    created: Option<stripe_types::Timestamp>,
55    currency: Option<stripe_types::Currency>,
56    fee_source: Option<Option<stripe_shared::PlatformEarningFeeSource>>,
57    id: Option<stripe_shared::ApplicationFeeId>,
58    livemode: Option<bool>,
59    originating_transaction: Option<Option<stripe_types::Expandable<stripe_shared::Charge>>>,
60    refunded: Option<bool>,
61    refunds: Option<stripe_types::List<stripe_shared::ApplicationFeeRefund>>,
62}
63
64#[allow(
65    unused_variables,
66    irrefutable_let_patterns,
67    clippy::let_unit_value,
68    clippy::match_single_binding,
69    clippy::single_match
70)]
71const _: () = {
72    use miniserde::de::{Map, Visitor};
73    use miniserde::json::Value;
74    use miniserde::{Deserialize, Result, make_place};
75    use stripe_types::miniserde_helpers::FromValueOpt;
76    use stripe_types::{MapBuilder, ObjectDeser};
77
78    make_place!(Place);
79
80    impl Deserialize for ApplicationFee {
81        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
82            Place::new(out)
83        }
84    }
85
86    struct Builder<'a> {
87        out: &'a mut Option<ApplicationFee>,
88        builder: ApplicationFeeBuilder,
89    }
90
91    impl Visitor for Place<ApplicationFee> {
92        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
93            Ok(Box::new(Builder {
94                out: &mut self.out,
95                builder: ApplicationFeeBuilder::deser_default(),
96            }))
97        }
98    }
99
100    impl MapBuilder for ApplicationFeeBuilder {
101        type Out = ApplicationFee;
102        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
103            Ok(match k {
104                "account" => Deserialize::begin(&mut self.account),
105                "amount" => Deserialize::begin(&mut self.amount),
106                "amount_refunded" => Deserialize::begin(&mut self.amount_refunded),
107                "application" => Deserialize::begin(&mut self.application),
108                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
109                "charge" => Deserialize::begin(&mut self.charge),
110                "created" => Deserialize::begin(&mut self.created),
111                "currency" => Deserialize::begin(&mut self.currency),
112                "fee_source" => Deserialize::begin(&mut self.fee_source),
113                "id" => Deserialize::begin(&mut self.id),
114                "livemode" => Deserialize::begin(&mut self.livemode),
115                "originating_transaction" => Deserialize::begin(&mut self.originating_transaction),
116                "refunded" => Deserialize::begin(&mut self.refunded),
117                "refunds" => Deserialize::begin(&mut self.refunds),
118                _ => <dyn Visitor>::ignore(),
119            })
120        }
121
122        fn deser_default() -> Self {
123            Self {
124                account: None,
125                amount: None,
126                amount_refunded: None,
127                application: None,
128                balance_transaction: Some(None),
129                charge: None,
130                created: None,
131                currency: None,
132                fee_source: Some(None),
133                id: None,
134                livemode: None,
135                originating_transaction: Some(None),
136                refunded: None,
137                refunds: None,
138            }
139        }
140
141        fn take_out(&mut self) -> Option<Self::Out> {
142            let (
143                Some(account),
144                Some(amount),
145                Some(amount_refunded),
146                Some(application),
147                Some(balance_transaction),
148                Some(charge),
149                Some(created),
150                Some(currency),
151                Some(fee_source),
152                Some(id),
153                Some(livemode),
154                Some(originating_transaction),
155                Some(refunded),
156                Some(refunds),
157            ) = (
158                self.account.take(),
159                self.amount,
160                self.amount_refunded,
161                self.application.take(),
162                self.balance_transaction.take(),
163                self.charge.take(),
164                self.created,
165                self.currency.take(),
166                self.fee_source.take(),
167                self.id.take(),
168                self.livemode,
169                self.originating_transaction.take(),
170                self.refunded,
171                self.refunds.take(),
172            )
173            else {
174                return None;
175            };
176            Some(Self::Out {
177                account,
178                amount,
179                amount_refunded,
180                application,
181                balance_transaction,
182                charge,
183                created,
184                currency,
185                fee_source,
186                id,
187                livemode,
188                originating_transaction,
189                refunded,
190                refunds,
191            })
192        }
193    }
194
195    impl Map for Builder<'_> {
196        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
197            self.builder.key(k)
198        }
199
200        fn finish(&mut self) -> Result<()> {
201            *self.out = self.builder.take_out();
202            Ok(())
203        }
204    }
205
206    impl ObjectDeser for ApplicationFee {
207        type Builder = ApplicationFeeBuilder;
208    }
209
210    impl FromValueOpt for ApplicationFee {
211        fn from_value(v: Value) -> Option<Self> {
212            let Value::Object(obj) = v else {
213                return None;
214            };
215            let mut b = ApplicationFeeBuilder::deser_default();
216            for (k, v) in obj {
217                match k.as_str() {
218                    "account" => b.account = FromValueOpt::from_value(v),
219                    "amount" => b.amount = FromValueOpt::from_value(v),
220                    "amount_refunded" => b.amount_refunded = FromValueOpt::from_value(v),
221                    "application" => b.application = FromValueOpt::from_value(v),
222                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
223                    "charge" => b.charge = FromValueOpt::from_value(v),
224                    "created" => b.created = FromValueOpt::from_value(v),
225                    "currency" => b.currency = FromValueOpt::from_value(v),
226                    "fee_source" => b.fee_source = FromValueOpt::from_value(v),
227                    "id" => b.id = FromValueOpt::from_value(v),
228                    "livemode" => b.livemode = FromValueOpt::from_value(v),
229                    "originating_transaction" => {
230                        b.originating_transaction = FromValueOpt::from_value(v)
231                    }
232                    "refunded" => b.refunded = FromValueOpt::from_value(v),
233                    "refunds" => b.refunds = FromValueOpt::from_value(v),
234                    _ => {}
235                }
236            }
237            b.take_out()
238        }
239    }
240};
241#[cfg(feature = "serialize")]
242impl serde::Serialize for ApplicationFee {
243    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
244        use serde::ser::SerializeStruct;
245        let mut s = s.serialize_struct("ApplicationFee", 15)?;
246        s.serialize_field("account", &self.account)?;
247        s.serialize_field("amount", &self.amount)?;
248        s.serialize_field("amount_refunded", &self.amount_refunded)?;
249        s.serialize_field("application", &self.application)?;
250        s.serialize_field("balance_transaction", &self.balance_transaction)?;
251        s.serialize_field("charge", &self.charge)?;
252        s.serialize_field("created", &self.created)?;
253        s.serialize_field("currency", &self.currency)?;
254        s.serialize_field("fee_source", &self.fee_source)?;
255        s.serialize_field("id", &self.id)?;
256        s.serialize_field("livemode", &self.livemode)?;
257        s.serialize_field("originating_transaction", &self.originating_transaction)?;
258        s.serialize_field("refunded", &self.refunded)?;
259        s.serialize_field("refunds", &self.refunds)?;
260
261        s.serialize_field("object", "application_fee")?;
262        s.end()
263    }
264}
265impl stripe_types::Object for ApplicationFee {
266    type Id = stripe_shared::ApplicationFeeId;
267    fn id(&self) -> &Self::Id {
268        &self.id
269    }
270
271    fn into_id(self) -> Self::Id {
272        self.id
273    }
274}
275stripe_types::def_id!(ApplicationFeeId);