stripe_shared/
transfer_data.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct TransferData {
5    /// The amount transferred to the destination account.
6    /// This transfer will occur automatically after the payment succeeds.
7    /// If no amount is specified, by default the entire payment amount is transferred to the destination account.
8    /// The amount must be less than or equal to the [amount](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-amount), and must be a positive integer.
9    ///  representing how much to transfer in the smallest currency unit (e.g., 100 cents to charge $1.00).
10    pub amount: Option<i64>,
11    /// The account (if any) that the payment is attributed to for tax reporting, and where funds from the payment are transferred to after payment success.
12    pub destination: stripe_types::Expandable<stripe_shared::Account>,
13}
14#[doc(hidden)]
15pub struct TransferDataBuilder {
16    amount: Option<Option<i64>>,
17    destination: Option<stripe_types::Expandable<stripe_shared::Account>>,
18}
19
20#[allow(
21    unused_variables,
22    irrefutable_let_patterns,
23    clippy::let_unit_value,
24    clippy::match_single_binding,
25    clippy::single_match
26)]
27const _: () = {
28    use miniserde::de::{Map, Visitor};
29    use miniserde::json::Value;
30    use miniserde::{Deserialize, Result, make_place};
31    use stripe_types::miniserde_helpers::FromValueOpt;
32    use stripe_types::{MapBuilder, ObjectDeser};
33
34    make_place!(Place);
35
36    impl Deserialize for TransferData {
37        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
38            Place::new(out)
39        }
40    }
41
42    struct Builder<'a> {
43        out: &'a mut Option<TransferData>,
44        builder: TransferDataBuilder,
45    }
46
47    impl Visitor for Place<TransferData> {
48        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
49            Ok(Box::new(Builder {
50                out: &mut self.out,
51                builder: TransferDataBuilder::deser_default(),
52            }))
53        }
54    }
55
56    impl MapBuilder for TransferDataBuilder {
57        type Out = TransferData;
58        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
59            Ok(match k {
60                "amount" => Deserialize::begin(&mut self.amount),
61                "destination" => Deserialize::begin(&mut self.destination),
62                _ => <dyn Visitor>::ignore(),
63            })
64        }
65
66        fn deser_default() -> Self {
67            Self { amount: Deserialize::default(), destination: Deserialize::default() }
68        }
69
70        fn take_out(&mut self) -> Option<Self::Out> {
71            let (Some(amount), Some(destination)) = (self.amount, self.destination.take()) else {
72                return None;
73            };
74            Some(Self::Out { amount, destination })
75        }
76    }
77
78    impl Map for Builder<'_> {
79        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
80            self.builder.key(k)
81        }
82
83        fn finish(&mut self) -> Result<()> {
84            *self.out = self.builder.take_out();
85            Ok(())
86        }
87    }
88
89    impl ObjectDeser for TransferData {
90        type Builder = TransferDataBuilder;
91    }
92
93    impl FromValueOpt for TransferData {
94        fn from_value(v: Value) -> Option<Self> {
95            let Value::Object(obj) = v else {
96                return None;
97            };
98            let mut b = TransferDataBuilder::deser_default();
99            for (k, v) in obj {
100                match k.as_str() {
101                    "amount" => b.amount = FromValueOpt::from_value(v),
102                    "destination" => b.destination = FromValueOpt::from_value(v),
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};