Skip to main content

stripe_shared/
payment_method_options_alipay.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 PaymentMethodOptionsAlipay {
6    /// Indicates that you intend to make future payments with this PaymentIntent's payment method.
7    ///
8    /// 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.
9    /// 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.
10    ///
11    /// 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.
12    ///
13    /// 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).
14    pub setup_future_usage: Option<PaymentMethodOptionsAlipaySetupFutureUsage>,
15}
16#[cfg(feature = "redact-generated-debug")]
17impl std::fmt::Debug for PaymentMethodOptionsAlipay {
18    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
19        f.debug_struct("PaymentMethodOptionsAlipay").finish_non_exhaustive()
20    }
21}
22#[doc(hidden)]
23pub struct PaymentMethodOptionsAlipayBuilder {
24    setup_future_usage: Option<Option<PaymentMethodOptionsAlipaySetupFutureUsage>>,
25}
26
27#[allow(
28    unused_variables,
29    irrefutable_let_patterns,
30    clippy::let_unit_value,
31    clippy::match_single_binding,
32    clippy::single_match
33)]
34const _: () = {
35    use miniserde::de::{Map, Visitor};
36    use miniserde::json::Value;
37    use miniserde::{Deserialize, Result, make_place};
38    use stripe_types::miniserde_helpers::FromValueOpt;
39    use stripe_types::{MapBuilder, ObjectDeser};
40
41    make_place!(Place);
42
43    impl Deserialize for PaymentMethodOptionsAlipay {
44        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
45            Place::new(out)
46        }
47    }
48
49    struct Builder<'a> {
50        out: &'a mut Option<PaymentMethodOptionsAlipay>,
51        builder: PaymentMethodOptionsAlipayBuilder,
52    }
53
54    impl Visitor for Place<PaymentMethodOptionsAlipay> {
55        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
56            Ok(Box::new(Builder {
57                out: &mut self.out,
58                builder: PaymentMethodOptionsAlipayBuilder::deser_default(),
59            }))
60        }
61    }
62
63    impl MapBuilder for PaymentMethodOptionsAlipayBuilder {
64        type Out = PaymentMethodOptionsAlipay;
65        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
66            Ok(match k {
67                "setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
68                _ => <dyn Visitor>::ignore(),
69            })
70        }
71
72        fn deser_default() -> Self {
73            Self { setup_future_usage: Some(None) }
74        }
75
76        fn take_out(&mut self) -> Option<Self::Out> {
77            let (Some(setup_future_usage),) = (self.setup_future_usage.take(),) else {
78                return None;
79            };
80            Some(Self::Out { setup_future_usage })
81        }
82    }
83
84    impl Map for Builder<'_> {
85        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
86            self.builder.key(k)
87        }
88
89        fn finish(&mut self) -> Result<()> {
90            *self.out = self.builder.take_out();
91            Ok(())
92        }
93    }
94
95    impl ObjectDeser for PaymentMethodOptionsAlipay {
96        type Builder = PaymentMethodOptionsAlipayBuilder;
97    }
98
99    impl FromValueOpt for PaymentMethodOptionsAlipay {
100        fn from_value(v: Value) -> Option<Self> {
101            let Value::Object(obj) = v else {
102                return None;
103            };
104            let mut b = PaymentMethodOptionsAlipayBuilder::deser_default();
105            for (k, v) in obj {
106                match k.as_str() {
107                    "setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
108                    _ => {}
109                }
110            }
111            b.take_out()
112        }
113    }
114};
115/// Indicates that you intend to make future payments with this PaymentIntent's payment method.
116///
117/// 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.
118/// 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.
119///
120/// 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.
121///
122/// 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).
123#[derive(Clone, Eq, PartialEq)]
124#[non_exhaustive]
125pub enum PaymentMethodOptionsAlipaySetupFutureUsage {
126    None,
127    OffSession,
128    /// An unrecognized value from Stripe. Should not be used as a request parameter.
129    Unknown(String),
130}
131impl PaymentMethodOptionsAlipaySetupFutureUsage {
132    pub fn as_str(&self) -> &str {
133        use PaymentMethodOptionsAlipaySetupFutureUsage::*;
134        match self {
135            None => "none",
136            OffSession => "off_session",
137            Unknown(v) => v,
138        }
139    }
140}
141
142impl std::str::FromStr for PaymentMethodOptionsAlipaySetupFutureUsage {
143    type Err = std::convert::Infallible;
144    fn from_str(s: &str) -> Result<Self, Self::Err> {
145        use PaymentMethodOptionsAlipaySetupFutureUsage::*;
146        match s {
147            "none" => Ok(None),
148            "off_session" => Ok(OffSession),
149            v => {
150                tracing::warn!(
151                    "Unknown value '{}' for enum '{}'",
152                    v,
153                    "PaymentMethodOptionsAlipaySetupFutureUsage"
154                );
155                Ok(Unknown(v.to_owned()))
156            }
157        }
158    }
159}
160impl std::fmt::Display for PaymentMethodOptionsAlipaySetupFutureUsage {
161    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
162        f.write_str(self.as_str())
163    }
164}
165
166#[cfg(not(feature = "redact-generated-debug"))]
167impl std::fmt::Debug for PaymentMethodOptionsAlipaySetupFutureUsage {
168    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
169        f.write_str(self.as_str())
170    }
171}
172#[cfg(feature = "redact-generated-debug")]
173impl std::fmt::Debug for PaymentMethodOptionsAlipaySetupFutureUsage {
174    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
175        f.debug_struct(stringify!(PaymentMethodOptionsAlipaySetupFutureUsage))
176            .finish_non_exhaustive()
177    }
178}
179#[cfg(feature = "serialize")]
180impl serde::Serialize for PaymentMethodOptionsAlipaySetupFutureUsage {
181    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
182    where
183        S: serde::Serializer,
184    {
185        serializer.serialize_str(self.as_str())
186    }
187}
188impl miniserde::Deserialize for PaymentMethodOptionsAlipaySetupFutureUsage {
189    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
190        crate::Place::new(out)
191    }
192}
193
194impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsAlipaySetupFutureUsage> {
195    fn string(&mut self, s: &str) -> miniserde::Result<()> {
196        use std::str::FromStr;
197        self.out =
198            Some(PaymentMethodOptionsAlipaySetupFutureUsage::from_str(s).expect("infallible"));
199        Ok(())
200    }
201}
202
203stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsAlipaySetupFutureUsage);
204#[cfg(feature = "deserialize")]
205impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsAlipaySetupFutureUsage {
206    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207        use std::str::FromStr;
208        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
209        Ok(Self::from_str(&s).expect("infallible"))
210    }
211}