use serde::{Deserialize, Serialize};
use crate::client::{Client, Response};
use crate::ids::TaxIdId;
use crate::params::{Deleted, Expand, Expandable, List, Object, Paginable, Timestamp};
use crate::resources::{Account, Application, Customer};
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxId {
pub id: TaxIdId,
#[serde(skip_serializing_if = "Option::is_none")]
pub country: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<Timestamp>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<Expandable<Customer>>,
#[serde(default)]
pub deleted: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub livemode: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<TaxIDsOwner>,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub type_: Option<TaxIdType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub verification: Option<TaxIdVerification>,
}
impl TaxId {
pub fn list(client: &Client, params: &ListTaxIds<'_>) -> Response<List<TaxId>> {
client.get_query("/tax_ids", params)
}
pub fn create(client: &Client, params: CreateTaxId<'_>) -> Response<TaxId> {
#[allow(clippy::needless_borrows_for_generic_args)]
client.post_form("/tax_ids", ¶ms)
}
pub fn retrieve(client: &Client, id: &TaxIdId, expand: &[&str]) -> Response<TaxId> {
client.get_query(&format!("/tax_ids/{}", id), Expand { expand })
}
pub fn delete(client: &Client, id: &TaxIdId) -> Response<Deleted<TaxIdId>> {
client.delete(&format!("/tax_ids/{}", id))
}
}
impl Object for TaxId {
type Id = TaxIdId;
fn id(&self) -> Self::Id {
self.id.clone()
}
fn object(&self) -> &'static str {
"tax_id"
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxIDsOwner {
#[serde(skip_serializing_if = "Option::is_none")]
pub account: Option<Expandable<Account>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub application: Option<Expandable<Application>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<Expandable<Customer>>,
#[serde(rename = "type")]
pub type_: TaxIDsOwnerType,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TaxIdVerification {
pub status: TaxIdVerificationStatus,
pub verified_address: Option<String>,
pub verified_name: Option<String>,
}
#[derive(Clone, Debug, Serialize)]
pub struct CreateTaxId<'a> {
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<CreateTaxIdOwner>,
#[serde(rename = "type")]
pub type_: TaxIdTypeFilter,
pub value: &'a str,
}
impl<'a> CreateTaxId<'a> {
pub fn new(type_: TaxIdTypeFilter, value: &'a str) -> Self {
CreateTaxId { expand: Default::default(), owner: Default::default(), type_, value }
}
}
#[derive(Clone, Debug, Serialize, Default)]
pub struct ListTaxIds<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub ending_before: Option<TaxIdId>,
#[serde(skip_serializing_if = "Expand::is_empty")]
pub expand: &'a [&'a str],
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owner: Option<ListTaxIdsOwner>,
#[serde(skip_serializing_if = "Option::is_none")]
pub starting_after: Option<TaxIdId>,
}
impl<'a> ListTaxIds<'a> {
pub fn new() -> Self {
ListTaxIds {
ending_before: Default::default(),
expand: Default::default(),
limit: Default::default(),
owner: Default::default(),
starting_after: Default::default(),
}
}
}
impl Paginable for ListTaxIds<'_> {
type O = TaxId;
fn set_last(&mut self, item: Self::O) {
self.starting_after = Some(item.id());
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CreateTaxIdOwner {
#[serde(skip_serializing_if = "Option::is_none")]
pub account: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<String>,
#[serde(rename = "type")]
pub type_: CreateTaxIdOwnerType,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ListTaxIdsOwner {
#[serde(skip_serializing_if = "Option::is_none")]
pub account: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub customer: Option<String>,
#[serde(rename = "type")]
pub type_: ListTaxIdsOwnerType,
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum CreateTaxIdOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}
impl CreateTaxIdOwnerType {
pub fn as_str(self) -> &'static str {
match self {
CreateTaxIdOwnerType::Account => "account",
CreateTaxIdOwnerType::Application => "application",
CreateTaxIdOwnerType::Customer => "customer",
CreateTaxIdOwnerType::Self_ => "self",
}
}
}
impl AsRef<str> for CreateTaxIdOwnerType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for CreateTaxIdOwnerType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for CreateTaxIdOwnerType {
fn default() -> Self {
Self::Account
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ListTaxIdsOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}
impl ListTaxIdsOwnerType {
pub fn as_str(self) -> &'static str {
match self {
ListTaxIdsOwnerType::Account => "account",
ListTaxIdsOwnerType::Application => "application",
ListTaxIdsOwnerType::Customer => "customer",
ListTaxIdsOwnerType::Self_ => "self",
}
}
}
impl AsRef<str> for ListTaxIdsOwnerType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for ListTaxIdsOwnerType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for ListTaxIdsOwnerType {
fn default() -> Self {
Self::Account
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TaxIDsOwnerType {
Account,
Application,
Customer,
#[serde(rename = "self")]
Self_,
}
impl TaxIDsOwnerType {
pub fn as_str(self) -> &'static str {
match self {
TaxIDsOwnerType::Account => "account",
TaxIDsOwnerType::Application => "application",
TaxIDsOwnerType::Customer => "customer",
TaxIDsOwnerType::Self_ => "self",
}
}
}
impl AsRef<str> for TaxIDsOwnerType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TaxIDsOwnerType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TaxIDsOwnerType {
fn default() -> Self {
Self::Account
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TaxIdType {
AdNrt,
AeTrn,
ArCuit,
AuAbn,
AuArn,
BgUic,
BoTin,
BrCnpj,
BrCpf,
CaBn,
CaGstHst,
CaPstBc,
CaPstMb,
CaPstSk,
CaQst,
ChVat,
ClTin,
CnTin,
CoNit,
CrTin,
DoRcn,
EcRuc,
EgTin,
EsCif,
EuOssVat,
EuVat,
GbVat,
GeVat,
HkBr,
HuTin,
IdNpwp,
IlVat,
InGst,
IsVat,
JpCn,
JpRn,
JpTrn,
KePin,
KrBrn,
LiUid,
MxRfc,
MyFrp,
MyItn,
MySst,
NoVat,
NzGst,
PeRuc,
PhTin,
RoTin,
RsPib,
RuInn,
RuKpp,
SaVat,
SgGst,
SgUen,
SiTin,
SvNit,
ThVat,
TrTin,
TwVat,
UaVat,
Unknown,
UsEin,
UyRuc,
VeRif,
VnTin,
ZaVat,
}
impl TaxIdType {
pub fn as_str(self) -> &'static str {
match self {
TaxIdType::AdNrt => "ad_nrt",
TaxIdType::AeTrn => "ae_trn",
TaxIdType::ArCuit => "ar_cuit",
TaxIdType::AuAbn => "au_abn",
TaxIdType::AuArn => "au_arn",
TaxIdType::BgUic => "bg_uic",
TaxIdType::BoTin => "bo_tin",
TaxIdType::BrCnpj => "br_cnpj",
TaxIdType::BrCpf => "br_cpf",
TaxIdType::CaBn => "ca_bn",
TaxIdType::CaGstHst => "ca_gst_hst",
TaxIdType::CaPstBc => "ca_pst_bc",
TaxIdType::CaPstMb => "ca_pst_mb",
TaxIdType::CaPstSk => "ca_pst_sk",
TaxIdType::CaQst => "ca_qst",
TaxIdType::ChVat => "ch_vat",
TaxIdType::ClTin => "cl_tin",
TaxIdType::CnTin => "cn_tin",
TaxIdType::CoNit => "co_nit",
TaxIdType::CrTin => "cr_tin",
TaxIdType::DoRcn => "do_rcn",
TaxIdType::EcRuc => "ec_ruc",
TaxIdType::EgTin => "eg_tin",
TaxIdType::EsCif => "es_cif",
TaxIdType::EuOssVat => "eu_oss_vat",
TaxIdType::EuVat => "eu_vat",
TaxIdType::GbVat => "gb_vat",
TaxIdType::GeVat => "ge_vat",
TaxIdType::HkBr => "hk_br",
TaxIdType::HuTin => "hu_tin",
TaxIdType::IdNpwp => "id_npwp",
TaxIdType::IlVat => "il_vat",
TaxIdType::InGst => "in_gst",
TaxIdType::IsVat => "is_vat",
TaxIdType::JpCn => "jp_cn",
TaxIdType::JpRn => "jp_rn",
TaxIdType::JpTrn => "jp_trn",
TaxIdType::KePin => "ke_pin",
TaxIdType::KrBrn => "kr_brn",
TaxIdType::LiUid => "li_uid",
TaxIdType::MxRfc => "mx_rfc",
TaxIdType::MyFrp => "my_frp",
TaxIdType::MyItn => "my_itn",
TaxIdType::MySst => "my_sst",
TaxIdType::NoVat => "no_vat",
TaxIdType::NzGst => "nz_gst",
TaxIdType::PeRuc => "pe_ruc",
TaxIdType::PhTin => "ph_tin",
TaxIdType::RoTin => "ro_tin",
TaxIdType::RsPib => "rs_pib",
TaxIdType::RuInn => "ru_inn",
TaxIdType::RuKpp => "ru_kpp",
TaxIdType::SaVat => "sa_vat",
TaxIdType::SgGst => "sg_gst",
TaxIdType::SgUen => "sg_uen",
TaxIdType::SiTin => "si_tin",
TaxIdType::SvNit => "sv_nit",
TaxIdType::ThVat => "th_vat",
TaxIdType::TrTin => "tr_tin",
TaxIdType::TwVat => "tw_vat",
TaxIdType::UaVat => "ua_vat",
TaxIdType::Unknown => "unknown",
TaxIdType::UsEin => "us_ein",
TaxIdType::UyRuc => "uy_ruc",
TaxIdType::VeRif => "ve_rif",
TaxIdType::VnTin => "vn_tin",
TaxIdType::ZaVat => "za_vat",
}
}
}
impl AsRef<str> for TaxIdType {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TaxIdType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TaxIdType {
fn default() -> Self {
Self::AdNrt
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TaxIdTypeFilter {
AdNrt,
AeTrn,
ArCuit,
AuAbn,
AuArn,
BgUic,
BoTin,
BrCnpj,
BrCpf,
CaBn,
CaGstHst,
CaPstBc,
CaPstMb,
CaPstSk,
CaQst,
ChVat,
ClTin,
CnTin,
CoNit,
CrTin,
DoRcn,
EcRuc,
EgTin,
EsCif,
EuOssVat,
EuVat,
GbVat,
GeVat,
HkBr,
HuTin,
IdNpwp,
IlVat,
InGst,
IsVat,
JpCn,
JpRn,
JpTrn,
KePin,
KrBrn,
LiUid,
MxRfc,
MyFrp,
MyItn,
MySst,
NoVat,
NzGst,
PeRuc,
PhTin,
RoTin,
RsPib,
RuInn,
RuKpp,
SaVat,
SgGst,
SgUen,
SiTin,
SvNit,
ThVat,
TrTin,
TwVat,
UaVat,
UsEin,
UyRuc,
VeRif,
VnTin,
ZaVat,
}
impl TaxIdTypeFilter {
pub fn as_str(self) -> &'static str {
match self {
TaxIdTypeFilter::AdNrt => "ad_nrt",
TaxIdTypeFilter::AeTrn => "ae_trn",
TaxIdTypeFilter::ArCuit => "ar_cuit",
TaxIdTypeFilter::AuAbn => "au_abn",
TaxIdTypeFilter::AuArn => "au_arn",
TaxIdTypeFilter::BgUic => "bg_uic",
TaxIdTypeFilter::BoTin => "bo_tin",
TaxIdTypeFilter::BrCnpj => "br_cnpj",
TaxIdTypeFilter::BrCpf => "br_cpf",
TaxIdTypeFilter::CaBn => "ca_bn",
TaxIdTypeFilter::CaGstHst => "ca_gst_hst",
TaxIdTypeFilter::CaPstBc => "ca_pst_bc",
TaxIdTypeFilter::CaPstMb => "ca_pst_mb",
TaxIdTypeFilter::CaPstSk => "ca_pst_sk",
TaxIdTypeFilter::CaQst => "ca_qst",
TaxIdTypeFilter::ChVat => "ch_vat",
TaxIdTypeFilter::ClTin => "cl_tin",
TaxIdTypeFilter::CnTin => "cn_tin",
TaxIdTypeFilter::CoNit => "co_nit",
TaxIdTypeFilter::CrTin => "cr_tin",
TaxIdTypeFilter::DoRcn => "do_rcn",
TaxIdTypeFilter::EcRuc => "ec_ruc",
TaxIdTypeFilter::EgTin => "eg_tin",
TaxIdTypeFilter::EsCif => "es_cif",
TaxIdTypeFilter::EuOssVat => "eu_oss_vat",
TaxIdTypeFilter::EuVat => "eu_vat",
TaxIdTypeFilter::GbVat => "gb_vat",
TaxIdTypeFilter::GeVat => "ge_vat",
TaxIdTypeFilter::HkBr => "hk_br",
TaxIdTypeFilter::HuTin => "hu_tin",
TaxIdTypeFilter::IdNpwp => "id_npwp",
TaxIdTypeFilter::IlVat => "il_vat",
TaxIdTypeFilter::InGst => "in_gst",
TaxIdTypeFilter::IsVat => "is_vat",
TaxIdTypeFilter::JpCn => "jp_cn",
TaxIdTypeFilter::JpRn => "jp_rn",
TaxIdTypeFilter::JpTrn => "jp_trn",
TaxIdTypeFilter::KePin => "ke_pin",
TaxIdTypeFilter::KrBrn => "kr_brn",
TaxIdTypeFilter::LiUid => "li_uid",
TaxIdTypeFilter::MxRfc => "mx_rfc",
TaxIdTypeFilter::MyFrp => "my_frp",
TaxIdTypeFilter::MyItn => "my_itn",
TaxIdTypeFilter::MySst => "my_sst",
TaxIdTypeFilter::NoVat => "no_vat",
TaxIdTypeFilter::NzGst => "nz_gst",
TaxIdTypeFilter::PeRuc => "pe_ruc",
TaxIdTypeFilter::PhTin => "ph_tin",
TaxIdTypeFilter::RoTin => "ro_tin",
TaxIdTypeFilter::RsPib => "rs_pib",
TaxIdTypeFilter::RuInn => "ru_inn",
TaxIdTypeFilter::RuKpp => "ru_kpp",
TaxIdTypeFilter::SaVat => "sa_vat",
TaxIdTypeFilter::SgGst => "sg_gst",
TaxIdTypeFilter::SgUen => "sg_uen",
TaxIdTypeFilter::SiTin => "si_tin",
TaxIdTypeFilter::SvNit => "sv_nit",
TaxIdTypeFilter::ThVat => "th_vat",
TaxIdTypeFilter::TrTin => "tr_tin",
TaxIdTypeFilter::TwVat => "tw_vat",
TaxIdTypeFilter::UaVat => "ua_vat",
TaxIdTypeFilter::UsEin => "us_ein",
TaxIdTypeFilter::UyRuc => "uy_ruc",
TaxIdTypeFilter::VeRif => "ve_rif",
TaxIdTypeFilter::VnTin => "vn_tin",
TaxIdTypeFilter::ZaVat => "za_vat",
}
}
}
impl AsRef<str> for TaxIdTypeFilter {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TaxIdTypeFilter {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TaxIdTypeFilter {
fn default() -> Self {
Self::AdNrt
}
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum TaxIdVerificationStatus {
Pending,
Unavailable,
Unverified,
Verified,
}
impl TaxIdVerificationStatus {
pub fn as_str(self) -> &'static str {
match self {
TaxIdVerificationStatus::Pending => "pending",
TaxIdVerificationStatus::Unavailable => "unavailable",
TaxIdVerificationStatus::Unverified => "unverified",
TaxIdVerificationStatus::Verified => "verified",
}
}
}
impl AsRef<str> for TaxIdVerificationStatus {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for TaxIdVerificationStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.as_str().fmt(f)
}
}
impl std::default::Default for TaxIdVerificationStatus {
fn default() -> Self {
Self::Pending
}
}