-
Notifications
You must be signed in to change notification settings - Fork 9.4k
UPS Option to include TAX in rate #11707
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
UPS Option to include TAX in rate #11707
Conversation
The current UPS Module uses the UPS Rate excluding TAX to use as the rate charged to the customer during checkout. This modification adds an additional config option so you can choose whether to request and include TAX information from UPS in the rate or not. This modification is especially useful for businesses who are not TAX registered and cannot claim back the TAX charged by UPS. This allows them to pass on the TAX costs to the customer as part of the overall shipping rate.
Remove blank line that was added by mistake
This pull request adds enough lines of code to the function to trigger the excessive method length check in PHPMD. The majority of the code in the function is not mine and I do not want to change stuff for the sake of passing this check. My goal was to make the changes with as little impact on the existing code base as possible.
I branched 2.2-develop for this fix, but if approved can it be merged into 2.3-develop aswell so future releases get the changes. |
Hi @gwharton , thanks for your contribution. A couple things:
|
Changed admin panel label from TAX to Tax
Here are the responses received for the following combinations with negotiated rates set For a UK-UK shipment (taxes applicable) Include Tax in rate = NO
Include Tax in rate = YES
For a UK-USA shipment (taxes NOT applicable) Include Tax in rate = NO
Include Tax in rate = YES
|
And the same responses received without negotiated rates set For a UK-UK shipment (taxes applicable) Include Tax in rate = NO
Include Tax in rate = YES
For a UK-USA shipment (taxes NOT applicable) Include Tax in rate = NO
Include Tax in rate = YES
|
The code change checks for the presence of the TaxCharges field. If the field is present and the option to include tax in rate is set to Yes, then the MonetaryValue of the TaxCharges field is added to the rate. There is an alternative method to get the total including tax as if tax is applicable to the rate then the additional field "TotalChargesWithTaxes" could be used instead of summing the two fields to obtain the total including tax, but I chose not to use this option to minimise the amount of code changes. Let me know if this method is preferred and I will update. |
@gwharton sorry for the delay. I think this will all work, but I'm wondering if it's better for naming consistency to name "total" and "total with taxes" fields like this: Negotiated rates = ON, Include Tax in Rate = ON Negotiated rates = OFF, , Include Tax in Rate = ON One last thing: I'd prefer to change the admin panel setting name slightly. Currently the name |
Updated admin panel label to "Request Tax-Inclusive Rate" Added comment "When applicable, taxes (sales tax, VAT etc.) are included in the rate". The above comment seems more appropriate than the one suggested as "When available, this value is returned in addition to totals without tax" would mean nothing to the end user. All he knows about/cares about is that the end total includes any taxes or not.
…aths. Previously the routine obtained the base cost, and then if taxes existed, it added the tax on to get the total. Now the function checks for the presence of the "TotalChargesWithTaxes" field. If present and the "Request Tax-Inclusive Rate" option is set, then the total is obtained from the "TotalChargesWithTaxes" field. If not present, or the "Request Tax-Inclusive Rate" option is not set, then the total is obtained from the original field which does not include tax. Also moved the setting of the "responseCurrencyCode" variable into the same logic. This ensures that the correct response currency code is always set correctly based on the value returned from UPS. Previously "responseCurrencyCode" would only have ever been set correctly if negotiated rates were never used.
@misha-kotov I have updated the labelling on the admin panel to be inline with your comments, although I have proposed a slightly different comment to the suggested one. I have also changed the logic to get rid of the maths. There is no point in obtaining the base charge, then the taxes and adding the two together, when the total including tax is also returned from UPS and can be used directly. I have also fixed a problem with the setting of the responseCurrencyCode which was not working correctly when negotiated rates were used, and was made worse by my original commit. With regard to the naming of the fields in the response, these are the field names that are returned by UPS in their API and are beyond our control I am afraid. They're not consistent, but we are stuck with them. |
Updated admin panel label and comment in i18n
Hi @gwharton thank you for update. Could you please cover your improvement with integration tests so that we can proceed with PR acceptance |
@gwharton thanks for your edits. Now that you changed the math calculations, can you provide examples of how it looks now? The 4 combinations/examples you gave above were very useful. |
@misha-kotov There are 8 possible routes through the code. I will summarise all 8 here. Option 1 Negotiated Rates Option set to "NO" XML Snippet received back from UPS Servers
In this combination
Option 2 Negotiated Rates Option set to "NO" XML Snippet received back from UPS Servers
In this combination
Option 3 Negotiated Rates Option set to "NO" XML Snippet received back from UPS Servers
In this combination
Option 4 Negotiated Rates Option set to "NO" XML Snippet received back from UPS Servers
In this combination
Option 5 Negotiated Rates Option set to "YES" XML Snippet received back from UPS Servers
In this combination
Option 6 Negotiated Rates Option set to "YES" XML Snippet received back from UPS Servers
In this combination
Option 7 Negotiated Rates Option set to "YES" XML Snippet received back from UPS Servers
In this combination
Option 8 Negotiated Rates Option set to "YES" XML Snippet received back from UPS Servers
In this combination
I'll take a look at the integration tests now, and make sure all 8 routes are covered by a test. |
Unit tests added to cover all 8 possible options.
@okorshenko I have added unit tests to cover the code changes. The unit tests use actual live XML response files obtained from the UPS servers, and are injected/fed through the xml parsing routines via the normal collectRates method with the various options set to cover all of the above 8 scenareos. |
This reverts commit 837b5fa.
Unit tests added to cover all 8 possible options. (That work this time)
Fixed Codacy issues
- fixed code style
…nclude TAX in rate #14217
…nclude TAX in rate #14217
Accepted Public Pull Requests: - #14231: [Forwardport] Add missing implementation for applySortOrder() (by @rostyslav-hymon) - #14229: [Forwardport] catalog:images:resize CLI command fix (by @rostyslav-hymon) - #14228: [Forwardport] fix incorrect phpdoc return type (by @rostyslav-hymon) - #14227: [Forwardport] Use `^1.4` for `composer/composer` (by @rostyslav-hymon) - #14225: [Forwardport] Send order email for Braintree Paypal orders (by @dimonovp) - #14223: [Forwardport] SQL query is printed into browser in case of exception (by @rostyslav-hymon) - #14217: [Forwardport] of PR-#11707 to 2.3-develop UPS Option to include TAX in rate (by @gwharton) Fixed GitHub Issues: - #13631: Totals sort order is not respected in customer account order view (reported by @schmengler) has been fixed in #14231 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. a7ff305 - #12792: [2.1.10] No order confirmation email after paying with PayPal Express (reported by @aeu) has been fixed in #14225 by @dimonovp in 2.3-develop branch Related commits: 1. 413b898 2. 2b64618 - #13778: Braintree Paypal Method No Order Confirmation Email Sent (reported by @snoroozi) has been fixed in #14225 by @dimonovp in 2.3-develop branch Related commits: 1. 413b898 2. 2b64618 - #13385: SQL query is printed into browser in case of exception (reported by @alexkuk) has been fixed in #14223 by @rostyslav-hymon in 2.3-develop branch Related commits: 1. f618e14
The current UPS Module uses the UPS Rate excluding TAX to use as the rate charged to the customer during checkout.
This modification adds an additional config option so you can choose whether to request and include TAX information from UPS in the rate or not.
This modification is especially useful for businesses who are not TAX registered and cannot claim back the TAX charged by UPS. This allows them to pass on the TAX costs to the customer as part of the overall shipping rate.
Description
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist