Learn how to set up and use Stripe Tax for automatic sales tax calculation, configure tax settings, handle exemptions, and manage tax reports for compliance.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
How to Use Stripe Tax for Automatic Sales Tax
Step 1: Set Up a Stripe Account
First, you need to have a Stripe account. If you don't have one yet, visit the Stripe website and sign up. Once you've created your account, navigate to the Dashboard.
Step 2: Enable Stripe Tax
To activate Stripe Tax:
You'll need to provide information about your business, including your business address and tax registration numbers for the regions where you operate.
Step 3: Configure Tax Settings
After enabling Stripe Tax, configure your tax settings:
These settings determine where and how Stripe will calculate taxes for your transactions.
Step 4: Implement Stripe Tax in Your Checkout Flow
Now you need to implement Stripe Tax in your checkout flow. Here's how to do it with Stripe Checkout:
const stripe = require('stripe')('sk_test_your_secret_key');
// Create a checkout session with automatic tax calculation
const session = await stripe.checkout.sessions.create({
line\_items: [
{
price: 'price\_1234',
quantity: 1,
},
],
mode: 'payment',
automatic\_tax: {
enabled: true,
},
customer\_email: '[email protected]',
billing_address_collection: 'required',
shipping_address_collection: {
allowed\_countries: ['US', 'CA'],
},
success\_url: 'https://example.com/success',
cancel\_url: 'https://example.com/cancel',
});
The key parameter here is automatic_tax: { enabled: true }
, which enables Stripe Tax for this session. Note that you need to collect either billing or shipping addresses to calculate taxes properly.
Step 5: Implement Stripe Tax with the Payment Element
If you're using Stripe's Payment Element for a custom checkout flow:
// Server-side code
const stripe = require('stripe')('sk_test_your_secret_key');
const paymentIntent = await stripe.paymentIntents.create({
amount: 1000,
currency: 'usd',
automatic\_tax: {
enabled: true,
},
customer: 'cus\_123456',
customer\_details: {
address: {
line1: '123 Main St',
city: 'San Francisco',
state: 'CA',
postal\_code: '94111',
country: 'US',
},
email: '[email protected]',
},
metadata: {
tax\_exempt: 'none', // or 'exempt' if customer is tax exempt
},
});
// Client-side code
const {clientSecret} = await fetch('/create-payment-intent', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
items: [{id: 'product-id'}],
customerDetails: {
address: {
line1: '123 Main St',
city: 'San Francisco',
state: 'CA',
postal\_code: '94111',
country: 'US',
},
},
}),
}).then(r => r.json());
const elements = stripe.elements({
clientSecret,
});
const paymentElement = elements.create('payment');
paymentElement.mount('#payment-element');
Step 6: Handle Tax Calculation for Subscriptions
For subscription products, enable automatic tax calculation like this:
// Create a subscription with automatic tax
const subscription = await stripe.subscriptions.create({
customer: 'cus\_123456',
items: [
{
price: 'price\_1234',
},
],
automatic\_tax: {
enabled: true,
},
payment_behavior: 'default_incomplete',
payment\_settings: {
save_default_payment_method: 'on_subscription',
},
expand: ['latest_invoice.payment_intent'],
});
Step 7: Define Product Tax Codes
Assign appropriate tax codes to your products to ensure correct tax rates:
// Create a product with a specific tax code
const product = await stripe.products.create({
name: 'T-shirt',
description: 'Comfortable cotton t-shirt',
tax_code: 'txcd_10000000', // General physical goods
});
// Create a price for the product
const price = await stripe.prices.create({
unit\_amount: 2000,
currency: 'usd',
product: product.id,
});
Common tax codes include:
Step 8: Handle Tax Exemptions
To handle tax-exempt customers:
// Update a customer to mark them as tax exempt
await stripe.customers.update(
'cus\_123456',
{
tax\_exempt: 'exempt', // Options: 'none', 'exempt', 'reverse'
tax_id_data: [
{
type: 'eu\_vat',
value: 'DE123456789',
},
],
}
);
Step 9: Test Tax Calculations
Before going live, test your tax calculations:
You can use Stripe's test clock feature to simulate subscriptions and recurring billing:
// Create a test clock
const clock = await stripe.testHelpers.testClocks.create({
frozen\_time: Math.floor(Date.now() / 1000),
});
// Create a customer on the test clock
const customer = await stripe.customers.create({
test\_clock: clock.id,
email: '[email protected]',
address: {
line1: '123 Main St',
city: 'San Francisco',
state: 'CA',
postal\_code: '94111',
country: 'US',
},
});
// Create a subscription with automatic tax on the test clock
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: 'price\_1234' }],
automatic\_tax: { enabled: true },
});
// Advance the test clock to simulate time passing
await stripe.testHelpers.testClocks.advance(
clock.id,
{ frozen\_time: Math.floor(Date.now() / 1000) + (30 _ 24 _ 60 \* 60) }
);
Step 10: Monitor and Manage Tax Reports
After implementing Stripe Tax, regularly monitor your tax reports:
You can also retrieve tax reports programmatically:
const reports = await stripe.reporting.reportRuns.create({
report\_type: 'tax.summary',
parameters: {
interval\_start: Math.floor(new Date('2023-01-01').getTime() / 1000),
interval\_end: Math.floor(new Date('2023-01-31').getTime() / 1000),
},
});
Step 11: Stay Compliant with Tax Regulations
Although Stripe Tax automates calculations, you're still responsible for tax compliance:
Stripe Tax helps with calculations but does not file taxes for you. Consider consulting with a tax professional to ensure full compliance with all applicable tax laws.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.