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                _ => <dyn Visitor>::ignore(),
61            })
62        }
63
64        fn deser_default() -> Self {
65            Self {
66                chargeback_loss_reason_code: Deserialize::default(),
67                reason_code: Deserialize::default(),
68            }
69        }
70
71        fn take_out(&mut self) -> Option<Self::Out> {
72            let (Some(chargeback_loss_reason_code), Some(reason_code)) =
73                (self.chargeback_loss_reason_code.take(), self.reason_code.take())
74            else {
75                return None;
76            };
77            Some(Self::Out { chargeback_loss_reason_code, reason_code })
78        }
79    }
80
81    impl Map for Builder<'_> {
82        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
83            self.builder.key(k)
84        }
85
86        fn finish(&mut self) -> Result<()> {
87            *self.out = self.builder.take_out();
88            Ok(())
89        }
90    }
91
92    impl ObjectDeser for DisputePaymentMethodDetailsKlarna {
93        type Builder = DisputePaymentMethodDetailsKlarnaBuilder;
94    }
95
96    impl FromValueOpt for DisputePaymentMethodDetailsKlarna {
97        fn from_value(v: Value) -> Option<Self> {
98            let Value::Object(obj) = v else {
99                return None;
100            };
101            let mut b = DisputePaymentMethodDetailsKlarnaBuilder::deser_default();
102            for (k, v) in obj {
103                match k.as_str() {
104                    "chargeback_loss_reason_code" => {
105                        b.chargeback_loss_reason_code = FromValueOpt::from_value(v)
106                    }
107                    "reason_code" => b.reason_code = FromValueOpt::from_value(v),
108                    _ => {}
109                }
110            }
111            b.take_out()
112        }
113    }
114};