--- title: Collect taxes for recurring payments subtitle: Learn how to collect and report taxes for recurring payments. route: /billing/taxes/collect-taxes --- # Collect taxes for recurring payments Learn how to collect and report taxes for recurring payments. To calculate tax for recurring payments, Stripe offers Stripe Tax and Tax Rates. - **Stripe Tax**—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. For more information, see [Stripe Tax](https://docs.stripe.com/tax.md). - **Tax Rates**—a free feature that allows you to define any number of tax rates for *invoices*, *subscriptions*, and one-time payments that use Checkout. Stripe won’t create or maintain any tax rates on your behalf. For more information, see [Tax Rates](https://docs.stripe.com/api/tax_rates.md) and [how to use them](https://docs.stripe.com/billing/taxes/tax-rates.md). # Stripe Tax > This is a Stripe Tax for when tax-calculation is stripe-tax. View the original doc at https://docs.stripe.com/billing/taxes/collect-taxes?tax-calculation=stripe-tax. Stripe Tax allows you to calculate the tax amount on your recurring payments when using Stripe Billing. Use your customer’s location details to preview the tax amount before creating a subscription and then create it with Stripe Tax enabled when your customer is ready to pay. Stripe Tax integrates with Stripe Billing and automatically handles tax calculation with your [pricing model](https://docs.stripe.com/products-prices/pricing-models.md), [prorations](https://docs.stripe.com/billing/subscriptions/prorations.md), [discounts](https://docs.stripe.com/billing/subscriptions/coupons.md), [trials](https://docs.stripe.com/billing/subscriptions/trials.md), and so on. This guide assumes you’re setting up Stripe Tax and Billing for the first time. See how to [update existing subscriptions](https://docs.stripe.com/tax/subscriptions/update.md). If you’re using Stripe Checkout to create new subscriptions, see how to [automatically collect tax on Checkout sessions](https://docs.stripe.com/tax/checkout.md), or watch the short video below: ## Estimate taxes and total When a customer first enters your checkout flow, you might not have their address information yet. In this case, [create a preview invoice](https://docs.stripe.com/api/invoices/create_preview.md) and set [customer_details.tax.ip_address](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-tax-ip_address) to let Stripe locate them using their IP address. In most cases, Stripe can resolve an IP address to a physical area, but its precision varies and might not reflect your customer’s actual location. We don’t recommend relying on a customer’s IP address to determine their address beyond an initial estimate. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new InvoiceCreatePreviewOptions { AutomaticTax = new InvoiceAutomaticTaxOptions { Enabled = true }, CustomerDetails = new InvoiceCustomerDetailsOptions { Tax = new InvoiceCustomerDetailsTaxOptions { IpAddress = "{{IP_ADDRESS}}" }, }, SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = new List { new InvoiceSubscriptionDetailsItemOptions { Price = "<>" }, }, }, }; var service = new InvoiceService(); Invoice invoice = service.CreatePreview(options); ``` ```go stripe.Key = "<>" params := &stripe.InvoiceCreatePreviewParams{ AutomaticTax: &stripe.InvoiceCreatePreviewAutomaticTaxParams{Enabled: stripe.Bool(true)}, CustomerDetails: &stripe.InvoiceCreatePreviewCustomerDetailsParams{ Tax: &stripe.InvoiceCreatePreviewCustomerDetailsTaxParams{ IPAddress: stripe.String("{{IP_ADDRESS}}"), }, }, SubscriptionDetails: &stripe.InvoiceCreatePreviewSubscriptionDetailsParams{ Items: []*stripe.InvoiceCreatePreviewSubscriptionDetailsItemParams{ &stripe.InvoiceCreatePreviewSubscriptionDetailsItemParams{Price: stripe.String("<>")}, }, }, }; result, err := invoice.CreatePreview(params); ``` ```java Stripe.apiKey = "<>"; InvoiceCreatePreviewParams params = InvoiceCreatePreviewParams.builder() .setAutomaticTax(InvoiceCreatePreviewParams.AutomaticTax.builder().setEnabled(true).build()) .setCustomerDetails( InvoiceCreatePreviewParams.CustomerDetails.builder() .setTax( InvoiceCreatePreviewParams.CustomerDetails.Tax.builder() .setIpAddress("{{IP_ADDRESS}}") .build() ) .build() ) .setSubscriptionDetails( InvoiceCreatePreviewParams.SubscriptionDetails.builder() .addItem( InvoiceCreatePreviewParams.SubscriptionDetails.Item.builder() .setPrice("<>") .build() ) .build() ) .build(); Invoice invoice = Invoice.createPreview(params); ``` ```node const stripe = require('stripe')('<>'); const invoice = await stripe.invoices.createPreview({ automatic_tax: { enabled: true, }, customer_details: { tax: { ip_address: '{{IP_ADDRESS}}', }, }, subscription_details: { items: [ { price: '<>', }, ], }, }); ``` ```python import stripe stripe.api_key = "<>" invoice = stripe.Invoice.create_preview( automatic_tax={"enabled": True}, customer_details={"tax": {"ip_address": "{{IP_ADDRESS}}"}}, subscription_details={"items": [{"price": "<>"}]}, ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $invoice = $stripe->invoices->createPreview([ 'automatic_tax' => ['enabled' => true], 'customer_details' => ['tax' => ['ip_address' => '{{IP_ADDRESS}}']], 'subscription_details' => ['items' => [['price' => '<>']]], ]); ``` ```ruby Stripe.api_key = '<>' invoice = Stripe::Invoice.create_preview({ automatic_tax: {enabled: true}, customer_details: {tax: {ip_address: '{{IP_ADDRESS}}'}}, subscription_details: {items: [{price: '<>'}]}, }) ``` When your customer fills in their address details, set [customer_details.address](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-address) also. Use [customer_details.shipping](https://docs.stripe.com/api/invoices/create_preview.md#create_create_preview-customer_details-shipping) if you’re collecting shipping addresses. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new InvoiceCreatePreviewOptions { AutomaticTax = new InvoiceAutomaticTaxOptions { Enabled = true }, CustomerDetails = new InvoiceCustomerDetailsOptions { Address = new AddressOptions { Line1 = "{{LINE1}}", Line2 = "{{LINE2}}", City = "{{CITY}}", State = "{{STATE}}", PostalCode = "{{POSTAL_CODE}}", Country = "{{COUNTRY}}", }, Tax = new InvoiceCustomerDetailsTaxOptions { IpAddress = "{{IP_ADDRESS}}" }, }, SubscriptionDetails = new InvoiceSubscriptionDetailsOptions { Items = new List { new InvoiceSubscriptionDetailsItemOptions { Price = "<>" }, }, }, }; var service = new InvoiceService(); Invoice invoice = service.CreatePreview(options); ``` ```go stripe.Key = "<>" params := &stripe.InvoiceCreatePreviewParams{ AutomaticTax: &stripe.InvoiceCreatePreviewAutomaticTaxParams{Enabled: stripe.Bool(true)}, CustomerDetails: &stripe.InvoiceCreatePreviewCustomerDetailsParams{ Address: &stripe.InvoiceCreatePreviewCustomerDetailsAddressParams{ Line1: stripe.String("{{LINE1}}"), Line2: stripe.String("{{LINE2}}"), City: stripe.String("{{CITY}}"), State: stripe.String("{{STATE}}"), PostalCode: stripe.String("{{POSTAL_CODE}}"), Country: stripe.String("{{COUNTRY}}"), }, Tax: &stripe.InvoiceCreatePreviewCustomerDetailsTaxParams{ IPAddress: stripe.String("{{IP_ADDRESS}}"), }, }, SubscriptionDetails: &stripe.InvoiceCreatePreviewSubscriptionDetailsParams{ Items: []*stripe.InvoiceCreatePreviewSubscriptionDetailsItemParams{ &stripe.InvoiceCreatePreviewSubscriptionDetailsItemParams{Price: stripe.String("<>")}, }, }, }; result, err := invoice.CreatePreview(params); ``` ```java Stripe.apiKey = "<>"; InvoiceCreatePreviewParams params = InvoiceCreatePreviewParams.builder() .setAutomaticTax(InvoiceCreatePreviewParams.AutomaticTax.builder().setEnabled(true).build()) .setCustomerDetails( InvoiceCreatePreviewParams.CustomerDetails.builder() .setAddress( InvoiceCreatePreviewParams.CustomerDetails.Address.builder() .setLine1("{{LINE1}}") .setLine2("{{LINE2}}") .setCity("{{CITY}}") .setState("{{STATE}}") .setPostalCode("{{POSTAL_CODE}}") .setCountry("{{COUNTRY}}") .build() ) .setTax( InvoiceCreatePreviewParams.CustomerDetails.Tax.builder() .setIpAddress("{{IP_ADDRESS}}") .build() ) .build() ) .setSubscriptionDetails( InvoiceCreatePreviewParams.SubscriptionDetails.builder() .addItem( InvoiceCreatePreviewParams.SubscriptionDetails.Item.builder() .setPrice("<>") .build() ) .build() ) .build(); Invoice invoice = Invoice.createPreview(params); ``` ```node const stripe = require('stripe')('<>'); const invoice = await stripe.invoices.createPreview({ automatic_tax: { enabled: true, }, customer_details: { address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: { ip_address: '{{IP_ADDRESS}}', }, }, subscription_details: { items: [ { price: '<>', }, ], }, }); ``` ```python import stripe stripe.api_key = "<>" invoice = stripe.Invoice.create_preview( automatic_tax={"enabled": True}, customer_details={ "address": { "line1": "{{LINE1}}", "line2": "{{LINE2}}", "city": "{{CITY}}", "state": "{{STATE}}", "postal_code": "{{POSTAL_CODE}}", "country": "{{COUNTRY}}", }, "tax": {"ip_address": "{{IP_ADDRESS}}"}, }, subscription_details={"items": [{"price": "<>"}]}, ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $invoice = $stripe->invoices->createPreview([ 'automatic_tax' => ['enabled' => true], 'customer_details' => [ 'address' => [ 'line1' => '{{LINE1}}', 'line2' => '{{LINE2}}', 'city' => '{{CITY}}', 'state' => '{{STATE}}', 'postal_code' => '{{POSTAL_CODE}}', 'country' => '{{COUNTRY}}', ], 'tax' => ['ip_address' => '{{IP_ADDRESS}}'], ], 'subscription_details' => ['items' => [['price' => '<>']]], ]); ``` ```ruby Stripe.api_key = '<>' invoice = Stripe::Invoice.create_preview({ automatic_tax: {enabled: true}, customer_details: { address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: {ip_address: '{{IP_ADDRESS}}'}, }, subscription_details: {items: [{price: '<>'}]}, }) ``` Check the [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) of the invoice. If the status is `requires_location_inputs`, it means that the address details are invalid or insufficient. In this case, prompt your customer to re-enter their address details or provide accurate address details. The invoice [total](https://docs.stripe.com/api/invoices/object.md#invoice_object-total) is how much your customer pays and [tax](https://docs.stripe.com/api/invoices/object.md#invoice_object-tax) is the sum of all tax amounts on the invoice. If you want a breakdown of taxes, see [total_tax_amounts](https://docs.stripe.com/api/invoices/object.md#invoice_object-total_tax_amounts). All amounts are in cents. If the `tax` is zero, make sure that you have a tax registration in your customer’s location. See how to [register for sales tax, VAT, and GST](https://docs.stripe.com/tax/registering.md) and learn more about [zero tax amounts and reverse charges](https://docs.stripe.com/tax/zero-tax.md). ## Collect customer information After you have an estimate of the taxes and the total, start collecting customer information including their shipping address (if applicable), billing address, and their payment details. Notice that when you use Stripe Tax, you collect payment details without an Intent. The first step is to [create an Elements object without an Intent](https://docs.stripe.com/js/elements_object/create_without_intent): ```javascript const stripe = Stripe("<>"); const elements = stripe.elements({ mode: 'subscription', currency: '{{CURRENCY}}', amount: {{TOTAL}}, }); ``` Next, [create an Address Element](https://docs.stripe.com/js/elements_object/create_address_element) and [a Payment Element](https://docs.stripe.com/js/elements_object/create_payment_element) and [mount](https://docs.stripe.com/js/element/mount) both: ```javascript const addressElement = elements.create('address', { mode: 'billing' // or 'shipping', if you are shipping goods }); addressElement.mount('#address-element'); const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` Then you can listen to [change events](https://docs.stripe.com/js/element/events/on_change?type=paymentElement#element_on_change-event) on the Address Element. When the address changes, [re-estimate](https://docs.stripe.com/tax/subscriptions.md?estimate=after#estimate-taxes-total) the taxes and the total. ```javascript addressElement.on('change', function(event) { // Throttle your requests to avoid overloading your server or hitting // Stripe's rate limits. const { tax, total } = await updateEstimate(event.value.address); elements.update({ amount: total }); // Update your page to display the new tax and total to the user... }); ``` When your customer is entering their address, Address Element fires a `change` event for each keystroke. To avoid overloading your server and hitting Stripe’s [rate limits](https://docs.stripe.com/rate-limits.md), wait for some time after the last `change` event before re-estimating the taxes and the total. ## Handle submission When your customer submits the form, call [elements.submit()](https://docs.stripe.com/js/elements/submit) to validate the form fields and collect any data required for wallets. You must wait for this function’s promise to resolve before performing any other operations. ```javascript document.querySelector("#form").addEventListener("submit", function(event) { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); const { error: submitError } = await elements.submit(); if (submitError) { // Handle error... return; } const { value: customerDetails } = await addressElement.getValue(); // See the "Save customer details" section below to implement this // server-side. await saveCustomerDetails(customerDetails); // See the "Create subscription" section below to implement this server-side. const { clientSecret } = await createSubscription(); const { error: confirmError } = await stripe.confirmPayment({ elements, clientSecret, confirmParams: { return_url: {{RETURN_URL}}, }, }); if (confirmError) { // Handle error... return; } // Upon a successful confirmation, your user will be redirected to the // return_url you provide before the Promise ever resolves. }); ``` ## Save customer details [Update](https://docs.stripe.com/api/customers/update.md) your `Customer` object using the details you’ve collected from your customer, so that Stripe Tax can determine their precise location for accurate results. If your customer is in the United States, provide a full address if possible. We use the term “rooftop-accurate” to mean that we can attribute your customer’s location to a specific house or building. This provides greater accuracy, where two houses located side-by-side on the same street might be subject to different tax rates, because of complex jurisdiction boundaries. If you haven’t already created a `Customer` object (for example, when your customer first signs up on your website), you can [create](https://docs.stripe.com/api/customers/create.md) one now. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new CustomerUpdateOptions { Address = new AddressOptions { Line1 = "{{LINE1}}", Line2 = "{{LINE2}}", City = "{{CITY}}", State = "{{STATE}}", PostalCode = "{{POSTAL_CODE}}", Country = "{{COUNTRY}}", }, Tax = new CustomerTaxOptions { ValidateLocation = "immediately" }, }; var service = new CustomerService(); Customer customer = service.Update("<>", options); ``` ```go stripe.Key = "<>" params := &stripe.CustomerParams{ Address: &stripe.AddressParams{ Line1: stripe.String("{{LINE1}}"), Line2: stripe.String("{{LINE2}}"), City: stripe.String("{{CITY}}"), State: stripe.String("{{STATE}}"), PostalCode: stripe.String("{{POSTAL_CODE}}"), Country: stripe.String("{{COUNTRY}}"), }, Tax: &stripe.CustomerTaxParams{ValidateLocation: stripe.String("immediately")}, }; result, err := customer.Update("<>", params); ``` ```java Stripe.apiKey = "<>"; Customer resource = Customer.retrieve("<>"); CustomerUpdateParams params = CustomerUpdateParams.builder() .setAddress( CustomerUpdateParams.Address.builder() .setLine1("{{LINE1}}") .setLine2("{{LINE2}}") .setCity("{{CITY}}") .setState("{{STATE}}") .setPostalCode("{{POSTAL_CODE}}") .setCountry("{{COUNTRY}}") .build() ) .setTax( CustomerUpdateParams.Tax.builder() .setValidateLocation(CustomerUpdateParams.Tax.ValidateLocation.IMMEDIATELY) .build() ) .build(); Customer customer = resource.update(params); ``` ```node const stripe = require('stripe')('<>'); const customer = await stripe.customers.update( '<>', { address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: { validate_location: 'immediately', }, } ); ``` ```python import stripe stripe.api_key = "<>" customer = stripe.Customer.modify( "<>", address={ "line1": "{{LINE1}}", "line2": "{{LINE2}}", "city": "{{CITY}}", "state": "{{STATE}}", "postal_code": "{{POSTAL_CODE}}", "country": "{{COUNTRY}}", }, tax={"validate_location": "immediately"}, ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $customer = $stripe->customers->update( '<>', [ 'address' => [ 'line1' => '{{LINE1}}', 'line2' => '{{LINE2}}', 'city' => '{{CITY}}', 'state' => '{{STATE}}', 'postal_code' => '{{POSTAL_CODE}}', 'country' => '{{COUNTRY}}', ], 'tax' => ['validate_location' => 'immediately'], ] ); ``` ```ruby Stripe.api_key = '<>' customer = Stripe::Customer.update( '<>', { address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: {validate_location: 'immediately'}, }, ) ``` If your customer has other existing subscriptions with automatic tax enabled and you update their address information, the tax and total amounts on their future invoices might be different. This is because tax rates vary depending on customer location. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new CustomerCreateOptions { Address = new AddressOptions { Line1 = "{{LINE1}}", Line2 = "{{LINE2}}", City = "{{CITY}}", State = "{{STATE}}", PostalCode = "{{POSTAL_CODE}}", Country = "{{COUNTRY}}", }, Tax = new CustomerTaxOptions { ValidateLocation = "immediately" }, }; var service = new CustomerService(); Customer customer = service.Create(options); ``` ```go stripe.Key = "<>" params := &stripe.CustomerParams{ Address: &stripe.AddressParams{ Line1: stripe.String("{{LINE1}}"), Line2: stripe.String("{{LINE2}}"), City: stripe.String("{{CITY}}"), State: stripe.String("{{STATE}}"), PostalCode: stripe.String("{{POSTAL_CODE}}"), Country: stripe.String("{{COUNTRY}}"), }, Tax: &stripe.CustomerTaxParams{ValidateLocation: stripe.String("immediately")}, }; result, err := customer.New(params); ``` ```java Stripe.apiKey = "<>"; CustomerCreateParams params = CustomerCreateParams.builder() .setAddress( CustomerCreateParams.Address.builder() .setLine1("{{LINE1}}") .setLine2("{{LINE2}}") .setCity("{{CITY}}") .setState("{{STATE}}") .setPostalCode("{{POSTAL_CODE}}") .setCountry("{{COUNTRY}}") .build() ) .setTax( CustomerCreateParams.Tax.builder() .setValidateLocation(CustomerCreateParams.Tax.ValidateLocation.IMMEDIATELY) .build() ) .build(); Customer customer = Customer.create(params); ``` ```node const stripe = require('stripe')('<>'); const customer = await stripe.customers.create({ address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: { validate_location: 'immediately', }, }); ``` ```python import stripe stripe.api_key = "<>" customer = stripe.Customer.create( address={ "line1": "{{LINE1}}", "line2": "{{LINE2}}", "city": "{{CITY}}", "state": "{{STATE}}", "postal_code": "{{POSTAL_CODE}}", "country": "{{COUNTRY}}", }, tax={"validate_location": "immediately"}, ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $customer = $stripe->customers->create([ 'address' => [ 'line1' => '{{LINE1}}', 'line2' => '{{LINE2}}', 'city' => '{{CITY}}', 'state' => '{{STATE}}', 'postal_code' => '{{POSTAL_CODE}}', 'country' => '{{COUNTRY}}', ], 'tax' => ['validate_location' => 'immediately'], ]); ``` ```ruby Stripe.api_key = '<>' customer = Stripe::Customer.create({ address: { line1: '{{LINE1}}', line2: '{{LINE2}}', city: '{{CITY}}', state: '{{STATE}}', postal_code: '{{POSTAL_CODE}}', country: '{{COUNTRY}}', }, tax: {validate_location: 'immediately'}, }) ``` The [tax.validate_location](https://docs.stripe.com/api/customers/update.md#update_customer-tax-validate_location) enum value helps you make sure that the tax location of the customer becomes (or remains) valid as a result of this operation. If not, Stripe fails your request with the [customer_tax_location_invalid](https://docs.stripe.com/error-codes.md#customer-tax-location-invalid) error code. This is important because you can’t create an automatic tax enabled subscription for a customer with an invalid tax location. If you’ve been checking the [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) of your preview invoices as [advised](#estimate-taxes-total) previously, this additional validation won’t ever fail. However, it’s good practice to set `tax[validate_location]="immediately"` whenever you’re creating or updating a `Customer` object. ## Create subscription [Create](https://docs.stripe.com/api/subscriptions/create.md) a subscription with automatic tax enabled. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new SubscriptionCreateOptions { AutomaticTax = new SubscriptionAutomaticTaxOptions { Enabled = true }, Customer = "<>", Items = new List { new SubscriptionItemOptions { Price = "<>" }, }, PaymentSettings = new SubscriptionPaymentSettingsOptions { SaveDefaultPaymentMethod = "on_subscription", }, Expand = new List { "latest_invoice.payment_intent" }, }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); ``` ```go stripe.Key = "<>" params := &stripe.SubscriptionParams{ AutomaticTax: &stripe.SubscriptionAutomaticTaxParams{Enabled: stripe.Bool(true)}, Customer: stripe.String("<>"), Items: []*stripe.SubscriptionItemsParams{ &stripe.SubscriptionItemsParams{Price: stripe.String("<>")}, }, PaymentSettings: &stripe.SubscriptionPaymentSettingsParams{ SaveDefaultPaymentMethod: stripe.String(string(stripe.SubscriptionPaymentSettingsSaveDefaultPaymentMethodOnSubscription)), }, }; params.AddExpand("latest_invoice.payment_intent") result, err := subscription.New(params); ``` ```java Stripe.apiKey = "<>"; SubscriptionCreateParams params = SubscriptionCreateParams.builder() .setAutomaticTax(SubscriptionCreateParams.AutomaticTax.builder().setEnabled(true).build()) .setCustomer("<>") .addItem(SubscriptionCreateParams.Item.builder().setPrice("<>").build()) .setPaymentSettings( SubscriptionCreateParams.PaymentSettings.builder() .setSaveDefaultPaymentMethod( SubscriptionCreateParams.PaymentSettings.SaveDefaultPaymentMethod.ON_SUBSCRIPTION ) .build() ) .addExpand("latest_invoice.payment_intent") .build(); Subscription subscription = Subscription.create(params); ``` ```node const stripe = require('stripe')('<>'); const subscription = await stripe.subscriptions.create({ automatic_tax: { enabled: true, }, customer: '<>', items: [ { price: '<>', }, ], payment_settings: { save_default_payment_method: 'on_subscription', }, expand: ['latest_invoice.payment_intent'], }); ``` ```python import stripe stripe.api_key = "<>" subscription = stripe.Subscription.create( automatic_tax={"enabled": True}, customer="<>", items=[{"price": "<>"}], payment_settings={"save_default_payment_method": "on_subscription"}, expand=["latest_invoice.payment_intent"], ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $subscription = $stripe->subscriptions->create([ 'automatic_tax' => ['enabled' => true], 'customer' => '<>', 'items' => [['price' => '<>']], 'payment_settings' => ['save_default_payment_method' => 'on_subscription'], 'expand' => ['latest_invoice.payment_intent'], ]); ``` ```ruby Stripe.api_key = '<>' subscription = Stripe::Subscription.create({ automatic_tax: {enabled: true}, customer: '<>', items: [{price: '<>'}], payment_settings: {save_default_payment_method: 'on_subscription'}, expand: ['latest_invoice.payment_intent'], }) ``` The [latest_invoice.payment_intent.client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) is the *client secret* of the *payment intent* of the first (and the latest) invoice of the new subscription. You need to pass the client secret to your front end to be able to *confirm* the payment intent. Don’t store, log, or expose the client secret to anyone other than the customer. Make sure that you have TLS enabled on any page that includes the client secret. If your customer has a default payment method, the first invoice of the subscription is paid automatically. You can confirm this using [latest_invoice.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-status) of the subscription. If you want to use the new payment details you collected from your customer in your checkout flow, make sure that the first invoice isn’t paid automatically. Pass `default_incomplete` for the [payment_behavior](https://docs.stripe.com/api/subscriptions/create.md#create_subscription-payment_behavior) when you’re creating your subscription and confirm the payment intent using [stripe.confirmPayment()](https://docs.stripe.com/js/payment_intents/confirm_payment) as shown. See [Billing collection methods](https://docs.stripe.com/billing/collection-method.md) for more information. ## Update your products and prices Stripe Tax uses information stored on *products* and *prices* to calculate tax, such as *tax code* and *tax behavior*. If you don’t explicitly specify these configurations, Stripe Tax will use the default tax code selected in [Tax Settings](https://dashboard.stripe.com/settings/tax). For more information, see [Specify product tax codes and tax behaviour](https://docs.stripe.com/tax/products-prices-tax-codes-tax-behavior.md). ## Handle refunds When you create a refund for an Invoice payment, Stripe Tax automatically reduces your tax liability. Alternatively, you can issue [Credit Notes](https://docs.stripe.com/api/credit_notes/object.md) to track tax liability decreases and provide records to your customers. To refund an amount associated with an invoice total, create a Credit Note and a Refund. Create a Credit Note and a [Refund](https://docs.stripe.com/api/refunds/object.md) together by calling [create Credit Note](https://docs.stripe.com/api/credit_notes/create.md) and providing a `refund_amount` value. ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new CreditNoteCreateOptions { Invoice = "<>", RefundAmount = 1000 }; var service = new CreditNoteService(); CreditNote creditNote = service.Create(options); ``` ```go stripe.Key = "<>" params := &stripe.CreditNoteParams{ Invoice: stripe.String("<>"), RefundAmount: stripe.Int64(1000), }; result, err := creditnote.New(params); ``` ```java Stripe.apiKey = "<>"; CreditNoteCreateParams params = CreditNoteCreateParams.builder().setInvoice("<>").setRefundAmount(1000L).build(); CreditNote creditNote = CreditNote.create(params); ``` ```node const stripe = require('stripe')('<>'); const creditNote = await stripe.creditNotes.create({ invoice: '<>', refund_amount: 1000, }); ``` ```python import stripe stripe.api_key = "<>" credit_note = stripe.CreditNote.create( invoice="<>", refund_amount=1000, ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $creditNote = $stripe->creditNotes->create([ 'invoice' => '<>', 'refund_amount' => 1000, ]); ``` ```ruby Stripe.api_key = '<>' credit_note = Stripe::CreditNote.create({ invoice: '<>', refund_amount: 1000, }) ``` [Create a Refund](https://docs.stripe.com/api/refunds/create.md), then include its ID when you create a [Credit Note](https://docs.stripe.com/api/credit_notes/object.md). In this case, don’t include a `refund_amount` value. Stripe Tax automatically distributes the total refund amount between taxes and the net amount. If you want to refund an amount associated with an invoice line item, first calculate the [total](https://docs.stripe.com/api/credit_notes/object.md#credit_note_object-total) and [total_excluding_tax](https://docs.stripe.com/api/credit_notes/object.md#credit_note_object-total_excluding_tax) amounts by calling [preview Credit Note](https://docs.stripe.com/api/credit_notes/preview.md). ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new CreditNotePreviewOptions { Invoice = "<>", Lines = new List { new CreditNoteLineOptions { Type = "invoice_line_item", InvoiceLineItem = "{{line item id from invoice}}", Amount = 1000, }, }, }; var service = new CreditNoteService(); CreditNote creditNote = service.Preview(options); ``` ```go stripe.Key = "<>" params := &stripe.CreditNotePreviewParams{ Invoice: stripe.String("<>"), Lines: []*stripe.CreditNotePreviewLineParams{ &stripe.CreditNotePreviewLineParams{ Type: stripe.String("invoice_line_item"), InvoiceLineItem: stripe.String("{{line item id from invoice}}"), Amount: stripe.Int64(1000), }, }, }; result, err := creditnote.Preview(params); ``` ```java Stripe.apiKey = "<>"; CreditNotePreviewParams params = CreditNotePreviewParams.builder() .setInvoice("<>") .addLine( CreditNotePreviewParams.Line.builder() .setType(CreditNotePreviewParams.Line.Type.INVOICE_LINE_ITEM) .setInvoiceLineItem("{{line item id from invoice}}") .setAmount(1000L) .build() ) .build(); CreditNote creditNote = CreditNote.preview(params); ``` ```node const stripe = require('stripe')('<>'); const creditNote = await stripe.creditNotes.preview({ invoice: '<>', lines: [ { type: 'invoice_line_item', invoice_line_item: '{{line item id from invoice}}', amount: 1000, }, ], }); ``` ```python import stripe stripe.api_key = "<>" credit_note = stripe.CreditNote.preview( invoice="<>", lines=[ { "type": "invoice_line_item", "invoice_line_item": "{{line item id from invoice}}", "amount": 1000, }, ], ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $creditNote = $stripe->creditNotes->preview([ 'invoice' => '<>', 'lines' => [ [ 'type' => 'invoice_line_item', 'invoice_line_item' => '{{line item id from invoice}}', 'amount' => 1000, ], ], ]); ``` ```ruby Stripe.api_key = '<>' credit_note = Stripe::CreditNote.preview({ invoice: '<>', lines: [ { type: 'invoice_line_item', invoice_line_item: '{{line item id from invoice}}', amount: 1000, }, ], }) ``` Then, create a [Credit Note](https://docs.stripe.com/api/credit_notes/object.md) and a [Refund](https://docs.stripe.com/api/refunds/object.md). Create a Credit Note and a [Refund](https://docs.stripe.com/api/refunds/object.md) together by calling [create Credit Note](https://docs.stripe.com/api/credit_notes/create.md) and providing a `refund_amount` value. [Create a Refund](https://docs.stripe.com/api/refunds/create.md) using the `total` calculated by the Credit Note preview, then include its ID when you create a [Credit Note](https://docs.stripe.com/api/credit_notes/object.md). In this case, don’t include a `refund_amount` value. ## Use webhooks We recommend listening to subscription events with *webhooks* because most subscription activity happens asynchronously. When you start using Stripe Tax, make sure to listen to [invoice.finalization_failed](https://docs.stripe.com/api/events/types.md#event_types-invoice.finalization_failed) events. If the [automatic_tax.status](https://docs.stripe.com/api/invoices/object.md#invoice_object-automatic_tax-status) of the invoice is `requires_location_inputs`, it means that the address details of your customer are invalid or insufficient. In this case, Stripe can’t calculate the taxes, can’t finalize the invoice, and can’t collect the payment. Notify your customer to re-enter their address details or provide an accurate address. See [Using webhooks with subscriptions](https://docs.stripe.com/billing/subscriptions/webhooks.md) to learn more. # Tax Rates > This is a Tax Rates for when tax-calculation is tax-rates. View the original doc at https://docs.stripe.com/billing/taxes/collect-taxes?tax-calculation=tax-rates. To collect taxes on a subscription, set [tax rates on the subscription](#static-configuration) or [set the tax rates on invoices as the subscription cycles](#dynamic-configuration). Or, if you use Checkout, you can [specify tax rates in Checkout Sessions](#adding-tax-rates-to-checkout) to apply taxes to subscriptions. ## Setting tax rates on a subscription Subscriptions create draft invoices that stay editable for about an hour. During this time, you can correct the tax rates using the steps outlined below. You can apply taxes at the subscription level and the subscription item level and set up to [five tax rates](https://docs.stripe.com/billing/taxes/tax-rates.md#using-multiple-tax-rates) on each subscription item. When invoices are generated for subscriptions, tax rates are copied from the subscription to the invoice. In the example below, the first subscription item has two tax rates: 3% and 5%, which overrides the 1% from the subscription level tax rate. The second item doesn’t have any tax rates set directly on it, so the 1% from the subscription level tax rate is automatically applied. | | | | | Subscription item 1 | 3% and 5% | ➡️ | Invoice item 1 | 3% and 5% | | Subscription item 2 | (no tax set) | ➡️ | Invoice item 2 | (no tax set) | | Subscription | 1% | ➡️ | Invoice | 1% | You can set tax rates when you create or update subscription items by passing the [tax rate IDs](https://docs.stripe.com/api/subscription_items/object.md#subscription_item_object-tax_rates-id). The example below updates an existing subscription item with two tax rates: ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new SubscriptionItemUpdateOptions { TaxRates = new List { "txr_1F6kmAAJVYItwOKqV9IWehUH", "txr_2J8lmBBGHJYyuUJqF6QJtkNM" }, }; var service = new SubscriptionItemService(); SubscriptionItem subscriptionItem = service.Update("si_F2yjdxUlCCOAtv", options); ``` ```go stripe.Key = "<>" params := &stripe.SubscriptionItemParams{ TaxRates: []*string{ stripe.String("txr_1F6kmAAJVYItwOKqV9IWehUH"), stripe.String("txr_2J8lmBBGHJYyuUJqF6QJtkNM"), }, }; result, err := subscriptionitem.Update("si_F2yjdxUlCCOAtv", params); ``` ```java Stripe.apiKey = "<>"; SubscriptionItem resource = SubscriptionItem.retrieve("si_F2yjdxUlCCOAtv"); SubscriptionItemUpdateParams params = SubscriptionItemUpdateParams.builder() .addTaxRate("txr_1F6kmAAJVYItwOKqV9IWehUH") .addTaxRate("txr_2J8lmBBGHJYyuUJqF6QJtkNM") .build(); SubscriptionItem subscriptionItem = resource.update(params); ``` ```node const stripe = require('stripe')('<>'); const subscriptionItem = await stripe.subscriptionItems.update( 'si_F2yjdxUlCCOAtv', { tax_rates: ['txr_1F6kmAAJVYItwOKqV9IWehUH', 'txr_2J8lmBBGHJYyuUJqF6QJtkNM'], } ); ``` ```python import stripe stripe.api_key = "<>" subscription_item = stripe.SubscriptionItem.modify( "si_F2yjdxUlCCOAtv", tax_rates=["txr_1F6kmAAJVYItwOKqV9IWehUH", "txr_2J8lmBBGHJYyuUJqF6QJtkNM"], ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $subscriptionItem = $stripe->subscriptionItems->update( 'si_F2yjdxUlCCOAtv', ['tax_rates' => ['txr_1F6kmAAJVYItwOKqV9IWehUH', 'txr_2J8lmBBGHJYyuUJqF6QJtkNM']] ); ``` ```ruby Stripe.api_key = '<>' subscription_item = Stripe::SubscriptionItem.update( 'si_F2yjdxUlCCOAtv', {tax_rates: ['txr_1F6kmAAJVYItwOKqV9IWehUH', 'txr_2J8lmBBGHJYyuUJqF6QJtkNM']}, ) ``` You can set subscription level tax rates when you create or update subscriptions. Set the tax rates you want to apply by passing the [default tax rate IDs](https://docs.stripe.com/api/subscriptions/object.md#subscription_object-default_tax_rates). The example below updates an existing subscription with two tax rates: ```dotnet StripeConfiguration.ApiKey = "<>"; var options = new SubscriptionUpdateOptions { DefaultTaxRates = new List { "txr_1EO66sClCIKljWvs98IiVfHW", "txr_1EEOvcClCIKljWvsqYb9U0MB", }, }; var service = new SubscriptionService(); Subscription subscription = service.Update("sub_BVxXIrxAAYb7Fb", options); ``` ```go stripe.Key = "<>" params := &stripe.SubscriptionParams{ DefaultTaxRates: []*string{ stripe.String("txr_1EO66sClCIKljWvs98IiVfHW"), stripe.String("txr_1EEOvcClCIKljWvsqYb9U0MB"), }, }; result, err := subscription.Update("sub_BVxXIrxAAYb7Fb", params); ``` ```java Stripe.apiKey = "<>"; Subscription resource = Subscription.retrieve("sub_BVxXIrxAAYb7Fb"); SubscriptionUpdateParams params = SubscriptionUpdateParams.builder() .addDefaultTaxRate("txr_1EO66sClCIKljWvs98IiVfHW") .addDefaultTaxRate("txr_1EEOvcClCIKljWvsqYb9U0MB") .build(); Subscription subscription = resource.update(params); ``` ```node const stripe = require('stripe')('<>'); const subscription = await stripe.subscriptions.update( 'sub_BVxXIrxAAYb7Fb', { default_tax_rates: ['txr_1EO66sClCIKljWvs98IiVfHW', 'txr_1EEOvcClCIKljWvsqYb9U0MB'], } ); ``` ```python import stripe stripe.api_key = "<>" subscription = stripe.Subscription.modify( "sub_BVxXIrxAAYb7Fb", default_tax_rates=["txr_1EO66sClCIKljWvs98IiVfHW", "txr_1EEOvcClCIKljWvsqYb9U0MB"], ) ``` ```php $stripe = new \Stripe\StripeClient('<>'); $subscription = $stripe->subscriptions->update( 'sub_BVxXIrxAAYb7Fb', ['default_tax_rates' => ['txr_1EO66sClCIKljWvs98IiVfHW', 'txr_1EEOvcClCIKljWvsqYb9U0MB']] ); ``` ```ruby Stripe.api_key = '<>' subscription = Stripe::Subscription.update( 'sub_BVxXIrxAAYb7Fb', {default_tax_rates: ['txr_1EO66sClCIKljWvs98IiVfHW', 'txr_1EEOvcClCIKljWvsqYb9U0MB']}, ) ``` ## Dynamically configuring tax rates on each subscription cycle If you add [extra invoice items](https://docs.stripe.com/billing/invoices/subscription.md#adding-upcoming-invoice-items), or sell in enough jurisdictions that tax rates change frequently, you can dynamically calculate and assign tax rates to the subscription’s invoice as it’s created. When a subscription renews and creates an invoice, Stripe sends the `invoice.created` *webhook* event. Stripe [waits approximately one hour](https://docs.stripe.com/billing/subscriptions/webhooks.md#understand) before finalizing the invoice and attempting payment or sending an email. During that delay, the invoice is a [draft](https://docs.stripe.com/api/invoices/object.md#invoice_object-status) and can be edited. Follow the process to [assign tax rates](https://docs.stripe.com/invoicing/taxes/tax-rates.md) to that invoice. If you have credit [prorations](https://docs.stripe.com/billing/subscriptions/prorations.md), use the `proration_details` parameter in the [(Invoice) Line Item](https://docs.stripe.com/api/invoices/line_item.md) object to reference to the original debit line items that the credit proration applies to. Use this reference to adjust the tax amounts correctly for credit prorations. ## Adding tax rates to Checkout You can specify [tax rates](https://docs.stripe.com/billing/taxes/tax-rates.md) (Sales, VAT, GST, and others) in Checkout Sessions to apply taxes to *subscriptions*. * Use fixed tax rates when you know the exact tax rate to charge your customers before they start the checkout process (for example, you only sell to customers in the UK and always charge 20% VAT). * With the *Prices* API, you can use dynamic tax rates when you require more information from your customer (for example, their billing or shipping address) before determining the tax rate to charge. With dynamic tax rates, you create tax rates for different regions (for example, a 20% VAT tax rate for customers in the UK and a 7.25% sales tax rate for customers in California, US) and Stripe attempts to match your customer’s location to one of those tax rates. Set [subscription_data.default_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-default_tax_rates) to apply a default tax rate to a subscription started with Checkout. You can also specify [line_items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-tax_rates) or [subscription_data.items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-items-tax_rates) to apply tax rates to specific plans or invoice line items. Pass an array of [tax rates](https://docs.stripe.com/api/tax_rates/object.md) to [line_items.dynamic_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates). Each tax rate must have a [supported](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates) `country`, and for the US, a `state`. This list matches tax rates to your customer’s [shipping address](https://docs.stripe.com/payments/collect-addresses.md), billing address, or country. The shipping address takes precedence over the billing address for determining the tax rate to charge. If you’re not collecting shipping or billing addresses, your customer’s country (and postal code where applicable) is used to determine the tax rate. If you haven’t passed a tax rate that matches your customer’s shipping address, billing address, or country, no tax rate is applied. ```bash curl https://api.stripe.com/v1/checkout/sessions \ -u <>: \ -d "payment_method_types[]"="{{payment_method_type}}" \ -d "line_items[][price]"="<>" \ -d "line_items[][quantity]"=1 \ -d "line_items[][dynamic_tax_rates][]"="{{FIRST_TAX_RATE_ID}}" \ -d "line_items[][dynamic_tax_rates][]"="{{SECOND_TAX_RATE_ID}}" \ -d "mode"="{{mode}}" \ -d "success_url"="https://example.com/success" \ -d "cancel_url"="https://example.com/cancel" ``` ```ruby <> session = Stripe::Checkout::Session.create( payment_method_types: ['{{payment_method_type}}'], line_items: [{ price: '<>', quantity: 1, dynamic_tax_rates: [ '{{FIRST_TAX_RATE_ID}}', '{{SECOND_TAX_RATE_ID}}', # additional tax rates ], }], mode: '{{mode}}', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', ) ``` ```python <> session = stripe.checkout.Session.create( payment_method_types=['{{payment_method_type}}'], line_items=[{ 'price': '<>', 'quantity': 1, 'dynamic_tax_rates': [ '{{FIRST_TAX_RATE_ID}}', '{{SECOND_TAX_RATE_ID}}', # additional tax rates ], }], mode='{{mode}}', success_url='https://example.com/success', cancel_url='https://example.com/cancel', ) ``` ```php <> $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['{{payment_method_type}}'], 'line_items' => [[ 'price' => '<>', 'quantity' => 1, 'dynamic_tax_rates' => [ '{{FIRST_TAX_RATE_ID}}', '{{SECOND_TAX_RATE_ID}}', // additional tax rates ], ]], 'mode' => '{{mode}}', 'success_url' => 'https://example.com/success', 'cancel_url' => 'https://example.com/cancel', ]); ``` ```java <> Map params = new HashMap(); ArrayList paymentMethodTypes = new ArrayList<>(); paymentMethodTypes.add("{{payment_method_type}}"); params.put("payment_method_types", paymentMethodTypes); ArrayList> lineItems = new ArrayList<>(); HashMap lineItem = new HashMap(); lineItem.put("price", "<>"); lineItem.put("quantity", 1); ArrayList taxRates = new ArrayList<>(); taxRates.add("{{FIRST_TAX_RATE_ID}}"); taxRates.add("{{SECOND_TAX_RATE_ID}}"); // additional tax rates lineItem.put("dynamic_tax_rates", taxRates); lineItems.add(lineItem); params.put("line_items", lineItems); params.put("mode", "{{mode}}"); params.put("success_url", "https://example.com/success"); params.put("cancel_url", "https://example.com/cancel"); Session session = Session.create(params); ``` ```javascript <> const session = await stripe.checkout.sessions.create({ payment_method_types: ['{{payment_method_type}}'], line_items: [{ price: '<>', quantity: 1, dynamic_tax_rates: [ '{{FIRST_TAX_RATE_ID}}', '{{SECOND_TAX_RATE_ID}}', // additional tax rates ], }], mode: '{{mode}}', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', }); ``` ```go <> params := &stripe.CheckoutSessionParams{ PaymentMethodTypes: stripe.StringSlice([]string{ "{{payment_method_type}}", }), LineItems: []*stripe.CheckoutSessionLineItemParams{ &stripe.CheckoutSessionLineItemParams{ Price: stripe.String("<>"), Quantity: stripe.Int64(1), DynamicTaxRates: stripe.StringSlice([]string{ "{{FIRST_TAX_RATE_ID}}", "{{SECOND_TAX_RATE_ID}}", // additional tax rates }), }, }, Mode: stripe.String("{{mode}}"), SuccessURL: stripe.String("https://example.com/success"), CancelURL: stripe.String("https://example.com/cancel"), } session, err := session.New(params) ``` ```dotnet <> var options = new SessionCreateOptions { PaymentMethodTypes = new List { "{{payment_method_type}}", }, LineItems = new List { new SessionLineItemOptions { Price = "<>", Quantity = 1, DynamicTaxRates = new List { "{{FIRST_TAX_RATE_ID}}", "{{SECOND_TAX_RATE_ID}}", // additional tax rates }, }, }, Mode = "{{mode}}", SuccessUrl = "https://example.com/success", CancelUrl = "https://example.com/cancel", }; var service = new SessionService(); Session session = service.Create(options); ``` [subscription_data.default_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-subscription_data-default_tax_rates) and [line_items.tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-tax_rates) cannot be used in combination with [line_items.dynamic_tax_rates](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-line_items-dynamic_tax_rates). You can use Stripe’s data exports to populate the periodic reports required for remittance. Visit [Tax reporting and remittance](https://docs.stripe.com/billing/taxes/tax-rates.md#remittance) for more information. ## See Also * [Determining customer locations](https://docs.stripe.com/tax/customer-locations.md) * [Customer tax IDs](https://docs.stripe.com/billing/customer/tax-ids.md) * [Reporting and filing](https://docs.stripe.com/tax/reports.md) * [Tax Rates](https://docs.stripe.com/billing/taxes/tax-rates.md) * [Tax Rates on Invoices](https://docs.stripe.com/invoicing/taxes/tax-rates.md)