use serde::{Deserialize, Serialize};
use crate::ids::CreditNoteLineItemId;
use crate::params::{Expandable, Object};
use crate::resources::{Discount, TaxRate};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreditNoteLineItem {
pub id: CreditNoteLineItemId,
pub amount: i64,
pub amount_excluding_tax: Option<i64>,
pub description: Option<String>,
pub discount_amount: i64,
pub discount_amounts: Vec<DiscountsResourceDiscountAmount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub invoice_line_item: Option<String>,
pub livemode: bool,
pub quantity: Option<u64>,
pub tax_amounts: Vec<CreditNoteTaxAmount>,
pub tax_rates: Vec<TaxRate>,
#[serde(rename = "type")]
pub type_: CreditNoteLineItemType,
pub unit_amount: Option<i64>,
pub unit_amount_decimal: Option<String>,
pub unit_amount_excluding_tax: Option<String>,
}
impl Object for CreditNoteLineItem {
type Id = CreditNoteLineItemId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"credit_note_line_item"
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreditNoteTaxAmount {
pub amount: i64,
pub inclusive: bool,
pub tax_rate: Expandable<TaxRate>,
pub taxability_reason: Option<CreditNoteTaxAmountTaxabilityReason>,
pub taxable_amount: Option<i64>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct DiscountsResourceDiscountAmount {
pub amount: i64,
pub discount: Expandable<Discount>,
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CreditNoteLineItemType {
CustomLineItem,
InvoiceLineItem,
}
impl CreditNoteLineItemType {
pub fn as_str(self) -> &'static str {
match self {
CreditNoteLineItemType::CustomLineItem => "custom_line_item",
CreditNoteLineItemType::InvoiceLineItem => "invoice_line_item",
}
}
}
impl AsRef<str> for CreditNoteLineItemType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for CreditNoteLineItemType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for CreditNoteLineItemType {
fn default() -> Self {
Self::CustomLineItem
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CreditNoteTaxAmountTaxabilityReason {
CustomerExempt,
NotCollecting,
NotSubjectToTax,
NotSupported,
PortionProductExempt,
PortionReducedRated,
PortionStandardRated,
ProductExempt,
ProductExemptHoliday,
ProportionallyRated,
ReducedRated,
ReverseCharge,
StandardRated,
TaxableBasisReduced,
ZeroRated,
}
impl CreditNoteTaxAmountTaxabilityReason {
pub fn as_str(self) -> &'static str {
match self {
CreditNoteTaxAmountTaxabilityReason::CustomerExempt => "customer_exempt",
CreditNoteTaxAmountTaxabilityReason::NotCollecting => "not_collecting",
CreditNoteTaxAmountTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
CreditNoteTaxAmountTaxabilityReason::NotSupported => "not_supported",
CreditNoteTaxAmountTaxabilityReason::PortionProductExempt => "portion_product_exempt",
CreditNoteTaxAmountTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
CreditNoteTaxAmountTaxabilityReason::PortionStandardRated => "portion_standard_rated",
CreditNoteTaxAmountTaxabilityReason::ProductExempt => "product_exempt",
CreditNoteTaxAmountTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
CreditNoteTaxAmountTaxabilityReason::ProportionallyRated => "proportionally_rated",
CreditNoteTaxAmountTaxabilityReason::ReducedRated => "reduced_rated",
CreditNoteTaxAmountTaxabilityReason::ReverseCharge => "reverse_charge",
CreditNoteTaxAmountTaxabilityReason::StandardRated => "standard_rated",
CreditNoteTaxAmountTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
CreditNoteTaxAmountTaxabilityReason::ZeroRated => "zero_rated",
}
}
}
impl AsRef<str> for CreditNoteTaxAmountTaxabilityReason {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for CreditNoteTaxAmountTaxabilityReason {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for CreditNoteTaxAmountTaxabilityReason {
fn default() -> Self {
Self::CustomerExempt
}
}