-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make tax calculation async #307
Comments
Spent a bit of time experimenting with this. It's a hard problem:
This issue need quite a bit of thought and design to get right. The goal is to enable more powerful tax calculations using async user code, which could e.g. call out to a 3rd party tax service (e.g. https://www.taxjar.com/) or perform some other lookup e.g. in a DB or file system. Since the tax on any given ProductVariant depends on the Customer's Zone (as determined by the However, we do store per-Channel prices for each variant, and each Channel has a This would mean that simply querying ProductVariants would not invoke Then at some stage of the checkout, e.g. when moving to |
Adding in a real-world use case that came up on Slack:
I think we need to distinguish between 2 separate concerns here:
|
After the recent overhaul of tax handling (#573) I have a much clearer understanding of each part and I've concluded that the TaxCalculationStrategy is incorrectly named. It is not really calculating taxes - it is calculating the price of a ProductVariant. Its job can be stated as:
That's all it does. Status quo: summarySo we have 3 distinct things at play regarding the pricing / taxes on products in an order:
Required Changes
|
Relates to #307 BREAKING CHANGE: The TaxCalculationStrategy return value has been simplified - it now only need return the `price` and `priceIncludesTax` properties. The `ProductVariant` entity has also been refactored to bring it into line with the corrected tax handling of the OrderItem entity. This will require a DB migration. See release blog post for details.
Relates to #307. BREAKING CHANGE: The `TaxCalculationStrategy` has been renamed to `ProductVariantPriceCalculationStrategy` and moved in the VendureCofig from `taxOptions` to `catalogOptions` and its API has been simplified. The `PriceCalculationStrategy` has been renamed to `OrderItemPriceCalculationStrategy`.
Is your feature request related to a problem? Please describe.
Currently the
TaxCalculationStrategy.calculate()
method is sync. This is very limiting because it prevents the use of 3rd-party tax calculation service APIs and even custom local calculation methods which e.g. require a database lookup.Describe the solution you'd like
Make the method async - able to return a result or a Promise of the result. This change will have a knock-on effect on several code paths related to calculating order totals, as the introduction of an async step then will require the entire order calculation logic to go async.
The text was updated successfully, but these errors were encountered: