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,
83                self.reference.take(),
84                self.revocation_reason,
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(Copy, Clone, Eq, PartialEq)]
130pub enum MandateBacsDebitNetworkStatus {
131    Accepted,
132    Pending,
133    Refused,
134    Revoked,
135}
136impl MandateBacsDebitNetworkStatus {
137    pub fn as_str(self) -> &'static str {
138        use MandateBacsDebitNetworkStatus::*;
139        match self {
140            Accepted => "accepted",
141            Pending => "pending",
142            Refused => "refused",
143            Revoked => "revoked",
144        }
145    }
146}
147
148impl std::str::FromStr for MandateBacsDebitNetworkStatus {
149    type Err = stripe_types::StripeParseError;
150    fn from_str(s: &str) -> Result<Self, Self::Err> {
151        use MandateBacsDebitNetworkStatus::*;
152        match s {
153            "accepted" => Ok(Accepted),
154            "pending" => Ok(Pending),
155            "refused" => Ok(Refused),
156            "revoked" => Ok(Revoked),
157            _ => Err(stripe_types::StripeParseError),
158        }
159    }
160}
161impl std::fmt::Display for MandateBacsDebitNetworkStatus {
162    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
163        f.write_str(self.as_str())
164    }
165}
166
167impl std::fmt::Debug for MandateBacsDebitNetworkStatus {
168    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169        f.write_str(self.as_str())
170    }
171}
172#[cfg(feature = "serialize")]
173impl serde::Serialize for MandateBacsDebitNetworkStatus {
174    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
175    where
176        S: serde::Serializer,
177    {
178        serializer.serialize_str(self.as_str())
179    }
180}
181impl miniserde::Deserialize for MandateBacsDebitNetworkStatus {
182    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
183        crate::Place::new(out)
184    }
185}
186
187impl miniserde::de::Visitor for crate::Place<MandateBacsDebitNetworkStatus> {
188    fn string(&mut self, s: &str) -> miniserde::Result<()> {
189        use std::str::FromStr;
190        self.out = Some(MandateBacsDebitNetworkStatus::from_str(s).map_err(|_| miniserde::Error)?);
191        Ok(())
192    }
193}
194
195stripe_types::impl_from_val_with_from_str!(MandateBacsDebitNetworkStatus);
196#[cfg(feature = "deserialize")]
197impl<'de> serde::Deserialize<'de> for MandateBacsDebitNetworkStatus {
198    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
199        use std::str::FromStr;
200        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
201        Self::from_str(&s).map_err(|_| {
202            serde::de::Error::custom("Unknown value for MandateBacsDebitNetworkStatus")
203        })
204    }
205}
206/// When the mandate is revoked on the Bacs network this field displays the reason for the revocation.
207#[derive(Copy, Clone, Eq, PartialEq)]
208pub enum MandateBacsDebitRevocationReason {
209    AccountClosed,
210    BankAccountRestricted,
211    BankOwnershipChanged,
212    CouldNotProcess,
213    DebitNotAuthorized,
214}
215impl MandateBacsDebitRevocationReason {
216    pub fn as_str(self) -> &'static str {
217        use MandateBacsDebitRevocationReason::*;
218        match self {
219            AccountClosed => "account_closed",
220            BankAccountRestricted => "bank_account_restricted",
221            BankOwnershipChanged => "bank_ownership_changed",
222            CouldNotProcess => "could_not_process",
223            DebitNotAuthorized => "debit_not_authorized",
224        }
225    }
226}
227
228impl std::str::FromStr for MandateBacsDebitRevocationReason {
229    type Err = stripe_types::StripeParseError;
230    fn from_str(s: &str) -> Result<Self, Self::Err> {
231        use MandateBacsDebitRevocationReason::*;
232        match s {
233            "account_closed" => Ok(AccountClosed),
234            "bank_account_restricted" => Ok(BankAccountRestricted),
235            "bank_ownership_changed" => Ok(BankOwnershipChanged),
236            "could_not_process" => Ok(CouldNotProcess),
237            "debit_not_authorized" => Ok(DebitNotAuthorized),
238            _ => Err(stripe_types::StripeParseError),
239        }
240    }
241}
242impl std::fmt::Display for MandateBacsDebitRevocationReason {
243    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
244        f.write_str(self.as_str())
245    }
246}
247
248impl std::fmt::Debug for MandateBacsDebitRevocationReason {
249    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250        f.write_str(self.as_str())
251    }
252}
253#[cfg(feature = "serialize")]
254impl serde::Serialize for MandateBacsDebitRevocationReason {
255    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
256    where
257        S: serde::Serializer,
258    {
259        serializer.serialize_str(self.as_str())
260    }
261}
262impl miniserde::Deserialize for MandateBacsDebitRevocationReason {
263    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
264        crate::Place::new(out)
265    }
266}
267
268impl miniserde::de::Visitor for crate::Place<MandateBacsDebitRevocationReason> {
269    fn string(&mut self, s: &str) -> miniserde::Result<()> {
270        use std::str::FromStr;
271        self.out =
272            Some(MandateBacsDebitRevocationReason::from_str(s).map_err(|_| miniserde::Error)?);
273        Ok(())
274    }
275}
276
277stripe_types::impl_from_val_with_from_str!(MandateBacsDebitRevocationReason);
278#[cfg(feature = "deserialize")]
279impl<'de> serde::Deserialize<'de> for MandateBacsDebitRevocationReason {
280    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
281        use std::str::FromStr;
282        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
283        Self::from_str(&s).map_err(|_| {
284            serde::de::Error::custom("Unknown value for MandateBacsDebitRevocationReason")
285        })
286    }
287}