1#[derive(Clone, Debug)]
7#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
8pub struct CreditNote {
9 pub amount: i64,
11 pub amount_shipping: i64,
13 pub created: stripe_types::Timestamp,
15 pub currency: stripe_types::Currency,
18 pub customer: stripe_types::Expandable<stripe_shared::Customer>,
20 pub customer_balance_transaction:
22 Option<stripe_types::Expandable<stripe_shared::CustomerBalanceTransaction>>,
23 pub discount_amount: i64,
25 pub discount_amounts: Vec<stripe_shared::DiscountsResourceDiscountAmount>,
27 pub effective_at: Option<stripe_types::Timestamp>,
31 pub id: stripe_shared::CreditNoteId,
33 pub invoice: stripe_types::Expandable<stripe_shared::Invoice>,
35 pub lines: stripe_types::List<stripe_shared::CreditNoteLineItem>,
37 pub livemode: bool,
39 pub memo: Option<String>,
41 pub metadata: Option<std::collections::HashMap<String, String>>,
44 pub number: String,
46 pub out_of_band_amount: Option<i64>,
48 pub pdf: String,
50 pub post_payment_amount: i64,
52 pub pre_payment_amount: i64,
54 pub pretax_credit_amounts: Vec<stripe_shared::CreditNotesPretaxCreditAmount>,
56 pub reason: Option<stripe_shared::CreditNoteReason>,
58 pub refunds: Vec<stripe_shared::CreditNoteRefund>,
60 pub shipping_cost: Option<stripe_shared::InvoicesResourceShippingCost>,
62 pub status: CreditNoteStatus,
65 pub subtotal: i64,
67 pub subtotal_excluding_tax: Option<i64>,
69 pub total: i64,
71 pub total_excluding_tax: Option<i64>,
73 pub total_taxes: Option<Vec<stripe_shared::BillingBillResourceInvoicingTaxesTax>>,
75 #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
79 pub type_: CreditNoteType,
80 pub voided_at: Option<stripe_types::Timestamp>,
82}
83#[doc(hidden)]
84pub struct CreditNoteBuilder {
85 amount: Option<i64>,
86 amount_shipping: Option<i64>,
87 created: Option<stripe_types::Timestamp>,
88 currency: Option<stripe_types::Currency>,
89 customer: Option<stripe_types::Expandable<stripe_shared::Customer>>,
90 customer_balance_transaction:
91 Option<Option<stripe_types::Expandable<stripe_shared::CustomerBalanceTransaction>>>,
92 discount_amount: Option<i64>,
93 discount_amounts: Option<Vec<stripe_shared::DiscountsResourceDiscountAmount>>,
94 effective_at: Option<Option<stripe_types::Timestamp>>,
95 id: Option<stripe_shared::CreditNoteId>,
96 invoice: Option<stripe_types::Expandable<stripe_shared::Invoice>>,
97 lines: Option<stripe_types::List<stripe_shared::CreditNoteLineItem>>,
98 livemode: Option<bool>,
99 memo: Option<Option<String>>,
100 metadata: Option<Option<std::collections::HashMap<String, String>>>,
101 number: Option<String>,
102 out_of_band_amount: Option<Option<i64>>,
103 pdf: Option<String>,
104 post_payment_amount: Option<i64>,
105 pre_payment_amount: Option<i64>,
106 pretax_credit_amounts: Option<Vec<stripe_shared::CreditNotesPretaxCreditAmount>>,
107 reason: Option<Option<stripe_shared::CreditNoteReason>>,
108 refunds: Option<Vec<stripe_shared::CreditNoteRefund>>,
109 shipping_cost: Option<Option<stripe_shared::InvoicesResourceShippingCost>>,
110 status: Option<CreditNoteStatus>,
111 subtotal: Option<i64>,
112 subtotal_excluding_tax: Option<Option<i64>>,
113 total: Option<i64>,
114 total_excluding_tax: Option<Option<i64>>,
115 total_taxes: Option<Option<Vec<stripe_shared::BillingBillResourceInvoicingTaxesTax>>>,
116 type_: Option<CreditNoteType>,
117 voided_at: Option<Option<stripe_types::Timestamp>>,
118}
119
120#[allow(
121 unused_variables,
122 irrefutable_let_patterns,
123 clippy::let_unit_value,
124 clippy::match_single_binding,
125 clippy::single_match
126)]
127const _: () = {
128 use miniserde::de::{Map, Visitor};
129 use miniserde::json::Value;
130 use miniserde::{Deserialize, Result, make_place};
131 use stripe_types::miniserde_helpers::FromValueOpt;
132 use stripe_types::{MapBuilder, ObjectDeser};
133
134 make_place!(Place);
135
136 impl Deserialize for CreditNote {
137 fn begin(out: &mut Option<Self>) -> &mut dyn Visitor {
138 Place::new(out)
139 }
140 }
141
142 struct Builder<'a> {
143 out: &'a mut Option<CreditNote>,
144 builder: CreditNoteBuilder,
145 }
146
147 impl Visitor for Place<CreditNote> {
148 fn map(&mut self) -> Result<Box<dyn Map + '_>> {
149 Ok(Box::new(Builder {
150 out: &mut self.out,
151 builder: CreditNoteBuilder::deser_default(),
152 }))
153 }
154 }
155
156 impl MapBuilder for CreditNoteBuilder {
157 type Out = CreditNote;
158 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
159 Ok(match k {
160 "amount" => Deserialize::begin(&mut self.amount),
161 "amount_shipping" => Deserialize::begin(&mut self.amount_shipping),
162 "created" => Deserialize::begin(&mut self.created),
163 "currency" => Deserialize::begin(&mut self.currency),
164 "customer" => Deserialize::begin(&mut self.customer),
165 "customer_balance_transaction" => {
166 Deserialize::begin(&mut self.customer_balance_transaction)
167 }
168 "discount_amount" => Deserialize::begin(&mut self.discount_amount),
169 "discount_amounts" => Deserialize::begin(&mut self.discount_amounts),
170 "effective_at" => Deserialize::begin(&mut self.effective_at),
171 "id" => Deserialize::begin(&mut self.id),
172 "invoice" => Deserialize::begin(&mut self.invoice),
173 "lines" => Deserialize::begin(&mut self.lines),
174 "livemode" => Deserialize::begin(&mut self.livemode),
175 "memo" => Deserialize::begin(&mut self.memo),
176 "metadata" => Deserialize::begin(&mut self.metadata),
177 "number" => Deserialize::begin(&mut self.number),
178 "out_of_band_amount" => Deserialize::begin(&mut self.out_of_band_amount),
179 "pdf" => Deserialize::begin(&mut self.pdf),
180 "post_payment_amount" => Deserialize::begin(&mut self.post_payment_amount),
181 "pre_payment_amount" => Deserialize::begin(&mut self.pre_payment_amount),
182 "pretax_credit_amounts" => Deserialize::begin(&mut self.pretax_credit_amounts),
183 "reason" => Deserialize::begin(&mut self.reason),
184 "refunds" => Deserialize::begin(&mut self.refunds),
185 "shipping_cost" => Deserialize::begin(&mut self.shipping_cost),
186 "status" => Deserialize::begin(&mut self.status),
187 "subtotal" => Deserialize::begin(&mut self.subtotal),
188 "subtotal_excluding_tax" => Deserialize::begin(&mut self.subtotal_excluding_tax),
189 "total" => Deserialize::begin(&mut self.total),
190 "total_excluding_tax" => Deserialize::begin(&mut self.total_excluding_tax),
191 "total_taxes" => Deserialize::begin(&mut self.total_taxes),
192 "type" => Deserialize::begin(&mut self.type_),
193 "voided_at" => Deserialize::begin(&mut self.voided_at),
194 _ => <dyn Visitor>::ignore(),
195 })
196 }
197
198 fn deser_default() -> Self {
199 Self {
200 amount: Deserialize::default(),
201 amount_shipping: Deserialize::default(),
202 created: Deserialize::default(),
203 currency: Deserialize::default(),
204 customer: Deserialize::default(),
205 customer_balance_transaction: Deserialize::default(),
206 discount_amount: Deserialize::default(),
207 discount_amounts: Deserialize::default(),
208 effective_at: Deserialize::default(),
209 id: Deserialize::default(),
210 invoice: Deserialize::default(),
211 lines: Deserialize::default(),
212 livemode: Deserialize::default(),
213 memo: Deserialize::default(),
214 metadata: Deserialize::default(),
215 number: Deserialize::default(),
216 out_of_band_amount: Deserialize::default(),
217 pdf: Deserialize::default(),
218 post_payment_amount: Deserialize::default(),
219 pre_payment_amount: Deserialize::default(),
220 pretax_credit_amounts: Deserialize::default(),
221 reason: Deserialize::default(),
222 refunds: Deserialize::default(),
223 shipping_cost: Deserialize::default(),
224 status: Deserialize::default(),
225 subtotal: Deserialize::default(),
226 subtotal_excluding_tax: Deserialize::default(),
227 total: Deserialize::default(),
228 total_excluding_tax: Deserialize::default(),
229 total_taxes: Deserialize::default(),
230 type_: Deserialize::default(),
231 voided_at: Deserialize::default(),
232 }
233 }
234
235 fn take_out(&mut self) -> Option<Self::Out> {
236 let (
237 Some(amount),
238 Some(amount_shipping),
239 Some(created),
240 Some(currency),
241 Some(customer),
242 Some(customer_balance_transaction),
243 Some(discount_amount),
244 Some(discount_amounts),
245 Some(effective_at),
246 Some(id),
247 Some(invoice),
248 Some(lines),
249 Some(livemode),
250 Some(memo),
251 Some(metadata),
252 Some(number),
253 Some(out_of_band_amount),
254 Some(pdf),
255 Some(post_payment_amount),
256 Some(pre_payment_amount),
257 Some(pretax_credit_amounts),
258 Some(reason),
259 Some(refunds),
260 Some(shipping_cost),
261 Some(status),
262 Some(subtotal),
263 Some(subtotal_excluding_tax),
264 Some(total),
265 Some(total_excluding_tax),
266 Some(total_taxes),
267 Some(type_),
268 Some(voided_at),
269 ) = (
270 self.amount,
271 self.amount_shipping,
272 self.created,
273 self.currency.take(),
274 self.customer.take(),
275 self.customer_balance_transaction.take(),
276 self.discount_amount,
277 self.discount_amounts.take(),
278 self.effective_at,
279 self.id.take(),
280 self.invoice.take(),
281 self.lines.take(),
282 self.livemode,
283 self.memo.take(),
284 self.metadata.take(),
285 self.number.take(),
286 self.out_of_band_amount,
287 self.pdf.take(),
288 self.post_payment_amount,
289 self.pre_payment_amount,
290 self.pretax_credit_amounts.take(),
291 self.reason.take(),
292 self.refunds.take(),
293 self.shipping_cost.take(),
294 self.status.take(),
295 self.subtotal,
296 self.subtotal_excluding_tax,
297 self.total,
298 self.total_excluding_tax,
299 self.total_taxes.take(),
300 self.type_.take(),
301 self.voided_at,
302 )
303 else {
304 return None;
305 };
306 Some(Self::Out {
307 amount,
308 amount_shipping,
309 created,
310 currency,
311 customer,
312 customer_balance_transaction,
313 discount_amount,
314 discount_amounts,
315 effective_at,
316 id,
317 invoice,
318 lines,
319 livemode,
320 memo,
321 metadata,
322 number,
323 out_of_band_amount,
324 pdf,
325 post_payment_amount,
326 pre_payment_amount,
327 pretax_credit_amounts,
328 reason,
329 refunds,
330 shipping_cost,
331 status,
332 subtotal,
333 subtotal_excluding_tax,
334 total,
335 total_excluding_tax,
336 total_taxes,
337 type_,
338 voided_at,
339 })
340 }
341 }
342
343 impl Map for Builder<'_> {
344 fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
345 self.builder.key(k)
346 }
347
348 fn finish(&mut self) -> Result<()> {
349 *self.out = self.builder.take_out();
350 Ok(())
351 }
352 }
353
354 impl ObjectDeser for CreditNote {
355 type Builder = CreditNoteBuilder;
356 }
357
358 impl FromValueOpt for CreditNote {
359 fn from_value(v: Value) -> Option<Self> {
360 let Value::Object(obj) = v else {
361 return None;
362 };
363 let mut b = CreditNoteBuilder::deser_default();
364 for (k, v) in obj {
365 match k.as_str() {
366 "amount" => b.amount = FromValueOpt::from_value(v),
367 "amount_shipping" => b.amount_shipping = FromValueOpt::from_value(v),
368 "created" => b.created = FromValueOpt::from_value(v),
369 "currency" => b.currency = FromValueOpt::from_value(v),
370 "customer" => b.customer = FromValueOpt::from_value(v),
371 "customer_balance_transaction" => {
372 b.customer_balance_transaction = FromValueOpt::from_value(v)
373 }
374 "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
375 "discount_amounts" => b.discount_amounts = FromValueOpt::from_value(v),
376 "effective_at" => b.effective_at = FromValueOpt::from_value(v),
377 "id" => b.id = FromValueOpt::from_value(v),
378 "invoice" => b.invoice = FromValueOpt::from_value(v),
379 "lines" => b.lines = FromValueOpt::from_value(v),
380 "livemode" => b.livemode = FromValueOpt::from_value(v),
381 "memo" => b.memo = FromValueOpt::from_value(v),
382 "metadata" => b.metadata = FromValueOpt::from_value(v),
383 "number" => b.number = FromValueOpt::from_value(v),
384 "out_of_band_amount" => b.out_of_band_amount = FromValueOpt::from_value(v),
385 "pdf" => b.pdf = FromValueOpt::from_value(v),
386 "post_payment_amount" => b.post_payment_amount = FromValueOpt::from_value(v),
387 "pre_payment_amount" => b.pre_payment_amount = FromValueOpt::from_value(v),
388 "pretax_credit_amounts" => {
389 b.pretax_credit_amounts = FromValueOpt::from_value(v)
390 }
391 "reason" => b.reason = FromValueOpt::from_value(v),
392 "refunds" => b.refunds = FromValueOpt::from_value(v),
393 "shipping_cost" => b.shipping_cost = FromValueOpt::from_value(v),
394 "status" => b.status = FromValueOpt::from_value(v),
395 "subtotal" => b.subtotal = FromValueOpt::from_value(v),
396 "subtotal_excluding_tax" => {
397 b.subtotal_excluding_tax = FromValueOpt::from_value(v)
398 }
399 "total" => b.total = FromValueOpt::from_value(v),
400 "total_excluding_tax" => b.total_excluding_tax = FromValueOpt::from_value(v),
401 "total_taxes" => b.total_taxes = FromValueOpt::from_value(v),
402 "type" => b.type_ = FromValueOpt::from_value(v),
403 "voided_at" => b.voided_at = FromValueOpt::from_value(v),
404 _ => {}
405 }
406 }
407 b.take_out()
408 }
409 }
410};
411#[cfg(feature = "serialize")]
412impl serde::Serialize for CreditNote {
413 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
414 use serde::ser::SerializeStruct;
415 let mut s = s.serialize_struct("CreditNote", 33)?;
416 s.serialize_field("amount", &self.amount)?;
417 s.serialize_field("amount_shipping", &self.amount_shipping)?;
418 s.serialize_field("created", &self.created)?;
419 s.serialize_field("currency", &self.currency)?;
420 s.serialize_field("customer", &self.customer)?;
421 s.serialize_field("customer_balance_transaction", &self.customer_balance_transaction)?;
422 s.serialize_field("discount_amount", &self.discount_amount)?;
423 s.serialize_field("discount_amounts", &self.discount_amounts)?;
424 s.serialize_field("effective_at", &self.effective_at)?;
425 s.serialize_field("id", &self.id)?;
426 s.serialize_field("invoice", &self.invoice)?;
427 s.serialize_field("lines", &self.lines)?;
428 s.serialize_field("livemode", &self.livemode)?;
429 s.serialize_field("memo", &self.memo)?;
430 s.serialize_field("metadata", &self.metadata)?;
431 s.serialize_field("number", &self.number)?;
432 s.serialize_field("out_of_band_amount", &self.out_of_band_amount)?;
433 s.serialize_field("pdf", &self.pdf)?;
434 s.serialize_field("post_payment_amount", &self.post_payment_amount)?;
435 s.serialize_field("pre_payment_amount", &self.pre_payment_amount)?;
436 s.serialize_field("pretax_credit_amounts", &self.pretax_credit_amounts)?;
437 s.serialize_field("reason", &self.reason)?;
438 s.serialize_field("refunds", &self.refunds)?;
439 s.serialize_field("shipping_cost", &self.shipping_cost)?;
440 s.serialize_field("status", &self.status)?;
441 s.serialize_field("subtotal", &self.subtotal)?;
442 s.serialize_field("subtotal_excluding_tax", &self.subtotal_excluding_tax)?;
443 s.serialize_field("total", &self.total)?;
444 s.serialize_field("total_excluding_tax", &self.total_excluding_tax)?;
445 s.serialize_field("total_taxes", &self.total_taxes)?;
446 s.serialize_field("type", &self.type_)?;
447 s.serialize_field("voided_at", &self.voided_at)?;
448
449 s.serialize_field("object", "credit_note")?;
450 s.end()
451 }
452}
453#[derive(Clone, Eq, PartialEq)]
456#[non_exhaustive]
457pub enum CreditNoteStatus {
458 Issued,
459 Void,
460 Unknown(String),
462}
463impl CreditNoteStatus {
464 pub fn as_str(&self) -> &str {
465 use CreditNoteStatus::*;
466 match self {
467 Issued => "issued",
468 Void => "void",
469 Unknown(v) => v,
470 }
471 }
472}
473
474impl std::str::FromStr for CreditNoteStatus {
475 type Err = std::convert::Infallible;
476 fn from_str(s: &str) -> Result<Self, Self::Err> {
477 use CreditNoteStatus::*;
478 match s {
479 "issued" => Ok(Issued),
480 "void" => Ok(Void),
481 v => {
482 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreditNoteStatus");
483 Ok(Unknown(v.to_owned()))
484 }
485 }
486 }
487}
488impl std::fmt::Display for CreditNoteStatus {
489 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
490 f.write_str(self.as_str())
491 }
492}
493
494impl std::fmt::Debug for CreditNoteStatus {
495 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
496 f.write_str(self.as_str())
497 }
498}
499#[cfg(feature = "serialize")]
500impl serde::Serialize for CreditNoteStatus {
501 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
502 where
503 S: serde::Serializer,
504 {
505 serializer.serialize_str(self.as_str())
506 }
507}
508impl miniserde::Deserialize for CreditNoteStatus {
509 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
510 crate::Place::new(out)
511 }
512}
513
514impl miniserde::de::Visitor for crate::Place<CreditNoteStatus> {
515 fn string(&mut self, s: &str) -> miniserde::Result<()> {
516 use std::str::FromStr;
517 self.out = Some(CreditNoteStatus::from_str(s).expect("infallible"));
518 Ok(())
519 }
520}
521
522stripe_types::impl_from_val_with_from_str!(CreditNoteStatus);
523#[cfg(feature = "deserialize")]
524impl<'de> serde::Deserialize<'de> for CreditNoteStatus {
525 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
526 use std::str::FromStr;
527 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
528 Ok(Self::from_str(&s).expect("infallible"))
529 }
530}
531#[derive(Clone, Eq, PartialEq)]
535#[non_exhaustive]
536pub enum CreditNoteType {
537 Mixed,
538 PostPayment,
539 PrePayment,
540 Unknown(String),
542}
543impl CreditNoteType {
544 pub fn as_str(&self) -> &str {
545 use CreditNoteType::*;
546 match self {
547 Mixed => "mixed",
548 PostPayment => "post_payment",
549 PrePayment => "pre_payment",
550 Unknown(v) => v,
551 }
552 }
553}
554
555impl std::str::FromStr for CreditNoteType {
556 type Err = std::convert::Infallible;
557 fn from_str(s: &str) -> Result<Self, Self::Err> {
558 use CreditNoteType::*;
559 match s {
560 "mixed" => Ok(Mixed),
561 "post_payment" => Ok(PostPayment),
562 "pre_payment" => Ok(PrePayment),
563 v => {
564 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreditNoteType");
565 Ok(Unknown(v.to_owned()))
566 }
567 }
568 }
569}
570impl std::fmt::Display for CreditNoteType {
571 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
572 f.write_str(self.as_str())
573 }
574}
575
576impl std::fmt::Debug for CreditNoteType {
577 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
578 f.write_str(self.as_str())
579 }
580}
581#[cfg(feature = "serialize")]
582impl serde::Serialize for CreditNoteType {
583 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
584 where
585 S: serde::Serializer,
586 {
587 serializer.serialize_str(self.as_str())
588 }
589}
590impl miniserde::Deserialize for CreditNoteType {
591 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
592 crate::Place::new(out)
593 }
594}
595
596impl miniserde::de::Visitor for crate::Place<CreditNoteType> {
597 fn string(&mut self, s: &str) -> miniserde::Result<()> {
598 use std::str::FromStr;
599 self.out = Some(CreditNoteType::from_str(s).expect("infallible"));
600 Ok(())
601 }
602}
603
604stripe_types::impl_from_val_with_from_str!(CreditNoteType);
605#[cfg(feature = "deserialize")]
606impl<'de> serde::Deserialize<'de> for CreditNoteType {
607 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
608 use std::str::FromStr;
609 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
610 Ok(Self::from_str(&s).expect("infallible"))
611 }
612}
613impl stripe_types::Object for CreditNote {
614 type Id = stripe_shared::CreditNoteId;
615 fn id(&self) -> &Self::Id {
616 &self.id
617 }
618
619 fn into_id(self) -> Self::Id {
620 self.id
621 }
622}
623stripe_types::def_id!(CreditNoteId);
624#[derive(Clone, Eq, PartialEq)]
625#[non_exhaustive]
626pub enum CreditNoteReason {
627 Duplicate,
628 Fraudulent,
629 OrderChange,
630 ProductUnsatisfactory,
631 Unknown(String),
633}
634impl CreditNoteReason {
635 pub fn as_str(&self) -> &str {
636 use CreditNoteReason::*;
637 match self {
638 Duplicate => "duplicate",
639 Fraudulent => "fraudulent",
640 OrderChange => "order_change",
641 ProductUnsatisfactory => "product_unsatisfactory",
642 Unknown(v) => v,
643 }
644 }
645}
646
647impl std::str::FromStr for CreditNoteReason {
648 type Err = std::convert::Infallible;
649 fn from_str(s: &str) -> Result<Self, Self::Err> {
650 use CreditNoteReason::*;
651 match s {
652 "duplicate" => Ok(Duplicate),
653 "fraudulent" => Ok(Fraudulent),
654 "order_change" => Ok(OrderChange),
655 "product_unsatisfactory" => Ok(ProductUnsatisfactory),
656 v => {
657 tracing::warn!("Unknown value '{}' for enum '{}'", v, "CreditNoteReason");
658 Ok(Unknown(v.to_owned()))
659 }
660 }
661 }
662}
663impl std::fmt::Display for CreditNoteReason {
664 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
665 f.write_str(self.as_str())
666 }
667}
668
669impl std::fmt::Debug for CreditNoteReason {
670 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
671 f.write_str(self.as_str())
672 }
673}
674impl serde::Serialize for CreditNoteReason {
675 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
676 where
677 S: serde::Serializer,
678 {
679 serializer.serialize_str(self.as_str())
680 }
681}
682impl miniserde::Deserialize for CreditNoteReason {
683 fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
684 crate::Place::new(out)
685 }
686}
687
688impl miniserde::de::Visitor for crate::Place<CreditNoteReason> {
689 fn string(&mut self, s: &str) -> miniserde::Result<()> {
690 use std::str::FromStr;
691 self.out = Some(CreditNoteReason::from_str(s).expect("infallible"));
692 Ok(())
693 }
694}
695
696stripe_types::impl_from_val_with_from_str!(CreditNoteReason);
697#[cfg(feature = "deserialize")]
698impl<'de> serde::Deserialize<'de> for CreditNoteReason {
699 fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
700 use std::str::FromStr;
701 let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
702 Ok(Self::from_str(&s).expect("infallible"))
703 }
704}