Skip to main content

stripe_shared/
checkout_wechat_pay_payment_method_options.rs

1#[derive(Clone, Eq, PartialEq)]
2#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
3#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
4#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
5pub struct CheckoutWechatPayPaymentMethodOptions {
6    /// The app ID registered with WeChat Pay. Only required when client is iOS or Android.
7    pub app_id: Option<String>,
8    /// The client type that the end customer will pay from
9    pub client: Option<CheckoutWechatPayPaymentMethodOptionsClient>,
10    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
11    ///
12    /// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
13    /// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
14    ///
15    /// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
16    ///
17    /// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
18    pub setup_future_usage: Option<CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage>,
19}
20#[cfg(feature = "redact-generated-debug")]
21impl std::fmt::Debug for CheckoutWechatPayPaymentMethodOptions {
22    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23        f.debug_struct("CheckoutWechatPayPaymentMethodOptions").finish_non_exhaustive()
24    }
25}
26#[doc(hidden)]
27pub struct CheckoutWechatPayPaymentMethodOptionsBuilder {
28    app_id: Option<Option<String>>,
29    client: Option<Option<CheckoutWechatPayPaymentMethodOptionsClient>>,
30    setup_future_usage: Option<Option<CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage>>,
31}
32
33#[allow(
34    unused_variables,
35    irrefutable_let_patterns,
36    clippy::let_unit_value,
37    clippy::match_single_binding,
38    clippy::single_match
39)]
40const _: () = {
41    use miniserde::de::{Map, Visitor};
42    use miniserde::json::Value;
43    use miniserde::{Deserialize, Result, make_place};
44    use stripe_types::miniserde_helpers::FromValueOpt;
45    use stripe_types::{MapBuilder, ObjectDeser};
46
47    make_place!(Place);
48
49    impl Deserialize for CheckoutWechatPayPaymentMethodOptions {
50        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
51            Place::new(out)
52        }
53    }
54
55    struct Builder<'a> {
56        out: &'a mut Option<CheckoutWechatPayPaymentMethodOptions>,
57        builder: CheckoutWechatPayPaymentMethodOptionsBuilder,
58    }
59
60    impl Visitor for Place<CheckoutWechatPayPaymentMethodOptions> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder: CheckoutWechatPayPaymentMethodOptionsBuilder::deser_default(),
65            }))
66        }
67    }
68
69    impl MapBuilder for CheckoutWechatPayPaymentMethodOptionsBuilder {
70        type Out = CheckoutWechatPayPaymentMethodOptions;
71        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
72            Ok(match k {
73                "app_id" => Deserialize::begin(&mut self.app_id),
74                "client" => Deserialize::begin(&mut self.client),
75                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
76                _ => <dyn Visitor>::ignore(),
77            })
78        }
79
80        fn deser_default() -> Self {
81            Self { app_id: Some(None), client: Some(None), setup_future_usage: Some(None) }
82        }
83
84        fn take_out(&mut self) -> Option<Self::Out> {
85            let (Some(app_id), Some(client), Some(setup_future_usage)) =
86                (self.app_id.take(), self.client.take(), self.setup_future_usage.take())
87            else {
88                return None;
89            };
90            Some(Self::Out { app_id, client, setup_future_usage })
91        }
92    }
93
94    impl Map for Builder<'_> {
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 CheckoutWechatPayPaymentMethodOptions {
106        type Builder = CheckoutWechatPayPaymentMethodOptionsBuilder;
107    }
108
109    impl FromValueOpt for CheckoutWechatPayPaymentMethodOptions {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = CheckoutWechatPayPaymentMethodOptionsBuilder::deser_default();
115            for (k, v) in obj {
116                match k.as_str() {
117                    "app_id" => b.app_id = FromValueOpt::from_value(v),
118                    "client" => b.client = FromValueOpt::from_value(v),
119                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
120                    _ => {}
121                }
122            }
123            b.take_out()
124        }
125    }
126};
127/// The client type that the end customer will pay from
128#[derive(Clone, Eq, PartialEq)]
129#[non_exhaustive]
130pub enum CheckoutWechatPayPaymentMethodOptionsClient {
131    Android,
132    Ios,
133    Web,
134    /// An unrecognized value from Stripe. Should not be used as a request parameter.
135    Unknown(String),
136}
137impl CheckoutWechatPayPaymentMethodOptionsClient {
138    pub fn as_str(&self) -> &str {
139        use CheckoutWechatPayPaymentMethodOptionsClient::*;
140        match self {
141            Android => "android",
142            Ios => "ios",
143            Web => "web",
144            Unknown(v) => v,
145        }
146    }
147}
148
149impl std::str::FromStr for CheckoutWechatPayPaymentMethodOptionsClient {
150    type Err = std::convert::Infallible;
151    fn from_str(s: &str) -> Result<Self, Self::Err> {
152        use CheckoutWechatPayPaymentMethodOptionsClient::*;
153        match s {
154            "android" => Ok(Android),
155            "ios" => Ok(Ios),
156            "web" => Ok(Web),
157            v => {
158                tracing::warn!(
159                    "Unknown value '{}' for enum '{}'",
160                    v,
161                    "CheckoutWechatPayPaymentMethodOptionsClient"
162                );
163                Ok(Unknown(v.to_owned()))
164            }
165        }
166    }
167}
168impl std::fmt::Display for CheckoutWechatPayPaymentMethodOptionsClient {
169    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
170        f.write_str(self.as_str())
171    }
172}
173
174#[cfg(not(feature = "redact-generated-debug"))]
175impl std::fmt::Debug for CheckoutWechatPayPaymentMethodOptionsClient {
176    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177        f.write_str(self.as_str())
178    }
179}
180#[cfg(feature = "redact-generated-debug")]
181impl std::fmt::Debug for CheckoutWechatPayPaymentMethodOptionsClient {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.debug_struct(stringify!(CheckoutWechatPayPaymentMethodOptionsClient))
184            .finish_non_exhaustive()
185    }
186}
187#[cfg(feature = "serialize")]
188impl serde::Serialize for CheckoutWechatPayPaymentMethodOptionsClient {
189    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
190    where
191        S: serde::Serializer,
192    {
193        serializer.serialize_str(self.as_str())
194    }
195}
196impl miniserde::Deserialize for CheckoutWechatPayPaymentMethodOptionsClient {
197    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
198        crate::Place::new(out)
199    }
200}
201
202impl miniserde::de::Visitor for crate::Place<CheckoutWechatPayPaymentMethodOptionsClient> {
203    fn string(&mut self, s: &str) -> miniserde::Result<()> {
204        use std::str::FromStr;
205        self.out =
206            Some(CheckoutWechatPayPaymentMethodOptionsClient::from_str(s).expect("infallible"));
207        Ok(())
208    }
209}
210
211stripe_types::impl_from_val_with_from_str!(CheckoutWechatPayPaymentMethodOptionsClient);
212#[cfg(feature = "deserialize")]
213impl<'de> serde::Deserialize<'de> for CheckoutWechatPayPaymentMethodOptionsClient {
214    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
215        use std::str::FromStr;
216        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
217        Ok(Self::from_str(&s).expect("infallible"))
218    }
219}
220/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
221///
222/// If you provide a Customer with the PaymentIntent, you can use this parameter to [attach the payment method](/payments/save-during-payment) to the Customer after the PaymentIntent is confirmed and the customer completes any required actions.
223/// If you don't provide a Customer, you can still [attach](/api/payment_methods/attach) the payment method to a Customer after the transaction completes.
224///
225/// If the payment method is `card_present` and isn't a digital wallet, Stripe creates and attaches a [generated_card](/api/charges/object#charge_object-payment_method_details-card_present-generated_card) payment method representing the card to the Customer instead.
226///
227/// When processing card payments, Stripe uses `setup_future_usage` to help you comply with regional legislation and network rules, such as [SCA](/strong-customer-authentication).
228#[derive(Clone, Eq, PartialEq)]
229#[non_exhaustive]
230pub enum CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
231    None,
232    /// An unrecognized value from Stripe. Should not be used as a request parameter.
233    Unknown(String),
234}
235impl CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
236    pub fn as_str(&self) -> &str {
237        use CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage::*;
238        match self {
239            None => "none",
240            Unknown(v) => v,
241        }
242    }
243}
244
245impl std::str::FromStr for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
246    type Err = std::convert::Infallible;
247    fn from_str(s: &str) -> Result<Self, Self::Err> {
248        use CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage::*;
249        match s {
250            "none" => Ok(None),
251            v => {
252                tracing::warn!(
253                    "Unknown value '{}' for enum '{}'",
254                    v,
255                    "CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage"
256                );
257                Ok(Unknown(v.to_owned()))
258            }
259        }
260    }
261}
262impl std::fmt::Display for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
263    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
264        f.write_str(self.as_str())
265    }
266}
267
268#[cfg(not(feature = "redact-generated-debug"))]
269impl std::fmt::Debug for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
270    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
271        f.write_str(self.as_str())
272    }
273}
274#[cfg(feature = "redact-generated-debug")]
275impl std::fmt::Debug for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
276    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
277        f.debug_struct(stringify!(CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage))
278            .finish_non_exhaustive()
279    }
280}
281#[cfg(feature = "serialize")]
282impl serde::Serialize for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
283    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
284    where
285        S: serde::Serializer,
286    {
287        serializer.serialize_str(self.as_str())
288    }
289}
290impl miniserde::Deserialize for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
291    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
292        crate::Place::new(out)
293    }
294}
295
296impl miniserde::de::Visitor
297    for crate::Place<CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage>
298{
299    fn string(&mut self, s: &str) -> miniserde::Result<()> {
300        use std::str::FromStr;
301        self.out = Some(
302            CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage::from_str(s).expect("infallible"),
303        );
304        Ok(())
305    }
306}
307
308stripe_types::impl_from_val_with_from_str!(CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage);
309#[cfg(feature = "deserialize")]
310impl<'de> serde::Deserialize<'de> for CheckoutWechatPayPaymentMethodOptionsSetupFutureUsage {
311    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
312        use std::str::FromStr;
313        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
314        Ok(Self::from_str(&s).expect("infallible"))
315    }
316}