diff --git a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php index 57b8b73d6..7b28e8bdb 100644 --- a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php @@ -443,14 +443,8 @@ class OrderEndpoint { $error = new RuntimeException( __( 'Could not retrieve order.', 'woocommerce-paypal-payments' ) ); - $this->logger->log( - 'warning', - $error->getMessage(), - array( - 'args' => $args, - 'response' => $response, - ) - ); + $this->logger->warning($error->getMessage()); + throw $error; } $json = json_decode( $response['body'] ); @@ -485,8 +479,8 @@ class OrderEndpoint { ); throw $error; } - $order = $this->order_factory->from_paypal_response( $json ); - return $order; + + return $this->order_factory->from_paypal_response( $json ); } /** diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php index a6d715f55..5356a7605 100644 --- a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php @@ -10,9 +10,11 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\WcGateway\Processor; use Psr\Log\LoggerInterface; +use WC_Order; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; +use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException; use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory; use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper; use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure; @@ -160,17 +162,21 @@ class OrderProcessor { * * @return bool */ - public function process( \WC_Order $wc_order ): bool { - $order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY ); - if ( ! $order_id ) { - $this->last_error = __( 'No PayPal order ID found in the current WooCommerce session.', 'woocommerce-paypal-payments' ); - return false; - } - - $order = $this->session_handler->order() ?? $this->order_endpoint->order( $order_id ); + public function process( WC_Order $wc_order ): bool { + $order = $this->session_handler->order(); if ( ! $order ) { - $this->last_error = __( 'No PayPal order found in the current WooCommerce session.', 'woocommerce-paypal-payments' ); - return false; + $order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY ); + if ( ! $order_id ) { + $this->last_error = __( 'No PayPal order ID found in order meta.', 'woocommerce-paypal-payments' ); + return false; + } + + try { + $order = $this->order_endpoint->order( $order_id ); + } catch ( RuntimeException $exception ) { + $this->last_error = __( 'Could not retrieve PayPal order.', 'woocommerce-paypal-payments' ); + return false; + } } $this->add_paypal_meta( $wc_order, $order, $this->environment );