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