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

Refunds not working, Fatal error: Uncaught TypeError: abs() in src/Payment/RefundLineItemsBuilder.php:73 #992

Open
Fidelity88 opened this issue Jan 28, 2025 · 0 comments

Comments

@Fidelity88
Copy link
Contributor

Fidelity88 commented Jan 28, 2025

When trying to do a refund on some orders. It's not working and give a fatal error:

[28-Jan-2025 15:19:19 UTC] PHP Fatal error:  Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/RefundLineItemsBuilder.php:71
Stack trace:
#0 /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/RefundLineItemsBuilder.php(71): abs()
#1 /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/RefundLineItemsBuilder.php(49): Mollie\WooCommerce\Payment\RefundLineItemsBuilder->buildLineItem()
#2 /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/OrderItemsRefunder.php(64): Mollie\WooCommerce\Payment\RefundLineItemsBuilder->buildLineItems()
#3 /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/MollieOrder.php(463): Mollie\WooCommerce\Payment\OrderItemsRefunder->refund()
#4 /wp-content/plugins/mollie-payments-for-woocommerce/src/Gateway/MolliePaymentGateway.php(524): Mollie\WooCommerce\Payment\MollieOrder->refund()
#5 /wp-content/plugins/woocommerce/includes/wc-order-functions.php(773): Mollie\WooCommerce\Gateway\MolliePaymentGateway->process_refund()
#6 /wp-content/plugins/woocommerce/includes/wc-order-functions.php(667): wc_refund_payment()
#7 /wp-content/plugins/woocommerce/includes/class-wc-ajax.php(2205): wc_create_refund()
#8 /wp-includes/class-wp-hook.php(324): WC_AJAX::refund_line_items()
#9 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#10 /wp-includes/plugin.php(517): WP_Hook->do_action()
#11 /wp-admin/admin-ajax.php(192): do_action()
#12 {main}
  thrown in /wp-content/plugins/mollie-payments-for-woocommerce/src/Payment/RefundLineItemsBuilder.php on line 71

The problem seems to lie within this line:

$toRefundItemQuantity = abs($toRefundItem->get_quantity());

$toRefundItemQuantity = abs($toRefundItem->get_quantity());

When I var_dump the output of $toRefundItem->get_quantity(), the output is string(5) "-100." . I don't know if this is expected when you enter "100" as refund quantity. I certainly did not type a dot after the value.

When I check the output of $toRefundItem, I get this result:

(
    [id:protected] => 34362
    [data:protected] => Array
        (
            [order_id] => 40786
            [name] => PTFE slang 1 mm x 2 mm
            [product_id] => 9475
            [variation_id] => 0
            [quantity] => -100.
            [tax_class] =>
            [subtotal] => -3.6
            [subtotal_tax] => -0.76
            [total] => -3.6
            [total_tax] => -0.76
[...]

So for some reason. The quantity refund breaks on this.

The workaround that fixed the problem for me was to add (int) inside the abs() function. So change this:
$toRefundItemQuantity = abs($toRefundItem->get_quantity());

To this:
$toRefundItemQuantity = abs((int) $toRefundItem->get_quantity());

I can now perform refunds in WooCommerce again.

Plugin version:
7.9.17.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant