woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Call to undefined method WC_Order_Refund::get_order_key() #808

Open james-allan opened 3 years ago

james-allan commented 3 years ago

Describe the bug

Slack thread: p1599652831251300-slack-CJTS771PB Ticket: 3255765-zd-woothemes

The site received a [payment_status] => Canceled_Reversal IPN with a custom arg {"order_id":87076,"order_key":"***"}, that 87076 order ID though may (cannot confirm) be associated with a refund because while processing that IPN the follow fatal error occurred.

2020-09-09T07:49:29+00:00 CRITICAL Uncaught Error: Call to undefined method Automattic\WooCommerce\Admin\Overrides\OrderRefund::get_order_key() in /wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/abstracts/abstract-wc-gateway-ppec-paypal-request-handler.php:57
Stack trace:
#0 /wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-ipn-handler.php(95): WC_Gateway_PPEC_PayPal_Request_Handler->get_paypal_order('{"order_id":870...')
#1 /wp-includes/class-wp-hook.php(287): WC_Gateway_PPEC_IPN_Handler->handle_valid_ipn(Array)
#2 /wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#3 /wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#4 /wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-ipn-handler.php(34): do_action('woocommerce_pay in /wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/abstracts/abstract-wc-gateway-ppec-paypal-request-handler.php on line 57

If you follow that stacktrace through, you'll find that it is this line that is throwing the error. It just checks that it got something back from wc_get_order(), in this case, it did get something back but it was a refund class which doesn't have a get_order_key() function.

I've tried to investigate why a refund ID was passed into the IPN but there's not much history we can find about that ID given you cant search for and view it.

I propose we just tighten that code so it knows we have an order (not a refund) before proceeding.

AashikP commented 2 years ago

I'm wondering if this is specifically related to PayPal Checkout. We have a user in 4370972-zen that ran into a similar issue with both PayPal Checkout and PayPal Payments.

We don't have logs for checkout, but refunding an order placed via their account (works fine when our test account is used on their site) returns the following error:

Response Body: {"name":"NOT_AUTHORIZED","message":"Authorization failed due to insufficient permissions.","debug_id":"redacted","details":[{"issue":"PERMISSION_DENIED","field":"capture_id","value":"redacted","description":"You do not have permission to access or perform operations on this resource.","location":"path"}],"links":[{"href":"https://developer.paypal.com/docs/api/payments/v2/#error-PERMISSION_DENIED","rel":"information_link"}]}

And then if we manually refund the order, we see this error on visiting Store > My Account page> Orders

https://d.pr/i/dVBnXu+

Any thoughts on if this is related?