stripe_shared/
dispute_payment_method_details_klarna.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct DisputePaymentMethodDetailsKlarna {
5    /// Chargeback loss reason mapped by Stripe from Klarna's chargeback loss reason
6    pub chargeback_loss_reason_code: Option<String>,
7    /// The reason for the dispute as defined by Klarna
8    pub reason_code: Option<String>,
9}
10#[doc(hidden)]
11pub struct DisputePaymentMethodDetailsKlarnaBuilder {
12    chargeback_loss_reason_code: Option<Option<String>>,
13    reason_code: Option<Option<String>>,
14}
15
16#[allow(
17    unused_variables,
18    irrefutable_let_patterns,
19    clippy::let_unit_value,
20    clippy::match_single_binding,
21    clippy::single_match
22)]
23const _: () = {
24    use miniserde::de::{Map, Visitor};
25    use miniserde::json::Value;
26    use miniserde::{Deserialize, Result, make_place};
27    use stripe_types::miniserde_helpers::FromValueOpt;
28    use stripe_types::{MapBuilder, ObjectDeser};
29
30    make_place!(Place);
31
32    impl Deserialize for DisputePaymentMethodDetailsKlarna {
33        fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
34            Place::new(out)
35        }
36    }
37
38    struct Builder<'a> {
39        out: &'a mut Option<DisputePaymentMethodDetailsKlarna>,
40        builder: DisputePaymentMethodDetailsKlarnaBuilder,
41    }
42
43    impl Visitor for Place<DisputePaymentMethodDetailsKlarna> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: DisputePaymentMethodDetailsKlarnaBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for DisputePaymentMethodDetailsKlarnaBuilder {
53        type Out = DisputePaymentMethodDetailsKlarna;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "chargeback_loss_reason_code" => {
57                    Deserialize::begin(&mut self.chargeback_loss_reason_code)
58                }
59                "reason_code" => Deserialize::begin(&mut self.reason_code),
60
61                _ => <dyn Visitor>::ignore(),
62            })
63        }
64
65        fn deser_default() -> Self {
66            Self {
67                chargeback_loss_reason_code: Deserialize::default(),
68                reason_code: Deserialize::default(),
69            }
70        }
71
72        fn take_out(&mut self) -> Option<Self::Out> {
73            let (Some(chargeback_loss_reason_code), Some(reason_code)) =
74                (self.chargeback_loss_reason_code.take(), self.reason_code.take())
75            else {
76                return None;
77            };
78            Some(Self::Out { chargeback_loss_reason_code, reason_code })
79        }
80    }
81
82    impl Map for Builder<'_> {
83        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
84            self.builder.key(k)
85        }
86
87        fn finish(&mut self) -> Result<()> {
88            *self.out = self.builder.take_out();
89            Ok(())
90        }
91    }
92
93    impl ObjectDeser for DisputePaymentMethodDetailsKlarna {
94        type Builder = DisputePaymentMethodDetailsKlarnaBuilder;
95    }
96
97    impl FromValueOpt for DisputePaymentMethodDetailsKlarna {
98        fn from_value(v: Value) -> Option<Self> {
99            let Value::Object(obj) = v else {
100                return None;
101            };
102            let mut b = DisputePaymentMethodDetailsKlarnaBuilder::deser_default();
103            for (k, v) in obj {
104                match k.as_str() {
105                    "chargeback_loss_reason_code" => {
106                        b.chargeback_loss_reason_code = FromValueOpt::from_value(v)
107                    }
108                    "reason_code" => b.reason_code = FromValueOpt::from_value(v),
109
110                    _ => {}
111                }
112            }
113            b.take_out()
114        }
115    }
116};