From 85d46a40e51a9d819f6aeee89e2708f91bd9dad7 Mon Sep 17 00:00:00 2001 From: Pond Date: Tue, 16 Jul 2024 15:57:41 +0700 Subject: [PATCH] Fix function for php unit test --- includes/OrderFlow/InstantSettle.php | 27 ++++++++++++++-------- tests/unit/orderFlow/InstantSettleTest.php | 6 ++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/includes/OrderFlow/InstantSettle.php b/includes/OrderFlow/InstantSettle.php index beab67ea..9f0ddede 100644 --- a/includes/OrderFlow/InstantSettle.php +++ b/includes/OrderFlow/InstantSettle.php @@ -106,16 +106,10 @@ public function process_instant_settle( WC_Order $order ) { self::$order_capture->settle_items( $order, $items_data, $total_all, $settle_items ); - /** - * Recheck the invoice before adding the order meta data _is_instant_settled. - * - * @param WC_Order $order order to get items. - */ - $invoice = reepay()->api( $order )->get_invoice_data( $order ); - if ( isset( $invoice['state'] ) && 'settled' === $invoice['state'] ) { - $order->add_meta_data( '_is_instant_settled', '1' ); - $order->save_meta_data(); - } + $order->add_meta_data( '_is_instant_settled', '1' ); + $order->save_meta_data(); + + $this->check_order_settled( $order ); } } @@ -282,4 +276,17 @@ public static function get_settled_items( WC_Order $order ): array { return $settled; } + + /** + * Recheck the invoice before adding the order meta data _is_instant_settled. + * + * @param WC_Order $order order to get items. + */ + public function check_order_settled( WC_Order $order ) { + $invoice = reepay()->api( $order )->get_invoice_data( $order ); + if ( isset( $invoice['state'] ) && 'settled' !== $invoice['state'] ) { + $order->delete_meta_data( '_is_instant_settled', '1' ); + $order->save_meta_data(); + } + } } diff --git a/tests/unit/orderFlow/InstantSettleTest.php b/tests/unit/orderFlow/InstantSettleTest.php index ee6eebc4..c3cc4989 100644 --- a/tests/unit/orderFlow/InstantSettleTest.php +++ b/tests/unit/orderFlow/InstantSettleTest.php @@ -39,8 +39,7 @@ public function test_maybe_settle_instantly_with_reepay_payment_method() { self::$instant_settle_instance->maybe_settle_instantly( $this->order_generator->order() ); - // Disable because live call error 2024-07-02 - // $this->assertSame( '1', $this->order_generator->get_meta( '_is_instant_settled' ) ); + $this->assertSame( '1', $this->order_generator->get_meta( '_is_instant_settled' ) ); } /** @@ -100,11 +99,10 @@ public function test_process_instant_settle_already_settled() { self::$instant_settle_instance->process_instant_settle( $this->order_generator->order() ); - /* Disable because live call error 2024-07-02 $this->assertFalse( WC_Order_Factory::get_order_item( $order_item_id )->meta_exists( 'settled' ) ); - */ + } /**