Comments (8)
This is also easily reproduced (at least on our site) by adding 2 different 12% moms products and increasing the item amount to a total of 4. It works fine when there only is one 12% moms product in the cart, but as soon as there are two different it breaks.
from billmate-checkout-for-woocommerce.
Based on the last screenshot I posted, the calculation for the sums in the error message is the following.
- Each product above costs 39 SEK inc VAT. VAT is 12%. Price ex VAT is 34,821428571. The total price ex VAT for 4 of the products is (39*4)/1,12 = 139,285714284 SEK.
- Shipping cost is 29 SEK inc VAT. VAT is 25%. Price ex VAT is 23,2 SEK.
- Invoice fee is 12 SEK inc VAT. VAT is 25%. Price ex VAT is 9,6 SEK.
Adding the price ex VAT for each above line:
139,285714284 + 23,2 + 9,6 = 172,085714284 SEK.
The "Beräknat totalt" is 172,08 in the error message, which means that it probably is rounded down via floor(). The "Tillhandahållet totalt" is using round().
So my theory is that Billmate is flooring the numbers on their end and the plugin is instead rounding them.
Edit: This ONLY happens when the third decimal is 5.
from billmate-checkout-for-woocommerce.
Final update with proposed solution
How to reproduce
- Make sure that you have a 12% MOMS/VAT rule set up in WooCommerce.
- Create 2 different products. They need to have 12% VAT and 39 SEK price inc VAT.
- Add both products to your cart. One of them needs 1 in quantity and the other one 3 in quantity.
- Go to checkout.
- You should now get an error that total sums are diffing by 0,01 SEK (it's presented in öre though).
Why is this happening?
In class-bco-cart-articles-helper.php, the function get_without_tax is not rounding up if the line_total is X.XX5. If the line_total would be 125.235, it would be rounded to 125.23. The Billmate API seems to round these numbers up instead, so it'd expect 125.24.
This ONLY happens if the third decimal of the order price sum without tax is 5.
Proposed fix
While searching around I found the answer in the top voted user contributed notes:
https://www.php.net/manual/en/function.round.php#114573
Basically we want to force always rounding up on the third decimal, so it can handle 0.005 floats.
/**
* Get cart row total articles price excluding tax.
*
* @param array $cart_item cart item.
* @return int $item_price Item price excluding tax.
*/
public static function get_without_tax( $cart_item ) {
$items_subtotal = $cart_item['line_total'];
$fig = (int) str_pad('1', 4, '0');
return round((ceil($items_subtotal * $fig) / $fig) * 100);
}
The fix seems to work fine with all different type of carts:
- Only 12% VAT products
- Only 25% VAT products
- Only 0% VAT products
- A mix of all above
- All above with % discount codes
Ping @NiklasHogefjord @andyjohansson
from billmate-checkout-for-woocommerce.
I've temporarily implemented the above fix in our production environment. No issues have been reported by customers so far and orders look correct. It has been live for approximately 12 hours. Usually we would've gotten around a lot of e-mails regarding this issue in that timeframe.
I do recommend that you test it yourselves too. I haven't tried it with 6% MOMS/VAT products, but it shouldn't in theory be any different.
Update: Still no issues as of 12:00 today.
from billmate-checkout-for-woocommerce.
Update on proposed fix & more debugging
The above fix works fine when the third decimal is 5, but we've now run into cases where even later decimals are at 5 – so the proposed fix isn't working in those cases.
I've been discussing with Paul at Billmate regarding this and one of the things we wanted to try was updating classes/requests/helpers/order/class-bco-order-cart-helper.php row 49.
Original:
public static function get_order_cart_total( $order ) {
return array(
'withouttax' => self::get_total_without_tax( $order ),
'tax' => self::get_total_tax( $order ),
'rounding' => 0,
'withtax' => self::get_total_with_tax( $order ),
);
}
Modified:
public static function get_order_cart_total( $order ) {
return array(
'withouttax' => self::get_total_without_tax( $order ),
'tax' => self::get_total_tax( $order ),
'rounding' => self::get_total_with_tax( $order ) - self::get_total_without_tax( $order ) - self::get_total_tax( $order ),
'withtax' => self::get_total_with_tax( $order ),
);
}
Result:
Unfortunately the rounding value was 0 even after changing, so the rounding error happens earlier. Will update if I find the culprit.
from billmate-checkout-for-woocommerce.
Could you take a look at this @NiklasHogefjord?
from billmate-checkout-for-woocommerce.
@DanielMarklund, I have tried to recreate the issue but it is working without any problems for me.
I have followed your instructions (1 x 39 kr incl 12% VAT + 3 x 39 kr incl 12% VAT + shipping 29 kr incl 25% VAT + invoice fee 12 kr incl 25% VAT) and this is what is being sent in to Billmate:
{
"credentials": {
"id": "removed",
"hash": "removed",
"test": "false",
"version": "2.2.2",
"client": "WooCommerce_v2:1.1.0.1"
},
"data": {
"Articles": [{
"artnr": "test1234",
"title": "Billmate rounding 2",
"quantity": 1,
"aprice": 3482,
"withouttax": 3482,
"taxrate": 12,
"discount": 0
}, {
"artnr": "test12345",
"title": "Billmate rounding 1",
"quantity": 3,
"aprice": 3482,
"withouttax": 10446,
"taxrate": 12,
"discount": 0
}],
"Cart": {
"Total": {
"withouttax": 17208,
"tax": 2492,
"rounding": 0,
"withtax": 19700
},
"Shipping": {
"withouttax": 2320,
"taxrate": 25
},
"Handling": {
"withouttax": 960,
"taxrate": 25
}
},
"PaymentData": {
"number": "109"
}
},
"function": "updateCheckout"
},
"timeout": 10
}
What is your Rounding option set to in the --> WooCommerce --> Settings --> Tax tab? Mine looks like this:
from billmate-checkout-for-woocommerce.
Closing this since we haven't heard back from @DanielMarklund. Please feel free to re-open the issue it you still are experiencing issues with this.
from billmate-checkout-for-woocommerce.
Related Issues (20)
- Move #bco-wc-form inside the checkout form HOT 3
- Validate phone number input HOT 1
- Öppna Mobilt BankID"/IOS
- Disable checkout if no delivery method exists. HOT 1
- Critical: Selected payment method not always stored HOT 7
- Delivery address not always saved in WooCommerce order (but it's saved in Billmate Online) HOT 5
- Billmate checkout hash is missing HOT 4
- Test titel
- Woocommerce order loops "invoice fee" in order view but not in BO.
- As a customer, i want to be able to handle orders from the nordic countries HOT 2
- Make private magic functions public HOT 1
- Merchant has reported that the invoice fee is written twice. HOT 2
- customer at times missing clarification what purchase was made. HOT 3
- If you change currency mid purchase will that result in different currencies in BO and the store. HOT 2
- Include Cart.Total.withouttax not always match articles withouttax HOT 1
- Checkout->continue without PNO and then selecting trustly will redirect you back to the checkout HOT 2
- Customer not redirected to woocommerce native checkout if country not allowed. HOT 1
- Use Total.rounding HOT 1
- Merchant gets link but cannot get redirected.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from billmate-checkout-for-woocommerce.