The Java SDK provides several tax-related objects, including TaxService
and TaxRateDetails
, that enable you to manage taxes. For details on taxes, see Manage sales taxes for US locales and Manage sales taxes for non-US
locales. For detailed information on tax objects, see the tax-related resources under the Name list resources of QuickBooks Online API Reference and the tax-related classes in
the Java Class Reference. The following sections describe how to use the SDK to manage taxes.
The TaxService
object provides a way to create tax codes and specify details such as tax rates to be associated with those tax codes. The following example shows how to create a TaxService
object, and then create a tax code and tax details. To see this example in context, see
TaxServiceCreate.java in the Java sample app on IntuitDeveloper. For detailed information on the TaxService
resource, see
TaxService.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | package com.intuit.developer.sampleapp.crud.entities.taxservice; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.UUID; import com.intuit.developer.sampleapp.crud.qbo.ContextFactory; import com.intuit.ipp.data.Error; import com.intuit.ipp.data.TaxRateApplicableOnEnum; import com.intuit.ipp.data.TaxRateDetails; import com.intuit.ipp.data.TaxService; import com.intuit.ipp.exception.FMSException; import com.intuit.ipp.services.GlobalTaxService; import com.intuit.ipp.util.Logger; public class TaxServiceCreate { private static final org.slf4j.Logger LOG = Logger.getLogger(); public static void main(String[] args) { try { createTaxService(); } catch (Exception e) { LOG.error("Error during CRUD", e.getCause()); } } public static void createTaxService() throws Exception { try { // Create a tax service TaxService taxservice = new TaxService(); taxservice.setTaxCode("MyTaxCode" + UUID.randomUUID()); TaxRateDetails trd = new TaxRateDetails(); trd.setRateValue(BigDecimal.ONE); trd.setTaxAgencyId("1"); // create tax agency first and use that id trd.setTaxRateName("MyTaxRate" + UUID.randomUUID()); trd.setTaxApplicableOn(TaxRateApplicableOnEnum.SALES); List<TaxRateDetails> taxRateDetails = new ArrayList<TaxRateDetails>(); taxRateDetails.add(trd); taxservice.setTaxRateDetails(taxRateDetails); GlobalTaxService taxdataservice = new GlobalTaxService(ContextFactory.getContext()); TaxService ts = taxdataservice.addTaxCode(taxservice); LOG.info("tx code id " + ts.getTaxCodeId()); } catch (FMSException e) { List<Error> list = e.getErrorList(); list.forEach(error -> LOG.error("Error while calling entity taxCode:: " + error.getMessage())); } } } |
The following example retrieves a list of existing tax rates. To see this example in context, see TaxRateQuery.java in the Java sample app on IntuitDeveloper.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package com.intuit.developer.sampleapp.crud.entities.taxrate; import java.text.ParseException; import java.util.List; import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory; import com.intuit.ipp.data.Error; import com.intuit.ipp.exception.FMSException; import com.intuit.ipp.services.DataService; import com.intuit.ipp.services.QueryResult; import com.intuit.ipp.util.Logger; public class TaxRateQuery { private static final org.slf4j.Logger LOG = Logger.getLogger(); public static void main(String[] args) { try { queryTaxRates(); } catch (Exception e) { LOG.error("Error during CRUD", e.getCause()); } } public static void queryTaxRates() throws FMSException, ParseException { try { DataService service = DataServiceFactory.getDataService(); // Get all taxrates String sql = "select * from taxrate"; QueryResult queryResult = service.executeQuery(sql); int count = queryResult.getEntities().size(); LOG.info("Total number of taxrates: " + count); } catch (FMSException e) { List<Error> list = e.getErrorList(); list.forEach(error -> LOG.error("Error while calling executeQuery :: " + error.getMessage())); } } } |
The following example retrieves a list of existing tax codes. To see this example in context, see TaxCodeQuery.java in the Java sample app on IntuitDeveloper.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package com.intuit.developer.sampleapp.crud.entities.taxcode; import java.text.ParseException; import java.util.List; import com.intuit.developer.sampleapp.crud.qbo.DataServiceFactory; import com.intuit.ipp.data.Error; import com.intuit.ipp.exception.FMSException; import com.intuit.ipp.services.DataService; import com.intuit.ipp.services.QueryResult; import com.intuit.ipp.util.Logger; public class TaxCodeQuery { private static final org.slf4j.Logger LOG = Logger.getLogger(); public static void main(String[] args) { try { queryTaxCodes(); } catch (Exception e) { LOG.error("Error during CRUD", e.getCause()); } } public static void queryTaxCodes() throws FMSException, ParseException { try { DataService service = DataServiceFactory.getDataService(); // Get all taxcodes String sql = "select * from taxcode"; QueryResult queryResult = service.executeQuery(sql); int count = queryResult.getEntities().size(); LOG.info("Total number of taxcodes: " + count); } catch (FMSException e) { List<Error> list = e.getErrorList(); list.forEach(error -> LOG.error("Error while calling executeQuery :: " + error.getMessage())); } } } |