Automattic / woocommerce-payments

Accept payments via credit card. Manage transactions within WordPress.
https://wordpress.org/plugins/woocommerce-payments/
Other
171 stars 69 forks source link

WooPayments Sends Wrong Total (Decimal Places) to Google/Apple Pay When Using Hungarian Forint #8277

Open ldr2273 opened 6 months ago

ldr2273 commented 6 months ago

Describe the bug

When using Hungarian Forint as a currency and setting the decimal place to "0" (because Hungarian Forint doesn't have cents), Google and Apple Pay still show the total with decimal places.

To Reproduce

  1. Head to WooCommerce > Settings > General and set the store currency to Hungarian Forint (Ft). Set the number of decimals to 0.
  2. Enable Google/Apple Pay with WooCommerce Payments.
  3. Add a product to cart and see that there are no decimal places in the total.
  4. Attempt to pay with Google or Apple Pay and see that the total now has decimal points.

This is a bit odd considering Ft doesn't have cents.

Annotation on 2024-02-26 at 12-18-21

Expected behavior

It would be expected that the total would pass to Google/Apple Pay without decimal places.

Desktop (please complete the following information):

All latest versions.

Additional context

This does happen with Stripe as well, but after chatting with the developers, it appears the payment request buttons and the total that gets sent is from the WooPayments side.

ldr2273 commented 6 months ago

7764001-zen

htdat commented 6 months ago

This issue impacts Express checkout buttons, so assigning to @Automattic/heisenberg (based on team responsibilities Pc2DNy-3z-p2) cc team lead @FangedParakeet.

Assigning as part of Gamma Triage process PcreKM-yM-p2.

timur27 commented 6 months ago

Thanks for the report @ldr2273! I was passing by and checked this a bit further. I can see that the problem happens regardless of the currency and is tied to the decimal number setting of the currency under WooCommerce -> General -> Currency options, the place you also mentioned. Below is the example with EUR

image

Having said that, although some currencies technically will always have decimals, WooPayments needs to handle any other decimals setting for a currency coming from WooCommerce.

Additional findings

While testing this I've noticed that decimal setting might lead to some bad outcomes in checkout blocks:

EUR with zero decimals ⬇️

image

EUR with one decimal ⬇️

image

This problem happens because Stripe expects all API requests' amounts to be provided in a currency’s smallest unit. . E.g. for EUR 20 it should be 20000 while we're sending the plain total (20) in this place..

Summary

  1. I can reproduce the problem described in this issue, and we need to fix it for every currency.
  2. Another (in my opinion, more critical) problem was found in Blocks, which also needs to be solved. The complexity of the fix should be around 2SP

cc @FangedParakeet

ldr2273 commented 6 months ago

@timur27 - thanks for the feedback and additional testing!

frosso commented 2 months ago

I can confirm that the PRB implementation with tokenized carts will fix the issue for the majority of currencies, regardless of the number of decimals in the configuration:

Euro with one decimal:

Screenshot 2024-06-21 at 6 13 20 PM

Euro with zero decimals:

Screenshot 2024-06-21 at 6 12 34 PM

The problem will be fixed also if the currency selected is a zero-decimals currency within Stripe:

Screenshot 2024-06-21 at 6 22 45 PM

We just need these changes for the tokenized cart implementation: https://github.com/Automattic/woocommerce-payments/pull/8998

CC @FangedParakeet