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

Order amount submitted to Stripe different from Order total #43

Open
endynamics opened this issue Oct 24, 2020 · 1 comment
Open

Order amount submitted to Stripe different from Order total #43

endynamics opened this issue Oct 24, 2020 · 1 comment
Labels

Comments

@endynamics
Copy link

Sometimes, when a payment is processed via the Stripe module, the amount submitted to stripe is not equal to the value of the items in the order. This issue does not affect every order, but does seem to affect values ending .99. For example, a recent order for 18.99 was submitted to Stripe as 18.98.

As far as I can tell, the amount which is sent to Stripe is generated in classes/StripeApi.php line 70:

$total = Utils::getCartTotal($cart);

This value is obtained by converting the order total into the correct amount per the currency settings for Stripe. In our case, using GBP, this means multiplying the value by 100:

stripe/classes/Utils.php

Lines 64 to 78 in 8d5274c

/**
* Converts amount into smallest common currency unit - that's cents for currencies like
* dollar or euro
*
* @param Currency $currency
* @param float $amount
* @return int
*/
public static function toCurrencyUnit(Currency $currency, $amount)
{
if (in_array(mb_strtolower($currency->iso_code), Stripe::$zeroDecimalCurrencies)) {
return (int)$amount;
}
return (int)($amount * 100);
}

I can't see anything in the above which would cause the value to change in this way, but the case remains that the amount recorded everywhere in the CMS is 18.99, but the amount submitted to & captured by Stripe is 18.98. I'm guessing that this is due to float value rounding somewhere but haven't been able to figure this out. It's worth noting that the application is also making use of the Vat Exemption Module, however this issue affects orders both with & without VAT.

If there's any additional information or detail I can provide to help with this issue, please let me know.

@getdatakick
Copy link
Contributor

The code in toCurrencyUnit does not perform rounding. If the price is 18.9899999 then the result is 1898 instead of 1899 (cents)

@getdatakick getdatakick added the bug label Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants