Closed canny[bot] closed 3 years ago
This issue has been linked to a Canny post: Stripe + Fee Recovery should round up the last digit so it matches the amount correctly :tada:
I think I've tracked where it is going wrong:
// includes/gateways/stripe/includes/class-give-stripe-gateway.php
public function format_amount( $amount ) {
return Money::of( $amount, give_get_currency() )->getMinorAmount();
}
price passed in is 257.78 formatted amount returned is 25777
Failing test to confirm the bug:
public function testMinorAmountIsNotChanged() {
$money = Money::of( 257.78, 'USD' );
$this->assertEquals( 25778, $money->getMinorAmount() );
}
1) MoneyTest::testMinorAmountIsNotChanged
Failed asserting that 25777 matches expected 25778.
I'll add that this is not specific to Fee Recovery, rather it is related to decimal values which can be reproduced with the Legacy Form Templates (which does support a decimal value as a custom donation amount).
As I expected, there is a float value being cast as an integer, which has the potential of data loss - due to the way floating point precision is handled. I've run across this before in Ninja Forms when making charges using Stripe (off by one cent).
Sometimes, depending on the amount donated using Stripe + Fee Recovery, GiveWP will pass the wrong amount to Stripe, although it shows the correct amount on the GiveWP dashboard. Example:
https://givewp.canny.io/admin/board/bug-reports/p/stripe-fee-recovery-should-round-up-the-last-digit-so-it-matches-the-amount-corr