stripe_shared/
payment_method_options_card_present.rs

1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaymentMethodOptionsCardPresent {
5    /// Controls when the funds will be captured from the customer's account.
6    pub capture_method: Option<PaymentMethodOptionsCardPresentCaptureMethod>,
7    /// Request ability to capture this payment beyond the standard [authorization validity window](https://stripe.com/docs/terminal/features/extended-authorizations#authorization-validity).
8    pub request_extended_authorization: Option<bool>,
9    /// Request ability to [increment](https://stripe.com/docs/terminal/features/incremental-authorizations) this PaymentIntent if the combination of MCC and card brand is eligible.
10    /// Check [incremental_authorization_supported](https://stripe.com/docs/api/charges/object#charge_object-payment_method_details-card_present-incremental_authorization_supported) in the [Confirm](https://stripe.com/docs/api/payment_intents/confirm) response to verify support.
11    pub request_incremental_authorization_support: Option<bool>,
12    pub routing: Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>,
13}
14#[doc(hidden)]
15pub struct PaymentMethodOptionsCardPresentBuilder {
16    capture_method: Option<Option<PaymentMethodOptionsCardPresentCaptureMethod>>,
17    request_extended_authorization: Option<Option<bool>>,
18    request_incremental_authorization_support: Option<Option<bool>>,
19    routing: Option<Option<stripe_shared::PaymentMethodOptionsCardPresentRouting>>,
20}
21
22#[allow(
23    unused_variables,
24    irrefutable_let_patterns,
25    clippy::let_unit_value,
26    clippy::match_single_binding,
27    clippy::single_match
28)]
29const _: () = {
30    use miniserde::de::{Map, Visitor};
31    use miniserde::json::Value;
32    use miniserde::{Deserialize, Result, make_place};
33    use stripe_types::miniserde_helpers::FromValueOpt;
34    use stripe_types::{MapBuilder, ObjectDeser};
35
36    make_place!(Place);
37
38    impl Deserialize for PaymentMethodOptionsCardPresent {
39        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
40            Place::new(out)
41        }
42    }
43
44    struct Builder<'a> {
45        out: &'a mut Option<PaymentMethodOptionsCardPresent>,
46        builder: PaymentMethodOptionsCardPresentBuilder,
47    }
48
49    impl Visitor for Place<PaymentMethodOptionsCardPresent> {
50        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
51            Ok(Box::new(Builder {
52                out: &mut self.out,
53                builder: PaymentMethodOptionsCardPresentBuilder::deser_default(),
54            }))
55        }
56    }
57
58    impl MapBuilder for PaymentMethodOptionsCardPresentBuilder {
59        type Out = PaymentMethodOptionsCardPresent;
60        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
61            Ok(match k {
62                "capture_method" => Deserialize::begin(&mut self.capture_method),
63                "request_extended_authorization" => {
64                    Deserialize::begin(&mut self.request_extended_authorization)
65                }
66                "request_incremental_authorization_support" => {
67                    Deserialize::begin(&mut self.request_incremental_authorization_support)
68                }
69                "routing" => Deserialize::begin(&mut self.routing),
70                _ => <dyn Visitor>::ignore(),
71            })
72        }
73
74        fn deser_default() -> Self {
75            Self {
76                capture_method: Deserialize::default(),
77                request_extended_authorization: Deserialize::default(),
78                request_incremental_authorization_support: Deserialize::default(),
79                routing: Deserialize::default(),
80            }
81        }
82
83        fn take_out(&mut self) -> Option<Self::Out> {
84            let (
85                Some(capture_method),
86                Some(request_extended_authorization),
87                Some(request_incremental_authorization_support),
88                Some(routing),
89            ) = (
90                self.capture_method,
91                self.request_extended_authorization,
92                self.request_incremental_authorization_support,
93                self.routing,
94            )
95            else {
96                return None;
97            };
98            Some(Self::Out {
99                capture_method,
100                request_extended_authorization,
101                request_incremental_authorization_support,
102                routing,
103            })
104        }
105    }
106
107    impl Map for Builder<'_> {
108        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
109            self.builder.key(k)
110        }
111
112        fn finish(&mut self) -> Result<()> {
113            *self.out = self.builder.take_out();
114            Ok(())
115        }
116    }
117
118    impl ObjectDeser for PaymentMethodOptionsCardPresent {
119        type Builder = PaymentMethodOptionsCardPresentBuilder;
120    }
121
122    impl FromValueOpt for PaymentMethodOptionsCardPresent {
123        fn from_value(v: Value) -> Option<Self> {
124            let Value::Object(obj) = v else {
125                return None;
126            };
127            let mut b = PaymentMethodOptionsCardPresentBuilder::deser_default();
128            for (k, v) in obj {
129                match k.as_str() {
130                    "capture_method" => b.capture_method = FromValueOpt::from_value(v),
131                    "request_extended_authorization" => {
132                        b.request_extended_authorization = FromValueOpt::from_value(v)
133                    }
134                    "request_incremental_authorization_support" => {
135                        b.request_incremental_authorization_support = FromValueOpt::from_value(v)
136                    }
137                    "routing" => b.routing = FromValueOpt::from_value(v),
138                    _ => {}
139                }
140            }
141            b.take_out()
142        }
143    }
144};
145/// Controls when the funds will be captured from the customer's account.
146#[derive(Copy, Clone, Eq, PartialEq)]
147pub enum PaymentMethodOptionsCardPresentCaptureMethod {
148    Manual,
149    ManualPreferred,
150}
151impl PaymentMethodOptionsCardPresentCaptureMethod {
152    pub fn as_str(self) -> &'static str {
153        use PaymentMethodOptionsCardPresentCaptureMethod::*;
154        match self {
155            Manual => "manual",
156            ManualPreferred => "manual_preferred",
157        }
158    }
159}
160
161impl std::str::FromStr for PaymentMethodOptionsCardPresentCaptureMethod {
162    type Err = stripe_types::StripeParseError;
163    fn from_str(s: &str) -> Result<Self, Self::Err> {
164        use PaymentMethodOptionsCardPresentCaptureMethod::*;
165        match s {
166            "manual" => Ok(Manual),
167            "manual_preferred" => Ok(ManualPreferred),
168            _ => Err(stripe_types::StripeParseError),
169        }
170    }
171}
172impl std::fmt::Display for PaymentMethodOptionsCardPresentCaptureMethod {
173    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
174        f.write_str(self.as_str())
175    }
176}
177
178impl std::fmt::Debug for PaymentMethodOptionsCardPresentCaptureMethod {
179    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180        f.write_str(self.as_str())
181    }
182}
183#[cfg(feature = "serialize")]
184impl serde::Serialize for PaymentMethodOptionsCardPresentCaptureMethod {
185    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
186    where
187        S: serde::Serializer,
188    {
189        serializer.serialize_str(self.as_str())
190    }
191}
192impl miniserde::Deserialize for PaymentMethodOptionsCardPresentCaptureMethod {
193    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
194        crate::Place::new(out)
195    }
196}
197
198impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsCardPresentCaptureMethod> {
199    fn string(&mut self, s: &str) -> miniserde::Result<()> {
200        use std::str::FromStr;
201        self.out = Some(
202            PaymentMethodOptionsCardPresentCaptureMethod::from_str(s)
203                .map_err(|_| miniserde::Error)?,
204        );
205        Ok(())
206    }
207}
208
209stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsCardPresentCaptureMethod);
210#[cfg(feature = "deserialize")]
211impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsCardPresentCaptureMethod {
212    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
213        use std::str::FromStr;
214        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
215        Self::from_str(&s).map_err(|_| {
216            serde::de::Error::custom(
217                "Unknown value for PaymentMethodOptionsCardPresentCaptureMethod",
218            )
219        })
220    }
221}