stripe_shared/
application_fee.rs

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