diff --git a/modules/ppcp-api-client/src/Endpoint/WebhookEndpoint.php b/modules/ppcp-api-client/src/Endpoint/WebhookEndpoint.php index d8cc06dca..6ae411cfa 100644 --- a/modules/ppcp-api-client/src/Endpoint/WebhookEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/WebhookEndpoint.php @@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookEventFactory; use WooCommerce\PayPalCommerce\ApiClient\Factory\WebhookFactory; use Psr\Log\LoggerInterface; +use WP_Error; /** * Class WebhookEndpoint @@ -193,7 +194,7 @@ class WebhookEndpoint { ); $response = $this->request( $url, $args ); - if ( is_wp_error( $response ) ) { + if ( $response instanceof WP_Error ) { throw new RuntimeException( __( 'Not able to delete the webhook.', 'woocommerce-paypal-payments' ) ); @@ -201,10 +202,7 @@ class WebhookEndpoint { $status_code = (int) wp_remote_retrieve_response_code( $response ); if ( 204 !== $status_code ) { - $json = null; - if ( is_array( $response ) ) { - $json = json_decode( $response['body'] ); - } + $json = json_decode( $response['body'] ) ?? null; throw new PayPalApiException( $json, $status_code diff --git a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php index 053cd619a..eab1defc0 100644 --- a/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php +++ b/modules/ppcp-webhooks/src/Handler/PaymentCaptureRefunded.php @@ -112,8 +112,7 @@ class PaymentCaptureRefunded implements RequestHandler { 'amount' => $request['resource']['amount']['value'], ) ); - if ( is_wp_error( $refund ) ) { - assert( $refund instanceof WP_Error ); + if ( $refund instanceof WP_Error ) { $message = sprintf( 'Order %1$s could not be refunded. %2$s', (string) $wc_order->get_id(),