Skip to main content

stripe_shared/
payment_method_options_wechat_pay.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 PaymentMethodOptionsWechatPay {
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<PaymentMethodOptionsWechatPayClient>,
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<PaymentMethodOptionsWechatPaySetupFutureUsage>,
19}
20#[cfg(feature = "redact-generated-debug")]
21impl std::fmt::Debug for PaymentMethodOptionsWechatPay {
22    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
23        f.debug_struct("PaymentMethodOptionsWechatPay").finish_non_exhaustive()
24    }
25}
26#[doc(hidden)]
27pub struct PaymentMethodOptionsWechatPayBuilder {
28    app_id: Option<Option<String>>,
29    client: Option<Option<PaymentMethodOptionsWechatPayClient>>,
30    setup_future_usage: Option<Option<PaymentMethodOptionsWechatPaySetupFutureUsage>>,
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 PaymentMethodOptionsWechatPay {
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<PaymentMethodOptionsWechatPay>,
57        builder: PaymentMethodOptionsWechatPayBuilder,
58    }
59
60    impl Visitor for Place<PaymentMethodOptionsWechatPay> {
61        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
62            Ok(Box::new(Builder {
63                out: &mut self.out,
64                builder: PaymentMethodOptionsWechatPayBuilder::deser_default(),
65            }))
66        }
67    }
68
69    impl MapBuilder for PaymentMethodOptionsWechatPayBuilder {
70        type Out = PaymentMethodOptionsWechatPay;
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 PaymentMethodOptionsWechatPay {
106        type Builder = PaymentMethodOptionsWechatPayBuilder;
107    }
108
109    impl FromValueOpt for PaymentMethodOptionsWechatPay {
110        fn from_value(v: Value) -> Option<Self> {
111            let Value::Object(obj) = v else {
112                return None;
113            };
114            let mut b = PaymentMethodOptionsWechatPayBuilder::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 PaymentMethodOptionsWechatPayClient {
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 PaymentMethodOptionsWechatPayClient {
138    pub fn as_str(&self) -> &str {
139        use PaymentMethodOptionsWechatPayClient::*;
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 PaymentMethodOptionsWechatPayClient {
150    type Err = std::convert::Infallible;
151    fn from_str(s: &str) -> Result<Self, Self::Err> {
152        use PaymentMethodOptionsWechatPayClient::*;
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                    "PaymentMethodOptionsWechatPayClient"
162                );
163                Ok(Unknown(v.to_owned()))
164            }
165        }
166    }
167}
168impl std::fmt::Display for PaymentMethodOptionsWechatPayClient {
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 PaymentMethodOptionsWechatPayClient {
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 PaymentMethodOptionsWechatPayClient {
182    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
183        f.debug_struct(stringify!(PaymentMethodOptionsWechatPayClient)).finish_non_exhaustive()
184    }
185}
186#[cfg(feature = "serialize")]
187impl serde::Serialize for PaymentMethodOptionsWechatPayClient {
188    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
189    where
190        S: serde::Serializer,
191    {
192        serializer.serialize_str(self.as_str())
193    }
194}
195impl miniserde::Deserialize for PaymentMethodOptionsWechatPayClient {
196    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
197        crate::Place::new(out)
198    }
199}
200
201impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPayClient> {
202    fn string(&mut self, s: &str) -> miniserde::Result<()> {
203        use std::str::FromStr;
204        self.out = Some(PaymentMethodOptionsWechatPayClient::from_str(s).expect("infallible"));
205        Ok(())
206    }
207}
208
209stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPayClient);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPayClient {
212    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213        use std::str::FromStr;
214        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215        Ok(Self::from_str(&s).expect("infallible"))
216    }
217}
218/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
219///
220/// 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.
221/// 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.
222///
223/// 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.
224///
225/// 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).
226#[derive(Clone, Eq, PartialEq)]
227#[non_exhaustive]
228pub enum PaymentMethodOptionsWechatPaySetupFutureUsage {
229    None,
230    /// An unrecognized value from Stripe. Should not be used as a request parameter.
231    Unknown(String),
232}
233impl PaymentMethodOptionsWechatPaySetupFutureUsage {
234    pub fn as_str(&self) -> &str {
235        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
236        match self {
237            None => "none",
238            Unknown(v) => v,
239        }
240    }
241}
242
243impl std::str::FromStr for PaymentMethodOptionsWechatPaySetupFutureUsage {
244    type Err = std::convert::Infallible;
245    fn from_str(s: &str) -> Result<Self, Self::Err> {
246        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
247        match s {
248            "none" => Ok(None),
249            v => {
250                tracing::warn!(
251                    "Unknown value '{}' for enum '{}'",
252                    v,
253                    "PaymentMethodOptionsWechatPaySetupFutureUsage"
254                );
255                Ok(Unknown(v.to_owned()))
256            }
257        }
258    }
259}
260impl std::fmt::Display for PaymentMethodOptionsWechatPaySetupFutureUsage {
261    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
262        f.write_str(self.as_str())
263    }
264}
265
266#[cfg(not(feature = "redact-generated-debug"))]
267impl std::fmt::Debug for PaymentMethodOptionsWechatPaySetupFutureUsage {
268    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
269        f.write_str(self.as_str())
270    }
271}
272#[cfg(feature = "redact-generated-debug")]
273impl std::fmt::Debug for PaymentMethodOptionsWechatPaySetupFutureUsage {
274    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275        f.debug_struct(stringify!(PaymentMethodOptionsWechatPaySetupFutureUsage))
276            .finish_non_exhaustive()
277    }
278}
279#[cfg(feature = "serialize")]
280impl serde::Serialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
281    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
282    where
283        S: serde::Serializer,
284    {
285        serializer.serialize_str(self.as_str())
286    }
287}
288impl miniserde::Deserialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
289    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
290        crate::Place::new(out)
291    }
292}
293
294impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPaySetupFutureUsage> {
295    fn string(&mut self, s: &str) -> miniserde::Result<()> {
296        use std::str::FromStr;
297        self.out =
298            Some(PaymentMethodOptionsWechatPaySetupFutureUsage::from_str(s).expect("infallible"));
299        Ok(())
300    }
301}
302
303stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPaySetupFutureUsage);
304#[cfg(feature = "deserialize")]
305impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPaySetupFutureUsage {
306    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
307        use std::str::FromStr;
308        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
309        Ok(Self::from_str(&s).expect("infallible"))
310    }
311}