Collecting Taxes With Stripe

"How do I collect taxes with Stripe?"

If you're in a state/country where you have to collect sales taxes, I'm sure you've asked this question. Thankfully, Stripe makes it simple. All you have to do is update one attribute on your customers' Stripe::Subscription and it's done.

To automatically collect taxes from your customers, just set the tax_percent attribute, like this:

customer = Stripe::Customer.retrieve('cu_123abc')
sub = customer.subscriptions.retrieve('sub_123abc')

sub.tax_percent = 5
sub.save

When Stripe attempts to pay this customer's next invoice the first time, they'll automatically calculate how much tax to add on. You'll see this amount in the tax attribute of the Stripe::Invoice, as well as being included in the amount_due and total attributes:

inv = Stripe::Invoice.retrieve('inv_12345')

inv.subtotal #=> 500
inv.tax_percent #=> 5
inv.tax #=> 25
inv.amount_due #=> 525

You also have the option of not using tax_percent and instead tacking on an invoice item in response to invoice.created webhook events, but that has some significant drawbacks. First, you have to actually build the code to make that happen. Second, depending on where you're located, the tax you tack on this way won't be properly reported to your tax agency, nor will it be simple to extract when you're showing invoices to customers and looking at your data in reporting tools like Baremetrics or FirstOfficer.

One more thing to note: tax_percent only works for Stripe subscriptions. If you're making one-time charges you'll have to calculate the tax as appropriate and add it to the amount you're charging manually.

Mastering Modern Payments

Build a Better Payment System

Get a free five part email course all about Stripe and Rails, including the first three chapters of Mastering Modern Payments.


No spam. Unsubscribe at any time.
Pete Keen Portrait Pete Keen has been professional software developer for a decade, building payment systems and other software for companies large and small. He blogs here and at petekeen.net.