impress-org / givewp

GiveWP - The #1 Donation Plugin for WordPress. Easily accept donations and fundraise using your WordPress website.
https://givewp.com/
GNU General Public License v3.0
339 stars 191 forks source link

Fee recovery problems with (custom) zero based currency #7425

Open joshAppDev opened 2 months ago

joshAppDev commented 2 months ago

User Story

As a zero decimal currency donor, I want fee recovery calculations to be less confusing.

Details

In this example, the donor is giving 10555 in the IDR currency. This currency is not classified as a zero based currency by default, but it was specified as such using the give_fee_zero_based_currency filter in the custom gateway plugin. The payment gateway only accepts integer amounts for this currency.

The donor checks the box to cover the transaction fees. Here is the preview shown: fee-recovery

So far so good.

But the actual calculations for the fee recovery do use decimal places. Here is the final breakdown of the fee recovery as shown in the receipt:

Amount: Rp10870,55 (Rp10554,55 donation + Rp316,00 for fees) prcessing-receipt

Three problems.

  1. Floating point math is not precise enough. 10555 got changed to 10554,55. For context, Rp10000 is less than $1 in USD. So it would not be uncommon for donors to give "large" amounts like this.
  2. The fee recovery amount was prioritized over the original donation amount. If an amount has to be changed for the fee calculations, it should be the fee.
  3. There should not be any decimal places at all.

Notably, this problem does not occur when using a currency that is zero based by default, such as the Japanese Yen.

Expected Behavior

The donation amount should remain the same as what the donor agreed to. It should be 10871. The amounts should not include any decimal places. The original amount should be 10555. The fee should be 316.

Steps to Reproduce

  1. Set your GiveWP currency to IDR (Indonesian Rupiah).
  2. Add a give_fee_zero_based_currency filter that inserts the IDR currency into the list.
  3. Enable fee recovery.
  4. Make a donation with fee recovery selected.

System Information

Details GiveWP 3.4.2 PHP 8.0.30

Acceptance Criteria

joshAppDev commented 3 weeks ago

Another solution would be for GiveWP to add these currencies into its hard coded list of zero based currencies: