Skip to content

Order amount submitted to Stripe different from Order total #43

@endynamics

Description

@endynamics

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions