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