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::{make_place, Deserialize, Result};
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
63                _ => <dyn Visitor>::ignore(),
64            })
65        }
66
67        fn deser_default() -> Self {
68            Self { amount: Deserialize::default(), destination: Deserialize::default() }
69        }
70
71        fn take_out(&mut self) -> Option<Self::Out> {
72            let (Some(amount), Some(destination)) = (self.amount, self.destination.take()) else {
73                return None;
74            };
75            Some(Self::Out { amount, destination })
76        }
77    }
78
79    impl<'a> Map for Builder<'a> {
80        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
81            self.builder.key(k)
82        }
83
84        fn finish(&mut self) -> Result<()> {
85            *self.out = self.builder.take_out();
86            Ok(())
87        }
88    }
89
90    impl ObjectDeser for TransferData {
91        type Builder = TransferDataBuilder;
92    }
93
94    impl FromValueOpt for TransferData {
95        fn from_value(v: Value) -> Option<Self> {
96            let Value::Object(obj) = v else {
97                return None;
98            };
99            let mut b = TransferDataBuilder::deser_default();
100            for (k, v) in obj {
101                match k.as_str() {
102                    "amount" => b.amount = FromValueOpt::from_value(v),
103                    "destination" => b.destination = FromValueOpt::from_value(v),
104
105                    _ => {}
106                }
107            }
108            b.take_out()
109        }
110    }
111};