#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
pub struct PaymentMethodOptionsKlarna {
pub capture_method: Option<PaymentMethodOptionsKlarnaCaptureMethod>,
pub preferred_locale: Option<String>,
pub setup_future_usage: Option<PaymentMethodOptionsKlarnaSetupFutureUsage>,
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for PaymentMethodOptionsKlarna {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("PaymentMethodOptionsKlarna").finish_non_exhaustive()
}
}
#[doc(hidden)]
pub struct PaymentMethodOptionsKlarnaBuilder {
capture_method: Option<Option<PaymentMethodOptionsKlarnaCaptureMethod>>,
preferred_locale: Option<Option<String>>,
setup_future_usage: Option<Option<PaymentMethodOptionsKlarnaSetupFutureUsage>>,
}
#[allow(
unused_variables,
irrefutable_let_patterns,
clippy::let_unit_value,
clippy::match_single_binding,
clippy::single_match
)]
const _: () = {
use miniserde::de::{Map, Visitor};
use miniserde::json::Value;
use miniserde::{Deserialize, Result, make_place};
use stripe_types::miniserde_helpers::FromValueOpt;
use stripe_types::{MapBuilder, ObjectDeser};
make_place!(Place);
impl Deserialize for PaymentMethodOptionsKlarna {
fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
Place::new(out)
}
}
struct Builder<'a> {
out: &'a mut Option<PaymentMethodOptionsKlarna>,
builder: PaymentMethodOptionsKlarnaBuilder,
}
impl Visitor for Place<PaymentMethodOptionsKlarna> {
fn map(&mut self) -> Result<Box<dyn Map + '_>> {
Ok(Box::new(Builder {
out: &mut self.out,
builder: PaymentMethodOptionsKlarnaBuilder::deser_default(),
}))
}
}
impl MapBuilder for PaymentMethodOptionsKlarnaBuilder {
type Out = PaymentMethodOptionsKlarna;
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
Ok(match k {
"capture_method" => Deserialize::begin(&mut self.capture_method),
"preferred_locale" => Deserialize::begin(&mut self.preferred_locale),
"setup_future_usage" => Deserialize::begin(&mut self.setup_future_usage),
_ => <dyn Visitor>::ignore(),
})
}
fn deser_default() -> Self {
Self {
capture_method: Some(None),
preferred_locale: Some(None),
setup_future_usage: Some(None),
}
}
fn take_out(&mut self) -> Option<Self::Out> {
let (Some(capture_method), Some(preferred_locale), Some(setup_future_usage)) = (
self.capture_method.take(),
self.preferred_locale.take(),
self.setup_future_usage.take(),
) else {
return None;
};
Some(Self::Out { capture_method, preferred_locale, setup_future_usage })
}
}
impl Map for Builder<'_> {
fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
self.builder.key(k)
}
fn finish(&mut self) -> Result<()> {
*self.out = self.builder.take_out();
Ok(())
}
}
impl ObjectDeser for PaymentMethodOptionsKlarna {
type Builder = PaymentMethodOptionsKlarnaBuilder;
}
impl FromValueOpt for PaymentMethodOptionsKlarna {
fn from_value(v: Value) -> Option<Self> {
let Value::Object(obj) = v else {
return None;
};
let mut b = PaymentMethodOptionsKlarnaBuilder::deser_default();
for (k, v) in obj {
match k.as_str() {
"capture_method" => b.capture_method = FromValueOpt::from_value(v),
"preferred_locale" => b.preferred_locale = FromValueOpt::from_value(v),
"setup_future_usage" => b.setup_future_usage = FromValueOpt::from_value(v),
_ => {}
}
}
b.take_out()
}
}
};
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum PaymentMethodOptionsKlarnaCaptureMethod {
Manual,
Unknown(String),
}
impl PaymentMethodOptionsKlarnaCaptureMethod {
pub fn as_str(&self) -> &str {
use PaymentMethodOptionsKlarnaCaptureMethod::*;
match self {
Manual => "manual",
Unknown(v) => v,
}
}
}
impl std::str::FromStr for PaymentMethodOptionsKlarnaCaptureMethod {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use PaymentMethodOptionsKlarnaCaptureMethod::*;
match s {
"manual" => Ok(Manual),
v => {
tracing::warn!(
"Unknown value '{}' for enum '{}'",
v,
"PaymentMethodOptionsKlarnaCaptureMethod"
);
Ok(Unknown(v.to_owned()))
}
}
}
}
impl std::fmt::Display for PaymentMethodOptionsKlarnaCaptureMethod {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for PaymentMethodOptionsKlarnaCaptureMethod {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for PaymentMethodOptionsKlarnaCaptureMethod {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct(stringify!(PaymentMethodOptionsKlarnaCaptureMethod)).finish_non_exhaustive()
}
}
#[cfg(feature = "serialize")]
impl serde::Serialize for PaymentMethodOptionsKlarnaCaptureMethod {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for PaymentMethodOptionsKlarnaCaptureMethod {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsKlarnaCaptureMethod> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out = Some(PaymentMethodOptionsKlarnaCaptureMethod::from_str(s).expect("infallible"));
Ok(())
}
}
stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsKlarnaCaptureMethod);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsKlarnaCaptureMethod {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Ok(Self::from_str(&s).expect("infallible"))
}
}
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum PaymentMethodOptionsKlarnaSetupFutureUsage {
None,
OffSession,
OnSession,
Unknown(String),
}
impl PaymentMethodOptionsKlarnaSetupFutureUsage {
pub fn as_str(&self) -> &str {
use PaymentMethodOptionsKlarnaSetupFutureUsage::*;
match self {
None => "none",
OffSession => "off_session",
OnSession => "on_session",
Unknown(v) => v,
}
}
}
impl std::str::FromStr for PaymentMethodOptionsKlarnaSetupFutureUsage {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use PaymentMethodOptionsKlarnaSetupFutureUsage::*;
match s {
"none" => Ok(None),
"off_session" => Ok(OffSession),
"on_session" => Ok(OnSession),
v => {
tracing::warn!(
"Unknown value '{}' for enum '{}'",
v,
"PaymentMethodOptionsKlarnaSetupFutureUsage"
);
Ok(Unknown(v.to_owned()))
}
}
}
}
impl std::fmt::Display for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(not(feature = "redact-generated-debug"))]
impl std::fmt::Debug for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(feature = "redact-generated-debug")]
impl std::fmt::Debug for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct(stringify!(PaymentMethodOptionsKlarnaSetupFutureUsage))
.finish_non_exhaustive()
}
}
#[cfg(feature = "serialize")]
impl serde::Serialize for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl miniserde::Deserialize for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
crate::Place::new(out)
}
}
impl miniserde::de::Visitor for crate::Place<PaymentMethodOptionsKlarnaSetupFutureUsage> {
fn string(&mut self, s: &str) -> miniserde::Result<()> {
use std::str::FromStr;
self.out =
Some(PaymentMethodOptionsKlarnaSetupFutureUsage::from_str(s).expect("infallible"));
Ok(())
}
}
stripe_types::impl_from_val_with_from_str!(PaymentMethodOptionsKlarnaSetupFutureUsage);
#[cfg(feature = "deserialize")]
impl<'de> serde::Deserialize<'de> for PaymentMethodOptionsKlarnaSetupFutureUsage {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use std::str::FromStr;
let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
Ok(Self::from_str(&s).expect("infallible"))
}
}