Tax API for Sales Tax, GST, and VAT
Use Stripe Tax APIs to implement tax calculations in your custom integration.
Note
This guide describes how to integrate Stripe Tax with a custom payment flow, such as PaymentIntents. You can also integrate Stripe Tax with Payment Links, Checkout, Billing and Invoicing with no or low code setups.
Beta
To streamline your integration of Stripe tax with Payment Intents, refer to Calculate tax in your custom payment flows. Sign up here.
Stripe Tax APIs enable you to calculate tax in custom payment flows. After your customer completes their payment, record the transaction so it appears in Stripe Tax reporting. The examples in this guide use Stripe payments APIs, but you can use the Tax API with any payment processor, or multiple payment processors.
Get started with a video demo
This short video walks through a Stripe Tax API integration that uses PaymentIntents and the Payment Element.
Add registrations
Stripe Tax only calculates tax in jurisdictions where you’re registered to collect tax and requires you to add your registrations in the Dashboard.
Calculate taxServer-side
You choose when and how often to calculate tax. For example, you can:
- Show a tax estimate based on your customer’s IP address when they enter your checkout flow
- Recalculate tax as your customer types their billing or shipping address
- Calculate the final tax amount to collect when your customer finishes typing their address
Stripe charges a fee per tax calculation API call. You can throttle tax calculation API calls to manage your costs.
The examples below show how to calculate tax in a variety of scenarios. Stripe Tax only calculates tax in jurisdictions where you’re registered to collect tax and requires you to add your registrations in the Dashboard.
The calculation response contains amounts you can display to your customer, and use to take payment:
Attribute | Description |
---|---|
amount_total | The grand total after calculating tax. Use this to set the PaymentIntent amount to charge your customer. |
tax_amount_exclusive | The amount of tax added on top of your line item amounts and shipping cost. This tax amount increases the amount_ . Use this to show your customer the amount of tax added to the transaction subtotal. |
tax_amount_inclusive | The amount of tax that’s included in your line item amounts and shipping cost (if using tax-inclusive pricing). This tax amount does not increase the amount_ . Use this to show your customer the tax included in the total they’re paying. |
tax_breakdown | A list of tax amounts broken out by country or state tax rate. Use this to show your customer the specific taxes you’re collecting. |
Handling customer location errors
The calculation returns the customer_
error code if your customer’s address is invalid or isn’t precise enough to calculate tax:
{ "error": { "doc_url": "https://docs.stripe.com/error-codes#customer-tax-location-invalid", "code": "customer_tax_location_invalid", "message": "We could not determine the customer's tax location based on the provided customer address.", "param": "customer_details[address]", "type": "invalid_request_error" } }
When you receive this error, prompt your customer to check the address they’ve entered and fix any typos.
Create tax transactionServer-side
Creating a tax transaction records the tax you’ve collected from your customer, so that later you can download exports and generate reports to help with filing your taxes. You can create a transaction from a calculation until the expires_at timestamp, 90 days after it’s created. Attempting to use it after this time returns an error.
Note
The transaction is considered effective on the date when create_from_calculation is called, and tax amounts won’t be recalculated.
When creating a tax transaction, you must provide a unique reference
for the tax transaction and each line item. The references appear in tax exports to help you reconcile the tax you collected with the orders in your system.
For example, a tax transaction with reference pi_
, line item references L1
and L2
, and a shipping cost, looks like this in the itemized tax exports:
ID | line_item_id | type | currency | transaction_date | … |
---|---|---|---|---|---|
pi_123456789 | L1 | external | usd | 2023-02-23 17:01:16 | … |
pi_123456789 | L2 | external | usd | 2023-02-23 17:01:16 | … |
pi_123456789 | shipping | external | usd | 2023-02-23 17:01:16 | … |
When your customer pays, use the calculation ID to record the tax collected. Two ways to do this are:
- If your server has an endpoint where your customer submits their order, you can create the tax transaction after the order is successfully submitted.
- Listen for the payment_intent.succeeded webhook event. Retrieve the calculation ID from the PaymentIntent
metadata
.
The example below creates a transaction and uses the PaymentIntent ID as the unique reference:
Store the tax transaction ID so that later you can record refunds. You can store the transaction ID in your database or in the PaymentIntent’s metadata:
Record refundsServer-side
After creating a tax transaction to record a sale to your customer, you might need to record refunds. These are also represented as tax transactions, with type=reversal
. Reversal transactions offset an earlier transaction by having amounts with opposite signs. For example, a transaction that recorded a sale for 50 USD might later have a full reversal of -50 USD.
When you issue a refund (using Stripe or outside of Stripe) you need to create a reversal tax transaction with a unique reference
. Common strategies include:
- Append a suffix to the original reference. For example, if the original transaction has reference
pi_
, then create the reversal transaction with reference123456789 pi_
.123456789-refund - Use the ID of the Stripe refund or a refund ID from your system. For example,
re_
or3MoslRBUZ691iUZ41bsYVkOg myRefund_
.456
Choose the approach that works best for how you reconcile your customer orders with your tax exports.
Fully refund a sale
When you fully refund a sale in your system, create a reversal transaction with mode=full
.
In the example below, tax_
is the tax transaction recording the sale to your customer:
This returns the full reversal transaction that’s created:
{ "id": "tax_1MEFtXI6rIcR421e0KTGXvCK", "object": "tax.transaction", "created": 1670866467, "currency": "eur", "customer": null, "customer_details": { "address": { "city": null, "country": "IE",
Fully reversing a transaction doesn’t affect previous partial reversals. When you record a full reversal, make sure you fully reverse any previous partial reversals for the same transaction to avoid duplicate refunds.
Partially refund a sale
After issuing a refund to your customer, create a reversal tax transaction with mode=partial
. This allows you to record a partial refund by providing the line item amounts refunded. You can create up to 30 partial reversals for each sale. Reversing more than the amount of tax you collected returns an error.
The example below records a refund of only the first line item in the original transaction:
This returns the partial reversal transaction that’s created:
{ "id": "tax_1MEFACI6rIcR421eHrjXCSmD", "object": "tax.transaction", "created": 1670863656, "currency": "eur", ... "line_items": { "object": "list", "data": [ {
For each line item reversed you need to provide the amount
and amount_
reversed. The amount
is tax-inclusive if the original calculation line item was tax-inclusive.
How amount
and amount_
are determined depends on your situation:
- If your transactions always have a single line item, use full reversals instead.
- If you always refund entire line items, use the original transaction line item
amount
andamount_
, but with negative signs.tax - If you refund parts of line items, you need to calculate the amounts refunded. For example, for a sale transaction with
amount=5000
andamount_
, after refunding half the line item you’d create a partial reversal with line itemtax=500 amount=-2500
andamount_
.tax=-250
Partially refund a sale by a flat amount
Alternatively, you can create a reversal with mode=partial
by specifying a flat after-tax amount to refund. The amount distributes across each line item and shipping cost proportionally, depending on the remaining amount left to refund on each.
In the example below, the transaction has two line items: one 10 USD item and one 20 USD item, both taxed at 10%. The total amount of the transaction is 33.00 USD. A refund for a flat 16.50 USD is recorded:
This returns the partial reversal transaction that’s created:
{ "id": "tax_1NVcQYBUZ691iUZ4SBPukGa6", "object": "tax.transaction", "created": 1689780994, "currency": "usd", ... "line_items": { "object": "list", "data": [ {
For each line item and shipping cost in the original transaction, the refunded amounts and tax are calculated as follows:
- First, we calculate the total remaining funds in the transaction available to refund. Because this transaction hasn’t had any other reversals recorded, the total amount is 33.00 USD.
- Next, we calculate the total amount to refund for each line item. We base this calculation on the proportion of the item’s total available amount to refund versus the total remaining amount of the transaction. For example, the 10 USD item, which has 11.00 USD total remaining to refund, represents 33.33% of the transaction’s remaining total, so the total amount to refund is
-16.
.50 USD * 33. 33% = -5. 50 USD - Finally, the total amount to refund is divided between
amount
andamount_
. We also do this proportionally, depending on how much tax is available to refund in the line item compared to the total funds left to refund. Using the 10 USD item example, tax (1.00 USD) represents 9.09% of the total remaining to refund (11.00 USD), so thetax amount_
istax -5.
.50 USD * 9. 09% = -0. 50 USD
The flat amount distributes according to what’s left to refund in the transaction, not what was originally recorded. Consider this example: instead of recording a refund for a flat 16.50 USD, you first record a partial reversal for the total amount of the 10 USD item:
After this, you record a 16.50 USD flat amount reversal:
This returns the partial reversal transaction:
{ "id": "tax_1NVxFIBUZ691iUZ4saOIloxB", "object": "tax.transaction", "created": 1689861020, "currency": "usd", ... "line_items": { "object": "list", "data": [ {
Because the total amount remaining in the transaction is now 22.00 USD and the 10 USD item is completely refunded, the 16.50 USD distributes entirely to the 20 USD item. The 16.50 USD then distributes, using the logic from step 3, into amount = -15.
and amount_
. Meanwhile, the 10 USD item in the transaction records a refund of 0 USD.
Undo a partial refund
Tax transactions are immutable but you can cancel out a partial refund by creating a full reversal of it.
You might need to do this when:
- The payment refund fails and you haven’t provided the good or service to your customer
- The wrong order is refunded or the wrong amounts are refunded
- The original sale is fully refunded and the partial refunds are no longer valid
In the example below, tax_
is the transaction representing the partial refund:
This returns the full reversal transaction that’s created:
{ "id": "tax_1MEFADI6rIcR421e94fNTOCK", "object": "tax.transaction", "created": 1670863657, "currency": "eur", ... "line_items": { "object": "list", "data": [ {
Testing
The response structure in test mode is identical to live mode, so that you can confirm your integration is working correctly before going live.
Warning
We don’t guarantee test mode calculations return up-to-date taxation results.
You are limited to 1,000 test mode tax calculations per day. Contact Stripe support if you need a higher limit.