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