# Tax calculation

Tax calculation in the Salesforce Lightning app is segregated into two separate layers. The inner layer, the `DRB2B_CartTaxCalculations` class, contains both the API connector and messaging functionality.&#x20;

Use the outer layer, `DRB2B_TaxCalculationService` class, as a global service that can be used as a stand-alone integration. This service has a `startCartProcessAsync`method which takes `CartId (id)`and `sfdc_checkout.IntegrationInfo` which returns a `ResponseModel`custom apex object.&#x20;

After making the API call to Digital River, the service uses the checkout service to store the response in the `CartTax` object. The `DRB2B_TaxCalculationService` service is used in both synchronous and asynchronous checkout flows.

Refer to the following example to understand how to use tax calculation in an the asynchronous checkout context:

<figure><img src="https://2681600133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFDmrn2Xgg8KN7ITpu9Nw%2Fuploads%2FTSKZ0E1NhWRi6XY4RnQF%2Fimage.png?alt=media&#x26;token=668d3999-2458-4098-a769-c7ff4a530e0a" alt=""><figcaption></figcaption></figure>

As an alternative to the previous example, you can call the tax calculation routine yourself. Refer to the following example to understand how the service can be called in a stand-alone use case:

<figure><img src="https://2681600133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFDmrn2Xgg8KN7ITpu9Nw%2Fuploads%2FzVdY9AoICLYUTPo32fIj%2Fimage.png?alt=media&#x26;token=b57978f1-18f5-45bb-ae90-b9db60811d50" alt=""><figcaption></figcaption></figure>

The following table provides details on the input parameters used in tax calculations:

| Input variable name | Description                                                                                                                                                                                                                             |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cartId              | <p>Type: Id</p><p></p><p>Identifies the cart in the checkout session.</p>                                                                                                                                                               |
| jobInfo             | <p>Type: <code>sfdc\_checkout.IntegrationInfo</code></p><p></p><p>Used in cases of an asynchronous checkout process used to load exceptions and related messages into a session. This can be NULL when used as stand-alone process.</p> |

The following table provides information on the output parameters used in tax calculations:

| Variable name         | Description                                                                                                                                                                                                                                            |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ResponseModel.status  | <p>Type: String</p><p></p><p>Possible values:<br></p><p>“Error” – This is passed when an exception or validation error occurs because the tax calculation cannot completed.<br></p><p>“Success” – This is passed when tax calculation was success.</p> |
| ResponseModel.message | <p>Type: String</p><p></p><p>Provides the response string message passed on when there is an exception.</p>                                                                                                                                            |
