stripe/resources/generated/
credit_note_line_item.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::ids::CreditNoteLineItemId;
6use crate::params::{Expandable, Object};
7use crate::resources::{Discount, TaxRate};
8use serde::{Deserialize, Serialize};
9
10/// The resource representing a Stripe "CreditNoteLineItem".
11///
12/// For more details see <https://stripe.com/docs/api/credit_notes/line_item>
13#[derive(Clone, Debug, Default, Deserialize, Serialize)]
14pub struct CreditNoteLineItem {
15    /// Unique identifier for the object.
16    pub id: CreditNoteLineItemId,
17
18    /// The integer amount in cents (or local equivalent) representing the gross amount being credited for this line item, excluding (exclusive) tax and discounts.
19    pub amount: i64,
20
21    /// The integer amount in cents (or local equivalent) representing the amount being credited for this line item, excluding all tax and discounts.
22    pub amount_excluding_tax: Option<i64>,
23
24    /// Description of the item being credited.
25    pub description: Option<String>,
26
27    /// The integer amount in cents (or local equivalent) representing the discount being credited for this line item.
28    pub discount_amount: i64,
29
30    /// The amount of discount calculated per discount for this line item.
31    pub discount_amounts: Vec<DiscountsResourceDiscountAmount>,
32
33    /// ID of the invoice line item being credited.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub invoice_line_item: Option<String>,
36
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
40    /// The number of units of product being credited.
41    pub quantity: Option<u64>,
42
43    /// The amount of tax calculated per tax rate for this line item.
44    pub tax_amounts: Vec<CreditNoteTaxAmount>,
45
46    /// The tax rates which apply to the line item.
47    pub tax_rates: Vec<TaxRate>,
48
49    /// The type of the credit note line item, one of `invoice_line_item` or `custom_line_item`.
50    ///
51    /// When the type is `invoice_line_item` there is an additional `invoice_line_item` property on the resource the value of which is the id of the credited line item on the invoice.
52    #[serde(rename = "type")]
53    pub type_: CreditNoteLineItemType,
54
55    /// The cost of each unit of product being credited.
56    pub unit_amount: Option<i64>,
57
58    /// Same as `unit_amount`, but contains a decimal value with at most 12 decimal places.
59    pub unit_amount_decimal: Option<String>,
60
61    /// The amount in cents (or local equivalent) representing the unit amount being credited for this line item, excluding all tax and discounts.
62    pub unit_amount_excluding_tax: Option<String>,
63}
64
65impl Object for CreditNoteLineItem {
66    type Id = CreditNoteLineItemId;
67    fn id(&self) -> Self::Id {
68        self.id.clone()
69    }
70    fn object(&self) -> &'static str {
71        "credit_note_line_item"
72    }
73}
74
75#[derive(Clone, Debug, Default, Deserialize, Serialize)]
76pub struct CreditNoteTaxAmount {
77    /// The amount, in cents (or local equivalent), of the tax.
78    pub amount: i64,
79
80    /// Whether this tax amount is inclusive or exclusive.
81    pub inclusive: bool,
82
83    /// The tax rate that was applied to get this tax amount.
84    pub tax_rate: Expandable<TaxRate>,
85
86    /// The reasoning behind this tax, for example, if the product is tax exempt.
87    ///
88    /// The possible values for this field may be extended as new tax rules are supported.
89    pub taxability_reason: Option<CreditNoteTaxAmountTaxabilityReason>,
90
91    /// The amount on which tax is calculated, in cents (or local equivalent).
92    pub taxable_amount: Option<i64>,
93}
94
95#[derive(Clone, Debug, Default, Deserialize, Serialize)]
96pub struct DiscountsResourceDiscountAmount {
97    /// The amount, in cents (or local equivalent), of the discount.
98    pub amount: i64,
99
100    /// The discount that was applied to get this discount amount.
101    pub discount: Expandable<Discount>,
102}
103
104/// An enum representing the possible values of an `CreditNoteLineItem`'s `type` field.
105#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
106#[serde(rename_all = "snake_case")]
107pub enum CreditNoteLineItemType {
108    CustomLineItem,
109    InvoiceLineItem,
110}
111
112impl CreditNoteLineItemType {
113    pub fn as_str(self) -> &'static str {
114        match self {
115            CreditNoteLineItemType::CustomLineItem => "custom_line_item",
116            CreditNoteLineItemType::InvoiceLineItem => "invoice_line_item",
117        }
118    }
119}
120
121impl AsRef<str> for CreditNoteLineItemType {
122    fn as_ref(&self) -> &str {
123        self.as_str()
124    }
125}
126
127impl std::fmt::Display for CreditNoteLineItemType {
128    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
129        self.as_str().fmt(f)
130    }
131}
132impl std::default::Default for CreditNoteLineItemType {
133    fn default() -> Self {
134        Self::CustomLineItem
135    }
136}
137
138/// An enum representing the possible values of an `CreditNoteTaxAmount`'s `taxability_reason` field.
139#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
140#[serde(rename_all = "snake_case")]
141pub enum CreditNoteTaxAmountTaxabilityReason {
142    CustomerExempt,
143    NotCollecting,
144    NotSubjectToTax,
145    NotSupported,
146    PortionProductExempt,
147    PortionReducedRated,
148    PortionStandardRated,
149    ProductExempt,
150    ProductExemptHoliday,
151    ProportionallyRated,
152    ReducedRated,
153    ReverseCharge,
154    StandardRated,
155    TaxableBasisReduced,
156    ZeroRated,
157}
158
159impl CreditNoteTaxAmountTaxabilityReason {
160    pub fn as_str(self) -> &'static str {
161        match self {
162            CreditNoteTaxAmountTaxabilityReason::CustomerExempt => "customer_exempt",
163            CreditNoteTaxAmountTaxabilityReason::NotCollecting => "not_collecting",
164            CreditNoteTaxAmountTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
165            CreditNoteTaxAmountTaxabilityReason::NotSupported => "not_supported",
166            CreditNoteTaxAmountTaxabilityReason::PortionProductExempt => "portion_product_exempt",
167            CreditNoteTaxAmountTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
168            CreditNoteTaxAmountTaxabilityReason::PortionStandardRated => "portion_standard_rated",
169            CreditNoteTaxAmountTaxabilityReason::ProductExempt => "product_exempt",
170            CreditNoteTaxAmountTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
171            CreditNoteTaxAmountTaxabilityReason::ProportionallyRated => "proportionally_rated",
172            CreditNoteTaxAmountTaxabilityReason::ReducedRated => "reduced_rated",
173            CreditNoteTaxAmountTaxabilityReason::ReverseCharge => "reverse_charge",
174            CreditNoteTaxAmountTaxabilityReason::StandardRated => "standard_rated",
175            CreditNoteTaxAmountTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
176            CreditNoteTaxAmountTaxabilityReason::ZeroRated => "zero_rated",
177        }
178    }
179}
180
181impl AsRef<str> for CreditNoteTaxAmountTaxabilityReason {
182    fn as_ref(&self) -> &str {
183        self.as_str()
184    }
185}
186
187impl std::fmt::Display for CreditNoteTaxAmountTaxabilityReason {
188    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
189        self.as_str().fmt(f)
190    }
191}
192impl std::default::Default for CreditNoteTaxAmountTaxabilityReason {
193    fn default() -> Self {
194        Self::CustomerExempt
195    }
196}