# Collect taxes

Calculate tax automatically in your mobile Checkout Sessions integration.

Stripe Tax automatically calculates tax on purchases when you use Mobile Checkout Elements. Add your tax registrations, configure the Checkout Session to collect tax, and render the calculated amounts from the latest session.

### Want access to Mobile Checkout Elements?

Mobile Checkout Elements is in private preview. Share your email address to request access.

```bash
curl https://docs.stripe.com/preview/register \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Referer: https://docs.stripe.com/payments/mobile/checkout-sessions/collect-taxes" \
  -d '{"email": "EMAIL", "preview": "elements_beta_preview"}'
```

# Android


## Add tax registrations [Dashboard] [Server-side]

Stripe Tax only collects tax in jurisdictions where you have an active registration. Create a [registration](https://docs.stripe.com/api/tax/registrations/create.md) for each country or state where you’re required to collect tax. The [country_options](https://docs.stripe.com/api/tax/registrations/create.md#tax_registration_create-country_options) structure varies by country.

```curl
curl https://api.stripe.com/v1/tax/registrations \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d country={{COUNTRY_CODE}} \
  -d "country_options[us][state]={{STATE}}" \
  -d "country_options[us][type]=state_sales_tax" \
  -d active_from=now
```

Alternatively, add registrations in the Dashboard. Go to the **Tax** > [Registrations](https://dashboard.stripe.com/tax/registrations). You only need to add a registration once per jurisdiction.

## Configure your Checkout Session to collect tax [Server-side]

To start collecting tax:

1. Pass [automatic_tax[enabled]=true](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-automatic_tax-enabled) when you create a Checkout Session.
2. Set [invoice_creation[enabled]](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-invoice_creation-enabled) to `true`.
3. Specify a [tax code](https://docs.stripe.com/tax/tax-codes.md) for each product, or set a preset tax code in the [Dashboard](https://dashboard.stripe.com/settings/tax).
4. Specify a [tax behavior](https://docs.stripe.com/tax/products-prices-tax-codes-tax-behavior.md) for each price, or set a default tax behavior in the [Dashboard](https://dashboard.stripe.com/settings/tax).
5. Collect the customer’s location. This example uses the shipping address and limits the countries that the customer can select.

```curl
curl https://api.stripe.com/v1/checkout/sessions \
  -u "<<YOUR_SECRET_KEY>>:" \
  -d ui_mode=mobile_elements \
  --data-urlencode "customer_email=jenny.rosen@example.com" \
  -d "shipping_address_collection[allowed_countries][0]=US" \
  -d "shipping_address_collection[allowed_countries][1]=CA" \
  -d "items[0][type]=one_time_price" \
  -d "items[0][one_time_price][items][0][price_data][currency]=usd" \
  -d "items[0][one_time_price][items][0][price_data][unit_amount]=2000" \
  -d "items[0][one_time_price][items][0][price_data][tax_behavior]=exclusive" \
  -d "items[0][one_time_price][items][0][price_data][product_data][name]=T-shirt" \
  -d "items[0][one_time_price][items][0][price_data][product_data][tax_code]=txcd_99999999" \
  -d "items[0][one_time_price][items][0][quantity]=1" \
  -d "automatic_tax[enabled]=true" \
  -d "invoice_creation[enabled]=true"
```

The tax code tells Stripe what you sell. Choose the most specific code that represents your product or service. If none of the specific codes apply, use a `General` code.

The tax behavior determines how to present tax to the customer:

- **Exclusive**: The product price doesn’t include tax. Stripe adds tax as a separate amount.
- **Inclusive**: The product price includes tax.

## Collect the customer's tax address [Client-side]

To calculate tax based off of shipping address, set the `shipping_address_collection.allowed_countries` on your Checkout Session and collect a shipping address using the Shipping Address Element or your own UI.

To use the Shipping Address Element, [set its configuration before using it](https://docs.stripe.com/payments/mobile/checkout-sessions/build-a-checkout-page.md#shipping-address).

To collect a shipping address through your own UI, call `CheckoutElementsController.updateShippingAddress()`. Always use the `Session.shippingAddress` as the source of truth for your UI.

Delegate shipping address updates to the `ViewModel` so the asynchronous call runs in `viewModelScope`:

```kotlin
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch

fun updateShippingAddress(name: String?, address: CheckoutElementsController.Address?) {
    viewModelScope.launch {
        val result = controller.updateShippingAddress(name, address)
        if (result is CheckoutElementsController.OperationResult.Failed) {
            showError(result.displayMessage)
        }
    }
}
```

When the customer saves their address, call `viewModel.updateShippingAddress(name, address)`.

To calculate tax based off of billing address, set `billing_address_collection=auto` when you create your Checkout Session. The Payment Element will automatically collect the minimum address details required for tax calculation.

If you need to collect the customer’s full billing address, set `billing_address_collection=required`.

## Render the tax amount [Client-side]

Render the totals from the latest Checkout Session whenever it changes.

```kotlin
@Composable
fun OrderTotals(controller: CheckoutElementsController) {
    val session by controller.session.collectAsState()
    val currentSession = session ?: return
    val totals = currentSession.totalSummary ?: return
    val tax = totals.taxAmounts
        .filterNot { it.inclusive }
        .sumOf { it.amount }

    Column {
        Text("Subtotal ${formatAmount(totals.subtotal, currentSession.currency)}")
        Text("Tax ${formatAmount(tax, currentSession.currency)}")
        Text("Total ${formatAmount(totals.totalDueToday, currentSession.currency)}")
    }
}
```

## Optional: Check the response

You can view the calculated tax amount for each payment as follows:

- In the Checkout Session resource, review the [total_details.amount_tax](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-total_details) property.
- In the [Dashboard](https://dashboard.stripe.com/), review the tax outcome for each payment.

