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::{make_place, Deserialize, Result};
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
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self {
74                network_status: Deserialize::default(),
75                reference: Deserialize::default(),
76                revocation_reason: Deserialize::default(),
77                url: Deserialize::default(),
78            }
79        }
80
81        fn take_out(&mut self) -> Option<Self::Out> {
82            let (Some(network_status), Some(reference), Some(revocation_reason), Some(url)) = (
83                self.network_status,
84                self.reference.take(),
85                self.revocation_reason,
86                self.url.take(),
87            ) else {
88                return None;
89            };
90            Some(Self::Out { network_status, reference, revocation_reason, url })
91        }
92    }
93
94    impl<'a> Map for Builder<'a> {
95        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
96            self.builder.key(k)
97        }
98
99        fn finish(&mut self) -> Result<()> {
100            *self.out = self.builder.take_out();
101            Ok(())
102        }
103    }
104
105    impl ObjectDeser for MandateBacsDebit {
106        type Builder = MandateBacsDebitBuilder;
107    }
108
109    impl FromValueOpt for MandateBacsDebit {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = MandateBacsDebitBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "network_status" => b.network_status = FromValueOpt::from_value(v),
118                    "reference" => b.reference = FromValueOpt::from_value(v),
119                    "revocation_reason" => b.revocation_reason = FromValueOpt::from_value(v),
120                    "url" => b.url = FromValueOpt::from_value(v),
121
122                    _ => {}
123                }
124            }
125            b.take_out()
126        }
127    }
128};
129/// The status of the mandate on the Bacs network.
130/// Can be one of `pending`, `revoked`, `refused`, or `accepted`.
131#[derive(Copy, Clone, Eq, PartialEq)]
132pub enum MandateBacsDebitNetworkStatus {
133    Accepted,
134    Pending,
135    Refused,
136    Revoked,
137}
138impl MandateBacsDebitNetworkStatus {
139    pub fn as_str(self) -> &'static str {
140        use MandateBacsDebitNetworkStatus::*;
141        match self {
142            Accepted => "accepted",
143            Pending => "pending",
144            Refused => "refused",
145            Revoked => "revoked",
146        }
147    }
148}
149
150impl std::str::FromStr for MandateBacsDebitNetworkStatus {
151    type Err = stripe_types::StripeParseError;
152    fn from_str(s: &str) -> Result<Self, Self::Err> {
153        use MandateBacsDebitNetworkStatus::*;
154        match s {
155            "accepted" => Ok(Accepted),
156            "pending" => Ok(Pending),
157            "refused" => Ok(Refused),
158            "revoked" => Ok(Revoked),
159            _ => Err(stripe_types::StripeParseError),
160        }
161    }
162}
163impl std::fmt::Display for MandateBacsDebitNetworkStatus {
164    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
165        f.write_str(self.as_str())
166    }
167}
168
169impl std::fmt::Debug for MandateBacsDebitNetworkStatus {
170    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171        f.write_str(self.as_str())
172    }
173}
174#[cfg(feature = "serialize")]
175impl serde::Serialize for MandateBacsDebitNetworkStatus {
176    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
177    where
178        S: serde::Serializer,
179    {
180        serializer.serialize_str(self.as_str())
181    }
182}
183impl miniserde::Deserialize for MandateBacsDebitNetworkStatus {
184    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
185        crate::Place::new(out)
186    }
187}
188
189impl miniserde::de::Visitor for crate::Place<MandateBacsDebitNetworkStatus> {
190    fn string(&mut self, s: &str) -> miniserde::Result<()> {
191        use std::str::FromStr;
192        self.out = Some(MandateBacsDebitNetworkStatus::from_str(s).map_err(|_| miniserde::Error)?);
193        Ok(())
194    }
195}
196
197stripe_types::impl_from_val_with_from_str!(MandateBacsDebitNetworkStatus);
198#[cfg(feature = "deserialize")]
199impl<'de> serde::Deserialize<'de> for MandateBacsDebitNetworkStatus {
200    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
201        use std::str::FromStr;
202        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
203        Self::from_str(&s).map_err(|_| {
204            serde::de::Error::custom("Unknown value for MandateBacsDebitNetworkStatus")
205        })
206    }
207}
208/// When the mandate is revoked on the Bacs network this field displays the reason for the revocation.
209#[derive(Copy, Clone, Eq, PartialEq)]
210pub enum MandateBacsDebitRevocationReason {
211    AccountClosed,
212    BankAccountRestricted,
213    BankOwnershipChanged,
214    CouldNotProcess,
215    DebitNotAuthorized,
216}
217impl MandateBacsDebitRevocationReason {
218    pub fn as_str(self) -> &'static str {
219        use MandateBacsDebitRevocationReason::*;
220        match self {
221            AccountClosed => "account_closed",
222            BankAccountRestricted => "bank_account_restricted",
223            BankOwnershipChanged => "bank_ownership_changed",
224            CouldNotProcess => "could_not_process",
225            DebitNotAuthorized => "debit_not_authorized",
226        }
227    }
228}
229
230impl std::str::FromStr for MandateBacsDebitRevocationReason {
231    type Err = stripe_types::StripeParseError;
232    fn from_str(s: &str) -> Result<Self, Self::Err> {
233        use MandateBacsDebitRevocationReason::*;
234        match s {
235            "account_closed" => Ok(AccountClosed),
236            "bank_account_restricted" => Ok(BankAccountRestricted),
237            "bank_ownership_changed" => Ok(BankOwnershipChanged),
238            "could_not_process" => Ok(CouldNotProcess),
239            "debit_not_authorized" => Ok(DebitNotAuthorized),
240            _ => Err(stripe_types::StripeParseError),
241        }
242    }
243}
244impl std::fmt::Display for MandateBacsDebitRevocationReason {
245    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
246        f.write_str(self.as_str())
247    }
248}
249
250impl std::fmt::Debug for MandateBacsDebitRevocationReason {
251    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
252        f.write_str(self.as_str())
253    }
254}
255#[cfg(feature = "serialize")]
256impl serde::Serialize for MandateBacsDebitRevocationReason {
257    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
258    where
259        S: serde::Serializer,
260    {
261        serializer.serialize_str(self.as_str())
262    }
263}
264impl miniserde::Deserialize for MandateBacsDebitRevocationReason {
265    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
266        crate::Place::new(out)
267    }
268}
269
270impl miniserde::de::Visitor for crate::Place<MandateBacsDebitRevocationReason> {
271    fn string(&mut self, s: &str) -> miniserde::Result<()> {
272        use std::str::FromStr;
273        self.out =
274            Some(MandateBacsDebitRevocationReason::from_str(s).map_err(|_| miniserde::Error)?);
275        Ok(())
276    }
277}
278
279stripe_types::impl_from_val_with_from_str!(MandateBacsDebitRevocationReason);
280#[cfg(feature = "deserialize")]
281impl<'de> serde::Deserialize<'de> for MandateBacsDebitRevocationReason {
282    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
283        use std::str::FromStr;
284        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
285        Self::from_str(&s).map_err(|_| {
286            serde::de::Error::custom("Unknown value for MandateBacsDebitRevocationReason")
287        })
288    }
289}