• Resolved hyperialab

    (@hyperialab)


    Hello,
    we’re using the Stripe plugin on a Woocommerce website.

    In our store, prices are set up with 4 decimals and inserted without taxes, but on the frontend those are displayed with 2 decimals everywhere (rounding is performed by hooking the wc_price function).

    Sometimes, the amount sent to Stripe is off by one cent with respect to the total shown to the user in cart and checkout.

    For instance:
    – Cart total: € 181.5657 (incl. taxes, shipping and any discount or coupons)
    – Total shown to user in checkout: € 181.57 (rounding to two decimal places performed by wc_price)
    – Total sent to stripe: € 181.56

    As a developer myself, I inspected the intent controller and found out that the amount is fetched from cart ($amount = WC()->cart->get_total(false)) and then transformed into the currency’s smallest unit (e.g.: 18156 cents of euros) before the request is sent to Stripe.

    The WC_Stripe_Helpers::get_stripe_amount which performs the conversion, considers the number of decimal places as configured in woocommerce settings (4 in our store) for rounding.
    However, in our case we would require rounding to consider only 2 decimal places, because that is the amount that the user sees in checkout.

    Would it be possible for you to add a filter which allows to customize the number of decimal places considered in roundings (the filter could default to wc_get_price_decimals() and leave the current behaviour unaltered), thus allowing us to hook that filter and perform the rounding with two decimal places?

    Other solutions would include to hook woocommerce_cart_get_total to round the amount before it is fetched from stripe, but that would also affect any other payment gateway.

    Thanks in advance for your support!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rounding issue with woocommerce’ is closed to new replies.