Skip to main content

stripe_shared/
application_fee_refund.rs

1/// `Application Fee Refund` objects allow you to refund an application fee that
2/// has previously been created but not yet refunded. Funds will be refunded to
3/// the Stripe account from which the fee was originally collected.
4///
5/// Related guide: [Refunding application fees](https://docs.stripe.com/connect/destination-charges#refunding-app-fee).
6///
7/// For more details see <<https://stripe.com/docs/api/fee_refunds/object>>.
8#[derive(Clone)]
9#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
10#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
11pub struct ApplicationFeeRefund {
12    /// Amount, in cents (or local equivalent).
13    pub amount: i64,
14    /// Balance transaction that describes the impact on your account balance.
15    pub balance_transaction: Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>,
16    /// Time at which the object was created. Measured in seconds since the Unix epoch.
17    pub created: stripe_types::Timestamp,
18    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
19    /// Must be a [supported currency](https://stripe.com/docs/currencies).
20    pub currency: stripe_types::Currency,
21    /// ID of the application fee that was refunded.
22    pub fee: stripe_types::Expandable<stripe_shared::ApplicationFee>,
23    /// Unique identifier for the object.
24    pub id: stripe_shared::ApplicationFeeRefundId,
25    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
26    /// This can be useful for storing additional information about the object in a structured format.
27    pub metadata: Option<std::collections::HashMap<String, String>>,
28}
29#[cfg(feature = "redact-generated-debug")]
30impl std::fmt::Debug for ApplicationFeeRefund {
31    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
32        f.debug_struct("ApplicationFeeRefund").finish_non_exhaustive()
33    }
34}
35#[doc(hidden)]
36pub struct ApplicationFeeRefundBuilder {
37    amount: Option<i64>,
38    balance_transaction:
39        Option<Option<stripe_types::Expandable<stripe_shared::BalanceTransaction>>>,
40    created: Option<stripe_types::Timestamp>,
41    currency: Option<stripe_types::Currency>,
42    fee: Option<stripe_types::Expandable<stripe_shared::ApplicationFee>>,
43    id: Option<stripe_shared::ApplicationFeeRefundId>,
44    metadata: Option<Option<std::collections::HashMap<String, String>>>,
45}
46
47#[allow(
48    unused_variables,
49    irrefutable_let_patterns,
50    clippy::let_unit_value,
51    clippy::match_single_binding,
52    clippy::single_match
53)]
54const _: () = {
55    use miniserde::de::{Map, Visitor};
56    use miniserde::json::Value;
57    use miniserde::{Deserialize, Result, make_place};
58    use stripe_types::miniserde_helpers::FromValueOpt;
59    use stripe_types::{MapBuilder, ObjectDeser};
60
61    make_place!(Place);
62
63    impl Deserialize for ApplicationFeeRefund {
64        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
65            Place::new(out)
66        }
67    }
68
69    struct Builder<'a> {
70        out: &'a mut Option<ApplicationFeeRefund>,
71        builder: ApplicationFeeRefundBuilder,
72    }
73
74    impl Visitor for Place<ApplicationFeeRefund> {
75        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
76            Ok(Box::new(Builder {
77                out: &mut self.out,
78                builder: ApplicationFeeRefundBuilder::deser_default(),
79            }))
80        }
81    }
82
83    impl MapBuilder for ApplicationFeeRefundBuilder {
84        type Out = ApplicationFeeRefund;
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            Ok(match k {
87                "amount" => Deserialize::begin(&mut self.amount),
88                "balance_transaction" => Deserialize::begin(&mut self.balance_transaction),
89                "created" => Deserialize::begin(&mut self.created),
90                "currency" => Deserialize::begin(&mut self.currency),
91                "fee" => Deserialize::begin(&mut self.fee),
92                "id" => Deserialize::begin(&mut self.id),
93                "metadata" => Deserialize::begin(&mut self.metadata),
94                _ => <dyn Visitor>::ignore(),
95            })
96        }
97
98        fn deser_default() -> Self {
99            Self {
100                amount: None,
101                balance_transaction: Some(None),
102                created: None,
103                currency: None,
104                fee: None,
105                id: None,
106                metadata: Some(None),
107            }
108        }
109
110        fn take_out(&mut self) -> Option<Self::Out> {
111            let (
112                Some(amount),
113                Some(balance_transaction),
114                Some(created),
115                Some(currency),
116                Some(fee),
117                Some(id),
118                Some(metadata),
119            ) = (
120                self.amount,
121                self.balance_transaction.take(),
122                self.created,
123                self.currency.take(),
124                self.fee.take(),
125                self.id.take(),
126                self.metadata.take(),
127            )
128            else {
129                return None;
130            };
131            Some(Self::Out { amount, balance_transaction, created, currency, fee, id, metadata })
132        }
133    }
134
135    impl Map for Builder<'_> {
136        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
137            self.builder.key(k)
138        }
139
140        fn finish(&mut self) -> Result<()> {
141            *self.out = self.builder.take_out();
142            Ok(())
143        }
144    }
145
146    impl ObjectDeser for ApplicationFeeRefund {
147        type Builder = ApplicationFeeRefundBuilder;
148    }
149
150    impl FromValueOpt for ApplicationFeeRefund {
151        fn from_value(v: Value) -> Option<Self> {
152            let Value::Object(obj) = v else {
153                return None;
154            };
155            let mut b = ApplicationFeeRefundBuilder::deser_default();
156            for (k, v) in obj {
157                match k.as_str() {
158                    "amount" => b.amount = FromValueOpt::from_value(v),
159                    "balance_transaction" => b.balance_transaction = FromValueOpt::from_value(v),
160                    "created" => b.created = FromValueOpt::from_value(v),
161                    "currency" => b.currency = FromValueOpt::from_value(v),
162                    "fee" => b.fee = FromValueOpt::from_value(v),
163                    "id" => b.id = FromValueOpt::from_value(v),
164                    "metadata" => b.metadata = FromValueOpt::from_value(v),
165                    _ => {}
166                }
167            }
168            b.take_out()
169        }
170    }
171};
172#[cfg(feature = "serialize")]
173impl serde::Serialize for ApplicationFeeRefund {
174    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
175        use serde::ser::SerializeStruct;
176        let mut s = s.serialize_struct("ApplicationFeeRefund", 8)?;
177        s.serialize_field("amount", &self.amount)?;
178        s.serialize_field("balance_transaction", &self.balance_transaction)?;
179        s.serialize_field("created", &self.created)?;
180        s.serialize_field("currency", &self.currency)?;
181        s.serialize_field("fee", &self.fee)?;
182        s.serialize_field("id", &self.id)?;
183        s.serialize_field("metadata", &self.metadata)?;
184
185        s.serialize_field("object", "fee_refund")?;
186        s.end()
187    }
188}
189impl stripe_types::Object for ApplicationFeeRefund {
190    type Id = stripe_shared::ApplicationFeeRefundId;
191    fn id(&self) -> &Self::Id {
192        &self.id
193    }
194
195    fn into_id(self) -> Self::Id {
196        self.id
197    }
198}
199stripe_types::def_id!(ApplicationFeeRefundId);