Skip to main content

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