stripe_shared/
credit_note.rs

1/// Issue a credit note to adjust an invoice's amount after the invoice is finalized.
2///
3/// Related guide: [Credit notes](https://stripe.com/docs/billing/invoices/credit-notes)
4///
5/// For more details see <<https://stripe.com/docs/api/credit_notes/object>>.
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))]
8pub struct CreditNote {
9    /// The integer amount in cents (or local equivalent) representing the total amount of the credit note, including tax.
10    pub amount: i64,
11    /// This is the sum of all the shipping amounts.
12    pub amount_shipping: i64,
13    /// Time at which the object was created. Measured in seconds since the Unix epoch.
14    pub created: stripe_types::Timestamp,
15    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
16    /// Must be a [supported currency](https://stripe.com/docs/currencies).
17    pub currency: stripe_types::Currency,
18    /// ID of the customer.
19    pub customer: stripe_types::Expandable<stripe_shared::Customer>,
20    /// Customer balance transaction related to this credit note.
21    pub customer_balance_transaction:
22        Option<stripe_types::Expandable<stripe_shared::CustomerBalanceTransaction>>,
23    /// The integer amount in cents (or local equivalent) representing the total amount of discount that was credited.
24    pub discount_amount: i64,
25    /// The aggregate amounts calculated per discount for all line items.
26    pub discount_amounts: Vec<stripe_shared::DiscountsResourceDiscountAmount>,
27    /// The date when this credit note is in effect.
28    /// Same as `created` unless overwritten.
29    /// When defined, this value replaces the system-generated 'Date of issue' printed on the credit note PDF.
30    pub effective_at: Option<stripe_types::Timestamp>,
31    /// Unique identifier for the object.
32    pub id: stripe_shared::CreditNoteId,
33    /// ID of the invoice.
34    pub invoice: stripe_types::Expandable<stripe_shared::Invoice>,
35    /// Line items that make up the credit note
36    pub lines: stripe_types::List<stripe_shared::CreditNoteLineItem>,
37    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
38    pub livemode: bool,
39    /// Customer-facing text that appears on the credit note PDF.
40    pub memo: Option<String>,
41    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
42    /// This can be useful for storing additional information about the object in a structured format.
43    pub metadata: Option<std::collections::HashMap<String, String>>,
44    /// A unique number that identifies this particular credit note and appears on the PDF of the credit note and its associated invoice.
45    pub number: String,
46    /// Amount that was credited outside of Stripe.
47    pub out_of_band_amount: Option<i64>,
48    /// The link to download the PDF of the credit note.
49    pub pdf: String,
50    /// The amount of the credit note that was refunded to the customer, credited to the customer's balance, credited outside of Stripe, or any combination thereof.
51    pub post_payment_amount: i64,
52    /// The amount of the credit note by which the invoice's `amount_remaining` and `amount_due` were reduced.
53    pub pre_payment_amount: i64,
54    /// The pretax credit amounts (ex: discount, credit grants, etc) for all line items.
55    pub pretax_credit_amounts: Vec<stripe_shared::CreditNotesPretaxCreditAmount>,
56    /// Reason for issuing this credit note, one of `duplicate`, `fraudulent`, `order_change`, or `product_unsatisfactory`.
57    pub reason: Option<stripe_shared::CreditNoteReason>,
58    /// Refunds related to this credit note.
59    pub refunds: Vec<stripe_shared::CreditNoteRefund>,
60    /// The details of the cost of shipping, including the ShippingRate applied to the invoice.
61    pub shipping_cost: Option<stripe_shared::InvoicesResourceShippingCost>,
62    /// Status of this credit note, one of `issued` or `void`.
63    /// Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
64    pub status: CreditNoteStatus,
65    /// The integer amount in cents (or local equivalent) representing the amount of the credit note, excluding exclusive tax and invoice level discounts.
66    pub subtotal: i64,
67    /// The integer amount in cents (or local equivalent) representing the amount of the credit note, excluding all tax and invoice level discounts.
68    pub subtotal_excluding_tax: Option<i64>,
69    /// The integer amount in cents (or local equivalent) representing the total amount of the credit note, including tax and all discount.
70    pub total: i64,
71    /// The integer amount in cents (or local equivalent) representing the total amount of the credit note, excluding tax, but including discounts.
72    pub total_excluding_tax: Option<i64>,
73    /// The aggregate tax information for all line items.
74    pub total_taxes: Option<Vec<stripe_shared::BillingBillResourceInvoicingTaxesTax>>,
75    /// Type of this credit note, one of `pre_payment` or `post_payment`.
76    /// A `pre_payment` credit note means it was issued when the invoice was open.
77    /// A `post_payment` credit note means it was issued when the invoice was paid.
78    #[cfg_attr(feature = "deserialize", serde(rename = "type"))]
79    pub type_: CreditNoteType,
80    /// The time that the credit note was voided.
81    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::{make_place, Deserialize, Result};
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
195                _ => <dyn Visitor>::ignore(),
196            })
197        }
198
199        fn deser_default() -> Self {
200            Self {
201                amount: Deserialize::default(),
202                amount_shipping: Deserialize::default(),
203                created: Deserialize::default(),
204                currency: Deserialize::default(),
205                customer: Deserialize::default(),
206                customer_balance_transaction: Deserialize::default(),
207                discount_amount: Deserialize::default(),
208                discount_amounts: Deserialize::default(),
209                effective_at: Deserialize::default(),
210                id: Deserialize::default(),
211                invoice: Deserialize::default(),
212                lines: Deserialize::default(),
213                livemode: Deserialize::default(),
214                memo: Deserialize::default(),
215                metadata: Deserialize::default(),
216                number: Deserialize::default(),
217                out_of_band_amount: Deserialize::default(),
218                pdf: Deserialize::default(),
219                post_payment_amount: Deserialize::default(),
220                pre_payment_amount: Deserialize::default(),
221                pretax_credit_amounts: Deserialize::default(),
222                reason: Deserialize::default(),
223                refunds: Deserialize::default(),
224                shipping_cost: Deserialize::default(),
225                status: Deserialize::default(),
226                subtotal: Deserialize::default(),
227                subtotal_excluding_tax: Deserialize::default(),
228                total: Deserialize::default(),
229                total_excluding_tax: Deserialize::default(),
230                total_taxes: Deserialize::default(),
231                type_: Deserialize::default(),
232                voided_at: Deserialize::default(),
233            }
234        }
235
236        fn take_out(&mut self) -> Option<Self::Out> {
237            let (
238                Some(amount),
239                Some(amount_shipping),
240                Some(created),
241                Some(currency),
242                Some(customer),
243                Some(customer_balance_transaction),
244                Some(discount_amount),
245                Some(discount_amounts),
246                Some(effective_at),
247                Some(id),
248                Some(invoice),
249                Some(lines),
250                Some(livemode),
251                Some(memo),
252                Some(metadata),
253                Some(number),
254                Some(out_of_band_amount),
255                Some(pdf),
256                Some(post_payment_amount),
257                Some(pre_payment_amount),
258                Some(pretax_credit_amounts),
259                Some(reason),
260                Some(refunds),
261                Some(shipping_cost),
262                Some(status),
263                Some(subtotal),
264                Some(subtotal_excluding_tax),
265                Some(total),
266                Some(total_excluding_tax),
267                Some(total_taxes),
268                Some(type_),
269                Some(voided_at),
270            ) = (
271                self.amount,
272                self.amount_shipping,
273                self.created,
274                self.currency.take(),
275                self.customer.take(),
276                self.customer_balance_transaction.take(),
277                self.discount_amount,
278                self.discount_amounts.take(),
279                self.effective_at,
280                self.id.take(),
281                self.invoice.take(),
282                self.lines.take(),
283                self.livemode,
284                self.memo.take(),
285                self.metadata.take(),
286                self.number.take(),
287                self.out_of_band_amount,
288                self.pdf.take(),
289                self.post_payment_amount,
290                self.pre_payment_amount,
291                self.pretax_credit_amounts.take(),
292                self.reason,
293                self.refunds.take(),
294                self.shipping_cost.take(),
295                self.status,
296                self.subtotal,
297                self.subtotal_excluding_tax,
298                self.total,
299                self.total_excluding_tax,
300                self.total_taxes.take(),
301                self.type_,
302                self.voided_at,
303            )
304            else {
305                return None;
306            };
307            Some(Self::Out {
308                amount,
309                amount_shipping,
310                created,
311                currency,
312                customer,
313                customer_balance_transaction,
314                discount_amount,
315                discount_amounts,
316                effective_at,
317                id,
318                invoice,
319                lines,
320                livemode,
321                memo,
322                metadata,
323                number,
324                out_of_band_amount,
325                pdf,
326                post_payment_amount,
327                pre_payment_amount,
328                pretax_credit_amounts,
329                reason,
330                refunds,
331                shipping_cost,
332                status,
333                subtotal,
334                subtotal_excluding_tax,
335                total,
336                total_excluding_tax,
337                total_taxes,
338                type_,
339                voided_at,
340            })
341        }
342    }
343
344    impl Map for Builder<'_> {
345        fn key(&mut self, k: &str) -> Result<&mut dyn Visitor> {
346            self.builder.key(k)
347        }
348
349        fn finish(&mut self) -> Result<()> {
350            *self.out = self.builder.take_out();
351            Ok(())
352        }
353    }
354
355    impl ObjectDeser for CreditNote {
356        type Builder = CreditNoteBuilder;
357    }
358
359    impl FromValueOpt for CreditNote {
360        fn from_value(v: Value) -> Option<Self> {
361            let Value::Object(obj) = v else {
362                return None;
363            };
364            let mut b = CreditNoteBuilder::deser_default();
365            for (k, v) in obj {
366                match k.as_str() {
367                    "amount" => b.amount = FromValueOpt::from_value(v),
368                    "amount_shipping" => b.amount_shipping = FromValueOpt::from_value(v),
369                    "created" => b.created = FromValueOpt::from_value(v),
370                    "currency" => b.currency = FromValueOpt::from_value(v),
371                    "customer" => b.customer = FromValueOpt::from_value(v),
372                    "customer_balance_transaction" => {
373                        b.customer_balance_transaction = FromValueOpt::from_value(v)
374                    }
375                    "discount_amount" => b.discount_amount = FromValueOpt::from_value(v),
376                    "discount_amounts" => b.discount_amounts = FromValueOpt::from_value(v),
377                    "effective_at" => b.effective_at = FromValueOpt::from_value(v),
378                    "id" => b.id = FromValueOpt::from_value(v),
379                    "invoice" => b.invoice = FromValueOpt::from_value(v),
380                    "lines" => b.lines = FromValueOpt::from_value(v),
381                    "livemode" => b.livemode = FromValueOpt::from_value(v),
382                    "memo" => b.memo = FromValueOpt::from_value(v),
383                    "metadata" => b.metadata = FromValueOpt::from_value(v),
384                    "number" => b.number = FromValueOpt::from_value(v),
385                    "out_of_band_amount" => b.out_of_band_amount = FromValueOpt::from_value(v),
386                    "pdf" => b.pdf = FromValueOpt::from_value(v),
387                    "post_payment_amount" => b.post_payment_amount = FromValueOpt::from_value(v),
388                    "pre_payment_amount" => b.pre_payment_amount = FromValueOpt::from_value(v),
389                    "pretax_credit_amounts" => {
390                        b.pretax_credit_amounts = FromValueOpt::from_value(v)
391                    }
392                    "reason" => b.reason = FromValueOpt::from_value(v),
393                    "refunds" => b.refunds = FromValueOpt::from_value(v),
394                    "shipping_cost" => b.shipping_cost = FromValueOpt::from_value(v),
395                    "status" => b.status = FromValueOpt::from_value(v),
396                    "subtotal" => b.subtotal = FromValueOpt::from_value(v),
397                    "subtotal_excluding_tax" => {
398                        b.subtotal_excluding_tax = FromValueOpt::from_value(v)
399                    }
400                    "total" => b.total = FromValueOpt::from_value(v),
401                    "total_excluding_tax" => b.total_excluding_tax = FromValueOpt::from_value(v),
402                    "total_taxes" => b.total_taxes = FromValueOpt::from_value(v),
403                    "type" => b.type_ = FromValueOpt::from_value(v),
404                    "voided_at" => b.voided_at = FromValueOpt::from_value(v),
405
406                    _ => {}
407                }
408            }
409            b.take_out()
410        }
411    }
412};
413#[cfg(feature = "serialize")]
414impl serde::Serialize for CreditNote {
415    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
416        use serde::ser::SerializeStruct;
417        let mut s = s.serialize_struct("CreditNote", 33)?;
418        s.serialize_field("amount", &self.amount)?;
419        s.serialize_field("amount_shipping", &self.amount_shipping)?;
420        s.serialize_field("created", &self.created)?;
421        s.serialize_field("currency", &self.currency)?;
422        s.serialize_field("customer", &self.customer)?;
423        s.serialize_field("customer_balance_transaction", &self.customer_balance_transaction)?;
424        s.serialize_field("discount_amount", &self.discount_amount)?;
425        s.serialize_field("discount_amounts", &self.discount_amounts)?;
426        s.serialize_field("effective_at", &self.effective_at)?;
427        s.serialize_field("id", &self.id)?;
428        s.serialize_field("invoice", &self.invoice)?;
429        s.serialize_field("lines", &self.lines)?;
430        s.serialize_field("livemode", &self.livemode)?;
431        s.serialize_field("memo", &self.memo)?;
432        s.serialize_field("metadata", &self.metadata)?;
433        s.serialize_field("number", &self.number)?;
434        s.serialize_field("out_of_band_amount", &self.out_of_band_amount)?;
435        s.serialize_field("pdf", &self.pdf)?;
436        s.serialize_field("post_payment_amount", &self.post_payment_amount)?;
437        s.serialize_field("pre_payment_amount", &self.pre_payment_amount)?;
438        s.serialize_field("pretax_credit_amounts", &self.pretax_credit_amounts)?;
439        s.serialize_field("reason", &self.reason)?;
440        s.serialize_field("refunds", &self.refunds)?;
441        s.serialize_field("shipping_cost", &self.shipping_cost)?;
442        s.serialize_field("status", &self.status)?;
443        s.serialize_field("subtotal", &self.subtotal)?;
444        s.serialize_field("subtotal_excluding_tax", &self.subtotal_excluding_tax)?;
445        s.serialize_field("total", &self.total)?;
446        s.serialize_field("total_excluding_tax", &self.total_excluding_tax)?;
447        s.serialize_field("total_taxes", &self.total_taxes)?;
448        s.serialize_field("type", &self.type_)?;
449        s.serialize_field("voided_at", &self.voided_at)?;
450
451        s.serialize_field("object", "credit_note")?;
452        s.end()
453    }
454}
455/// Status of this credit note, one of `issued` or `void`.
456/// Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
457#[derive(Copy, Clone, Eq, PartialEq)]
458pub enum CreditNoteStatus {
459    Issued,
460    Void,
461}
462impl CreditNoteStatus {
463    pub fn as_str(self) -> &'static str {
464        use CreditNoteStatus::*;
465        match self {
466            Issued => "issued",
467            Void => "void",
468        }
469    }
470}
471
472impl std::str::FromStr for CreditNoteStatus {
473    type Err = stripe_types::StripeParseError;
474    fn from_str(s: &str) -> Result<Self, Self::Err> {
475        use CreditNoteStatus::*;
476        match s {
477            "issued" => Ok(Issued),
478            "void" => Ok(Void),
479            _ => Err(stripe_types::StripeParseError),
480        }
481    }
482}
483impl std::fmt::Display for CreditNoteStatus {
484    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
485        f.write_str(self.as_str())
486    }
487}
488
489impl std::fmt::Debug for CreditNoteStatus {
490    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
491        f.write_str(self.as_str())
492    }
493}
494#[cfg(feature = "serialize")]
495impl serde::Serialize for CreditNoteStatus {
496    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
497    where
498        S: serde::Serializer,
499    {
500        serializer.serialize_str(self.as_str())
501    }
502}
503impl miniserde::Deserialize for CreditNoteStatus {
504    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
505        crate::Place::new(out)
506    }
507}
508
509impl miniserde::de::Visitor for crate::Place<CreditNoteStatus> {
510    fn string(&mut self, s: &str) -> miniserde::Result<()> {
511        use std::str::FromStr;
512        self.out = Some(CreditNoteStatus::from_str(s).map_err(|_| miniserde::Error)?);
513        Ok(())
514    }
515}
516
517stripe_types::impl_from_val_with_from_str!(CreditNoteStatus);
518#[cfg(feature = "deserialize")]
519impl<'de> serde::Deserialize<'de> for CreditNoteStatus {
520    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
521        use std::str::FromStr;
522        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
523        Self::from_str(&s)
524            .map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteStatus"))
525    }
526}
527/// Type of this credit note, one of `pre_payment` or `post_payment`.
528/// A `pre_payment` credit note means it was issued when the invoice was open.
529/// A `post_payment` credit note means it was issued when the invoice was paid.
530#[derive(Copy, Clone, Eq, PartialEq)]
531pub enum CreditNoteType {
532    Mixed,
533    PostPayment,
534    PrePayment,
535}
536impl CreditNoteType {
537    pub fn as_str(self) -> &'static str {
538        use CreditNoteType::*;
539        match self {
540            Mixed => "mixed",
541            PostPayment => "post_payment",
542            PrePayment => "pre_payment",
543        }
544    }
545}
546
547impl std::str::FromStr for CreditNoteType {
548    type Err = stripe_types::StripeParseError;
549    fn from_str(s: &str) -> Result<Self, Self::Err> {
550        use CreditNoteType::*;
551        match s {
552            "mixed" => Ok(Mixed),
553            "post_payment" => Ok(PostPayment),
554            "pre_payment" => Ok(PrePayment),
555            _ => Err(stripe_types::StripeParseError),
556        }
557    }
558}
559impl std::fmt::Display for CreditNoteType {
560    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
561        f.write_str(self.as_str())
562    }
563}
564
565impl std::fmt::Debug for CreditNoteType {
566    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
567        f.write_str(self.as_str())
568    }
569}
570#[cfg(feature = "serialize")]
571impl serde::Serialize for CreditNoteType {
572    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
573    where
574        S: serde::Serializer,
575    {
576        serializer.serialize_str(self.as_str())
577    }
578}
579impl miniserde::Deserialize for CreditNoteType {
580    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
581        crate::Place::new(out)
582    }
583}
584
585impl miniserde::de::Visitor for crate::Place<CreditNoteType> {
586    fn string(&mut self, s: &str) -> miniserde::Result<()> {
587        use std::str::FromStr;
588        self.out = Some(CreditNoteType::from_str(s).map_err(|_| miniserde::Error)?);
589        Ok(())
590    }
591}
592
593stripe_types::impl_from_val_with_from_str!(CreditNoteType);
594#[cfg(feature = "deserialize")]
595impl<'de> serde::Deserialize<'de> for CreditNoteType {
596    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
597        use std::str::FromStr;
598        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
599        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteType"))
600    }
601}
602impl stripe_types::Object for CreditNote {
603    type Id = stripe_shared::CreditNoteId;
604    fn id(&self) -> &Self::Id {
605        &self.id
606    }
607
608    fn into_id(self) -> Self::Id {
609        self.id
610    }
611}
612stripe_types::def_id!(CreditNoteId);
613#[derive(Copy, Clone, Eq, PartialEq)]
614pub enum CreditNoteReason {
615    Duplicate,
616    Fraudulent,
617    OrderChange,
618    ProductUnsatisfactory,
619}
620impl CreditNoteReason {
621    pub fn as_str(self) -> &'static str {
622        use CreditNoteReason::*;
623        match self {
624            Duplicate => "duplicate",
625            Fraudulent => "fraudulent",
626            OrderChange => "order_change",
627            ProductUnsatisfactory => "product_unsatisfactory",
628        }
629    }
630}
631
632impl std::str::FromStr for CreditNoteReason {
633    type Err = stripe_types::StripeParseError;
634    fn from_str(s: &str) -> Result<Self, Self::Err> {
635        use CreditNoteReason::*;
636        match s {
637            "duplicate" => Ok(Duplicate),
638            "fraudulent" => Ok(Fraudulent),
639            "order_change" => Ok(OrderChange),
640            "product_unsatisfactory" => Ok(ProductUnsatisfactory),
641            _ => Err(stripe_types::StripeParseError),
642        }
643    }
644}
645impl std::fmt::Display for CreditNoteReason {
646    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
647        f.write_str(self.as_str())
648    }
649}
650
651impl std::fmt::Debug for CreditNoteReason {
652    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
653        f.write_str(self.as_str())
654    }
655}
656impl serde::Serialize for CreditNoteReason {
657    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
658    where
659        S: serde::Serializer,
660    {
661        serializer.serialize_str(self.as_str())
662    }
663}
664impl miniserde::Deserialize for CreditNoteReason {
665    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
666        crate::Place::new(out)
667    }
668}
669
670impl miniserde::de::Visitor for crate::Place<CreditNoteReason> {
671    fn string(&mut self, s: &str) -> miniserde::Result<()> {
672        use std::str::FromStr;
673        self.out = Some(CreditNoteReason::from_str(s).map_err(|_| miniserde::Error)?);
674        Ok(())
675    }
676}
677
678stripe_types::impl_from_val_with_from_str!(CreditNoteReason);
679#[cfg(feature = "deserialize")]
680impl<'de> serde::Deserialize<'de> for CreditNoteReason {
681    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
682        use std::str::FromStr;
683        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
684        Self::from_str(&s)
685            .map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteReason"))
686    }
687}