Collect tax on off-Stripe payments
Use the Stripe Tax API to calculate and report tax on payments processed outside of Stripe.
Use the Stripe Tax API to calculate and report tax on payments you process outside of Stripe. This works with any third-party payment processor or your in-house payment and invoicing systems.
Integrations for those who process on Stripe
If you process payments with Stripe, consider these integrations instead:
- Stripe Tax with PaymentIntents for automatic tax transaction management
- Stripe Tax with Checkout , Invoicing or Subscriptions for built-in tax support
Add registrations
Stripe Tax only calculates tax in jurisdictions where you’re registered to collect tax. You must add your registrations in the Dashboard.
Optional Collect customer address Server-side
Calculate tax Server-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. You must add your registrations in the Dashboard.
Example:
This example calculates tax for a US shipping address. The line item has a price of 10 USD and uses your account’s preset tax code.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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 as the 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_total. 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 doesn’t increase the amount_total. 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. |
Handle customer location errors
The calculation returns the customer_tax_location_invalid 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"
}
}
If you receive this error, prompt your customer to check the address they entered and fix any typos.
Create tax transaction Server-side
When you collect tax from your customer, create a Tax Transaction object to record it so that you can download exports and generate reports later to help with filing your taxes. You can create the Tax Transaction after the payment is successfully processed in your system – for example, in your order submission endpoint or in response to a payment success callback from your processor.
You can create a transaction using a Tax Calculation object’s ID until the expires_at timestamp, 90 days after it’s created. You’ll get an error if you try to use it after this time.
The Tax Transaction is considered effective on the date it’s created. Tax amounts aren’t recalculated if the tax rate changes after you create the Tax Transaction object.
When you create a Tax Transaction, provide a unique reference for the transaction. The reference appears in tax exports to help you reconcile the tax you collected with the orders in your system.
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
Store the resulting Tax Transaction ID in your database with the order it belongs to so you can record refunds later.
Example itemised tax export
For example, a Tax Transaction with reference order_123456789, line item references L1 and L2 and a shipping cost, looks like this in the itemised Tax exports:
| ID | line_item_id | type | currency | transaction_date |
|---|---|---|---|---|
| order_123456789 | L1 | external | usd | 2023-02-23 17:01:16 |
| order_123456789 | L2 | external | usd | 2023-02-23 17:01:16 |
| order_123456789 | shipping | external | usd | 2023-02-23 17:01:16 |
Record refunds Server-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, you must 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 order _ 123456789 , then create the Reversal Transaction with reference order _ 123456789-refund .
- Use a Refund ID from your system. For example, myRefund _ 456 .
Choose the approach that works best for how you reconcile your customer orders with your tax exports.
Request to join the preview for flat, tax-only refunds.
Enter your email to request access.
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_1MEFAAI6rIcR421eB1YOzACZ is the tax transaction that records the sale to your customer:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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, you need to 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:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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 must provide the amount and amount_tax reversed. The amount is tax-inclusive if the original calculation line item was tax-inclusive.
How amount and amount_tax 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 and amount _ tax , but with negative signs.
- If you refund parts of line items, you must calculate the amounts refunded. For example, for a sale transaction with amount=5000 and amount _ tax=500 , after refunding half the line item, you create a partial reversal with line item amount=-2500 and amount _ tax=-250 .
Tax reports with partial refunds
If you refund a tax amount such that the total tax is no longer proportional to the subtotal, your tax reporting can be unreliable. It won’t automatically adjust the taxable and non-taxable amounts, and won’t reflect the reason for the tax reversal (such as product exempt, customer exempt, or reverse charge). We recommend not refunding partial line item tax amounts. Instead, fully reverse the transaction and create a new one with appropriate inputs for an accurate tax calculation.
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:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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 and amount _ tax . 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 the amount _ tax is -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. For 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:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
After this, you record a 16.50 USD flat amount reversal:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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.00 USD and amount_tax = -1.50 USD. 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 a partial refund by creating a full reversal.
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_1MEFACI6rIcR421eHrjXCSmD is the transaction that represents the partial refund:
Command Line
Select a language
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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
Use sandboxes, which is identical in response structure to live mode, to confirm your integration works correctly before going live.
Warning
In testing environments, calculations aren’t guaranteed to return up-to-date taxation results. You’re limited to 1,000 tax calculations per day. If you need a higher limit, contact Stripe support. For guidance on automated testing and strategies to avoid rate limits in testing environments, see Automated testing.
View tax transactions
You can view all tax transactions for your account on the Tax Transactions page in the Dashboard. Click an individual transaction to see a detailed breakdown of calculated tax by jurisdiction, and by the individual products included in the transaction.
Note
The Tax Transactions page only includes transactions and not calculations. If you expect to see a calculation and can’t find it on this page, verify that you successfully created a tax transaction from the calculation.
For advanced options like shipping costs, tax-inclusive pricing, IP address estimation, and more, see the Standalone Tax API reference.
