stripe_shared/
mandate_bacs_debit.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct MandateBacsDebit {
5    /// The status of the mandate on the Bacs network.
6    /// Can be one of `pending`, `revoked`, `refused`, or `accepted`.
7    pub network_status: MandateBacsDebitNetworkStatus,
8    /// The unique reference identifying the mandate on the Bacs network.
9    pub reference: String,
10    /// When the mandate is revoked on the Bacs network this field displays the reason for the revocation.
11    pub revocation_reason: Option<MandateBacsDebitRevocationReason>,
12    /// The URL that will contain the mandate that the customer has signed.
13    pub url: String,
14}
15#[doc(hidden)]
16pub struct MandateBacsDebitBuilder {
17    network_status: Option<MandateBacsDebitNetworkStatus>,
18    reference: Option<String>,
19    revocation_reason: Option<Option<MandateBacsDebitRevocationReason>>,
20    url: Option<String>,
21}
22
23#[allow(
24    unused_variables,
25    irrefutable_let_patterns,
26    clippy::let_unit_value,
27    clippy::match_single_binding,
28    clippy::single_match
29)]
30const _: () = {
31    use miniserde::de::{Map, Visitor};
32    use miniserde::json::Value;
33    use miniserde::{Deserialize, Result, make_place};
34    use stripe_types::miniserde_helpers::FromValueOpt;
35    use stripe_types::{MapBuilder, ObjectDeser};
36
37    make_place!(Place);
38
39    impl Deserialize for MandateBacsDebit {
40        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
41            Place::new(out)
42        }
43    }
44
45    struct Builder<'a> {
46        out: &'a mut Option<MandateBacsDebit>,
47        builder: MandateBacsDebitBuilder,
48    }
49
50    impl Visitor for Place<MandateBacsDebit> {
51        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
52            Ok(Box::new(Builder {
53                out: &mut self.out,
54                builder: MandateBacsDebitBuilder::deser_default(),
55            }))
56        }
57    }
58
59    impl MapBuilder for MandateBacsDebitBuilder {
60        type Out = MandateBacsDebit;
61        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
62            Ok(match k {
63                "network_status" => Deserialize::begin(&mut self.network_status),
64                "reference" => Deserialize::begin(&mut self.reference),
65                "revocation_reason" => Deserialize::begin(&mut self.revocation_reason),
66                "url" => Deserialize::begin(&mut self.url),
67                _ => <dyn Visitor>::ignore(),
68            })
69        }
70
71        fn deser_default() -> Self {
72            Self {
73                network_status: Deserialize::default(),
74                reference: Deserialize::default(),
75                revocation_reason: Deserialize::default(),
76                url: Deserialize::default(),
77            }
78        }
79
80        fn take_out(&mut self) -> Option<Self::Out> {
81            let (Some(network_status), Some(reference), Some(revocation_reason), Some(url)) = (
82                self.network_status.take(),
83                self.reference.take(),
84                self.revocation_reason.take(),
85                self.url.take(),
86            ) else {
87                return None;
88            };
89            Some(Self::Out { network_status, reference, revocation_reason, url })
90        }
91    }
92
93    impl Map for Builder<'_> {
94        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
95            self.builder.key(k)
96        }
97
98        fn finish(&mut self) -> Result<()> {
99            *self.out = self.builder.take_out();
100            Ok(())
101        }
102    }
103
104    impl ObjectDeser for MandateBacsDebit {
105        type Builder = MandateBacsDebitBuilder;
106    }
107
108    impl FromValueOpt for MandateBacsDebit {
109        fn from_value(v: Value) -> Option<Self> {
110            let Value::Object(obj) = v else {
111                return None;
112            };
113            let mut b = MandateBacsDebitBuilder::deser_default();
114            for (k, v) in obj {
115                match k.as_str() {
116                    "network_status" => b.network_status = FromValueOpt::from_value(v),
117                    "reference" => b.reference = FromValueOpt::from_value(v),
118                    "revocation_reason" => b.revocation_reason = FromValueOpt::from_value(v),
119                    "url" => b.url = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};
127/// The status of the mandate on the Bacs network.
128/// Can be one of `pending`, `revoked`, `refused`, or `accepted`.
129#[derive(Clone, Eq, PartialEq)]
130#[non_exhaustive]
131pub enum MandateBacsDebitNetworkStatus {
132    Accepted,
133    Pending,
134    Refused,
135    Revoked,
136    /// An unrecognized value from Stripe. Should not be used as a request parameter.
137    Unknown(String),
138}
139impl MandateBacsDebitNetworkStatus {
140    pub fn as_str(&self) -> &str {
141        use MandateBacsDebitNetworkStatus::*;
142        match self {
143            Accepted => "accepted",
144            Pending => "pending",
145            Refused => "refused",
146            Revoked => "revoked",
147            Unknown(v) => v,
148        }
149    }
150}
151
152impl std::str::FromStr for MandateBacsDebitNetworkStatus {
153    type Err = std::convert::Infallible;
154    fn from_str(s: &str) -> Result<Self, Self::Err> {
155        use MandateBacsDebitNetworkStatus::*;
156        match s {
157            "accepted" => Ok(Accepted),
158            "pending" => Ok(Pending),
159            "refused" => Ok(Refused),
160            "revoked" => Ok(Revoked),
161            v => {
162                tracing::warn!(
163                    "Unknown value '{}' for enum '{}'",
164                    v,
165                    "MandateBacsDebitNetworkStatus"
166                );
167                Ok(Unknown(v.to_owned()))
168            }
169        }
170    }
171}
172impl std::fmt::Display for MandateBacsDebitNetworkStatus {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177
178impl std::fmt::Debug for MandateBacsDebitNetworkStatus {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183#[cfg(feature = "serialize")]
184impl serde::Serialize for MandateBacsDebitNetworkStatus {
185    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
186    where
187        S: serde::Serializer,
188    {
189        serializer.serialize_str(self.as_str())
190    }
191}
192impl miniserde::Deserialize for MandateBacsDebitNetworkStatus {
193    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
194        crate::Place::new(out)
195    }
196}
197
198impl miniserde::de::Visitor for crate::Place<MandateBacsDebitNetworkStatus> {
199    fn string(&mut self, s: &str) -> miniserde::Result<()> {
200        use std::str::FromStr;
201        self.out = Some(MandateBacsDebitNetworkStatus::from_str(s).expect("infallible"));
202        Ok(())
203    }
204}
205
206stripe_types::impl_from_val_with_from_str!(MandateBacsDebitNetworkStatus);
207#[cfg(feature = "deserialize")]
208impl<'de> serde::Deserialize<'de> for MandateBacsDebitNetworkStatus {
209    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
210        use std::str::FromStr;
211        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
212        Ok(Self::from_str(&s).expect("infallible"))
213    }
214}
215/// When the mandate is revoked on the Bacs network this field displays the reason for the revocation.
216#[derive(Clone, Eq, PartialEq)]
217#[non_exhaustive]
218pub enum MandateBacsDebitRevocationReason {
219    AccountClosed,
220    BankAccountRestricted,
221    BankOwnershipChanged,
222    CouldNotProcess,
223    DebitNotAuthorized,
224    /// An unrecognized value from Stripe. Should not be used as a request parameter.
225    Unknown(String),
226}
227impl MandateBacsDebitRevocationReason {
228    pub fn as_str(&self) -> &str {
229        use MandateBacsDebitRevocationReason::*;
230        match self {
231            AccountClosed => "account_closed",
232            BankAccountRestricted => "bank_account_restricted",
233            BankOwnershipChanged => "bank_ownership_changed",
234            CouldNotProcess => "could_not_process",
235            DebitNotAuthorized => "debit_not_authorized",
236            Unknown(v) => v,
237        }
238    }
239}
240
241impl std::str::FromStr for MandateBacsDebitRevocationReason {
242    type Err = std::convert::Infallible;
243    fn from_str(s: &str) -> Result<Self, Self::Err> {
244        use MandateBacsDebitRevocationReason::*;
245        match s {
246            "account_closed" => Ok(AccountClosed),
247            "bank_account_restricted" => Ok(BankAccountRestricted),
248            "bank_ownership_changed" => Ok(BankOwnershipChanged),
249            "could_not_process" => Ok(CouldNotProcess),
250            "debit_not_authorized" => Ok(DebitNotAuthorized),
251            v => {
252                tracing::warn!(
253                    "Unknown value '{}' for enum '{}'",
254                    v,
255                    "MandateBacsDebitRevocationReason"
256                );
257                Ok(Unknown(v.to_owned()))
258            }
259        }
260    }
261}
262impl std::fmt::Display for MandateBacsDebitRevocationReason {
263    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
264        f.write_str(self.as_str())
265    }
266}
267
268impl std::fmt::Debug for MandateBacsDebitRevocationReason {
269    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
270        f.write_str(self.as_str())
271    }
272}
273#[cfg(feature = "serialize")]
274impl serde::Serialize for MandateBacsDebitRevocationReason {
275    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
276    where
277        S: serde::Serializer,
278    {
279        serializer.serialize_str(self.as_str())
280    }
281}
282impl miniserde::Deserialize for MandateBacsDebitRevocationReason {
283    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
284        crate::Place::new(out)
285    }
286}
287
288impl miniserde::de::Visitor for crate::Place<MandateBacsDebitRevocationReason> {
289    fn string(&mut self, s: &str) -> miniserde::Result<()> {
290        use std::str::FromStr;
291        self.out = Some(MandateBacsDebitRevocationReason::from_str(s).expect("infallible"));
292        Ok(())
293    }
294}
295
296stripe_types::impl_from_val_with_from_str!(MandateBacsDebitRevocationReason);
297#[cfg(feature = "deserialize")]
298impl<'de> serde::Deserialize<'de> for MandateBacsDebitRevocationReason {
299    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
300        use std::str::FromStr;
301        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
302        Ok(Self::from_str(&s).expect("infallible"))
303    }
304}