Skip to content

Commit

Permalink
feat: add tax calculation api behind a feature
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Jun 23, 2023
1 parent f32cd8d commit 2266ed1
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 47 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ full = [
"sigma",
"terminal",
"webhook-endpoints",
"tax-calculation",
]

stream = []
Expand All @@ -56,6 +57,7 @@ orders = []
sigma = []
terminal = []
webhook-endpoints = []
tax-calculation = []

# deserialize events from webhooks
webhook-events = ["events", "hmac", "sha2", "chrono", "hex"]
Expand Down
2 changes: 2 additions & 0 deletions src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ def_id!(SubscriptionItemId, "si_");
def_id!(SubscriptionLineId, "sli_");
def_id!(SubscriptionScheduleId, "sub_sched_");
def_id!(TaxIdId, "txi_");
def_id!(TaxCalculationId: String);
def_id!(TaxCalculationLineItemId: String);
def_id!(TaxCodeId, "txcd_");
def_id!(TaxDeductedAtSourceId, "itds");
def_id!(TaxRateId, "txr_");
Expand Down
10 changes: 10 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ pub use {
},
};

#[rustfmt::skip]
#[cfg(feature = "tax-calculation")]
pub use {
generated::tax_calculation::{
tax_calculation::*,
tax_calculation_line_item::*,
tax_product_resource_customer_details::*,
}
};

