> For the complete documentation index, see [llms.txt](https://docs.digitalriver.com/salesforce-lightning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digitalriver.com/salesforce-lightning/salesforce-lightning-b2b-commerce-app-1.2.1/extend-the-salesforce-lightning-app/tax-calculation.md).

# Tax calculation

Learn about how tax calculation works when you use the Salesforce Lightning app.

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://2621088907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiQ5A1tasgCx8G4Luajf9%2Fuploads%2FLgdAPBxZbsT54zb7fq4k%2Fimage.png?alt=media&amp;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://2621088907-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiQ5A1tasgCx8G4Luajf9%2Fuploads%2FJ1K34kMr0ZM4276on94k%2Fimage.png?alt=media&amp;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>                                                                                                                                            |
