From 59503b29b3f56a56ec2820e566b899da29574baf Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Thu, 3 Jul 2025 00:16:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20OrderFactory=20?= =?UTF-8?q?to=20consolidate=203DS=20and=20regular=20response=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Endpoint/OrderEndpoint.php | 7 +--- .../src/Factory/OrderFactory.php | 33 ++----------------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php index 768bce393..62b24803a 100644 --- a/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php +++ b/modules/ppcp-api-client/src/Endpoint/OrderEndpoint.php @@ -265,12 +265,7 @@ class OrderEndpoint { throw $error; } - // Check if this is a PAYER_ACTION_REQUIRED response (3DS). - $is_3ds_response = isset( $json->status ) && $json->status === 'PAYER_ACTION_REQUIRED'; - - $order = $is_3ds_response - ? $this->order_factory->from_paypal_response_with_3ds( $json ) - : $this->order_factory->from_paypal_response( $json ); + $order = $this->order_factory->from_paypal_response( $json ); do_action( 'woocommerce_paypal_payments_paypal_order_created', $order ); diff --git a/modules/ppcp-api-client/src/Factory/OrderFactory.php b/modules/ppcp-api-client/src/Factory/OrderFactory.php index 0f994f7ba..8846216ce 100644 --- a/modules/ppcp-api-client/src/Factory/OrderFactory.php +++ b/modules/ppcp-api-client/src/Factory/OrderFactory.php @@ -68,7 +68,8 @@ class OrderFactory { $order->payer(), $order->intent(), $order->create_time(), - $order->update_time() + $order->update_time(), + $order->links() ); } @@ -83,36 +84,6 @@ class OrderFactory { public function from_paypal_response( \stdClass $order_data ): Order { $this->validate_order_id( $order_data ); - $purchase_units = $this->create_purchase_units( $order_data ); - $status = $this->create_order_status( $order_data ); - $intent = $this->get_intent( $order_data ); - $timestamps = $this->create_timestamps( $order_data ); - $payer = $this->create_payer( $order_data ); - $payment_source = $this->create_payment_source( $order_data ); - - return new Order( - $order_data->id, - $purchase_units, - $status, - $payment_source, - $payer, - $intent, - $timestamps['create_time'], - $timestamps['update_time'] - ); - } - - /** - * Returns an Order object based off a PayPal 3DS Response. - * - * @param \stdClass $order_data The JSON object. - * - * @return Order - * @throws RuntimeException When JSON object is malformed. - */ - public function from_paypal_response_with_3ds( \stdClass $order_data ): Order { - $this->validate_order_id( $order_data ); - $purchase_units = $this->create_purchase_units( $order_data ); $status = $this->create_order_status( $order_data ); $intent = $this->get_intent( $order_data );