#[rustfmt::skip]
#[cfg(feature = "connect")]
pub use {
Expand Down
8 changes: 8 additions & 0 deletions src/resources/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ pub mod checkout {
pub mod payment_link;
}

#[path = "generated"]
#[cfg(feature = "tax-calculation")]
pub mod tax_calculation {
pub mod tax_calculation;
pub mod tax_calculation_line_item;
pub mod tax_product_resource_customer_details;
}

#[path = "generated"]
#[cfg(feature = "billing")]
pub mod billing {
Expand Down
83 changes: 57 additions & 26 deletions src/resources/generated/tax_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// This file was automatically generated.
// ======================================

use crate::ids::{TaxCalculationId};
use serde::{Deserialize, Serialize};

use crate::ids::TaxCalculationId;
use crate::params::{List, Object, Timestamp};
use crate::resources::{Currency, TaxCalculationLineItem, TaxProductResourceCustomerDetails};
use serde::{Deserialize, Serialize};

/// The resource representing a Stripe "TaxProductResourceTaxCalculation".
///
Expand Down Expand Up @@ -65,7 +66,6 @@ impl Object for TaxCalculation {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceTaxBreakdown {

/// The amount of tax, in integer cents.
pub amount: i64,

Expand All @@ -85,7 +85,6 @@ pub struct TaxProductResourceTaxBreakdown {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceTaxCalculationShippingCost {

/// The shipping amount in integer cents.
///
/// If `tax_behavior=inclusive`, then this amount includes taxes.
Expand Down Expand Up @@ -114,7 +113,6 @@ pub struct TaxProductResourceTaxCalculationShippingCost {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceLineItemTaxBreakdown {

/// The amount of tax, in integer cents.
pub amount: i64,

Expand All @@ -139,7 +137,6 @@ pub struct TaxProductResourceLineItemTaxBreakdown {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceJurisdiction {

/// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
pub country: String,

Expand All @@ -157,7 +154,6 @@ pub struct TaxProductResourceJurisdiction {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceLineItemTaxRateDetails {

/// A localized display name for tax type, intended to be human-readable.
///
/// For example, "Local Sales and Use Tax", "Value-added tax (VAT)", or "Umsatzsteuer (USt.)".
Expand All @@ -174,7 +170,6 @@ pub struct TaxProductResourceLineItemTaxRateDetails {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceTaxRateDetails {

/// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
pub country: Option<String>,

Expand Down Expand Up @@ -288,20 +283,44 @@ pub enum TaxProductResourceLineItemTaxBreakdownTaxabilityReason {
impl TaxProductResourceLineItemTaxBreakdownTaxabilityReason {
pub fn as_str(self) -> &'static str {
match self {
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::CustomerExempt => "customer_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotCollecting => "not_collecting",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::CustomerExempt => {
"customer_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotCollecting => {
"not_collecting"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSubjectToTax => {
"not_subject_to_tax"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSupported => "not_supported",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionProductExempt => "portion_product_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionStandardRated => "portion_standard_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExempt => "product_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProportionallyRated => "proportionally_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionProductExempt => {
"portion_product_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionReducedRated => {
"portion_reduced_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionStandardRated => {
"portion_standard_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExempt => {
"product_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExemptHoliday => {
"product_exempt_holiday"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProportionallyRated => {
"proportionally_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReducedRated => "reduced_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReverseCharge => "reverse_charge",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::StandardRated => "standard_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReverseCharge => {
"reverse_charge"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::StandardRated => {
"standard_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::TaxableBasisReduced => {
"taxable_basis_reduced"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ZeroRated => "zero_rated",
}
}
Expand Down Expand Up @@ -402,16 +421,28 @@ impl TaxProductResourceTaxBreakdownTaxabilityReason {
TaxProductResourceTaxBreakdownTaxabilityReason::NotCollecting => "not_collecting",
TaxProductResourceTaxBreakdownTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
TaxProductResourceTaxBreakdownTaxabilityReason::NotSupported => "not_supported",
TaxProductResourceTaxBreakdownTaxabilityReason::PortionProductExempt => "portion_product_exempt",
TaxProductResourceTaxBreakdownTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
TaxProductResourceTaxBreakdownTaxabilityReason::PortionStandardRated => "portion_standard_rated",
TaxProductResourceTaxBreakdownTaxabilityReason::PortionProductExempt => {
"portion_product_exempt"
}
TaxProductResourceTaxBreakdownTaxabilityReason::PortionReducedRated => {
"portion_reduced_rated"
}
TaxProductResourceTaxBreakdownTaxabilityReason::PortionStandardRated => {
"portion_standard_rated"
}
TaxProductResourceTaxBreakdownTaxabilityReason::ProductExempt => "product_exempt",
TaxProductResourceTaxBreakdownTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
TaxProductResourceTaxBreakdownTaxabilityReason::ProportionallyRated => "proportionally_rated",
TaxProductResourceTaxBreakdownTaxabilityReason::ProductExemptHoliday => {
"product_exempt_holiday"
}
TaxProductResourceTaxBreakdownTaxabilityReason::ProportionallyRated => {
"proportionally_rated"
}
TaxProductResourceTaxBreakdownTaxabilityReason::ReducedRated => "reduced_rated",
TaxProductResourceTaxBreakdownTaxabilityReason::ReverseCharge => "reverse_charge",
TaxProductResourceTaxBreakdownTaxabilityReason::StandardRated => "standard_rated",
TaxProductResourceTaxBreakdownTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
TaxProductResourceTaxBreakdownTaxabilityReason::TaxableBasisReduced => {
"taxable_basis_reduced"
}
TaxProductResourceTaxBreakdownTaxabilityReason::ZeroRated => "zero_rated",
}
}
Expand Down
56 changes: 39 additions & 17 deletions src/resources/generated/tax_calculation_line_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// This file was automatically generated.
// ======================================

use crate::ids::{TaxCalculationLineItemId};
use crate::params::{Object};
use serde::{Deserialize, Serialize};

use crate::ids::TaxCalculationLineItemId;
use crate::params::Object;

/// The resource representing a Stripe "TaxProductResourceTaxCalculationLineItem".
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxCalculationLineItem {
Expand Down Expand Up @@ -59,7 +60,6 @@ impl Object for TaxCalculationLineItem {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceLineItemTaxBreakdown {

/// The amount of tax, in integer cents.
pub amount: i64,

Expand All @@ -84,7 +84,6 @@ pub struct TaxProductResourceLineItemTaxBreakdown {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceJurisdiction {

/// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
pub country: String,

Expand All @@ -102,7 +101,6 @@ pub struct TaxProductResourceJurisdiction {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceLineItemTaxRateDetails {

/// A localized display name for tax type, intended to be human-readable.
///
/// For example, "Local Sales and Use Tax", "Value-added tax (VAT)", or "Umsatzsteuer (USt.)".
Expand Down Expand Up @@ -249,20 +247,44 @@ pub enum TaxProductResourceLineItemTaxBreakdownTaxabilityReason {
impl TaxProductResourceLineItemTaxBreakdownTaxabilityReason {
pub fn as_str(self) -> &'static str {
match self {
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::CustomerExempt => "customer_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotCollecting => "not_collecting",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSubjectToTax => "not_subject_to_tax",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::CustomerExempt => {
"customer_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotCollecting => {
"not_collecting"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSubjectToTax => {
"not_subject_to_tax"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::NotSupported => "not_supported",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionProductExempt => "portion_product_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionReducedRated => "portion_reduced_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionStandardRated => "portion_standard_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExempt => "product_exempt",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExemptHoliday => "product_exempt_holiday",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProportionallyRated => "proportionally_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionProductExempt => {
"portion_product_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionReducedRated => {
"portion_reduced_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::PortionStandardRated => {
"portion_standard_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExempt => {
"product_exempt"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProductExemptHoliday => {
"product_exempt_holiday"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ProportionallyRated => {
"proportionally_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReducedRated => "reduced_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReverseCharge => "reverse_charge",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::StandardRated => "standard_rated",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::TaxableBasisReduced => "taxable_basis_reduced",
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ReverseCharge => {
"reverse_charge"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::StandardRated => {
"standard_rated"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::TaxableBasisReduced => {
"taxable_basis_reduced"
}
TaxProductResourceLineItemTaxBreakdownTaxabilityReason::ZeroRated => "zero_rated",
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize};
/// The resource representing a Stripe "TaxProductResourceCustomerDetails".
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceCustomerDetails {

/// The customer's postal address (for example, home or business location).
pub address: Option<TaxProductResourcePostalAddress>,

Expand All @@ -26,7 +25,6 @@ pub struct TaxProductResourceCustomerDetails {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourceCustomerDetailsResourceTaxId {

/// The type of the tax ID, one of `eu_vat`, `br_cnpj`, `br_cpf`, `eu_oss_vat`, `gb_vat`, `nz_gst`, `au_abn`, `au_arn`, `in_gst`, `no_vat`, `za_vat`, `ch_vat`, `mx_rfc`, `sg_uen`, `ru_inn`, `ru_kpp`, `ca_bn`, `hk_br`, `es_cif`, `tw_vat`, `th_vat`, `jp_cn`, `jp_rn`, `jp_trn`, `li_uid`, `my_itn`, `us_ein`, `kr_brn`, `ca_qst`, `ca_gst_hst`, `ca_pst_bc`, `ca_pst_mb`, `ca_pst_sk`, `my_sst`, `sg_gst`, `ae_trn`, `cl_tin`, `sa_vat`, `id_npwp`, `my_frp`, `il_vat`, `ge_vat`, `ua_vat`, `is_vat`, `bg_uic`, `hu_tin`, `si_tin`, `ke_pin`, `tr_tin`, `eg_tin`, `ph_tin`, or `unknown`.
#[serde(rename = "type")]
pub type_: TaxProductResourceCustomerDetailsResourceTaxIdType,
Expand All @@ -37,7 +35,6 @@ pub struct TaxProductResourceCustomerDetailsResourceTaxId {

#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxProductResourcePostalAddress {

/// City, district, suburb, town, or village.
pub city: Option<String>,

Expand Down Expand Up @@ -239,7 +236,9 @@ pub enum TaxProductResourceCustomerDetailsTaxabilityOverride {
impl TaxProductResourceCustomerDetailsTaxabilityOverride {
pub fn as_str(self) -> &'static str {
match self {
TaxProductResourceCustomerDetailsTaxabilityOverride::CustomerExempt => "customer_exempt",
TaxProductResourceCustomerDetailsTaxabilityOverride::CustomerExempt => {
"customer_exempt"
}
TaxProductResourceCustomerDetailsTaxabilityOverride::None => "none",
TaxProductResourceCustomerDetailsTaxabilityOverride::ReverseCharge => "reverse_charge",
}
Expand Down

0 comments on commit 2266ed1

Please sign in to comment.