Skip to main content

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