Skip to main content

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