stripe_shared/
payment_method_details_crypto.rs

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