Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
joshAppDev opened this issue Jun 27, 2024 · 3 comments
Open
2 tasks

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

joshAppDev opened this issue Jun 27, 2024 · 3 comments
Labels
type: bug Existing functionality is broken

Comments

@joshAppDev
Copy link

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

  • Fee calculations should respect the give_fee_zero_based_currency filter.
  • OR GiveWP can provide a way to set a currency as zero based in the settings.
@joshAppDev joshAppDev added the type: bug Existing functionality is broken label Jun 27, 2024
@joshAppDev
Copy link
Author

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

  • KES
  • IDR
  • VND

Copy link

github-actions bot commented Oct 5, 2024

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 14 additional days. Note, if this Issue is reporting a bug, please reach out to our support at https://givewp.com/support. If this is a feature request, please see our feedback board at feedback.givewp.com — that’s the best place to make feature requests, unless you’re providing a PR.

@github-actions github-actions bot added the Stale label Oct 5, 2024
@joshAppDev
Copy link
Author

I found my problem. There are TWO separate GiveWP filters for designating a currency as zero based.

  • give_get_zero_based_currencies
  • give_fee_zero_based_currency

I was only using the latter one. Both need to be used together. For example:

        // Gateway does not accept amounts with decimal places for these currencies
        add_filter('give_get_zero_based_currencies', static function($currency_list) {
            foreach (self::ZERO_BASED_CURRENCIES as $currency => $symbol) {
                if (!in_array($currency, $currency_list)) {
                    $currency_list[] = $currency;
                }
            }
            return $currency_list;
        });
        add_filter('give_fee_zero_based_currency', static function ($currency_list) {
            foreach (self::ZERO_BASED_CURRENCIES as $currency => $symbol) {
                if (!isset($currency_list[$currency])) {
                    $currency_list[$currency] = give_currency_symbol($currency) ?? $symbol;
                }
            }
            return $currency_list;
        });

@github-actions github-actions bot removed the Stale label Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Existing functionality is broken
Projects
None yet
Development

No branches or pull requests

1 participant