github.com/stripe/stripe-go/v76@v76.25.0/taxrate.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import "encoding/json"
    10  
    11  // The level of the jurisdiction that imposes this tax rate. Will be `null` for manually defined tax rates.
    12  type TaxRateJurisdictionLevel string
    13  
    14  // List of values that TaxRateJurisdictionLevel can take
    15  const (
    16  	TaxRateJurisdictionLevelCity     TaxRateJurisdictionLevel = "city"
    17  	TaxRateJurisdictionLevelCountry  TaxRateJurisdictionLevel = "country"
    18  	TaxRateJurisdictionLevelCounty   TaxRateJurisdictionLevel = "county"
    19  	TaxRateJurisdictionLevelDistrict TaxRateJurisdictionLevel = "district"
    20  	TaxRateJurisdictionLevelMultiple TaxRateJurisdictionLevel = "multiple"
    21  	TaxRateJurisdictionLevelState    TaxRateJurisdictionLevel = "state"
    22  )
    23  
    24  // The high-level tax type, such as `vat` or `sales_tax`.
    25  type TaxRateTaxType string
    26  
    27  // List of values that TaxRateTaxType can take
    28  const (
    29  	TaxRateTaxTypeAmusementTax      TaxRateTaxType = "amusement_tax"
    30  	TaxRateTaxTypeCommunicationsTax TaxRateTaxType = "communications_tax"
    31  	TaxRateTaxTypeGST               TaxRateTaxType = "gst"
    32  	TaxRateTaxTypeHST               TaxRateTaxType = "hst"
    33  	TaxRateTaxTypeIGST              TaxRateTaxType = "igst"
    34  	TaxRateTaxTypeJCT               TaxRateTaxType = "jct"
    35  	TaxRateTaxTypeLeaseTax          TaxRateTaxType = "lease_tax"
    36  	TaxRateTaxTypePST               TaxRateTaxType = "pst"
    37  	TaxRateTaxTypeQST               TaxRateTaxType = "qst"
    38  	TaxRateTaxTypeRST               TaxRateTaxType = "rst"
    39  	TaxRateTaxTypeSalesTax          TaxRateTaxType = "sales_tax"
    40  	TaxRateTaxTypeVAT               TaxRateTaxType = "vat"
    41  	TaxRateTaxTypeServiceTax        TaxRateTaxType = "service_tax"
    42  )
    43  
    44  // Returns a list of your tax rates. Tax rates are returned sorted by creation date, with the most recently created tax rates appearing first.
    45  type TaxRateListParams struct {
    46  	ListParams `form:"*"`
    47  	// Optional flag to filter by tax rates that are either active or inactive (archived).
    48  	Active *bool `form:"active"`
    49  	// Optional range for filtering created date.
    50  	Created *int64 `form:"created"`
    51  	// Optional range for filtering created date.
    52  	CreatedRange *RangeQueryParams `form:"created"`
    53  	// Specifies which fields in the response should be expanded.
    54  	Expand []*string `form:"expand"`
    55  	// Optional flag to filter by tax rates that are inclusive (or those that are not inclusive).
    56  	Inclusive *bool `form:"inclusive"`
    57  }
    58  
    59  // AddExpand appends a new field to expand.
    60  func (p *TaxRateListParams) AddExpand(f string) {
    61  	p.Expand = append(p.Expand, &f)
    62  }
    63  
    64  // Creates a new tax rate.
    65  type TaxRateParams struct {
    66  	Params `form:"*"`
    67  	// Flag determining whether the tax rate is active or inactive (archived). Inactive tax rates cannot be used with new applications or Checkout Sessions, but will still work for subscriptions and invoices that already have it set.
    68  	Active *bool `form:"active"`
    69  	// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
    70  	Country *string `form:"country"`
    71  	// An arbitrary string attached to the tax rate for your internal use only. It will not be visible to your customers.
    72  	Description *string `form:"description"`
    73  	// The display name of the tax rate, which will be shown to users.
    74  	DisplayName *string `form:"display_name"`
    75  	// Specifies which fields in the response should be expanded.
    76  	Expand []*string `form:"expand"`
    77  	// This specifies if the tax rate is inclusive or exclusive.
    78  	Inclusive *bool `form:"inclusive"`
    79  	// The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. It also appears on your customer's invoice.
    80  	Jurisdiction *string `form:"jurisdiction"`
    81  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
    82  	Metadata map[string]string `form:"metadata"`
    83  	// This represents the tax rate percent out of 100.
    84  	Percentage *float64 `form:"percentage"`
    85  	// [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
    86  	State *string `form:"state"`
    87  	// The high-level tax type, such as `vat` or `sales_tax`.
    88  	TaxType *string `form:"tax_type"`
    89  }
    90  
    91  // AddExpand appends a new field to expand.
    92  func (p *TaxRateParams) AddExpand(f string) {
    93  	p.Expand = append(p.Expand, &f)
    94  }
    95  
    96  // AddMetadata adds a new key-value pair to the Metadata.
    97  func (p *TaxRateParams) AddMetadata(key string, value string) {
    98  	if p.Metadata == nil {
    99  		p.Metadata = make(map[string]string)
   100  	}
   101  
   102  	p.Metadata[key] = value
   103  }
   104  
   105  // Tax rates can be applied to [invoices](https://stripe.com/docs/billing/invoices/tax-rates), [subscriptions](https://stripe.com/docs/billing/subscriptions/taxes) and [Checkout Sessions](https://stripe.com/docs/payments/checkout/set-up-a-subscription#tax-rates) to collect tax.
   106  //
   107  // Related guide: [Tax rates](https://stripe.com/docs/billing/taxes/tax-rates)
   108  type TaxRate struct {
   109  	APIResource
   110  	// Defaults to `true`. When set to `false`, this tax rate cannot be used with new applications or Checkout Sessions, but will still work for subscriptions and invoices that already have it set.
   111  	Active bool `json:"active"`
   112  	// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
   113  	Country string `json:"country"`
   114  	// Time at which the object was created. Measured in seconds since the Unix epoch.
   115  	Created int64 `json:"created"`
   116  	// An arbitrary string attached to the tax rate for your internal use only. It will not be visible to your customers.
   117  	Description string `json:"description"`
   118  	// The display name of the tax rates as it will appear to your customer on their receipt email, PDF, and the hosted invoice page.
   119  	DisplayName string `json:"display_name"`
   120  	// Actual/effective tax rate percentage out of 100. For tax calculations with automatic_tax[enabled]=true,
   121  	// this percentage reflects the rate actually used to calculate tax based on the product's taxability
   122  	// and whether the user is registered to collect taxes in the corresponding jurisdiction.
   123  	EffectivePercentage float64 `json:"effective_percentage"`
   124  	// Unique identifier for the object.
   125  	ID string `json:"id"`
   126  	// This specifies if the tax rate is inclusive or exclusive.
   127  	Inclusive bool `json:"inclusive"`
   128  	// The jurisdiction for the tax rate. You can use this label field for tax reporting purposes. It also appears on your customer's invoice.
   129  	Jurisdiction string `json:"jurisdiction"`
   130  	// The level of the jurisdiction that imposes this tax rate. Will be `null` for manually defined tax rates.
   131  	JurisdictionLevel TaxRateJurisdictionLevel `json:"jurisdiction_level"`
   132  	// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
   133  	Livemode bool `json:"livemode"`
   134  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
   135  	Metadata map[string]string `json:"metadata"`
   136  	// String representing the object's type. Objects of the same type share the same value.
   137  	Object string `json:"object"`
   138  	// Tax rate percentage out of 100. For tax calculations with automatic_tax[enabled]=true, this percentage includes the statutory tax rate of non-taxable jurisdictions.
   139  	Percentage float64 `json:"percentage"`
   140  	// [ISO 3166-2 subdivision code](https://en.wikipedia.org/wiki/ISO_3166-2:US), without country prefix. For example, "NY" for New York, United States.
   141  	State string `json:"state"`
   142  	// The high-level tax type, such as `vat` or `sales_tax`.
   143  	TaxType TaxRateTaxType `json:"tax_type"`
   144  }
   145  
   146  // TaxRateList is a list of TaxRates as retrieved from a list endpoint.
   147  type TaxRateList struct {
   148  	APIResource
   149  	ListMeta
   150  	Data []*TaxRate `json:"data"`
   151  }
   152  
   153  // UnmarshalJSON handles deserialization of a TaxRate.
   154  // This custom unmarshaling is needed because the resulting
   155  // property may be an id or the full struct if it was expanded.
   156  func (t *TaxRate) UnmarshalJSON(data []byte) error {
   157  	if id, ok := ParseID(data); ok {
   158  		t.ID = id
   159  		return nil
   160  	}
   161  
   162  	type taxRate TaxRate
   163  	var v taxRate
   164  	if err := json.Unmarshal(data, &v); err != nil {
   165  		return err
   166  	}
   167  
   168  	*t = TaxRate(v)
   169  	return nil
   170  }