stripe_shared/
source_receiver_flow.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct SourceReceiverFlow {
5    /// The address of the receiver source.
6    /// This is the value that should be communicated to the customer to send their funds to.
7    pub address: Option<String>,
8    /// The total amount that was moved to your balance.
9    /// This is almost always equal to the amount charged.
10    /// In rare cases when customers deposit excess funds and we are unable to refund those, those funds get moved to your balance and show up in amount_charged as well.
11    /// The amount charged is expressed in the source's currency.
12    pub amount_charged: i64,
13    /// The total amount received by the receiver source.
14    /// `amount_received = amount_returned + amount_charged` should be true for consumed sources unless customers deposit excess funds.
15    /// The amount received is expressed in the source's currency.
16    pub amount_received: i64,
17    /// The total amount that was returned to the customer.
18    /// The amount returned is expressed in the source's currency.
19    pub amount_returned: i64,
20    /// Type of refund attribute method, one of `email`, `manual`, or `none`.
21    pub refund_attributes_method: String,
22    /// Type of refund attribute status, one of `missing`, `requested`, or `available`.
23    pub refund_attributes_status: String,
24}
25#[doc(hidden)]
26pub struct SourceReceiverFlowBuilder {
27    address: Option<Option<String>>,
28    amount_charged: Option<i64>,
29    amount_received: Option<i64>,
30    amount_returned: Option<i64>,
31    refund_attributes_method: Option<String>,
32    refund_attributes_status: Option<String>,
33}
34
35#[allow(
36    unused_variables,
37    irrefutable_let_patterns,
38    clippy::let_unit_value,
39    clippy::match_single_binding,
40    clippy::single_match
41)]
42const _: () = {
43    use miniserde::de::{Map, Visitor};
44    use miniserde::json::Value;
45    use miniserde::{make_place, Deserialize, Result};
46    use stripe_types::miniserde_helpers::FromValueOpt;
47    use stripe_types::{MapBuilder, ObjectDeser};
48
49    make_place!(Place);
50
51    impl Deserialize for SourceReceiverFlow {
52        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
53            Place::new(out)
54        }
55    }
56
57    struct Builder<'a> {
58        out: &'a mut Option<SourceReceiverFlow>,
59        builder: SourceReceiverFlowBuilder,
60    }
61
62    impl Visitor for Place<SourceReceiverFlow> {
63        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
64            Ok(Box::new(Builder {
65                out: &mut self.out,
66                builder: SourceReceiverFlowBuilder::deser_default(),
67            }))
68        }
69    }
70
71    impl MapBuilder for SourceReceiverFlowBuilder {
72        type Out = SourceReceiverFlow;
73        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
74            Ok(match k {
75                "address" => Deserialize::begin(&mut self.address),
76                "amount_charged" => Deserialize::begin(&mut self.amount_charged),
77                "amount_received" => Deserialize::begin(&mut self.amount_received),
78                "amount_returned" => Deserialize::begin(&mut self.amount_returned),
79                "refund_attributes_method" => {
80                    Deserialize::begin(&mut self.refund_attributes_method)
81                }
82                "refund_attributes_status" => {
83                    Deserialize::begin(&mut self.refund_attributes_status)
84                }
85
86                _ => <dyn Visitor>::ignore(),
87            })
88        }
89
90        fn deser_default() -> Self {
91            Self {
92                address: Deserialize::default(),
93                amount_charged: Deserialize::default(),
94                amount_received: Deserialize::default(),
95                amount_returned: Deserialize::default(),
96                refund_attributes_method: Deserialize::default(),
97                refund_attributes_status: Deserialize::default(),
98            }
99        }
100
101        fn take_out(&mut self) -> Option<Self::Out> {
102            let (
103                Some(address),
104                Some(amount_charged),
105                Some(amount_received),
106                Some(amount_returned),
107                Some(refund_attributes_method),
108                Some(refund_attributes_status),
109            ) = (
110                self.address.take(),
111                self.amount_charged,
112                self.amount_received,
113                self.amount_returned,
114                self.refund_attributes_method.take(),
115                self.refund_attributes_status.take(),
116            )
117            else {
118                return None;
119            };
120            Some(Self::Out {
121                address,
122                amount_charged,
123                amount_received,
124                amount_returned,
125                refund_attributes_method,
126                refund_attributes_status,
127            })
128        }
129    }
130
131    impl<'a> Map for Builder<'a> {
132        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
133            self.builder.key(k)
134        }
135
136        fn finish(&mut self) -> Result<()> {
137            *self.out = self.builder.take_out();
138            Ok(())
139        }
140    }
141
142    impl ObjectDeser for SourceReceiverFlow {
143        type Builder = SourceReceiverFlowBuilder;
144    }
145
146    impl FromValueOpt for SourceReceiverFlow {
147        fn from_value(v: Value) -> Option<Self> {
148            let Value::Object(obj) = v else {
149                return None;
150            };
151            let mut b = SourceReceiverFlowBuilder::deser_default();
152            for (k, v) in obj {
153                match k.as_str() {
154                    "address" => b.address = FromValueOpt::from_value(v),
155                    "amount_charged" => b.amount_charged = FromValueOpt::from_value(v),
156                    "amount_received" => b.amount_received = FromValueOpt::from_value(v),
157                    "amount_returned" => b.amount_returned = FromValueOpt::from_value(v),
158                    "refund_attributes_method" => {
159                        b.refund_attributes_method = FromValueOpt::from_value(v)
160                    }
161                    "refund_attributes_status" => {
162                        b.refund_attributes_status = FromValueOpt::from_value(v)
163                    }
164
165                    _ => {}
166                }
167            }
168            b.take_out()
169        }
170    }
171};