-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix tax calculation arguments, other tax fixes #4811
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
Fix tax calculation arguments, other tax fixes #4811
Conversation
being passed to calculateOrderTaxes function Changes for tax plugins to be aware of: - Will now be called even when there is not yet a shipping address. Return `null` if you are not able to calculate due to no shipping address or any other missing information. - Called with a stable order-like schema, which now includes `originAddress`, `currencyCode`, `fulfillmentPrices`, and `price` on every item - Change function name from `calculateOrderGroupTaxes` to `calculateOrderTaxes`
better than recalculating whenever we query those fields
We expect other plugins to need the same transformations
|
@Akarshit Please test your plugin against this branch, and note the changes you'll need to make described in the PR description. |
|
@aldeed Would it make sense to add the following in the CommonOrder:
|
|
|
I was curious why billing address would be required, but this quote from the Radial docs explains it.
|
|
@Akarshit I added all except discounts because the current discounts handling is janky and not calculated by item or by group. A proper promotions engine is on the roadmap very soon, so we can make sure the new promotions get added to CommonOrder at that time, and then tax plugins can be updated to handle them. |
|
@aldeed While checking this, I found that billingAddress is always |
|
@Akarshit I can't reproduce that. Tested with example and Stripe payment from classic UI, and If Radial requires |
nnnnat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
|
Yes, I realized that and typed something similar but forgot to press enter. :( |
Resolves #4807
Impact: minor
Type: feature
Changes
The order data being passed to tax calculation functions was not consistent due to differences between Cart and Order schemas. This PR introduces a new schema CommonOrder, which represents one actual or potential order for one shop. New transforms allow a cart fulfillment group or an order fulfillment group to be converted to a CommonOrder. Tax calculation functions only need to understand and deal with CommonOrders.
This was implemented in a generic way because we expect to need this same transformation for shipping restrictions, surcharges, and other similar calculations that do not need to care whether they're calculating for a Cart or an Order.
Breaking changes for custom tax plugins
There are breaking changes only within the current RC7 release, since prior PRs were merged. Custom tax plugins should do the following:
calculateOrderGroupTaxestocalculateOrderTaxescalculateOrderTaxeswill be called with{ context, order }rather than{ context, group }, whereorderis similar to whatgroupwas, but is guaranteed to be in the newCommonOrderschema, whether being called for a Cart or an Order. Among other things, a common order hasoriginAddressandcurrencyCodeproperties, and the items are guaranteed to havepriceproperty set.calculateOrderTaxesto now be called even whenshippingAddressisnull. Returnnullif you cannot calculate taxes. In most cases, tax plugins will immediately check whethershippingAddressisnulland if so, returnnull.calculateOrderTaxesfunction may now setcalculatedByTaxServiceNameproperty in thetaxSummarythat is returned. Set this to the name of your tax service (same as intaxServicesarray inregisterPackage). One good reason to set this is to determine whether tax was calculated by your tax service after the order is placed. Depending on the type of tax integration, you may need to inform the third-party tax service that the order was placed. UsereferenceIdto store the corresponding calculation ID from the third-party system if necessary.Testing
out.
calculateOrderTaxesfunction for the included "custom rates" service and verify that theorderargument is the same whether being called for a cart (such as when adding items) or for an order (such as when completing checkout).