stripe_shared/
paypal_seller_protection.rs

1#[derive(Clone, Debug)]
2#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
3#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
4pub struct PaypalSellerProtection {
5    /// An array of conditions that are covered for the transaction, if applicable.
6    pub dispute_categories: Option<Vec<PaypalSellerProtectionDisputeCategories>>,
7    /// Indicates whether the transaction is eligible for PayPal's seller protection.
8    pub status: PaypalSellerProtectionStatus,
9}
10#[doc(hidden)]
11pub struct PaypalSellerProtectionBuilder {
12    dispute_categories: Option<Option<Vec<PaypalSellerProtectionDisputeCategories>>>,
13    status: Option<PaypalSellerProtectionStatus>,
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 PaypalSellerProtection {
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<PaypalSellerProtection>,
40        builder: PaypalSellerProtectionBuilder,
41    }
42
43    impl Visitor for Place<PaypalSellerProtection> {
44        fn map(&mut self) -> Result<Box<dyn Map + '_>> {
45            Ok(Box::new(Builder {
46                out: &mut self.out,
47                builder: PaypalSellerProtectionBuilder::deser_default(),
48            }))
49        }
50    }
51
52    impl MapBuilder for PaypalSellerProtectionBuilder {
53        type Out = PaypalSellerProtection;
54        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
55            Ok(match k {
56                "dispute_categories" => Deserialize::begin(&mut self.dispute_categories),
57                "status" => Deserialize::begin(&mut self.status),
58
59                _ => <dyn Visitor>::ignore(),
60            })
61        }
62
63        fn deser_default() -> Self {
64            Self { dispute_categories: Deserialize::default(), status: Deserialize::default() }
65        }
66
67        fn take_out(&mut self) -> Option<Self::Out> {
68            let (Some(dispute_categories), Some(status)) =
69                (self.dispute_categories.take(), self.status)
70            else {
71                return None;
72            };
73            Some(Self::Out { dispute_categories, status })
74        }
75    }
76
77    impl Map for Builder<'_> {
78        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
79            self.builder.key(k)
80        }
81
82        fn finish(&mut self) -> Result<()> {
83            *self.out = self.builder.take_out();
84            Ok(())
85        }
86    }
87
88    impl ObjectDeser for PaypalSellerProtection {
89        type Builder = PaypalSellerProtectionBuilder;
90    }
91
92    impl FromValueOpt for PaypalSellerProtection {
93        fn from_value(v: Value) -> Option<Self> {
94            let Value::Object(obj) = v else {
95                return None;
96            };
97            let mut b = PaypalSellerProtectionBuilder::deser_default();
98            for (k, v) in obj {
99                match k.as_str() {
100                    "dispute_categories" => b.dispute_categories = FromValueOpt::from_value(v),
101                    "status" => b.status = FromValueOpt::from_value(v),
102
103                    _ => {}
104                }
105            }
106            b.take_out()
107        }
108    }
109};
110/// An array of conditions that are covered for the transaction, if applicable.
111#[derive(Copy, Clone, Eq, PartialEq)]
112pub enum PaypalSellerProtectionDisputeCategories {
113    Fraudulent,
114    ProductNotReceived,
115}
116impl PaypalSellerProtectionDisputeCategories {
117    pub fn as_str(self) -> &'static str {
118        use PaypalSellerProtectionDisputeCategories::*;
119        match self {
120            Fraudulent => "fraudulent",
121            ProductNotReceived => "product_not_received",
122        }
123    }
124}
125
126impl std::str::FromStr for PaypalSellerProtectionDisputeCategories {
127    type Err = stripe_types::StripeParseError;
128    fn from_str(s: &str) -> Result<Self, Self::Err> {
129        use PaypalSellerProtectionDisputeCategories::*;
130        match s {
131            "fraudulent" => Ok(Fraudulent),
132            "product_not_received" => Ok(ProductNotReceived),
133            _ => Err(stripe_types::StripeParseError),
134        }
135    }
136}
137impl std::fmt::Display for PaypalSellerProtectionDisputeCategories {
138    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139        f.write_str(self.as_str())
140    }
141}
142
143impl std::fmt::Debug for PaypalSellerProtectionDisputeCategories {
144    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148#[cfg(feature = "serialize")]
149impl serde::Serialize for PaypalSellerProtectionDisputeCategories {
150    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
151    where
152        S: serde::Serializer,
153    {
154        serializer.serialize_str(self.as_str())
155    }
156}
157impl miniserde::Deserialize for PaypalSellerProtectionDisputeCategories {
158    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
159        crate::Place::new(out)
160    }
161}
162
163impl miniserde::de::Visitor for crate::Place<PaypalSellerProtectionDisputeCategories> {
164    fn string(&mut self, s: &str) -> miniserde::Result<()> {
165        use std::str::FromStr;
166        self.out = Some(
167            PaypalSellerProtectionDisputeCategories::from_str(s).map_err(|_| miniserde::Error)?,
168        );
169        Ok(())
170    }
171}
172
173stripe_types::impl_from_val_with_from_str!(PaypalSellerProtectionDisputeCategories);
174#[cfg(feature = "deserialize")]
175impl<'de> serde::Deserialize<'de> for PaypalSellerProtectionDisputeCategories {
176    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
177        use std::str::FromStr;
178        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
179        Self::from_str(&s).map_err(|_| {
180            serde::de::Error::custom("Unknown value for PaypalSellerProtectionDisputeCategories")
181        })
182    }
183}
184/// Indicates whether the transaction is eligible for PayPal's seller protection.
185#[derive(Copy, Clone, Eq, PartialEq)]
186pub enum PaypalSellerProtectionStatus {
187    Eligible,
188    NotEligible,
189    PartiallyEligible,
190}
191impl PaypalSellerProtectionStatus {
192    pub fn as_str(self) -> &'static str {
193        use PaypalSellerProtectionStatus::*;
194        match self {
195            Eligible => "eligible",
196            NotEligible => "not_eligible",
197            PartiallyEligible => "partially_eligible",
198        }
199    }
200}
201
202impl std::str::FromStr for PaypalSellerProtectionStatus {
203    type Err = stripe_types::StripeParseError;
204    fn from_str(s: &str) -> Result<Self, Self::Err> {
205        use PaypalSellerProtectionStatus::*;
206        match s {
207            "eligible" => Ok(Eligible),
208            "not_eligible" => Ok(NotEligible),
209            "partially_eligible" => Ok(PartiallyEligible),
210            _ => Err(stripe_types::StripeParseError),
211        }
212    }
213}
214impl std::fmt::Display for PaypalSellerProtectionStatus {
215    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
216        f.write_str(self.as_str())
217    }
218}
219
220impl std::fmt::Debug for PaypalSellerProtectionStatus {
221    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
222        f.write_str(self.as_str())
223    }
224}
225#[cfg(feature = "serialize")]
226impl serde::Serialize for PaypalSellerProtectionStatus {
227    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
228    where
229        S: serde::Serializer,
230    {
231        serializer.serialize_str(self.as_str())
232    }
233}
234impl miniserde::Deserialize for PaypalSellerProtectionStatus {
235    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
236        crate::Place::new(out)
237    }
238}
239
240impl miniserde::de::Visitor for crate::Place<PaypalSellerProtectionStatus> {
241    fn string(&mut self, s: &str) -> miniserde::Result<()> {
242        use std::str::FromStr;
243        self.out = Some(PaypalSellerProtectionStatus::from_str(s).map_err(|_| miniserde::Error)?);
244        Ok(())
245    }
246}
247
248stripe_types::impl_from_val_with_from_str!(PaypalSellerProtectionStatus);
249#[cfg(feature = "deserialize")]
250impl<'de> serde::Deserialize<'de> for PaypalSellerProtectionStatus {
251    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
252        use std::str::FromStr;
253        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
254        Self::from_str(&s)
255            .map_err(|_| serde::de::Error::custom("Unknown value for PaypalSellerProtectionStatus"))
256    }
257}