We multiply the amount by 100 regardless of how many fraction digits a currency has.
Same bug as the one in Stripe: #2913605: Yen currency is processed incorrectly (100x the input value). Once that one is fixed, the fix can probably be copied here.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2928926-6.patch | 1.58 KB | flocondetoile |
Comments
Comment #2
bojanz commentedCommerce 2.2 now has a $this->toMinorUnits() helper on the payment gateway base, let's use it.
Reference: #2928972: Add PaymentGatewayBase::toMinorUnits().
Comment #3
flocondetoileAttached the related tiny patch.
Comment #4
bojanz commentedThe method already returns an int, the cast is unnecessary.
toMinorUnits() is a protected function, so this can only crash. We'll need to patch Commerce to make it public: #2944281: PaymentGatewayBase::toMinorUnits() should be a public method.
Comment #5
flocondetoileYes, I saw this after but didn't find time to report/fix it. Deadline was very short. I will update the patch.
Comment #6
flocondetoilePatch updated.
Comment #7
flocondetoileTested #6.
Got an error when submitting a payment
InvalidArgumentException: Integer expected. Amount is always in cents in Ogone\AbstractPaymentRequest->setAmount() (line 160 of .../vendor/marlon-be/marlon-ogone/lib/Ogone/AbstractPaymentRequest.php).Looks like the cast (int) is necessary
Comment #8
flocondetoileSeems that toMinorUnits return à float value (the round method()) and not an integer.
Comment #9
flocondetoileTested #3 with patch from #2944281: PaymentGatewayBase::toMinorUnits() should be a public method.
Works fine.
Comment #11
bojanz commentedWon't have time to commit the Commerce patch in the next day or two, committed the first portion of the fix:
This at least reduces the bug for people.
Comment #12
flocondetoileHi Bojanz,
As reported in #7, the cast (int) seems necessary in fact. Even if the round method should return an integer because of the precision 0, the value returned is typed as a float (or a string ?) and the AbstractPaymentRequest->setAmount() method check this value with the is_int() method which expect strictly an integer (https://github.com/marlon-be/marlon-ogone/blob/eefe735d7113a3ce8023d7c0a...).
The patch #3 is the patch to use. Not #6
Comment #14
flocondetoilePostpone the issue until #2944281: PaymentGatewayBase::toMinorUnits() should be a public method is committed.
Comment #15
flocondetoileComment #16
flocondetoileOnce this patch committed, I would release a first beta.
Comment #17
eric_a commentedSo #2944281: PaymentGatewayBase::toMinorUnits() should be a public method was fixed in October and is in Commerce 2.15 (released 6 November 2019).
Comment #18
flocondetoileYes I want first release a first beta without this patch. And then commit it, release a new beta with a dependency on commerce ^2.15. But we have currently others (greater) issues to fix.
Comment #20
flocondetoileA first beta release follow
Comment #22
pstewart commentedThis issue needs to reopen as #6 only fixes payments amounts set during checkout in
ECommerceOffsiteFormandDirectLink::createPayment- it misses other operations such as post-checkout payment capturing and refunds inOperationsTrait. It also notewortht that the int cast is also actively harmful in the unmodified code due to the way php rounds in a cast (e.g. php -r 'print (int)(39.98 * 100);'), however is safe when toMinorUnits is used as the output of round() is reliable.I need to put a fix for this into production as soon as I can so will prepare a patch against current dev.
Comment #23
flocondetoilePlease create a follow up. This issue is closed.
Comment #24
pstewart commentedSee attached patch.
Comment #25
pstewart commentedSorry, didn't see your post before uploading. Will open new issue now
Comment #26
pstewart commentedHiding patch from #24 as this has now been resubmitted to #3192390