stripe_shared/
payment_intent_next_action_verify_with_microdeposits.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentIntentNextActionVerifyWithMicrodeposits {
5    /// The timestamp when the microdeposits are expected to land.
6    pub arrival_date: stripe_types::Timestamp,
7    /// The URL for the hosted verification page, which allows customers to verify their bank account.
8    pub hosted_verification_url: String,
9    /// The type of the microdeposit sent to the customer.
10    /// Used to distinguish between different verification methods.
11    pub microdeposit_type: Option<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>,
12}
13#[doc(hidden)]
14pub struct PaymentIntentNextActionVerifyWithMicrodepositsBuilder {
15    arrival_date: Option<stripe_types::Timestamp>,
16    hosted_verification_url: Option<String>,
17    microdeposit_type:
18        Option<Option<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>>,
19}
20
21#[allow(
22    unused_variables,
23    irrefutable_let_patterns,
24    clippy::let_unit_value,
25    clippy::match_single_binding,
26    clippy::single_match
27)]
28const _: () = {
29    use miniserde::de::{Map, Visitor};
30    use miniserde::json::Value;
31    use miniserde::{Deserialize, Result, make_place};
32    use stripe_types::miniserde_helpers::FromValueOpt;
33    use stripe_types::{MapBuilder, ObjectDeser};
34
35    make_place!(Place);
36
37    impl Deserialize for PaymentIntentNextActionVerifyWithMicrodeposits {
38        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
39            Place::new(out)
40        }
41    }
42
43    struct Builder<'a> {
44        out: &'a mut Option<PaymentIntentNextActionVerifyWithMicrodeposits>,
45        builder: PaymentIntentNextActionVerifyWithMicrodepositsBuilder,
46    }
47
48    impl Visitor for Place<PaymentIntentNextActionVerifyWithMicrodeposits> {
49        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
50            Ok(Box::new(Builder {
51                out: &mut self.out,
52                builder: PaymentIntentNextActionVerifyWithMicrodepositsBuilder::deser_default(),
53            }))
54        }
55    }
56
57    impl MapBuilder for PaymentIntentNextActionVerifyWithMicrodepositsBuilder {
58        type Out = PaymentIntentNextActionVerifyWithMicrodeposits;
59        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
60            Ok(match k {
61                "arrival_date" => Deserialize::begin(&mut self.arrival_date),
62                "hosted_verification_url" => Deserialize::begin(&mut self.hosted_verification_url),
63                "microdeposit_type" => Deserialize::begin(&mut self.microdeposit_type),
64                _ => <dyn Visitor>::ignore(),
65            })
66        }
67
68        fn deser_default() -> Self {
69            Self {
70                arrival_date: Deserialize::default(),
71                hosted_verification_url: Deserialize::default(),
72                microdeposit_type: Deserialize::default(),
73            }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(arrival_date), Some(hosted_verification_url), Some(microdeposit_type)) = (
78                self.arrival_date,
79                self.hosted_verification_url.take(),
80                self.microdeposit_type.take(),
81            ) else {
82                return None;
83            };
84            Some(Self::Out { arrival_date, hosted_verification_url, microdeposit_type })
85        }
86    }
87
88    impl Map for Builder<'_> {
89        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
90            self.builder.key(k)
91        }
92
93        fn finish(&mut self) -> Result<()> {
94            *self.out = self.builder.take_out();
95            Ok(())
96        }
97    }
98
99    impl ObjectDeser for PaymentIntentNextActionVerifyWithMicrodeposits {
100        type Builder = PaymentIntentNextActionVerifyWithMicrodepositsBuilder;
101    }
102
103    impl FromValueOpt for PaymentIntentNextActionVerifyWithMicrodeposits {
104        fn from_value(v: Value) -> Option<Self> {
105            let Value::Object(obj) = v else {
106                return None;
107            };
108            let mut b = PaymentIntentNextActionVerifyWithMicrodepositsBuilder::deser_default();
109            for (k, v) in obj {
110                match k.as_str() {
111                    "arrival_date" => b.arrival_date = FromValueOpt::from_value(v),
112                    "hosted_verification_url" => {
113                        b.hosted_verification_url = FromValueOpt::from_value(v)
114                    }
115                    "microdeposit_type" => b.microdeposit_type = FromValueOpt::from_value(v),
116                    _ => {}
117                }
118            }
119            b.take_out()
120        }
121    }
122};
123/// The type of the microdeposit sent to the customer.
124/// Used to distinguish between different verification methods.
125#[derive(Clone, Eq, PartialEq)]
126#[non_exhaustive]
127pub enum PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
128    Amounts,
129    DescriptorCode,
130    /// An unrecognized value from Stripe. Should not be used as a request parameter.
131    Unknown(String),
132}
133impl PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
134    pub fn as_str(&self) -> &str {
135        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
136        match self {
137            Amounts => "amounts",
138            DescriptorCode => "descriptor_code",
139            Unknown(v) => v,
140        }
141    }
142}
143
144impl std::str::FromStr for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
145    type Err = std::convert::Infallible;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::*;
148        match s {
149            "amounts" => Ok(Amounts),
150            "descriptor_code" => Ok(DescriptorCode),
151            v => {
152                tracing::warn!(
153                    "Unknown value '{}' for enum '{}'",
154                    v,
155                    "PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType"
156                );
157                Ok(Unknown(v.to_owned()))
158            }
159        }
160    }
161}
162impl std::fmt::Display for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167
168impl std::fmt::Debug for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173#[cfg(feature = "serialize")]
174impl serde::Serialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
175    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
176    where
177        S: serde::Serializer,
178    {
179        serializer.serialize_str(self.as_str())
180    }
181}
182impl miniserde::Deserialize for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType {
183    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
184        crate::Place::new(out)
185    }
186}
187
188impl miniserde::de::Visitor
189    for crate::Place<PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType>
190{
191    fn string(&mut self, s: &str) -> miniserde::Result<()> {
192        use std::str::FromStr;
193        self.out = Some(
194            PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType::from_str(s)
195                .expect("infallible"),
196        );
197        Ok(())
198    }
199}
200
201stripe_types::impl_from_val_with_from_str!(
202    PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
203);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de>
206    for PaymentIntentNextActionVerifyWithMicrodepositsMicrodepositType
207{
208    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
209        use std::str::FromStr;
210        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
211        Ok(Self::from_str(&s).expect("infallible"))
212    }
213}