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.take())
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(Clone, Eq, PartialEq)]
110#[non_exhaustive]
111pub enum PaypalSellerProtectionDisputeCategories {
112 Fraudulent,
113 ProductNotReceived,
114 Unknown(String),
116}
117impl PaypalSellerProtectionDisputeCategories {
118 pub fn as_str(&self) -> &str {
119 use PaypalSellerProtectionDisputeCategories::*;
120 match self {
121 Fraudulent => "fraudulent",
122 ProductNotReceived => "product_not_received",
123 Unknown(v) => v,
124 }
125 }
126}
127
128impl std::str::FromStr for PaypalSellerProtectionDisputeCategories {
129 type Err = std::convert::Infallible;
130 fn from_str(s: &str) -> Result<Self, Self::Err> {
131 use PaypalSellerProtectionDisputeCategories::*;
132 match s {
133 "fraudulent" => Ok(Fraudulent),
134 "product_not_received" => Ok(ProductNotReceived),
135 v => {
136 tracing::warn!(
137 "Unknown value '{}' for enum '{}'",
138 v,
139 "PaypalSellerProtectionDisputeCategories"
140 );
141 Ok(Unknown(v.to_owned()))
142 }
143 }
144 }
145}
146impl std::fmt::Display for PaypalSellerProtectionDisputeCategories {
147 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148 f.write_str(self.as_str())
149 }
150}
151
152impl std::fmt::Debug for PaypalSellerProtectionDisputeCategories {
153 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154 f.write_str(self.as_str())
155 }
156}
157#[cfg(feature = "serialize")]
158impl serde::Serialize for PaypalSellerProtectionDisputeCategories {
159 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
160 where
161 S: serde::Serializer,
162 {
163 serializer.serialize_str(self.as_str())
164 }
165}
166impl miniserde::Deserialize for PaypalSellerProtectionDisputeCategories {
167 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
168 crate::Place::new(out)
169 }
170}
171
172impl miniserde::de::Visitor for crate::Place<PaypalSellerProtectionDisputeCategories> {
173 fn string(&mut self, s: &str) -> miniserde::Result<()> {
174 use std::str::FromStr;
175 self.out = Some(PaypalSellerProtectionDisputeCategories::from_str(s).expect("infallible"));
176 Ok(())
177 }
178}
179
180stripe_types::impl_from_val_with_from_str!(PaypalSellerProtectionDisputeCategories);
181#[cfg(feature = "deserialize")]
182impl<'de> serde::Deserialize<'de> for PaypalSellerProtectionDisputeCategories {
183 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
184 use std::str::FromStr;
185 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
186 Ok(Self::from_str(&s).expect("infallible"))
187 }
188}
189#[derive(Clone, Eq, PartialEq)]
191#[non_exhaustive]
192pub enum PaypalSellerProtectionStatus {
193 Eligible,
194 NotEligible,
195 PartiallyEligible,
196 Unknown(String),
198}
199impl PaypalSellerProtectionStatus {
200 pub fn as_str(&self) -> &str {
201 use PaypalSellerProtectionStatus::*;
202 match self {
203 Eligible => "eligible",
204 NotEligible => "not_eligible",
205 PartiallyEligible => "partially_eligible",
206 Unknown(v) => v,
207 }
208 }
209}
210
211impl std::str::FromStr for PaypalSellerProtectionStatus {
212 type Err = std::convert::Infallible;
213 fn from_str(s: &str) -> Result<Self, Self::Err> {
214 use PaypalSellerProtectionStatus::*;
215 match s {
216 "eligible" => Ok(Eligible),
217 "not_eligible" => Ok(NotEligible),
218 "partially_eligible" => Ok(PartiallyEligible),
219 v => {
220 tracing::warn!(
221 "Unknown value '{}' for enum '{}'",
222 v,
223 "PaypalSellerProtectionStatus"
224 );
225 Ok(Unknown(v.to_owned()))
226 }
227 }
228 }
229}
230impl std::fmt::Display for PaypalSellerProtectionStatus {
231 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
232 f.write_str(self.as_str())
233 }
234}
235
236impl std::fmt::Debug for PaypalSellerProtectionStatus {
237 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238 f.write_str(self.as_str())
239 }
240}
241#[cfg(feature = "serialize")]
242impl serde::Serialize for PaypalSellerProtectionStatus {
243 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
244 where
245 S: serde::Serializer,
246 {
247 serializer.serialize_str(self.as_str())
248 }
249}
250impl miniserde::Deserialize for PaypalSellerProtectionStatus {
251 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
252 crate::Place::new(out)
253 }
254}
255
256impl miniserde::de::Visitor for crate::Place<PaypalSellerProtectionStatus> {
257 fn string(&mut self, s: &str) -> miniserde::Result<()> {
258 use std::str::FromStr;
259 self.out = Some(PaypalSellerProtectionStatus::from_str(s).expect("infallible"));
260 Ok(())
261 }
262}
263
264stripe_types::impl_from_val_with_from_str!(PaypalSellerProtectionStatus);
265#[cfg(feature = "deserialize")]
266impl<'de> serde::Deserialize<'de> for PaypalSellerProtectionStatus {
267 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
268 use std::str::FromStr;
269 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
270 Ok(Self::from_str(&s).expect("infallible"))
271 }
272}