1#[derive(Clone, Debug)]
12#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
13pub struct Product {
14 pub active: bool,
16 pub created: stripe_types::Timestamp,
18 pub default_price: Option<stripe_types::Expandable<stripe_shared::Price>>,
20 pub description: Option<String>,
23 pub id: stripe_shared::ProductId,
25 pub images: Vec<String>,
27 pub livemode: bool,
29 pub marketing_features: Vec<stripe_shared::ProductMarketingFeature>,
32 pub metadata: std::collections::HashMap<String, String>,
35 pub name: String,
37 pub package_dimensions: Option<stripe_shared::PackageDimensions>,
39 pub shippable: Option<bool>,
41 pub statement_descriptor: Option<String>,
45 pub tax_code: Option<stripe_types::Expandable<stripe_shared::TaxCode>>,
47 #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
50 pub type_: stripe_shared::ProductType,
51 pub unit_label: Option<String>,
54 pub updated: stripe_types::Timestamp,
56 pub url: Option<String>,
58}
59#[doc(hidden)]
60pub struct ProductBuilder {
61 active: Option<bool>,
62 created: Option<stripe_types::Timestamp>,
63 default_price: Option<Option<stripe_types::Expandable<stripe_shared::Price>>>,
64 description: Option<Option<String>>,
65 id: Option<stripe_shared::ProductId>,
66 images: Option<Vec<String>>,
67 livemode: Option<bool>,
68 marketing_features: Option<Vec<stripe_shared::ProductMarketingFeature>>,
69 metadata: Option<std::collections::HashMap<String, String>>,
70 name: Option<String>,
71 package_dimensions: Option<Option<stripe_shared::PackageDimensions>>,
72 shippable: Option<Option<bool>>,
73 statement_descriptor: Option<Option<String>>,
74 tax_code: Option<Option<stripe_types::Expandable<stripe_shared::TaxCode>>>,
75 type_: Option<stripe_shared::ProductType>,
76 unit_label: Option<Option<String>>,
77 updated: Option<stripe_types::Timestamp>,
78 url: Option<Option<String>>,
79}
80
81#[allow(
82 unused_variables,
83 irrefutable_let_patterns,
84 clippy::let_unit_value,
85 clippy::match_single_binding,
86 clippy::single_match
87)]
88const _: () = {
89 use miniserde::de::{Map, Visitor};
90 use miniserde::json::Value;
91 use miniserde::{Deserialize, Result, make_place};
92 use stripe_types::miniserde_helpers::FromValueOpt;
93 use stripe_types::{MapBuilder, ObjectDeser};
94
95 make_place!(Place);
96
97 impl Deserialize for Product {
98 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
99 Place::new(out)
100 }
101 }
102
103 struct Builder<'a> {
104 out: &'a mut Option<Product>,
105 builder: ProductBuilder,
106 }
107
108 impl Visitor for Place<Product> {
109 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
110 Ok(Box::new(Builder { out: &mut self.out, builder: ProductBuilder::deser_default() }))
111 }
112 }
113
114 impl MapBuilder for ProductBuilder {
115 type Out = Product;
116 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
117 Ok(match k {
118 "active" => Deserialize::begin(&mut self.active),
119 "created" => Deserialize::begin(&mut self.created),
120 "default_price" => Deserialize::begin(&mut self.default_price),
121 "description" => Deserialize::begin(&mut self.description),
122 "id" => Deserialize::begin(&mut self.id),
123 "images" => Deserialize::begin(&mut self.images),
124 "livemode" => Deserialize::begin(&mut self.livemode),
125 "marketing_features" => Deserialize::begin(&mut self.marketing_features),
126 "metadata" => Deserialize::begin(&mut self.metadata),
127 "name" => Deserialize::begin(&mut self.name),
128 "package_dimensions" => Deserialize::begin(&mut self.package_dimensions),
129 "shippable" => Deserialize::begin(&mut self.shippable),
130 "statement_descriptor" => Deserialize::begin(&mut self.statement_descriptor),
131 "tax_code" => Deserialize::begin(&mut self.tax_code),
132 "type" => Deserialize::begin(&mut self.type_),
133 "unit_label" => Deserialize::begin(&mut self.unit_label),
134 "updated" => Deserialize::begin(&mut self.updated),
135 "url" => Deserialize::begin(&mut self.url),
136 _ => <dyn Visitor>::ignore(),
137 })
138 }
139
140 fn deser_default() -> Self {
141 Self {
142 active: Deserialize::default(),
143 created: Deserialize::default(),
144 default_price: Deserialize::default(),
145 description: Deserialize::default(),
146 id: Deserialize::default(),
147 images: Deserialize::default(),
148 livemode: Deserialize::default(),
149 marketing_features: Deserialize::default(),
150 metadata: Deserialize::default(),
151 name: Deserialize::default(),
152 package_dimensions: Deserialize::default(),
153 shippable: Deserialize::default(),
154 statement_descriptor: Deserialize::default(),
155 tax_code: Deserialize::default(),
156 type_: Deserialize::default(),
157 unit_label: Deserialize::default(),
158 updated: Deserialize::default(),
159 url: Deserialize::default(),
160 }
161 }
162
163 fn take_out(&mut self) -> Option<Self::Out> {
164 let (
165 Some(active),
166 Some(created),
167 Some(default_price),
168 Some(description),
169 Some(id),
170 Some(images),
171 Some(livemode),
172 Some(marketing_features),
173 Some(metadata),
174 Some(name),
175 Some(package_dimensions),
176 Some(shippable),
177 Some(statement_descriptor),
178 Some(tax_code),
179 Some(type_),
180 Some(unit_label),
181 Some(updated),
182 Some(url),
183 ) = (
184 self.active,
185 self.created,
186 self.default_price.take(),
187 self.description.take(),
188 self.id.take(),
189 self.images.take(),
190 self.livemode,
191 self.marketing_features.take(),
192 self.metadata.take(),
193 self.name.take(),
194 self.package_dimensions,
195 self.shippable,
196 self.statement_descriptor.take(),
197 self.tax_code.take(),
198 self.type_.take(),
199 self.unit_label.take(),
200 self.updated,
201 self.url.take(),
202 )
203 else {
204 return None;
205 };
206 Some(Self::Out {
207 active,
208 created,
209 default_price,
210 description,
211 id,
212 images,
213 livemode,
214 marketing_features,
215 metadata,
216 name,
217 package_dimensions,
218 shippable,
219 statement_descriptor,
220 tax_code,
221 type_,
222 unit_label,
223 updated,
224 url,
225 })
226 }
227 }
228
229 impl Map for Builder<'_> {
230 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
231 self.builder.key(k)
232 }
233
234 fn finish(&mut self) -> Result<()> {
235 *self.out = self.builder.take_out();
236 Ok(())
237 }
238 }
239
240 impl ObjectDeser for Product {
241 type Builder = ProductBuilder;
242 }
243
244 impl FromValueOpt for Product {
245 fn from_value(v: Value) -> Option<Self> {
246 let Value::Object(obj) = v else {
247 return None;
248 };
249 let mut b = ProductBuilder::deser_default();
250 for (k, v) in obj {
251 match k.as_str() {
252 "active" => b.active = FromValueOpt::from_value(v),
253 "created" => b.created = FromValueOpt::from_value(v),
254 "default_price" => b.default_price = FromValueOpt::from_value(v),
255 "description" => b.description = FromValueOpt::from_value(v),
256 "id" => b.id = FromValueOpt::from_value(v),
257 "images" => b.images = FromValueOpt::from_value(v),
258 "livemode" => b.livemode = FromValueOpt::from_value(v),
259 "marketing_features" => b.marketing_features = FromValueOpt::from_value(v),
260 "metadata" => b.metadata = FromValueOpt::from_value(v),
261 "name" => b.name = FromValueOpt::from_value(v),
262 "package_dimensions" => b.package_dimensions = FromValueOpt::from_value(v),
263 "shippable" => b.shippable = FromValueOpt::from_value(v),
264 "statement_descriptor" => b.statement_descriptor = FromValueOpt::from_value(v),
265 "tax_code" => b.tax_code = FromValueOpt::from_value(v),
266 "type" => b.type_ = FromValueOpt::from_value(v),
267 "unit_label" => b.unit_label = FromValueOpt::from_value(v),
268 "updated" => b.updated = FromValueOpt::from_value(v),
269 "url" => b.url = FromValueOpt::from_value(v),
270 _ => {}
271 }
272 }
273 b.take_out()
274 }
275 }
276};
277#[cfg(feature = "serialize")]
278impl serde::Serialize for Product {
279 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
280 use serde::ser::SerializeStruct;
281 let mut s = s.serialize_struct("Product", 19)?;
282 s.serialize_field("active", &self.active)?;
283 s.serialize_field("created", &self.created)?;
284 s.serialize_field("default_price", &self.default_price)?;
285 s.serialize_field("description", &self.description)?;
286 s.serialize_field("id", &self.id)?;
287 s.serialize_field("images", &self.images)?;
288 s.serialize_field("livemode", &self.livemode)?;
289 s.serialize_field("marketing_features", &self.marketing_features)?;
290 s.serialize_field("metadata", &self.metadata)?;
291 s.serialize_field("name", &self.name)?;
292 s.serialize_field("package_dimensions", &self.package_dimensions)?;
293 s.serialize_field("shippable", &self.shippable)?;
294 s.serialize_field("statement_descriptor", &self.statement_descriptor)?;
295 s.serialize_field("tax_code", &self.tax_code)?;
296 s.serialize_field("type", &self.type_)?;
297 s.serialize_field("unit_label", &self.unit_label)?;
298 s.serialize_field("updated", &self.updated)?;
299 s.serialize_field("url", &self.url)?;
300
301 s.serialize_field("object", "product")?;
302 s.end()
303 }
304}
305impl stripe_types::Object for Product {
306 type Id = stripe_shared::ProductId;
307 fn id(&self) -> &Self::Id {
308 &self.id
309 }
310
311 fn into_id(self) -> Self::Id {
312 self.id
313 }
314}
315stripe_types::def_id!(ProductId);
316#[derive(Clone, Eq, PartialEq)]
317#[non_exhaustive]
318pub enum ProductType {
319 Good,
320 Service,
321 Unknown(String),
323}
324impl ProductType {
325 pub fn as_str(&self) -> &str {
326 use ProductType::*;
327 match self {
328 Good => "good",
329 Service => "service",
330 Unknown(v) => v,
331 }
332 }
333}
334
335impl std::str::FromStr for ProductType {
336 type Err = std::convert::Infallible;
337 fn from_str(s: &str) -> Result<Self, Self::Err> {
338 use ProductType::*;
339 match s {
340 "good" => Ok(Good),
341 "service" => Ok(Service),
342 v => {
343 tracing::warn!("Unknown value '{}' for enum '{}'", v, "ProductType");
344 Ok(Unknown(v.to_owned()))
345 }
346 }
347 }
348}
349impl std::fmt::Display for ProductType {
350 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
351 f.write_str(self.as_str())
352 }
353}
354
355impl std::fmt::Debug for ProductType {
356 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
357 f.write_str(self.as_str())
358 }
359}
360impl serde::Serialize for ProductType {
361 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
362 where
363 S: serde::Serializer,
364 {
365 serializer.serialize_str(self.as_str())
366 }
367}
368impl miniserde::Deserialize for ProductType {
369 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
370 crate::Place::new(out)
371 }
372}
373
374impl miniserde::de::Visitor for crate::Place<ProductType> {
375 fn string(&mut self, s: &str) -> miniserde::Result<()> {
376 use std::str::FromStr;
377 self.out = Some(ProductType::from_str(s).expect("infallible"));
378 Ok(())
379 }
380}
381
382stripe_types::impl_from_val_with_from_str!(ProductType);
383#[cfg(feature = "deserialize")]
384impl<'de> serde::Deserialize<'de> for ProductType {
385 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
386 use std::str::FromStr;
387 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
388 Ok(Self::from_str(&s).expect("infallible"))
389 }
390}