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::{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,
292                self.refunds.take(),
293                self.shipping_cost.take(),
294                self.status,
295                self.subtotal,
296                self.subtotal_excluding_tax,
297                self.total,
298                self.total_excluding_tax,
299                self.total_taxes.take(),
300                self.type_,
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/// Status of this credit note, one of `issued` or `void`.
454/// Learn more about [voiding credit notes](https://stripe.com/docs/billing/invoices/credit-notes#voiding).
455#[derive(Copy, Clone, Eq, PartialEq)]
456pub enum CreditNoteStatus {
457    Issued,
458    Void,
459}
460impl CreditNoteStatus {
461    pub fn as_str(self) -> &'static str {
462        use CreditNoteStatus::*;
463        match self {
464            Issued => "issued",
465            Void => "void",
466        }
467    }
468}
469
470impl std::str::FromStr for CreditNoteStatus {
471    type Err = stripe_types::StripeParseError;
472    fn from_str(s: &str) -> Result<Self, Self::Err> {
473        use CreditNoteStatus::*;
474        match s {
475            "issued" => Ok(Issued),
476            "void" => Ok(Void),
477            _ => Err(stripe_types::StripeParseError),
478        }
479    }
480}
481impl std::fmt::Display for CreditNoteStatus {
482    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
483        f.write_str(self.as_str())
484    }
485}
486
487impl std::fmt::Debug for CreditNoteStatus {
488    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
489        f.write_str(self.as_str())
490    }
491}
492#[cfg(feature = "serialize")]
493impl serde::Serialize for CreditNoteStatus {
494    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
495    where
496        S: serde::Serializer,
497    {
498        serializer.serialize_str(self.as_str())
499    }
500}
501impl miniserde::Deserialize for CreditNoteStatus {
502    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
503        crate::Place::new(out)
504    }
505}
506
507impl miniserde::de::Visitor for crate::Place<CreditNoteStatus> {
508    fn string(&mut self, s: &str) -> miniserde::Result<()> {
509        use std::str::FromStr;
510        self.out = Some(CreditNoteStatus::from_str(s).map_err(|_| miniserde::Error)?);
511        Ok(())
512    }
513}
514
515stripe_types::impl_from_val_with_from_str!(CreditNoteStatus);
516#[cfg(feature = "deserialize")]
517impl<'de> serde::Deserialize<'de> for CreditNoteStatus {
518    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
519        use std::str::FromStr;
520        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
521        Self::from_str(&s)
522            .map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteStatus"))
523    }
524}
525/// Type of this credit note, one of `pre_payment` or `post_payment`.
526/// A `pre_payment` credit note means it was issued when the invoice was open.
527/// A `post_payment` credit note means it was issued when the invoice was paid.
528#[derive(Copy, Clone, Eq, PartialEq)]
529pub enum CreditNoteType {
530    Mixed,
531    PostPayment,
532    PrePayment,
533}
534impl CreditNoteType {
535    pub fn as_str(self) -> &'static str {
536        use CreditNoteType::*;
537        match self {
538            Mixed => "mixed",
539            PostPayment => "post_payment",
540            PrePayment => "pre_payment",
541        }
542    }
543}
544
545impl std::str::FromStr for CreditNoteType {
546    type Err = stripe_types::StripeParseError;
547    fn from_str(s: &str) -> Result<Self, Self::Err> {
548        use CreditNoteType::*;
549        match s {
550            "mixed" => Ok(Mixed),
551            "post_payment" => Ok(PostPayment),
552            "pre_payment" => Ok(PrePayment),
553            _ => Err(stripe_types::StripeParseError),
554        }
555    }
556}
557impl std::fmt::Display for CreditNoteType {
558    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
559        f.write_str(self.as_str())
560    }
561}
562
563impl std::fmt::Debug for CreditNoteType {
564    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
565        f.write_str(self.as_str())
566    }
567}
568#[cfg(feature = "serialize")]
569impl serde::Serialize for CreditNoteType {
570    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
571    where
572        S: serde::Serializer,
573    {
574        serializer.serialize_str(self.as_str())
575    }
576}
577impl miniserde::Deserialize for CreditNoteType {
578    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
579        crate::Place::new(out)
580    }
581}
582
583impl miniserde::de::Visitor for crate::Place<CreditNoteType> {
584    fn string(&mut self, s: &str) -> miniserde::Result<()> {
585        use std::str::FromStr;
586        self.out = Some(CreditNoteType::from_str(s).map_err(|_| miniserde::Error)?);
587        Ok(())
588    }
589}
590
591stripe_types::impl_from_val_with_from_str!(CreditNoteType);
592#[cfg(feature = "deserialize")]
593impl<'de> serde::Deserialize<'de> for CreditNoteType {
594    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
595        use std::str::FromStr;
596        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
597        Self::from_str(&s).map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteType"))
598    }
599}
600impl stripe_types::Object for CreditNote {
601    type Id = stripe_shared::CreditNoteId;
602    fn id(&self) -> &Self::Id {
603        &self.id
604    }
605
606    fn into_id(self) -> Self::Id {
607        self.id
608    }
609}
610stripe_types::def_id!(CreditNoteId);
611#[derive(Copy, Clone, Eq, PartialEq)]
612pub enum CreditNoteReason {
613    Duplicate,
614    Fraudulent,
615    OrderChange,
616    ProductUnsatisfactory,
617}
618impl CreditNoteReason {
619    pub fn as_str(self) -> &'static str {
620        use CreditNoteReason::*;
621        match self {
622            Duplicate => "duplicate",
623            Fraudulent => "fraudulent",
624            OrderChange => "order_change",
625            ProductUnsatisfactory => "product_unsatisfactory",
626        }
627    }
628}
629
630impl std::str::FromStr for CreditNoteReason {
631    type Err = stripe_types::StripeParseError;
632    fn from_str(s: &str) -> Result<Self, Self::Err> {
633        use CreditNoteReason::*;
634        match s {
635            "duplicate" => Ok(Duplicate),
636            "fraudulent" => Ok(Fraudulent),
637            "order_change" => Ok(OrderChange),
638            "product_unsatisfactory" => Ok(ProductUnsatisfactory),
639            _ => Err(stripe_types::StripeParseError),
640        }
641    }
642}
643impl std::fmt::Display for CreditNoteReason {
644    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
645        f.write_str(self.as_str())
646    }
647}
648
649impl std::fmt::Debug for CreditNoteReason {
650    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
651        f.write_str(self.as_str())
652    }
653}
654impl serde::Serialize for CreditNoteReason {
655    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
656    where
657        S: serde::Serializer,
658    {
659        serializer.serialize_str(self.as_str())
660    }
661}
662impl miniserde::Deserialize for CreditNoteReason {
663    fn begin(out: &mut Option<Self>) -> &mut dyn miniserde::de::Visitor {
664        crate::Place::new(out)
665    }
666}
667
668impl miniserde::de::Visitor for crate::Place<CreditNoteReason> {
669    fn string(&mut self, s: &str) -> miniserde::Result<()> {
670        use std::str::FromStr;
671        self.out = Some(CreditNoteReason::from_str(s).map_err(|_| miniserde::Error)?);
672        Ok(())
673    }
674}
675
676stripe_types::impl_from_val_with_from_str!(CreditNoteReason);
677#[cfg(feature = "deserialize")]
678impl<'de> serde::Deserialize<'de> for CreditNoteReason {
679    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
680        use std::str::FromStr;
681        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
682        Self::from_str(&s)
683            .map_err(|_| serde::de::Error::custom("Unknown value for CreditNoteReason"))
684    }
685}