ethercreative / web-payments

Web Payments for Craft Commerce
Other
5 stars 7 forks source link

Invalid value for paymentRequest() #4

Closed SamHoltby closed 5 years ago

SamHoltby commented 5 years ago

Issue Description

I'm experiencing an issue when trying to buy a product that has cents. For example, 17.99.

In the JS console I get the error Invalid value for paymentRequest(): displayItems.0.amount should be an amount in the currency's subunit. You specified: 1798.9999999999998.

I managed to track down where the issue is happening but have no idea what is causing it. In the file vendor\ether\web-payments\src\web\Variable.php on line 103 the $options variable is converted in to json with the method json_encode. This is where the line item sale price changes from 1799 to 1798.9999999999998.

Steps to Reproduce

  1. Install and setup web-payment plugin.
  2. add product with price of 17.99.
  3. Add product to cart and go to checkout.
  4. View JS console for errors.

Expected Results

Apple Pay and Google Pay work on mobile with prices of 17.99.

Additional Information

Current Work arround

Use prices that do not have decimal places.

SamHoltby commented 5 years ago

Thanks!

codal-mpurohit commented 3 years ago

Hi, @SamHoltby you can work around using *Math.round(your_amount 100)**