veritrans / SNAP-Woocommerce

MIT License
19 stars 17 forks source link

Refund webhook notification, causes unexpected err: Too few arguments to function WC_Midtrans_Utils::check_and_restore_original_order_id() #76

Closed oxcid closed 1 year ago

oxcid commented 1 year ago

Hi,

Currently using Midtrans - WooCommerce Payment Gateway version 2.32.1.

I received an automated "midtrans Error Notification" email about not being able to reach my endpoint when sending refund notification. I noticed the error detail is InternalServerError, and I found this on my server's error log:

PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function WC_Midtrans_Utils::check_and_restore_original_order_id(), 0 passed in /var/www/html/wp-content/plugins/midtrans-woocommerce/abstract/abstract.midtrans-gateway.php on line 358 and exactly 1 expected in /var/www/html/wp-content/plugins/midtrans-woocommerce/class/class.midtrans-utils.php:157
Stack trace:
#0 /var/www/html/wp-content/plugins/midtrans-woocommerce/abstract/abstract.midtrans-gateway.php(358): WC_Midtrans_Utils::check_and_restore_original_order_id()
#1 /var/www/html/wp-includes/class-wp-hook.php(307): WC_Gateway_Midtrans_Abstract->midtrans_refund()

I confirmed that the payload from Midtrans indeed has "order_id" included. Then I checked on midtrans-woocommerce/abstract/abstract.midtrans-gateway.php, line 357:

public function midtrans_refund( $order_id, $refund_amount, $refund_reason, $isFullRefund = false ) {
    $order_id = WC_Midtrans_Utils::check_and_restore_original_order_id();
    $order  = wc_get_order( $order_id );
    if( ! is_a( $order, 'WC_Order') ) {
        return;
    }

On the second line of the above snippet, when "check_and_restore_original_order_id" function is called, there's no parameter included, while that function expects 1 parameter to be included ("midtrans-woocommerce/class/class.midtrans-utils.php").

public static function check_and_restore_original_order_id($non_duplicate_order_id)

Is this a possible cause for the error?

Thanks.

rizdaprasetya commented 1 year ago

Hi @oxcid thanks for reporting & the detailed report. Looks like you are correct! This function call: https://github.com/veritrans/SNAP-Woocommerce/blob/3736a7ca76d7b836bc2708cbcb5345c123289fe9/abstract/abstract.midtrans-gateway.php#L357-L358

Seems to be missing $order_id (when I mis-wrote that code a while back, but seems wasn't caught during development due to it was unintentionally got into catch block). Valid issue.

Possible Impact

Action Item

Thanks for reaching out! we'll update soon 🙏

rizdaprasetya commented 1 year ago

Released fixed version v2.32.2! ✅

Please do try to install the updated version. Let us know for any issue. Thanks! 👌

oxcid commented 1 year ago

Thanks @rizdaprasetya , I've installed the latest version. Will let you know if any issue still persist.