#Chris Geelhoed
1 messages ยท Page 1 of 1 (latest)
Hi there
Yes this would be the proper workaround
There is no limit on amount of tax rates so you should be fine there
Ok, great! As a way to investigate this workaround, we created a script that does the following for each US ZIP code:
- Uses the upcoming invoice API with automatic tax on to get the automatic tax rate IDs
- Takes the automatic tax rate ID returned above and makes another API request to get the tax rate percentage, description, etc
- Uses the data fetched above to create our own tax rate
However, after a while we started to receive 404 (eg No such tax rate: 'txr_1Lim0pLdg9njNQWDK73VrHPc') responses when we tried to look up the tax rate details by the automatic tax rate ID. I'm guessing your system has protection to prevent scripts from crawling all your tax rates? How do we prevent getting 404s when we apply this system to production?
I just ran my script again, and got this:
"No such tax rate: 'txr_1LjsulLdg9njNQWDyUx6FIf2'"
req_pLGIm7qz7PXqHy
Thanks, looking
Hmmm
Are you sure your script isn't grabbing tax rates from the upcoming invoice preview?
As opposed to the tax rate you are actually creating?
I want to get the tax rates from the upcoming invoice preview, so I know the correct tax to apply
Ah but those don't actually exist
Because it is a preview
So you can't retrieve those
You need to create the associated tax rate
Then retrieve that tax rate you actually created (not the one from the upcoming invoice preview)
But I need to know the correct tax percentage to apply before I can create my own tax rates
Right but you are getting that information from the preview, no?
I thought that was your flow...
1/ preview upcoming invoice based on address to know tax rate
2/ create your own tax rate that mirrors the above tax rate
3/ use that tax rate you created on the Subscription
Right now you appear to be retrieving the tax rate from step 1, no?
Instead of step 2?
The upcoming invoice response does not return the actual tax percentage, just the automatic tax rate ID
So those 2 API requests are both part of step 1
Huh I must be mis-remembering what the upcoming invoice returns in that case
One sec
Ah okay yeah I forgot โ we only give you the amount for tax, not the % rate.
So yeah this is an issue
Because you can't retrieve tax rates from an invoice preview
Since they have never actually been created
So I think in this case you would have to determine the rate based on the amount returned in the Preview
Ok. For whats its worth this method of taking the invoice preview tax rate and using that to look up the tax rate details did work previously. Thats the method we were planning to use to show customers the taxes they will be paying before they subscribe to our product
Do you have an example of it working previously?
I see ~600 tax rates in your account... are you sure you weren't retrieving tax rates that did exist in the past? This really should never have worked unfortunately
Yes I'm 100% sure. If you check the tax percent and details assigned to those tax rates you will see they match the automatic tax rates exactly.
Okay if you have a request ID of a successful retrieval I would love to look at it to see what changed in that case
The method of using the tax total and the invoice total to compute the percentage is a good idea. We also want to use the description on the automatic tax rate as well however
Hmm wait a sec
Doh
You can expand the tax rate
When you preview the upcoming invoice
Yeah that's what you want
Totally forgot that was expandable
I tried that, I don't think upcoming invoices are expanding in the same way that existing invoices are
I just tested and it works fine
Ah there isn't a description
Hmm wonder why that is actually
But you get the percentage
What programming language did you expand the tax rates in? I'm using the PHP client and I have not had much luck with that so far. I'm using syntax similar to this - just wondering where the "expand" key should go.
$stripe->invoices->upcoming([
'customer' => 'cus_MSniqFfPKIjD9k',
]);
Yeah it should be $stripe->invoices->upcoming( 'cus_MSniqFfPKIjD9k', ['expand' => ['total_tax_amounts.tax_rate]] );
Oops
Missed a bracket
(edited)
Docs on expanding are here: https://stripe.com/docs/expand
Though actually those snippets use our old PHP library. So you can reference https://stripe.com/docs/api/expanding_objects?lang=php to see the new client library in use.
Ok, I will try that now
๐
Yeah doesn't look like we set description at all for auto tax
Since it is an arbitrary string for a tax rate
Think maybe you mean using display_name?
Which will indicate "Sales Tax" or "VAT" or the according tax
I believe that there is also some attribute that indicates the jurisdiction of the tax rate (eg the state in some cases)
We'd like to get that as well
That is returned when expanding via the preview
I'm running into a "Got unexpected keys in options array: expand" when I use this syntax with the PHP client:
$testInvoice = $client->invoices->upcoming(
$testInvoiceParams,
['expand' => ['total_tax_amounts.tax_rate']]
);
(sorry, not sure how to format code)
you need to include expand as part of the $testInvoiceParams, not in it's own array
Ok, trying that...