stripe_shared/
payment_method_options_wechat_pay.rs

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