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::{make_place, Deserialize, Result};
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
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                app_id: Deserialize::default(),
77                client: Deserialize::default(),
78                setup_future_usage: Deserialize::default(),
79            }
80        }
81
82        fn take_out(&mut self) -> Option<Self::Out> {
83            let (Some(app_id), Some(client), Some(setup_future_usage)) =
84                (self.app_id.take(), self.client, self.setup_future_usage)
85            else {
86                return None;
87            };
88            Some(Self::Out { app_id, client, setup_future_usage })
89        }
90    }
91
92    impl<'a> Map for Builder<'a> {
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 PaymentMethodOptionsWechatPay {
104        type Builder = PaymentMethodOptionsWechatPayBuilder;
105    }
106
107    impl FromValueOpt for PaymentMethodOptionsWechatPay {
108        fn from_value(v: Value) -> Option<Self> {
109            let Value::Object(obj) = v else {
110                return None;
111            };
112            let mut b = PaymentMethodOptionsWechatPayBuilder::deser_default();
113            for (k, v) in obj {
114                match k.as_str() {
115                    "app_id" => b.app_id = FromValueOpt::from_value(v),
116                    "client" => b.client = FromValueOpt::from_value(v),
117                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
118
119                    _ => {}
120                }
121            }
122            b.take_out()
123        }
124    }
125};
126/// The client type that the end customer will pay from
127#[derive(Copy, Clone, Eq, PartialEq)]
128pub enum PaymentMethodOptionsWechatPayClient {
129    Android,
130    Ios,
131    Web,
132}
133impl PaymentMethodOptionsWechatPayClient {
134    pub fn as_str(self) -> &'static str {
135        use PaymentMethodOptionsWechatPayClient::*;
136        match self {
137            Android => "android",
138            Ios => "ios",
139            Web => "web",
140        }
141    }
142}
143
144impl std::str::FromStr for PaymentMethodOptionsWechatPayClient {
145    type Err = stripe_types::StripeParseError;
146    fn from_str(s: &str) -> Result<Self, Self::Err> {
147        use PaymentMethodOptionsWechatPayClient::*;
148        match s {
149            "android" => Ok(Android),
150            "ios" => Ok(Ios),
151            "web" => Ok(Web),
152            _ => Err(stripe_types::StripeParseError),
153        }
154    }
155}
156impl std::fmt::Display for PaymentMethodOptionsWechatPayClient {
157    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
158        f.write_str(self.as_str())
159    }
160}
161
162impl std::fmt::Debug for PaymentMethodOptionsWechatPayClient {
163    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
164        f.write_str(self.as_str())
165    }
166}
167#[cfg(feature = "serialize")]
168impl serde::Serialize for PaymentMethodOptionsWechatPayClient {
169    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
170    where
171        S: serde::Serializer,
172    {
173        serializer.serialize_str(self.as_str())
174    }
175}
176impl miniserde::Deserialize for PaymentMethodOptionsWechatPayClient {
177    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
178        crate::Place::new(out)
179    }
180}
181
182impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPayClient> {
183    fn string(&mut self, s: &str) -> miniserde::Result<()> {
184        use std::str::FromStr;
185        self.out =
186            Some(PaymentMethodOptionsWechatPayClient::from_str(s).map_err(|_| miniserde::Error)?);
187        Ok(())
188    }
189}
190
191stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPayClient);
192#[cfg(feature = "deserialize")]
193impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPayClient {
194    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
195        use std::str::FromStr;
196        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
197        Self::from_str(&s).map_err(|_| {
198            serde::de::Error::custom("Unknown value for PaymentMethodOptionsWechatPayClient")
199        })
200    }
201}
202/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
203///
204/// 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.
205/// 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.
206///
207/// 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.
208///
209/// 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).
210#[derive(Copy, Clone, Eq, PartialEq)]
211pub enum PaymentMethodOptionsWechatPaySetupFutureUsage {
212    None,
213}
214impl PaymentMethodOptionsWechatPaySetupFutureUsage {
215    pub fn as_str(self) -> &'static str {
216        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
217        match self {
218            None => "none",
219        }
220    }
221}
222
223impl std::str::FromStr for PaymentMethodOptionsWechatPaySetupFutureUsage {
224    type Err = stripe_types::StripeParseError;
225    fn from_str(s: &str) -> Result<Self, Self::Err> {
226        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
227        match s {
228            "none" => Ok(None),
229            _ => Err(stripe_types::StripeParseError),
230        }
231    }
232}
233impl std::fmt::Display for PaymentMethodOptionsWechatPaySetupFutureUsage {
234    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
235        f.write_str(self.as_str())
236    }
237}
238
239impl std::fmt::Debug for PaymentMethodOptionsWechatPaySetupFutureUsage {
240    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
241        f.write_str(self.as_str())
242    }
243}
244#[cfg(feature = "serialize")]
245impl serde::Serialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
246    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
247    where
248        S: serde::Serializer,
249    {
250        serializer.serialize_str(self.as_str())
251    }
252}
253impl miniserde::Deserialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
254    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
255        crate::Place::new(out)
256    }
257}
258
259impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPaySetupFutureUsage> {
260    fn string(&mut self, s: &str) -> miniserde::Result<()> {
261        use std::str::FromStr;
262        self.out = Some(
263            PaymentMethodOptionsWechatPaySetupFutureUsage::from_str(s)
264                .map_err(|_| miniserde::Error)?,
265        );
266        Ok(())
267    }
268}
269
270stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPaySetupFutureUsage);
271#[cfg(feature = "deserialize")]
272impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPaySetupFutureUsage {
273    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
274        use std::str::FromStr;
275        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
276        Self::from_str(&s).map_err(|_| {
277            serde::de::Error::custom(
278                "Unknown value for PaymentMethodOptionsWechatPaySetupFutureUsage",
279            )
280        })
281    }
282}