Skip to main content

stripe_shared/
source_receiver_flow.rs

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