From 8a0b439e5fe62fab7f8d217979edd1572cb6f941 Mon Sep 17 00:00:00 2001 From: dinamiko Date: Tue, 7 Jun 2022 12:17:35 +0200 Subject: [PATCH] Add order status `CREATED` to order processor check --- .../src/Endpoint/ApproveOrderEndpoint.php | 4 ++-- .../src/Processor/OrderProcessor.php | 13 ++++++------- .../WcGateway/Processor/OrderProcessorTest.php | 4 ++++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/ppcp-button/src/Endpoint/ApproveOrderEndpoint.php b/modules/ppcp-button/src/Endpoint/ApproveOrderEndpoint.php index bfbde9923..82a0c789e 100644 --- a/modules/ppcp-button/src/Endpoint/ApproveOrderEndpoint.php +++ b/modules/ppcp-button/src/Endpoint/ApproveOrderEndpoint.php @@ -173,10 +173,10 @@ class ApproveOrderEndpoint implements EndpointInterface { wp_send_json_success( $order ); } - if ( ! $order->status()->is( OrderStatus::APPROVED ) ) { + if ( ! $order->status()->is( OrderStatus::APPROVED ) && ! $order->status()->is( OrderStatus::CREATED ) ) { $message = sprintf( // translators: %s is the id of the order. - __( 'Order %s is not approved yet.', 'woocommerce-paypal-payments' ), + __( 'Order %s is not ready for processing yet.', 'woocommerce-paypal-payments' ), $data['order_id'] ); diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php index b1d3358bd..6ce0e068f 100644 --- a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php @@ -160,9 +160,9 @@ class OrderProcessor { $this->add_paypal_meta( $wc_order, $order, $this->environment ); $error_message = null; - if ( ! $this->order_is_approved( $order ) ) { + if ( ! $this->order_is_ready_for_process( $order ) ) { $error_message = __( - 'The payment has not been approved yet.', + 'The payment is not ready for processing yet.', 'woocommerce-paypal-payments' ); } @@ -269,15 +269,15 @@ class OrderProcessor { } /** - * Whether a given order is approved. + * Whether a given order is ready for processing. * * @param Order $order The order. * * @return bool */ - private function order_is_approved( Order $order ): bool { + private function order_is_ready_for_process( Order $order ): bool { - if ( $order->status()->is( OrderStatus::APPROVED ) ) { + if ( $order->status()->is( OrderStatus::APPROVED ) || $order->status()->is( OrderStatus::CREATED ) ) { return true; } @@ -285,7 +285,7 @@ class OrderProcessor { return false; } - $is_approved = in_array( + return in_array( $this->threed_secure->proceed_with_order( $order ), array( ThreeDSecure::NO_DECISION, @@ -293,6 +293,5 @@ class OrderProcessor { ), true ); - return $is_approved; } } diff --git a/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php b/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php index ae051a68c..6fd7f6c78 100644 --- a/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php +++ b/tests/PHPUnit/WcGateway/Processor/OrderProcessorTest.php @@ -306,6 +306,10 @@ class OrderProcessorTest extends TestCase ->expects('is') ->with(OrderStatus::APPROVED) ->andReturn(false); + $orderStatus + ->expects('is') + ->with(OrderStatus::CREATED) + ->andReturn(false); $orderId = 'abc'; $orderIntent = 'CAPTURE'; $currentOrder = Mockery::mock(Order::class);