Stripe Tax is a paid product that automatically calculates the tax on your transactions without the need to define the rates and rules. Fees only apply after you’ve added at least one location where you’re registered to calculate and remit tax.
To start collecting tax:
- Pass automatic_tax[enabled]=true.
- Specify a tax_code for each line item or set a preset tax code in the Dashboard.
- Specify a tax_behavior for each line item or set a default tax behaviour in the Dashboard.
curl https://api.stripe.com/v1/checkout/sessions \
-u "sk_test_BQokikJOvBiI2HlWgH4olfQ2
:" \
-d "line_items[0][price_data][currency]"=usd \
-d "line_items[0][price_data][product_data][name]"=T-shirt \
-d "line_items[0][price_data][product_data][tax_code]"=txcd_99999999 \
-d "line_items[0][price_data][unit_amount]"=2000 \
-d "line_items[0][price_data][tax_behavior]"=exclusive \
-d "line_items[0][quantity]"=1 \
-d mode=payment \
-d ui_mode=custom \
-d return_url={{RETURN_URL}} \
-d "automatic_tax[enabled]"=true
Tax codes
Tax codes associate products with tax rates. Choose the tax code that best fits your product from the list of available tax codes. If a product doesn’t fit any of the specific codes, use one of the codes with “General” in its name.
Tax behaviour
The tax behaviour determines how tax is presented to the buyer. There are two options for tax behaviour:
- Exclusive: The product price doesn’t include tax. Tax is added as a separate amount.
- Inclusive: The product price includes any tax amount.
Learn more about tax behaviour.
Use useCheckout to render the tax amount in your checkout form. Understand the difference between inclusive and exclusive tax.
import React from 'react';
import {useCheckout} from '@stripe/react-stripe-js';
const CheckoutForm = () => {
const checkoutState = useCheckout();
if (checkoutState.type === 'loading') {
return (
<div>Loading...</div>
);
} else if (checkoutState.type === 'error') {
return (
<div>Error: {checkoutState.error.message}</div>
);
}
const {checkout} = checkoutState;
return (
<div>
<h2>Checkout Summary</h2>
<pre>
{JSON.stringify(checkout.lineItems, null, 2)}
</pre>
<h3>Totals</h3>
<pre>
Subtotal: {checkout.total.subtotal.amount}
{}
Tax: {checkout.total.taxExclusive.amount}
Total: {checkout.total.total.amount}
</pre>
</div>
)
};