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, self.setup_future_usage)
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(Copy, Clone, Eq, PartialEq)]
126pub enum PaymentMethodOptionsWechatPayClient {
127    Android,
128    Ios,
129    Web,
130}
131impl PaymentMethodOptionsWechatPayClient {
132    pub fn as_str(self) -> &'static str {
133        use PaymentMethodOptionsWechatPayClient::*;
134        match self {
135            Android => "android",
136            Ios => "ios",
137            Web => "web",
138        }
139    }
140}
141
142impl std::str::FromStr for PaymentMethodOptionsWechatPayClient {
143    type Err = stripe_types::StripeParseError;
144    fn from_str(s: &str) -> Result<Self, Self::Err> {
145        use PaymentMethodOptionsWechatPayClient::*;
146        match s {
147            "android" => Ok(Android),
148            "ios" => Ok(Ios),
149            "web" => Ok(Web),
150            _ => Err(stripe_types::StripeParseError),
151        }
152    }
153}
154impl std::fmt::Display for PaymentMethodOptionsWechatPayClient {
155    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156        f.write_str(self.as_str())
157    }
158}
159
160impl std::fmt::Debug for PaymentMethodOptionsWechatPayClient {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(self.as_str())
163    }
164}
165#[cfg(feature = "serialize")]
166impl serde::Serialize for PaymentMethodOptionsWechatPayClient {
167    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
168    where
169        S: serde::Serializer,
170    {
171        serializer.serialize_str(self.as_str())
172    }
173}
174impl miniserde::Deserialize for PaymentMethodOptionsWechatPayClient {
175    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
176        crate::Place::new(out)
177    }
178}
179
180impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPayClient> {
181    fn string(&mut self, s: &str) -> miniserde::Result<()> {
182        use std::str::FromStr;
183        self.out =
184            Some(PaymentMethodOptionsWechatPayClient::from_str(s).map_err(|_| miniserde::Error)?);
185        Ok(())
186    }
187}
188
189stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPayClient);
190#[cfg(feature = "deserialize")]
191impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPayClient {
192    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
193        use std::str::FromStr;
194        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
195        Self::from_str(&s).map_err(|_| {
196            serde::de::Error::custom("Unknown value for PaymentMethodOptionsWechatPayClient")
197        })
198    }
199}
200/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
201///
202/// 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.
203/// 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.
204///
205/// 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.
206///
207/// 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).
208#[derive(Copy, Clone, Eq, PartialEq)]
209pub enum PaymentMethodOptionsWechatPaySetupFutureUsage {
210    None,
211}
212impl PaymentMethodOptionsWechatPaySetupFutureUsage {
213    pub fn as_str(self) -> &'static str {
214        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
215        match self {
216            None => "none",
217        }
218    }
219}
220
221impl std::str::FromStr for PaymentMethodOptionsWechatPaySetupFutureUsage {
222    type Err = stripe_types::StripeParseError;
223    fn from_str(s: &str) -> Result<Self, Self::Err> {
224        use PaymentMethodOptionsWechatPaySetupFutureUsage::*;
225        match s {
226            "none" => Ok(None),
227            _ => Err(stripe_types::StripeParseError),
228        }
229    }
230}
231impl std::fmt::Display for PaymentMethodOptionsWechatPaySetupFutureUsage {
232    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
233        f.write_str(self.as_str())
234    }
235}
236
237impl std::fmt::Debug for PaymentMethodOptionsWechatPaySetupFutureUsage {
238    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
239        f.write_str(self.as_str())
240    }
241}
242#[cfg(feature = "serialize")]
243impl serde::Serialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
244    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
245    where
246        S: serde::Serializer,
247    {
248        serializer.serialize_str(self.as_str())
249    }
250}
251impl miniserde::Deserialize for PaymentMethodOptionsWechatPaySetupFutureUsage {
252    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
253        crate::Place::new(out)
254    }
255}
256
257impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsWechatPaySetupFutureUsage> {
258    fn string(&mut self, s: &str) -> miniserde::Result<()> {
259        use std::str::FromStr;
260        self.out = Some(
261            PaymentMethodOptionsWechatPaySetupFutureUsage::from_str(s)
262                .map_err(|_| miniserde::Error)?,
263        );
264        Ok(())
265    }
266}
267
268stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsWechatPaySetupFutureUsage);
269#[cfg(feature = "deserialize")]
270impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsWechatPaySetupFutureUsage {
271    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
272        use std::str::FromStr;
273        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
274        Self::from_str(&s).map_err(|_| {
275            serde::de::Error::custom(
276                "Unknown value for PaymentMethodOptionsWechatPaySetupFutureUsage",
277            )
278        })
279    }
280}