To create a tax, you must perform the following:
- Get the orders manager.
Get an instance of the OrdersManager object.
- Create a new tax.
To create a new tax class, call the CreateTax method of the manager.
- Set the properties of the
In this example the following properties are set:
Gets or sets the display name of the department.
Gets or sets the default rate for the tax.
Gets or sets the country that the tax is associated with.Note that if the value of this property is "United States", you have to set the State property as well.
NOTE: You can additionally narrow the location for the Tax by using the optional City, County, FromZip, and ToZip properties. Regarding the ZIP related properties, you can use either only the FromZip property for a single ZIP number (default behavior), or to use both of them for a range of ZIP numbers. To do the latter, you must set the UseZipRange property to true. All of these properties should be used only when the Country property is set to "United States".
Gets or sets the address type the tax is applied to. You can choose between AddressType.Shipping and AddresType.Billing.
Indicates whether the tax is applied to the shipping.
- Specify rate values for each available tax class.
To do this, perform the following:
- Create a List of TaxClassRate objects.
- Create the standard rate item.
Create an instance of the TaxClassRate class. Set its Id property to Guid.Empty. Then set its Name property to “standardrate”. Set the Rate and the TaxExempt properties to the desired values. Finally add the standard rate item to the list.
- Create a TaxClassRate item for each available tax class.
First, get all the available tax classes. Then iterate through them and create an instance of the TaxClassRate for each item. Set the Id and the Name properties of the TaxClassRate instance to the values of the Id and Title properties of the TaxClass instance. Add each of the TaxClassRate instances to the list.
- Serialize the List of TaxClassRate objects.
- Set the tax class rates.
Set the serialized string to the TaxRates property of the Tax instance. You can access the tax class rates as a collection through the TaxRateCollection property of the Tax instance. Note that you can only modify the collection by modifying the string value of the TaxRates property. For more information, see For developers: Set the tax class rates.
- Save the changes.
To save the changes, call the SaveChanges method of the orders manager.
Use the following code sample: